veryfront 0.1.813 → 0.1.814
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/durable-append-errors.d.ts +17 -0
- package/esm/src/agent/conversation/durable-append-errors.d.ts.map +1 -0
- package/esm/src/agent/conversation/durable-append-errors.js +49 -0
- package/esm/src/agent/conversation/durable.d.ts +1 -16
- package/esm/src/agent/conversation/durable.d.ts.map +1 -1
- package/esm/src/agent/conversation/durable.js +3 -49
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +5 -23
- package/esm/src/agent/runtime/streamed-assistant-message.d.ts +8 -0
- package/esm/src/agent/runtime/streamed-assistant-message.d.ts.map +1 -0
- package/esm/src/agent/runtime/streamed-assistant-message.js +29 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts +19 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts.map +1 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.js +53 -0
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts +1 -4
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
- package/esm/src/agent/streaming/fork-runtime-stream.js +13 -52
- package/esm/src/proxy/main.js +16 -13
- package/esm/src/proxy/server-timing.d.ts +11 -0
- package/esm/src/proxy/server-timing.d.ts.map +1 -0
- package/esm/src/proxy/server-timing.js +61 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +9 -9
package/esm/deno.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Error shape for append conversation run events. */
|
|
2
|
+
export declare class AppendConversationRunEventsError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly detail: string | null;
|
|
5
|
+
constructor(input: {
|
|
6
|
+
status: number;
|
|
7
|
+
detail?: string | null;
|
|
8
|
+
statusText?: string;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/** Parses append conversation run events error body. */
|
|
12
|
+
export declare function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null;
|
|
13
|
+
/** Error shape for is ignorable conversation run append. */
|
|
14
|
+
export declare function isIgnorableConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
|
|
15
|
+
/** Error shape for is cursor mismatch conversation run append. */
|
|
16
|
+
export declare function isCursorMismatchConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
|
|
17
|
+
//# sourceMappingURL=durable-append-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-append-errors.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable-append-errors.ts"],"names":[],"mappings":"AAEA,sDAAsD;AACtD,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEnB,KAAK,EAAE;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAOF;AAED,wDAAwD;AACxD,wBAAgB,yCAAyC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAezF;AAED,4DAA4D;AAC5D,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gCAAgC,CAiB3C;AAED,kEAAkE;AAClE,wBAAgB,0CAA0C,CACxD,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gCAAgC,CAM3C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getConversationRunErrorSchema } from "./durable-contracts.js";
|
|
2
|
+
/** Error shape for append conversation run events. */
|
|
3
|
+
export class AppendConversationRunEventsError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
detail;
|
|
6
|
+
constructor(input) {
|
|
7
|
+
const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
|
|
8
|
+
super(`Append conversation run events failed (${input.status}): ${detail}`);
|
|
9
|
+
this.name = "AppendConversationRunEventsError";
|
|
10
|
+
this.status = input.status;
|
|
11
|
+
this.detail = input.detail?.trim() || null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Parses append conversation run events error body. */
|
|
15
|
+
export function parseAppendConversationRunEventsErrorBody(bodyText) {
|
|
16
|
+
if (!bodyText) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const parsed = getConversationRunErrorSchema().safeParse(JSON.parse(bodyText));
|
|
21
|
+
if (parsed.success) {
|
|
22
|
+
return parsed.data.detail ?? parsed.data.error ?? null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return bodyText;
|
|
27
|
+
}
|
|
28
|
+
return bodyText;
|
|
29
|
+
}
|
|
30
|
+
/** Error shape for is ignorable conversation run append. */
|
|
31
|
+
export function isIgnorableConversationRunAppendError(error) {
|
|
32
|
+
if (!(error instanceof AppendConversationRunEventsError)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (error.status === 404) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (error.status !== 400) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return (error.detail === "Cannot append external events to a terminal run" ||
|
|
42
|
+
error.detail === "Cannot append external events while the run is waiting for a tool result");
|
|
43
|
+
}
|
|
44
|
+
/** Error shape for is cursor mismatch conversation run append. */
|
|
45
|
+
export function isCursorMismatchConversationRunAppendError(error) {
|
|
46
|
+
return (error instanceof AppendConversationRunEventsError &&
|
|
47
|
+
error.status === 400 &&
|
|
48
|
+
error.detail === "External run event cursor mismatch");
|
|
49
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ActiveConversationRunStatus, AppendConversationRunEventsResponse, ConversationRunAppendCursorResyncResult, ConversationRunAppendFailureOutcome, ConversationRunAppendRecoveryOutcome, ConversationRunEventQueueController, ConversationRunProjection, CreateConversationAgentRunInput, FinalizeConversationAgentRunInput, TerminalConversationRunStatus } from "./durable-contracts.js";
|
|
2
2
|
export { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, CreateConversationRunAcceptedSchema, getAppendConversationRunEventsResponseSchema, getCompleteConversationRunResponseSchema, getConversationRunProjectionSchema, getConversationRunStatusSchema, getConversationRunTargetsSchema, getCreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
|
|
3
|
+
export { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
|
|
3
4
|
export type { ActiveConversationRunStatus, AppendConversationRunEventsResponse, ConversationAgentRunUsage, ConversationRunAppendCursorResyncResult, ConversationRunAppendExecutionOutcome, ConversationRunAppendFailureOutcome, ConversationRunAppendRecoveryOutcome, ConversationRunBatchFlushOutcome, ConversationRunEventQueueController, ConversationRunProjection, ConversationRunQueueFlushOutcome, ConversationRunTargets, CreateConversationAgentRunInput, FinalizeConversationAgentRunInput, TerminalConversationRunStatus, } from "./durable-contracts.js";
|
|
4
5
|
/** Error shape for conversation run terminal state. */
|
|
5
6
|
export declare class ConversationRunTerminalStateError extends Error {
|
|
@@ -7,22 +8,6 @@ export declare class ConversationRunTerminalStateError extends Error {
|
|
|
7
8
|
readonly run: ConversationRunProjection;
|
|
8
9
|
constructor(run: ConversationRunProjection, status: TerminalConversationRunStatus);
|
|
9
10
|
}
|
|
10
|
-
/** Error shape for append conversation run events. */
|
|
11
|
-
export declare class AppendConversationRunEventsError extends Error {
|
|
12
|
-
readonly status: number;
|
|
13
|
-
readonly detail: string | null;
|
|
14
|
-
constructor(input: {
|
|
15
|
-
status: number;
|
|
16
|
-
detail?: string | null;
|
|
17
|
-
statusText?: string;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/** Parses append conversation run events error body. */
|
|
21
|
-
export declare function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null;
|
|
22
|
-
/** Error shape for is ignorable conversation run append. */
|
|
23
|
-
export declare function isIgnorableConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
|
|
24
|
-
/** Error shape for is cursor mismatch conversation run append. */
|
|
25
|
-
export declare function isCursorMismatchConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
|
|
26
11
|
/** Check whether a conversation run status is active. */
|
|
27
12
|
export declare function isActiveConversationRunStatus(status: ConversationRunProjection["status"]): status is ActiveConversationRunStatus;
|
|
28
13
|
/** Check whether a conversation run projection can accept more events. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/conversation/durable.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mCAAmC,EACnC,uCAAuC,EACvC,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,yBAAyB,EACzB,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC9B,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EACL,yCAAyC,EACzC,qCAAqC,EACrC,+BAA+B,EAC/B,2BAA2B,EAC3B,4BAA4B,EAC5B,mCAAmC,EACnC,4CAA4C,EAC5C,wCAAwC,EACxC,kCAAkC,EAClC,8BAA8B,EAC9B,+BAA+B,EAC/B,sCAAsC,EACtC,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gCAAgC,EAChC,0CAA0C,EAC1C,qCAAqC,EACrC,yCAAyC,GAC1C,MAAM,4BAA4B,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AAC;IACd,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,CAAC,KAAK,EAAE,iCAAiC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,GAAG,OAAO,CAAC,IAAI,CAAC,CA+ChB;AAED,sCAAsC;AACtC,wBAAsB,2BAA2B,CAAC,KAAK,EAAE;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qCAAqC,CAAC,EAAE,MAAM,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAyD/C;AAED,qCAAqC;AACrC,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,yBAAyB,CAAC,CA4DpC;AAED,8CAA8C;AAC9C,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
-
import { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, CreateConversationRunAcceptedSchema,
|
|
2
|
+
import { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, CreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
|
|
3
|
+
import { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
|
|
3
4
|
export { AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, CreateConversationRunAcceptedSchema, getAppendConversationRunEventsResponseSchema, getCompleteConversationRunResponseSchema, getConversationRunProjectionSchema, getConversationRunStatusSchema, getConversationRunTargetsSchema, getCreateConversationRunAcceptedSchema, resolveConversationRunTargets, } from "./durable-contracts.js";
|
|
5
|
+
export { AppendConversationRunEventsError, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, } from "./durable-append-errors.js";
|
|
4
6
|
const AGENT_RUN_API_TIMEOUT_MS = 15_000;
|
|
5
7
|
function createTimedAbortSignal(timeoutMs, abortSignal) {
|
|
6
8
|
const controller = new AbortController();
|
|
@@ -39,54 +41,6 @@ export class ConversationRunTerminalStateError extends Error {
|
|
|
39
41
|
this.run = run;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
/** Error shape for append conversation run events. */
|
|
43
|
-
export class AppendConversationRunEventsError extends Error {
|
|
44
|
-
status;
|
|
45
|
-
detail;
|
|
46
|
-
constructor(input) {
|
|
47
|
-
const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
|
|
48
|
-
super(`Append conversation run events failed (${input.status}): ${detail}`);
|
|
49
|
-
this.name = "AppendConversationRunEventsError";
|
|
50
|
-
this.status = input.status;
|
|
51
|
-
this.detail = input.detail?.trim() || null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** Parses append conversation run events error body. */
|
|
55
|
-
export function parseAppendConversationRunEventsErrorBody(bodyText) {
|
|
56
|
-
if (!bodyText) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const parsed = getConversationRunErrorSchema().safeParse(JSON.parse(bodyText));
|
|
61
|
-
if (parsed.success) {
|
|
62
|
-
return parsed.data.detail ?? parsed.data.error ?? null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return bodyText;
|
|
67
|
-
}
|
|
68
|
-
return bodyText;
|
|
69
|
-
}
|
|
70
|
-
/** Error shape for is ignorable conversation run append. */
|
|
71
|
-
export function isIgnorableConversationRunAppendError(error) {
|
|
72
|
-
if (!(error instanceof AppendConversationRunEventsError)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (error.status === 404) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
if (error.status !== 400) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return (error.detail === "Cannot append external events to a terminal run" ||
|
|
82
|
-
error.detail === "Cannot append external events while the run is waiting for a tool result");
|
|
83
|
-
}
|
|
84
|
-
/** Error shape for is cursor mismatch conversation run append. */
|
|
85
|
-
export function isCursorMismatchConversationRunAppendError(error) {
|
|
86
|
-
return (error instanceof AppendConversationRunEventsError &&
|
|
87
|
-
error.status === 400 &&
|
|
88
|
-
error.detail === "External run event cursor mismatch");
|
|
89
|
-
}
|
|
90
44
|
/** Check whether a conversation run status is active. */
|
|
91
45
|
export function isActiveConversationRunStatus(status) {
|
|
92
46
|
return status === "pending" || status === "running" || status === "waiting_for_tool";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAGlB,KAAK,OAAO,EAGZ,KAAK,QAAQ,EAGd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAqB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAA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mB;IAOjC;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,sBAAsB;IAoB9B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC;IAI5B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC;QAC9B,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAIF;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnC"}
|
|
@@ -30,6 +30,7 @@ import { captureStreamedToolCallInput, collectFinalStreamToolResults, collectGen
|
|
|
30
30
|
import { enforceSkillPolicy, extractSkillId, extractSkillPolicy, hasSubmittedFormInputResult, hydrateActiveSkillStateFromMessages, LOAD_SKILL_TOOL_ID, removeFormInputAfterSubmission, } from "./skill-policy-enforcement.js";
|
|
31
31
|
import { getRuntimeAllowedRemoteTools, getRuntimeForwardedIntegrationToolDefs, getRuntimeProviderTools, } from "./runtime-tool-config.js";
|
|
32
32
|
import { prepareAgentRuntimeStep } from "./agent-runtime-step.js";
|
|
33
|
+
import { buildStreamedAssistantMessage } from "./streamed-assistant-message.js";
|
|
33
34
|
// Re-export from submodules
|
|
34
35
|
export { closeSSEStream, generateMessageId, sendSSE } from "./sse-utils.js";
|
|
35
36
|
export { RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./resume-session.js";
|
|
@@ -591,25 +592,12 @@ export class AgentRuntime {
|
|
|
591
592
|
}, abortSignal);
|
|
592
593
|
throwIfAborted(abortSignal);
|
|
593
594
|
finalFinishReason = state.finishReason ?? finalFinishReason;
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
!reasoningPart.redactedData) {
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
streamParts.push({
|
|
602
|
-
type: "reasoning",
|
|
603
|
-
...(reasoningPart.text.length > 0 ? { text: reasoningPart.text } : {}),
|
|
604
|
-
...(reasoningPart.signature ? { signature: reasoningPart.signature } : {}),
|
|
605
|
-
...(reasoningPart.redactedData ? { redactedData: reasoningPart.redactedData } : {}),
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
if (state.accumulatedText)
|
|
609
|
-
streamParts.push({ type: "text", text: state.accumulatedText });
|
|
595
|
+
const assistantMessage = buildStreamedAssistantMessage(state, {
|
|
596
|
+
id: `msg_${Date.now()}_${step}`,
|
|
597
|
+
timestamp: Date.now(),
|
|
598
|
+
});
|
|
610
599
|
for (const tc of state.toolCalls.values()) {
|
|
611
600
|
const materialized = materializeStreamedToolCall(tc);
|
|
612
|
-
streamParts.push(materialized.part);
|
|
613
601
|
if (materialized.kind === "incomplete" && isRecoverablePlaceholderToolCall(tc)) {
|
|
614
602
|
// Provisional empty-object placeholder that never finalized. The
|
|
615
603
|
// model never committed arguments; the loop will recover by
|
|
@@ -647,12 +635,6 @@ export class AgentRuntime {
|
|
|
647
635
|
});
|
|
648
636
|
}
|
|
649
637
|
}
|
|
650
|
-
const assistantMessage = {
|
|
651
|
-
id: `msg_${Date.now()}_${step}`,
|
|
652
|
-
role: "assistant",
|
|
653
|
-
parts: streamParts,
|
|
654
|
-
timestamp: Date.now(),
|
|
655
|
-
};
|
|
656
638
|
latestAssistantText = getTextFromParts(assistantMessage.parts);
|
|
657
639
|
currentMessages.push(assistantMessage);
|
|
658
640
|
await this.memory.add(assistantMessage);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Message } from "../types.js";
|
|
2
|
+
import type { ChatStreamState } from "./chat-stream-handler.js";
|
|
3
|
+
export interface StreamedAssistantMessageIdentity {
|
|
4
|
+
id: string;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildStreamedAssistantMessage(state: Pick<ChatStreamState, "accumulatedText" | "reasoningParts" | "toolCalls">, identity: StreamedAssistantMessageIdentity): Message;
|
|
8
|
+
//# sourceMappingURL=streamed-assistant-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamed-assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/streamed-assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,MAAM,WAAW,gCAAgC;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,WAAW,CAAC,EAChF,QAAQ,EAAE,gCAAgC,GACzC,OAAO,CAiCT"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { materializeStreamedToolCall } from "./tool-result-continuation.js";
|
|
2
|
+
export function buildStreamedAssistantMessage(state, identity) {
|
|
3
|
+
const parts = [];
|
|
4
|
+
for (const reasoningPart of state.reasoningParts) {
|
|
5
|
+
if (reasoningPart.text.length === 0 &&
|
|
6
|
+
!reasoningPart.signature &&
|
|
7
|
+
!reasoningPart.redactedData) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
parts.push({
|
|
11
|
+
type: "reasoning",
|
|
12
|
+
...(reasoningPart.text.length > 0 ? { text: reasoningPart.text } : {}),
|
|
13
|
+
...(reasoningPart.signature ? { signature: reasoningPart.signature } : {}),
|
|
14
|
+
...(reasoningPart.redactedData ? { redactedData: reasoningPart.redactedData } : {}),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (state.accumulatedText) {
|
|
18
|
+
parts.push({ type: "text", text: state.accumulatedText });
|
|
19
|
+
}
|
|
20
|
+
for (const toolCall of state.toolCalls.values()) {
|
|
21
|
+
parts.push(materializeStreamedToolCall(toolCall).part);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
id: identity.id,
|
|
25
|
+
role: "assistant",
|
|
26
|
+
parts,
|
|
27
|
+
timestamp: identity.timestamp,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentResponse, Message as AgentMessage } from "../schemas/index.js";
|
|
2
|
+
import type { ForkRuntimeStep } from "./fork-runtime-stream.js";
|
|
3
|
+
export interface ForkRuntimeProgress {
|
|
4
|
+
steps: ForkRuntimeStep[];
|
|
5
|
+
currentMessages: AgentMessage[];
|
|
6
|
+
accumulatedInputTokens: number;
|
|
7
|
+
accumulatedOutputTokens: number;
|
|
8
|
+
}
|
|
9
|
+
/** Build a fork runtime step from an agent response. */
|
|
10
|
+
export declare function buildForkRuntimeStepFromResponse(response: AgentResponse): ForkRuntimeStep;
|
|
11
|
+
/** Should continue fork runtime step helper. */
|
|
12
|
+
export declare function shouldContinueForkRuntimeStep(step: ForkRuntimeStep, response: AgentResponse): boolean;
|
|
13
|
+
export declare function createForkRuntimeProgress(currentMessages: AgentMessage[]): ForkRuntimeProgress;
|
|
14
|
+
export declare function commitForkRuntimeStep(progress: ForkRuntimeProgress, response: AgentResponse): ForkRuntimeStep;
|
|
15
|
+
export declare function getForkRuntimeProgressUsage(progress: ForkRuntimeProgress): {
|
|
16
|
+
inputTokens: number;
|
|
17
|
+
outputTokens: number;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=fork-runtime-step-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork-runtime-step-progress.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-step-progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,eAAe,EAAE,YAAY,EAAE,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,wDAAwD;AACxD,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,aAAa,GAAG,eAAe,CA2BzF;AAED,gDAAgD;AAChD,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAGT;AAED,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,EAAE,GAC9B,mBAAmB,CAOrB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,mBAAmB,EAC7B,QAAQ,EAAE,aAAa,GACtB,eAAe,CAOjB;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,mBAAmB,GAC5B;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAK/C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Build a fork runtime step from an agent response. */
|
|
2
|
+
export function buildForkRuntimeStepFromResponse(response) {
|
|
3
|
+
const toolCalls = response.toolCalls.map((toolCall) => ({
|
|
4
|
+
toolCallId: toolCall.id,
|
|
5
|
+
toolName: toolCall.name,
|
|
6
|
+
input: toolCall.args,
|
|
7
|
+
}));
|
|
8
|
+
const toolResults = response.toolCalls.flatMap((toolCall) => toolCall.status === "completed"
|
|
9
|
+
? [
|
|
10
|
+
{
|
|
11
|
+
toolCallId: toolCall.id,
|
|
12
|
+
toolName: toolCall.name,
|
|
13
|
+
input: toolCall.args,
|
|
14
|
+
output: toolCall.result,
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
: []);
|
|
18
|
+
const finishReasonValue = response.metadata?.finishReason;
|
|
19
|
+
return {
|
|
20
|
+
text: response.text,
|
|
21
|
+
messages: structuredClone(response.messages),
|
|
22
|
+
toolCalls,
|
|
23
|
+
toolResults,
|
|
24
|
+
finishReason: typeof finishReasonValue === "string" ? finishReasonValue : null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Should continue fork runtime step helper. */
|
|
28
|
+
export function shouldContinueForkRuntimeStep(step, response) {
|
|
29
|
+
return step.finishReason === "tool-calls" &&
|
|
30
|
+
response.toolCalls.some((toolCall) => toolCall.status !== "error");
|
|
31
|
+
}
|
|
32
|
+
export function createForkRuntimeProgress(currentMessages) {
|
|
33
|
+
return {
|
|
34
|
+
steps: [],
|
|
35
|
+
currentMessages,
|
|
36
|
+
accumulatedInputTokens: 0,
|
|
37
|
+
accumulatedOutputTokens: 0,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function commitForkRuntimeStep(progress, response) {
|
|
41
|
+
const step = buildForkRuntimeStepFromResponse(response);
|
|
42
|
+
progress.steps.push(step);
|
|
43
|
+
progress.accumulatedInputTokens += response.usage?.promptTokens ?? 0;
|
|
44
|
+
progress.accumulatedOutputTokens += response.usage?.completionTokens ?? 0;
|
|
45
|
+
progress.currentMessages = response.messages;
|
|
46
|
+
return step;
|
|
47
|
+
}
|
|
48
|
+
export function getForkRuntimeProgressUsage(progress) {
|
|
49
|
+
return {
|
|
50
|
+
inputTokens: progress.accumulatedInputTokens,
|
|
51
|
+
outputTokens: progress.accumulatedOutputTokens,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -4,6 +4,7 @@ export { buildRecoveredStepParts, createForkRuntimeStreamMappingState, createFra
|
|
|
4
4
|
export { applyPartToStreamedStepState, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
5
5
|
export type { ForkRecoveredPartsState, ForkRuntimeStreamMappingState, FrameworkStreamState, RecoveredToolObservation, } from "./fork-runtime-part-mapper.js";
|
|
6
6
|
export type { StreamedStepState } from "./fork-runtime-step-state.js";
|
|
7
|
+
export { buildForkRuntimeStepFromResponse, shouldContinueForkRuntimeStep, } from "./fork-runtime-step-progress.js";
|
|
7
8
|
interface ForkStreamPart {
|
|
8
9
|
type: "reasoning-delta" | "text-delta";
|
|
9
10
|
text: string;
|
|
@@ -162,10 +163,6 @@ export type ForkRuntimeContinuationPromptResolver = (input: {
|
|
|
162
163
|
step: ForkRuntimeStep;
|
|
163
164
|
stepIndex: number;
|
|
164
165
|
}) => Promise<string | null> | string | null;
|
|
165
|
-
/** Response payload for build fork runtime step from. */
|
|
166
|
-
export declare function buildForkRuntimeStepFromResponse(response: AgentResponse): ForkRuntimeStep;
|
|
167
|
-
/** Should continue fork runtime step helper. */
|
|
168
|
-
export declare function shouldContinueForkRuntimeStep(step: ForkRuntimeStep, response: AgentResponse): boolean;
|
|
169
166
|
/** Message shape for create fork runtime user. */
|
|
170
167
|
export declare function createForkRuntimeUserMessage(input: {
|
|
171
168
|
text: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fork-runtime-stream.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EAET,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAmB7B,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"fork-runtime-stream.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EAET,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAmB7B,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQlF,OAAO,EACL,uBAAuB,EACvB,mCAAmC,EACnC,0BAA0B,EAC1B,8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AAC;CAC/B,GAAG,MAAM,CAET;AAED,mDAAmD;AACnD,wBAAsB,mCAAmC,CAAC,KAAK,EAAE;IAC/D,0BAA0B,EAAE,MAAM,CAAC;IACnC,YAAY,CAAC,EAAE,qCAAqC,CAAC;IACrD,IAAI,EAAE,eAAe,CAAC;IACtB,eAAe,EAAE,YAAY,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,0BAA0B,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,YAAY,EAAE,CAAA;CAAE,GAAG,IAAI,CAAC,CAoB1F;AAED,iCAAiC;AACjC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,GAAG,uBAAuB,CAiGhG"}
|
|
@@ -6,8 +6,10 @@ import { buildRecoveredStepParts, createForkRuntimeStreamMappingState, mapAgUiRu
|
|
|
6
6
|
import { applyPartToStreamedStepState, createAgentRuntimeForkAbortError, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
7
7
|
import { getForkRuntimeAllowedToolNames, getProviderNativeToolNames, } from "../runtime/provider-native-tool-inventory.js";
|
|
8
8
|
import { AgentRuntime } from "../runtime/index.js";
|
|
9
|
+
import { commitForkRuntimeStep, createForkRuntimeProgress, getForkRuntimeProgressUsage, shouldContinueForkRuntimeStep, } from "./fork-runtime-step-progress.js";
|
|
9
10
|
export { buildRecoveredStepParts, createForkRuntimeStreamMappingState, createFrameworkStreamState, mapAgUiRuntimeEventToForkParts, mapFrameworkEventToForkParts, } from "./fork-runtime-part-mapper.js";
|
|
10
11
|
export { applyPartToStreamedStepState, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
12
|
+
export { buildForkRuntimeStepFromResponse, shouldContinueForkRuntimeStep, } from "./fork-runtime-step-progress.js";
|
|
11
13
|
/** Default value for fork response promise timeout ms. */
|
|
12
14
|
export const DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS = 1_000;
|
|
13
15
|
/** Starts agent runtime fork with host tools. */
|
|
@@ -143,37 +145,6 @@ export function runFrameworkForkStep(input) {
|
|
|
143
145
|
...(input.providerOptions ? { providerOptions: input.providerOptions } : {}),
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
|
-
/** Response payload for build fork runtime step from. */
|
|
147
|
-
export function buildForkRuntimeStepFromResponse(response) {
|
|
148
|
-
const toolCalls = response.toolCalls.map((toolCall) => ({
|
|
149
|
-
toolCallId: toolCall.id,
|
|
150
|
-
toolName: toolCall.name,
|
|
151
|
-
input: toolCall.args,
|
|
152
|
-
}));
|
|
153
|
-
const toolResults = response.toolCalls.flatMap((toolCall) => toolCall.status === "completed"
|
|
154
|
-
? [
|
|
155
|
-
{
|
|
156
|
-
toolCallId: toolCall.id,
|
|
157
|
-
toolName: toolCall.name,
|
|
158
|
-
input: toolCall.args,
|
|
159
|
-
output: toolCall.result,
|
|
160
|
-
},
|
|
161
|
-
]
|
|
162
|
-
: []);
|
|
163
|
-
const finishReasonValue = response.metadata?.finishReason;
|
|
164
|
-
return {
|
|
165
|
-
text: response.text,
|
|
166
|
-
messages: structuredClone(response.messages),
|
|
167
|
-
toolCalls,
|
|
168
|
-
toolResults,
|
|
169
|
-
finishReason: typeof finishReasonValue === "string" ? finishReasonValue : null,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
/** Should continue fork runtime step helper. */
|
|
173
|
-
export function shouldContinueForkRuntimeStep(step, response) {
|
|
174
|
-
return step.finishReason === "tool-calls" &&
|
|
175
|
-
response.toolCalls.some((toolCall) => toolCall.status !== "error");
|
|
176
|
-
}
|
|
177
148
|
/** Message shape for create fork runtime user. */
|
|
178
149
|
export function createForkRuntimeUserMessage(input) {
|
|
179
150
|
return {
|
|
@@ -222,25 +193,22 @@ export async function resolveForkRuntimeContinuationState(input) {
|
|
|
222
193
|
export function startAgentRuntimeFork(input) {
|
|
223
194
|
const stepsDeferred = createForkRuntimeDeferred();
|
|
224
195
|
const totalUsageDeferred = createForkRuntimeDeferred();
|
|
225
|
-
const steps = [];
|
|
226
|
-
let accumulatedInputTokens = 0;
|
|
227
|
-
let accumulatedOutputTokens = 0;
|
|
228
196
|
const runStep = input.runStep ?? runAgentRuntimeForkStep;
|
|
229
197
|
return {
|
|
230
198
|
fullStream: (async function* () {
|
|
231
199
|
if (!input.initialMessages?.length && typeof input.prompt !== "string") {
|
|
232
200
|
throw new Error("startAgentRuntimeFork requires a prompt when no initialMessages are provided.");
|
|
233
201
|
}
|
|
234
|
-
|
|
202
|
+
const progress = createForkRuntimeProgress(createInitialForkRuntimeMessages({
|
|
235
203
|
initialMessages: input.initialMessages,
|
|
236
204
|
prompt: input.prompt,
|
|
237
|
-
});
|
|
205
|
+
}));
|
|
238
206
|
let continuationStepsRemaining = input.maxContinuationSteps ?? 0;
|
|
239
207
|
try {
|
|
240
|
-
while (steps.length < getMaxForkRuntimeStepCount(input)) {
|
|
208
|
+
while (progress.steps.length < getMaxForkRuntimeStepCount(input)) {
|
|
241
209
|
const prepared = await prepareForkRuntimeStep({
|
|
242
210
|
prepareStep: input.prepareStep,
|
|
243
|
-
messages: currentMessages,
|
|
211
|
+
messages: progress.currentMessages,
|
|
244
212
|
buildInstructions: input.buildInstructions,
|
|
245
213
|
forkToolNames: input.forkToolNames,
|
|
246
214
|
});
|
|
@@ -270,38 +238,31 @@ export function startAgentRuntimeFork(input) {
|
|
|
270
238
|
responsePromise,
|
|
271
239
|
responseTimeoutMs: input.responseTimeoutMs ?? DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS,
|
|
272
240
|
...(input.abortSignal ? { abortSignal: input.abortSignal } : {}),
|
|
273
|
-
currentMessages,
|
|
241
|
+
currentMessages: progress.currentMessages,
|
|
274
242
|
streamedStepState,
|
|
275
243
|
});
|
|
276
|
-
const step =
|
|
244
|
+
const step = commitForkRuntimeStep(progress, response);
|
|
277
245
|
for (const recoveredPart of buildRecoveredStepParts(step, state)) {
|
|
278
246
|
yield recoveredPart;
|
|
279
247
|
}
|
|
280
|
-
steps.push(step);
|
|
281
|
-
accumulatedInputTokens += response.usage?.promptTokens ?? 0;
|
|
282
|
-
accumulatedOutputTokens += response.usage?.completionTokens ?? 0;
|
|
283
|
-
currentMessages = response.messages;
|
|
284
248
|
if (!shouldContinueForkRuntimeStep(step, response)) {
|
|
285
249
|
const followUpState = await resolveForkRuntimeContinuationState({
|
|
286
250
|
continuationStepsRemaining,
|
|
287
251
|
onBeforeStop: input.onBeforeStop,
|
|
288
252
|
step,
|
|
289
|
-
currentMessages,
|
|
290
|
-
stepIndex: steps.length - 1,
|
|
253
|
+
currentMessages: progress.currentMessages,
|
|
254
|
+
stepIndex: progress.steps.length - 1,
|
|
291
255
|
});
|
|
292
256
|
if (followUpState) {
|
|
293
257
|
continuationStepsRemaining = followUpState.continuationStepsRemaining;
|
|
294
|
-
currentMessages = followUpState.currentMessages;
|
|
258
|
+
progress.currentMessages = followUpState.currentMessages;
|
|
295
259
|
continue;
|
|
296
260
|
}
|
|
297
261
|
break;
|
|
298
262
|
}
|
|
299
263
|
}
|
|
300
|
-
stepsDeferred.resolve(steps);
|
|
301
|
-
totalUsageDeferred.resolve(
|
|
302
|
-
inputTokens: accumulatedInputTokens,
|
|
303
|
-
outputTokens: accumulatedOutputTokens,
|
|
304
|
-
});
|
|
264
|
+
stepsDeferred.resolve(progress.steps);
|
|
265
|
+
totalUsageDeferred.resolve(getForkRuntimeProgressUsage(progress));
|
|
305
266
|
}
|
|
306
267
|
catch (error) {
|
|
307
268
|
stepsDeferred.reject(error);
|
package/esm/src/proxy/main.js
CHANGED
|
@@ -37,6 +37,7 @@ import { createProxyErrorResponse, jsonErrorResponse } from "./error-response.js
|
|
|
37
37
|
import { handleReleaseAssetRequest, isReleaseAssetPath } from "./asset-handler.js";
|
|
38
38
|
import { runProxyRequestLifecycle } from "./request-lifecycle.js";
|
|
39
39
|
import { createUpstreamFailureResponse, createUpstreamTimeoutResponse, UPSTREAM_FAILURE_STATUS, UPSTREAM_TIMEOUT_STATUS, } from "./upstream-error-response.js";
|
|
40
|
+
import { createProxyServerTiming, markProxyServerTimingPhase, profileProxyServerTimingPhase, withProxyServerTimingHeader, } from "./server-timing.js";
|
|
40
41
|
function getLocalProjects() {
|
|
41
42
|
const raw = getEnv("LOCAL_PROJECTS");
|
|
42
43
|
return raw ? JSON.parse(raw) : {};
|
|
@@ -231,11 +232,13 @@ function handleWebSocketUpgrade(req, url) {
|
|
|
231
232
|
}
|
|
232
233
|
function forwardToServer(req, url) {
|
|
233
234
|
const startTime = performance.now();
|
|
235
|
+
const proxyTiming = createProxyServerTiming();
|
|
236
|
+
const withProxyTiming = (response) => withProxyServerTimingHeader(response, proxyTiming, performance.now() - startTime);
|
|
234
237
|
const requestId = dntShim.crypto.randomUUID();
|
|
235
238
|
const host = req.headers.get("host") || "";
|
|
236
239
|
const execute = async (lifecycle) => {
|
|
237
240
|
try {
|
|
238
|
-
const ctx = await proxyHandler.processRequest(req, { url });
|
|
241
|
+
const ctx = await profileProxyServerTimingPhase(proxyTiming, "proxy.resolve_request", () => proxyHandler.processRequest(req, { url }));
|
|
239
242
|
return runWithProxyRequestContext({
|
|
240
243
|
requestId,
|
|
241
244
|
projectSlug: ctx.projectSlug,
|
|
@@ -251,7 +254,7 @@ function forwardToServer(req, url) {
|
|
|
251
254
|
const logLevel = getProxyFailureLogLevel(ctx.error.status, req.method, url.pathname);
|
|
252
255
|
proxyLogger[logLevel](`${ctx.error.status} ${req.method} ${url.pathname}`, { ms });
|
|
253
256
|
lifecycle.end(ctx.error.status);
|
|
254
|
-
return createProxyErrorResponse(ctx.error);
|
|
257
|
+
return withProxyTiming(createProxyErrorResponse(ctx.error));
|
|
255
258
|
}
|
|
256
259
|
const reqLogger = proxyLogger.child({
|
|
257
260
|
...(ctx.projectSlug && { project: ctx.projectSlug }),
|
|
@@ -287,9 +290,7 @@ function forwardToServer(req, url) {
|
|
|
287
290
|
let skipDedicated = false;
|
|
288
291
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
289
292
|
// Resolve dedicated server per attempt so retries can fall back to shared pool
|
|
290
|
-
const dedicatedServerUrl = skipDedicated
|
|
291
|
-
? null
|
|
292
|
-
: await serverResolver.resolve(ctx.environmentId);
|
|
293
|
+
const dedicatedServerUrl = skipDedicated ? null : await profileProxyServerTimingPhase(proxyTiming, "proxy.resolve_server", () => serverResolver.resolve(ctx.environmentId));
|
|
293
294
|
const baseUrl = dedicatedServerUrl ??
|
|
294
295
|
rendererRouter?.resolve(ctx.projectSlug) ??
|
|
295
296
|
PRODUCTION_SERVER_URL;
|
|
@@ -302,14 +303,16 @@ function forwardToServer(req, url) {
|
|
|
302
303
|
pathname: url.pathname,
|
|
303
304
|
method: req.method,
|
|
304
305
|
});
|
|
306
|
+
const retryDelayStartedAt = performance.now();
|
|
305
307
|
await new Promise((resolve) => dntShim.setTimeout(resolve, VERYFRONT_SERVER_RETRY_DELAY_MS)); // no cleanup needed: one-shot
|
|
308
|
+
markProxyServerTimingPhase(proxyTiming, "proxy.retry_delay", performance.now() - retryDelayStartedAt);
|
|
306
309
|
}
|
|
307
310
|
const abortController = new AbortController();
|
|
308
311
|
const timeoutId = dntShim.setTimeout(() => {
|
|
309
312
|
abortController.abort();
|
|
310
313
|
}, VERYFRONT_SERVER_REQUEST_TIMEOUT_MS);
|
|
311
314
|
try {
|
|
312
|
-
const response = await withSpan(ProxySpanNames.HTTP_CLIENT_FETCH, () => fetch(serverUrl.toString(), {
|
|
315
|
+
const response = await profileProxyServerTimingPhase(proxyTiming, "proxy.upstream", () => withSpan(ProxySpanNames.HTTP_CLIENT_FETCH, () => fetch(serverUrl.toString(), {
|
|
313
316
|
method: req.method,
|
|
314
317
|
headers: newHeaders,
|
|
315
318
|
body: req.body,
|
|
@@ -323,7 +326,7 @@ function forwardToServer(req, url) {
|
|
|
323
326
|
"proxy.project_slug": ctx.projectSlug || "",
|
|
324
327
|
"proxy.timeout_ms": VERYFRONT_SERVER_REQUEST_TIMEOUT_MS,
|
|
325
328
|
"proxy.retry_attempt": attempt,
|
|
326
|
-
});
|
|
329
|
+
}));
|
|
327
330
|
clearTimeout(timeoutId);
|
|
328
331
|
const ms = Math.round(performance.now() - startTime);
|
|
329
332
|
if (attempt > 0) {
|
|
@@ -332,11 +335,11 @@ function forwardToServer(req, url) {
|
|
|
332
335
|
else {
|
|
333
336
|
reqLogger.info(`${response.status} ${req.method} ${url.pathname}`, { ms });
|
|
334
337
|
}
|
|
335
|
-
return new Response(response.body, {
|
|
338
|
+
return withProxyTiming(new Response(response.body, {
|
|
336
339
|
status: response.status,
|
|
337
340
|
statusText: response.statusText,
|
|
338
341
|
headers: response.headers,
|
|
339
|
-
});
|
|
342
|
+
}));
|
|
340
343
|
}
|
|
341
344
|
catch (error) {
|
|
342
345
|
clearTimeout(timeoutId);
|
|
@@ -348,7 +351,7 @@ function forwardToServer(req, url) {
|
|
|
348
351
|
timeoutMs: VERYFRONT_SERVER_REQUEST_TIMEOUT_MS,
|
|
349
352
|
});
|
|
350
353
|
lifecycle.end(UPSTREAM_TIMEOUT_STATUS, error);
|
|
351
|
-
return createUpstreamTimeoutResponse(VERYFRONT_SERVER_REQUEST_TIMEOUT_MS);
|
|
354
|
+
return withProxyTiming(createUpstreamTimeoutResponse(VERYFRONT_SERVER_REQUEST_TIMEOUT_MS));
|
|
352
355
|
}
|
|
353
356
|
// Check if this is a retryable error and we have retries left
|
|
354
357
|
if (isRetryableConnectionError(error) && attempt < maxRetries) {
|
|
@@ -378,17 +381,17 @@ function forwardToServer(req, url) {
|
|
|
378
381
|
const logLevel = getProxyFailureLogLevel(UPSTREAM_FAILURE_STATUS, req.method, url.pathname);
|
|
379
382
|
proxyLogger[logLevel](`${UPSTREAM_FAILURE_STATUS} ${req.method} ${url.pathname}`, { ms }, lastError);
|
|
380
383
|
lifecycle.end(UPSTREAM_FAILURE_STATUS, lastError);
|
|
381
|
-
return createUpstreamFailureResponse(lastError);
|
|
384
|
+
return withProxyTiming(createUpstreamFailureResponse(lastError));
|
|
382
385
|
});
|
|
383
386
|
}
|
|
384
387
|
catch (error) {
|
|
385
388
|
const ms = Math.round(performance.now() - startTime);
|
|
386
389
|
proxyLogger.error(`500 ${req.method} ${url.pathname}`, { ms }, error);
|
|
387
390
|
lifecycle.end(500, error);
|
|
388
|
-
return jsonErrorResponse(500, {
|
|
391
|
+
return withProxyTiming(jsonErrorResponse(500, {
|
|
389
392
|
error: "Internal Proxy Error",
|
|
390
393
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
391
|
-
});
|
|
394
|
+
}));
|
|
392
395
|
}
|
|
393
396
|
};
|
|
394
397
|
return runProxyRequestLifecycle({
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ProxyServerTiming {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
startedAt: number;
|
|
4
|
+
phases: Map<string, number>;
|
|
5
|
+
}
|
|
6
|
+
export declare function shouldEnableProxyServerTiming(): boolean;
|
|
7
|
+
export declare function createProxyServerTiming(enabled?: boolean): ProxyServerTiming;
|
|
8
|
+
export declare function markProxyServerTimingPhase(timing: ProxyServerTiming, name: string, durationMs?: number): void;
|
|
9
|
+
export declare function profileProxyServerTimingPhase<T>(timing: ProxyServerTiming, name: string, fn: () => Promise<T>): Promise<T>;
|
|
10
|
+
export declare function withProxyServerTimingHeader(response: Response, timing: ProxyServerTiming, totalMs?: number): Response;
|
|
11
|
+
//# sourceMappingURL=server-timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-timing.d.ts","sourceRoot":"","sources":["../../../src/src/proxy/server-timing.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAcD,wBAAgB,6BAA6B,IAAI,OAAO,CAGvD;AAED,wBAAgB,uBAAuB,CACrC,OAAO,UAAkC,GACxC,iBAAiB,CAMnB;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,UAAU,SAAI,GACb,IAAI,CAGN;AAED,wBAAsB,6BAA6B,CAAC,CAAC,EACnD,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CASZ;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,iBAAiB,EACzB,OAAO,SAAuC,GAC7C,QAAQ,CAwBV"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getEnv } from "../platform/compat/process.js";
|
|
2
|
+
function roundMs(value) {
|
|
3
|
+
return Math.round(value * 100) / 100;
|
|
4
|
+
}
|
|
5
|
+
function formatDuration(value) {
|
|
6
|
+
return Math.max(0, roundMs(value)).toFixed(2);
|
|
7
|
+
}
|
|
8
|
+
function sanitizeMetricName(name) {
|
|
9
|
+
return name.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, "_");
|
|
10
|
+
}
|
|
11
|
+
export function shouldEnableProxyServerTiming() {
|
|
12
|
+
return getEnv("VERYFRONT_ENABLE_PROXY_SERVER_TIMING") === "1" ||
|
|
13
|
+
getEnv("VERYFRONT_ENABLE_SERVER_TIMING") === "1";
|
|
14
|
+
}
|
|
15
|
+
export function createProxyServerTiming(enabled = shouldEnableProxyServerTiming()) {
|
|
16
|
+
return {
|
|
17
|
+
enabled,
|
|
18
|
+
startedAt: performance.now(),
|
|
19
|
+
phases: new Map(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function markProxyServerTimingPhase(timing, name, durationMs = 0) {
|
|
23
|
+
if (!timing.enabled)
|
|
24
|
+
return;
|
|
25
|
+
timing.phases.set(name, roundMs((timing.phases.get(name) ?? 0) + durationMs));
|
|
26
|
+
}
|
|
27
|
+
export async function profileProxyServerTimingPhase(timing, name, fn) {
|
|
28
|
+
if (!timing.enabled)
|
|
29
|
+
return await fn();
|
|
30
|
+
const startedAt = performance.now();
|
|
31
|
+
try {
|
|
32
|
+
return await fn();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
markProxyServerTimingPhase(timing, name, performance.now() - startedAt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function withProxyServerTimingHeader(response, timing, totalMs = performance.now() - timing.startedAt) {
|
|
39
|
+
if (!timing.enabled)
|
|
40
|
+
return response;
|
|
41
|
+
const metrics = [`proxy.total;dur=${formatDuration(totalMs)}`];
|
|
42
|
+
for (const [name, duration] of timing.phases.entries()) {
|
|
43
|
+
metrics.push(`${sanitizeMetricName(name)};dur=${formatDuration(duration)}`);
|
|
44
|
+
}
|
|
45
|
+
const value = metrics.join(", ");
|
|
46
|
+
try {
|
|
47
|
+
const existing = response.headers.get("Server-Timing");
|
|
48
|
+
response.headers.set("Server-Timing", existing ? `${existing}, ${value}` : value);
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
const headers = new Headers(response.headers);
|
|
53
|
+
const existing = headers.get("Server-Timing");
|
|
54
|
+
headers.set("Server-Timing", existing ? `${existing}, ${value}` : value);
|
|
55
|
+
return new Response(response.body, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.814",
|
|
4
4
|
"description": "The simplest way to build AI-powered apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -347,14 +347,14 @@
|
|
|
347
347
|
"@kreuzberg/node": "4.4.2",
|
|
348
348
|
"@kreuzberg/wasm": "4.5.2",
|
|
349
349
|
"@opentelemetry/api": "1.9.1",
|
|
350
|
-
"@opentelemetry/auto-instrumentations-node": "0.
|
|
351
|
-
"@opentelemetry/context-async-hooks": "2.
|
|
352
|
-
"@opentelemetry/core": "2.
|
|
353
|
-
"@opentelemetry/exporter-trace-otlp-http": "0.
|
|
354
|
-
"@opentelemetry/resources": "2.
|
|
355
|
-
"@opentelemetry/sdk-node": "0.
|
|
356
|
-
"@opentelemetry/sdk-trace-base": "2.
|
|
357
|
-
"@opentelemetry/semantic-conventions": "1.
|
|
350
|
+
"@opentelemetry/auto-instrumentations-node": "0.77.0",
|
|
351
|
+
"@opentelemetry/context-async-hooks": "2.8.0",
|
|
352
|
+
"@opentelemetry/core": "2.8.0",
|
|
353
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.219.0",
|
|
354
|
+
"@opentelemetry/resources": "2.8.0",
|
|
355
|
+
"@opentelemetry/sdk-node": "0.219.0",
|
|
356
|
+
"@opentelemetry/sdk-trace-base": "2.8.0",
|
|
357
|
+
"@opentelemetry/semantic-conventions": "1.41.1"
|
|
358
358
|
},
|
|
359
359
|
"devDependencies": {
|
|
360
360
|
"@types/node": "20.9.0"
|