veryfront 0.1.251 → 0.1.252

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.251",
3
+ "version": "0.1.252",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -0,0 +1,8 @@
1
+ type ConversationRunEventRecord = Record<string, unknown> & {
2
+ type: string;
3
+ };
4
+ export declare function getConversationRunEventJsonByteLength(value: unknown): number;
5
+ export declare function normalizeConversationRunEvent(event: ConversationRunEventRecord): ConversationRunEventRecord[];
6
+ export declare function normalizeConversationRunEvents(events: ConversationRunEventRecord[]): ConversationRunEventRecord[];
7
+ export {};
8
+ //# sourceMappingURL=conversation-run-event-normalization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-run-event-normalization.d.ts","sourceRoot":"","sources":["../../../src/src/agent/conversation-run-event-normalization.ts"],"names":[],"mappings":"AAQA,KAAK,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAS7E,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM5E;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,0BAA0B,GAChC,0BAA0B,EAAE,CAkB9B;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,0BAA0B,EAAE,GACnC,0BAA0B,EAAE,CAE9B"}
@@ -0,0 +1,167 @@
1
+ const MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES = 240 * 1024;
2
+ const MAX_SUMMARY_DEPTH = 4;
3
+ const MAX_SUMMARY_ARRAY_ITEMS = 8;
4
+ const MAX_SUMMARY_OBJECT_KEYS = 24;
5
+ const MAX_SUMMARY_STRING_BYTES = 8 * 1024;
6
+ const encoder = new TextEncoder();
7
+ function hasStringField(event, field) {
8
+ return typeof event[field] === "string";
9
+ }
10
+ export function getConversationRunEventJsonByteLength(value) {
11
+ try {
12
+ return encoder.encode(JSON.stringify(value)).byteLength;
13
+ }
14
+ catch {
15
+ return Number.POSITIVE_INFINITY;
16
+ }
17
+ }
18
+ export function normalizeConversationRunEvent(event) {
19
+ if (getConversationRunEventJsonByteLength(event) <= MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
20
+ return [event];
21
+ }
22
+ switch (event.type) {
23
+ case "TEXT_MESSAGE_CONTENT":
24
+ case "REASONING_CONTENT":
25
+ case "REASONING_MESSAGE_CONTENT":
26
+ case "TOOL_CALL_ARGS":
27
+ return hasStringField(event, "delta") ? splitStringFieldEvent(event, "delta") : [event];
28
+ case "TOOL_CALL_RESULT":
29
+ return [summarizeToolResultEvent(event)];
30
+ default:
31
+ return [summarizeGenericEvent(event)];
32
+ }
33
+ }
34
+ export function normalizeConversationRunEvents(events) {
35
+ return events.flatMap(normalizeConversationRunEvent);
36
+ }
37
+ function summarizeToolResultEvent(event) {
38
+ if (event.type !== "TOOL_CALL_RESULT") {
39
+ return event;
40
+ }
41
+ if (typeof event.content === "string") {
42
+ const maxResultBytes = getStringFieldBudget(event, "content");
43
+ return {
44
+ ...event,
45
+ content: truncateUtf8String(event.content, maxResultBytes, " [tool result truncated in conversation-run event]"),
46
+ };
47
+ }
48
+ const summarizedEvent = {
49
+ ...event,
50
+ content: summarizeValue(event.content),
51
+ };
52
+ if (getConversationRunEventJsonByteLength(summarizedEvent) <=
53
+ MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
54
+ return summarizedEvent;
55
+ }
56
+ return {
57
+ ...event,
58
+ content: {
59
+ truncated: true,
60
+ originalType: describeValueType(event.content),
61
+ note: "Tool result omitted from the conversation-run event because it exceeded the payload size limit.",
62
+ },
63
+ };
64
+ }
65
+ function summarizeGenericEvent(event) {
66
+ return {
67
+ ...event,
68
+ truncated: true,
69
+ note: "Conversation-run event payload was summarized to stay within storage limits.",
70
+ };
71
+ }
72
+ function splitStringFieldEvent(event, field) {
73
+ const maxBytes = getStringFieldBudget(event, field);
74
+ const parts = splitUtf8String(event[field], maxBytes);
75
+ return parts.map((part) => ({ ...event, [field]: part }));
76
+ }
77
+ function getStringFieldBudget(event, field) {
78
+ const eventWithEmptyField = {
79
+ ...event,
80
+ [field]: "",
81
+ };
82
+ return Math.max(1, MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES -
83
+ getConversationRunEventJsonByteLength(eventWithEmptyField));
84
+ }
85
+ function splitUtf8String(value, maxBytes) {
86
+ if (encoder.encode(value).byteLength <= maxBytes) {
87
+ return [value];
88
+ }
89
+ const parts = [];
90
+ let startIndex = 0;
91
+ while (startIndex < value.length) {
92
+ let low = startIndex + 1;
93
+ let high = value.length;
94
+ let bestEndIndex = startIndex + 1;
95
+ while (low <= high) {
96
+ const mid = Math.floor((low + high) / 2);
97
+ const slice = value.slice(startIndex, mid);
98
+ if (encoder.encode(slice).byteLength <= maxBytes) {
99
+ bestEndIndex = mid;
100
+ low = mid + 1;
101
+ }
102
+ else {
103
+ high = mid - 1;
104
+ }
105
+ }
106
+ parts.push(value.slice(startIndex, bestEndIndex));
107
+ startIndex = bestEndIndex;
108
+ }
109
+ return parts;
110
+ }
111
+ function truncateUtf8String(value, maxBytes, suffix) {
112
+ if (encoder.encode(value).byteLength <= maxBytes) {
113
+ return value;
114
+ }
115
+ const suffixBytes = encoder.encode(suffix).byteLength;
116
+ if (suffixBytes >= maxBytes) {
117
+ return suffix.slice(0, Math.max(1, maxBytes));
118
+ }
119
+ const prefixBudget = maxBytes - suffixBytes;
120
+ const [prefix] = splitUtf8String(value, prefixBudget);
121
+ return `${prefix}${suffix}`;
122
+ }
123
+ function summarizeValue(value, depth = 0, seen = new WeakSet()) {
124
+ if (typeof value === "string") {
125
+ return truncateUtf8String(value, MAX_SUMMARY_STRING_BYTES, "… [truncated]");
126
+ }
127
+ if (value === null || typeof value !== "object") {
128
+ return value;
129
+ }
130
+ if (seen.has(value)) {
131
+ return "[circular]";
132
+ }
133
+ if (depth >= MAX_SUMMARY_DEPTH) {
134
+ return "[truncated nested data]";
135
+ }
136
+ seen.add(value);
137
+ if (Array.isArray(value)) {
138
+ const items = value
139
+ .slice(0, MAX_SUMMARY_ARRAY_ITEMS)
140
+ .map((item) => summarizeValue(item, depth + 1, seen));
141
+ if (value.length > MAX_SUMMARY_ARRAY_ITEMS) {
142
+ items.push(`[truncated ${value.length - MAX_SUMMARY_ARRAY_ITEMS} more items]`);
143
+ }
144
+ return items;
145
+ }
146
+ const entries = Object.entries(value);
147
+ const summarizedEntries = entries
148
+ .slice(0, MAX_SUMMARY_OBJECT_KEYS)
149
+ .map(([key, entryValue]) => [key, summarizeValue(entryValue, depth + 1, seen)]);
150
+ const summarizedObject = Object.fromEntries(summarizedEntries);
151
+ if (entries.length > MAX_SUMMARY_OBJECT_KEYS) {
152
+ return {
153
+ ...summarizedObject,
154
+ _truncatedKeys: entries.length - MAX_SUMMARY_OBJECT_KEYS,
155
+ };
156
+ }
157
+ return summarizedObject;
158
+ }
159
+ function describeValueType(value) {
160
+ if (Array.isArray(value)) {
161
+ return "array";
162
+ }
163
+ if (value === null) {
164
+ return "null";
165
+ }
166
+ return typeof value;
167
+ }
@@ -93,6 +93,7 @@ export { type ConversationRunContext, createConversationRunContext, } from "./co
93
93
  export { type ConversationRootRunContext, type ConversationRootRunDescriptor, createConversationRootRunContext, createConversationRootRunStartAdapter, prepareConversationRootRunContext, startConversationRootRun, } from "./conversation-root-run-context.js";
