-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
311 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@assistant-ui/react-hook-form": patch | ||
"@assistant-ui/react": patch | ||
--- | ||
|
||
feat: Tool Render functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/react/src/context/stores/AssistantToolRenderers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use client"; | ||
|
||
import { create } from "zustand"; | ||
import type { ToolRenderComponent } from "../../model-config/ToolRenderComponent"; | ||
|
||
export type AssistantToolRenderersState = { | ||
// biome-ignore lint/suspicious/noExplicitAny: intentional any | ||
getToolRenderer: (name: string) => ToolRenderComponent<any, any> | null; | ||
setToolRenderer: ( | ||
name: string, | ||
// biome-ignore lint/suspicious/noExplicitAny: intentional any | ||
render: ToolRenderComponent<any, any>, | ||
) => () => void; | ||
}; | ||
|
||
export const makeAssistantToolRenderersStore = () => | ||
create<AssistantToolRenderersState>((set) => { | ||
// biome-ignore lint/suspicious/noExplicitAny: intentional any | ||
const renderers = new Map<string, ToolRenderComponent<any, any>[]>(); | ||
|
||
return { | ||
getToolRenderer: (name) => { | ||
const arr = renderers.get(name); | ||
const last = arr?.at(-1); | ||
if (last) return last; | ||
return null; | ||
}, | ||
setToolRenderer: (name, render) => { | ||
let arr = renderers.get(name); | ||
if (!arr) { | ||
arr = []; | ||
renderers.set(name, arr); | ||
} | ||
arr.push(render); | ||
set({}); // notify the store listeners | ||
|
||
return () => { | ||
const index = arr.indexOf(render); | ||
if (index !== -1) { | ||
arr.splice(index, 1); | ||
} | ||
set({}); // notify the store listeners | ||
}; | ||
}, | ||
} satisfies AssistantToolRenderersState; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use client"; | ||
import type { ComponentType } from "react"; | ||
import type { ToolCallContentPart } from "../experimental"; | ||
|
||
export type ToolRenderComponent<TArgs, TResult> = ComponentType<{ | ||
part: ToolCallContentPart<TArgs, TResult>; | ||
status: "done" | "in_progress" | "error"; | ||
}>; |
Oops, something went wrong.