@assistant-ui/react 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/edge.d.mts +31 -17
- package/dist/edge.d.ts +31 -17
- package/dist/edge.js +101 -24
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs +101 -24
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +58 -14
- package/dist/index.d.ts +58 -14
- package/dist/index.js +59 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -29
- package/dist/index.mjs.map +1 -1
- package/dist/tailwindcss/index.d.mts +1 -1
- package/dist/tailwindcss/index.d.ts +1 -1
- package/dist/tailwindcss/index.js +7 -4
- package/dist/tailwindcss/index.js.map +1 -1
- package/dist/tailwindcss/index.mjs +7 -4
- package/dist/tailwindcss/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -29,6 +29,21 @@ function useAssistantContext(options) {
|
|
29
29
|
import { create } from "zustand";
|
30
30
|
|
31
31
|
// src/types/ModelConfigTypes.ts
|
32
|
+
import { z } from "zod";
|
33
|
+
var LanguageModelV1CallSettingsSchema = z.object({
|
34
|
+
maxTokens: z.number().int().positive().optional(),
|
35
|
+
temperature: z.number().optional(),
|
36
|
+
topP: z.number().optional(),
|
37
|
+
presencePenalty: z.number().optional(),
|
38
|
+
frequencyPenalty: z.number().optional(),
|
39
|
+
seed: z.number().int().optional(),
|
40
|
+
headers: z.record(z.string().optional()).optional()
|
41
|
+
});
|
42
|
+
var LanguageModelConfigSchema = z.object({
|
43
|
+
apiKey: z.string().optional(),
|
44
|
+
baseUrl: z.string().optional(),
|
45
|
+
modelName: z.string().optional()
|
46
|
+
});
|
32
47
|
var mergeModelConfigs = (configSet) => {
|
33
48
|
const configs = Array.from(configSet).map((c) => c.getModelConfig()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
34
49
|
return configs.reduce((acc, config) => {
|
@@ -2215,6 +2230,10 @@ var toCoreMessages = (message) => {
|
|
2215
2230
|
role: message2.role,
|
2216
2231
|
content: message2.content.map((part) => {
|
2217
2232
|
if (part.type === "ui") throw new Error("UI parts are not supported");
|
2233
|
+
if (part.type === "tool-call") {
|
2234
|
+
const { argsText, ...rest } = part;
|
2235
|
+
return rest;
|
2236
|
+
}
|
2218
2237
|
return part;
|
2219
2238
|
})
|
2220
2239
|
};
|
@@ -2222,7 +2241,7 @@ var toCoreMessages = (message) => {
|
|
2222
2241
|
};
|
2223
2242
|
|
2224
2243
|
// src/runtimes/edge/converters/toLanguageModelTools.ts
|
2225
|
-
import { z } from "zod";
|
2244
|
+
import { z as z2 } from "zod";
|
2226
2245
|
import zodToJsonSchema from "zod-to-json-schema";
|
2227
2246
|
var toLanguageModelTools = (tools) => {
|
2228
2247
|
if (!tools) return [];
|
@@ -2230,7 +2249,7 @@ var toLanguageModelTools = (tools) => {
|
|
2230
2249
|
type: "function",
|
2231
2250
|
name,
|
2232
2251
|
...tool.description ? { description: tool.description } : void 0,
|
2233
|
-
parameters: tool.parameters instanceof
|
2252
|
+
parameters: tool.parameters instanceof z2.ZodType ? zodToJsonSchema(tool.parameters) : tool.parameters
|
2234
2253
|
}));
|
2235
2254
|
};
|
2236
2255
|
|
@@ -2807,7 +2826,7 @@ var appendOrUpdateFinish = (message, chunk) => {
|
|
2807
2826
|
};
|
2808
2827
|
|
2809
2828
|
// src/runtimes/edge/streams/toolResultStream.ts
|
2810
|
-
import { z as
|
2829
|
+
import { z as z3 } from "zod";
|
2811
2830
|
import sjson2 from "secure-json-parse";
|
2812
2831
|
function toolResultStream(tools) {
|
2813
2832
|
const toolCallExecutions = /* @__PURE__ */ new Map();
|
@@ -2821,12 +2840,16 @@ function toolResultStream(tools) {
|
|
2821
2840
|
const tool = tools?.[toolName];
|
2822
2841
|
if (!tool || !tool.execute) return;
|
2823
2842
|
const args = sjson2.parse(argsText);
|
2824
|
-
if (tool.parameters instanceof
|
2843
|
+
if (tool.parameters instanceof z3.ZodType) {
|
2825
2844
|
const result = tool.parameters.safeParse(args);
|
2826
2845
|
if (!result.success) {
|
2827
2846
|
controller.enqueue({
|
2828
|
-
type: "
|
2829
|
-
|
2847
|
+
type: "tool-result",
|
2848
|
+
toolCallType,
|
2849
|
+
toolCallId,
|
2850
|
+
toolName,
|
2851
|
+
result: "Function parameter validation failed. " + JSON.stringify(result.error.issues),
|
2852
|
+
isError: true
|
2830
2853
|
});
|
2831
2854
|
return;
|
2832
2855
|
} else {
|
@@ -2843,9 +2866,14 @@ function toolResultStream(tools) {
|
|
2843
2866
|
result: result2
|
2844
2867
|
});
|
2845
2868
|
} catch (error) {
|
2869
|
+
console.error("Error: ", error);
|
2846
2870
|
controller.enqueue({
|
2847
|
-
type: "
|
2848
|
-
|
2871
|
+
type: "tool-result",
|
2872
|
+
toolCallType,
|
2873
|
+
toolCallId,
|
2874
|
+
toolName,
|
2875
|
+
result: "Error: " + error,
|
2876
|
+
isError: true
|
2849
2877
|
});
|
2850
2878
|
} finally {
|
2851
2879
|
toolCallExecutions.delete(toolCallId);
|
@@ -2903,7 +2931,9 @@ var EdgeChatAdapter = class {
|
|
2903
2931
|
messages: toCoreMessages(messages),
|
2904
2932
|
tools: toLanguageModelTools(
|
2905
2933
|
config.tools
|
2906
|
-
)
|
2934
|
+
),
|
2935
|
+
...config.callSettings,
|
2936
|
+
...config.config
|
2907
2937
|
}),
|
2908
2938
|
signal: abortSignal
|
2909
2939
|
});
|
@@ -3131,7 +3161,7 @@ var fromLanguageModelMessages = (lm, mergeRoundtrips) => {
|
|
3131
3161
|
toolCallId: part.toolCallId,
|
3132
3162
|
toolName: part.toolName,
|
3133
3163
|
argsText: JSON.stringify(part.args),
|
3134
|
-
args:
|
3164
|
+
args: part.args
|
3135
3165
|
};
|
3136
3166
|
}
|
3137
3167
|
return part;
|
@@ -3271,47 +3301,47 @@ var LocalThreadRuntime = class {
|
|
3271
3301
|
async startRun(parentId) {
|
3272
3302
|
this.repository.resetHead(parentId);
|
3273
3303
|
const messages = this.repository.getMessages();
|
3274
|
-
|
3304
|
+
let message = {
|
3275
3305
|
id: generateId(),
|
3276
3306
|
role: "assistant",
|
3277
3307
|
status: { type: "in_progress" },
|
3278
3308
|
content: [{ type: "text", text: "" }],
|
3279
3309
|
createdAt: /* @__PURE__ */ new Date()
|
3280
3310
|
};
|
3281
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3282
3311
|
this.abortController?.abort();
|
3283
3312
|
this.abortController = new AbortController();
|
3313
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3284
3314
|
this.notifySubscribers();
|
3285
|
-
|
3286
|
-
|
3287
|
-
message
|
3288
|
-
|
3289
|
-
this.repository.addOrUpdateMessage(parentId, newMessage);
|
3290
|
-
this.notifySubscribers();
|
3291
|
-
return newMessage;
|
3315
|
+
const updateMessage = (m) => {
|
3316
|
+
message = {
|
3317
|
+
...message,
|
3318
|
+
...m
|
3292
3319
|
};
|
3320
|
+
this.repository.addOrUpdateMessage(parentId, message);
|
3321
|
+
this.notifySubscribers();
|
3322
|
+
return message;
|
3323
|
+
};
|
3324
|
+
try {
|
3293
3325
|
const result = await this.adapter.run({
|
3294
3326
|
messages,
|
3295
3327
|
abortSignal: this.abortController.signal,
|
3296
3328
|
config: this.configProvider.getModelConfig(),
|
3297
|
-
onUpdate:
|
3329
|
+
onUpdate: updateMessage
|
3298
3330
|
});
|
3299
|
-
if (result !== void 0) {
|
3300
|
-
updateHandler(result);
|
3301
|
-
}
|
3302
3331
|
if (result.status?.type === "in_progress")
|
3303
3332
|
throw new Error(
|
3304
3333
|
"Unexpected in_progress status returned from ChatModelAdapter"
|
3305
3334
|
);
|
3306
|
-
|
3335
|
+
this.abortController = null;
|
3336
|
+
updateMessage({ status: { type: "done" }, ...result });
|
3307
3337
|
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3308
3338
|
} catch (e) {
|
3309
|
-
|
3310
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3311
|
-
throw e;
|
3312
|
-
} finally {
|
3339
|
+
const isAbortError = e instanceof Error && e.name === "AbortError";
|
3313
3340
|
this.abortController = null;
|
3314
|
-
|
3341
|
+
updateMessage({
|
3342
|
+
status: isAbortError ? { type: "cancelled" } : { type: "error", error: e }
|
3343
|
+
});
|
3344
|
+
if (!isAbortError) throw e;
|
3315
3345
|
}
|
3316
3346
|
}
|
3317
3347
|
cancelRun() {
|