94
94
  export { bootstrapConversationAgentRun, type BootstrapConversationAgentRunResult, type ConversationMessageRecord, ConversationMessageRecordSchema, type ConversationRecord, ConversationRecordSchema, createConversationMessage, createConversationRecord, ensureConversationProjectLink, fetchConversationRecord, } from "./conversation-bootstrap.js";
95
95
  export { type ConversationChildLifecycleContext, type ConversationHostedLifecycleFinalizeInput, createConversationChildLifecycleAdapter, createConversationHostedLifecycleAdapter, type CreateConversationHostedLifecycleAdapterOptions, } from "./conversation-hosted-lifecycle.js";
96
+ export { getConversationRunEventJsonByteLength, normalizeConversationRunEvent, normalizeConversationRunEvents, } from "./conversation-run-event-normalization.js";
96
97
  export { type ConversationRunMirror, type ConversationRunMirrorRetryScheduledState, type ConversationRunMirrorSnapshot, type ConversationRunMirrorStoppedState, createConversationRunMirror, } from "./conversation-run-mirror.js";
97
98
  export { type ActiveConversationRunStatus, appendConversationRunEvents, AppendConversationRunEventsError, type AppendConversationRunEventsResponse, AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, type ConversationAgentRunUsage, type ConversationRunAppendCursorResyncResult, type ConversationRunAppendExecutionOutcome, type ConversationRunAppendFailureOutcome, type ConversationRunAppendRecoveryOutcome, type ConversationRunBatchFlushOutcome, type ConversationRunEventQueueController, type ConversationRunProjection, ConversationRunProjectionSchema, type ConversationRunQueueFlushOutcome, ConversationRunStatusSchema, type ConversationRunTargets, ConversationRunTargetsSchema, ConversationRunTerminalStateError, createConversationAgentRun, createConversationRunEventQueueController, finalizeConversationAgentRun, flushConversationRunEventBatches, flushConversationRunEventQueue, getConversationRun, isActiveConversationRunStatus, isAppendableConversationRunProjection, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, monitorConversationRunStatus, parseAppendConversationRunEventsErrorBody, recoverConversationRunAppendExecution, recoverConversationRunAppendFailure, recoverConversationRunCursorMismatch, resolveConversationRunTargets, resyncConversationRunAppendCursor, type TerminalConversationRunStatus, } from "./durable.js";
