@assistant-ui/react 0.7.21 → 0.7.23
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/ComposerRuntime.d.ts +9 -7
- package/dist/api/ComposerRuntime.d.ts.map +1 -1
- package/dist/api/ComposerRuntime.js +9 -4
- package/dist/api/ComposerRuntime.js.map +1 -1
- package/dist/api/ComposerRuntime.mjs +9 -4
- package/dist/api/ComposerRuntime.mjs.map +1 -1
- package/dist/api/MessageRuntime.d.ts +7 -3
- package/dist/api/MessageRuntime.d.ts.map +1 -1
- package/dist/api/MessageRuntime.js +5 -2
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +5 -2
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +5 -5
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +3 -2
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +3 -2
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +6 -3
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +19 -6
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +19 -6
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts +6 -4
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +6 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +2 -0
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +2 -0
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts +13 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js +3 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs +3 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +2 -2
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +2 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +3 -2
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +14 -5
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +14 -5
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/types/AssistantTypes.d.ts +5 -0
- package/dist/types/AssistantTypes.d.ts.map +1 -1
- package/dist/types/AssistantTypes.js.map +1 -1
- package/package.json +1 -1
- package/src/api/ComposerRuntime.ts +21 -12
- package/src/api/MessageRuntime.ts +11 -3
- package/src/api/ThreadRuntime.ts +9 -4
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +26 -6
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +2 -1
- package/src/runtimes/core/ComposerRuntimeCore.tsx +9 -6
- package/src/runtimes/core/ThreadRuntimeCore.tsx +7 -1
- package/src/runtimes/edge/EdgeChatAdapter.ts +2 -0
- package/src/runtimes/edge/EdgeRuntimeRequestOptions.ts +5 -0
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +4 -1
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -2
- package/src/runtimes/local/ChatModelAdapter.tsx +2 -0
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +17 -4
- package/src/types/AssistantTypes.ts +7 -0
@@ -49,6 +49,7 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
49
49
|
this.__internal_setOptions(options);
|
50
50
|
}
|
51
51
|
_options;
|
52
|
+
_lastRunConfig = {};
|
52
53
|
get extras() {
|
53
54
|
return void 0;
|
54
55
|
}
|
@@ -81,13 +82,19 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
81
82
|
this.repository.addOrUpdateMessage(message.parentId, newMessage);
|
82
83
|
const startRun = message.startRun ?? message.role === "user";
|
83
84
|
if (startRun) {
|
84
|
-
await this.startRun(
|
85
|
+
await this.startRun({
|
86
|
+
parentId: newMessage.id,
|
87
|
+
runConfig: message.runConfig ?? {}
|
88
|
+
});
|
85
89
|
} else {
|
86
90
|
this.repository.resetHead(newMessage.id);
|
87
91
|
this._notifySubscribers();
|
88
92
|
}
|
89
93
|
}
|
90
|
-
async startRun(
|
94
|
+
async startRun({
|
95
|
+
parentId,
|
96
|
+
runConfig
|
97
|
+
}) {
|
91
98
|
this.ensureInitialized();
|
92
99
|
this.repository.resetHead(parentId);
|
93
100
|
const id = (0, import_internal.generateId)();
|
@@ -101,10 +108,10 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
101
108
|
};
|
102
109
|
this._notifyEventSubscribers("run-start");
|
103
110
|
do {
|
104
|
-
message = await this.performRoundtrip(parentId, message);
|
111
|
+
message = await this.performRoundtrip(parentId, message, runConfig);
|
105
112
|
} while ((0, import_shouldContinue.shouldContinue)(message));
|
106
113
|
}
|
107
|
-
async performRoundtrip(parentId, message) {
|
114
|
+
async performRoundtrip(parentId, message, runConfig) {
|
108
115
|
const messages = this.repository.getMessages();
|
109
116
|
this.abortController?.abort();
|
110
117
|
this.abortController = new AbortController();
|
@@ -149,8 +156,10 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
149
156
|
});
|
150
157
|
}
|
151
158
|
try {
|
159
|
+
this._lastRunConfig = runConfig ?? {};
|
152
160
|
const promiseOrGenerator = this.adapters.chatModel.run({
|
153
161
|
messages,
|
162
|
+
runConfig: this._lastRunConfig,
|
154
163
|
abortSignal: this.abortController.signal,
|
155
164
|
config: this.getModelConfig(),
|
156
165
|
unstable_assistantMessageId: message.id
|
@@ -217,7 +226,7 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
217
226
|
};
|
218
227
|
this.repository.addOrUpdateMessage(parentId, message);
|
219
228
|
if (added && (0, import_shouldContinue.shouldContinue)(message)) {
|
220
|
-
this.performRoundtrip(parentId, message);
|
229
|
+
this.performRoundtrip(parentId, message, this._lastRunConfig);
|
221
230
|
}
|
222
231
|
}
|
223
232
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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ACZ,QAAQ,EAAE,MAAM,cAAc,QAAQ,YAAY;AAAA,QACpD,CAAC;AAAA,MACH,OAAO;AACL,sBAAc;AAAA,UACZ,QAAQ,EAAE,MAAM,cAAc,QAAQ,SAAS,OAAO,EAAE;AAAA,QAC1D,CAAC;AAED,cAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEO,YAAY;AACjB,SAAK,iBAAiB,MAAM;AAC5B,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAEO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAyB;AACvB,UAAM,cAAc,KAAK,WAAW,WAAW,SAAS;AACxD,UAAM,EAAE,SAAS,IAAI;AACrB,QAAI,EAAE,QAAQ,IAAI;AAElB,QAAI,QAAQ,SAAS;AACnB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,QAAQ;AACZ,QAAI,QAAQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,aAAS,sCAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,OAAO;AAAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAM3B,kBAAgC;AAEhC,4BAA+B;AAQ/B,mCAAsC;AAG/B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class extends BaseThreadRuntimeCore {
|
|
25
25
|
this.__internal_setOptions(options);
|
26
26
|
}
|
27
27
|
_options;
|
28
|
+
_lastRunConfig = {};
|
28
29
|
get extras() {
|
29
30
|
return void 0;
|
30
31
|
}
|
@@ -57,13 +58,19 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
57
58
|
this.repository.addOrUpdateMessage(message.parentId, newMessage);
|
58
59
|
const startRun = message.startRun ?? message.role === "user";
|
59
60
|
if (startRun) {
|
60
|
-
await this.startRun(
|
61
|
+
await this.startRun({
|
62
|
+
parentId: newMessage.id,
|
63
|
+
runConfig: message.runConfig ?? {}
|
64
|
+
});
|
61
65
|
} else {
|
62
66
|
this.repository.resetHead(newMessage.id);
|
63
67
|
this._notifySubscribers();
|
64
68
|
}
|
65
69
|
}
|
66
|
-
async startRun(
|
70
|
+
async startRun({
|
71
|
+
parentId,
|
72
|
+
runConfig
|
73
|
+
}) {
|
67
74
|
this.ensureInitialized();
|
68
75
|
this.repository.resetHead(parentId);
|
69
76
|
const id = generateId();
|
@@ -77,10 +84,10 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
77
84
|
};
|
78
85
|
this._notifyEventSubscribers("run-start");
|
79
86
|
do {
|
80
|
-
message = await this.performRoundtrip(parentId, message);
|
87
|
+
message = await this.performRoundtrip(parentId, message, runConfig);
|
81
88
|
} while (shouldContinue(message));
|
82
89
|
}
|
83
|
-
async performRoundtrip(parentId, message) {
|
90
|
+
async performRoundtrip(parentId, message, runConfig) {
|
84
91
|
const messages = this.repository.getMessages();
|
85
92
|
this.abortController?.abort();
|
86
93
|
this.abortController = new AbortController();
|
@@ -125,8 +132,10 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
125
132
|
});
|
126
133
|
}
|
127
134
|
try {
|
135
|
+
this._lastRunConfig = runConfig ?? {};
|
128
136
|
const promiseOrGenerator = this.adapters.chatModel.run({
|
129
137
|
messages,
|
138
|
+
runConfig: this._lastRunConfig,
|
130
139
|
abortSignal: this.abortController.signal,
|
131
140
|
config: this.getModelConfig(),
|
132
141
|
unstable_assistantMessageId: message.id
|
@@ -193,7 +202,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
193
202
|
};
|
194
203
|
this.repository.addOrUpdateMessage(parentId, message);
|
195
204
|
if (added && shouldContinue(message)) {
|
196
|
-
this.performRoundtrip(parentId, message);
|
205
|
+
this.performRoundtrip(parentId, message, this._lastRunConfig);
|
197
206
|
}
|
198
207
|
}
|
199
208
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun(newMessage.id);\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAM3B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAO/B,SAAS,6BAA6B;AAE/B,IAAM,yBAAN,cACG,sBAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,SACA;AACA,UAAM,cAAc;AACpB,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA,EAEQ;AAAA,EAER,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,SAAkC;AAC7D,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW;AAC9C,QAAI,KAAK,aAAa,WAAW,UAAU;AACzC,WAAK,aAAa,SAAS;AAC3B,mBAAa;AAAA,IACf;AAEA,UAAM,YAAY,QAAQ,UAAU,gBAAgB;AACpD,QAAI,KAAK,aAAa,gBAAgB,WAAW;AAC/C,WAAK,aAAa,cAAc;AAChC,mBAAa;AAAA,IACf;AAEA,UAAM,cAAc,QAAQ,UAAU,aAAa;AACnD,QAAI,KAAK,aAAa,aAAa,aAAa;AAC9C,WAAK,aAAa,WAAW;AAC7B,mBAAa;AAAA,IACf;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AAA,IACzC;AAAA,EACF;AACF;","names":["steps"]}
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);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AAO;AAEpD,QAAI,SAAS,eAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
@@ -93,10 +93,15 @@ export type ThreadAssistantMessage = MessageCommonProps & {
|
|
93
93
|
readonly custom: Record<string, unknown>;
|
94
94
|
};
|
95
95
|
};
|
96
|
+
export type RunConfig = {
|
97
|
+
readonly custom?: Record<string, unknown>;
|
98
|
+
};
|
96
99
|
export type AppendMessage = CoreMessage & {
|
97
100
|
parentId: string | null;
|
98
101
|
attachments: readonly CompleteAttachment[];
|
99
102
|
startRun?: boolean | undefined;
|
103
|
+
/** TODO: make required in 0.8.0 */
|
104
|
+
runConfig?: RunConfig | undefined;
|
100
105
|
};
|
101
106
|
type BaseThreadMessage = {
|
102
107
|
readonly status?: ThreadAssistantMessage["status"];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantTypes.d.ts","sourceRoot":"","sources":["../../src/types/AssistantTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,IAAI,EAAE,MAA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AE5B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,wBAAwB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,eAAe,GACf,oBAAoB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { CompleteAttachment } from \"./AttachmentTypes\";\n\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\nexport type TextContentPart = {\n readonly type: \"text\";\n readonly text: string;\n};\n\nexport type ImageContentPart = {\n readonly type: \"image\";\n readonly image: string;\n};\n\nexport type Unstable_AudioContentPart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type UIContentPart = {\n readonly type: \"ui\";\n readonly display: ReactNode;\n};\n\nexport type CoreToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: TArgs;\n readonly result?: TResult | undefined;\n readonly isError?: boolean | undefined;\n};\n\nexport type ToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = CoreToolCallContentPart<TArgs, TResult> & {\n readonly argsText: string;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | UIContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ToolCallContentPart\n | UIContentPart;\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadStep = {\n readonly usage?:\n | {\n readonly promptTokens: number;\n readonly completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: [TextContentPart];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: ThreadUserContentPart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: ThreadAssistantContentPart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly steps: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type AppendMessage = CoreMessage & {\n parentId: string | null;\n attachments: readonly CompleteAttachment[];\n startRun?: boolean | undefined;\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly steps?: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\n/** Core Message Types (without UI content parts) */\n\nexport type CoreUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart;\nexport type CoreAssistantContentPart =\n | TextContentPart\n | CoreToolCallContentPart;\n\nexport type CoreSystemMessage = {\n role: \"system\";\n content: [TextContentPart];\n};\n\nexport type CoreUserMessage = {\n role: \"user\";\n content: CoreUserContentPart[];\n};\n\nexport type CoreAssistantMessage = {\n role: \"assistant\";\n content: CoreAssistantContentPart[];\n};\n\nexport type CoreMessage =\n | CoreSystemMessage\n | CoreUserMessage\n | CoreAssistantMessage;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
1
|
+
{"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { CompleteAttachment } from \"./AttachmentTypes\";\n\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\nexport type TextContentPart = {\n readonly type: \"text\";\n readonly text: string;\n};\n\nexport type ImageContentPart = {\n readonly type: \"image\";\n readonly image: string;\n};\n\nexport type Unstable_AudioContentPart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type UIContentPart = {\n readonly type: \"ui\";\n readonly display: ReactNode;\n};\n\nexport type CoreToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: TArgs;\n readonly result?: TResult | undefined;\n readonly isError?: boolean | undefined;\n};\n\nexport type ToolCallContentPart<\n TArgs extends Record<string, unknown> = Record<string | number, unknown>,\n TResult = unknown,\n> = CoreToolCallContentPart<TArgs, TResult> & {\n readonly argsText: string;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart\n | UIContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ToolCallContentPart\n | UIContentPart;\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadStep = {\n readonly usage?:\n | {\n readonly promptTokens: number;\n readonly completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: [TextContentPart];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: ThreadUserContentPart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: ThreadAssistantContentPart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly steps: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type RunConfig = {\n // TODO allow user customization via global type overrides\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = CoreMessage & {\n parentId: string | null;\n attachments: readonly CompleteAttachment[];\n startRun?: boolean | undefined;\n /** TODO: make required in 0.8.0 */\n runConfig?: RunConfig | undefined;\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly steps?: ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\n/** Core Message Types (without UI content parts) */\n\nexport type CoreUserContentPart =\n | TextContentPart\n | ImageContentPart\n | Unstable_AudioContentPart;\nexport type CoreAssistantContentPart =\n | TextContentPart\n | CoreToolCallContentPart;\n\nexport type CoreSystemMessage = {\n role: \"system\";\n content: [TextContentPart];\n};\n\nexport type CoreUserMessage = {\n role: \"user\";\n content: CoreUserContentPart[];\n};\n\nexport type CoreAssistantMessage = {\n role: \"assistant\";\n content: CoreAssistantContentPart[];\n};\n\nexport type CoreMessage =\n | CoreSystemMessage\n | CoreUserMessage\n | CoreAssistantMessage;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/package.json
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
|
17
17
|
import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
|
18
18
|
import { ComposerRuntimePath } from "./RuntimePathTypes";
|
19
|
-
import { MessageRole } from "../types/AssistantTypes";
|
19
|
+
import { MessageRole, RunConfig } from "../types/AssistantTypes";
|
20
20
|
|
21
21
|
export type ThreadComposerRuntimeCoreBinding = SubscribableWithState<
|
22
22
|
ThreadComposerRuntimeCore | undefined,
|
@@ -34,13 +34,14 @@ export type ComposerRuntimeCoreBinding = SubscribableWithState<
|
|
34
34
|
>;
|
35
35
|
|
36
36
|
type BaseComposerState = {
|
37
|
-
readonly text: string;
|
38
|
-
readonly role: MessageRole;
|
39
|
-
readonly attachments: readonly Attachment[];
|
40
|
-
|
41
37
|
readonly canCancel: boolean;
|
42
38
|
readonly isEditing: boolean;
|
43
39
|
readonly isEmpty: boolean;
|
40
|
+
|
41
|
+
readonly text: string;
|
42
|
+
readonly role: MessageRole;
|
43
|
+
readonly attachments: readonly Attachment[];
|
44
|
+
readonly runConfig: RunConfig;
|
44
45
|
};
|
45
46
|
|
46
47
|
export type ThreadComposerState = BaseComposerState & {
|
@@ -56,6 +57,7 @@ export type EditComposerState = BaseComposerState & {
|
|
56
57
|
export type ComposerState = ThreadComposerState | EditComposerState;
|
57
58
|
|
58
59
|
const EMPTY_ARRAY = Object.freeze([]);
|
60
|
+
const EMPTY_OBJECT = Object.freeze({});
|
59
61
|
const getThreadComposerState = (
|
60
62
|
runtime: ThreadComposerRuntimeCore | undefined,
|
61
63
|
): ThreadComposerState => {
|
@@ -65,9 +67,11 @@ const getThreadComposerState = (
|
|
65
67
|
isEditing: runtime?.isEditing ?? false,
|
66
68
|
canCancel: runtime?.canCancel ?? false,
|
67
69
|
isEmpty: runtime?.isEmpty ?? true,
|
68
|
-
|
70
|
+
|
69
71
|
attachments: runtime?.attachments ?? EMPTY_ARRAY,
|
72
|
+
text: runtime?.text ?? "",
|
70
73
|
role: runtime?.role ?? "user",
|
74
|
+
runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
|
71
75
|
|
72
76
|
value: runtime?.text ?? "",
|
73
77
|
});
|
@@ -82,9 +86,11 @@ const getEditComposerState = (
|
|
82
86
|
isEditing: runtime?.isEditing ?? false,
|
83
87
|
canCancel: runtime?.canCancel ?? false,
|
84
88
|
isEmpty: runtime?.isEmpty ?? true,
|
89
|
+
|
85
90
|
text: runtime?.text ?? "",
|
86
|
-
attachments: runtime?.attachments ?? EMPTY_ARRAY,
|
87
91
|
role: runtime?.role ?? "user",
|
92
|
+
attachments: runtime?.attachments ?? EMPTY_ARRAY,
|
93
|
+
runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
|
88
94
|
|
89
95
|
value: runtime?.text ?? "",
|
90
96
|
});
|
@@ -95,12 +101,13 @@ export type ComposerRuntime = {
|
|
95
101
|
readonly type: "edit" | "thread";
|
96
102
|
getState(): ComposerState;
|
97
103
|
|
98
|
-
setText(text: string): void;
|
99
|
-
setValue(text: string): void;
|
100
|
-
|
101
104
|
getAttachmentAccept(): string;
|
102
105
|
addAttachment(file: File): Promise<void>;
|
103
106
|
|
107
|
+
setText(text: string): void;
|
108
|
+
setRole(role: MessageRole): void;
|
109
|
+
setRunConfig(runConfig: RunConfig): void;
|
110
|
+
|
104
111
|
reset(): void;
|
105
112
|
send(): void;
|
106
113
|
cancel(): void;
|
@@ -125,8 +132,10 @@ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
|
|
125
132
|
core.setText(text);
|
126
133
|
}
|
127
134
|
|
128
|
-
public
|
129
|
-
this.
|
135
|
+
public setRunConfig(runConfig: RunConfig) {
|
136
|
+
const core = this._core.getState();
|
137
|
+
if (!core) throw new Error("Composer is not available");
|
138
|
+
core.setRunConfig(runConfig);
|
130
139
|
}
|
131
140
|
|
132
141
|
public addAttachment(file: File) {
|
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
} from "../types";
|
11
11
|
import {
|
12
12
|
ContentPartStatus,
|
13
|
+
RunConfig,
|
13
14
|
ToolCallContentPartStatus,
|
14
15
|
} from "../types/AssistantTypes";
|
15
16
|
import { getThreadMessageText } from "../utils/getThreadMessageText";
|
@@ -110,13 +111,17 @@ export type MessageStateBinding = SubscribableWithState<
|
|
110
111
|
MessageRuntimePath
|
111
112
|
>;
|
112
113
|
|
114
|
+
type ReloadConfig = {
|
115
|
+
runConfig?: RunConfig;
|
116
|
+
};
|
117
|
+
|
113
118
|
export type MessageRuntime = {
|
114
119
|
readonly path: MessageRuntimePath;
|
115
120
|
|
116
121
|
readonly composer: EditComposerRuntime;
|
117
122
|
|
118
123
|
getState(): MessageState;
|
119
|
-
reload(): void;
|
124
|
+
reload(config?: ReloadConfig): void;
|
120
125
|
/**
|
121
126
|
* @deprecated This API is still under active development and might change without notice.
|
122
127
|
*/
|
@@ -175,12 +180,15 @@ export class MessageRuntimeImpl implements MessageRuntime {
|
|
175
180
|
return this._core.getState();
|
176
181
|
}
|
177
182
|
|
178
|
-
public reload() {
|
183
|
+
public reload({ runConfig = {} }: ReloadConfig = {}) {
|
179
184
|
const state = this._core.getState();
|
180
185
|
if (state.role !== "assistant")
|
181
186
|
throw new Error("Can only reload assistant messages");
|
182
187
|
|
183
|
-
this._threadBinding.getState().startRun(
|
188
|
+
this._threadBinding.getState().startRun({
|
189
|
+
parentId: state.parentId,
|
190
|
+
runConfig,
|
191
|
+
});
|
184
192
|
}
|
185
193
|
|
186
194
|
public speak() {
|
package/src/api/ThreadRuntime.ts
CHANGED
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
ThreadRuntimeCore,
|
5
5
|
SpeechState,
|
6
6
|
ThreadRuntimeEventType,
|
7
|
+
StartRunConfig,
|
7
8
|
} from "../runtimes/core/ThreadRuntimeCore";
|
8
9
|
import { ExportedMessageRepository } from "../runtimes/utils/MessageRepository";
|
9
10
|
import {
|
@@ -189,10 +190,10 @@ export type ThreadRuntime = {
|
|
189
190
|
append(message: CreateAppendMessage): void;
|
190
191
|
|
191
192
|
/**
|
192
|
-
*
|
193
|
-
* @param parentId
|
193
|
+
* @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.
|
194
194
|
*/
|
195
195
|
startRun(parentId: string | null): void;
|
196
|
+
startRun(config: StartRunConfig): void;
|
196
197
|
subscribe(callback: () => void): Unsubscribe;
|
197
198
|
cancelRun(): void;
|
198
199
|
getModelConfig(): ModelConfig;
|
@@ -286,8 +287,12 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
|
|
286
287
|
return this._threadBinding.getState().getModelConfig();
|
287
288
|
}
|
288
289
|
|
289
|
-
public startRun(
|
290
|
-
|
290
|
+
public startRun(configOrParentId: string | null | StartRunConfig) {
|
291
|
+
const config =
|
292
|
+
configOrParentId === null || typeof configOrParentId === "string"
|
293
|
+
? { parentId: configOrParentId }
|
294
|
+
: configOrParentId;
|
295
|
+
return this._threadBinding.getState().startRun(config);
|
291
296
|
}
|
292
297
|
|
293
298
|
public cancelRun() {
|
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
ComposerRuntimeCore,
|
10
10
|
ComposerRuntimeEventType,
|
11
11
|
} from "../core/ComposerRuntimeCore";
|
12
|
-
import { MessageRole } from "../../types/AssistantTypes";
|
12
|
+
import { MessageRole, RunConfig } from "../../types/AssistantTypes";
|
13
13
|
|
14
14
|
const isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>
|
15
15
|
a.status.type === "complete";
|
@@ -51,25 +51,44 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
51
51
|
return this._role;
|
52
52
|
}
|
53
53
|
|
54
|
+
private _runConfig: RunConfig = {};
|
55
|
+
|
56
|
+
get runConfig() {
|
57
|
+
return this._runConfig;
|
58
|
+
}
|
59
|
+
|
60
|
+
public setText(value: string) {
|
61
|
+
if (this._text === value) return;
|
62
|
+
|
63
|
+
this._text = value;
|
64
|
+
this.notifySubscribers();
|
65
|
+
}
|
66
|
+
|
54
67
|
public setRole(role: MessageRole) {
|
68
|
+
if (this._role === role) return;
|
69
|
+
|
55
70
|
this._role = role;
|
56
71
|
this.notifySubscribers();
|
57
72
|
}
|
58
73
|
|
59
|
-
public
|
60
|
-
this.
|
74
|
+
public setRunConfig(runConfig: RunConfig) {
|
75
|
+
if (this._runConfig === runConfig) return;
|
76
|
+
|
77
|
+
this._runConfig = runConfig;
|
61
78
|
this.notifySubscribers();
|
62
79
|
}
|
63
80
|
|
64
81
|
private _resetInternal() {
|
82
|
+
// TODO attachmentAdapter.remove should be called here
|
83
|
+
this._attachments = [];
|
65
84
|
this._text = "";
|
66
85
|
this._role = "user";
|
67
|
-
this.
|
86
|
+
this._runConfig = {};
|
68
87
|
this.notifySubscribers();
|
69
88
|
}
|
70
89
|
|
71
|
-
public reset() {
|
72
|
-
this._resetInternal();
|
90
|
+
public async reset() {
|
91
|
+
return this._resetInternal();
|
73
92
|
}
|
74
93
|
|
75
94
|
public async send() {
|
@@ -89,6 +108,7 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
89
108
|
role: this.role,
|
90
109
|
content: this.text ? [{ type: "text", text: this.text }] : [],
|
91
110
|
attachments,
|
111
|
+
runConfig: this.runConfig,
|
92
112
|
};
|
93
113
|
this._resetInternal();
|
94
114
|
|
@@ -17,6 +17,7 @@ import {
|
|
17
17
|
RuntimeCapabilities,
|
18
18
|
SubmittedFeedback,
|
19
19
|
ThreadRuntimeEventType,
|
20
|
+
StartRunConfig,
|
20
21
|
} from "../core/ThreadRuntimeCore";
|
21
22
|
import { DefaultEditComposerRuntimeCore } from "../composer/DefaultEditComposerRuntimeCore";
|
22
23
|
import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
@@ -42,7 +43,7 @@ export abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
|
|
42
43
|
|
43
44
|
public abstract get capabilities(): RuntimeCapabilities;
|
44
45
|
public abstract append(message: AppendMessage): void;
|
45
|
-
public abstract startRun(
|
46
|
+
public abstract startRun(config: StartRunConfig): void;
|
46
47
|
public abstract addToolResult(options: AddToolResultOptions): void;
|
47
48
|
public abstract cancelRun(): void;
|
48
49
|
|
@@ -1,26 +1,29 @@
|
|
1
1
|
import type { Attachment, PendingAttachment, Unsubscribe } from "../../types";
|
2
|
-
import { MessageRole } from "../../types/AssistantTypes";
|
2
|
+
import { MessageRole, RunConfig } from "../../types/AssistantTypes";
|
3
3
|
|
4
4
|
export type ComposerRuntimeEventType = "send";
|
5
5
|
|
6
6
|
export type ComposerRuntimeCore = Readonly<{
|
7
|
+
isEditing: boolean;
|
8
|
+
|
9
|
+
canCancel: boolean;
|
10
|
+
isEmpty: boolean;
|
11
|
+
|
7
12
|
attachments: readonly Attachment[];
|
8
13
|
|
9
14
|
getAttachmentAccept(): string;
|
10
15
|
addAttachment: (file: File) => Promise<void>;
|
11
16
|
removeAttachment: (attachmentId: string) => Promise<void>;
|
12
17
|
|
13
|
-
isEditing: boolean;
|
14
|
-
|
15
|
-
canCancel: boolean;
|
16
|
-
isEmpty: boolean;
|
17
|
-
|
18
18
|
text: string;
|
19
19
|
setText: (value: string) => void;
|
20
20
|
|
21
21
|
role: MessageRole;
|
22
22
|
setRole: (role: MessageRole) => void;
|
23
23
|
|
24
|
+
runConfig: RunConfig;
|
25
|
+
setRunConfig: (runConfig: RunConfig) => void;
|
26
|
+
|
24
27
|
reset: () => void;
|
25
28
|
|
26
29
|
send: () => void;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { AppendMessage, ModelConfig, ThreadMessage } from "../../types";
|
2
|
+
import { RunConfig } from "../../types/AssistantTypes";
|
2
3
|
import type { Unsubscribe } from "../../types/Unsubscribe";
|
3
4
|
import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
4
5
|
import { ExportedMessageRepository } from "../utils/MessageRepository";
|
@@ -48,6 +49,11 @@ export type ThreadRuntimeEventType =
|
|
48
49
|
| "initialize"
|
49
50
|
| "model-config-update";
|
50
51
|
|
52
|
+
export type StartRunConfig = {
|
53
|
+
parentId: string | null;
|
54
|
+
runConfig?: RunConfig | undefined;
|
55
|
+
};
|
56
|
+
|
51
57
|
export type ThreadRuntimeCore = Readonly<{
|
52
58
|
getMessageById: (messageId: string) =>
|
53
59
|
| {
|
@@ -60,7 +66,7 @@ export type ThreadRuntimeCore = Readonly<{
|
|
60
66
|
switchToBranch: (branchId: string) => void;
|
61
67
|
|
62
68
|
append: (message: AppendMessage) => void;
|
63
|
-
startRun: (
|
69
|
+
startRun: (config: StartRunConfig) => void;
|
64
70
|
cancelRun: () => void;
|
65
71
|
|
66
72
|
addToolResult: (options: AddToolResultOptions) => void;
|