veryfront 0.1.1010 → 0.1.1012
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/conversation/run-event-normalization.d.ts.map +1 -1
- package/esm/src/agent/conversation/run-event-normalization.js +64 -18
- package/esm/src/agent/hosted/chat-execution-runtime.d.ts +4 -0
- package/esm/src/agent/hosted/chat-execution-runtime.d.ts.map +1 -1
- package/esm/src/agent/hosted/chat-execution-runtime.js +54 -2
- 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/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-event-normalization.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/run-event-normalization.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wCAAwC,QAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"run-event-normalization.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/run-event-normalization.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wCAAwC,QAAa,CAAC;AASnE,KAAK,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAS7E,sDAAsD;AACtD,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM5E;AAED,oDAAoD;AACpD,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,0BAA0B,GAChC,0BAA0B,EAAE,CAQ9B;AA0CD,0CAA0C;AAC1C,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,0BAA0B,EAAE,GACnC,0BAA0B,EAAE,CAE9B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES = 240 * 1024;
|
|
2
|
+
const OMITTED_CONVERSATION_RUN_EVENT_TYPE = "CUSTOM";
|
|
2
3
|
const MAX_SUMMARY_DEPTH = 4;
|
|
3
4
|
const MAX_SUMMARY_ARRAY_ITEMS = 8;
|
|
4
5
|
const MAX_SUMMARY_OBJECT_KEYS = 24;
|
|
@@ -55,13 +56,7 @@ function enforceEventSizeLimit(event) {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
return
|
|
59
|
-
type: event.type,
|
|
60
|
-
...(typeof event.messageId === "string" ? { messageId: event.messageId } : {}),
|
|
61
|
-
...(typeof event.toolCallId === "string" ? { toolCallId: event.toolCallId } : {}),
|
|
62
|
-
truncated: true,
|
|
63
|
-
note: "Conversation-run event payload exceeded the size limit and was omitted.",
|
|
64
|
-
};
|
|
59
|
+
return buildOmittedEvent(event);
|
|
65
60
|
}
|
|
66
61
|
/** Normalizes conversation run events. */
|
|
67
62
|
export function normalizeConversationRunEvents(events) {
|
|
@@ -139,6 +134,36 @@ function truncateEventStringFieldToLimit(event, field, suffix) {
|
|
|
139
134
|
}
|
|
140
135
|
return buildCandidate(best);
|
|
141
136
|
}
|
|
137
|
+
function addStringFieldWithinLimit(event, field, value) {
|
|
138
|
+
const candidate = { ...event, [field]: value };
|
|
139
|
+
if (getConversationRunEventJsonByteLength(candidate) <= MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
|
|
140
|
+
return candidate;
|
|
141
|
+
}
|
|
142
|
+
return truncateEventStringFieldToLimit(candidate, field, " [truncated]") ?? event;
|
|
143
|
+
}
|
|
144
|
+
function buildOmittedEvent(event) {
|
|
145
|
+
let omitted = {
|
|
146
|
+
type: OMITTED_CONVERSATION_RUN_EVENT_TYPE,
|
|
147
|
+
name: "conversation-run-event-omitted",
|
|
148
|
+
truncated: true,
|
|
149
|
+
note: "Conversation-run event payload exceeded the size limit and was omitted.",
|
|
150
|
+
};
|
|
151
|
+
omitted = addStringFieldWithinLimit(omitted, "originalType", event.type);
|
|
152
|
+
if (typeof event.messageId === "string") {
|
|
153
|
+
omitted = addStringFieldWithinLimit(omitted, "originalMessageId", event.messageId);
|
|
154
|
+
}
|
|
155
|
+
if (typeof event.toolCallId === "string") {
|
|
156
|
+
omitted = addStringFieldWithinLimit(omitted, "originalToolCallId", event.toolCallId);
|
|
157
|
+
}
|
|
158
|
+
if (getConversationRunEventJsonByteLength(omitted) <= MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
|
|
159
|
+
return omitted;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
type: OMITTED_CONVERSATION_RUN_EVENT_TYPE,
|
|
163
|
+
name: "conversation-run-event-omitted",
|
|
164
|
+
truncated: true,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
142
167
|
function summarizeGenericEvent(event) {
|
|
143
168
|
const { type, ...rest } = event;
|
|
144
169
|
return {
|
|
@@ -149,17 +174,38 @@ function summarizeGenericEvent(event) {
|
|
|
149
174
|
};
|
|
150
175
|
}
|
|
151
176
|
function splitStringFieldEvent(event, field) {
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
const value = event[field];
|
|
178
|
+
const buildPart = (slice) => ({ ...event, [field]: slice });
|
|
179
|
+
const parts = [];
|
|
180
|
+
let startIndex = 0;
|
|
181
|
+
while (startIndex < value.length) {
|
|
182
|
+
// Largest prefix whose WHOLE serialized event fits the byte limit. Measuring the
|
|
183
|
+
// event (not the raw slice) keeps the split correct for escape-heavy content that
|
|
184
|
+
// expands under JSON.stringify — the same unit the API enforces — so every part
|
|
185
|
+
// fits without the size-limit backstop having to truncate (drop) any data.
|
|
186
|
+
let low = startIndex + 1;
|
|
187
|
+
let high = value.length;
|
|
188
|
+
let bestEndIndex = -1;
|
|
189
|
+
while (low <= high) {
|
|
190
|
+
const mid = Math.floor((low + high) / 2);
|
|
191
|
+
if (getConversationRunEventJsonByteLength(buildPart(value.slice(startIndex, mid))) <=
|
|
192
|
+
MAX_CONVERSATION_RUN_EVENT_PAYLOAD_BYTES) {
|
|
193
|
+
bestEndIndex = mid;
|
|
194
|
+
low = mid + 1;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
high = mid - 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (bestEndIndex <= startIndex) {
|
|
201
|
+
// Even a single character overflows the envelope; hand off to the size-limit
|
|
202
|
+
// backstop rather than loop forever emitting zero-progress parts.
|
|
203
|
+
return [event];
|
|
204
|
+
}
|
|
205
|
+
parts.push(buildPart(value.slice(startIndex, bestEndIndex)));
|
|
206
|
+
startIndex = bestEndIndex;
|
|
207
|
+
}
|
|
208
|
+
return parts.length > 0 ? parts : [event];
|
|
163
209
|
}
|
|
164
210
|
function splitUtf8String(value, maxBytes) {
|
|
165
211
|
if (encoder.encode(value).byteLength <= maxBytes) {
|
|
@@ -48,6 +48,8 @@ export interface CreateHostedChatExecutionRuntimeBootstrapInput {
|
|
|
48
48
|
abortSignal: AbortSignal;
|
|
49
49
|
traceStream?: <T>(operation: () => Promise<T>) => Promise<T>;
|
|
50
50
|
createRootStreamWatchdog?: () => HostedChatExecutionRootStreamWatchdog;
|
|
51
|
+
streamBootstrapKeepaliveIntervalMs?: number;
|
|
52
|
+
streamBootstrapTimeoutMs?: number;
|
|
51
53
|
}
|
|
52
54
|
/** Input payload for create hosted chat execution runtime. */
|
|
53
55
|
export interface CreateHostedChatExecutionRuntimeInput {
|
|
@@ -92,6 +94,8 @@ export interface CreateBootstrappedHostedChatExecutionRuntimeInput {
|
|
|
92
94
|
terminalErrorCode?: string;
|
|
93
95
|
incompleteToolCallsPartErrorText?: string;
|
|
94
96
|
createRootStreamWatchdog?: CreateHostedChatExecutionRuntimeBootstrapInput["createRootStreamWatchdog"];
|
|
97
|
+
streamBootstrapKeepaliveIntervalMs?: CreateHostedChatExecutionRuntimeBootstrapInput["streamBootstrapKeepaliveIntervalMs"];
|
|
98
|
+
streamBootstrapTimeoutMs?: CreateHostedChatExecutionRuntimeBootstrapInput["streamBootstrapTimeoutMs"];
|
|
95
99
|
createTerminalAdapter?: CreateHostedRootRunLifecycleRuntimeAdapterInput["createTerminalAdapter"];
|
|
96
100
|
}
|
|
97
101
|
/** Public API contract for bootstrapped hosted chat execution runtime. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-execution-runtime.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/hosted/chat-execution-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat-execution-runtime.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/hosted/chat-execution-runtime.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAC9F,OAAO,EAGL,KAAK,+CAA+C,EACpD,KAAK,4BAA4B,EACjC,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EACV,sBAAsB,EACtB,4BAA4B,EAC5B,6BAA6B,EAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EACL,KAAK,oCAAoC,EAK1C,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,+BAA+B,EACpC,KAAK,+BAA+B,EACrC,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EACL,wBAAwB,EAEzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qCAAqC,CAAC;AAC/F,YAAY,EAAE,mCAAmC,EA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,4DAA4D;AAC5D,wBAAgB,0CAA0C,CAAC,KAAK,EAAE;IAChE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,mCAAmC,CAAC;IACtD,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gCAAgC,EAAE,MAAM,CAAC;CAC1C,GAAG,CACF,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,+BAA+B,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,CAAC,CA2BjF;AAmJD,4CAA4C;AAC5C,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,qCAAqC,GAC3C,0BAA0B,CAwH5B"}
|
|
@@ -6,9 +6,11 @@ import { dispatchConversationHostedStreamErrorState, dispatchConversationHostedT
|
|
|
6
6
|
import { createHostedMirroredUiStream, createMirroredToolChunkState, } from "../streaming/mirrored-tool-chunk-state.js";
|
|
7
7
|
import { finalizeHostedDetached, finalizeHostedResponse, } from "./stream-finalization.js";
|
|
8
8
|
import { getEmptyHostedFinalizedMessageTerminalError, getHostedStreamErrorText, shouldFailEmptyHostedFinalizedMessage, } from "./stream-terminal-error.js";
|
|
9
|
-
import { createChatStreamWatchdog } from "../../chat/stream-watchdog.js";
|
|
9
|
+
import { createChatStreamWatchdog, DEFAULT_CHAT_STREAM_TOOL_RUNNING_TIMEOUT_MS, } from "../../chat/stream-watchdog.js";
|
|
10
10
|
const INCOMPLETE_TOOL_CALLS_PART_ERROR_TEXT = "Assistant ended before tool execution completed";
|
|
11
11
|
const FINALIZATION_TERMINAL_STATE_FALLBACK_MODEL_ID = "";
|
|
12
|
+
const DEFAULT_STREAM_BOOTSTRAP_KEEPALIVE_INTERVAL_MS = 30_000;
|
|
13
|
+
const DEFAULT_STREAM_BOOTSTRAP_TIMEOUT_MS = DEFAULT_CHAT_STREAM_TOOL_RUNNING_TIMEOUT_MS;
|
|
12
14
|
/** State for to hosted chat execution final. */
|
|
13
15
|
export function toHostedChatExecutionFinalState(input) {
|
|
14
16
|
return toConversationHostedTerminalState({
|
|
@@ -37,6 +39,42 @@ function createHostedChatExecutionCleanup(cleanup) {
|
|
|
37
39
|
function createDefaultHostedChatExecutionRootStreamWatchdog() {
|
|
38
40
|
return createChatStreamWatchdog();
|
|
39
41
|
}
|
|
42
|
+
function resolveStreamBootstrapKeepaliveIntervalMs(intervalMs) {
|
|
43
|
+
if (typeof intervalMs !== "number" || !Number.isFinite(intervalMs) || intervalMs <= 0) {
|
|
44
|
+
return DEFAULT_STREAM_BOOTSTRAP_KEEPALIVE_INTERVAL_MS;
|
|
45
|
+
}
|
|
46
|
+
return intervalMs;
|
|
47
|
+
}
|
|
48
|
+
function resolveStreamBootstrapTimeoutMs(timeoutMs) {
|
|
49
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
50
|
+
return DEFAULT_STREAM_BOOTSTRAP_TIMEOUT_MS;
|
|
51
|
+
}
|
|
52
|
+
return timeoutMs;
|
|
53
|
+
}
|
|
54
|
+
function createStreamBootstrapWatchdogKeepalive(input) {
|
|
55
|
+
const intervalMs = resolveStreamBootstrapKeepaliveIntervalMs(input.intervalMs);
|
|
56
|
+
const timeoutMs = resolveStreamBootstrapTimeoutMs(input.timeoutMs);
|
|
57
|
+
const timeoutController = new AbortController();
|
|
58
|
+
const interval = globalThis.setInterval(() => {
|
|
59
|
+
input.rootStreamWatchdog.observe({
|
|
60
|
+
type: "message-metadata",
|
|
61
|
+
messageMetadata: {
|
|
62
|
+
createdAt: new Date().toISOString(),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}, intervalMs);
|
|
66
|
+
const timeout = globalThis.setTimeout(() => {
|
|
67
|
+
timeoutController.abort(new DOMException(`Chat stream bootstrap timeout after ${timeoutMs}ms`, "AbortError"));
|
|
68
|
+
clearInterval(interval);
|
|
69
|
+
}, timeoutMs);
|
|
70
|
+
return {
|
|
71
|
+
signal: timeoutController.signal,
|
|
72
|
+
dispose: () => {
|
|
73
|
+
clearInterval(interval);
|
|
74
|
+
clearTimeout(timeout);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
40
78
|
function traceHostedChatRuntimeStream(traceStream, operation) {
|
|
41
79
|
if (!traceStream) {
|
|
42
80
|
return operation();
|
|
@@ -53,7 +91,16 @@ export async function createHostedChatExecutionRuntimeBootstrap(input) {
|
|
|
53
91
|
const rootStreamWatchdog = input.createRootStreamWatchdog
|
|
54
92
|
? input.createRootStreamWatchdog()
|
|
55
93
|
: createDefaultHostedChatExecutionRootStreamWatchdog();
|
|
56
|
-
const
|
|
94
|
+
const bootstrapKeepalive = createStreamBootstrapWatchdogKeepalive({
|
|
95
|
+
rootStreamWatchdog,
|
|
96
|
+
intervalMs: input.streamBootstrapKeepaliveIntervalMs,
|
|
97
|
+
timeoutMs: input.streamBootstrapTimeoutMs,
|
|
98
|
+
});
|
|
99
|
+
const streamAbortSignal = AbortSignal.any([
|
|
100
|
+
input.abortSignal,
|
|
101
|
+
rootStreamWatchdog.signal,
|
|
102
|
+
bootstrapKeepalive.signal,
|
|
103
|
+
]);
|
|
57
104
|
let streamResult;
|
|
58
105
|
try {
|
|
59
106
|
streamResult = await traceHostedChatRuntimeStream(input.traceStream, () => input.agent.stream({
|
|
@@ -65,6 +112,9 @@ export async function createHostedChatExecutionRuntimeBootstrap(input) {
|
|
|
65
112
|
rootStreamWatchdog.dispose();
|
|
66
113
|
throw error;
|
|
67
114
|
}
|
|
115
|
+
finally {
|
|
116
|
+
bootstrapKeepalive.dispose();
|
|
117
|
+
}
|
|
68
118
|
return {
|
|
69
119
|
cleanup,
|
|
70
120
|
lifecycleAdapter: input.lifecycleAdapter,
|
|
@@ -100,6 +150,8 @@ async function createBootstrappedHostedChatRuntime(input, agentRunSpan) {
|
|
|
100
150
|
...(input.createRootStreamWatchdog
|
|
101
151
|
? { createRootStreamWatchdog: input.createRootStreamWatchdog }
|
|
102
152
|
: {}),
|
|
153
|
+
streamBootstrapKeepaliveIntervalMs: input.streamBootstrapKeepaliveIntervalMs,
|
|
154
|
+
streamBootstrapTimeoutMs: input.streamBootstrapTimeoutMs,
|
|
103
155
|
});
|
|
104
156
|
}
|
|
105
157
|
catch (error) {
|