veryfront 0.1.220 → 0.1.222

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.
Files changed (44) hide show
  1. package/esm/deno.d.ts +0 -3
  2. package/esm/deno.js +1 -4
  3. package/esm/src/agent/ag-ui-detached-start.d.ts.map +1 -1
  4. package/esm/src/agent/ag-ui-detached-start.js +2 -77
  5. package/esm/src/agent/ag-ui-handler.d.ts +1 -66
  6. package/esm/src/agent/ag-ui-handler.d.ts.map +1 -1
  7. package/esm/src/agent/ag-ui-handler.js +8 -136
  8. package/esm/src/agent/ag-ui-host-support.d.ts +76 -0
  9. package/esm/src/agent/ag-ui-host-support.d.ts.map +1 -0
  10. package/esm/src/agent/ag-ui-host-support.js +182 -0
  11. package/esm/src/agent/index.d.ts +2 -1
  12. package/esm/src/agent/index.d.ts.map +1 -1
  13. package/esm/src/agent/index.js +2 -1
  14. package/esm/src/agent/runtime-ag-ui-contract.d.ts +2 -0
  15. package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -1
  16. package/esm/src/agent/runtime-ag-ui-contract.js +26 -0
  17. package/esm/src/platform/compat/media-types.d.ts.map +1 -1
  18. package/esm/src/platform/compat/media-types.js +6 -6
  19. package/esm/src/react/components/chat/theme.d.ts +1 -1
  20. package/esm/src/react/components/chat/theme.d.ts.map +1 -1
  21. package/esm/src/react/components/chat/theme.js +1 -1
  22. package/esm/src/server/handlers/dev/framework-candidates.generated.d.ts.map +1 -1
  23. package/esm/src/server/handlers/dev/framework-candidates.generated.js +1 -0
  24. package/esm/src/utils/clsx.d.ts +14 -0
  25. package/esm/src/utils/clsx.d.ts.map +1 -0
  26. package/esm/src/utils/clsx.js +32 -0
  27. package/esm/src/utils/mime-types.d.ts +42 -0
  28. package/esm/src/utils/mime-types.d.ts.map +1 -0
  29. package/esm/src/utils/mime-types.js +148 -0
  30. package/esm/src/utils/version-constant.d.ts +1 -1
  31. package/esm/src/utils/version-constant.js +1 -1
  32. package/package.json +1 -3
  33. package/src/deno.js +1 -4
  34. package/src/src/agent/ag-ui-detached-start.ts +7 -93
  35. package/src/src/agent/ag-ui-handler.ts +23 -176
  36. package/src/src/agent/ag-ui-host-support.ts +238 -0
  37. package/src/src/agent/index.ts +10 -0
  38. package/src/src/agent/runtime-ag-ui-contract.ts +37 -0
  39. package/src/src/platform/compat/media-types.ts +10 -6
  40. package/src/src/react/components/chat/theme.ts +1 -1
  41. package/src/src/server/handlers/dev/framework-candidates.generated.ts +1 -0
  42. package/src/src/utils/clsx.ts +40 -0
  43. package/src/src/utils/mime-types.ts +155 -0
  44. package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.d.ts CHANGED