98
99
  export { buildInvokeAgentChildRunLifecycleCustomEvent, buildInvokeAgentChildRunProgressEvents, buildInvokeAgentChildRunStateDelta, type InvokeAgentChildRunLifecycleCustomEvent, InvokeAgentChildRunLifecycleCustomEventSchema, type InvokeAgentChildRunLifecycleValue, InvokeAgentChildRunLifecycleValueSchema, type InvokeAgentChildRunProgressEvent, type InvokeAgentChildRunProgressInput, type InvokeAgentChildRunStateDelta, InvokeAgentChildRunStateDeltaSchema, publishInvokeAgentChildRunProgress, } from "./invoke-agent-child-runs.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,iCAAi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ACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MA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qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
@@ -92,6 +92,7 @@ export { createConversationRunContext, } from "./conversation-run-context.js";
92
92
  export { createConversationRootRunContext, createConversationRootRunStartAdapter, prepareConversationRootRunContext, startConversationRootRun, } from "./conversation-root-run-context.js";
93
93
  export { bootstrapConversationAgentRun, ConversationMessageRecordSchema, ConversationRecordSchema, createConversationMessage, createConversationRecord, ensureConversationProjectLink, fetchConversationRecord, } from "./conversation-bootstrap.js";
94
94
  export { createConversationChildLifecycleAdapter, createConversationHostedLifecycleAdapter, } from "./conversation-hosted-lifecycle.js";
95
+ export { getConversationRunEventJsonByteLength, normalizeConversationRunEvent, normalizeConversationRunEvents, } from "./conversation-run-event-normalization.js";
95
96
  export { createConversationRunMirror, } from "./conversation-run-mirror.js";
96
97
  export { appendConversationRunEvents, AppendConversationRunEventsError, AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, ConversationRunTerminalStateError, createConversationAgentRun, createConversationRunEventQueueController, finalizeConversationAgentRun, flushConversationRunEventBatches, flushConversationRunEventQueue, getConversationRun, isActiveConversationRunStatus, isAppendableConversationRunProjection, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, monitorConversationRunStatus, parseAppendConversationRunEventsErrorBody, recoverConversationRunAppendExecution, recoverConversationRunAppendFailure, recoverConversationRunCursorMismatch, resolveConversationRunTargets, resyncConversationRunAppendCursor, } from "./durable.js";
