@assistant-ui/react 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. package/dist/{ModelConfigTypes-BF5HxVrH.d.mts → Thread-By2aBNAG.d.mts} +14 -2
  2. package/dist/{ModelConfigTypes-BF5HxVrH.d.ts → Thread-By2aBNAG.d.ts} +14 -2
  3. package/dist/{chunk-CY4TTHR7.mjs → chunk-SCWPIDP6.mjs} +8 -1
  4. package/dist/{chunk-CY4TTHR7.mjs.map → chunk-SCWPIDP6.mjs.map} +1 -1
  5. package/dist/experimental.d.mts +3 -38
  6. package/dist/experimental.d.ts +3 -38
  7. package/dist/experimental.js +17 -301
  8. package/dist/experimental.js.map +1 -1
  9. package/dist/experimental.mjs +1 -112
  10. package/dist/experimental.mjs.map +1 -1
  11. package/dist/index.d.mts +73 -5
  12. package/dist/index.d.ts +73 -5
  13. package/dist/index.js +297 -23
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +315 -13
  16. package/dist/index.mjs.map +1 -1
  17. package/package.json +5 -15
  18. package/dist/AssistantRuntime-BM_jVV3g.d.mts +0 -23
  19. package/dist/AssistantRuntime-CBMSAJqH.d.mts +0 -23
  20. package/dist/AssistantRuntime-C_BvM7ZT.d.ts +0 -23
  21. package/dist/AssistantRuntime-DELpXWfG.d.ts +0 -23
  22. package/dist/ModelConfigTypes-B9UY4zxv.d.mts +0 -55
  23. package/dist/ModelConfigTypes-B9UY4zxv.d.ts +0 -55
  24. package/dist/ModelConfigTypes-Cf3yjaDu.d.mts +0 -55
  25. package/dist/ModelConfigTypes-Cf3yjaDu.d.ts +0 -55
  26. package/dist/chunk-3XZUKECF.mjs +0 -207
  27. package/dist/chunk-3XZUKECF.mjs.map +0 -1
  28. package/dist/chunk-4DQ2CIAD.mjs +0 -69
  29. package/dist/chunk-4DQ2CIAD.mjs.map +0 -1
  30. package/dist/chunk-5YONSDN4.mjs +0 -200
  31. package/dist/chunk-5YONSDN4.mjs.map +0 -1
  32. package/dist/chunk-DKAWDNW5.mjs +0 -22
  33. package/dist/chunk-DKAWDNW5.mjs.map +0 -1
  34. package/dist/chunk-GQKH2ADD.mjs +0 -165
  35. package/dist/chunk-GQKH2ADD.mjs.map +0 -1
  36. package/dist/chunk-J5LGTIGS.mjs +0 -10
  37. package/dist/chunk-J5LGTIGS.mjs.map +0 -1
  38. package/dist/chunk-X4HBDEFP.mjs +0 -30
  39. package/dist/chunk-X4HBDEFP.mjs.map +0 -1
  40. package/dist/internal-dlLjX30u.d.mts +0 -75
  41. package/dist/internal-dlLjX30u.d.ts +0 -75
  42. package/dist/internal.d.mts +0 -25
  43. package/dist/internal.d.ts +0 -25
  44. package/dist/internal.js +0 -225
  45. package/dist/internal.js.map +0 -1
  46. package/dist/internal.mjs +0 -12
  47. package/dist/internal.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { ReactNode } from 'react';
2
1
  import { z } from 'zod';
2
+ import { ReactNode } from 'react';
3
3
 
4
4
  type TextContentPart = {
5
5
  type: "text";
@@ -52,4 +52,16 @@ type ModelConfig = {
52
52
  };
53
53
  type ModelConfigProvider = () => ModelConfig;
54
54
 
55
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfig as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ModelConfigProvider as b, ThreadMessage as c, AppendMessage as d, AssistantMessage as e, UserMessage as f, UserContentPart as g, AppendContentPart as h };
55
+ type Unsubscribe = () => void;
56
+
57
+ type ThreadState = {
58
+ messages: readonly ThreadMessage[];
59
+ isRunning: boolean;
60
+ getBranches: (messageId: string) => readonly string[];
61
+ switchToBranch: (branchId: string) => void;
62
+ append: (message: AppendMessage) => void;
63
+ startRun: (parentId: string | null) => void;
64
+ cancelRun: () => void;
65
+ };
66
+
67
+ export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j };
@@ -1,5 +1,5 @@
1
- import { ReactNode } from 'react';
2
1
  import { z } from 'zod';
