veryfront 0.1.1136 → 0.1.1143

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 (60) hide show
  1. package/esm/deno.js +8 -8
  2. package/esm/src/agent/hosted/chat-request-parser.d.ts.map +1 -1
  3. package/esm/src/agent/hosted/chat-request-parser.js +101 -1
  4. package/esm/src/agent/hosted/chat-request-tool-part.d.ts +11 -0
  5. package/esm/src/agent/hosted/chat-request-tool-part.d.ts.map +1 -0
  6. package/esm/src/agent/hosted/chat-request-tool-part.js +19 -0
  7. package/esm/src/agent/hosted/chat-request.d.ts +24 -0
  8. package/esm/src/agent/hosted/chat-request.d.ts.map +1 -1
  9. package/esm/src/agent/hosted/chat-request.js +298 -2
  10. package/esm/src/chat/conversation.d.ts +35 -2
  11. package/esm/src/chat/conversation.d.ts.map +1 -1
  12. package/esm/src/chat/conversation.js +323 -44
  13. package/esm/src/chat/message-prep.d.ts.map +1 -1
  14. package/esm/src/chat/message-prep.js +24 -6
  15. package/esm/src/html/hydration-script-builder/hydration-data-generator.d.ts.map +1 -1
  16. package/esm/src/html/hydration-script-builder/hydration-data-generator.js +3 -0
  17. package/esm/src/html/hydration-script-builder/templates/renderer.d.ts.map +1 -1
  18. package/esm/src/html/hydration-script-builder/templates/renderer.js +23 -0
  19. package/esm/src/html/hydration-script-builder/templates/router.d.ts.map +1 -1
  20. package/esm/src/html/hydration-script-builder/templates/router.js +23 -0
  21. package/esm/src/html/hydration-script-builder/types.d.ts +2 -0
  22. package/esm/src/html/hydration-script-builder/types.d.ts.map +1 -1
  23. package/esm/src/html/schemas/html.schema.d.ts +4 -0
  24. package/esm/src/html/schemas/html.schema.d.ts.map +1 -1
  25. package/esm/src/html/schemas/html.schema.js +2 -0
  26. package/esm/src/middleware/core/pipeline/pipeline.d.ts +21 -0
  27. package/esm/src/middleware/core/pipeline/pipeline.d.ts.map +1 -1
  28. package/esm/src/middleware/core/pipeline/pipeline.js +150 -4
  29. package/esm/src/react/compat/ssr-adapter/stream-renderer.d.ts.map +1 -1
  30. package/esm/src/react/compat/ssr-adapter/stream-renderer.js +14 -2
  31. package/esm/src/react/compat/ssr-adapter/types.d.ts +1 -0
  32. package/esm/src/react/compat/ssr-adapter/types.d.ts.map +1 -1
  33. package/esm/src/rendering/app-reserved.d.ts +10 -1
  34. package/esm/src/rendering/app-reserved.d.ts.map +1 -1
  35. package/esm/src/rendering/app-reserved.js +13 -3
  36. package/esm/src/rendering/orchestrator/html.d.ts +15 -0
  37. package/esm/src/rendering/orchestrator/html.d.ts.map +1 -1
  38. package/esm/src/rendering/orchestrator/html.js +66 -1
  39. package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
  40. package/esm/src/rendering/orchestrator/pipeline.js +16 -0
  41. package/esm/src/rendering/orchestrator/ssr-orchestrator.d.ts +10 -1
  42. package/esm/src/rendering/orchestrator/ssr-orchestrator.d.ts.map +1 -1
  43. package/esm/src/rendering/orchestrator/ssr-orchestrator.js +104 -9
  44. package/esm/src/rendering/orchestrator/ssr.d.ts.map +1 -1
  45. package/esm/src/rendering/orchestrator/ssr.js +1 -0
  46. package/esm/src/rendering/orchestrator/types.d.ts +4 -0
  47. package/esm/src/rendering/orchestrator/types.d.ts.map +1 -1
  48. package/esm/src/rendering/renderer.d.ts.map +1 -1
  49. package/esm/src/rendering/renderer.js +1 -0
  50. package/esm/src/rendering/ssr-globals/dom-stubs.d.ts +2 -9
  51. package/esm/src/rendering/ssr-globals/dom-stubs.d.ts.map +1 -1
  52. package/esm/src/rendering/ssr-globals/dom-stubs.js +5 -7
  53. package/esm/src/rendering/ssr-renderer.d.ts.map +1 -1
  54. package/esm/src/rendering/ssr-renderer.js +8 -2
  55. package/esm/src/server/services/rendering/ssr.service.d.ts +1 -1
  56. package/esm/src/server/services/rendering/ssr.service.d.ts.map +1 -1
  57. package/esm/src/server/services/rendering/ssr.service.js +115 -18
  58. package/esm/src/utils/version-constant.d.ts +1 -1
  59. package/esm/src/utils/version-constant.js +1 -1
  60. package/package.json +5 -5
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.1136",
3
+ "version": "0.1.1143",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": {
@@ -406,14 +406,14 @@ export default {
406
406
  "build": "deno task build:prepare && deno run -A scripts/build/compile-binary.ts --output ./bin/veryfront",
407
407
  "build:npm": "deno run -A scripts/build/generate-integrations-module.ts && deno task generate && deno run -A scripts/build/build-npm-dnt.ts",
408
408
  "release": "deno run -A scripts/release.ts",
409
- "test": "deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' --unstable-worker-options --unstable-net",
410
- "test:unit": "deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all --v8-flags=--max-old-space-size=8192 '--ignore=tests,src/workflow/__tests__' --unstable-worker-options --unstable-net $(find src cli -name '*.test.ts*' ! -name '*.integration.test.ts*')",
411
- "test:integration": "deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' tests --unstable-worker-options --unstable-net",
412
- "test:integration:cli": "VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --no-check --parallel --allow-all --unstable-worker-options --unstable-net $(find cli -name '*.integration.test.ts')",
409
+ "test": "deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' --unstable-worker-options --unstable-net",
410
+ "test:unit": "deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all --v8-flags=--max-old-space-size=8192 '--ignore=tests,src/workflow/__tests__' --unstable-worker-options --unstable-net $(find src cli -name '*.test.ts*' ! -name '*.integration.test.ts*')",
411
+ "test:integration": "deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --allow-all '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' tests --unstable-worker-options --unstable-net",
412
+ "test:integration:cli": "DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --no-check --parallel --allow-all --unstable-worker-options --unstable-net $(find cli -name '*.integration.test.ts')",
413
413
  "test:record": "VCR=record deno test --no-check --allow-all $(find cli -name '*.integration.test.ts' -path '*/commands/*')",
414
- "test:coverage": "rm -rf coverage && deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests/integration/compiled-binary-e2e.test.ts' --unstable-worker-options --unstable-net || exit 1",
415
- "test:coverage:unit": "rm -rf coverage && deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests,src/workflow/__tests__' --unstable-worker-options --unstable-net $(find src cli -name '*.test.ts*' ! -name '*.integration.test.ts*') || exit 1",
416
- "test:coverage:integration": "rm -rf coverage && deno task generate && VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' tests --unstable-worker-options --unstable-net || exit 1",
414
+ "test:coverage": "rm -rf coverage && deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests/integration/compiled-binary-e2e.test.ts' --unstable-worker-options --unstable-net || exit 1",
415
+ "test:coverage:unit": "rm -rf coverage && deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests,src/workflow/__tests__' --unstable-worker-options --unstable-net $(find src cli -name '*.test.ts*' ! -name '*.integration.test.ts*') || exit 1",
416
+ "test:coverage:integration": "rm -rf coverage && deno task generate && DENO_TESTING=1 VF_DISABLE_LRU_INTERVAL=1 SSR_TRANSFORM_PER_PROJECT_LIMIT=0 REVALIDATION_PER_PROJECT_LIMIT=0 NODE_ENV=production LOG_FORMAT=text deno test --preload=src/schemas/_test-setup.ts --no-check --parallel --fail-fast --allow-all --v8-flags=--max-old-space-size=8192 --coverage=coverage '--ignore=tests/e2e,tests/integration/compiled-binary-e2e.test.ts' tests --unstable-worker-options --unstable-net || exit 1",
417
417
  "coverage:report": "deno coverage coverage --include=src/ --exclude=tests '--exclude=src/**/*_test.ts' '--exclude=src/**/*_test.tsx' '--exclude=src/**/*.test.ts' '--exclude=src/**/*.test.tsx' --lcov > coverage/lcov.info && deno run --allow-read scripts/lint/check-coverage.ts 80",
418
418
  "coverage:gate": "deno coverage coverage --include=src/ --exclude=tests '--exclude=src/**/*_test.ts' '--exclude=src/**/*_test.tsx' '--exclude=src/**/*.test.ts' '--exclude=src/**/*.test.tsx' --lcov > coverage/lcov.info && deno run --allow-read scripts/lint/check-coverage.ts 80",
419
419
  "coverage:ci:shard": "deno run --allow-read --allow-write --allow-run --allow-env scripts/test/coverage-ci.ts shard",
@@ -1 +1 @@
1
- {"version":3,"file":"chat-request-parser.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/hosted/chat-request-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO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C;CAC5E,GAAG,OAAO,CAAC,uBAAuB,GAAG,QAAQ,CAAC,CAuE9C;AAED,0DAA0D;AAC1D,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,uBAAuB,GAAG,QAAQ,CAAC,CAuB7C;AAED,uFAAuF;AACvF,wBAAsB,0DAA0D,CAC9E,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,sDAAsD,GAC9D,OAAO,CAAC,uBAAuB,GAAG,QAAQ,CAAC,CAmD7C"}
@@ -1,8 +1,10 @@
1
+ import { stringifyUnknown } from "../../chat/conversation.js";
1
2
  import { buildHostedChatRequestInputFromRuntimeAgentInvocation, hostedChatRequestSchema, } from "./chat-request.js";
2
3
  import { RuntimeAgentRunInvocationSchema } from "../runtime/agent-invocation-contract.js";
3
4
  import { isRequestBodyTooLargeError, readBodyWithLimit, } from "../../security/input-validation/limits.js";
4
5
  import { DEFAULT_MAX_BODY_SIZE_BYTES } from "../../utils/constants/index.js";
5
6
  import { verifyHostedRuntimeSourceBinding, } from "./runtime-source-binding.js";
7
+ import { getHostedChatUiToolIdentity } from "./chat-request-tool-part.js";
6
8
  async function parseRequestJson(request) {
7
9
  let body;
8
10
  try {
@@ -37,6 +39,104 @@ function normalizeProjectSlug(projectSlug) {
37
39
  const normalized = projectSlug?.trim();
38
40
  return normalized || undefined;
39
41
  }
42
+ function isRecord(value) {
43
+ return value !== null && typeof value === "object" && !Array.isArray(value);
44
+ }
45
+ function mapRawToolCallState(state) {
46
+ switch (state) {
47
+ case "streaming":
48
+ return "input-streaming";
49
+ case "pending":
50
+ return "pending";
51
+ case "error":
52
+ return "completed";
53
+ default:
54
+ return "completed";
55
+ }
56
+ }
57
+ function normalizeHostedChatRequestMessages(messages) {
58
+ const knownToolNames = new Map();
59
+ const knownToolInputs = new Map();
60
+ return messages.map((message) => {
61
+ const parts = [];
62
+ const partIndexByToolCallId = new Map();
63
+ for (const part of message.parts) {
64
+ const uiToolIdentity = getHostedChatUiToolIdentity(part);
65
+ if (uiToolIdentity) {
66
+ knownToolNames.set(uiToolIdentity.toolCallId, uiToolIdentity.toolName);
67
+ const input = isRecord(part)
68
+ ? part["input"]
69
+ : undefined;
70
+ if (isRecord(input)) {
71
+ knownToolInputs.set(uiToolIdentity.toolCallId, input);
72
+ }
73
+ partIndexByToolCallId.set(uiToolIdentity.toolCallId, parts.length);
74
+ }
75
+ if (isRecord(part) && part.type === "tool_call" && "id" in part && "name" in part) {
76
+ const rawPart = part;
77
+ const rawId = rawPart["id"];
78
+ const rawName = rawPart["name"];
79
+ const toolCallId = typeof rawId === "string" ? rawId : "";
80
+ const toolName = typeof rawName === "string" ? rawName : "";
81
+ const state = typeof part.state === "string" ? part.state : "completed";
82
+ if (!toolCallId || !toolName)
83
+ continue;
84
+ const input = isRecord(part.input) ? part.input : {};
85
+ knownToolNames.set(toolCallId, toolName);
86
+ knownToolInputs.set(toolCallId, input);
87
+ partIndexByToolCallId.set(toolCallId, parts.length);
88
+ parts.push({
89
+ type: "tool_call",
90
+ toolCallId,
91
+ toolName,
92
+ input,
93
+ state: mapRawToolCallState(state),
94
+ });
95
+ continue;
96
+ }
97
+ if (isRecord(part) && part.type === "tool_result") {
98
+ const toolCallId = typeof part.tool_call_id === "string" ? part.tool_call_id : "";
99
+ const explicitToolName = typeof part.tool_name === "string" ? part.tool_name : "";
100
+ const toolName = explicitToolName || knownToolNames.get(toolCallId);
101
+ if (!toolCallId || !toolName)
102
+ continue;
103
+ const resultPart = {
104
+ type: "tool_call",
105
+ toolCallId,
106
+ toolName,
107
+ input: knownToolInputs.get(toolCallId) ?? {},
108
+ state: part.is_error === true ? "output-error" : "output-available",
109
+ output: part.output,
110
+ ...(part.is_error === true
111
+ ? { errorText: stringifyUnknown(part.output ?? "Tool error") }
112
+ : {}),
113
+ };
114
+ const existingIndex = partIndexByToolCallId.get(toolCallId);
115
+ if (existingIndex !== undefined) {
116
+ const existingPart = parts[existingIndex];
117
+ if (existingPart && isRecord(existingPart)) {
118
+ parts[existingIndex] = {
119
+ ...existingPart,
120
+ state: resultPart.state,
121
+ output: resultPart.output,
122
+ ...(resultPart.errorText ? { errorText: resultPart.errorText } : {}),
123
+ };
124
+ }
125
+ }
126
+ else {
127
+ parts.push(resultPart);
128
+ }
129
+ continue;
130
+ }
131
+ parts.push(part);
132
+ }
133
+ return {
134
+ ...message,
135
+ role: message.role,
136
+ parts,
137
+ };
138
+ });
139
+ }
40
140
  function isBlankProjectSlug(projectSlug) {
41
141
  return projectSlug !== undefined && !normalizeProjectSlug(projectSlug);
42
142
  }
@@ -105,7 +205,7 @@ export async function buildParsedHostedChatRequest(input) {
105
205
  agentId: input.agentId,
106
206
  userId: input.userId,
107
207
  authToken: input.authToken,
108
- messages: messages,
208
+ messages: normalizeHostedChatRequestMessages(messages),
109
209
  validatedContext,
110
210
  projectId,
111
211
  projectSlug: verifiedProjectSlug,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Resolve the identity carried by a normalized UI tool part.
3
+ *
4
+ * Static tools derive their name from `tool-<name>` while dynamic and replay
5
+ * tool parts carry an explicit `toolName`.
6
+ */
7
+ export declare function getHostedChatUiToolIdentity(part: unknown): {
8
+ toolCallId: string;
9
+ toolName: string;
10
+ } | null;
11
+ //# sourceMappingURL=chat-request-tool-part.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-request-tool-part.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/hosted/chat-request-tool-part.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,OAAO,GACZ;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAWjD"}
@@ -0,0 +1,19 @@
1
+ function isRecord(value) {
2
+ return value !== null && typeof value === "object" && !Array.isArray(value);
3
+ }
4
+ /**
5
+ * Resolve the identity carried by a normalized UI tool part.
6
+ *
7
+ * Static tools derive their name from `tool-<name>` while dynamic and replay
8
+ * tool parts carry an explicit `toolName`.
9
+ */
10
+ export function getHostedChatUiToolIdentity(part) {
11
+ if (!isRecord(part) || typeof part.type !== "string") {
12
+ return null;
13
+ }
14
+ const toolCallId = typeof part.toolCallId === "string" ? part.toolCallId : "";
15
+ const explicitToolName = typeof part.toolName === "string" ? part.toolName : "";
16
+ const derivedToolName = part.type.startsWith("tool-") ? part.type.slice("tool-".length) : "";
17
+ const toolName = explicitToolName || derivedToolName;
18
+ return toolCallId && toolName ? { toolCallId, toolName } : null;
19
+ }
@@ -105,6 +105,18 @@ export declare const getHostedChatRequestSchema: () => import("../../internal-ag
105
105
  }) | import("../../extensions/schema/schema-validator.js").InferShape<{
106
106
  type: import("../../internal-agents/schema.js").Schema<`data-${string}`>;
107
107
  data: import("../../internal-agents/schema.js").Schema<unknown>;
108
+ }> | import("../../extensions/schema/schema-validator.js").InferShape<{
109
+ type: import("../../internal-agents/schema.js").Schema<"tool_call">;
110
+ id: import("../../internal-agents/schema.js").Schema<string>;
111
+ name: import("../../internal-agents/schema.js").Schema<string>;
112
+ input: import("../../internal-agents/schema.js").Schema<Record<string, unknown>>;
113
+ state: import("../../internal-agents/schema.js").Schema<string>;
114
+ }> | import("../../extensions/schema/schema-validator.js").InferShape<{
115
+ type: import("../../internal-agents/schema.js").Schema<"tool_result">;
116
+ tool_call_id: import("../../internal-agents/schema.js").Schema<string>;
117
+ output: import("../../internal-agents/schema.js").Schema<unknown>;
118
+ is_error: import("../../internal-agents/schema.js").Schema<boolean | undefined>;
119
+ tool_name: import("../../internal-agents/schema.js").Schema<string | undefined>;
108
120
  }>)[]>;
109
121
  metadata: import("../../internal-agents/schema.js").Schema<Record<string, unknown> | undefined>;
110
122
  }>[]>;
@@ -206,6 +218,18 @@ export declare const hostedChatRequestSchema: import("../../internal-agents/sche
206
218
  }) | import("../../extensions/schema/schema-validator.js").InferShape<{
207
219
  type: import("../../internal-agents/schema.js").Schema<`data-${string}`>;
208
220
  data: import("../../internal-agents/schema.js").Schema<unknown>;
221
+ }> | import("../../extensions/schema/schema-validator.js").InferShape<{
222
+ type: import("../../internal-agents/schema.js").Schema<"tool_call">;
223
+ id: import("../../internal-agents/schema.js").Schema<string>;
224
+ name: import("../../internal-agents/schema.js").Schema<string>;
225
+ input: import("../../internal-agents/schema.js").Schema<Record<string, unknown>>;
226
+ state: import("../../internal-agents/schema.js").Schema<string>;
227
+ }> | import("../../extensions/schema/schema-validator.js").InferShape<{
228
+ type: import("../../internal-agents/schema.js").Schema<"tool_result">;
229
+ tool_call_id: import("../../internal-agents/schema.js").Schema<string>;
230
+ output: import("../../internal-agents/schema.js").Schema<unknown>;
231
+ is_error: import("../../internal-agents/schema.js").Schema<boolean | undefined>;
232
+ tool_name: import("../../internal-agents/schema.js").Schema<string | undefined>;
209
233
  }>)[]>;
