@assistant-ui/react 0.7.5 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/ContentPartRuntime.d.ts +3 -3
- package/dist/api/ContentPartRuntime.d.ts.map +1 -1
- package/dist/api/ContentPartRuntime.js +7 -2
- package/dist/api/ContentPartRuntime.js.map +1 -1
- package/dist/api/ContentPartRuntime.mjs +7 -2
- package/dist/api/ContentPartRuntime.mjs.map +1 -1
- package/dist/context/providers/TextContentPartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextContentPartProvider.js +12 -4
- package/dist/context/providers/TextContentPartProvider.js.map +1 -1
- package/dist/context/providers/TextContentPartProvider.mjs +12 -4
- package/dist/context/providers/TextContentPartProvider.mjs.map +1 -1
- package/dist/ui/thread-config.d.ts.map +1 -1
- package/dist/ui/thread-config.js +8 -1
- package/dist/ui/thread-config.js.map +1 -1
- package/dist/ui/thread-config.mjs +8 -1
- package/dist/ui/thread-config.mjs.map +1 -1
- package/package.json +7 -7
- package/src/api/ContentPartRuntime.ts +11 -5
- package/src/context/providers/TextContentPartProvider.tsx +14 -4
- package/src/ui/thread-config.tsx +16 -7
@@ -20,10 +20,10 @@ export type ContentPartRuntime = {
|
|
20
20
|
};
|
21
21
|
export declare class ContentPartRuntimeImpl implements ContentPartRuntime {
|
22
22
|
private contentBinding;
|
23
|
-
private messageApi
|
24
|
-
private threadApi
|
23
|
+
private messageApi?;
|
24
|
+
private threadApi?;
|
25
25
|
get path(): ContentPartRuntimePath;
|
26
|
-
constructor(contentBinding: ContentPartSnapshotBinding, messageApi
|
26
|
+
constructor(contentBinding: ContentPartSnapshotBinding, messageApi?: MessageStateBinding | undefined, threadApi?: ThreadRuntimeCoreBinding | undefined);
|
27
27
|
getState(): ContentPartState;
|
28
28
|
addToolResult(result: any): void;
|
29
29
|
subscribe(callback: () => void): Unsubscribe;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ContentPartRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ContentPartRuntime.ts"],"names":[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AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,MAAM,gBAAgB,GAAG,CAC3B,qBAAqB,GACrB,0BAA0B,CAC7B,GAAG;IACF,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,yBAAyB,CAAC;CAChE,CAAC;AAEF,KAAK,0BAA0B,GAAG,qBAAqB,CACrD,gBAAgB,EAChB,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IAEjC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,IAAI,gBAAgB,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;CAC9C,CAAC;AAEF,qBAAa,sBAAuB,YAAW,kBAAkB;IAM7D,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,SAAS,CAAC;IAPpB,IAAW,IAAI,2BAEd;gBAGS,cAAc,EAAE,0BAA0B,EAC1C,UAAU,CAAC,EAAE,mBAAmB,YAAA,EAChC,SAAS,CAAC,EAAE,wBAAwB,YAAA;IAGvC,QAAQ;IAIR,aAAa,CAAC,MAAM,EAAE,GAAG;IA2BzB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;CAGtC"}
|
@@ -36,12 +36,17 @@ var ContentPartRuntimeImpl = class {
|
|
36
36
|
return this.contentBinding.getState();
|
37
37
|
}
|
38
38
|
addToolResult(result) {
|
39
|
-
const message = this.messageApi.getState();
|
40
|
-
if (!message) throw new Error("Message is not available");
|
41
39
|
const state = this.contentBinding.getState();
|
42
40
|
if (!state) throw new Error("Content part is not available");
|
43
41
|
if (state.type !== "tool-call")
|
44
42
|
throw new Error("Tried to add tool result to non-tool content part");
|
43
|
+
if (!this.messageApi)
|
44
|
+
throw new Error(
|
45
|
+
"Message API is not available. This is likely a bug in assistant-ui."
|
46
|
+
);
|
47
|
+
if (!this.threadApi) throw new Error("Thread API is not available");
|
48
|
+
const message = this.messageApi.getState();
|
49
|
+
if (!message) throw new Error("Message is not available");
|
45
50
|
const toolName = state.toolName;
|
46
51
|
const toolCallId = state.toolCallId;
|
47
52
|
this.threadApi.getState().addToolResult({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi
|
1
|
+
{"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {}\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Content part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool content part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EARH,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAQO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAa;AAChC,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
|
@@ -12,12 +12,17 @@ var ContentPartRuntimeImpl = class {
|
|
12
12
|
return this.contentBinding.getState();
|
13
13
|
}
|
14
14
|
addToolResult(result) {
|
15
|
-
const message = this.messageApi.getState();
|
16
|
-
if (!message) throw new Error("Message is not available");
|
17
15
|
const state = this.contentBinding.getState();
|
18
16
|
if (!state) throw new Error("Content part is not available");
|
19
17
|
if (state.type !== "tool-call")
|
20
18
|
throw new Error("Tried to add tool result to non-tool content part");
|
19
|
+
if (!this.messageApi)
|
20
|
+
throw new Error(
|
21
|
+
"Message API is not available. This is likely a bug in assistant-ui."
|
22
|
+
);
|
23
|
+
if (!this.threadApi) throw new Error("Thread API is not available");
|
24
|
+
const message = this.messageApi.getState();
|
25
|
+
if (!message) throw new Error("Message is not available");
|
21
26
|
const toolName = state.toolName;
|
22
27
|
const toolCallId = state.toolCallId;
|
23
28
|
this.threadApi.getState().addToolResult({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi
|
1
|
+
{"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {}\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Content part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool content part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";AAoCO,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EARH,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAQO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAa;AAChC,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TextContentPartProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAcnD,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACjC,CAAC,CAAC;CACJ;AAUD,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,
|
1
|
+
{"version":3,"file":"TextContentPartProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAcnD,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACjC,CAAC,CAAC;CACJ;AAUD,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAuDrE,CAAC"}
|
@@ -42,15 +42,23 @@ var TextContentPartProvider = ({
|
|
42
42
|
isRunning
|
43
43
|
}) => {
|
44
44
|
const [context] = (0, import_react.useState)(() => {
|
45
|
-
const useContentPartRuntime = (0, import_zustand.create)(
|
46
|
-
// TODO
|
47
|
-
() => new import_ContentPartRuntime.ContentPartRuntimeImpl(null, null, null)
|
48
|
-
);
|
49
45
|
const useContentPart = (0, import_zustand.create)(() => ({
|
50
46
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
51
47
|
type: "text",
|
52
48
|
text
|
53
49
|
}));
|
50
|
+
const useContentPartRuntime = (0, import_zustand.create)(
|
51
|
+
() => new import_ContentPartRuntime.ContentPartRuntimeImpl({
|
52
|
+
path: {
|
53
|
+
ref: "text",
|
54
|
+
threadSelector: { type: "main" },
|
55
|
+
messageSelector: { type: "messageId", messageId: "" },
|
56
|
+
contentPartSelector: { type: "index", index: 0 }
|
57
|
+
},
|
58
|
+
getState: useContentPart.getState,
|
59
|
+
subscribe: useContentPart.subscribe
|
60
|
+
})
|
61
|
+
);
|
54
62
|
return { useContentPartRuntime, useContentPart };
|
55
63
|
});
|
56
64
|
(0, import_react.useEffect)(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport {\n ContentPartContext,\n ContentPartContextValue,\n} from \"../react/ContentPartContext\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport {\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"../../api/ContentPartRuntime\";\n\nexport namespace TextContentPartProvider {\n export type Props = PropsWithChildren<{\n text: string;\n isRunning?: boolean | undefined;\n }>;\n}\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nconst RUNNING_STATUS: ContentPartStatus = {\n type: \"running\",\n};\n\nexport const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({\n children,\n text,\n isRunning,\n}) => {\n const [context] = useState<ContentPartContextValue>(() => {\n const
|
1
|
+
{"version":3,"sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport {\n ContentPartContext,\n ContentPartContextValue,\n} from \"../react/ContentPartContext\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport {\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"../../api/ContentPartRuntime\";\n\nexport namespace TextContentPartProvider {\n export type Props = PropsWithChildren<{\n text: string;\n isRunning?: boolean | undefined;\n }>;\n}\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nconst RUNNING_STATUS: ContentPartStatus = {\n type: \"running\",\n};\n\nexport const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({\n children,\n text,\n isRunning,\n}) => {\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(() => ({\n status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,\n type: \"text\",\n text,\n }));\n\n const useContentPartRuntime = create(\n () =>\n new ContentPartRuntimeImpl({\n path: {\n ref: \"text\",\n threadSelector: { type: \"main\" },\n messageSelector: { type: \"messageId\", messageId: \"\" },\n contentPartSelector: { type: \"index\", index: 0 },\n },\n getState: useContentPart.getState,\n subscribe: useContentPart.subscribe,\n }),\n );\n\n return { useContentPartRuntime, useContentPart };\n });\n\n useEffect(() => {\n const state = context.useContentPart.getState() as ContentPartState & {\n type: \"text\";\n };\n\n const textUpdated = (state as TextContentPart).text !== text;\n const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;\n const statusUpdated = state.status !== targetStatus;\n\n if (!textUpdated && !statusUpdated) return;\n\n writableStore(context.useContentPart).setState(\n {\n type: \"text\",\n text,\n status: targetStatus,\n } satisfies ContentPartState,\n true,\n );\n }, [context, isRunning, text]);\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAoC;AACpC,qBAAuB;AACvB,gCAGO;AAEP,2BAA8B;AAC9B,gCAGO;AAoEH;AA3DJ,IAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEA,IAAM,iBAAoC;AAAA,EACxC,MAAM;AACR;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,OAAO,QAAI,uBAAkC,MAAM;AACxD,UAAM,qBAAiB,uBAAyB,OAAO;AAAA,MACrD,QAAQ,YAAY,iBAAiB;AAAA,MACrC,MAAM;AAAA,MACN;AAAA,IACF,EAAE;AAEF,UAAM,4BAAwB;AAAA,MAC5B,MACE,IAAI,iDAAuB;AAAA,QACzB,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,UAC/B,iBAAiB,EAAE,MAAM,aAAa,WAAW,GAAG;AAAA,UACpD,qBAAqB,EAAE,MAAM,SAAS,OAAO,EAAE;AAAA,QACjD;AAAA,QACA,UAAU,eAAe;AAAA,QACzB,WAAW,eAAe;AAAA,MAC5B,CAAC;AAAA,IACL;AAEA,WAAO,EAAE,uBAAuB,eAAe;AAAA,EACjD,CAAC;AAED,8BAAU,MAAM;AACd,UAAM,QAAQ,QAAQ,eAAe,SAAS;AAI9C,UAAM,cAAe,MAA0B,SAAS;AACxD,UAAM,eAAe,YAAY,iBAAiB;AAClD,UAAM,gBAAgB,MAAM,WAAW;AAEvC,QAAI,CAAC,eAAe,CAAC,cAAe;AAEpC,4CAAc,QAAQ,cAAc,EAAE;AAAA,MACpC;AAAA,QACE,MAAM;AAAA,QACN;AAAA,QACA,QAAQ;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,WAAW,IAAI,CAAC;AAE7B,SACE,4CAAC,6CAAmB,UAAnB,EAA4B,OAAO,SACjC,UACH;AAEJ;","names":[]}
|
@@ -23,15 +23,23 @@ var TextContentPartProvider = ({
|
|
23
23
|
isRunning
|
24
24
|
}) => {
|
25
25
|
const [context] = useState(() => {
|
26
|
-
const useContentPartRuntime = create(
|
27
|
-
// TODO
|
28
|
-
() => new ContentPartRuntimeImpl(null, null, null)
|
29
|
-
);
|
30
26
|
const useContentPart = create(() => ({
|
31
27
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
32
28
|
type: "text",
|
33
29
|
text
|
34
30
|
}));
|
31
|
+
const useContentPartRuntime = create(
|
32
|
+
() => new ContentPartRuntimeImpl({
|
33
|
+
path: {
|
34
|
+
ref: "text",
|
35
|
+
threadSelector: { type: "main" },
|
36
|
+
messageSelector: { type: "messageId", messageId: "" },
|
37
|
+
contentPartSelector: { type: "index", index: 0 }
|
38
|
+
},
|
39
|
+
getState: useContentPart.getState,
|
40
|
+
subscribe: useContentPart.subscribe
|
41
|
+
})
|
42
|
+
);
|
35
43
|
return { useContentPartRuntime, useContentPart };
|
36
44
|
});
|
37
45
|
useEffect(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport {\n ContentPartContext,\n ContentPartContextValue,\n} from \"../react/ContentPartContext\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport {\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"../../api/ContentPartRuntime\";\n\nexport namespace TextContentPartProvider {\n export type Props = PropsWithChildren<{\n text: string;\n isRunning?: boolean | undefined;\n }>;\n}\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nconst RUNNING_STATUS: ContentPartStatus = {\n type: \"running\",\n};\n\nexport const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({\n children,\n text,\n isRunning,\n}) => {\n const [context] = useState<ContentPartContextValue>(() => {\n const
|
1
|
+
{"version":3,"sources":["../../../src/context/providers/TextContentPartProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport {\n ContentPartContext,\n ContentPartContextValue,\n} from \"../react/ContentPartContext\";\nimport { ContentPartStatus, TextContentPart } from \"../../types/AssistantTypes\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport {\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"../../api/ContentPartRuntime\";\n\nexport namespace TextContentPartProvider {\n export type Props = PropsWithChildren<{\n text: string;\n isRunning?: boolean | undefined;\n }>;\n}\n\nconst COMPLETE_STATUS: ContentPartStatus = {\n type: \"complete\",\n};\n\nconst RUNNING_STATUS: ContentPartStatus = {\n type: \"running\",\n};\n\nexport const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({\n children,\n text,\n isRunning,\n}) => {\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(() => ({\n status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,\n type: \"text\",\n text,\n }));\n\n const useContentPartRuntime = create(\n () =>\n new ContentPartRuntimeImpl({\n path: {\n ref: \"text\",\n threadSelector: { type: \"main\" },\n messageSelector: { type: \"messageId\", messageId: \"\" },\n contentPartSelector: { type: \"index\", index: 0 },\n },\n getState: useContentPart.getState,\n subscribe: useContentPart.subscribe,\n }),\n );\n\n return { useContentPartRuntime, useContentPart };\n });\n\n useEffect(() => {\n const state = context.useContentPart.getState() as ContentPartState & {\n type: \"text\";\n };\n\n const textUpdated = (state as TextContentPart).text !== text;\n const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;\n const statusUpdated = state.status !== targetStatus;\n\n if (!textUpdated && !statusUpdated) return;\n\n writableStore(context.useContentPart).setState(\n {\n type: \"text\",\n text,\n status: targetStatus,\n } satisfies ContentPartState,\n true,\n );\n }, [context, isRunning, text]);\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AACpC,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,OAEK;AAEP,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,OAEK;AAoEH;AA3DJ,IAAM,kBAAqC;AAAA,EACzC,MAAM;AACR;AAEA,IAAM,iBAAoC;AAAA,EACxC,MAAM;AACR;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,OAAO,IAAI,SAAkC,MAAM;AACxD,UAAM,iBAAiB,OAAyB,OAAO;AAAA,MACrD,QAAQ,YAAY,iBAAiB;AAAA,MACrC,MAAM;AAAA,MACN;AAAA,IACF,EAAE;AAEF,UAAM,wBAAwB;AAAA,MAC5B,MACE,IAAI,uBAAuB;AAAA,QACzB,MAAM;AAAA,UACJ,KAAK;AAAA,UACL,gBAAgB,EAAE,MAAM,OAAO;AAAA,UAC/B,iBAAiB,EAAE,MAAM,aAAa,WAAW,GAAG;AAAA,UACpD,qBAAqB,EAAE,MAAM,SAAS,OAAO,EAAE;A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C;CACnC,CAAC,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,EAAE,CAAC,yBAAyB,CAmC9D,CAAC"}
|
package/dist/ui/thread-config.js
CHANGED
@@ -38,7 +38,14 @@ var ThreadConfigProvider = ({
|
|
38
38
|
config
|
39
39
|
}) => {
|
40
40
|
const hasAssistant = !!(0, import_AssistantContext.useAssistantRuntime)({ optional: true });
|
41
|
-
const
|
41
|
+
const hasConfig = config && Object.keys(config).length > 0;
|
42
|
+
const outerConfig = useThreadConfig();
|
43
|
+
if (hasConfig && Object.keys(outerConfig).length > 0) {
|
44
|
+
throw new Error(
|
45
|
+
"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component."
|
46
|
+
);
|
47
|
+
}
|
48
|
+
const configProvider = hasConfig ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
42
49
|
if (!config?.runtime) return configProvider;
|
43
50
|
if (hasAssistant) {
|
44
51
|
throw new Error(
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/ui/thread-config.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ComponentType,\n FC,\n PropsWithChildren,\n ReactNode,\n createContext,\n useContext,\n} from \"react\";\n\nimport { AssistantRuntime } from \"../api/AssistantRuntime\";\nimport { AvatarProps } from \"./base/avatar\";\nimport { TextContentPartComponent, ToolCallContentPartProps } from \"../types\";\nimport { AssistantRuntimeProvider } from \"../context\";\nimport { AssistantToolUI } from \"../model-config\";\nimport { useAssistantRuntime } from \"../context/react/AssistantContext\";\n\nexport type SuggestionConfig = {\n text?: ReactNode | undefined;\n prompt: string;\n};\n\nexport type ThreadWelcomeConfig = {\n message?: string | null | undefined;\n suggestions?: SuggestionConfig[] | undefined;\n};\n\nexport type UserMessageConfig = {\n allowEdit?: boolean | undefined;\n};\n\nexport type AssistantMessageConfig = {\n allowReload?: boolean | undefined;\n allowCopy?: boolean | undefined;\n allowSpeak?: boolean | undefined;\n allowFeedbackPositive?: boolean | undefined;\n allowFeedbackNegative?: boolean | undefined;\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n ToolFallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | undefined;\n};\n\nexport type BranchPickerConfig = {\n allowBranchPicker?: boolean | undefined;\n};\n\nexport type ComposerConfig = {\n allowAttachments?: boolean | undefined;\n};\n\nexport type StringsConfig = {\n assistantModal?: {\n open: {\n button: {\n tooltip?: string | undefined;\n };\n };\n closed: {\n button: {\n tooltip?: string | undefined;\n };\n };\n };\n thread?: {\n scrollToBottom?: {\n tooltip?: string | undefined;\n };\n };\n welcome?: {\n message?: string | undefined;\n };\n userMessage?: {\n edit?: {\n tooltip?: string | undefined;\n };\n };\n assistantMessage?: {\n reload?: {\n tooltip?: string | undefined;\n };\n copy?: {\n tooltip?: string | undefined;\n };\n speak?: {\n tooltip?: string | undefined;\n stop?: {\n tooltip?: string | undefined;\n };\n };\n feedback?: {\n positive?: {\n tooltip?: string | undefined;\n };\n negative?: {\n tooltip?: string | undefined;\n };\n };\n };\n branchPicker?: {\n previous?: {\n tooltip?: string | undefined;\n };\n next?: {\n tooltip?: string | undefined;\n };\n };\n composer?: {\n send?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n cancel?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n addAttachment?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n removeAttachment?: {\n tooltip?: string | undefined;\n };\n input?: {\n placeholder?: string | undefined;\n };\n };\n editComposer?: {\n send?: {\n label?: string | undefined;\n };\n cancel?: {\n label?: string | undefined;\n };\n };\n code?: {\n header?: {\n copy?: {\n tooltip?: string | undefined;\n };\n };\n };\n};\n\nconst ThreadConfigContext = createContext<ThreadConfig>({});\n\nexport type ThreadConfig = {\n runtime?: AssistantRuntime | undefined;\n\n assistantAvatar?: AvatarProps | undefined;\n\n welcome?: ThreadWelcomeConfig | undefined;\n assistantMessage?: AssistantMessageConfig | undefined;\n userMessage?: UserMessageConfig | undefined;\n\n branchPicker?: BranchPickerConfig | undefined;\n\n composer?: ComposerConfig | undefined;\n\n strings?: StringsConfig | undefined;\n\n tools?: AssistantToolUI[] | undefined; // TODO add AssistantTool support\n\n components?:\n | {\n UserMessage?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n Composer?: ComponentType | undefined;\n ThreadWelcome?: ComponentType | undefined;\n }\n | undefined;\n};\n\nexport const useThreadConfig = (): Omit<ThreadConfig, \"runtime\"> => {\n return useContext(ThreadConfigContext);\n};\n\nexport type ThreadConfigProviderProps = PropsWithChildren<{\n config?: ThreadConfig | undefined;\n}>;\n\nexport const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({\n children,\n config,\n}) => {\n const hasAssistant = !!useAssistantRuntime({ optional: true });\n\n const
|
1
|
+
{"version":3,"sources":["../../src/ui/thread-config.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ComponentType,\n FC,\n PropsWithChildren,\n ReactNode,\n createContext,\n useContext,\n} from \"react\";\n\nimport { AssistantRuntime } from \"../api/AssistantRuntime\";\nimport { AvatarProps } from \"./base/avatar\";\nimport { TextContentPartComponent, ToolCallContentPartProps } from \"../types\";\nimport { AssistantRuntimeProvider } from \"../context\";\nimport { AssistantToolUI } from \"../model-config\";\nimport { useAssistantRuntime } from \"../context/react/AssistantContext\";\n\nexport type SuggestionConfig = {\n text?: ReactNode | undefined;\n prompt: string;\n};\n\nexport type ThreadWelcomeConfig = {\n message?: string | null | undefined;\n suggestions?: SuggestionConfig[] | undefined;\n};\n\nexport type UserMessageConfig = {\n allowEdit?: boolean | undefined;\n};\n\nexport type AssistantMessageConfig = {\n allowReload?: boolean | undefined;\n allowCopy?: boolean | undefined;\n allowSpeak?: boolean | undefined;\n allowFeedbackPositive?: boolean | undefined;\n allowFeedbackNegative?: boolean | undefined;\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n ToolFallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | undefined;\n};\n\nexport type BranchPickerConfig = {\n allowBranchPicker?: boolean | undefined;\n};\n\nexport type ComposerConfig = {\n allowAttachments?: boolean | undefined;\n};\n\nexport type StringsConfig = {\n assistantModal?: {\n open: {\n button: {\n tooltip?: string | undefined;\n };\n };\n closed: {\n button: {\n tooltip?: string | undefined;\n };\n };\n };\n thread?: {\n scrollToBottom?: {\n tooltip?: string | undefined;\n };\n };\n welcome?: {\n message?: string | undefined;\n };\n userMessage?: {\n edit?: {\n tooltip?: string | undefined;\n };\n };\n assistantMessage?: {\n reload?: {\n tooltip?: string | undefined;\n };\n copy?: {\n tooltip?: string | undefined;\n };\n speak?: {\n tooltip?: string | undefined;\n stop?: {\n tooltip?: string | undefined;\n };\n };\n feedback?: {\n positive?: {\n tooltip?: string | undefined;\n };\n negative?: {\n tooltip?: string | undefined;\n };\n };\n };\n branchPicker?: {\n previous?: {\n tooltip?: string | undefined;\n };\n next?: {\n tooltip?: string | undefined;\n };\n };\n composer?: {\n send?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n cancel?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n addAttachment?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n removeAttachment?: {\n tooltip?: string | undefined;\n };\n input?: {\n placeholder?: string | undefined;\n };\n };\n editComposer?: {\n send?: {\n label?: string | undefined;\n };\n cancel?: {\n label?: string | undefined;\n };\n };\n code?: {\n header?: {\n copy?: {\n tooltip?: string | undefined;\n };\n };\n };\n};\n\nconst ThreadConfigContext = createContext<ThreadConfig>({});\n\nexport type ThreadConfig = {\n runtime?: AssistantRuntime | undefined;\n\n assistantAvatar?: AvatarProps | undefined;\n\n welcome?: ThreadWelcomeConfig | undefined;\n assistantMessage?: AssistantMessageConfig | undefined;\n userMessage?: UserMessageConfig | undefined;\n\n branchPicker?: BranchPickerConfig | undefined;\n\n composer?: ComposerConfig | undefined;\n\n strings?: StringsConfig | undefined;\n\n tools?: AssistantToolUI[] | undefined; // TODO add AssistantTool support\n\n components?:\n | {\n UserMessage?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n Composer?: ComponentType | undefined;\n ThreadWelcome?: ComponentType | undefined;\n }\n | undefined;\n};\n\nexport const useThreadConfig = (): Omit<ThreadConfig, \"runtime\"> => {\n return useContext(ThreadConfigContext);\n};\n\nexport type ThreadConfigProviderProps = PropsWithChildren<{\n config?: ThreadConfig | undefined;\n}>;\n\nexport const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({\n children,\n config,\n}) => {\n const hasAssistant = !!useAssistantRuntime({ optional: true });\n\n const hasConfig = config && Object.keys(config).length > 0;\n const outerConfig = useThreadConfig();\n\n if (hasConfig && Object.keys(outerConfig).length > 0) {\n throw new Error(\n \"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component.\",\n );\n }\n\n const configProvider = hasConfig ? (\n <ThreadConfigContext.Provider value={config}>\n {children}\n </ThreadConfigContext.Provider>\n ) : (\n <>{children}</>\n );\n\n if (!config?.runtime) return configProvider;\n\n if (hasAssistant) {\n throw new Error(\n \"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed.\",\n );\n }\n return (\n <AssistantRuntimeProvider runtime={config.runtime}>\n {configProvider}\n </AssistantRuntimeProvider>\n );\n};\n\nThreadConfigProvider.displayName = \"ThreadConfigProvider\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;AAKP,qBAAyC;AAEzC,8BAAoC;AA4LhC;AAtDJ,IAAM,0BAAsB,4BAA4B,CAAC,CAAC;AA8BnD,IAAM,kBAAkB,MAAqC;AAClE,aAAO,yBAAW,mBAAmB;AACvC;AAMO,IAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,eAAe,CAAC,KAAC,6CAAoB,EAAE,UAAU,KAAK,CAAC;AAE7D,QAAM,YAAY,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS;AACzD,QAAM,cAAc,gBAAgB;AAEpC,MAAI,aAAa,OAAO,KAAK,WAAW,EAAE,SAAS,GAAG;AACpD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,iBAAiB,YACrB,4CAAC,oBAAoB,UAApB,EAA6B,OAAO,QAClC,UACH,IAEA,2EAAG,UAAS;AAGd,MAAI,CAAC,QAAQ,QAAS,QAAO;AAE7B,MAAI,cAAc;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SACE,4CAAC,2CAAyB,SAAS,OAAO,SACvC,0BACH;AAEJ;AAEA,qBAAqB,cAAc;","names":[]}
|
@@ -17,7 +17,14 @@ var ThreadConfigProvider = ({
|
|
17
17
|
config
|
18
18
|
}) => {
|
19
19
|
const hasAssistant = !!useAssistantRuntime({ optional: true });
|
20
|
-
const
|
20
|
+
const hasConfig = config && Object.keys(config).length > 0;
|
21
|
+
const outerConfig = useThreadConfig();
|
22
|
+
if (hasConfig && Object.keys(outerConfig).length > 0) {
|
23
|
+
throw new Error(
|
24
|
+
"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component."
|
25
|
+
);
|
26
|
+
}
|
27
|
+
const configProvider = hasConfig ? /* @__PURE__ */ jsx(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx(Fragment, { children });
|
21
28
|
if (!config?.runtime) return configProvider;
|
22
29
|
if (hasAssistant) {
|
23
30
|
throw new Error(
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/ui/thread-config.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ComponentType,\n FC,\n PropsWithChildren,\n ReactNode,\n createContext,\n useContext,\n} from \"react\";\n\nimport { AssistantRuntime } from \"../api/AssistantRuntime\";\nimport { AvatarProps } from \"./base/avatar\";\nimport { TextContentPartComponent, ToolCallContentPartProps } from \"../types\";\nimport { AssistantRuntimeProvider } from \"../context\";\nimport { AssistantToolUI } from \"../model-config\";\nimport { useAssistantRuntime } from \"../context/react/AssistantContext\";\n\nexport type SuggestionConfig = {\n text?: ReactNode | undefined;\n prompt: string;\n};\n\nexport type ThreadWelcomeConfig = {\n message?: string | null | undefined;\n suggestions?: SuggestionConfig[] | undefined;\n};\n\nexport type UserMessageConfig = {\n allowEdit?: boolean | undefined;\n};\n\nexport type AssistantMessageConfig = {\n allowReload?: boolean | undefined;\n allowCopy?: boolean | undefined;\n allowSpeak?: boolean | undefined;\n allowFeedbackPositive?: boolean | undefined;\n allowFeedbackNegative?: boolean | undefined;\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n ToolFallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | undefined;\n};\n\nexport type BranchPickerConfig = {\n allowBranchPicker?: boolean | undefined;\n};\n\nexport type ComposerConfig = {\n allowAttachments?: boolean | undefined;\n};\n\nexport type StringsConfig = {\n assistantModal?: {\n open: {\n button: {\n tooltip?: string | undefined;\n };\n };\n closed: {\n button: {\n tooltip?: string | undefined;\n };\n };\n };\n thread?: {\n scrollToBottom?: {\n tooltip?: string | undefined;\n };\n };\n welcome?: {\n message?: string | undefined;\n };\n userMessage?: {\n edit?: {\n tooltip?: string | undefined;\n };\n };\n assistantMessage?: {\n reload?: {\n tooltip?: string | undefined;\n };\n copy?: {\n tooltip?: string | undefined;\n };\n speak?: {\n tooltip?: string | undefined;\n stop?: {\n tooltip?: string | undefined;\n };\n };\n feedback?: {\n positive?: {\n tooltip?: string | undefined;\n };\n negative?: {\n tooltip?: string | undefined;\n };\n };\n };\n branchPicker?: {\n previous?: {\n tooltip?: string | undefined;\n };\n next?: {\n tooltip?: string | undefined;\n };\n };\n composer?: {\n send?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n cancel?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n addAttachment?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n removeAttachment?: {\n tooltip?: string | undefined;\n };\n input?: {\n placeholder?: string | undefined;\n };\n };\n editComposer?: {\n send?: {\n label?: string | undefined;\n };\n cancel?: {\n label?: string | undefined;\n };\n };\n code?: {\n header?: {\n copy?: {\n tooltip?: string | undefined;\n };\n };\n };\n};\n\nconst ThreadConfigContext = createContext<ThreadConfig>({});\n\nexport type ThreadConfig = {\n runtime?: AssistantRuntime | undefined;\n\n assistantAvatar?: AvatarProps | undefined;\n\n welcome?: ThreadWelcomeConfig | undefined;\n assistantMessage?: AssistantMessageConfig | undefined;\n userMessage?: UserMessageConfig | undefined;\n\n branchPicker?: BranchPickerConfig | undefined;\n\n composer?: ComposerConfig | undefined;\n\n strings?: StringsConfig | undefined;\n\n tools?: AssistantToolUI[] | undefined; // TODO add AssistantTool support\n\n components?:\n | {\n UserMessage?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n Composer?: ComponentType | undefined;\n ThreadWelcome?: ComponentType | undefined;\n }\n | undefined;\n};\n\nexport const useThreadConfig = (): Omit<ThreadConfig, \"runtime\"> => {\n return useContext(ThreadConfigContext);\n};\n\nexport type ThreadConfigProviderProps = PropsWithChildren<{\n config?: ThreadConfig | undefined;\n}>;\n\nexport const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({\n children,\n config,\n}) => {\n const hasAssistant = !!useAssistantRuntime({ optional: true });\n\n const
|
1
|
+
{"version":3,"sources":["../../src/ui/thread-config.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ComponentType,\n FC,\n PropsWithChildren,\n ReactNode,\n createContext,\n useContext,\n} from \"react\";\n\nimport { AssistantRuntime } from \"../api/AssistantRuntime\";\nimport { AvatarProps } from \"./base/avatar\";\nimport { TextContentPartComponent, ToolCallContentPartProps } from \"../types\";\nimport { AssistantRuntimeProvider } from \"../context\";\nimport { AssistantToolUI } from \"../model-config\";\nimport { useAssistantRuntime } from \"../context/react/AssistantContext\";\n\nexport type SuggestionConfig = {\n text?: ReactNode | undefined;\n prompt: string;\n};\n\nexport type ThreadWelcomeConfig = {\n message?: string | null | undefined;\n suggestions?: SuggestionConfig[] | undefined;\n};\n\nexport type UserMessageConfig = {\n allowEdit?: boolean | undefined;\n};\n\nexport type AssistantMessageConfig = {\n allowReload?: boolean | undefined;\n allowCopy?: boolean | undefined;\n allowSpeak?: boolean | undefined;\n allowFeedbackPositive?: boolean | undefined;\n allowFeedbackNegative?: boolean | undefined;\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n ToolFallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | undefined;\n};\n\nexport type BranchPickerConfig = {\n allowBranchPicker?: boolean | undefined;\n};\n\nexport type ComposerConfig = {\n allowAttachments?: boolean | undefined;\n};\n\nexport type StringsConfig = {\n assistantModal?: {\n open: {\n button: {\n tooltip?: string | undefined;\n };\n };\n closed: {\n button: {\n tooltip?: string | undefined;\n };\n };\n };\n thread?: {\n scrollToBottom?: {\n tooltip?: string | undefined;\n };\n };\n welcome?: {\n message?: string | undefined;\n };\n userMessage?: {\n edit?: {\n tooltip?: string | undefined;\n };\n };\n assistantMessage?: {\n reload?: {\n tooltip?: string | undefined;\n };\n copy?: {\n tooltip?: string | undefined;\n };\n speak?: {\n tooltip?: string | undefined;\n stop?: {\n tooltip?: string | undefined;\n };\n };\n feedback?: {\n positive?: {\n tooltip?: string | undefined;\n };\n negative?: {\n tooltip?: string | undefined;\n };\n };\n };\n branchPicker?: {\n previous?: {\n tooltip?: string | undefined;\n };\n next?: {\n tooltip?: string | undefined;\n };\n };\n composer?: {\n send?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n cancel?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n addAttachment?:\n | {\n tooltip?: string | undefined;\n }\n | undefined;\n removeAttachment?: {\n tooltip?: string | undefined;\n };\n input?: {\n placeholder?: string | undefined;\n };\n };\n editComposer?: {\n send?: {\n label?: string | undefined;\n };\n cancel?: {\n label?: string | undefined;\n };\n };\n code?: {\n header?: {\n copy?: {\n tooltip?: string | undefined;\n };\n };\n };\n};\n\nconst ThreadConfigContext = createContext<ThreadConfig>({});\n\nexport type ThreadConfig = {\n runtime?: AssistantRuntime | undefined;\n\n assistantAvatar?: AvatarProps | undefined;\n\n welcome?: ThreadWelcomeConfig | undefined;\n assistantMessage?: AssistantMessageConfig | undefined;\n userMessage?: UserMessageConfig | undefined;\n\n branchPicker?: BranchPickerConfig | undefined;\n\n composer?: ComposerConfig | undefined;\n\n strings?: StringsConfig | undefined;\n\n tools?: AssistantToolUI[] | undefined; // TODO add AssistantTool support\n\n components?:\n | {\n UserMessage?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n Composer?: ComponentType | undefined;\n ThreadWelcome?: ComponentType | undefined;\n }\n | undefined;\n};\n\nexport const useThreadConfig = (): Omit<ThreadConfig, \"runtime\"> => {\n return useContext(ThreadConfigContext);\n};\n\nexport type ThreadConfigProviderProps = PropsWithChildren<{\n config?: ThreadConfig | undefined;\n}>;\n\nexport const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({\n children,\n config,\n}) => {\n const hasAssistant = !!useAssistantRuntime({ optional: true });\n\n const hasConfig = config && Object.keys(config).length > 0;\n const outerConfig = useThreadConfig();\n\n if (hasConfig && Object.keys(outerConfig).length > 0) {\n throw new Error(\n \"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component.\",\n );\n }\n\n const configProvider = hasConfig ? (\n <ThreadConfigContext.Provider value={config}>\n {children}\n </ThreadConfigContext.Provider>\n ) : (\n <>{children}</>\n );\n\n if (!config?.runtime) return configProvider;\n\n if (hasAssistant) {\n throw new Error(\n \"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed.\",\n );\n }\n return (\n <AssistantRuntimeProvider runtime={config.runtime}>\n {configProvider}\n </AssistantRuntimeProvider>\n );\n};\n\nThreadConfigProvider.displayName = \"ThreadConfigProvider\";\n"],"mappings":";;;AAEA;AAAA,EAKE;AAAA,EACA;AAAA,OACK;AAKP,SAAS,gCAAgC;AAEzC,SAAS,2BAA2B;AA4LhC,SAIA,UAJA;AAtDJ,IAAM,sBAAsB,cAA4B,CAAC,CAAC;AA8BnD,IAAM,kBAAkB,MAAqC;AAClE,SAAO,WAAW,mBAAmB;AACvC;AAMO,IAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,eAAe,CAAC,CAAC,oBAAoB,EAAE,UAAU,KAAK,CAAC;AAE7D,QAAM,YAAY,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS;AACzD,QAAM,cAAc,gBAAgB;AAEpC,MAAI,aAAa,OAAO,KAAK,WAAW,EAAE,SAAS,GAAG;AACpD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,iBAAiB,YACrB,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,QAClC,UACH,IAEA,gCAAG,UAAS;AAGd,MAAI,CAAC,QAAQ,QAAS,QAAO;AAE7B,MAAI,cAAc;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SACE,oBAAC,4BAAyB,SAAS,OAAO,SACvC,0BACH;AAEJ;AAEA,qBAAqB,cAAc;","names":[]}
|
package/package.json
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
"conversational-ui",
|
30
30
|
"conversational-ai"
|
31
31
|
],
|
32
|
-
"version": "0.7.
|
32
|
+
"version": "0.7.7",
|
33
33
|
"license": "MIT",
|
34
34
|
"exports": {
|
35
35
|
".": {
|
@@ -65,7 +65,7 @@
|
|
65
65
|
],
|
66
66
|
"sideEffects": false,
|
67
67
|
"dependencies": {
|
68
|
-
"@ai-sdk/provider": "^0.0
|
68
|
+
"@ai-sdk/provider": "^1.0.0",
|
69
69
|
"@radix-ui/primitive": "^1.1.0",
|
70
70
|
"@radix-ui/react-avatar": "^1.1.1",
|
71
71
|
"@radix-ui/react-compose-refs": "^1.1.0",
|
@@ -83,7 +83,7 @@
|
|
83
83
|
"lucide-react": "^0.460.0",
|
84
84
|
"nanoid": "^5.0.8",
|
85
85
|
"react-textarea-autosize": "^8.5.5",
|
86
|
-
"secure-json-parse": "^
|
86
|
+
"secure-json-parse": "^3.0.1",
|
87
87
|
"zod": "^3.23.8",
|
88
88
|
"zod-to-json-schema": "^3.23.5",
|
89
89
|
"zustand": "^5.0.1"
|
@@ -108,7 +108,7 @@
|
|
108
108
|
},
|
109
109
|
"devDependencies": {
|
110
110
|
"@types/json-schema": "^7.0.15",
|
111
|
-
"@types/node": "^22.9.
|
111
|
+
"@types/node": "^22.9.1",
|
112
112
|
"autoprefixer": "^10.4.20",
|
113
113
|
"esbuild-plugin-file-path-extensions": "^2.1.3",
|
114
114
|
"eslint": "^9",
|
@@ -121,14 +121,14 @@
|
|
121
121
|
"tsup": "8.3.5",
|
122
122
|
"tsx": "^4.19.2",
|
123
123
|
"@assistant-ui/tailwindcss-transformer": "0.1.0",
|
124
|
-
"@assistant-ui/
|
125
|
-
"@assistant-ui/
|
124
|
+
"@assistant-ui/tsconfig": "0.0.0",
|
125
|
+
"@assistant-ui/tsbuildutils": "^0.0.0"
|
126
126
|
},
|
127
127
|
"publishConfig": {
|
128
128
|
"access": "public",
|
129
129
|
"provenance": true
|
130
130
|
},
|
131
|
-
"homepage": "https://assistant-ui.com/",
|
131
|
+
"homepage": "https://www.assistant-ui.com/",
|
132
132
|
"repository": {
|
133
133
|
"type": "git",
|
134
134
|
"url": "https://github.com/Yonom/assistant-ui/tree/main/packages/react"
|
@@ -41,8 +41,8 @@ export class ContentPartRuntimeImpl implements ContentPartRuntime {
|
|
41
41
|
|
42
42
|
constructor(
|
43
43
|
private contentBinding: ContentPartSnapshotBinding,
|
44
|
-
private messageApi
|
45
|
-
private threadApi
|
44
|
+
private messageApi?: MessageStateBinding,
|
45
|
+
private threadApi?: ThreadRuntimeCoreBinding,
|
46
46
|
) {}
|
47
47
|
|
48
48
|
public getState() {
|
@@ -50,15 +50,21 @@ export class ContentPartRuntimeImpl implements ContentPartRuntime {
|
|
50
50
|
}
|
51
51
|
|
52
52
|
public addToolResult(result: any) {
|
53
|
-
const message = this.messageApi.getState();
|
54
|
-
if (!message) throw new Error("Message is not available");
|
55
|
-
|
56
53
|
const state = this.contentBinding.getState();
|
57
54
|
if (!state) throw new Error("Content part is not available");
|
58
55
|
|
59
56
|
if (state.type !== "tool-call")
|
60
57
|
throw new Error("Tried to add tool result to non-tool content part");
|
61
58
|
|
59
|
+
if (!this.messageApi)
|
60
|
+
throw new Error(
|
61
|
+
"Message API is not available. This is likely a bug in assistant-ui.",
|
62
|
+
);
|
63
|
+
if (!this.threadApi) throw new Error("Thread API is not available");
|
64
|
+
|
65
|
+
const message = this.messageApi.getState();
|
66
|
+
if (!message) throw new Error("Message is not available");
|
67
|
+
|
62
68
|
const toolName = state.toolName;
|
63
69
|
const toolCallId = state.toolCallId;
|
64
70
|
|
@@ -35,16 +35,26 @@ export const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({
|
|
35
35
|
isRunning,
|
36
36
|
}) => {
|
37
37
|
const [context] = useState<ContentPartContextValue>(() => {
|
38
|
-
const useContentPartRuntime = create(
|
39
|
-
// TODO
|
40
|
-
() => new ContentPartRuntimeImpl(null as any, null as any, null as any),
|
41
|
-
);
|
42
38
|
const useContentPart = create<ContentPartState>(() => ({
|
43
39
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
44
40
|
type: "text",
|
45
41
|
text,
|
46
42
|
}));
|
47
43
|
|
44
|
+
const useContentPartRuntime = create(
|
45
|
+
() =>
|
46
|
+
new ContentPartRuntimeImpl({
|
47
|
+
path: {
|
48
|
+
ref: "text",
|
49
|
+
threadSelector: { type: "main" },
|
50
|
+
messageSelector: { type: "messageId", messageId: "" },
|
51
|
+
contentPartSelector: { type: "index", index: 0 },
|
52
|
+
},
|
53
|
+
getState: useContentPart.getState,
|
54
|
+
subscribe: useContentPart.subscribe,
|
55
|
+
}),
|
56
|
+
);
|
57
|
+
|
48
58
|
return { useContentPartRuntime, useContentPart };
|
49
59
|
});
|
50
60
|
|
package/src/ui/thread-config.tsx
CHANGED
@@ -192,14 +192,23 @@ export const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({
|
|
192
192
|
}) => {
|
193
193
|
const hasAssistant = !!useAssistantRuntime({ optional: true });
|
194
194
|
|
195
|
-
const
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
<>{children}</>
|
195
|
+
const hasConfig = config && Object.keys(config).length > 0;
|
196
|
+
const outerConfig = useThreadConfig();
|
197
|
+
|
198
|
+
if (hasConfig && Object.keys(outerConfig).length > 0) {
|
199
|
+
throw new Error(
|
200
|
+
"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component.",
|
202
201
|
);
|
202
|
+
}
|
203
|
+
|
204
|
+
const configProvider = hasConfig ? (
|
205
|
+
<ThreadConfigContext.Provider value={config}>
|
206
|
+
{children}
|
207
|
+
</ThreadConfigContext.Provider>
|
208
|
+
) : (
|
209
|
+
<>{children}</>
|
210
|
+
);
|
211
|
+
|
203
212
|
if (!config?.runtime) return configProvider;
|
204
213
|
|
205
214
|
if (hasAssistant) {
|