2
+ import { ReactNode } from 'react';
3
3
 
4
4
  type TextContentPart = {
5
5
  type: "text";
@@ -52,4 +52,16 @@ type ModelConfig = {
52
52
  };
53
53
  type ModelConfigProvider = () => ModelConfig;
54
54
 
55
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfig as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ModelConfigProvider as b, ThreadMessage as c, AppendMessage as d, AssistantMessage as e, UserMessage as f, UserContentPart as g, AppendContentPart as h };
55
+ type Unsubscribe = () => void;
56
+
57
+ type ThreadState = {
58
+ messages: readonly ThreadMessage[];
59
+ isRunning: boolean;
60
+ getBranches: (messageId: string) => readonly string[];
61
+ switchToBranch: (branchId: string) => void;
62
+ append: (message: AppendMessage) => void;
63
+ startRun: (parentId: string | null) => void;
64
+ cancelRun: () => void;
65
+ };
66
+
67
+ export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j };
@@ -1,3 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
1
7
  // src/context/MessageContext.ts
2
8
  import { createContext, useContext } from "react";
3
9
  var MessageContext = createContext(null);
@@ -63,6 +69,7 @@ var useAssistantContext = () => {
63
69
  };
64
70
 
65
71
  export {
72
+ __export,
66
73
  MessageContext,
67
74
  useMessageContext,
68
75
  ThreadContext,
@@ -73,4 +80,4 @@ export {
73
80
  AssistantContext,
74
81
  useAssistantContext
75
82
  };
76
- //# sourceMappingURL=chunk-CY4TTHR7.mjs.map
83
+ //# sourceMappingURL=chunk-SCWPIDP6.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/ContentPartContext.ts","../src/context/AssistantContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\"This component must be used within an AssistantRuntimeProvider.\");\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n"],"mappings":";AAAA,SAAS,eAAe,kBAAkB;AAUnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAYnC,IAAM,gBAAgBD,eAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,UAAUC,YAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iEAAiE;AACnF,SAAO;AACT;;;ACnBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AACxE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;ACxBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,qBAAqBD;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,UAAUC,YAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,mBAAmBD;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAUC,YAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;","names":["createContext","useContext","useContext","useContext","createContext","useContext","createContext","useContext"]}
1
+ {"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/ContentPartContext.ts","../src/context/AssistantContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\"This component must be used within an AssistantRuntimeProvider.\");\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n"],"mappings":";;;;;;;AAAA,SAAS,eAAe,kBAAkB;AAUnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAYnC,IAAM,gBAAgBD,eAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,UAAUC,YAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iEAAiE;AACnF,SAAO;AACT;;;ACnBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AACxE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;ACxBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,qBAAqBD;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,UAAUC,YAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACnBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,mBAAmBD;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAUC,YAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;","names":["createContext","useContext","useContext","useContext","createContext","useContext","createContext","useContext"]}
@@ -1,6 +1,5 @@
1
- import { h as ModelConfigProvider, b as ThreadMessage, M as ModelConfig, e as AssistantContentPart, d as AppendMessage } from './ModelConfigTypes-B9UY4zxv.mjs';
2
- export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './ModelConfigTypes-B9UY4zxv.mjs';
3
- import { U as Unsubscribe, a as ThreadState, A as AssistantRuntime } from './AssistantRuntime-CBMSAJqH.mjs';
1
+ import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, b as ThreadState } from './Thread-By2aBNAG.mjs';
2
+ export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './Thread-By2aBNAG.mjs';
4
3
  import { ReactNode } from 'react';
5
4
  import { UseBoundStore, StoreApi } from 'zustand';
6
5
  import 'zod';
@@ -81,40 +80,6 @@ type ContentPartContextValue = {
81
80
  };
82
81
  declare const useContentPartContext: () => ContentPartContextValue;
83
82
 
