veryfront 0.1.151 → 0.1.154
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/esm/deno.js +1 -1
- package/esm/src/agent/ag-ui-run-control.d.ts +33 -0
- package/esm/src/agent/ag-ui-run-control.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-run-control.js +102 -0
- package/esm/src/agent/index.d.ts +2 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +2 -0
- package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/chat-stream-handler.js +1 -25
- package/esm/src/agent/runtime/error-utils.d.ts +4 -0
- package/esm/src/agent/runtime/error-utils.d.ts.map +1 -0
- package/esm/src/agent/runtime/error-utils.js +25 -0
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +1 -25
- package/esm/src/agent/runtime-ag-ui-contract.d.ts +207 -0
- package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -0
- package/esm/src/agent/runtime-ag-ui-contract.js +109 -0
- package/esm/src/internal-agents/schema.d.ts +14 -68
- package/esm/src/internal-agents/schema.d.ts.map +1 -1
- package/esm/src/internal-agents/schema.js +8 -98
- package/esm/src/provider/runtime-loader.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader.js +9 -32
- package/esm/src/routing/api/module-loader/loader.js +26 -28
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/src/agent/ag-ui-run-control.ts +161 -0
- package/src/src/agent/index.ts +18 -0
- package/src/src/agent/runtime/chat-stream-handler.ts +1 -33
- package/src/src/agent/runtime/error-utils.ts +32 -0
- package/src/src/agent/runtime/index.ts +1 -33
- package/src/src/agent/runtime-ag-ui-contract.ts +144 -0
- package/src/src/internal-agents/schema.ts +22 -129
- package/src/src/provider/runtime-loader.ts +9 -39
- package/src/src/routing/api/module-loader/loader.ts +37 -38
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type AgUiRuntimeRequest } from "../agent/runtime-ag-ui-contract.js";
|
|
2
3
|
export declare const RunIdSchema: z.ZodString;
|
|
3
4
|
export declare const AgentIdSchema: z.ZodString;
|
|
4
|
-
export declare const
|
|
5
|
+
export declare const RuntimeAgentSourceContextSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
|
+
type: z.ZodLiteral<"branch">;
|
|
7
|
+
branch: z.ZodString;
|
|
8
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
9
|
+
type: z.ZodLiteral<"environment">;
|
|
10
|
+
environmentName: z.ZodString;
|
|
11
|
+
releaseId: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"release">;
|
|
14
|
+
releaseId: z.ZodString;
|
|
15
|
+
}, z.core.$strip>], "type">;
|
|
5
16
|
export declare const RuntimeInjectedToolSchema: z.ZodObject<{
|
|
6
17
|
name: z.ZodString;
|
|
7
18
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -22,71 +33,6 @@ export declare const RuntimeContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObj
|
|
|
22
33
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
23
34
|
text: z.ZodOptional<z.ZodString>;
|
|
24
35
|
}, z.core.$strip>], "type">;
|
|
25
|
-
export declare const RuntimeAgentSourceContextSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
26
|
-
type: z.ZodLiteral<"branch">;
|
|
27
|
-
branch: z.ZodString;
|
|
28
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
29
|
-
type: z.ZodLiteral<"environment">;
|
|
30
|
-
environmentName: z.ZodString;
|
|
31
|
-
releaseId: z.ZodOptional<z.ZodString>;
|
|
32
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
-
type: z.ZodLiteral<"release">;
|
|
34
|
-
releaseId: z.ZodString;
|
|
35
|
-
}, z.core.$strip>], "type">;
|
|
36
|
-
export declare const RuntimeToolFunctionCallSchema: z.ZodObject<{
|
|
37
|
-
name: z.ZodString;
|
|
38
|
-
arguments: z.ZodString;
|
|
39
|
-
}, z.core.$strict>;
|
|
40
|
-
export declare const RuntimeToolCallSchema: z.ZodObject<{
|
|
41
|
-
id: z.ZodString;
|
|
42
|
-
type: z.ZodLiteral<"function">;
|
|
43
|
-
function: z.ZodObject<{
|
|
44
|
-
name: z.ZodString;
|
|
45
|
-
arguments: z.ZodString;
|
|
46
|
-
}, z.core.$strict>;
|
|
47
|
-
}, z.core.$strict>;
|
|
48
|
-
export declare const RuntimeSystemMessageSchema: z.ZodObject<{
|
|
49
|
-
name: z.ZodOptional<z.ZodString>;
|
|
50
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
51
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
52
|
-
id: z.ZodString;
|
|
53
|
-
role: z.ZodLiteral<"system">;
|
|
54
|
-
content: z.ZodString;
|
|
55
|
-
}, z.core.$strict>;
|
|
56
|
-
export declare const RuntimeUserMessageSchema: z.ZodObject<{
|
|
57
|
-
name: z.ZodOptional<z.ZodString>;
|
|
58
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
59
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
60
|
-
id: z.ZodString;
|
|
61
|
-
role: z.ZodLiteral<"user">;
|
|
62
|
-
content: z.ZodString;
|
|
63
|
-
}, z.core.$strict>;
|
|
64
|
-
export declare const RuntimeAssistantMessageSchema: z.ZodObject<{
|
|
65
|
-
name: z.ZodOptional<z.ZodString>;
|
|
66
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
67
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
68
|
-
id: z.ZodString;
|
|
69
|
-
role: z.ZodLiteral<"assistant">;
|
|
70
|
-
content: z.ZodOptional<z.ZodString>;
|
|
71
|
-
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
72
|
-
id: z.ZodString;
|
|
73
|
-
type: z.ZodLiteral<"function">;
|
|
74
|
-
function: z.ZodObject<{
|
|
75
|
-
name: z.ZodString;
|
|
76
|
-
arguments: z.ZodString;
|
|
77
|
-
}, z.core.$strict>;
|
|
78
|
-
}, z.core.$strict>>>;
|
|
79
|
-
}, z.core.$strict>;
|
|
80
|
-
export declare const RuntimeToolMessageSchema: z.ZodObject<{
|
|
81
|
-
name: z.ZodOptional<z.ZodString>;
|
|
82
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
83
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
84
|
-
id: z.ZodString;
|
|
85
|
-
role: z.ZodLiteral<"tool">;
|
|
86
|
-
toolCallId: z.ZodString;
|
|
87
|
-
content: z.ZodString;
|
|
88
|
-
error: z.ZodOptional<z.ZodString>;
|
|
89
|
-
}, z.core.$strict>;
|
|
90
36
|
export declare const RuntimeMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
91
37
|
name: z.ZodOptional<z.ZodString>;
|
|
92
38
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
@@ -321,7 +267,7 @@ export declare const InternalAgentStreamRequestSchema: z.ZodObject<{
|
|
|
321
267
|
}, z.core.$strip>], "type">>;
|
|
322
268
|
forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
323
269
|
}, z.core.$strip>;
|
|
324
|
-
export declare function toRuntimeRunAgentInput(input: z.infer<typeof InternalAgentStreamRequestSchema>):
|
|
270
|
+
export declare function toRuntimeRunAgentInput(input: z.infer<typeof InternalAgentStreamRequestSchema>): AgUiRuntimeRequest;
|
|
325
271
|
export declare const ResumeSignalSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
326
272
|
type: z.ZodLiteral<"tool_result">;
|
|
327
273
|
toolCallId: z.ZodString;
|
|
@@ -331,7 +277,7 @@ export declare const ResumeSignalSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
331
277
|
export type RuntimeInjectedTool = z.infer<typeof RuntimeInjectedToolSchema>;
|
|
332
278
|
export type RuntimeContextItem = z.infer<typeof RuntimeContextItemSchema>;
|
|
333
279
|
export type RuntimeAgentSourceContext = z.infer<typeof RuntimeAgentSourceContextSchema>;
|
|
334
|
-
export type RuntimeRunAgentInput =
|
|
280
|
+
export type RuntimeRunAgentInput = AgUiRuntimeRequest;
|
|
335
281
|
export type InternalAgentStreamRequest = z.infer<typeof InternalAgentStreamRequestSchema>;
|
|
336
282
|
export type ResumeSignal = z.infer<typeof ResumeSignalSchema>;
|
|
337
283
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAML,KAAK,kBAAkB,EAIxB,MAAM,oCAAoC,CAAC;AAiB5C,eAAO,MAAM,WAAW,aAAyB,CAAC;AAElD,eAAO,MAAM,aAAa,aAAqD,CAAC;AAEhF,eAAO,MAAM,+BAA+B;;;;;;;;;;2BAc1C,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;iBAAgC,CAAC;AACvE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;2BAA+B,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;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} from "../agent/runtime-ag-ui-contract.js";
|
|
2
3
|
const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
3
|
-
const MAX_TOOL_PARAMETERS_BYTES = 16_384;
|
|
4
|
-
const MAX_CONTEXT_ITEM_BYTES = 16_384;
|
|
5
|
-
const MAX_CONTEXT_TOTAL_BYTES = 65_536;
|
|
6
4
|
const MAX_FORWARDED_PROPS_BYTES = 65_536;
|
|
7
5
|
const MAX_TOOL_RESULT_BYTES = 65_536;
|
|
8
6
|
const MAX_RUNTIME_MESSAGES = 100;
|
|
@@ -15,37 +13,8 @@ function isWithinJsonSizeLimit(value, maxBytes) {
|
|
|
15
13
|
return false;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
|
-
export const RunIdSchema =
|
|
16
|
+
export const RunIdSchema = AgUiRuntimeRunIdSchema;
|
|
19
17
|
export const AgentIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
|
|
20
|
-
export const ClientToolNameSchema = z
|
|
21
|
-
.string()
|
|
22
|
-
.min(1)
|
|
23
|
-
.max(128)
|
|
24
|
-
.regex(/^[a-zA-Z][a-zA-Z0-9._:-]*$/, "Tool names must start with a letter and use a valid client-tool format");
|
|
25
|
-
export const RuntimeInjectedToolSchema = z.object({
|
|
26
|
-
name: ClientToolNameSchema,
|
|
27
|
-
description: z.string().max(1024).optional(),
|
|
28
|
-
parameters: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES), { message: "Tool parameters must be less than 16 KB" }),
|
|
29
|
-
});
|
|
30
|
-
export const RuntimeContextItemSchema = z.discriminatedUnion("type", [
|
|
31
|
-
z.object({
|
|
32
|
-
type: z.literal("text"),
|
|
33
|
-
title: z.string().max(256).optional(),
|
|
34
|
-
text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
|
|
35
|
-
}),
|
|
36
|
-
z.object({
|
|
37
|
-
type: z.literal("json"),
|
|
38
|
-
title: z.string().max(256).optional(),
|
|
39
|
-
data: z.record(z.string(), z.unknown()).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES), { message: "JSON context item must be less than 16 KB" }),
|
|
40
|
-
}),
|
|
41
|
-
z.object({
|
|
42
|
-
type: z.literal("resource"),
|
|
43
|
-
title: z.string().max(256).optional(),
|
|
44
|
-
uri: z.string().max(2048),
|
|
45
|
-
mimeType: z.string().max(256).optional(),
|
|
46
|
-
text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
|
|
47
|
-
}),
|
|
48
|
-
]);
|
|
49
18
|
export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
|
|
50
19
|
z.object({
|
|
51
20
|
type: z.literal("branch"),
|
|
@@ -61,70 +30,11 @@ export const RuntimeAgentSourceContextSchema = z.discriminatedUnion("type", [
|
|
|
61
30
|
releaseId: z.string().min(1).max(255),
|
|
62
31
|
}),
|
|
63
32
|
]);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export const RuntimeToolFunctionCallSchema = z.object({
|
|
70
|
-
name: ClientToolNameSchema,
|
|
71
|
-
arguments: z.string().max(MAX_TOOL_PARAMETERS_BYTES),
|
|
72
|
-
}).strict();
|
|
73
|
-
export const RuntimeToolCallSchema = z.object({
|
|
74
|
-
id: z.string().min(1).max(128),
|
|
75
|
-
type: z.literal("function"),
|
|
76
|
-
function: RuntimeToolFunctionCallSchema,
|
|
77
|
-
}).strict();
|
|
78
|
-
export const RuntimeSystemMessageSchema = z.object({
|
|
79
|
-
id: z.string().min(1),
|
|
80
|
-
role: z.literal("system"),
|
|
81
|
-
content: z.string(),
|
|
82
|
-
...RuntimeMessageExtensionFieldsSchema,
|
|
83
|
-
}).strict();
|
|
84
|
-
export const RuntimeUserMessageSchema = z.object({
|
|
85
|
-
id: z.string().min(1),
|
|
86
|
-
role: z.literal("user"),
|
|
87
|
-
content: z.string(),
|
|
88
|
-
...RuntimeMessageExtensionFieldsSchema,
|
|
89
|
-
}).strict();
|
|
90
|
-
export const RuntimeAssistantMessageSchema = z.object({
|
|
91
|
-
id: z.string().min(1),
|
|
92
|
-
role: z.literal("assistant"),
|
|
93
|
-
content: z.string().optional(),
|
|
94
|
-
toolCalls: z.array(RuntimeToolCallSchema).optional(),
|
|
95
|
-
...RuntimeMessageExtensionFieldsSchema,
|
|
96
|
-
}).strict();
|
|
97
|
-
export const RuntimeToolMessageSchema = z.object({
|
|
98
|
-
id: z.string().min(1),
|
|
99
|
-
role: z.literal("tool"),
|
|
100
|
-
toolCallId: z.string().min(1).max(128),
|
|
101
|
-
content: z.string(),
|
|
102
|
-
error: z.string().optional(),
|
|
103
|
-
...RuntimeMessageExtensionFieldsSchema,
|
|
104
|
-
}).strict();
|
|
105
|
-
export const RuntimeMessageSchema = z.discriminatedUnion("role", [
|
|
106
|
-
RuntimeSystemMessageSchema,
|
|
107
|
-
RuntimeUserMessageSchema,
|
|
108
|
-
RuntimeAssistantMessageSchema,
|
|
109
|
-
RuntimeToolMessageSchema,
|
|
110
|
-
]);
|
|
111
|
-
export const RuntimeContextSchema = z.union([
|
|
112
|
-
z.object({
|
|
113
|
-
description: z.string().max(1024),
|
|
114
|
-
value: z.string().max(MAX_CONTEXT_ITEM_BYTES),
|
|
115
|
-
}),
|
|
116
|
-
RuntimeContextItemSchema,
|
|
117
|
-
]);
|
|
118
|
-
export const RuntimeRunAgentInputSchema = z.object({
|
|
119
|
-
threadId: z.string().uuid(),
|
|
120
|
-
runId: RunIdSchema,
|
|
121
|
-
parentRunId: RunIdSchema.optional(),
|
|
122
|
-
state: z.unknown().optional(),
|
|
123
|
-
messages: z.array(RuntimeMessageSchema).max(MAX_RUNTIME_MESSAGES),
|
|
124
|
-
tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
|
|
125
|
-
context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
|
|
126
|
-
forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
|
|
127
|
-
});
|
|
33
|
+
export const RuntimeInjectedToolSchema = AgUiRuntimeInjectedToolSchema;
|
|
34
|
+
export const RuntimeContextItemSchema = AgUiRuntimeContextItemSchema;
|
|
35
|
+
export const RuntimeMessageSchema = AgUiRuntimeMessageSchema;
|
|
36
|
+
export const RuntimeContextSchema = AgUiRuntimeContextSchema;
|
|
37
|
+
export const RuntimeRunAgentInputSchema = AgUiRuntimeRequestSchema;
|
|
128
38
|
export const InternalAgentCompatibilityMessageSchema = z.object({
|
|
129
39
|
id: z.string().min(1),
|
|
130
40
|
role: z.enum(["user", "assistant", "system", "tool"]),
|
|
@@ -140,7 +50,7 @@ export const InternalAgentStreamRequestSchema = z.object({
|
|
|
140
50
|
state: z.unknown().optional(),
|
|
141
51
|
messages: z.array(z.union([RuntimeMessageSchema, InternalAgentCompatibilityMessageSchema])).max(MAX_RUNTIME_MESSAGES),
|
|
142
52
|
tools: z.array(RuntimeInjectedToolSchema).max(50).default([]),
|
|
143
|
-
context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value,
|
|
53
|
+
context: z.array(RuntimeContextSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, 65_536), { message: "context must be less than 64 KB total" }),
|
|
144
54
|
agentSource: RuntimeAgentSourceContextSchema.optional(),
|
|
145
55
|
forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
|
|
146
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AA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AE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC;CAC9B;AAu/CD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,MAAM,GACd,YAAY,CA4Dd;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CA0ClB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CAgDlB"}
|
|
@@ -404,11 +404,11 @@ function buildAnthropicGenerateResult(payload) {
|
|
|
404
404
|
usage: extractAnthropicUsage(payload),
|
|
405
405
|
};
|
|
406
406
|
}
|
|
407
|
-
function
|
|
408
|
-
const blocks = chunk.split(
|
|
407
|
+
function parseSseChunk(chunk) {
|
|
408
|
+
const blocks = chunk.split(/\r?\n\r?\n/);
|
|
409
409
|
const remainder = blocks.pop() ?? "";
|
|
410
410
|
const events = blocks.flatMap((block) => {
|
|
411
|
-
const dataLines = block.split(
|
|
411
|
+
const dataLines = block.split(/\r?\n/)
|
|
412
412
|
.filter((line) => line.startsWith("data:"))
|
|
413
413
|
.map((line) => line.slice(5).trimStart());
|
|
414
414
|
if (!dataLines.length) {
|
|
@@ -435,7 +435,7 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
435
435
|
let usage;
|
|
436
436
|
for await (const chunk of stream) {
|
|
437
437
|
buffer += decoder.decode(chunk, { stream: true });
|
|
438
|
-
const parsed =
|
|
438
|
+
const parsed = parseSseChunk(buffer);
|
|
439
439
|
buffer = parsed.remainder;
|
|
440
440
|
for (const event of parsed.events) {
|
|
441
441
|
if (event === "[DONE]") {
|
|
@@ -547,7 +547,7 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
547
547
|
}
|
|
548
548
|
}
|
|
549
549
|
if (buffer.trim().length > 0) {
|
|
550
|
-
const parsed =
|
|
550
|
+
const parsed = parseSseChunk(`${buffer}\n\n`);
|
|
551
551
|
for (const event of parsed.events) {
|
|
552
552
|
if (event === "[DONE]") {
|
|
553
553
|
continue;
|
|
@@ -855,7 +855,7 @@ async function* streamGoogleCompatibleParts(stream) {
|
|
|
855
855
|
let usage;
|
|
856
856
|
for await (const chunk of stream) {
|
|
857
857
|
buffer += decoder.decode(chunk, { stream: true });
|
|
858
|
-
const parsed =
|
|
858
|
+
const parsed = parseSseChunk(buffer);
|
|
859
859
|
buffer = parsed.remainder;
|
|
860
860
|
for (const event of parsed.events) {
|
|
861
861
|
if (event === "[DONE]") {
|
|
@@ -902,7 +902,7 @@ async function* streamGoogleCompatibleParts(stream) {
|
|
|
902
902
|
}
|
|
903
903
|
}
|
|
904
904
|
if (buffer.trim().length > 0) {
|
|
905
|
-
const parsed =
|
|
905
|
+
const parsed = parseSseChunk(`${buffer}\n\n`);
|
|
906
906
|
for (const event of parsed.events) {
|
|
907
907
|
if (event === "[DONE]") {
|
|
908
908
|
continue;
|
|
@@ -947,29 +947,6 @@ function buildOpenAIGenerateResult(payload) {
|
|
|
947
947
|
usage: extractOpenAIUsage(payload),
|
|
948
948
|
};
|
|
949
949
|
}
|
|
950
|
-
function parseOpenAISseChunk(chunk) {
|
|
951
|
-
const blocks = chunk.split("\n\n");
|
|
952
|
-
const remainder = blocks.pop() ?? "";
|
|
953
|
-
const events = blocks.flatMap((block) => {
|
|
954
|
-
const dataLines = block.split("\n")
|
|
955
|
-
.filter((line) => line.startsWith("data:"))
|
|
956
|
-
.map((line) => line.slice(5).trimStart());
|
|
957
|
-
if (!dataLines.length) {
|
|
958
|
-
return [];
|
|
959
|
-
}
|
|
960
|
-
const payload = dataLines.join("\n").trim();
|
|
961
|
-
if (payload === "[DONE]") {
|
|
962
|
-
return ["[DONE]"];
|
|
963
|
-
}
|
|
964
|
-
try {
|
|
965
|
-
return [JSON.parse(payload)];
|
|
966
|
-
}
|
|
967
|
-
catch {
|
|
968
|
-
return [];
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
return { events, remainder };
|
|
972
|
-
}
|
|
973
950
|
async function* streamOpenAICompatibleParts(stream) {
|
|
974
951
|
const decoder = new TextDecoder();
|
|
975
952
|
let buffer = "";
|
|
@@ -978,7 +955,7 @@ async function* streamOpenAICompatibleParts(stream) {
|
|
|
978
955
|
let usage;
|
|
979
956
|
for await (const chunk of stream) {
|
|
980
957
|
buffer += decoder.decode(chunk, { stream: true });
|
|
981
|
-
const parsed =
|
|
958
|
+
const parsed = parseSseChunk(buffer);
|
|
982
959
|
buffer = parsed.remainder;
|
|
983
960
|
for (const event of parsed.events) {
|
|
984
961
|
if (event === "[DONE]") {
|
|
@@ -1040,7 +1017,7 @@ async function* streamOpenAICompatibleParts(stream) {
|
|
|
1040
1017
|
}
|
|
1041
1018
|
}
|
|
1042
1019
|
if (buffer.trim().length > 0) {
|
|
1043
|
-
const parsed =
|
|
1020
|
+
const parsed = parseSseChunk(`${buffer}\n\n`);
|
|
1044
1021
|
for (const event of parsed.events) {
|
|
1045
1022
|
if (event === "[DONE]") {
|
|
1046
1023
|
continue;
|
|
@@ -293,24 +293,32 @@ function createImportMapPlugin(projectDir, adapter, config) {
|
|
|
293
293
|
logger.debug(`Import map resolved: ${args.path} -> ${absolutePath}`);
|
|
294
294
|
return { path: absolutePath, namespace: "import-map" };
|
|
295
295
|
});
|
|
296
|
-
build.onLoad({ filter: /.*/, namespace: "import-map" },
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
contents,
|
|
301
|
-
loader: getLoaderForFile(filePath),
|
|
302
|
-
resolveDir: pathHelper.dirname(filePath),
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
307
|
-
logger.error(`Failed to load file via import map: ${args.path}`, error);
|
|
308
|
-
return { errors: [{ text: `Failed to load: ${msg}` }] };
|
|
309
|
-
}
|
|
296
|
+
build.onLoad({ filter: /.*/, namespace: "import-map" }, createNamespaceOnLoadHandler({
|
|
297
|
+
adapter,
|
|
298
|
+
projectDir,
|
|
299
|
+
errorLabel: "file via import map",
|
|
310
300
|
}));
|
|
311
301
|
},
|
|
312
302
|
};
|
|
313
303
|
}
|
|
304
|
+
function createNamespaceOnLoadHandler(options) {
|
|
305
|
+
const { adapter, projectDir, errorLabel } = options;
|
|
306
|
+
return wrapWithCurrentContext(async (args) => {
|
|
307
|
+
try {
|
|
308
|
+
const { filePath, contents } = await readFileWithExtensions(adapter, args.path, FILE_EXTENSIONS, projectDir);
|
|
309
|
+
return {
|
|
310
|
+
contents,
|
|
311
|
+
loader: getLoaderForFile(filePath),
|
|
312
|
+
resolveDir: pathHelper.dirname(filePath),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
317
|
+
logger.error(`Failed to load ${errorLabel}: ${args.path}`, error);
|
|
318
|
+
return { errors: [{ text: `Failed to load: ${msg}` }] };
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
314
322
|
/** Resolves relative imports through the adapter's virtual FS for remote projects. */
|
|
315
323
|
function createAdapterResolvePlugin(adapter, projectDir) {
|
|
316
324
|
return {
|
|
@@ -337,20 +345,10 @@ function createAdapterResolvePlugin(adapter, projectDir) {
|
|
|
337
345
|
// callbacks fire from the child process message handler, losing the
|
|
338
346
|
// AsyncLocalStorage store. Without this, MultiProjectFSAdapter.getAdapter()
|
|
339
347
|
// cannot resolve the per-project adapter and all file reads fail silently.
|
|
340
|
-
build.onLoad({ filter: /.*/, namespace: "vf-adapter" },
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
contents,
|
|
345
|
-
loader: getLoaderForFile(filePath),
|
|
346
|
-
resolveDir: pathHelper.dirname(filePath),
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
351
|
-
logger.error(`Failed to load via adapter: ${args.path}`, error);
|
|
352
|
-
return { errors: [{ text: `Failed to load: ${msg}` }] };
|
|
353
|
-
}
|
|
348
|
+
build.onLoad({ filter: /.*/, namespace: "vf-adapter" }, createNamespaceOnLoadHandler({
|
|
349
|
+
adapter,
|
|
350
|
+
projectDir,
|
|
351
|
+
errorLabel: "via adapter",
|
|
354
352
|
}));
|
|
355
353
|
},
|
|
356
354
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.154";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { INVALID_ARGUMENT } from "../errors/index.js";
|
|
4
|
+
import {
|
|
5
|
+
RunNotActiveError,
|
|
6
|
+
RunResumeSessionManager,
|
|
7
|
+
WaitConflictError,
|
|
8
|
+
WaitNotPendingError,
|
|
9
|
+
} from "./runtime/resume-session.js";
|
|
10
|
+
|
|
11
|
+
const RESUME_PATH_REGEX = /^\/api\/ag-ui\/runs\/([^/]+)\/resume$/;
|
|
12
|
+
const CANCEL_PATH_REGEX = /^\/api\/ag-ui\/runs\/([^/]+)$/;
|
|
13
|
+
|
|
14
|
+
export const AgUiResumeSignalSchema = z.discriminatedUnion("type", [
|
|
15
|
+
z.object({
|
|
16
|
+
type: z.literal("tool_result"),
|
|
17
|
+
toolCallId: z.string().min(1).max(128),
|
|
18
|
+
result: z.unknown(),
|
|
19
|
+
isError: z.boolean().optional().default(false),
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export type AgUiResumeSignal = z.infer<typeof AgUiResumeSignalSchema>;
|
|
24
|
+
|
|
25
|
+
type ResumeValue = {
|
|
26
|
+
result: unknown;
|
|
27
|
+
isError: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function isRequest(value: unknown): value is dntShim.Request {
|
|
31
|
+
return (
|
|
32
|
+
typeof value === "object" &&
|
|
33
|
+
value !== null &&
|
|
34
|
+
"json" in value &&
|
|
35
|
+
typeof value.json === "function" &&
|
|
36
|
+
"url" in value &&
|
|
37
|
+
typeof value.url === "string" &&
|
|
38
|
+
"method" in value &&
|
|
39
|
+
typeof value.method === "string"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function extractRequest(requestOrCtx: unknown): dntShim.Request {
|
|
44
|
+
if (isRequest(requestOrCtx)) return requestOrCtx;
|
|
45
|
+
|
|
46
|
+
if (typeof requestOrCtx === "object" && requestOrCtx !== null && "request" in requestOrCtx) {
|
|
47
|
+
const candidate = (requestOrCtx as Record<string, unknown>).request;
|
|
48
|
+
if (isRequest(candidate)) return candidate;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw INVALID_ARGUMENT.create({
|
|
52
|
+
detail: "Invalid handler argument: expected Request or APIContext",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getRunId(pathname: string, regex: RegExp): string | null {
|
|
57
|
+
return regex.exec(pathname)?.[1] ?? null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface AgUiRunControlHandlerOptions {
|
|
61
|
+
resolveRunId?:
|
|
62
|
+
| ((input: { request: dntShim.Request; requestOrCtx: unknown }) => string | null)
|
|
63
|
+
| ((input: { request: dntShim.Request; requestOrCtx: unknown }) => Promise<string | null>);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AgUiResumeHandlerOptions extends AgUiRunControlHandlerOptions {
|
|
67
|
+
sessionManager: RunResumeSessionManager<ResumeValue>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AgUiCancelHandlerOptions<T = unknown> extends AgUiRunControlHandlerOptions {
|
|
71
|
+
sessionManager: RunResumeSessionManager<T>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function resolveRunId(
|
|
75
|
+
requestOrCtx: unknown,
|
|
76
|
+
request: dntShim.Request,
|
|
77
|
+
options: AgUiRunControlHandlerOptions | undefined,
|
|
78
|
+
regex: RegExp,
|
|
79
|
+
): Promise<string | null> {
|
|
80
|
+
const explicit = await options?.resolveRunId?.({ request, requestOrCtx });
|
|
81
|
+
if (explicit) return explicit;
|
|
82
|
+
return getRunId(new URL(request.url).pathname, regex);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function createAgUiResumeHandler(
|
|
86
|
+
options: AgUiResumeHandlerOptions,
|
|
87
|
+
): (requestOrCtx: unknown) => Promise<dntShim.Response> {
|
|
88
|
+
return async function POST(requestOrCtx: unknown): Promise<dntShim.Response> {
|
|
89
|
+
const request = extractRequest(requestOrCtx);
|
|
90
|
+
const runId = await resolveRunId(requestOrCtx, request, options, RESUME_PATH_REGEX);
|
|
91
|
+
|
|
92
|
+
if (!runId) {
|
|
93
|
+
return dntShim.Response.json({ error: "Run not found" }, { status: 404 });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const parsed = AgUiResumeSignalSchema.parse(await request.json());
|
|
98
|
+
const outcome = options.sessionManager.submitSignal(runId, {
|
|
99
|
+
waitKey: parsed.toolCallId,
|
|
100
|
+
value: {
|
|
101
|
+
result: parsed.result,
|
|
102
|
+
isError: parsed.isError,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return dntShim.Response.json(outcome, { status: 200 });
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error instanceof z.ZodError) {
|
|
109
|
+
return dntShim.Response.json(
|
|
110
|
+
{
|
|
111
|
+
error: "Invalid AG-UI resume request",
|
|
112
|
+
details: error.issues.map((issue) => ({
|
|
113
|
+
path: issue.path,
|
|
114
|
+
message: issue.message,
|
|
115
|
+
})),
|
|
116
|
+
},
|
|
117
|
+
{ status: 400 },
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (error instanceof WaitConflictError) {
|
|
122
|
+
return dntShim.Response.json({ error: "TOOL_RESULT_CONFLICT" }, { status: 409 });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (error instanceof WaitNotPendingError) {
|
|
126
|
+
return dntShim.Response.json({ error: "TOOL_RESULT_NOT_WAITING" }, { status: 409 });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (error instanceof RunNotActiveError) {
|
|
130
|
+
return dntShim.Response.json({ error: "RUN_NOT_ACTIVE" }, { status: 410 });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return dntShim.Response.json(
|
|
134
|
+
{
|
|
135
|
+
error: error instanceof Error ? error.message : "Internal resume failed",
|
|
136
|
+
},
|
|
137
|
+
{ status: 500 },
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function createAgUiCancelHandler<T = unknown>(
|
|
144
|
+
options: AgUiCancelHandlerOptions<T>,
|
|
145
|
+
): (requestOrCtx: unknown) => Promise<dntShim.Response> {
|
|
146
|
+
return async function DELETE(requestOrCtx: unknown): Promise<dntShim.Response> {
|
|
147
|
+
const request = extractRequest(requestOrCtx);
|
|
148
|
+
const runId = await resolveRunId(requestOrCtx, request, options, CANCEL_PATH_REGEX);
|
|
149
|
+
|
|
150
|
+
if (!runId) {
|
|
151
|
+
return dntShim.Response.json({ error: "Run not found" }, { status: 404 });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const accepted = options.sessionManager.cancelRun(runId);
|
|
155
|
+
if (accepted) {
|
|
156
|
+
return dntShim.Response.json({ accepted: true }, { status: 202 });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return new dntShim.Response(null, { status: 204 });
|
|
160
|
+
};
|
|
161
|
+
}
|
package/src/src/agent/index.ts
CHANGED
|
@@ -135,6 +135,24 @@ export {
|
|
|
135
135
|
} from "./composition/index.js";
|
|
136
136
|
|
|
137
137
|
export { agent } from "./factory.js";
|
|
138
|
+
export {
|
|
139
|
+
type AgUiRuntimeContextItem,
|
|
140
|
+
AgUiRuntimeContextItemSchema,
|
|
141
|
+
type AgUiRuntimeInjectedTool,
|
|
142
|
+
AgUiRuntimeInjectedToolSchema,
|
|
143
|
+
type AgUiRuntimeMessage,
|
|
144
|
+
AgUiRuntimeMessageSchema,
|
|
145
|
+
type AgUiRuntimeRequest,
|
|
146
|
+
AgUiRuntimeRequestSchema,
|
|
147
|
+
} from "./runtime-ag-ui-contract.js";
|
|
148
|
+
export {
|
|
149
|
+
type AgUiCancelHandlerOptions,
|
|
150
|
+
type AgUiResumeHandlerOptions,
|
|
151
|
+
type AgUiResumeSignal,
|
|
152
|
+
AgUiResumeSignalSchema,
|
|
153
|
+
createAgUiCancelHandler,
|
|
154
|
+
createAgUiResumeHandler,
|
|
155
|
+
} from "./ag-ui-run-control.js";
|
|
138
156
|
export {
|
|
139
157
|
type AgUiContextItem,
|
|
140
158
|
type AgUiHandlerConfigWithAgent,
|