97
98
  export { buildInvokeAgentChildRunLifecycleCustomEvent, buildInvokeAgentChildRunProgressEvents, buildInvokeAgentChildRunStateDelta, InvokeAgentChildRunLifecycleCustomEventSchema, InvokeAgentChildRunLifecycleValueSchema, InvokeAgentChildRunStateDeltaSchema, publishInvokeAgentChildRunProgress, } from "./invoke-agent-child-runs.js";
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.251";
1
+ export declare const VERSION = "0.1.252";
2
2
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.251";
3
+ export const VERSION = "0.1.252";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.251",
3
+ "version": "0.1.252",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
package/src/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.251",
3
+ "version": "0.1.252",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -0,0 +1,228 @@
1
+ const MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES = 240 * 1024;
2
+ const MAX_SUMMARY_DEPTH = 4;
3
+ const MAX_SUMMARY_ARRAY_ITEMS = 8;
4
+ const MAX_SUMMARY_OBJECT_KEYS = 24;
5
+ const MAX_SUMMARY_STRING_BYTES = 8 * 1024;
6
+
7
+ const encoder = new TextEncoder();
8
+
9
+ type ConversationRunEventRecord = Record<string, unknown> & { type: string };
10
+
11
+ function hasStringField<TField extends "delta" | "content">(
12
+ event: ConversationRunEventRecord,
13
+ field: TField,
14
+ ): event is ConversationRunEventRecord & Record<TField, string> {
15
+ return typeof event[field] === "string";
16
+ }
17
+
18
+ export function getConversationRunEventJsonByteLength(value: unknown): number {
19
+ try {
20
+ return encoder.encode(JSON.stringify(value)).byteLength;
21
+ } catch {
22
+ return Number.POSITIVE_INFINITY;
23
+ }
24
+ }
25
+
26
+ export function normalizeConversationRunEvent(
27
+ event: ConversationRunEventRecord,
28
+ ): ConversationRunEventRecord[] {
29
+ if (getConversationRunEventJsonByteLength(event) <= MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
30
+ return [event];
31
+ }
32
+
33
+ switch (event.type) {
34
+ case "TEXT_MESSAGE_CONTENT":
35
+ case "REASONING_CONTENT":
36
+ case "REASONING_MESSAGE_CONTENT":
37
+ case "TOOL_CALL_ARGS":
38
+ return hasStringField(event, "delta") ? splitStringFieldEvent(event, "delta") : [event];
39
+
40
+ case "TOOL_CALL_RESULT":
41
+ return [summarizeToolResultEvent(event)];
42
+
43
+ default:
44
+ return [summarizeGenericEvent(event)];
45
+ }
46
+ }
47
+
48
+ export function normalizeConversationRunEvents(
49
+ events: ConversationRunEventRecord[],
50
+ ): ConversationRunEventRecord[] {
51
+ return events.flatMap(normalizeConversationRunEvent);
52
+ }
53
+
54
+ function summarizeToolResultEvent(event: ConversationRunEventRecord): ConversationRunEventRecord {
55
+ if (event.type !== "TOOL_CALL_RESULT") {
56
+ return event;
57
+ }
58
+
59
+ if (typeof event.content === "string") {
60
+ const maxResultBytes = getStringFieldBudget(event, "content");
61
+ return {
62
+ ...event,
63
+ content: truncateUtf8String(
64
+ event.content,
65
+ maxResultBytes,
66
+ " [tool result truncated in conversation-run event]",
67
+ ),
68
+ };
69
+ }
70
+
71
+ const summarizedEvent = {
72
+ ...event,
73
+ content: summarizeValue(event.content),
74
+ } satisfies ConversationRunEventRecord;
75
+
76
+ if (
77
+ getConversationRunEventJsonByteLength(summarizedEvent) <=
78
+ MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES
79
+ ) {
80
+ return summarizedEvent;
81
+ }
82
+
83
+ return {
84
+ ...event,
85
+ content: {
86
+ truncated: true,
87
+ originalType: describeValueType(event.content),
88
+ note:
89
+ "Tool result omitted from the conversation-run event because it exceeded the payload size limit.",
90
+ },
91
+ };
92
+ }
93
+
94
+ function summarizeGenericEvent(event: ConversationRunEventRecord): ConversationRunEventRecord {
95
+ return {
96
+ ...event,
97
+ truncated: true,
98
+ note: "Conversation-run event payload was summarized to stay within storage limits.",
99
+ };
100
+ }
101
+
102
+ function splitStringFieldEvent<TField extends "delta" | "content">(
103
+ event: ConversationRunEventRecord & Record<TField, string>,
104
+ field: TField,
105
+ ): ConversationRunEventRecord[] {
106
+ const maxBytes = getStringFieldBudget(event, field);
107
+ const parts = splitUtf8String(event[field], maxBytes);
108
+ return parts.map((part) => ({ ...event, [field]: part }));
109
+ }
110
+
111
+ function getStringFieldBudget(
112
+ event: ConversationRunEventRecord,
113
+ field: "delta" | "content",
114
+ ): number {
115
+ const eventWithEmptyField = {
116
+ ...event,
117
+ [field]: "",
118
+ };
119
+
120
+ return Math.max(
121
+ 1,
122
+ MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES -
123
+ getConversationRunEventJsonByteLength(eventWithEmptyField),
124
+ );
125
+ }
126
+
127
+ function splitUtf8String(value: string, maxBytes: number): string[] {
128
+ if (encoder.encode(value).byteLength <= maxBytes) {
129
+ return [value];
130
+ }
131
+
132
+ const parts: string[] = [];
133
+ let startIndex = 0;
134
+
135
+ while (startIndex < value.length) {
136
+ let low = startIndex + 1;
137
+ let high = value.length;
138
+ let bestEndIndex = startIndex + 1;
139
+
140
+ while (low <= high) {
141
+ const mid = Math.floor((low + high) / 2);
142
+ const slice = value.slice(startIndex, mid);
143
+ if (encoder.encode(slice).byteLength <= maxBytes) {
144
+ bestEndIndex = mid;
145
+ low = mid + 1;
146
+ } else {
147
+ high = mid - 1;
148
+ }
149
+ }
150
+
151
+ parts.push(value.slice(startIndex, bestEndIndex));
152
+ startIndex = bestEndIndex;
153
+ }
154
+
155
+ return parts;
156
+ }
157
+
158
+ function truncateUtf8String(value: string, maxBytes: number, suffix: string): string {
159
+ if (encoder.encode(value).byteLength <= maxBytes) {
160
+ return value;
161
+ }
162
+
163
+ const suffixBytes = encoder.encode(suffix).byteLength;
164
+ if (suffixBytes >= maxBytes) {
165
+ return suffix.slice(0, Math.max(1, maxBytes));
166
+ }
167
+
168
+ const prefixBudget = maxBytes - suffixBytes;
169
+ const [prefix] = splitUtf8String(value, prefixBudget);
170
+ return `${prefix}${suffix}`;
171
+ }
172
+
173
+ function summarizeValue(value: unknown, depth = 0, seen: WeakSet<object> = new WeakSet()): unknown {
174
+ if (typeof value === "string") {
175
+ return truncateUtf8String(value, MAX_SUMMARY_STRING_BYTES, "… [truncated]");
176
+ }
177
+
178
+ if (value === null || typeof value !== "object") {
179
+ return value;
180
+ }
181
+
182
+ if (seen.has(value)) {
183
+ return "[circular]";
184
+ }
185
+
186
+ if (depth >= MAX_SUMMARY_DEPTH) {
187
+ return "[truncated nested data]";
188
+ }
189
+
190
+ seen.add(value);
191
+
192
+ if (Array.isArray(value)) {
193
+ const items = value
194
+ .slice(0, MAX_SUMMARY_ARRAY_ITEMS)
195
+ .map((item) => summarizeValue(item, depth + 1, seen));
196
+ if (value.length > MAX_SUMMARY_ARRAY_ITEMS) {
197
+ items.push(`[truncated ${value.length - MAX_SUMMARY_ARRAY_ITEMS} more items]`);
198
+ }
199
+ return items;
200
+ }
201
+
202
+ const entries = Object.entries(value);
203
+ const summarizedEntries = entries
204
+ .slice(0, MAX_SUMMARY_OBJECT_KEYS)
205
+ .map(([key, entryValue]) => [key, summarizeValue(entryValue, depth + 1, seen)] as const);
206
+ const summarizedObject = Object.fromEntries(summarizedEntries);
207
+
208
+ if (entries.length > MAX_SUMMARY_OBJECT_KEYS) {
209
+ return {
210
+ ...summarizedObject,
211
+ _truncatedKeys: entries.length - MAX_SUMMARY_OBJECT_KEYS,
212
+ };
213
+ }
214
+
215
+ return summarizedObject;
216
+ }
217
+
218
+ function describeValueType(value: unknown): string {
219
+ if (Array.isArray(value)) {
220
+ return "array";
221
+ }
222
+
223
+ if (value === null) {
224
+ return "null";
225
+ }
226
+
227
+ return typeof value;
228
+ }
@@ -211,6 +211,11 @@ export {
211
211
  createConversationHostedLifecycleAdapter,
212
212
  type CreateConversationHostedLifecycleAdapterOptions,
213
213
  } from "./conversation-hosted-lifecycle.js";
214
+ export {
215
+ getConversationRunEventJsonByteLength,
216
+ normalizeConversationRunEvent,
217
+ normalizeConversationRunEvents,
218
+ } from "./conversation-run-event-normalization.js";
214
219
  export {
215
220
  type ConversationRunMirror,
216
221
  type ConversationRunMirrorRetryScheduledState,
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.251";
3
+ export const VERSION = "0.1.252";