@@ -212,7 +212,6 @@ declare namespace _default {
212
212
  "@std/fs": string;
213
213
  "@std/async": string;
214
214
  "@std/front-matter/yaml": string;
215
- csstype: string;
216
215
  "@types/react": string;
217
216
  "@types/react-dom": string;
218
217
  react: string;
@@ -241,7 +240,6 @@ declare namespace _default {
241
240
  "es-module-lexer": string;
242
241
  "gray-matter": string;
243
242
  zod: string;
244
- "mime-types": string;
245
243
  mdast: string;
246
244
  hast: string;
247
245
  unist: string;
@@ -263,7 +261,6 @@ declare namespace _default {
263
261
  "@babel/generator": string;
264
262
  "@babel/types": string;
265
263
  "class-variance-authority": string;
266
- clsx: string;
267
264
  "tailwind-merge": string;
268
265
  "@kreuzberg/wasm": string;
269
266
  "#kreuzberg-wasm-glue": string;
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.220",
3
+ "version": "0.1.222",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -225,7 +225,6 @@ export default {
225
225
  "@std/fs": "jsr:@std/fs",
226
226
  "@std/async": "jsr:@std/async",
227
227
  "@std/front-matter/yaml": "./src/platform/compat/std/front-matter-yaml.ts",
228
- "csstype": "https://esm.sh/csstype@3.2.3",
229
228
  "@types/react": "https://esm.sh/@types/react@18.3.27?deps=csstype@3.2.3",
230
229
  "@types/react-dom": "https://esm.sh/@types/react-dom@18.3.7?deps=csstype@3.2.3",
231
230
  "react": "https://esm.sh/react@19.2.4?target=es2022&deps=csstype@3.2.3",
@@ -254,7 +253,6 @@ export default {
254
253
  "es-module-lexer": "npm:es-module-lexer@2.0.0",
255
254
  "gray-matter": "npm:gray-matter@4.0.3",
256
255
  "zod": "npm:zod@4.3.6",
257
- "mime-types": "npm:mime-types@3.0.2",
258
256
  "mdast": "npm:@types/mdast@4.0.3",
259
257
  "hast": "npm:@types/hast@3.0.3",
260
258
  "unist": "npm:@types/unist@3.0.2",
@@ -276,7 +274,6 @@ export default {
276
274
  "@babel/generator": "npm:@babel/generator@7.29.1",
277
275
  "@babel/types": "npm:@babel/types@7.29.0",
278
276
  "class-variance-authority": "npm:class-variance-authority@0.7.1",
279
- "clsx": "npm:clsx@2.1.1",
280
277
  "tailwind-merge": "npm:tailwind-merge@3.5.0",
281
278
  "@kreuzberg/wasm": "npm:@kreuzberg/wasm@4.5.2",
282
279
  "#kreuzberg-wasm-glue": "npm:@kreuzberg/wasm@4.5.2/dist/pkg/kreuzberg_wasm.js"
@@ -1 +1 @@
1
- {"version":3,"file":"ag-ui-detached-start.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-detached-start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM,YAAY,CAAC;AAMjD,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,gBAAgB,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAA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,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAChF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAChG;AAED,MAAM,MAAM,+BAA+B,GACvC,CAAC,mCAAmC,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,GACxD,CAAC,mCAAmC,GAAG;IACvC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,sBAAsB,EAAE,4BAA4B,CAAC;CACtD,CAAC,CAAC;AA0BL,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAwH9C"}
@@ -3,85 +3,10 @@ import { INVALID_ARGUMENT } from "../errors/index.js";
3
3
  import { SKILL_TOOL_IDS } from "../skill/types.js";
4
4
  import { toolRegistry } from "../tool/index.js";
5
5
  import { streamDataStreamEvents } from "./data-stream.js";
6
- import { AgUiRequestSchema } from "./ag-ui-handler.js";
6
+ import { AgUiRequestSchema, normalizeAgUiMessages, } from "./ag-ui-host-support.js";
7
7
  import { AgentRuntime, RunAlreadyExistsError, } from "./runtime/index.js";
8
8
  const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
9
9
  const AG_UI_DETACHED_RUN_ID_SCHEMA = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
10
- const MAX_TEXT_PART_LENGTH = 10_000;
11
- function isRecord(value) {
12
- return typeof value === "object" && value !== null && !Array.isArray(value);
13
- }
14
- function normalizeToolArgs(part) {
15
- if (isRecord(part.args))
16
- return part.args;
17
- if (isRecord(part.input))
18
- return part.input;
19
- return {};
20
- }
21
- function normalizeMessagePart(part) {
22
- if (part.type === "text" && typeof part.text === "string" &&
23
- part.text.length <= MAX_TEXT_PART_LENGTH) {
24
- return { type: "text", text: part.text };
25
- }
26
- if (part.type === "tool_call" && typeof part.id === "string" && typeof part.name === "string") {
27
- return {
28
- type: "tool-call",
29
- toolCallId: part.id,
30
- toolName: part.name,
31
- args: normalizeToolArgs(part),
32
- };
33
- }
34
- if (part.type === "tool-call" &&
35
- typeof part.toolCallId === "string" &&
36
- typeof part.toolName === "string") {
37
- return {
38
- type: "tool-call",
39
- toolCallId: part.toolCallId,
40
- toolName: part.toolName,
41
- args: normalizeToolArgs(part),
42
- };
43
- }
44
- if (typeof part.type === "string" &&
45
- part.type.startsWith("tool-") &&
46
- part.type !== "tool-result" &&
47
- typeof part.toolCallId === "string" &&
48
- typeof part.toolName === "string") {
49
- return {
50
- type: part.type,
51
- toolCallId: part.toolCallId,
52
- toolName: part.toolName,
53
- args: normalizeToolArgs(part),
54
- };
55
- }
56
- if (part.type === "tool_result" && typeof part.tool_call_id === "string") {
57
- return {
58
- type: "tool-result",
59
- toolCallId: part.tool_call_id,
60
- toolName: typeof part.tool_name === "string" ? part.tool_name : "unknown",
61
- result: "output" in part ? part.output : undefined,
62
- };
63
- }
64
- if (part.type === "tool-result" && typeof part.toolCallId === "string") {
65
- return {
66
- type: "tool-result",
67
- toolCallId: part.toolCallId,
68
- toolName: typeof part.toolName === "string" ? part.toolName : "unknown",
69
- result: "result" in part ? part.result : undefined,
70
- };
71
- }
72
- return null;
73
- }
74
- function normalizeMessages(messages) {
75
- return messages.map((message) => ({
76
- id: message.id,
77
- role: message.role,
78
- parts: message.parts
79
- .map((part) => normalizeMessagePart(part))
80
- .filter((part) => part !== null),
81
- ...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
82
- ...(message.metadata ? { metadata: message.metadata } : {}),
83
- }));
84
- }
85
10
  function isRequest(obj) {
86
11
  return (typeof obj === "object" &&
87
12
  obj !== null &&
@@ -195,7 +120,7 @@ async function startDefaultDetachedExecution(input) {
195
120
  ...input.agent.config,
196
121
  tools: buildMergedTools(input.agent, input.request, input.sessionManager),
197
122
  });
198
- const runtimeStream = await runtime.stream(normalizeMessages(input.request.messages), buildStreamContext(input.request, input.context, input.request.threadId, input.request.runId), undefined, input.request.model, input.request.maxOutputTokens, input.abortSignal);
123
+ const runtimeStream = await runtime.stream(normalizeAgUiMessages(input.request.messages), buildStreamContext(input.request, input.context, input.request.threadId, input.request.runId), undefined, input.request.model, input.request.maxOutputTokens, input.abortSignal);
199
124
  await drainRuntimeStream(runtimeStream);
200
125
  }
201
126
  export function createAgUiDetachedStartHandler(options) {
@@ -1,70 +1,6 @@
1
- import { z } from "zod";
2
1
  import type { Agent } from "./types.js";
3
2
  import { type RunResumeSessionManager } from "./runtime/index.js";
4
- declare const AgUiInjectedToolSchema: z.ZodObject<{
5
- name: z.ZodString;
6
- description: z.ZodOptional<z.ZodString>;
7
- parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
8
- }, z.core.$strip>;
9
- declare const AgUiContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
- type: z.ZodLiteral<"text">;
11
- title: z.ZodOptional<z.ZodString>;
12
- text: z.ZodString;
13
- }, z.core.$strip>, z.ZodObject<{
14
- type: z.ZodLiteral<"json">;
15
- title: z.ZodOptional<z.ZodString>;
16
- data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
17
- }, z.core.$strip>, z.ZodObject<{
18
- type: z.ZodLiteral<"resource">;
19
- title: z.ZodOptional<z.ZodString>;
20
- uri: z.ZodString;
21
- mimeType: z.ZodOptional<z.ZodString>;
22
- text: z.ZodOptional<z.ZodString>;
23
- }, z.core.$strip>], "type">;
24
- export declare const AgUiRequestSchema: z.ZodObject<{
25
- threadId: z.ZodOptional<z.ZodString>;
26
- runId: z.ZodOptional<z.ZodString>;
27
- messages: z.ZodArray<z.ZodObject<{
28
- id: z.ZodString;
29
- role: z.ZodEnum<{
30
- tool: "tool";
31
- user: "user";
32
- assistant: "assistant";
33
- system: "system";
34
- }>;
35
- parts: z.ZodDefault<z.ZodArray<z.ZodObject<{
36
- type: z.ZodString;
37
- }, z.core.$loose>>>;
38
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
39
- createdAt: z.ZodOptional<z.ZodString>;
40
- }, z.core.$strip>>;
41
- tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
42
- name: z.ZodString;
43
- description: z.ZodOptional<z.ZodString>;
44
- parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
- }, z.core.$strip>>>;
46
- context: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
47
- type: z.ZodLiteral<"text">;
48
- title: z.ZodOptional<z.ZodString>;
49
- text: z.ZodString;
50
- }, z.core.$strip>, z.ZodObject<{
51
- type: z.ZodLiteral<"json">;
52
- title: z.ZodOptional<z.ZodString>;
53
- data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
54
- }, z.core.$strip>, z.ZodObject<{
55
- type: z.ZodLiteral<"resource">;
56
- title: z.ZodOptional<z.ZodString>;
57
- uri: z.ZodString;
58
- mimeType: z.ZodOptional<z.ZodString>;
59
- text: z.ZodOptional<z.ZodString>;
60
- }, z.core.$strip>], "type">>>;
61
- forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
62
- model: z.ZodOptional<z.ZodString>;
63
- maxOutputTokens: z.ZodOptional<z.ZodNumber>;
64
- }, z.core.$strip>;
65
- export type AgUiInjectedTool = z.infer<typeof AgUiInjectedToolSchema>;
66
- export type AgUiContextItem = z.infer<typeof AgUiContextItemSchema>;
67
- export type AgUiRequest = z.infer<typeof AgUiRequestSchema>;
3
+ export { type AgUiContextItem, AgUiContextItemSchema, type AgUiInjectedTool, AgUiInjectedToolSchema, type AgUiRequest, AgUiRequestSchema, } from "./ag-ui-host-support.js";
68
4
  type AgUiResumeValue = {
69
5
  result: unknown;
70
6
  isError: boolean;
@@ -78,5 +14,4 @@ export interface AgUiHandlerConfigWithAgent extends AgUiHandlerOptions {
78
14
  }
79
15
  export declare function createAgUiHandler(agentId: string, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise<Response>;
80
16
  export declare function createAgUiHandler(config: AgUiHandlerConfigWithAgent, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise<Response>;
81
- export {};
82
17
  //# sourceMappingURL=ag-ui-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ag-ui-handler.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM,YAAY,CAAC;AACjD,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAsC5B,QAAA,MAAM,sBAAsB;;;;iBAO1B,CAAC;AAEH,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;2BAqBzB,CAAC;AAYH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAe5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAyY7D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,CAAC,OAAO,EAAE,O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AC,CAAC;IACvF,cAAc,CAAC,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,KAAK,EAAE,KAAK,CAAC;CACd;AAUD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,0BAA0B,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC"}
@@ -7,144 +7,13 @@ import { SKILL_TOOL_IDS } from "../skill/types.js";
7
7
  import { toolRegistry } from "../tool/index.js";
8
8
  import { createStreamTransformState, finalizeRunEvents, formatAgUiEvent, mapRuntimeEventToAgUi, } from "../internal-agents/ag-ui-sse.js";
9
9
  import { streamDataStreamEvents } from "./data-stream.js";
10
- const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
11
- const MAX_TOOL_PARAMETERS_BYTES = 16_384;
12
- const MAX_CONTEXT_ITEM_BYTES = 16_384;
13
- const MAX_CONTEXT_TOTAL_BYTES = 65_536;
14
- const MAX_FORWARDED_PROPS_BYTES = 65_536;
15
- const MAX_TEXT_PART_LENGTH = 10_000;
16
- const MAX_MESSAGES_PER_REQUEST = 100;
17
- const encoder = new TextEncoder();
10
+ import { normalizeAgUiMessages, parseAgUiRequestOrError, } from "./ag-ui-host-support.js";
11
+ export { AgUiContextItemSchema, AgUiInjectedToolSchema, AgUiRequestSchema, } from "./ag-ui-host-support.js";
18
12
  const AG_UI_HEADERS = {
19
13
  "Content-Type": "text/event-stream",
20
14
  "Cache-Control": "no-cache",
21
15
  Connection: "keep-alive",
22
16
  };
23
- function isWithinJsonSizeLimit(value, maxBytes) {
24
- try {
25
- return encoder.encode(JSON.stringify(value)).byteLength <= maxBytes;
26
- }
27
- catch {
28
- return false;
29
- }
30
- }
31
- const AgUiRunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
32
- const AgUiInjectedToolSchema = z.object({
33
- name: z.string().min(1).max(128),
34
- description: z.string().max(1024).optional(),
35
- 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" }),
36
- });
37
- const AgUiContextItemSchema = z.discriminatedUnion("type", [
38
- z.object({
39
- type: z.literal("text"),
40
- title: z.string().max(256).optional(),
41
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
42
- }),
43
- z.object({
44
- type: z.literal("json"),
45
- title: z.string().max(256).optional(),
46
- 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" }),
47
- }),
48
- z.object({
49
- type: z.literal("resource"),
50
- title: z.string().max(256).optional(),
51
- uri: z.string().max(2048),
52
- mimeType: z.string().max(256).optional(),
53
- text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
54
- }),
55
- ]);
56
- const AgUiMessagePartSchema = z.object({ type: z.string().min(1) }).passthrough();
57
- const AgUiMessageSchema = z.object({
58
- id: z.string().min(1),
59
- role: z.enum(["user", "assistant", "system", "tool"]),
60
- parts: z.array(AgUiMessagePartSchema).default([]),
61
- metadata: z.record(z.string(), z.unknown()).optional(),
62
- createdAt: z.string().optional(),
63
- });
64
- export const AgUiRequestSchema = z.object({
65
- threadId: z.string().uuid().optional(),
66
- runId: AgUiRunIdSchema.optional(),
67
- messages: z.array(AgUiMessageSchema).min(1).max(MAX_MESSAGES_PER_REQUEST),
68
- tools: z.array(AgUiInjectedToolSchema).max(50).default([]),
69
- context: z.array(AgUiContextItemSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
70
- 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" }),
71
- model: z.string().optional(),
72
- maxOutputTokens: z.number().int().positive().optional(),
73
- });
74
- function isRecord(value) {
75
- return typeof value === "object" && value !== null && !Array.isArray(value);
76
- }
77
- function normalizeToolArgs(part) {
78
- if (isRecord(part.args))
79
- return part.args;
80
- if (isRecord(part.input))
81
- return part.input;
82
- return {};
83
- }
84
- function normalizeMessagePart(part) {
85
- if (part.type === "text" && typeof part.text === "string" &&
86
- part.text.length <= MAX_TEXT_PART_LENGTH) {
87
- return { type: "text", text: part.text };
88
- }
89
- if (part.type === "tool_call" && typeof part.id === "string" && typeof part.name === "string") {
90
- return {
91
- type: "tool-call",
92
- toolCallId: part.id,
93
- toolName: part.name,
94
- args: normalizeToolArgs(part),
95
- };
96
- }
97
- if (part.type === "tool-call" &&
98
- typeof part.toolCallId === "string" &&
99
- typeof part.toolName === "string") {
100
- return {
101
- type: "tool-call",
102
- toolCallId: part.toolCallId,
103
- toolName: part.toolName,
104
- args: normalizeToolArgs(part),
105
- };
106
- }
107
- if (typeof part.type === "string" &&
108
- part.type.startsWith("tool-") &&
109
- part.type !== "tool-result" &&
110
- typeof part.toolCallId === "string" &&
111
- typeof part.toolName === "string") {
112
- return {
113
- type: part.type,
114
- toolCallId: part.toolCallId,
115
- toolName: part.toolName,
116
- args: normalizeToolArgs(part),
117
- };
118
- }
119
- if (part.type === "tool_result" && typeof part.tool_call_id === "string") {
120
- return {
121
- type: "tool-result",
122
- toolCallId: part.tool_call_id,
123
- toolName: typeof part.tool_name === "string" ? part.tool_name : "unknown",
124
- result: "output" in part ? part.output : undefined,
125
- };
126
- }
127
- if (part.type === "tool-result" && typeof part.toolCallId === "string") {
128
- return {
129
- type: "tool-result",
130
- toolCallId: part.toolCallId,
131
- toolName: typeof part.toolName === "string" ? part.toolName : "unknown",
132
- result: "result" in part ? part.result : undefined,
133
- };
134
- }
135
- return null;
136
- }
137
- function normalizeMessages(messages) {
138
- return messages.map((message) => ({
139
- id: message.id,
140
- role: message.role,
141
- parts: message.parts
142
- .map((part) => normalizeMessagePart(part))
143
- .filter((part) => part !== null),
144
- ...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
145
- ...(message.metadata ? { metadata: message.metadata } : {}),
146
- }));
147
- }
148
17
  function isRequest(obj) {
149
18
  return (typeof obj === "object" &&
150
19
  obj !== null &&
@@ -270,7 +139,7 @@ async function createAgUiDirectStreamResponse(agent, request, baseContext) {
270
139
  const runId = request.runId ?? generateRunId();
271
140
  await agent.clearMemory();
272
141
  const result = await agent.stream({
273
- messages: normalizeMessages(request.messages),
142
+ messages: normalizeAgUiMessages(request.messages),
274
143
  context: buildStreamContext(request, baseContext, threadId, runId),
275
144
  ...(request.model ? { model: request.model } : {}),
276
145
  ...(request.maxOutputTokens ? { maxOutputTokens: request.maxOutputTokens } : {}),
@@ -339,7 +208,7 @@ async function createAgUiInjectedToolsStreamResponse(agent, request, baseContext
339
208
  });
340
209
  let upstreamBody;
341
210
  try {
342
- upstreamBody = await runtime.stream(normalizeMessages(request.messages), buildStreamContext(request, baseContext, threadId, runId), undefined, request.model, request.maxOutputTokens);
211
+ upstreamBody = await runtime.stream(normalizeAgUiMessages(request.messages), buildStreamContext(request, baseContext, threadId, runId), undefined, request.model, request.maxOutputTokens);
343
212
  }
344
213
  catch (error) {
345
214
  sessionManager.failRun(runId);
@@ -392,7 +261,10 @@ export function createAgUiHandler(agentIdOrConfig, options) {
392
261
  return Response.json({ error: "Agent not found" }, { status: 404 });
393
262
  }
394
263
  try {
395
- const parsed = AgUiRequestSchema.parse(await request.json());
264
+ const parsed = await parseAgUiRequestOrError(request);
265
+ if (parsed instanceof Response) {
266
+ return parsed;
267
+ }
396
268
  if (parsed.tools.length > 0) {
397
269
  if (!options?.sessionManager) {
398
270
  return Response.json({
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import type { Message } from "./types.js";
3
+ export interface AgUiSseEvent {
4
+ event: string;
5
+ payload: Record<string, unknown>;
6
+ }
7
+ export declare const AgUiInjectedToolSchema: z.ZodObject<{
8
+ name: z.ZodString;
9
+ description: z.ZodOptional<z.ZodString>;
10
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
11
+ }, z.core.$strip>;
12
+ export declare const AgUiContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
13
+ type: z.ZodLiteral<"text">;
14
+ title: z.ZodOptional<z.ZodString>;
15
+ text: z.ZodString;
16
+ }, z.core.$strip>, z.ZodObject<{
17
+ type: z.ZodLiteral<"json">;
18
+ title: z.ZodOptional<z.ZodString>;
19
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"resource">;
22
+ title: z.ZodOptional<z.ZodString>;
23
+ uri: z.ZodString;
24
+ mimeType: z.ZodOptional<z.ZodString>;
25
+ text: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strip>], "type">;
27
+ export declare const AgUiRequestSchema: z.ZodObject<{
28
+ threadId: z.ZodOptional<z.ZodString>;
29
+ runId: z.ZodOptional<z.ZodString>;
30
+ messages: z.ZodArray<z.ZodObject<{
31
+ id: z.ZodString;
32
+ role: z.ZodEnum<{
33
+ tool: "tool";
34
+ user: "user";
35
+ assistant: "assistant";
36
+ system: "system";
37
+ }>;
38
+ parts: z.ZodDefault<z.ZodArray<z.ZodObject<{
39
+ type: z.ZodString;
40
+ }, z.core.$loose>>>;
41
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ createdAt: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strip>>;
44
+ tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
45
+ name: z.ZodString;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
48
+ }, z.core.$strip>>>;
49
+ context: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
50
+ type: z.ZodLiteral<"text">;
51
+ title: z.ZodOptional<z.ZodString>;
52
+ text: z.ZodString;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ type: z.ZodLiteral<"json">;
55
+ title: z.ZodOptional<z.ZodString>;
56
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
57
+ }, z.core.$strip>, z.ZodObject<{
58
+ type: z.ZodLiteral<"resource">;
59
+ title: z.ZodOptional<z.ZodString>;
60
+ uri: z.ZodString;
61
+ mimeType: z.ZodOptional<z.ZodString>;
62
+ text: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strip>], "type">>>;
64
+ forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
65
+ model: z.ZodOptional<z.ZodString>;
66
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
67
+ }, z.core.$strip>;
68
+ export type AgUiInjectedTool = z.infer<typeof AgUiInjectedToolSchema>;
69
+ export type AgUiContextItem = z.infer<typeof AgUiContextItemSchema>;
70
+ export type AgUiRequest = z.infer<typeof AgUiRequestSchema>;
71
+ export declare function parseAgUiRequest(request: Request): Promise<AgUiRequest>;
72
+ export declare function parseAgUiRequestOrError(request: Request): Promise<AgUiRequest | Response>;
73
+ export declare function normalizeAgUiMessages(messages: AgUiRequest["messages"]): Message[];
74
+ export declare function createAgUiRunErrorEvent(message: string, code?: string): AgUiSseEvent;
75
+ export declare function createAgUiSseErrorResponse(event: AgUiSseEvent, status: number): Response;
76
+ //# sourceMappingURL=ag-ui-host-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ag-ui-host-support.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-host-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,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