@assistant-ui/react 0.11.8 → 0.11.10
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/AssistantApiContext.js +1 -1
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js +4 -2
- package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js +4 -2
- package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.js +4 -2
- package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js +4 -2
- package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js +8 -2
- package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +4 -2
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
- package/package.json +1 -1
- package/src/context/react/AssistantApiContext.tsx +2 -2
- package/src/legacy-runtime/hooks/AttachmentContext.ts +4 -4
- package/src/legacy-runtime/hooks/ComposerContext.ts +4 -4
- package/src/legacy-runtime/hooks/MessageContext.ts +4 -4
- package/src/legacy-runtime/hooks/MessagePartContext.ts +4 -2
- package/src/legacy-runtime/hooks/ThreadContext.ts +8 -4
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +6 -4
@@ -140,7 +140,7 @@ var extendApi = (api, api2) => {
|
|
140
140
|
var AssistantProvider = ({ api: api2, children }) => {
|
141
141
|
const api = useAssistantApi();
|
142
142
|
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
143
|
-
return /* @__PURE__ */ jsx(AssistantApiContext, { value: extendedApi, children: /* @__PURE__ */ jsx(ThreadViewportProvider, { children }) });
|
143
|
+
return /* @__PURE__ */ jsx(AssistantApiContext.Provider, { value: extendedApi, children: /* @__PURE__ */ jsx(ThreadViewportProvider, { children }) });
|
144
144
|
};
|
145
145
|
export {
|
146
146
|
AssistantProvider,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/AssistantApiContext.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { ToolUIApi, ToolUIState, ToolUIMeta } from \"../../client/types/ToolUI\";\nimport {\n MessageClientApi,\n MessageClientState,\n} from \"../../client/types/Message\";\nimport {\n ThreadListItemClientApi,\n ThreadListItemClientState,\n} from \"../../client/types/ThreadListItem\";\nimport {\n MessagePartClientApi,\n MessagePartClientState,\n} from \"../../client/types/Part\";\nimport { ThreadClientApi, ThreadClientState } from \"../../client/types/Thread\";\nimport {\n ComposerClientApi,\n ComposerClientState,\n} from \"../../client/types/Composer\";\nimport {\n AttachmentClientApi,\n AttachmentClientState,\n} from \"../../client/types/Attachment\";\nimport { Unsubscribe } from \"@assistant-ui/tap\";\nimport { ModelContextProvider } from \"../../model-context\";\nimport { AssistantRuntime } from \"../../legacy-runtime/runtime/AssistantRuntime\";\nimport {\n AssistantEvent,\n AssistantEventCallback,\n AssistantEventSelector,\n normalizeEventSelector,\n} from \"../../types/EventTypes\";\nimport {\n ThreadListClientApi,\n ThreadListClientState,\n} from \"../../client/types/ThreadList\";\nimport { ThreadViewportProvider } from \"../providers/ThreadViewportProvider\";\n\nexport type AssistantState = {\n readonly threads: ThreadListClientState;\n readonly toolUIs: ToolUIState;\n\n readonly threadListItem: ThreadListItemClientState;\n readonly thread: ThreadClientState;\n readonly composer: ComposerClientState;\n readonly message: MessageClientState;\n readonly part: MessagePartClientState;\n readonly attachment: AttachmentClientState;\n};\n\ntype AssistantApiField<\n TApi,\n TMeta extends { source: string | null; query: any },\n> = (() => TApi) & (TMeta | { source: null; query: Record<string, never> });\n\n// Meta types for each API method\ntype ThreadsMeta = {\n source: \"root\";\n query: Record<string, never>;\n};\n\ntype ThreadListItemMeta = {\n source: \"threads\";\n query:\n | { type: \"index\"; index: number; archived: boolean }\n | { type: \"main\" }\n | { type: \"id\"; id: string };\n};\n\ntype ThreadMeta = {\n source: \"threads\";\n query: { type: \"main\" };\n};\n\ntype ComposerMeta = {\n source: \"message\" | \"thread\";\n query: Record<string, never>;\n};\n\ntype MessageMeta = {\n source: \"thread\";\n query: { type: \"index\"; index: number };\n};\n\ntype PartMeta = {\n source: \"message\" | \"root\";\n query: { type: \"index\"; index: number } | Record<string, never>;\n};\n\ntype AttachmentMeta = {\n source: \"message\" | \"composer\";\n query: { type: \"index\"; index: number };\n};\n\nexport type AssistantApi = {\n threads: AssistantApiField<ThreadListClientApi, ThreadsMeta>;\n toolUIs: AssistantApiField<ToolUIApi, ToolUIMeta>;\n threadListItem: AssistantApiField<\n ThreadListItemClientApi,\n ThreadListItemMeta\n >;\n thread: AssistantApiField<ThreadClientApi, ThreadMeta>;\n composer: AssistantApiField<ComposerClientApi, ComposerMeta>;\n message: AssistantApiField<MessageClientApi, MessageMeta>;\n part: AssistantApiField<MessagePartClientApi, PartMeta>;\n attachment: AssistantApiField<AttachmentClientApi, AttachmentMeta>;\n\n subscribe(listener: () => void): Unsubscribe;\n flushSync(): void;\n\n on<TEvent extends AssistantEvent>(\n event: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n ): Unsubscribe;\n\n // temp\n registerModelContextProvider(provider: ModelContextProvider): void;\n /** @internal */\n __internal_getRuntime(): AssistantRuntime | null;\n};\n\nexport const createAssistantApiField = <\n TApi,\n TMeta extends { source: any; query: any },\n>(\n config: {\n get: () => TApi;\n } & (TMeta | { source: null; query: Record<string, never> }),\n): AssistantApiField<TApi, TMeta> => {\n const fn = config.get as AssistantApiField<TApi, TMeta>;\n fn.source = config.source;\n fn.query = config.query;\n return fn;\n};\n\nconst NO_OP_FN = () => () => {};\n\nconst AssistantApiContext = createContext<AssistantApi>({\n threads: createAssistantApiField({\n source: null,\n query: {},\n get: () => {\n throw new Error(\"Threads is only available inside <AssistantProvider />\");\n },\n }),\n toolUIs: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"ToolUIs is only available inside <AssistantProvider />\");\n },\n }),\n threadListItem: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"ThreadListItem is only available inside <AssistantProvider />\",\n );\n },\n }),\n thread: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"Thread is only available inside <AssistantProvider />\");\n },\n }),\n composer: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Composer is only available inside <AssistantProvider />\",\n );\n },\n }),\n message: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Message is only available inside <ThreadPrimitive.Messages />\",\n );\n },\n }),\n part: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Part is only available inside <MessagePrimitive.Parts />\",\n );\n },\n }),\n attachment: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />\",\n );\n },\n }),\n\n subscribe: NO_OP_FN,\n flushSync: NO_OP_FN,\n on: (selector) => {\n const { scope } = normalizeEventSelector(selector);\n throw new Error(`Event scope is not available in this component: ${scope}`);\n },\n\n registerModelContextProvider: () => {\n throw new Error(\n \"Registering model context providers is only available inside <AssistantProvider />\",\n );\n },\n __internal_getRuntime: () => {\n return null;\n },\n});\n\nexport const useAssistantApi = (): AssistantApi => {\n return useContext(AssistantApiContext);\n};\n\nconst mergeFns = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => void,\n fn2: (...args: TArgs) => void,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n fn1(...args);\n fn2(...args);\n };\n};\n\nconst mergeFnsWithUnsubscribe = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => Unsubscribe,\n fn2: (...args: TArgs) => Unsubscribe,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n const unsubscribe1 = fn1(...args);\n const unsubscribe2 = fn2(...args);\n\n return () => {\n unsubscribe1();\n unsubscribe2();\n };\n };\n};\n\nconst extendApi = (\n api: AssistantApi,\n api2: Partial<AssistantApi>,\n): AssistantApi => {\n const api2Subscribe = api2.subscribe;\n const api2FlushSync = api2.flushSync;\n return {\n ...api,\n ...api2,\n subscribe: mergeFnsWithUnsubscribe(\n api.subscribe,\n api2Subscribe ?? NO_OP_FN,\n ),\n flushSync: mergeFns(api.flushSync, api2FlushSync ?? NO_OP_FN),\n };\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<{ api: Partial<AssistantApi> }>\n> = ({ api: api2, children }) => {\n const api = useAssistantApi();\n const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);\n\n return (\n <AssistantApiContext value={extendedApi}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </AssistantApiContext>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AA2BP;AAAA,EAIE;AAAA,OACK;AAKP,SAAS,8BAA8B;AAwPjC;AAnKC,IAAM,0BAA0B,CAIrC,WAGmC;AACnC,QAAM,KAAK,OAAO;AAClB,KAAG,SAAS,OAAO;AACnB,KAAG,QAAQ,OAAO;AAClB,SAAO;AACT;AAEA,IAAM,WAAW,MAAM,MAAM;AAAC;AAE9B,IAAM,sBAA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M,UAAU,KAAK,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC;AAEnE,SACE,oBAAC,uBAAoB,OAAO,aAG1B,8BAAC,0BAAwB,UAAS,GACpC;AAEJ;","names":[]}
|
1
|
+
{"version":3,"sources":["../../../src/context/react/AssistantApiContext.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { ToolUIApi, ToolUIState, ToolUIMeta } from \"../../client/types/ToolUI\";\nimport {\n MessageClientApi,\n MessageClientState,\n} from \"../../client/types/Message\";\nimport {\n ThreadListItemClientApi,\n ThreadListItemClientState,\n} from \"../../client/types/ThreadListItem\";\nimport {\n MessagePartClientApi,\n MessagePartClientState,\n} from \"../../client/types/Part\";\nimport { ThreadClientApi, ThreadClientState } from \"../../client/types/Thread\";\nimport {\n ComposerClientApi,\n ComposerClientState,\n} from \"../../client/types/Composer\";\nimport {\n AttachmentClientApi,\n AttachmentClientState,\n} from \"../../client/types/Attachment\";\nimport { Unsubscribe } from \"@assistant-ui/tap\";\nimport { ModelContextProvider } from \"../../model-context\";\nimport { AssistantRuntime } from \"../../legacy-runtime/runtime/AssistantRuntime\";\nimport {\n AssistantEvent,\n AssistantEventCallback,\n AssistantEventSelector,\n normalizeEventSelector,\n} from \"../../types/EventTypes\";\nimport {\n ThreadListClientApi,\n ThreadListClientState,\n} from \"../../client/types/ThreadList\";\nimport { ThreadViewportProvider } from \"../providers/ThreadViewportProvider\";\n\nexport type AssistantState = {\n readonly threads: ThreadListClientState;\n readonly toolUIs: ToolUIState;\n\n readonly threadListItem: ThreadListItemClientState;\n readonly thread: ThreadClientState;\n readonly composer: ComposerClientState;\n readonly message: MessageClientState;\n readonly part: MessagePartClientState;\n readonly attachment: AttachmentClientState;\n};\n\ntype AssistantApiField<\n TApi,\n TMeta extends { source: string | null; query: any },\n> = (() => TApi) & (TMeta | { source: null; query: Record<string, never> });\n\n// Meta types for each API method\ntype ThreadsMeta = {\n source: \"root\";\n query: Record<string, never>;\n};\n\ntype ThreadListItemMeta = {\n source: \"threads\";\n query:\n | { type: \"index\"; index: number; archived: boolean }\n | { type: \"main\" }\n | { type: \"id\"; id: string };\n};\n\ntype ThreadMeta = {\n source: \"threads\";\n query: { type: \"main\" };\n};\n\ntype ComposerMeta = {\n source: \"message\" | \"thread\";\n query: Record<string, never>;\n};\n\ntype MessageMeta = {\n source: \"thread\";\n query: { type: \"index\"; index: number };\n};\n\ntype PartMeta = {\n source: \"message\" | \"root\";\n query: { type: \"index\"; index: number } | Record<string, never>;\n};\n\ntype AttachmentMeta = {\n source: \"message\" | \"composer\";\n query: { type: \"index\"; index: number };\n};\n\nexport type AssistantApi = {\n threads: AssistantApiField<ThreadListClientApi, ThreadsMeta>;\n toolUIs: AssistantApiField<ToolUIApi, ToolUIMeta>;\n threadListItem: AssistantApiField<\n ThreadListItemClientApi,\n ThreadListItemMeta\n >;\n thread: AssistantApiField<ThreadClientApi, ThreadMeta>;\n composer: AssistantApiField<ComposerClientApi, ComposerMeta>;\n message: AssistantApiField<MessageClientApi, MessageMeta>;\n part: AssistantApiField<MessagePartClientApi, PartMeta>;\n attachment: AssistantApiField<AttachmentClientApi, AttachmentMeta>;\n\n subscribe(listener: () => void): Unsubscribe;\n flushSync(): void;\n\n on<TEvent extends AssistantEvent>(\n event: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n ): Unsubscribe;\n\n // temp\n registerModelContextProvider(provider: ModelContextProvider): void;\n /** @internal */\n __internal_getRuntime(): AssistantRuntime | null;\n};\n\nexport const createAssistantApiField = <\n TApi,\n TMeta extends { source: any; query: any },\n>(\n config: {\n get: () => TApi;\n } & (TMeta | { source: null; query: Record<string, never> }),\n): AssistantApiField<TApi, TMeta> => {\n const fn = config.get as AssistantApiField<TApi, TMeta>;\n fn.source = config.source;\n fn.query = config.query;\n return fn;\n};\n\nconst NO_OP_FN = () => () => {};\n\nconst AssistantApiContext = createContext<AssistantApi>({\n threads: createAssistantApiField({\n source: null,\n query: {},\n get: () => {\n throw new Error(\"Threads is only available inside <AssistantProvider />\");\n },\n }),\n toolUIs: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"ToolUIs is only available inside <AssistantProvider />\");\n },\n }),\n threadListItem: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"ThreadListItem is only available inside <AssistantProvider />\",\n );\n },\n }),\n thread: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"Thread is only available inside <AssistantProvider />\");\n },\n }),\n composer: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Composer is only available inside <AssistantProvider />\",\n );\n },\n }),\n message: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Message is only available inside <ThreadPrimitive.Messages />\",\n );\n },\n }),\n part: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Part is only available inside <MessagePrimitive.Parts />\",\n );\n },\n }),\n attachment: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />\",\n );\n },\n }),\n\n subscribe: NO_OP_FN,\n flushSync: NO_OP_FN,\n on: (selector) => {\n const { scope } = normalizeEventSelector(selector);\n throw new Error(`Event scope is not available in this component: ${scope}`);\n },\n\n registerModelContextProvider: () => {\n throw new Error(\n \"Registering model context providers is only available inside <AssistantProvider />\",\n );\n },\n __internal_getRuntime: () => {\n return null;\n },\n});\n\nexport const useAssistantApi = (): AssistantApi => {\n return useContext(AssistantApiContext);\n};\n\nconst mergeFns = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => void,\n fn2: (...args: TArgs) => void,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n fn1(...args);\n fn2(...args);\n };\n};\n\nconst mergeFnsWithUnsubscribe = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => Unsubscribe,\n fn2: (...args: TArgs) => Unsubscribe,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n const unsubscribe1 = fn1(...args);\n const unsubscribe2 = fn2(...args);\n\n return () => {\n unsubscribe1();\n unsubscribe2();\n };\n };\n};\n\nconst extendApi = (\n api: AssistantApi,\n api2: Partial<AssistantApi>,\n): AssistantApi => {\n const api2Subscribe = api2.subscribe;\n const api2FlushSync = api2.flushSync;\n return {\n ...api,\n ...api2,\n subscribe: mergeFnsWithUnsubscribe(\n api.subscribe,\n api2Subscribe ?? NO_OP_FN,\n ),\n flushSync: mergeFns(api.flushSync, api2FlushSync ?? NO_OP_FN),\n };\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<{ api: Partial<AssistantApi> }>\n> = ({ api: api2, children }) => {\n const api = useAssistantApi();\n const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);\n\n return (\n <AssistantApiContext.Provider value={extendedApi}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </AssistantApiContext.Provider>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AA2BP;AAAA,EAIE;AAAA,OACK;AAKP,SAAS,8BAA8B;AAwPjC;AAnKC,IAAM,0BAA0B,CAIrC,WAGmC;AACnC,QAAM,KAAK,OAAO;AAClB,KAAG,SAAS,OAAO;AACnB,KAAG,QAAQ,OAAO;AAClB,SAAO;AACT;AAEA,IAAM,WAAW,MAAM,MAAM;AAAC;AAE9B,IAAM,sBAAsB,cAA4B;AAAA,EACtD,SAAS,wBAAwB;AAAA,IAC/B,QAAQ;AAAA,IACR,OAAO,CAAC;AAAA,IACR,KAAK,MAAM;AACT,Y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C,0BAAwB,UAAS,GACpC;AAEJ;","names":[]}
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
// src/legacy-runtime/hooks/AttachmentContext.ts
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
5
|
-
import { useAssistantApi } from "../../context/react/index.js";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react/index.js";
|
6
6
|
function useAttachmentRuntime(options) {
|
7
7
|
const api = useAssistantApi();
|
8
|
-
const runtime =
|
8
|
+
const runtime = useAssistantState(
|
9
|
+
() => api.attachment.source ? api.attachment().__internal_getRuntime() : null
|
10
|
+
);
|
9
11
|
if (!runtime && !options?.optional) {
|
10
12
|
throw new Error("AttachmentRuntime is not available");
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi } from \"../../context/react\";\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const api = useAssistantApi();\n const runtime = api.attachment.source
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.attachment.source ? api.attachment().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"AttachmentRuntime is not available\");\n }\n return runtime;\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"thread-composer\">;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"thread-composer\">;\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"edit-composer\">;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a message's ComposerPrimitive.Attachments component.\",\n );\n\n return attachmentRuntime as AttachmentRuntime<\"edit-composer\">;\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"message\">;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"message\">;\n}\n\nexport const useAttachment = createStateHookForRuntime(useAttachmentRuntime);\n\nexport const useThreadComposerAttachment = createStateHookForRuntime(\n useThreadComposerAttachmentRuntime,\n);\nexport const useEditComposerAttachment = createStateHookForRuntime(\n useEditComposerAttachmentRuntime,\n);\nexport const useMessageAttachment = createStateHookForRuntime(\n useMessageAttachmentRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,qBAAqB,SAER;AAC3B,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,WAAW,SAAS,IAAI,WAAW,EAAE,sBAAsB,IAAI;AAAA,EACrE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AAQO,SAAS,mCAAmC,SAEH;AAC9C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,iCAAiC,SAEH;AAC5C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQO,SAAS,4BAA4B,SAEJ;AACtC,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAEO,IAAM,gBAAgB,0BAA0B,oBAAoB;AAEpE,IAAM,8BAA8B;AAAA,EACzC;AACF;AACO,IAAM,4BAA4B;AAAA,EACvC;AACF;AACO,IAAM,uBAAuB;AAAA,EAClC;AACF;","names":[]}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
// src/legacy-runtime/hooks/ComposerContext.ts
|
4
|
-
import { useAssistantApi } from "../../context/react/index.js";
|
4
|
+
import { useAssistantApi, useAssistantState } from "../../context/react/index.js";
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
6
6
|
function useComposerRuntime(options) {
|
7
7
|
const api = useAssistantApi();
|
8
|
-
const runtime =
|
8
|
+
const runtime = useAssistantState(
|
9
|
+
() => api.composer.source ? api.composer().__internal_getRuntime() : null
|
10
|
+
);
|
9
11
|
if (!runtime && !options?.optional) {
|
10
12
|
throw new Error("ComposerRuntime is not available");
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n *\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n *\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n *\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const api = useAssistantApi();\n const runtime = api.composer.source
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n *\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n *\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n *\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.composer.source ? api.composer().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ComposerRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current composer state.\n *\n * This hook provides reactive access to the composer's state, including text content,\n * attachments, editing status, and send/cancel capabilities.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected composer state or the entire composer state if no selector provided\n *\n * @example\n * ```tsx\n * function ComposerStatus() {\n * const text = useComposer((state) => state.text);\n * const canSend = useComposer((state) => state.canSend);\n * const attachmentCount = useComposer((state) => state.attachments.length);\n *\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n * ```\n */\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,iBAAiB,yBAAyB;AAEnD,SAAS,iCAAiC;AA8CnC,SAAS,mBAAmB,SAER;AACzB,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,SAAS,SAAS,IAAI,SAAS,EAAE,sBAAsB,IAAI;AAAA,EACjE;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AACA,SAAO;AACT;AA4BO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
// src/legacy-runtime/hooks/MessageContext.ts
|
4
|
-
import { useAssistantApi } from "../../context/react/index.js";
|
4
|
+
import { useAssistantApi, useAssistantState } from "../../context/react/index.js";
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
6
6
|
function useMessageRuntime(options) {
|
7
7
|
const api = useAssistantApi();
|
8
|
-
const runtime =
|
8
|
+
const runtime = useAssistantState(
|
9
|
+
() => api.message.source ? api.message().__internal_getRuntime() : null
|
10
|
+
);
|
9
11
|
if (!runtime && !options?.optional) {
|
10
12
|
throw new Error("MessageRuntime is not available");
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessageRuntime } from \"../runtime/MessageRuntime\";\nimport { useAssistantApi } from \"../../context/react\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../runtime\";\n\n/**\n * Hook to access the MessageRuntime from the current context.\n *\n * The MessageRuntime provides access to message-level state and actions,\n * including message content, status, editing capabilities, and branching.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The MessageRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MessageActions() {\n * const runtime = useMessageRuntime();\n *\n * const handleReload = () => {\n * runtime.reload();\n * };\n *\n * const handleEdit = () => {\n * runtime.startEdit();\n * };\n *\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = api.message.source
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessageRuntime } from \"../runtime/MessageRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../runtime\";\n\n/**\n * Hook to access the MessageRuntime from the current context.\n *\n * The MessageRuntime provides access to message-level state and actions,\n * including message content, status, editing capabilities, and branching.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The MessageRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MessageActions() {\n * const runtime = useMessageRuntime();\n *\n * const handleReload = () => {\n * runtime.reload();\n * };\n *\n * const handleEdit = () => {\n * runtime.startEdit();\n * };\n *\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.message.source ? api.message().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessageRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current message state.\n *\n * This hook provides reactive access to the message's state, including content,\n * role, status, and other message-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected message state or the entire message state if no selector provided\n *\n * @example\n * ```tsx\n * function MessageContent() {\n * const role = useMessage((state) => state.role);\n * const content = useMessage((state) => state.content);\n * const isLoading = useMessage((state) => state.status.type === \"running\");\n *\n * return (\n * <div className={`message-${role}`}>\n * {isLoading ? \"Loading...\" : content.map(part => part.text).join(\"\")}\n * </div>\n * );\n * }\n * ```\n */\nexport const useMessage = createStateHookForRuntime(useMessageRuntime);\n\nconst useEditComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;\nexport const useEditComposer = createStateHookForRuntime(\n useEditComposerRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,iCAAiC;AAyCnC,SAAS,kBAAkB,SAE/B;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,QAAQ,SAAS,IAAI,QAAQ,EAAE,sBAAsB,IAAI;AAAA,EAC/D;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,SAAO;AACT;AA0BO,IAAM,aAAa,0BAA0B,iBAAiB;AAErE,IAAM,yBAAyB,CAAC,QAEE,kBAAkB,GAAG,GAAG,YAAY;AAC/D,IAAM,kBAAkB;AAAA,EAC7B;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MessagePartContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAInE,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"MessagePartContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAInE,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAc9B,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CAAmD,CAAC"}
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
// src/legacy-runtime/hooks/MessagePartContext.ts
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
5
|
-
import { useAssistantApi } from "../../context/react/index.js";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react/index.js";
|
6
6
|
function useMessagePartRuntime(options) {
|
7
7
|
const api = useAssistantApi();
|
8
|
-
const runtime =
|
8
|
+
const runtime = useAssistantState(
|
9
|
+
() => api.part.source ? api.part().__internal_getRuntime() : null
|
10
|
+
);
|
9
11
|
if (!runtime && !options?.optional) {
|
10
12
|
throw new Error("MessagePartRuntime is not available");
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessagePartRuntime } from \"../runtime/MessagePartRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi } from \"../../context/react\";\n\nexport function useMessagePartRuntime(options?: {\n optional?: false | undefined;\n}): MessagePartRuntime;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}): MessagePartRuntime | null;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = api.part.source ? api.part().__internal_getRuntime() : null;\n if (!runtime && !options?.optional) {\n throw new Error(\"MessagePartRuntime is not available\");\n }\n return runtime;\n}\n\nexport const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/MessagePartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { MessagePartRuntime } from \"../runtime/MessagePartRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useMessagePartRuntime(options?: {\n optional?: false | undefined;\n}): MessagePartRuntime;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}): MessagePartRuntime | null;\nexport function useMessagePartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.part.source ? api.part().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"MessagePartRuntime is not available\");\n }\n return runtime;\n}\n\nexport const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,sBAAsB,SAEnC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,KAAK,SAAS,IAAI,KAAK,EAAE,sBAAsB,IAAI;AAAA,EACzD;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACA,SAAO;AACT;AAEO,IAAM,iBAAiB,0BAA0B,qBAAqB;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,aAAa,CAAC;AAClB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,aAAa,GAAG,IAAI,CAAC;AAYzB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAA8C,CAAC;AAKrE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAAC;AACjB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,YAAY,GAAG,IAAI,CAAC"}
|
@@ -3,10 +3,16 @@
|
|
3
3
|
// src/legacy-runtime/hooks/ThreadContext.ts
|
4
4
|
import { useState } from "react";
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
6
|
-
import {
|
6
|
+
import {
|
7
|
+
useAssistantApi,
|
8
|
+
useAssistantEvent,
|
9
|
+
useAssistantState
|
10
|
+
} from "../../context/react/index.js";
|
7
11
|
function useThreadRuntime(options) {
|
8
12
|
const api = useAssistantApi();
|
9
|
-
const runtime =
|
13
|
+
const runtime = useAssistantState(
|
14
|
+
() => api.thread.source ? api.thread().__internal_getRuntime() : null
|
15
|
+
);
|
10
16
|
if (!runtime && !options?.optional) {
|
11
17
|
throw new Error("ThreadRuntime is not available");
|
12
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { ThreadRuntime } from \"../runtime/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../runtime\";\nimport {
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { ThreadRuntime } from \"../runtime/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../runtime\";\nimport {\n useAssistantApi,\n useAssistantEvent,\n useAssistantState,\n} from \"../../context/react\";\n\n/**\n * Hook to access the ThreadRuntime from the current context.\n *\n * The ThreadRuntime provides access to thread-level state and actions,\n * including message management, thread state, and composer functionality.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ThreadRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const runtime = useThreadRuntime();\n *\n * const handleSendMessage = (text: string) => {\n * runtime.append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n *\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n * ```\n */\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.thread.source ? api.thread().__internal_getRuntime() : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * Hook to access the current thread state.\n *\n * This hook provides reactive access to the thread's state, including messages,\n * running status, capabilities, and other thread-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected thread state or the entire thread state if no selector provided\n *\n * @example\n * ```tsx\n * function ThreadStatus() {\n * const isRunning = useThread((state) => state.isRunning);\n * const messageCount = useThread((state) => state.messages.length);\n *\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n * ```\n */\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useAssistantEvent(\"thread.model-context-update\", () => rerender({}));\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,gBAAgB;AAGzB,SAAS,iCAAiC;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA+BA,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,OAAO,SAAS,IAAI,OAAO,EAAE,sBAAsB,IAAI;AAAA,EAC7D;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO;AACT;AAqBO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,oBAAkB,+BAA+B,MAAM,SAAS,CAAC,CAAC,CAAC;AAEnE,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ThreadListItemContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,qBAAqB,CAAC;AAC1B,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,qBAAqB,GAAG,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"ThreadListItemContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,qBAAqB,CAAC;AAC1B,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,qBAAqB,GAAG,IAAI,CAAC;AAgBjC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC"}
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
// src/legacy-runtime/hooks/ThreadListItemContext.ts
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
5
|
-
import { useAssistantApi } from "../../context/react/index.js";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react/index.js";
|
6
6
|
function useThreadListItemRuntime(options) {
|
7
7
|
const api = useAssistantApi();
|
8
|
-
const runtime =
|
8
|
+
const runtime = useAssistantState(
|
9
|
+
() => api.threadListItem.source ? api.threadListItem().__internal_getRuntime() : null
|
10
|
+
);
|
9
11
|
if (!runtime && !options?.optional) {
|
10
12
|
throw new Error("ThreadListItemRuntime is not available");
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"sourcesContent":["\"use client\";\n\nimport { ThreadListItemRuntime } from \"../runtime/ThreadListItemRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi } from \"../../context/react\";\n\nexport function useThreadListItemRuntime(options?: {\n optional?: false | undefined;\n}): ThreadListItemRuntime;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadListItemRuntime | null;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = api.threadListItem.source\n
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"sourcesContent":["\"use client\";\n\nimport { ThreadListItemRuntime } from \"../runtime/ThreadListItemRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\nexport function useThreadListItemRuntime(options?: {\n optional?: false | undefined;\n}): ThreadListItemRuntime;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadListItemRuntime | null;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.threadListItem.source\n ? api.threadListItem().__internal_getRuntime()\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadListItemRuntime is not available\");\n }\n return runtime;\n}\n\nexport const useThreadListItem = createStateHookForRuntime(\n useThreadListItemRuntime,\n);\n"],"mappings":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAQ5C,SAAS,yBAAyB,SAEtC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,eAAe,SACf,IAAI,eAAe,EAAE,sBAAsB,IAC3C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACA,SAAO;AACT;AAEO,IAAM,oBAAoB;AAAA,EAC/B;AACF;","names":[]}
|
package/package.json
CHANGED
@@ -288,10 +288,10 @@ export const AssistantProvider: FC<
|
|
288
288
|
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
289
289
|
|
290
290
|
return (
|
291
|
-
<AssistantApiContext value={extendedApi}>
|
291
|
+
<AssistantApiContext.Provider value={extendedApi}>
|
292
292
|
{/* TODO temporarily allow accessing viewport state from outside the viewport */}
|
293
293
|
{/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
|
294
294
|
<ThreadViewportProvider>{children}</ThreadViewportProvider>
|
295
|
-
</AssistantApiContext>
|
295
|
+
</AssistantApiContext.Provider>
|
296
296
|
);
|
297
297
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { AttachmentRuntime } from "../runtime/AttachmentRuntime";
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
5
|
-
import { useAssistantApi } from "../../context/react";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react";
|
6
6
|
|
7
7
|
export function useAttachmentRuntime(options?: {
|
8
8
|
optional?: false | undefined;
|
@@ -14,9 +14,9 @@ export function useAttachmentRuntime(options?: {
|
|
14
14
|
optional?: boolean | undefined;
|
15
15
|
}): AttachmentRuntime | null {
|
16
16
|
const api = useAssistantApi();
|
17
|
-
const runtime =
|
18
|
-
? api.attachment().__internal_getRuntime()
|
19
|
-
|
17
|
+
const runtime = useAssistantState(() =>
|
18
|
+
api.attachment.source ? api.attachment().__internal_getRuntime() : null,
|
19
|
+
);
|
20
20
|
if (!runtime && !options?.optional) {
|
21
21
|
throw new Error("AttachmentRuntime is not available");
|
22
22
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
|
-
import { useAssistantApi } from "../../context/react";
|
3
|
+
import { useAssistantApi, useAssistantState } from "../../context/react";
|
4
4
|
import { ComposerRuntime } from "../runtime/ComposerRuntime";
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
6
6
|
|
@@ -52,9 +52,9 @@ export function useComposerRuntime(options?: {
|
|
52
52
|
optional?: boolean | undefined;
|
53
53
|
}): ComposerRuntime | null {
|
54
54
|
const api = useAssistantApi();
|
55
|
-
const runtime =
|
56
|
-
? api.composer().__internal_getRuntime()
|
57
|
-
|
55
|
+
const runtime = useAssistantState(() =>
|
56
|
+
api.composer.source ? api.composer().__internal_getRuntime() : null,
|
57
|
+
);
|
58
58
|
if (!runtime && !options?.optional) {
|
59
59
|
throw new Error("ComposerRuntime is not available");
|
60
60
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
import { MessageRuntime } from "../runtime/MessageRuntime";
|
4
|
-
import { useAssistantApi } from "../../context/react";
|
4
|
+
import { useAssistantApi, useAssistantState } from "../../context/react";
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
6
6
|
import { EditComposerRuntime } from "../runtime";
|
7
7
|
|
@@ -47,9 +47,9 @@ export function useMessageRuntime(options?: {
|
|
47
47
|
optional?: boolean | undefined;
|
48
48
|
}) {
|
49
49
|
const api = useAssistantApi();
|
50
|
-
const runtime =
|
51
|
-
? api.message().__internal_getRuntime()
|
52
|
-
|
50
|
+
const runtime = useAssistantState(() =>
|
51
|
+
api.message.source ? api.message().__internal_getRuntime() : null,
|
52
|
+
);
|
53
53
|
if (!runtime && !options?.optional) {
|
54
54
|
throw new Error("MessageRuntime is not available");
|
55
55
|
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { MessagePartRuntime } from "../runtime/MessagePartRuntime";
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
5
|
-
import { useAssistantApi } from "../../context/react";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react";
|
6
6
|
|
7
7
|
export function useMessagePartRuntime(options?: {
|
8
8
|
optional?: false | undefined;
|
@@ -14,7 +14,9 @@ export function useMessagePartRuntime(options?: {
|
|
14
14
|
optional?: boolean | undefined;
|
15
15
|
}) {
|
16
16
|
const api = useAssistantApi();
|
17
|
-
const runtime =
|
17
|
+
const runtime = useAssistantState(() =>
|
18
|
+
api.part.source ? api.part().__internal_getRuntime() : null,
|
19
|
+
);
|
18
20
|
if (!runtime && !options?.optional) {
|
19
21
|
throw new Error("MessagePartRuntime is not available");
|
20
22
|
}
|
@@ -5,7 +5,11 @@ import { ThreadRuntime } from "../runtime/ThreadRuntime";
|
|
5
5
|
import { ModelContext } from "../../model-context";
|
6
6
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
7
7
|
import { ThreadComposerRuntime } from "../runtime";
|
8
|
-
import {
|
8
|
+
import {
|
9
|
+
useAssistantApi,
|
10
|
+
useAssistantEvent,
|
11
|
+
useAssistantState,
|
12
|
+
} from "../../context/react";
|
9
13
|
|
10
14
|
/**
|
11
15
|
* Hook to access the ThreadRuntime from the current context.
|
@@ -38,9 +42,9 @@ export function useThreadRuntime(options?: {
|
|
38
42
|
}): ThreadRuntime | null;
|
39
43
|
export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
|
40
44
|
const api = useAssistantApi();
|
41
|
-
const runtime =
|
42
|
-
? api.thread().__internal_getRuntime()
|
43
|
-
|
45
|
+
const runtime = useAssistantState(() =>
|
46
|
+
api.thread.source ? api.thread().__internal_getRuntime() : null,
|
47
|
+
);
|
44
48
|
if (!runtime && !options?.optional) {
|
45
49
|
throw new Error("ThreadRuntime is not available");
|
46
50
|
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime";
|
4
4
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
5
|
-
import { useAssistantApi } from "../../context/react";
|
5
|
+
import { useAssistantApi, useAssistantState } from "../../context/react";
|
6
6
|
|
7
7
|
export function useThreadListItemRuntime(options?: {
|
8
8
|
optional?: false | undefined;
|
@@ -14,9 +14,11 @@ export function useThreadListItemRuntime(options?: {
|
|
14
14
|
optional?: boolean | undefined;
|
15
15
|
}) {
|
16
16
|
const api = useAssistantApi();
|
17
|
-
const runtime =
|
18
|
-
|
19
|
-
|
17
|
+
const runtime = useAssistantState(() =>
|
18
|
+
api.threadListItem.source
|
19
|
+
? api.threadListItem().__internal_getRuntime()
|
20
|
+
: null,
|
21
|
+
);
|
20
22
|
if (!runtime && !options?.optional) {
|
21
23
|
throw new Error("ThreadListItemRuntime is not available");
|
22
24
|
}
|