84
- type ChatModelRunResult = {
85
- content: AssistantContentPart[];
86
- };
87
- type ChatModelRunOptions = {
88
- messages: ThreadMessage[];
89
- abortSignal: AbortSignal;
90
- config: ModelConfig;
91
- onUpdate: (result: ChatModelRunResult) => void;
92
- };
93
- type ChatModelAdapter = {
94
- run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
95
- };
96
-
97
- declare class LocalRuntime implements AssistantRuntime {
98
- adapter: ChatModelAdapter;
99
- private _subscriptions;
100
- private _configProviders;
101
- private abortController;
102
- private repository;
103
- get messages(): ThreadMessage[];
104
- get isRunning(): boolean;
105
- constructor(adapter: ChatModelAdapter);
106
- getBranches(messageId: string): string[];
107
- switchToBranch(branchId: string): void;
108
- append(message: AppendMessage): Promise<void>;
109
- startRun(parentId: string | null): Promise<void>;
110
- cancelRun(): void;
111
- private notifySubscribers;
112
- subscribe(callback: () => void): Unsubscribe;
113
- registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
114
- }
115
-
116
- declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
117
-
118
83
  declare const useAssistantInstructions: (instruction: string) => void;
119
84
 
120
- export { type AssistantContextValue, type AssistantModelConfigState, type ChatModelAdapter, type ChatModelRunOptions, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useLocalRuntime, useMessageContext, useThreadContext };
85
+ export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -1,6 +1,5 @@
1
- import { h as ModelConfigProvider, b as ThreadMessage, M as ModelConfig, e as AssistantContentPart, d as AppendMessage } from './ModelConfigTypes-B9UY4zxv.js';
2
- export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './ModelConfigTypes-B9UY4zxv.js';
3
- import { U as Unsubscribe, a as ThreadState, A as AssistantRuntime } from './AssistantRuntime-C_BvM7ZT.js';
1
+ import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, b as ThreadState } from './Thread-By2aBNAG.js';
2
+ export { I as ImageContentPart, a as ToolCallContentPart, U as UIContentPart } from './Thread-By2aBNAG.js';
4
3
  import { ReactNode } from 'react';
5
4
  import { UseBoundStore, StoreApi } from 'zustand';
6
5
  import 'zod';
@@ -81,40 +80,6 @@ type ContentPartContextValue = {
81
80
  };
82
81
  declare const useContentPartContext: () => ContentPartContextValue;
83
82
 
84
- type ChatModelRunResult = {
85
- content: AssistantContentPart[];
86
- };
87
- type ChatModelRunOptions = {
88
- messages: ThreadMessage[];
89
- abortSignal: AbortSignal;
90
- config: ModelConfig;
91
- onUpdate: (result: ChatModelRunResult) => void;
92
- };
93
- type ChatModelAdapter = {
94
- run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
95
- };
96
-
97
- declare class LocalRuntime implements AssistantRuntime {
98
- adapter: ChatModelAdapter;
99
- private _subscriptions;
100
- private _configProviders;
101
- private abortController;
102
- private repository;
103
- get messages(): ThreadMessage[];
104
- get isRunning(): boolean;
105
- constructor(adapter: ChatModelAdapter);
106
- getBranches(messageId: string): string[];
107
- switchToBranch(branchId: string): void;
108
- append(message: AppendMessage): Promise<void>;
109
- startRun(parentId: string | null): Promise<void>;
110
- cancelRun(): void;
111
- private notifySubscribers;
112
- subscribe(callback: () => void): Unsubscribe;
113
- registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
114
- }
115
-
116
- declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
117
-
118
83
  declare const useAssistantInstructions: (instruction: string) => void;
119
84
 
120
- export { type AssistantContextValue, type AssistantModelConfigState, type ChatModelAdapter, type ChatModelRunOptions, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useLocalRuntime, useMessageContext, useThreadContext };
85
+ export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, useAssistantContext, useAssistantInstructions, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -24,301 +24,18 @@ __export(experimental_exports, {
24
24
  useAssistantInstructions: () => useAssistantInstructions,
25
25
  useComposerContext: () => useComposerContext,
26
26
  useContentPartContext: () => useContentPartContext,
27
- useLocalRuntime: () => useLocalRuntime,
28
27
  useMessageContext: () => useMessageContext,
29
28
  useThreadContext: () => useThreadContext
30
29
  });
31
30
  module.exports = __toCommonJS(experimental_exports);
32
31
 