210
234
  metadata: import("../../internal-agents/schema.js").Schema<Record<string, unknown> | undefined>;
211
235
  }>[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"chat-request.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/hosted/chat-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EACL,2BAA2B,EAG5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAMzF,eAAO,MAAM,uCAAuC;;;;;;;;GAUnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oCAAoC;;;;;;;;GAEhD,CAAC;AAEF,eAAO,MAAM,mCAAmC;;;;;GAO/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;;;GAAkD,CAAC;AAehG,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AChF,wBAAgB,8DAA8D,CAC5E,KAAK,EAAE,yBAAyB,GAC/B,iBAAiB,CAAC,gBAAgB,CAAC,CAcrC;AAED,sEAAsE;AACtE,wBAAgB,qDAAqD,CACnE,KAAK,EAAE,yBAAyB,GAC/B,sBAAsB,CA0BxB;AAED,gEAAgE;AAChE,wBAAgB,gDAAgD,CAC9D,KAAK,EAAE,yBAAyB,GAC/B,iBAAiB,CAInB"}
@@ -1,5 +1,6 @@
1
1
  import { getChatRequestContextSchema, getChatUiMessagePartSchema, getChatUiMessageRoleSchema, } from "../../chat/types.js";
2
2
  import { defineSchema, lazySchema } from "../../schemas/index.js";
