@assistant-ui/react 0.10.17 → 0.10.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.d.ts.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +4 -3
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/model-context/useAssistantToolUI.js +2 -2
- package/dist/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -6
- package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
- package/dist/primitives/contentPart/useContentPartFile.d.ts +1 -1
- package/dist/primitives/contentPart/useContentPartImage.d.ts +1 -1
- package/dist/primitives/contentPart/useContentPartReasoning.d.ts +1 -1
- package/dist/primitives/contentPart/useContentPartSource.d.ts +1 -1
- package/dist/primitives/contentPart/useContentPartText.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context/react/utils/createStateHookForRuntime.ts +1 -1
- package/src/model-context/makeAssistantVisible.tsx +5 -3
- package/src/model-context/useAssistantToolUI.tsx +2 -2
- package/src/primitives/assistantModal/AssistantModalRoot.tsx +1 -6
- package/src/types/index.ts +2 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n\n // it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available\n // eslint-
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/createStateHookForRuntime.ts"],"sourcesContent":["import {\n SubscribableRuntime,\n useRuntimeStateInternal,\n} from \"./useRuntimeState\";\n\nexport function createStateHookForRuntime<TState>(\n useRuntime: (options: {\n optional: boolean | undefined;\n }) => SubscribableRuntime<TState> | null,\n) {\n // empty\n function useStoreHook(): TState;\n\n // selector\n function useStoreHook<TSelected>(\n selector: (state: TState) => TSelected,\n ): TSelected;\n\n // selector?\n function useStoreHook<TSelected>(\n selector: ((state: TState) => TSelected) | undefined,\n ): TSelected | TState;\n\n // optional=false\n function useStoreHook(options: { optional?: false | undefined }): TState;\n\n // optional?\n function useStoreHook(options: {\n optional?: boolean | undefined;\n }): TState | null;\n\n // optional=false, selector\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected;\n\n // optional=false, selector?\n function useStoreHook<TSelected>(options: {\n optional?: false | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState;\n\n // optional?, selector\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: (state: TState) => TSelected;\n }): TSelected | null;\n\n // optional?, selector?\n function useStoreHook<TSelected>(options: {\n optional?: boolean | undefined;\n selector: ((state: TState) => TSelected) | undefined;\n }): TSelected | TState | null;\n\n function useStoreHook<TSelected>(\n param?:\n | ((state: TState) => TSelected)\n | {\n optional?: boolean | undefined;\n selector?: ((state: TState) => TSelected) | undefined;\n },\n ): TSelected | TState | null {\n let optional = false;\n let selector: ((state: TState) => TSelected) | undefined;\n\n if (typeof param === \"function\") {\n selector = param;\n } else if (param) {\n optional = !!param.optional;\n selector = param.selector;\n }\n\n const store = useRuntime({ optional });\n if (!store) return null;\n\n // it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useRuntimeStateInternal(store, selector);\n }\n\n return useStoreHook;\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OACK;AAEA,SAAS,0BACd,YAGA;AA8CA,WAAS,aACP,OAM2B;AAC3B,QAAI,WAAW;AACf,QAAI;AAEJ,QAAI,OAAO,UAAU,YAAY;AAC/B,iBAAW;AAAA,IACb,WAAW,OAAO;AAChB,iBAAW,CAAC,CAAC,MAAM;AACnB,iBAAW,MAAM;AAAA,IACnB;AAEA,UAAM,QAAQ,WAAW,EAAE,SAAS,CAAC;AACrC,QAAI,CAAC,MAAO,QAAO;AAInB,WAAO,wBAAwB,OAAO,QAAQ;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"makeAssistantVisible.d.ts","sourceRoot":"","sources":["../../src/model-context/makeAssistantVisible.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAMd,MAAM,OAAO,CAAC;AAmDf,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC/D,WAAW,CAAC,EACZ,SAAS;IAAE,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,
|
1
|
+
{"version":3,"file":"makeAssistantVisible.d.ts","sourceRoot":"","sources":["../../src/model-context/makeAssistantVisible.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAMd,MAAM,OAAO,CAAC;AAmDf,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC/D,WAAW,CAAC,EACZ,SAAS;IAAE,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,KA6CrC,CACxC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
@@ -57,19 +57,20 @@ var makeAssistantVisible = (Component, config) => {
|
|
57
57
|
const clickId = useId();
|
58
58
|
const componentRef = useRef(null);
|
59
59
|
const assistant = useAssistantRuntime();
|
60
|
+
const { clickable, editable } = config ?? {};
|
60
61
|
useEffect(() => {
|
61
62
|
return assistant.registerModelContextProvider({
|
62
63
|
getModelContext: () => {
|
63
64
|
return {
|
64
65
|
tools: {
|
65
|
-
...
|
66
|
-
...
|
66
|
+
...clickable ? { click } : {},
|
67
|
+
...editable ? { edit } : {}
|
67
68
|
},
|
68
69
|
system: !isNestedReadable ? componentRef.current?.outerHTML : void 0
|
69
70
|
};
|
70
71
|
}
|
71
72
|
});
|
72
|
-
}, [
|
73
|
+
}, [isNestedReadable, assistant, clickable, editable]);
|
73
74
|
const ref = useComposedRefs(componentRef, outerRef);
|
74
75
|
return /* @__PURE__ */ jsx(ReadableContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
|
75
76
|
Component,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\n// TODO replace zod with json-schema so we can drop the zod dep\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(
|
1
|
+
{"version":3,"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n ComponentType,\n ForwardedRef,\n PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { z } from \"zod\";\nimport { useAssistantRuntime } from \"../context\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"./tool\";\n\n// TODO replace zod with json-schema so we can drop the zod dep\n\nconst click = tool({\n parameters: z.object({\n clickId: z.string(),\n }),\n execute: async ({ clickId }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst edit = tool({\n parameters: z.object({\n editId: z.string(),\n value: z.string(),\n }),\n execute: async ({ editId, value }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n el.value = value;\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const assistant = useAssistantRuntime();\n\n const { clickable, editable } = config ?? {};\n useEffect(() => {\n return assistant.registerModelContextProvider({\n getModelContext: () => {\n return {\n tools: {\n ...(clickable ? { click } : {}),\n ...(editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [isNestedReadable, assistant, clickable, editable]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n ReadableComponent.displayName = Component.displayName;\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAClB,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAiFX;AA7EV,IAAM,QAAQ,KAAK;AAAA,EACjB,YAAY,EAAE,OAAO;AAAA,IACnB,SAAS,EAAE,OAAO;AAAA,EACpB,CAAC;AAAA,EACD,SAAS,OAAO,EAAE,QAAQ,MAAM;AAC9B,UAAM,iBAAiB,IAAI,OAAO,OAAO;AACzC,UAAM,KAAK,SAAS,cAAc,mBAAmB,cAAc,IAAI;AACvE,QAAI,cAAc,aAAa;AAC7B,SAAG,MAAM;AAGT,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC;AACxD,aAAO,CAAC;AAAA,IACV,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;AAED,IAAM,OAAO,KAAK;AAAA,EAChB,YAAY,EAAE,OAAO;AAAA,IACnB,QAAQ,EAAE,OAAO;AAAA,IACjB,OAAO,EAAE,OAAO;AAAA,EAClB,CAAC;AAAA,EACD,SAAS,OAAO,EAAE,QAAQ,MAAM,MAAM;AACpC,UAAM,gBAAgB,IAAI,OAAO,MAAM;AACvC,UAAM,KAAK,SAAS,cAAc,kBAAkB,aAAa,IAAI;AACrE,QAAI,cAAc,oBAAoB,cAAc,qBAAqB;AACvE,SAAG,QAAQ;AACX,SAAG,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC;AACtD,SAAG,cAAc,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC,CAAC;AAGvD,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC;AACxD,aAAO,CAAC;AAAA,IACV,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;AAED,IAAM,kBAAkB,cAAuB,KAAK;AAE7C,IAAM,uBAAuB,CAClC,WACA,WACG;AACH,QAAM,oBAAoB;AAAA,IACxB,CAAC,OAA2B,aAAgC;AAC1D,YAAM,mBAAmB,WAAW,eAAe;AAEnD,YAAM,UAAU,MAAM;AACtB,YAAM,eAAe,OAAoB,IAAI;AAE7C,YAAM,YAAY,oBAAoB;AAEtC,YAAM,EAAE,WAAW,SAAS,IAAI,UAAU,CAAC;AAC3C,gBAAU,MAAM;AACd,eAAO,UAAU,6BAA6B;AAAA,UAC5C,iBAAiB,MAAM;AACrB,mBAAO;AAAA,cACL,OAAO;AAAA,gBACL,GAAI,YAAY,EAAE,MAAM,IAAI,CAAC;AAAA,gBAC7B,GAAI,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,cAC7B;AAAA,cACA,QAAQ,CAAC,mBACL,aAAa,SAAS,YACtB;AAAA,YACN;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,GAAG,CAAC,kBAAkB,WAAW,WAAW,QAAQ,CAAC;AAErD,YAAM,MAAM,gBAAgB,cAAc,QAAQ;AAElD,aACE,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAC/B;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACJ,GAAI,QAAQ,YAAY,EAAE,iBAAiB,QAAQ,IAAI,CAAC;AAAA,UACxD,GAAI,QAAQ,WAAW,EAAE,gBAAgB,QAAQ,IAAI,CAAC;AAAA,UACvD;AAAA;AAAA,MACF,GACF;AAAA,IAEJ;AAAA,EACF;AAEA,oBAAkB,cAAc,UAAU;AAE1C,SAAO;AACT;AAEA,IAAO,+BAAQ;","names":[]}
|
@@ -6,9 +6,9 @@ import { useToolUIsStore } from "../context/react/AssistantContext.js";
|
|
6
6
|
var useAssistantToolUI = (tool) => {
|
7
7
|
const toolUIsStore = useToolUIsStore();
|
8
8
|
useEffect(() => {
|
9
|
-
if (!tool) return;
|
9
|
+
if (!tool?.toolName || !tool?.render) return;
|
10
10
|
return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);
|
11
|
-
}, [toolUIsStore, tool?.toolName, tool?.render
|
11
|
+
}, [toolUIsStore, tool?.toolName, tool?.render]);
|
12
12
|
};
|
13
13
|
export {
|
14
14
|
useAssistantToolUI
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render
|
1
|
+
{"version":3,"sources":["../../src/model-context/useAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useToolUIsStore } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const toolUIsStore = useToolUIsStore();\n useEffect(() => {\n if (!tool?.toolName || !tool?.render) return;\n return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);\n }, [toolUIsStore, tool?.toolName, tool?.render]);\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAQzB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,eAAe,gBAAgB;AACrC,YAAU,MAAM;AACd,QAAI,CAAC,MAAM,YAAY,CAAC,MAAM,OAAQ;AACtC,WAAO,aAAa,SAAS,EAAE,UAAU,KAAK,UAAU,KAAK,MAAM;AAAA,EACrE,GAAG,CAAC,cAAc,MAAM,UAAU,MAAM,MAAM,CAAC;AACjD;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantModalRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAI5D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG,gBAAgB,CAAC,YAAY,GAAG;QAClD,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC/C,CAAC;CACH;
|
1
|
+
{"version":3,"file":"AssistantModalRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAI5D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG,gBAAgB,CAAC,YAAY,GAAG;QAClD,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC/C,CAAC;CACH;AAwBD,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CA6BlC,CAAC"}
|
@@ -18,12 +18,7 @@ var useAssistantModalOpenState = ({
|
|
18
18
|
return threadRuntime.unstable_on("run-start", () => {
|
19
19
|
setOpen(true);
|
20
20
|
});
|
21
|
-
}, [
|
22
|
-
unstable_openOnRunStart,
|
23
|
-
setOpen,
|
24
|
-
threadRuntime,
|
25
|
-
!unstable_openOnRunStart
|
26
|
-
]);
|
21
|
+
}, [unstable_openOnRunStart, setOpen, threadRuntime]);
|
27
22
|
return state;
|
28
23
|
};
|
29
24
|
var AssistantModalPrimitiveRoot = ({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { useThreadRuntime } from \"../../context\";\n\nexport namespace AssistantModalPrimitiveRoot {\n export type Props = PopoverPrimitive.PopoverProps & {\n unstable_openOnRunStart?: boolean | undefined;\n };\n}\n\nconst useAssistantModalOpenState = ({\n defaultOpen = false,\n unstable_openOnRunStart = true,\n}: {\n defaultOpen?: boolean | undefined;\n unstable_openOnRunStart?: boolean | undefined;\n}) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n if (!unstable_openOnRunStart) return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", () => {\n setOpen(true);\n });\n }, [
|
1
|
+
{"version":3,"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { useThreadRuntime } from \"../../context\";\n\nexport namespace AssistantModalPrimitiveRoot {\n export type Props = PopoverPrimitive.PopoverProps & {\n unstable_openOnRunStart?: boolean | undefined;\n };\n}\n\nconst useAssistantModalOpenState = ({\n defaultOpen = false,\n unstable_openOnRunStart = true,\n}: {\n defaultOpen?: boolean | undefined;\n unstable_openOnRunStart?: boolean | undefined;\n}) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n if (!unstable_openOnRunStart) return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", () => {\n setOpen(true);\n });\n }, [unstable_openOnRunStart, setOpen, threadRuntime]);\n\n return state;\n};\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRoot.Props\n> = ({\n __scopeAssistantModal,\n defaultOpen,\n unstable_openOnRunStart,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRoot.Props>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useAssistantModalOpenState({\n defaultOpen,\n unstable_openOnRunStart,\n });\n\n const openChangeHandler = (open: boolean) => {\n onOpenChange?.(open);\n setOpen(open);\n };\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={open === undefined ? modalOpen : open}\n onOpenChange={openChangeHandler}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n"],"mappings":";;;AAEA,SAAa,WAAW,gBAAgB;AACxC,YAAY,sBAAsB;AAClC,SAAsB,uBAAuB;AAC7C,SAAS,wBAAwB;AAqD7B;AA7CJ,IAAM,6BAA6B,CAAC;AAAA,EAClC,cAAc;AAAA,EACd,0BAA0B;AAC5B,MAGM;AACJ,QAAM,QAAQ,SAAS,WAAW;AAElC,QAAM,CAAC,EAAE,OAAO,IAAI;AACpB,QAAM,gBAAgB,iBAAiB;AACvC,YAAU,MAAM;AACd,QAAI,CAAC,wBAAyB,QAAO;AAErC,WAAO,cAAc,YAAY,aAAa,MAAM;AAClD,cAAQ,IAAI;AAAA,IACd,CAAC;AAAA,EACH,GAAG,CAAC,yBAAyB,SAAS,aAAa,CAAC;AAEpD,SAAO;AACT;AAEO,IAAM,8BAET,CAAC;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAsD;AACpD,QAAM,QAAQ,gBAAgB,qBAAqB;AAEnD,QAAM,CAAC,WAAW,OAAO,IAAI,2BAA2B;AAAA,IACtD;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,oBAAoB,CAACA,UAAkB;AAC3C,mBAAeA,KAAI;AACnB,YAAQA,KAAI;AAAA,EACd;AAEA,SACE;AAAA,IAAkB;AAAA,IAAjB;AAAA,MACE,GAAG;AAAA,MACJ,MAAM,SAAS,SAAY,YAAY;AAAA,MACvC,cAAc;AAAA,MACb,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,4BAA4B,cAAc;","names":["open"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FileContentPart } from "../../types";
|
2
2
|
export declare const useContentPartFile: () => FileContentPart & {
|
3
|
-
readonly status: import("
|
3
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
4
4
|
};
|
5
5
|
//# sourceMappingURL=useContentPartFile.d.ts.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ImageContentPart } from "../../types";
|
2
2
|
export declare const useContentPartImage: () => ImageContentPart & {
|
3
|
-
readonly status: import("
|
3
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
4
4
|
};
|
5
5
|
//# sourceMappingURL=useContentPartImage.d.ts.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ReasoningContentPart } from "../../types";
|
2
2
|
export declare const useContentPartReasoning: () => ReasoningContentPart & {
|
3
|
-
readonly status: import("
|
3
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
4
4
|
};
|
5
5
|
//# sourceMappingURL=useContentPartReasoning.d.ts.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { SourceContentPart } from "../../types";
|
2
2
|
export declare const useContentPartSource: () => SourceContentPart & {
|
3
|
-
readonly status: import("
|
3
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
4
4
|
};
|
5
5
|
//# sourceMappingURL=useContentPartSource.d.ts.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { TextContentPart, ReasoningContentPart } from "../../types";
|
2
2
|
export declare const useContentPartText: () => (TextContentPart & {
|
3
|
-
readonly status: import("
|
3
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
4
4
|
}) | (ReasoningContentPart & {
|
5
|
-
readonly status: import("
|
5
|
+
readonly status: import("../..").ContentPartStatus | import("../..").ToolCallContentPartStatus;
|
6
6
|
});
|
7
7
|
//# sourceMappingURL=useContentPartText.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export type { Attachment, PendingAttachment, CompleteAttachment, AttachmentStatus, } from "./AttachmentTypes";
|
2
|
-
export type { AppendMessage, TextContentPart, ReasoningContentPart, SourceContentPart, ImageContentPart, FileContentPart, Unstable_AudioContentPart, ToolCallContentPart, MessageStatus, ThreadUserContentPart, ThreadAssistantContentPart, ThreadSystemMessage, ThreadAssistantMessage, ThreadUserMessage, ThreadMessage, } from "./AssistantTypes";
|
2
|
+
export type { AppendMessage, TextContentPart, ReasoningContentPart, SourceContentPart, ImageContentPart, FileContentPart, Unstable_AudioContentPart, ToolCallContentPart, MessageStatus, ContentPartStatus, ToolCallContentPartStatus, ThreadUserContentPart, ThreadAssistantContentPart, ThreadSystemMessage, ThreadAssistantMessage, ThreadUserMessage, ThreadMessage, } from "./AssistantTypes";
|
3
3
|
export type { EmptyContentPartProps, EmptyContentPartComponent, TextContentPartProps, TextContentPartComponent, ReasoningContentPartProps, ReasoningContentPartComponent, SourceContentPartProps, SourceContentPartComponent, ImageContentPartProps, ImageContentPartComponent, FileContentPartProps, FileContentPartComponent, Unstable_AudioContentPartProps, Unstable_AudioContentPartComponent, ToolCallContentPartProps, ToolCallContentPartComponent, } from "./ContentPartComponentTypes";
|
4
4
|
export type { Unsubscribe } from "./Unsubscribe";
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EAGzB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAC9B,kCAAkC,EAClC,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
@@ -75,7 +75,7 @@ export function createStateHookForRuntime<TState>(
|
|
75
75
|
if (!store) return null;
|
76
76
|
|
77
77
|
// it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available
|
78
|
-
// eslint-
|
78
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
79
79
|
return useRuntimeStateInternal(store, selector);
|
80
80
|
}
|
81
81
|
|
@@ -73,13 +73,15 @@ export const makeAssistantVisible = <T extends ComponentType<any>>(
|
|
73
73
|
const componentRef = useRef<HTMLElement>(null);
|
74
74
|
|
75
75
|
const assistant = useAssistantRuntime();
|
76
|
+
|
77
|
+
const { clickable, editable } = config ?? {};
|
76
78
|
useEffect(() => {
|
77
79
|
return assistant.registerModelContextProvider({
|
78
80
|
getModelContext: () => {
|
79
81
|
return {
|
80
82
|
tools: {
|
81
|
-
...(
|
82
|
-
...(
|
83
|
+
...(clickable ? { click } : {}),
|
84
|
+
...(editable ? { edit } : {}),
|
83
85
|
},
|
84
86
|
system: !isNestedReadable // only pass content if this readable isn't nested in another readable
|
85
87
|
? componentRef.current?.outerHTML
|
@@ -87,7 +89,7 @@ export const makeAssistantVisible = <T extends ComponentType<any>>(
|
|
87
89
|
};
|
88
90
|
},
|
89
91
|
});
|
90
|
-
}, [
|
92
|
+
}, [isNestedReadable, assistant, clickable, editable]);
|
91
93
|
|
92
94
|
const ref = useComposedRefs(componentRef, outerRef);
|
93
95
|
|
@@ -14,7 +14,7 @@ export const useAssistantToolUI = (
|
|
14
14
|
) => {
|
15
15
|
const toolUIsStore = useToolUIsStore();
|
16
16
|
useEffect(() => {
|
17
|
-
if (!tool) return;
|
17
|
+
if (!tool?.toolName || !tool?.render) return;
|
18
18
|
return toolUIsStore.getState().setToolUI(tool.toolName, tool.render);
|
19
|
-
}, [toolUIsStore, tool?.toolName, tool?.render
|
19
|
+
}, [toolUIsStore, tool?.toolName, tool?.render]);
|
20
20
|
};
|
@@ -28,12 +28,7 @@ const useAssistantModalOpenState = ({
|
|
28
28
|
return threadRuntime.unstable_on("run-start", () => {
|
29
29
|
setOpen(true);
|
30
30
|
});
|
31
|
-
}, [
|
32
|
-
unstable_openOnRunStart,
|
33
|
-
setOpen,
|
34
|
-
threadRuntime,
|
35
|
-
!unstable_openOnRunStart,
|
36
|
-
]);
|
31
|
+
}, [unstable_openOnRunStart, setOpen, threadRuntime]);
|
37
32
|
|
38
33
|
return state;
|
39
34
|
};
|