33
- // src/runtime/local/useLocalRuntime.tsx
34
- var import_react = require("react");
35
-
36
- // src/utils/ModelConfigTypes.ts
37
- var mergeModelConfigs = (configs) => {
38
- return configs.reduce((acc, config) => {
39
- if (config.system) {
40
- if (acc.system) {
41
- acc.system += `
42
-
43
- ${config.system}`;
44
- } else {
45
- acc.system = config.system;
46
- }
47
- }
48
- if (config.tools) {
49
- acc.tools = { ...acc.tools, ...config.tools };
50
- }
51
- return acc;
52
- }, {});
53
- };
54
-
55
- // src/runtime/utils/idUtils.tsx
56
- var import_non_secure = require("nanoid/non-secure");
57
- var generateId = (0, import_non_secure.customAlphabet)(
58
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
59
- 7
60
- );
61
- var optimisticPrefix = "__optimistic__";
62
- var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
63
-
64
- // src/runtime/utils/MessageRepository.tsx
65
- var findHead = (message) => {
66
- if (message.next) return findHead(message.next);
67
- return message;
68
- };
69
- var MessageRepository = class {
70
- messages = /* @__PURE__ */ new Map();
71
- // message_id -> item
72
- head = null;
73
- root = {
74
- children: []
75
- };
76
- performOp(newParent, child, operation) {
77
- const parentOrRoot = child.prev ?? this.root;
78
- const newParentOrRoot = newParent ?? this.root;
79
- if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
80
- if (operation !== "link") {
81
- parentOrRoot.children = parentOrRoot.children.filter(
82
- (m) => m !== child.current.id
83
- );
84
- if (child.prev?.next === child) {
85
- const fallbackId = child.prev.children.at(-1);
86
- const fallback = fallbackId ? this.messages.get(fallbackId) : null;
87
- if (fallback === void 0) {
88
- throw new Error(
89
- "MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
90
- );
91
- }
92
- child.prev.next = fallback;
93
- }
94
- }
95
- if (operation !== "cut") {
96
- newParentOrRoot.children = [
97
- ...newParentOrRoot.children,
98
- child.current.id
99
- ];
100
- if (newParent && (findHead(child) === this.head || newParent.next === null)) {
101
- newParent.next = child;
102
- }
103
- child.prev = newParent;
104
- }
105
- }
106
- getMessages() {
107
- const messages = new Array(this.head?.level ?? 0);
108
- for (let current = this.head; current; current = current.prev) {
109
- messages[current.level] = current.current;
110
- }
111
- return messages;
112
- }
113
- addOrUpdateMessage(parentId, message) {
114
- const existingItem = this.messages.get(message.id);
115
- const prev = parentId ? this.messages.get(parentId) : null;
116
- if (prev === void 0)
117
- throw new Error(
118
- "MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
119
- );
120
- if (existingItem) {
121
- existingItem.current = message;
122
- this.performOp(prev, existingItem, "relink");
123
- return;
124
- }
125
- const newItem = {
126
- prev,
127
- current: message,
128
- next: null,
129
- children: [],
130
- level: prev ? prev.level + 1 : 0
131
- };
132
- this.messages.set(message.id, newItem);
133
- this.performOp(prev, newItem, "link");
134
- if (this.head === prev) {
135
- this.head = newItem;
136
- }
137
- }
138
- appendOptimisticMessage(parentId, message) {
139
- let optimisticId;
140
- do {
141
- optimisticId = generateOptimisticId();
142
- } while (this.messages.has(optimisticId));
143
- this.addOrUpdateMessage(parentId, {
144
- ...message,
145
- id: optimisticId,
146
- createdAt: /* @__PURE__ */ new Date(),
147
- ...message.role === "assistant" ? { status: "in_progress" } : void 0
148
- });
149
- return optimisticId;
150
- }
151
- deleteMessage(messageId, replacementId) {
152
- const message = this.messages.get(messageId);
153
- if (!message)
154
- throw new Error(
155
- "MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
156
- );
157
- const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
158
- if (replacement === void 0)
159
- throw new Error(
160
- "MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
161
- );
162
- for (const child of message.children) {
163
- const childMessage = this.messages.get(child);
164
- if (!childMessage)
165
- throw new Error(
166
- "MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
167
- );
168
- this.performOp(replacement, childMessage, "relink");
169
- }
170
- this.performOp(null, message, "cut");
171
- this.messages.delete(messageId);
172
- if (this.head === message) {
173
- this.head = replacement ? findHead(replacement) : null;
174
- }
175
- }
176
- getBranches(messageId) {
177
- const message = this.messages.get(messageId);
178
- if (!message)
179
- throw new Error(
180
- "MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
181
- );
182
- const { children } = message.prev ?? this.root;
183
- return children;
184
- }
185
- switchToBranch(messageId) {
186
- const message = this.messages.get(messageId);
187
- if (!message)
188
- throw new Error(
189
- "MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
190
- );
191
- if (message.prev) {
192
- message.prev.next = message;
193
- }
194
- this.head = findHead(message);
195
- }
196
- resetHead(messageId) {
197
- if (messageId === null) {
198
- this.head = null;
199
- return;
200
- }
201
- const message = this.messages.get(messageId);
202
- if (!message)
203
- throw new Error(
204
- "MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
205
- );
206
- this.head = message;
207
- for (let current = message; current; current = current.prev) {
208
- if (current.prev) {
209
- current.prev.next = current;
210
- }
211
- }
212
- }
213
- };
214
-
215
- // src/runtime/local/LocalRuntime.tsx
216
- var LocalRuntime = class {
217
- constructor(adapter) {
218
- this.adapter = adapter;
219
- }
220
- _subscriptions = /* @__PURE__ */ new Set();
221
- _configProviders = /* @__PURE__ */ new Set();
222
- abortController = null;
223
- repository = new MessageRepository();
224
- get messages() {
225
- return this.repository.getMessages();
226
- }
227
- get isRunning() {
228
- return this.abortController != null;
229
- }
230
- getBranches(messageId) {
231
- return this.repository.getBranches(messageId);
232
- }
233
- switchToBranch(branchId) {
234
- this.repository.switchToBranch(branchId);
235
- this.notifySubscribers();
236
- }
237
- async append(message) {
238
- const userMessageId = generateId();
239
- const userMessage = {
240
- id: userMessageId,
241
- role: "user",
242
- content: message.content,
243
- createdAt: /* @__PURE__ */ new Date()
244
- };
245
- this.repository.addOrUpdateMessage(message.parentId, userMessage);
246
- await this.startRun(userMessageId);
247
- }
248
- async startRun(parentId) {
249
- const id = generateId();
250
- this.repository.resetHead(parentId);
251
- const messages = this.repository.getMessages();
252
- const message = {
253
- id,
254
- role: "assistant",
255
- status: "in_progress",
256
- content: [{ type: "text", text: "" }],
257
- createdAt: /* @__PURE__ */ new Date()
258
- };
259
- this.repository.addOrUpdateMessage(parentId, { ...message });
260
- this.abortController?.abort();
261
- this.abortController = new AbortController();
262
- this.notifySubscribers();
263
- try {
264
- const updateHandler = ({ content }) => {
265
- message.content = content;
266
- this.repository.addOrUpdateMessage(parentId, { ...message });
267
- this.notifySubscribers();
268
- };
269
- const result = await this.adapter.run({
270
- messages,
271
- abortSignal: this.abortController.signal,
272
- config: mergeModelConfigs([...this._configProviders].map((p) => p())),
273
- onUpdate: updateHandler
274
- });
275
- updateHandler(result);
276
- message.status = "done";
277
- this.repository.addOrUpdateMessage(parentId, { ...message });
278
- } catch (e) {
279
- message.status = "error";
280
- this.repository.addOrUpdateMessage(parentId, { ...message });
281
- console.error(e);
282
- } finally {
283
- this.abortController = null;
284
- this.notifySubscribers();
285
- }
286
- }
287
- cancelRun() {
288
- if (!this.abortController) return;
289
- this.abortController.abort();
290
- this.abortController = null;
291
- this.notifySubscribers();
292
- }
293
- notifySubscribers() {
294
- for (const callback of this._subscriptions) callback();
295
- }
296
- subscribe(callback) {
297
- this._subscriptions.add(callback);
298
- return () => this._subscriptions.delete(callback);
299
- }
300
- registerModelConfigProvider(provider) {
301
- this._configProviders.add(provider);
302
- return () => this._configProviders.delete(provider);
303
- }
304
- };
305
-
306
- // src/runtime/local/useLocalRuntime.tsx
307
- var useLocalRuntime = (adapter) => {
308
- const [runtime] = (0, import_react.useState)(() => new LocalRuntime(adapter));
309
- (0, import_react.useInsertionEffect)(() => {
310
- runtime.adapter = adapter;
311
- });
312
- return runtime;
313
- };
314
-
315
32
  // src/context/AssistantContext.ts