3
+ import { getHostedChatUiToolIdentity } from "./chat-request-tool-part.js";
3
4
  const getDurableRootRunIdSchema = defineSchema((v) => v.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/));
4
5
  export const getHostedDurableRootRunDescriptorSchema = defineSchema((v) => v.object({
5
6
  runId: getDurableRootRunIdSchema(),
@@ -24,13 +25,308 @@ export const getHostedChatRuntimeOverridesSchema = defineSchema((v) => v.object(
24
25
  * @deprecated Use getHostedChatRuntimeOverridesSchema()
25
26
  */
26
27
  export const hostedChatRuntimeOverridesSchema = lazySchema(getHostedChatRuntimeOverridesSchema);
28
+ const getHostedChatRawToolCallPartSchema = defineSchema((v) => v.object({
29
+ type: v.literal("tool_call"),
30
+ id: v.string().min(1),
31
+ name: v.string().min(1),
32
+ input: v.record(v.string(), v.unknown()),
33
+ state: v.enum(["streaming", "pending", "completed", "error"]),
34
+ }).strip());
35
+ const getHostedChatRawToolResultPartSchema = defineSchema((v) => v.object({
36
+ type: v.literal("tool_result"),
37
+ tool_call_id: v.string().min(1),
38
+ output: v.unknown(),
39
+ is_error: v.boolean().optional(),
40
+ tool_name: v.string().min(1).optional(),
41
+ }).strip());
42
+ const getHostedChatRequestMessagePartSchema = defineSchema((v) => v.union([
43
+ getChatUiMessagePartSchema(),
44
+ getHostedChatRawToolCallPartSchema(),
45
+ getHostedChatRawToolResultPartSchema(),
46
+ ]));
47
+ function isHostedChatUiToolPartCandidate(part) {
48
+ if (!isRecord(part) || typeof part.type !== "string") {
49
+ return false;
50
+ }
51
+ return (typeof part.toolCallId === "string" && part.toolCallId.length > 0 &&
52
+ (part.type === "dynamic-tool" || part.type === "tool_call" || part.type.startsWith("tool-")));
53
+ }
54
+ function isHostedChatToolResultPart(part) {
55
+ if (!isRecord(part)) {
56
+ return false;
57
+ }
58
+ if (part.type === "tool_result") {
59
+ return true;
60
+ }
61
+ return (getHostedChatUiToolIdentity(part) !== null && "state" in part &&
62
+ (part.state === "output-available" || part.state === "output-error" ||
63
+ part.state === "output-denied" || part.state === "error"));
64
+ }
65
+ function hasHostedChatNonEmptyString(value) {
66
+ return typeof value === "string" && value.length > 0;
67
+ }
68
+ function isHostedChatProviderVisibleNonToolPart(role, part) {
69
+ if (!isRecord(part)) {
70
+ return false;
71
+ }
72
+ if (role === "system") {
73
+ return part.type === "text" && typeof part.text === "string" && part.text.length > 0;
74
+ }
75
+ if (role === "user") {
76
+ return (part.type === "text" && typeof part.text === "string" && part.text.length > 0 ||
77
+ (part.type === "file" || part.type === "image") &&
78
+ typeof part.mediaType === "string" && typeof part.url === "string");
79
+ }
80
+ if (role === "assistant") {
81
+ return (part.type === "text" && typeof part.text === "string" && part.text.length > 0 ||
82
+ part.type === "reasoning" &&
83
+ (hasHostedChatNonEmptyString(part.text) ||
84
+ hasHostedChatNonEmptyString(part.signature) ||
85
+ hasHostedChatNonEmptyString(part.redactedData)) ||
86
+ (part.type === "file" || part.type === "image") &&
87
+ typeof part.mediaType === "string" && typeof part.url === "string");
88
+ }
89
+ return false;
90
+ }
27
91
  const getHostedChatRequestMessageSchema = defineSchema((v) => v.object({
28
92
  id: v.string().min(1),
29
93
  role: getChatUiMessageRoleSchema(),
30
- parts: v.array(getChatUiMessagePartSchema()),
94
+ parts: v.array(getHostedChatRequestMessagePartSchema()),
31
95
  metadata: v.record(v.string(), v.unknown()).optional(),
32
96
  }).strip());
33
- const getHostedChatRequestMessagesSchema = defineSchema((v) => v.array(getHostedChatRequestMessageSchema()));
97
+ const getHostedChatRequestMessagesSchema = defineSchema((v) => v.array(getHostedChatRequestMessageSchema()).superRefine((messages, ctx) => {
98
+ const knownToolNames = new Map();
99
+ const knownToolResultIds = new Set();
100
+ const openToolCalls = new Map();
101
+ const recordToolCall = (toolCallId, toolName, path, options) => {
102
+ rejectOpenToolCallsBeforeNewCall(options.messageIndex);
103
+ if (knownToolNames.has(toolCallId)) {
104
+ ctx.addIssue({
105
+ code: "custom",
106
+ message: "tool_call id must be unique",
107
+ path,
108
+ });
109
+ return false;
110
+ }
111
+ knownToolNames.set(toolCallId, toolName);
112
+ openToolCalls.set(toolCallId, {
113
+ toolName,
114
+ path,
115
+ originMessageIndex: options.messageIndex,
116
+ requiresResult: options?.requiresResult === true,
117
+ sawLaterNonResultContent: false,
118
+ });
119
+ return true;
120
+ };
121
+ const rejectUnresolvedTerminalToolCalls = (message) => {
122
+ let rejected = false;
123
+ for (const openToolCall of openToolCalls.values()) {
124
+ if (!openToolCall.requiresResult) {
125
+ continue;
126
+ }
127
+ rejected = true;
128
+ ctx.addIssue({
129
+ code: "custom",
130
+ message,
131
+ path: openToolCall.path,
132
+ });
133
+ }
134
+ if (rejected) {
135
+ openToolCalls.clear();
136
+ }
137
+ return rejected;
138
+ };
139
+ const closeOpenBatchBeforeContinuation = () => {
140
+ rejectUnresolvedTerminalToolCalls("terminal tool_call requires an adjacent tool_result before conversation continuation");
141
+ openToolCalls.clear();
142
+ };
143
+ const rejectOpenToolCallsBeforeNewCall = (messageIndex) => {
144
+ for (const [toolCallId, openToolCall] of openToolCalls) {
145
+ if (openToolCall.originMessageIndex === messageIndex &&
146
+ !openToolCall.sawLaterNonResultContent) {
147
+ continue;
148
+ }
149
+ if (openToolCall.requiresResult) {
150
+ ctx.addIssue({
151
+ code: "custom",
152
+ message: openToolCall.originMessageIndex === messageIndex
153
+ ? "terminal tool_call requires a same-message tool_result before assistant continuation"
154
+ : "terminal tool_call requires an adjacent tool_result before conversation continuation",
155
+ path: openToolCall.path,
156
+ });
157
+ }
158
+ openToolCalls.delete(toolCallId);
159
+ }
160
+ };
161
+ const handleNonResultContent = (messageIndex) => {
162
+ for (const [toolCallId, openToolCall] of openToolCalls) {
163
+ if (openToolCall.originMessageIndex !== messageIndex) {
164
+ if (openToolCall.requiresResult) {
165
+ ctx.addIssue({
166
+ code: "custom",
167
+ message: "terminal tool_call requires an adjacent tool_result before conversation continuation",
168
+ path: openToolCall.path,
169
+ });
170
+ }
171
+ openToolCalls.delete(toolCallId);
172
+ continue;
173
+ }
174
+ openToolCalls.set(toolCallId, {
175
+ ...openToolCall,
176
+ sawLaterNonResultContent: true,
177
+ });
178
+ }
179
+ };
180
+ const closeOpenBatchAfterSameMessageContinuation = () => {
181
+ for (const [toolCallId, openToolCall] of openToolCalls) {
182
+ if (!openToolCall.sawLaterNonResultContent) {
183
+ continue;
184
+ }
185
+ if (openToolCall.requiresResult) {
186
+ ctx.addIssue({
187
+ code: "custom",
188
+ message: "terminal tool_call requires a same-message tool_result before assistant continuation",
189
+ path: openToolCall.path,
190
+ });
191
+ }
192
+ openToolCalls.delete(toolCallId);
193
+ }
194
+ };
195
+ const validateToolResult = (toolCallId, toolName, toolCallIdPath, toolNamePath) => {
196
+ if (knownToolResultIds.has(toolCallId)) {
197
+ ctx.addIssue({
198
+ code: "custom",
199
+ message: "tool_result for tool_call_id must be unique",
200
+ path: toolCallIdPath,
201
+ });
202
+ return;
203
+ }
204
+ knownToolResultIds.add(toolCallId);
205
+ const knownToolName = knownToolNames.get(toolCallId);
206
+ if (!knownToolName) {
207
+ ctx.addIssue({
208
+ code: "custom",
209
+ message: "tool_result requires a preceding matching tool_call",
210
+ path: toolCallIdPath,
211
+ });
212
+ return;
213
+ }
214
+ const openToolCall = openToolCalls.get(toolCallId);
215
+ if (!openToolCall) {
216
+ ctx.addIssue({
217
+ code: "custom",
218
+ message: "tool_result requires an adjacent terminal tool_call",
219
+ path: toolCallIdPath,
220
+ });
221
+ return;
222
+ }
223
+ openToolCalls.delete(toolCallId);
224
+ if (toolName && toolName !== openToolCall.toolName) {
225
+ ctx.addIssue({
226
+ code: "custom",
227
+ message: "tool_result tool_name must match its preceding tool_call",
228
+ path: toolNamePath,
229
+ });
230
+ }
231
+ };
232
+ const getFirstProviderVisiblePart = (role, parts) => {
233
+ return parts.find((part) => isHostedChatToolResultPart(part) ||
234
+ isHostedChatUiToolPartCandidate(part) ||
235
+ (isRecord(part) && part.type === "tool_call" && "id" in part && "name" in part) ||
236
+ isHostedChatProviderVisibleNonToolPart(role, part));
237
+ };
238
+ for (const [messageIndex, message] of messages.entries()) {
239
+ const firstPart = getFirstProviderVisiblePart(message.role, message.parts);
240
+ if (firstPart && openToolCalls.size > 0 && !isHostedChatToolResultPart(firstPart)) {
241
+ closeOpenBatchBeforeContinuation();
242
+ }
243
+ for (const [partIndex, part] of message.parts.entries()) {
244
+ const uiToolIdentity = getHostedChatUiToolIdentity(part);
245
+ const isRawToolCall = part.type === "tool_call" && "id" in part && "name" in part;
246
+ if (isRawToolCall && message.role !== "assistant") {
247
+ ctx.addIssue({
248
+ code: "custom",
249
+ message: "tool_call is only allowed in assistant messages",
250
+ path: [messageIndex, "parts", partIndex, "type"],
251
+ });
252
+ continue;
253
+ }
254
+ if (!uiToolIdentity && !isRawToolCall && isHostedChatUiToolPartCandidate(part)) {
255
+ ctx.addIssue({
256
+ code: "custom",
257
+ message: "tool UI parts require a non-empty toolName",
258
+ path: [messageIndex, "parts", partIndex, "toolName"],
259
+ });
260
+ continue;
261
+ }
262
+ if (uiToolIdentity && message.role !== "assistant" && message.role !== "tool") {
263
+ ctx.addIssue({
264
+ code: "custom",
265
+ message: "tool UI parts are only allowed in assistant or tool messages",
266
+ path: [messageIndex, "parts", partIndex, "type"],
267
+ });
268
+ continue;
269
+ }
270
+ if (part.type === "tool_result" && message.role !== "assistant" && message.role !== "tool") {
271
+ ctx.addIssue({
272
+ code: "custom",
273
+ message: "tool_result is only allowed in assistant or tool messages",
274
+ path: [messageIndex, "parts", partIndex, "type"],
275
+ });
276
+ continue;
277
+ }
278
+ if (isRawToolCall) {
279
+ recordToolCall(part.id, part.name, [messageIndex, "parts", partIndex, "id"], {
280
+ messageIndex,
281
+ requiresResult: part.state === "completed" || part.state === "error",
282
+ });
283
+ continue;
284
+ }
285
+ if (uiToolIdentity) {
286
+ if (message.role === "assistant") {
287
+ recordToolCall(uiToolIdentity.toolCallId, uiToolIdentity.toolName, [
288
+ messageIndex,
289
+ "parts",
290
+ partIndex,
291
+ "toolCallId",
292
+ ], {
293
+ messageIndex,
294
+ requiresResult: "state" in part && part.state === "completed",
295
+ });
296
+ }
297
+ const hasUiToolResult = "state" in part &&
298
+ (part.state === "output-available" || part.state === "output-error" ||
299
+ part.state === "output-denied" || part.state === "error");
300
+ if (message.role === "tool" && !hasUiToolResult) {
301
+ ctx.addIssue({
302
+ code: "custom",
303
+ message: "tool message UI parts require a result-bearing state",
304
+ path: [messageIndex, "parts", partIndex, "state"],
305
+ });
306
+ continue;
307
+ }
308
+ if (hasUiToolResult) {
309
+ validateToolResult(uiToolIdentity.toolCallId, uiToolIdentity.toolName, [messageIndex, "parts", partIndex, "toolCallId"], [
310
+ messageIndex,
311
+ "parts",
312
+ partIndex,
313
+ "toolName" in part ? "toolName" : "type",
314
+ ]);
315
+ }
316
+ continue;
317
+ }
318
+ if (part.type !== "tool_result") {
319
+ if (isHostedChatProviderVisibleNonToolPart(message.role, part)) {
320
+ handleNonResultContent(messageIndex);
321
+ }
322
+ continue;
323
+ }
324
+ validateToolResult(part.tool_call_id, part.tool_name, [messageIndex, "parts", partIndex, "tool_call_id"], [messageIndex, "parts", partIndex, "tool_name"]);
325
+ }
326
+ closeOpenBatchAfterSameMessageContinuation();
327
+ }
328
+ rejectUnresolvedTerminalToolCalls("terminal tool_call requires a matching tool_result");
329
+ }));
34
330
  export const getHostedChatRequestSchema = defineSchema((v) => v.object({
35
331
  messages: getHostedChatRequestMessagesSchema(),
36
332
  context: getChatRequestContextSchema(),
@@ -1,5 +1,5 @@
1
1
  import type { InferSchema } from "../extensions/schema/index.js";
2
- import type { ChatUiMessage, ChatUiMessagePart, ProviderModelMessage } from "./types.js";
2
+ import type { ChatUiMessage, ChatUiMessagePart, ChatUiMessageRole, ProviderModelMessage } from "./types.js";
3
3
  declare const PROVIDER_MODEL_MESSAGE_SOURCE_ID: unique symbol;
4
4
  /** Provider model message plus local-only source metadata. */
5
5
  export type ProviderModelMessageWithSourceId = ProviderModelMessage & {
@@ -204,6 +204,27 @@ type ToolUiPart = Extract<ChatUiMessagePart, {
204
204
  toolCallId: string;
205
205
  state: string;
206
206
  }>;
207
+ type RawToolCallMessagePart = Extract<MessagePart, {
208
+ type: "tool_call";
209
+ }>;
210
+ type RawToolResultMessagePart = Extract<MessagePart, {
211
+ type: "tool_result";
212
+ }>;
213
+ /** Stored tool-call replay part accepted by provider conversion. */
214
+ export type ChatProviderModelInputToolCallPart = RawToolCallMessagePart;
215
+ /** Stored tool-result replay part accepted by provider conversion. */
216
+ export type ChatProviderModelInputToolResultPart = RawToolResultMessagePart & {
217
+ tool_name?: string;
218
+ };
219
+ /** Message part accepted by provider conversion. */
220
+ export type ChatProviderModelInputPart = ChatUiMessagePart | ChatProviderModelInputToolCallPart | ChatProviderModelInputToolResultPart;
221
+ /** Message accepted by provider conversion. */
222
+ export interface ChatProviderModelInputMessage<TMessageMetadata = unknown> {
223
+ id: string;
224
+ role: ChatUiMessageRole;
225
+ parts: ChatProviderModelInputPart[];
226
+ metadata?: TMessageMetadata;
227
+ }
207
228
  /** Shared UUID pattern value. */
208
229
  export declare const UUID_PATTERN: RegExp;
209
230
  /** Check whether a value is a UUID. */
@@ -252,7 +273,19 @@ export declare function isTextPart(value: unknown): value is TextPartLike;
252
273
  export declare function isReasoningPart(value: unknown): value is ReasoningPartLike;
253
274
  /** Message shape for extract text from. */
254
275
  export declare function extractTextFromMessage(message: ProviderModelMessage): string;
276
+ /** Tool replay parts that are valid to expose to provider conversion. */
277
+ export type ProviderVisibleToolReplayMatches = {
278
+ preservedTransientToolParts: WeakSet<object>;
279
+ matchedToolCallParts: WeakSet<object>;
280
+ matchedToolResultParts: WeakSet<object>;
281
+ matchedToolResultNames: WeakMap<object, string>;
282
+ toolCallPartsStartingNewBatch: WeakSet<object>;
283
+ supersededToolCallParts: WeakSet<object>;
284
+ supersededToolResultParts: WeakSet<object>;
285
+ };
286
+ /** Find adjacent replay call/result occurrences using part object identity. */
287
+ export declare function findProviderVisibleToolReplayMatches(messages: readonly ChatProviderModelInputMessage[]): ProviderVisibleToolReplayMatches;
255
288
  /** Convert UI messages to provider model messages. */
256
- export declare function convertUiMessagesToProviderModelMessages(messages: ChatUiMessage[]): ProviderModelMessage[];
289
+ export declare function convertUiMessagesToProviderModelMessages(messages: readonly ChatProviderModelInputMessage[]): ProviderModelMessage[];
257
290
  export {};
258
291
  //# sourceMappingURL=conversation.d.ts.map