316
- var import_react2 = require("react");
317
- var AssistantContext = (0, import_react2.createContext)(
33
+ var import_react = require("react");
34
+ var AssistantContext = (0, import_react.createContext)(
318
35
  null
319
36
  );
320
37
  var useAssistantContext = () => {
321
- const context = (0, import_react2.useContext)(AssistantContext);
38
+ const context = (0, import_react.useContext)(AssistantContext);
322
39
  if (!context)
323
40
  throw new Error(
324
41
  "This component must be used within an AssistantRuntimeProvider."
@@ -327,23 +44,23 @@ var useAssistantContext = () => {
327
44
  };
328
45
 
329
46
  // src/context/ThreadContext.ts
330
- var import_react3 = require("react");
331
- var ThreadContext = (0, import_react3.createContext)(null);
47
+ var import_react2 = require("react");
48
+ var ThreadContext = (0, import_react2.createContext)(null);
332
49
  var useThreadContext = () => {
333
- const context = (0, import_react3.useContext)(ThreadContext);
50
+ const context = (0, import_react2.useContext)(ThreadContext);
334
51
  if (!context)
335
52
  throw new Error("This component must be used within an AssistantRuntimeProvider.");
336
53
  return context;
337
54
  };
338
55
 
339
56
  // src/context/ComposerContext.ts
340
- var import_react5 = require("react");
57
+ var import_react4 = require("react");
341
58
 
342
59
  // src/context/MessageContext.ts
343
- var import_react4 = require("react");
344
- var MessageContext = (0, import_react4.createContext)(null);
60
+ var import_react3 = require("react");
61
+ var MessageContext = (0, import_react3.createContext)(null);
345
62
  var useMessageContext = () => {
346
- const context = (0, import_react4.useContext)(MessageContext);
63
+ const context = (0, import_react3.useContext)(MessageContext);
347
64
  if (!context)
348
65
  throw new Error(
349
66
  "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
@@ -354,8 +71,8 @@ var useMessageContext = () => {
354
71
  // src/context/ComposerContext.ts
355
72
  var useComposerContext = () => {
356
73
  const { useComposer } = useThreadContext();
357
- const { useComposer: useEditComposer } = (0, import_react5.useContext)(MessageContext) ?? {};
358
- return (0, import_react5.useMemo)(
74
+ const { useComposer: useEditComposer } = (0, import_react4.useContext)(MessageContext) ?? {};
75
+ return (0, import_react4.useMemo)(
359
76
  () => ({
360
77
  useComposer: useEditComposer ?? useComposer,
361
78
  type: useEditComposer ? "edit" : "new"
@@ -365,12 +82,12 @@ var useComposerContext = () => {
365
82
  };
366
83
 
367
84
  // src/context/ContentPartContext.ts
368
- var import_react6 = require("react");
369
- var ContentPartContext = (0, import_react6.createContext)(
85
+ var import_react5 = require("react");
86
+ var ContentPartContext = (0, import_react5.createContext)(
370
87
  null
371
88
  );
372
89
  var useContentPartContext = () => {
373
- const context = (0, import_react6.useContext)(ContentPartContext);
90
+ const context = (0, import_react5.useContext)(ContentPartContext);
374
91
  if (!context)
375
92
  throw new Error(
376
93
  "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
@@ -379,13 +96,13 @@ var useContentPartContext = () => {
379
96
  };
380
97
 
381
98
  // src/model-config/useAssistantInstructions.tsx
382
- var import_react7 = require("react");
99
+ var import_react6 = require("react");
383
100
  var useAssistantInstructions = (instruction) => {
384
101
  const { useModelConfig } = useAssistantContext();
385
102
  const addContextProvider = useModelConfig(
386
103
  (s) => s.registerModelConfigProvider
387
104
  );
388
- (0, import_react7.useEffect)(
105
+ (0, import_react6.useEffect)(
389
106
  () => addContextProvider(() => {
390
107
  return {
391
108
  system: instruction
@@ -400,7 +117,6 @@ var useAssistantInstructions = (instruction) => {
400
117
  useAssistantInstructions,
401
118
  useComposerContext,
402
119
  useContentPartContext,
403
- useLocalRuntime,
404
120
  useMessageContext,
405
121
  useThreadContext
406
122
  });