narrarium-engine 0.1.16 → 0.1.20
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/README.md +35 -4
- package/dist/ai/config.d.ts +91 -0
- package/dist/ai/config.d.ts.map +1 -1
- package/dist/ai/config.js +150 -0
- package/dist/ai/config.js.map +1 -1
- package/dist/ai/fetch-client.d.ts +39 -4
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +276 -123
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/memory.d.ts +34 -0
- package/dist/ai/memory.d.ts.map +1 -0
- package/dist/ai/memory.js +27 -0
- package/dist/ai/memory.js.map +1 -0
- package/dist/ai/provider-error.d.ts +50 -0
- package/dist/ai/provider-error.d.ts.map +1 -0
- package/dist/ai/provider-error.js +197 -0
- package/dist/ai/provider-error.js.map +1 -0
- package/dist/ai/redact.js +1 -1
- package/dist/ai/redact.js.map +1 -1
- package/dist/ai/request.d.ts +98 -9
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +153 -23
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/responses.d.ts +106 -0
- package/dist/ai/responses.d.ts.map +1 -0
- package/dist/ai/responses.js +226 -0
- package/dist/ai/responses.js.map +1 -0
- package/dist/ai/router.d.ts +28 -4
- package/dist/ai/router.d.ts.map +1 -1
- package/dist/ai/router.js +57 -23
- package/dist/ai/router.js.map +1 -1
- package/dist/ai/routing.d.ts +14 -4
- package/dist/ai/routing.d.ts.map +1 -1
- package/dist/ai/routing.js +88 -16
- package/dist/ai/routing.js.map +1 -1
- package/dist/ai/types.d.ts +77 -2
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +6 -2
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/attempt.d.ts +11 -0
- package/dist/autopilot/attempt.d.ts.map +1 -0
- package/dist/autopilot/attempt.js +53 -0
- package/dist/autopilot/attempt.js.map +1 -0
- package/dist/autopilot/calls/recorder.d.ts +1 -0
- package/dist/autopilot/calls/recorder.d.ts.map +1 -1
- package/dist/autopilot/calls/recorder.js +16 -1
- package/dist/autopilot/calls/recorder.js.map +1 -1
- package/dist/autopilot/calls/run-calls.d.ts +8 -0
- package/dist/autopilot/calls/run-calls.d.ts.map +1 -1
- package/dist/autopilot/calls/run-calls.js +56 -4
- package/dist/autopilot/calls/run-calls.js.map +1 -1
- package/dist/autopilot/calls/types.d.ts +29 -6
- package/dist/autopilot/calls/types.d.ts.map +1 -1
- package/dist/autopilot/calls/types.js +2 -2
- package/dist/autopilot/calls/types.js.map +1 -1
- package/dist/autopilot/errors.d.ts.map +1 -1
- package/dist/autopilot/errors.js +111 -1
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/live.d.ts +11 -1
- package/dist/autopilot/live.d.ts.map +1 -1
- package/dist/autopilot/live.js +17 -2
- package/dist/autopilot/live.js.map +1 -1
- package/dist/autopilot/runner.d.ts +5 -0
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +40 -1
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +8 -0
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +10 -2
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/types.d.ts +94 -7
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +2 -0
- package/dist/autopilot/types.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/ai/routing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { likelyMessageTokens, likelyTextTokens, resolveModelTokenBudgets } from "./budget.js";
|
|
2
2
|
import { redactSecrets } from "./redact.js";
|
|
3
|
-
import { buildChatRequest } from "./request.js";
|
|
4
|
-
import {
|
|
3
|
+
import { buildChatRequest, candidateDestination, effectiveAiBase, endpointOrigin } from "./request.js";
|
|
4
|
+
import { describeAiRoute } from "./router.js";
|
|
5
5
|
import { AiPromptTooLargeError, AiProviderError, AiRoutingBudgetError, AiToolsRequiredError, AiUnavailableError } from "./types.js";
|
|
6
6
|
/** What a fallback's privacy boundary is: the integration (one provider account). Same as the web app's `candidateBoundary`. */
|
|
7
7
|
export function candidateBoundary(candidate) {
|
|
@@ -14,6 +14,32 @@ export function applySameBoundaryPolicy(config, candidates) {
|
|
|
14
14
|
const primary = candidateBoundary(candidates[0]);
|
|
15
15
|
return candidates.filter((candidate) => candidateBoundary(candidate) === primary);
|
|
16
16
|
}
|
|
17
|
+
/** The step that says a candidate was left out: who it is, and why (`extra` has the numbers). Names are cleaned of the credentials of the configuration. */
|
|
18
|
+
export function leftOutStep(candidate, position, reason, secrets, githubModelsBaseUrl, extra = {}) {
|
|
19
|
+
const { endpoint, path, protocol } = candidateDestination(candidate, githubModelsBaseUrl);
|
|
20
|
+
return {
|
|
21
|
+
position,
|
|
22
|
+
integrationId: redactSecrets(candidate.integration.id, secrets),
|
|
23
|
+
integrationName: redactSecrets(candidate.integration.name, secrets),
|
|
24
|
+
provider: candidate.integration.provider,
|
|
25
|
+
model: redactSecrets(candidate.model, secrets),
|
|
26
|
+
outcome: "left-out",
|
|
27
|
+
...(endpoint ? { endpoint } : {}),
|
|
28
|
+
...(path ? { path: redactSecrets(path, secrets) } : {}),
|
|
29
|
+
...(protocol ? { protocol } : {}),
|
|
30
|
+
leftOut: reason,
|
|
31
|
+
...extra,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** The route of a failed plan, in the order the author wrote it: what a host puts on the error it ends with. */
|
|
35
|
+
export function sortedRoute(steps) {
|
|
36
|
+
return [...steps].sort((left, right) => left.position - right.position);
|
|
37
|
+
}
|
|
38
|
+
function withRoute(error, steps) {
|
|
39
|
+
if (steps.length)
|
|
40
|
+
error.route = sortedRoute(steps);
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
17
43
|
export function routingLimits(config) {
|
|
18
44
|
const execution = config.routingExecution;
|
|
19
45
|
return { maxTotalDurationMs: execution?.maxTotalDurationMs, maxTokenAttempts: execution?.maxTokenAttempts, maxEstimatedCost: execution?.maxEstimatedCost };
|
|
@@ -25,38 +51,81 @@ function estimateAttempt(candidate, inputTokens, outputLimit) {
|
|
|
25
51
|
cost: candidate.pricing ? inputTokens / 1_000_000 * (candidate.pricing.inputPerMTok ?? 0) + output / 1_000_000 * (candidate.pricing.outputPerMTok ?? 0) : 0,
|
|
26
52
|
};
|
|
27
53
|
}
|
|
54
|
+
/** The step that says a target of the route cannot be called at all: who it is as far as the configuration knows it, and why. */
|
|
55
|
+
function unusableStep(entry, config, secrets, githubModelsBaseUrl) {
|
|
56
|
+
const target = entry.target;
|
|
57
|
+
const integration = config.aiIntegrations.find((candidate) => candidate.id === target?.integrationId);
|
|
58
|
+
const endpoint = integration ? endpointOrigin(effectiveAiBase(integration, githubModelsBaseUrl)) : undefined;
|
|
59
|
+
return {
|
|
60
|
+
position: entry.position,
|
|
61
|
+
integrationId: redactSecrets(target?.integrationId ?? "", secrets),
|
|
62
|
+
integrationName: redactSecrets(integration?.name ?? target?.integrationId ?? "", secrets),
|
|
63
|
+
provider: integration?.provider ?? "",
|
|
64
|
+
model: redactSecrets(target?.model ?? "", secrets),
|
|
65
|
+
outcome: "left-out",
|
|
66
|
+
...(endpoint ? { endpoint } : {}),
|
|
67
|
+
leftOut: "unusable",
|
|
68
|
+
...(entry.unusable ? { why: entry.unusable } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** What the author reads when a route is written and none of its targets can be called. */
|
|
72
|
+
function unusableMessage(capability, steps) {
|
|
73
|
+
const why = {
|
|
74
|
+
"integration-missing": "its integration is no longer there",
|
|
75
|
+
"provider-unsupported": "its provider cannot run chat tasks here",
|
|
76
|
+
"model-missing": "the model is not in the integration",
|
|
77
|
+
"task-not-allowed": "the model is not allowed for this task",
|
|
78
|
+
};
|
|
79
|
+
const list = steps.map((step) => `"${step.model}" in "${step.integrationName}" (${step.why ? why[step.why] : "it cannot be called"})`).join("; ");
|
|
80
|
+
return `No model of the route of the "${capability}" task can be called: ${list}. Fix the route in the AI router or the models in AI Integrations. Nothing was sent.`;
|
|
81
|
+
}
|
|
28
82
|
/**
|
|
29
|
-
* The candidates a call will try, in order, with the request each would get: the route's order, minus the fallbacks the
|
|
83
|
+
* The candidates a call will try, in order, with the request each would get: the route's order, minus the targets that cannot be called, minus the fallbacks the
|
|
30
84
|
* privacy policy excludes, minus (for a structured request, with "Tools only" on, which is the default) the models marked as without
|
|
31
85
|
* tool calls, minus the candidates whose context window cannot hold the prompt (a prompt is never cut),
|
|
32
86
|
* kept while the estimated attempts stay within the token and cost limits. A prompt no window holds, a first attempt
|
|
33
87
|
* that alone exceeds the limits, or a route where no model can call a function, is refused before anything is sent.
|
|
34
88
|
* The privacy policy is applied to the whole route first, so a primary that is skipped is still the account content is meant to stay in.
|
|
89
|
+
* Whatever is left out has its place in the route and its reason in `leftOut`, and in the `route` of the error when nothing is left to ask: a candidate is never dropped without a word.
|
|
35
90
|
*/
|
|
36
91
|
export function planAttempts(config, request, githubModelsBaseUrl) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
92
|
+
const entries = describeAiRoute(config, request.capability);
|
|
93
|
+
const resolved = entries.flatMap((entry) => (entry.candidate ? [entry.candidate] : []));
|
|
94
|
+
const secrets = config.aiIntegrations.map((integration) => integration.apiKey);
|
|
95
|
+
const leftOut = entries.filter((entry) => entry.unusable).map((entry) => unusableStep(entry, config, secrets, githubModelsBaseUrl));
|
|
96
|
+
if (!resolved.length) {
|
|
97
|
+
const unavailable = new AiUnavailableError(request.capability, leftOut.length ? redactSecrets(unusableMessage(request.capability, leftOut), secrets) : undefined);
|
|
98
|
+
throw withRoute(unavailable, leftOut);
|
|
99
|
+
}
|
|
100
|
+
const positions = new Map(entries.flatMap((entry) => (entry.candidate ? [[entry.candidate, entry.position]] : [])));
|
|
101
|
+
const place = (candidate) => positions.get(candidate) ?? 0;
|
|
40
102
|
const limits = routingLimits(config);
|
|
41
103
|
const inBoundary = applySameBoundaryPolicy(config, resolved);
|
|
104
|
+
for (const candidate of resolved)
|
|
105
|
+
if (!inBoundary.includes(candidate))
|
|
106
|
+
leftOut.push(leftOutStep(candidate, place(candidate), "boundary", secrets, githubModelsBaseUrl));
|
|
42
107
|
const toolsOnly = config.toolsOnly !== false && Boolean(request.json);
|
|
43
108
|
const skipped = [];
|
|
44
109
|
const allowed = inBoundary.filter((candidate) => {
|
|
45
110
|
if (!toolsOnly || candidate.supportsToolCalls !== false)
|
|
46
111
|
return true;
|
|
47
|
-
skipped.push({ candidate, index:
|
|
112
|
+
skipped.push({ candidate, index: place(candidate), reason: "no-tool-calls" });
|
|
113
|
+
leftOut.push(leftOutStep(candidate, place(candidate), "no-tool-calls", secrets, githubModelsBaseUrl));
|
|
48
114
|
return false;
|
|
49
115
|
});
|
|
50
116
|
if (!allowed.length) {
|
|
51
|
-
|
|
52
|
-
throw new AiToolsRequiredError(redactSecrets(toolsRequiredMessage(skipped), secrets), skipped.map((entry) => redactSecrets(entry.candidate.model, secrets)), skipped.map((entry) => ({ integration: entry.candidate.integration.id, model: redactSecrets(entry.candidate.model, secrets) })));
|
|
117
|
+
throw withRoute(new AiToolsRequiredError(redactSecrets(toolsRequiredMessage(skipped), secrets), skipped.map((entry) => redactSecrets(entry.candidate.model, secrets)), skipped.map((entry) => ({ integration: entry.candidate.integration.id, model: redactSecrets(entry.candidate.model, secrets) }))), leftOut);
|
|
53
118
|
}
|
|
54
|
-
const planned = allowed.map((
|
|
55
|
-
const index =
|
|
119
|
+
const planned = allowed.map((entry) => {
|
|
120
|
+
const index = place(entry);
|
|
121
|
+
// What the host has learned of the model (see `AiModelMemory`) is applied as if the author had set it: a model known to refuse thinking with tools is not sent a level with them.
|
|
122
|
+
const remembered = request.memory?.noThinkingWithTools(entry.integration.id, entry.model);
|
|
123
|
+
const how = remembered === "none" || entry.noThinkingWithTools === "none" ? "none" : entry.noThinkingWithTools ?? remembered;
|
|
124
|
+
const candidate = how !== entry.noThinkingWithTools ? { ...entry, noThinkingWithTools: how } : entry;
|
|
56
125
|
try {
|
|
57
126
|
const built = buildChatRequest(candidate, request, { githubModelsBaseUrl });
|
|
58
127
|
const tools = built.useTools ? likelyTextTokens(JSON.stringify(built.body.tools)) + 8 : 0;
|
|
59
|
-
const inputTokens = likelyMessageTokens(built.
|
|
128
|
+
const inputTokens = likelyMessageTokens(built.messages) + tools;
|
|
60
129
|
return { candidate, index, built, inputTokens, estimate: estimateAttempt(candidate, inputTokens, built.outputLimit) };
|
|
61
130
|
}
|
|
62
131
|
catch (error) {
|
|
@@ -73,27 +142,30 @@ export function planAttempts(config, request, githubModelsBaseUrl) {
|
|
|
73
142
|
return true;
|
|
74
143
|
largestBudget = Math.max(largestBudget, available);
|
|
75
144
|
estimated = Math.max(estimated, attempt.inputTokens);
|
|
145
|
+
leftOut.push(leftOutStep(attempt.candidate, attempt.index, "context-window", secrets, githubModelsBaseUrl, { promptTokens: attempt.inputTokens, windowTokens: available }));
|
|
76
146
|
return false;
|
|
77
147
|
});
|
|
78
148
|
if (!fitting.length) {
|
|
79
|
-
throw new AiPromptTooLargeError(`The prompt (about ${estimated} tokens) is larger than the context window configured for every model routed to this task (largest input budget: ${largestBudget} tokens, after the output reserve and a 5% safety margin). Nothing was sent. Raise the models' context window ("maxInputTokens") if they support more, or route this task to a model with a larger context window.`, estimated, largestBudget);
|
|
149
|
+
throw withRoute(new AiPromptTooLargeError(`The prompt (about ${estimated} tokens) is larger than the context window configured for every model routed to this task (largest input budget: ${largestBudget} tokens, after the output reserve and a 5% safety margin). Nothing was sent. Raise the models' context window ("maxInputTokens") if they support more, or route this task to a model with a larger context window.`, estimated, largestBudget), leftOut);
|
|
80
150
|
}
|
|
81
151
|
const attempts = [];
|
|
82
152
|
let tokens = 0;
|
|
83
153
|
let cost = 0;
|
|
84
|
-
for (const attempt of fitting) {
|
|
154
|
+
for (const [at, attempt] of fitting.entries()) {
|
|
85
155
|
const overTokens = limits.maxTokenAttempts !== undefined && tokens + attempt.estimate.tokens > limits.maxTokenAttempts;
|
|
86
156
|
const overCost = limits.maxEstimatedCost !== undefined && cost + attempt.estimate.cost > limits.maxEstimatedCost;
|
|
87
157
|
if (overTokens || overCost) {
|
|
158
|
+
for (const rest of fitting.slice(at))
|
|
159
|
+
leftOut.push(leftOutStep(rest.candidate, rest.index, "budget", secrets, githubModelsBaseUrl));
|
|
88
160
|
if (!attempts.length)
|
|
89
|
-
throw new AiRoutingBudgetError("The first routing candidate exceeds the configured token-attempt or estimated-cost budget (maxTokenAttempts, maxEstimatedCost). Nothing was sent.");
|
|
161
|
+
throw withRoute(new AiRoutingBudgetError("The first routing candidate exceeds the configured token-attempt or estimated-cost budget (maxTokenAttempts, maxEstimatedCost). Nothing was sent."), leftOut);
|
|
90
162
|
break;
|
|
91
163
|
}
|
|
92
164
|
attempts.push(attempt);
|
|
93
165
|
tokens += attempt.estimate.tokens;
|
|
94
166
|
cost += attempt.estimate.cost;
|
|
95
167
|
}
|
|
96
|
-
return { attempts, primary: resolved[0], limits, excludedByBoundary: resolved.length - inBoundary.length, skipped };
|
|
168
|
+
return { attempts, primary: resolved[0], limits, excludedByBoundary: resolved.length - inBoundary.length, skipped, leftOut: sortedRoute(leftOut) };
|
|
97
169
|
}
|
|
98
170
|
function toolsRequiredMessage(skipped) {
|
|
99
171
|
const models = skipped.map(({ candidate }) => `"${candidate.model}" in "${candidate.integration.name}"`).join(", ");
|
package/dist/ai/routing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/ai/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE9F,OAAO,EAAE,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C,CAAC;YAC9N,MAAM;QACR,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAClC,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;AACrJ,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAkC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,KAAK,SAAS,SAAS,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpH,OAAO,0FAA0F,MAAM,yKAAyK,CAAC;AACnR,CAAC"}
|
package/dist/ai/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { FetchAiAttempt, FetchAiAttemptEnd } from "./fetch-client.js";
|
|
2
|
+
import type { AiModelLearning, AiModelMemory } from "./memory.js";
|
|
3
|
+
import type { AiErrorBody } from "./provider-error.js";
|
|
2
4
|
/** Function-calling schema used to request structured output. */
|
|
3
5
|
export interface AiJsonSchema {
|
|
4
6
|
name: string;
|
|
@@ -77,6 +79,10 @@ export interface AiRequest {
|
|
|
77
79
|
onAttempt?: (attempt: FetchAiAttempt) => void;
|
|
78
80
|
/** An attempt of this call ended, worked or not (the client's `onAttemptEnd`, for this call only). Never part of what is sent. */
|
|
79
81
|
onAttemptEnd?: (end: FetchAiAttemptEnd) => void;
|
|
82
|
+
/** What the host remembers of its models between calls (see `AiModelMemory`): the client applies it to the request and tells it what a refusal teaches. Never part of what is sent. */
|
|
83
|
+
memory?: AiModelMemory;
|
|
84
|
+
/** This call learned something about a model (see `AiModelLearning`): said once, when the call learns it. Never part of what is sent. */
|
|
85
|
+
onLearned?: (learning: AiModelLearning) => void;
|
|
80
86
|
}
|
|
81
87
|
export interface AiResponse {
|
|
82
88
|
text: string;
|
|
@@ -100,7 +106,9 @@ export interface AiPort {
|
|
|
100
106
|
}
|
|
101
107
|
export declare class AiUnavailableError extends Error {
|
|
102
108
|
readonly capability: string;
|
|
103
|
-
|
|
109
|
+
/** The targets of the route that cannot be called, when the author wrote one and none of them can (see `AiRouteStep`). */
|
|
110
|
+
route?: AiRouteStep[];
|
|
111
|
+
constructor(capability: string, message?: string);
|
|
104
112
|
}
|
|
105
113
|
/**
|
|
106
114
|
* The integration a failed request was sent to (the last candidate tried), so that a client can say where it failed. Never a key, and the
|
|
@@ -111,8 +119,14 @@ export interface AiErrorTarget {
|
|
|
111
119
|
provider: string;
|
|
112
120
|
model: string;
|
|
113
121
|
integrationId: string;
|
|
114
|
-
/** The origin (`https://api.openai.com`) of the integration's address: never its path or its query. */
|
|
122
|
+
/** The origin (`https://api.openai.com`) of the integration's address, or of the model's own address: never its path or its query (`path` is the path of an address of the model's own). */
|
|
115
123
|
endpoint?: string;
|
|
124
|
+
/** The API version the request carried (Azure OpenAI's `api-version`, or `v1`), as `effectiveApiVersion` says it for the model that was asked. Absent for a provider that has none. */
|
|
125
|
+
apiVersion?: string;
|
|
126
|
+
/** The model was asked through the Responses API (absent: Chat Completions). */
|
|
127
|
+
protocol?: "responses";
|
|
128
|
+
/** The path of the model's own address (`endpointUrl`), when it has one: with `endpoint`, where the request went. Never its query. */
|
|
129
|
+
path?: string;
|
|
116
130
|
}
|
|
117
131
|
/** Which deadline of a call ran out: the provider did not start answering (`start`), went silent while it answered (`idle`), or the call took longer than any call may (`total`). */
|
|
118
132
|
export type AiTimeoutPhase = "start" | "idle" | "total";
|
|
@@ -123,6 +137,58 @@ export interface AiTimeoutDetails {
|
|
|
123
137
|
ms: number;
|
|
124
138
|
/** The provider timeout the integration asked for, when the call raised it to the minimum (`MIN_REQUEST_TIMEOUT_MS`). */
|
|
125
139
|
raisedFrom?: number;
|
|
140
|
+
/**
|
|
141
|
+
* The limit was not the call's own but the routing time that was left (`maxTotalDurationMs`, the author's «Maximum total duration», less what the earlier candidates of the call took):
|
|
142
|
+
* only a candidate after the first is held to it, and only it makes the deadline `total` shorter than the four hours that no call may pass.
|
|
143
|
+
*/
|
|
144
|
+
routing?: boolean;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Why a candidate of a route was not asked: its target cannot be called at all (`unusable`), "Tools only" skips a model without tool calls (`no-tool-calls`), the privacy policy keeps content in the
|
|
148
|
+
* primary's account (`boundary`), the prompt does not fit the model's context window (`context-window`), the routing limits of tokens or cost were reached (`budget`), the author did not acknowledge
|
|
149
|
+
* sending content to another account (`not-acknowledged`) or the routing time was used up (`out-of-time`).
|
|
150
|
+
*/
|
|
151
|
+
export type AiLeftOutReason = "unusable" | "no-tool-calls" | "boundary" | "context-window" | "budget" | "not-acknowledged" | "out-of-time";
|
|
152
|
+
/** Why a target the author wrote in a route cannot be called: its integration is gone, its provider cannot run chat here, its model is not in the integration, or the model is not allowed this task. */
|
|
153
|
+
export type AiUnusableWhy = "integration-missing" | "provider-unsupported" | "model-missing" | "task-not-allowed";
|
|
154
|
+
/**
|
|
155
|
+
* What became of one candidate of the route of a call: it was asked (and how it ended) or it was left out (and why). The route is the author's, in the order they wrote it: `position` 0 is the
|
|
156
|
+
* primary, and a candidate that the router could not use or the plan left out has its place in it, so that the primary that did not answer is never taken for the one that did. Names are the author's
|
|
157
|
+
* and are cleaned of credentials; nothing here is a key or the text of a request or a reply. A host keeps it on the error of a call that failed (`AiProviderError.route`) and in its records.
|
|
158
|
+
*/
|
|
159
|
+
export interface AiRouteStep {
|
|
160
|
+
position: number;
|
|
161
|
+
integrationId: string;
|
|
162
|
+
integrationName: string;
|
|
163
|
+
provider: string;
|
|
164
|
+
model: string;
|
|
165
|
+
outcome: "ok" | "failed" | "timeout" | "cancelled" | "left-out";
|
|
166
|
+
/** The origin of the integration's address, or of the model's own address (never a path or a query). */
|
|
167
|
+
endpoint?: string;
|
|
168
|
+
/** The API version the attempt carried (Azure OpenAI's `api-version`, or `v1`), when the provider has one: the model's own, else its integration's. */
|
|
169
|
+
apiVersion?: string;
|
|
170
|
+
/** The model was asked through the Responses API (absent: Chat Completions). */
|
|
171
|
+
protocol?: "responses";
|
|
172
|
+
/** The path of the model's own address (`endpointUrl`), when it has one: with `endpoint`, where the request went. Never its query. */
|
|
173
|
+
path?: string;
|
|
174
|
+
/** The HTTP status the provider answered, when it did. */
|
|
175
|
+
status?: number;
|
|
176
|
+
/** How long the attempt took, in milliseconds. Absent for a candidate that was left out. */
|
|
177
|
+
durationMs?: number;
|
|
178
|
+
/** What the provider or the engine said, cleaned of credentials and cut short. Absent for a candidate that was left out. */
|
|
179
|
+
message?: string;
|
|
180
|
+
/** What the provider answered, in its own words (message, type, param, code and the status), when it refused the request: the whole of what `message` shortens. */
|
|
181
|
+
body?: AiErrorBody;
|
|
182
|
+
/** For a timeout: which deadline ran out and how long it was, and whether it was the routing time that was left. */
|
|
183
|
+
timeoutPhase?: AiTimeoutPhase;
|
|
184
|
+
timeoutMs?: number;
|
|
185
|
+
routing?: boolean;
|
|
186
|
+
/** For a candidate that was left out: why, and the numbers that say it. */
|
|
187
|
+
leftOut?: AiLeftOutReason;
|
|
188
|
+
why?: AiUnusableWhy;
|
|
189
|
+
/** `context-window`: the tokens the prompt needs (as estimated before sending) and what the model's window leaves for it. */
|
|
190
|
+
promptTokens?: number;
|
|
191
|
+
windowTokens?: number;
|
|
126
192
|
}
|
|
127
193
|
/**
|
|
128
194
|
* How a streamed reply ended, as far as the engine could tell: `done` (the provider closed it with `[DONE]`), `closed` (the provider closed the connection without
|
|
@@ -164,6 +230,8 @@ export interface AiTransportDiagnostics {
|
|
|
164
230
|
}
|
|
165
231
|
/** What a failed attempt already cost: the provider may bill a reply the engine rejects. */
|
|
166
232
|
export interface AiProviderErrorDetails {
|
|
233
|
+
/** What the provider answered, in its own words: the status, and the message, type, param and code of its error (see `AiErrorBody`). Present on the failure of an HTTP request that was refused. */
|
|
234
|
+
body?: AiErrorBody;
|
|
167
235
|
/** Where the request went. Set by the engine's client on the errors of the candidates it tried. */
|
|
168
236
|
target?: AiErrorTarget;
|
|
169
237
|
/** What the transport saw of the failed call (see `AiTransportDiagnostics`). */
|
|
@@ -196,12 +264,18 @@ export interface AiProviderErrorDetails {
|
|
|
196
264
|
timedOut?: boolean;
|
|
197
265
|
/** Which deadline ran out, for a request that timed out. */
|
|
198
266
|
timeout?: AiTimeoutDetails;
|
|
267
|
+
/**
|
|
268
|
+
* Every candidate of the route of the call that failed, in the order the author wrote it: the ones that were asked and how each ended, the ones that were left out and why. Set by the engine's client
|
|
269
|
+
* on the error it ends with, so that a host does not take the last candidate for the only one.
|
|
270
|
+
*/
|
|
271
|
+
route?: AiRouteStep[];
|
|
199
272
|
}
|
|
200
273
|
/** The most characters of a reply that stopped halfway that an error keeps (`AiProviderErrorDetails.partialText`). */
|
|
201
274
|
export declare const MAX_PARTIAL_CHARACTERS = 200000;
|
|
202
275
|
export declare class AiProviderError extends Error {
|
|
203
276
|
readonly status?: number | undefined;
|
|
204
277
|
readonly retryable: boolean;
|
|
278
|
+
body?: AiErrorBody;
|
|
205
279
|
target?: AiErrorTarget;
|
|
206
280
|
transport?: AiTransportDiagnostics;
|
|
207
281
|
partialText?: string;
|
|
@@ -220,6 +294,7 @@ export declare class AiProviderError extends Error {
|
|
|
220
294
|
transient?: boolean;
|
|
221
295
|
timedOut?: boolean;
|
|
222
296
|
timeout?: AiTimeoutDetails;
|
|
297
|
+
route?: AiRouteStep[];
|
|
223
298
|
constructor(message: string, status?: number | undefined, retryable?: boolean, details?: AiProviderErrorDetails);
|
|
224
299
|
}
|
|
225
300
|
/** How a reply that was being streamed stopped: the connection was lost (`lost`), the provider closed the stream too early (`ended`), reported a failure inside it (`provider-error`) or ended it with an abort (`provider-abort`). */
|
package/dist/ai/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,iFAAiF;AACjF,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,mHAAmH;AACnH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,GAAG,MA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AAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,eAAe;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;IAAO,QAAQ,CAAC,aAAa,EAAE,cAAc,EAAE;gBAAzF,OAAO,EAAE,MAAM,EAAW,MAAM,GAAE,MAAM,EAAO,EAAW,aAAa,GAAE,cAAc,EAAO;CAI3G;AAED,gHAAgH;AAChH,eAAO,MAAM,eAAe;;;;;;;CAOlB,CAAC"}
|
package/dist/ai/types.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export class AiUnavailableError extends Error {
|
|
2
2
|
capability;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/** The targets of the route that cannot be called, when the author wrote one and none of them can (see `AiRouteStep`). */
|
|
4
|
+
route;
|
|
5
|
+
constructor(capability, message) {
|
|
6
|
+
super(message ?? `No AI model is configured for the "${capability}" task. Configure an integration in the AI router.`);
|
|
5
7
|
this.capability = capability;
|
|
6
8
|
this.name = "AiUnavailableError";
|
|
7
9
|
}
|
|
@@ -13,6 +15,7 @@ export const MAX_PARTIAL_CHARACTERS = 200_000;
|
|
|
13
15
|
export class AiProviderError extends Error {
|
|
14
16
|
status;
|
|
15
17
|
retryable;
|
|
18
|
+
body;
|
|
16
19
|
target;
|
|
17
20
|
transport;
|
|
18
21
|
partialText;
|
|
@@ -31,6 +34,7 @@ export class AiProviderError extends Error {
|
|
|
31
34
|
transient;
|
|
32
35
|
timedOut;
|
|
33
36
|
timeout;
|
|
37
|
+
route;
|
|
34
38
|
constructor(message, status, retryable = false, details = {}) {
|
|
35
39
|
super(message);
|
|
36
40
|
this.status = status;
|
package/dist/ai/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"A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B,EAAE,EAAW,gBAAkC,EAAE;QACxG,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QADG,WAAM,GAAN,MAAM,CAAe;QAAW,kBAAa,GAAb,aAAa,CAAuB;QAExG,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,gHAAgH;AAChH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,WAAW;IACnB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,mBAAmB;IAC3B,aAAa,EAAE,2BAA2B;IAC1C,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FetchAiAttempt } from "../ai/fetch-client.js";
|
|
2
|
+
import type { AutopilotAttemptInfo } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The attempt in flight as a client may keep it, from something read from elsewhere (an event, the snapshot of a host that is not this one): its fields as `AutopilotAttemptInfo` has them, or
|
|
5
|
+
* `undefined` when it does not say which candidate it is. Names are cut at a sane length, `fallback` is always `candidateIndex` above 0, and a thinking level this engine does not know is kept as it
|
|
6
|
+
* is (a newer host may have one): a client shows the word.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeAttempt(value: unknown): AutopilotAttemptInfo | undefined;
|
|
9
|
+
/** What the client says of the attempt it is about to send (the `call-attempt` event), without the prompt it carries, and nothing of the key: names and numbers. `undefined` when the report says too little. */
|
|
10
|
+
export declare function attemptInfoOf(report: FetchAiAttempt): AutopilotAttemptInfo | undefined;
|
|
11
|
+
//# sourceMappingURL=attempt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/autopilot/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAQvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAwBjF;AAED,iNAAiN;AACjN,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,oBAAoB,GAAG,SAAS,CActF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** The longest name a client keeps of an integration, a model or a thinking level: a configuration that a person wrote, never a place for text. */
|
|
2
|
+
const NAME_CHARACTERS = 160;
|
|
3
|
+
const whole = (value, least) => (typeof value === "number" && Number.isInteger(value) && value >= least ? value : undefined);
|
|
4
|
+
const word = (value) => (typeof value === "string" && value.trim() ? value.slice(0, NAME_CHARACTERS) : undefined);
|
|
5
|
+
/**
|
|
6
|
+
* The attempt in flight as a client may keep it, from something read from elsewhere (an event, the snapshot of a host that is not this one): its fields as `AutopilotAttemptInfo` has them, or
|
|
7
|
+
* `undefined` when it does not say which candidate it is. Names are cut at a sane length, `fallback` is always `candidateIndex` above 0, and a thinking level this engine does not know is kept as it
|
|
8
|
+
* is (a newer host may have one): a client shows the word.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeAttempt(value) {
|
|
11
|
+
if (!value || typeof value !== "object")
|
|
12
|
+
return undefined;
|
|
13
|
+
const source = value;
|
|
14
|
+
const attempt = whole(source.attempt, 1);
|
|
15
|
+
const candidateIndex = whole(source.candidateIndex, 0);
|
|
16
|
+
const integrationId = word(source.integrationId);
|
|
17
|
+
const integrationName = word(source.integrationName) ?? integrationId;
|
|
18
|
+
const model = word(source.model);
|
|
19
|
+
const thinking = word(source.thinking);
|
|
20
|
+
if (attempt === undefined || candidateIndex === undefined || !integrationId || !integrationName || !model || !thinking)
|
|
21
|
+
return undefined;
|
|
22
|
+
return {
|
|
23
|
+
attempt,
|
|
24
|
+
attempts: Math.max(attempt, whole(source.attempts, 1) ?? attempt),
|
|
25
|
+
candidateIndex,
|
|
26
|
+
candidateCount: Math.max(candidateIndex + 1, whole(source.candidateCount, 1) ?? candidateIndex + 1),
|
|
27
|
+
fallback: candidateIndex > 0,
|
|
28
|
+
integrationId,
|
|
29
|
+
integrationName,
|
|
30
|
+
provider: word(source.provider) ?? "",
|
|
31
|
+
model,
|
|
32
|
+
thinking: thinking,
|
|
33
|
+
...(source.thinkingWhy === "tools" ? { thinkingWhy: "tools" } : {}),
|
|
34
|
+
streamMode: source.streamMode === "off" ? "off" : "auto",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** What the client says of the attempt it is about to send (the `call-attempt` event), without the prompt it carries, and nothing of the key: names and numbers. `undefined` when the report says too little. */
|
|
38
|
+
export function attemptInfoOf(report) {
|
|
39
|
+
return normalizeAttempt({
|
|
40
|
+
attempt: report.attempt,
|
|
41
|
+
attempts: report.attempts,
|
|
42
|
+
candidateIndex: report.index,
|
|
43
|
+
candidateCount: report.candidates,
|
|
44
|
+
integrationId: report.integrationId,
|
|
45
|
+
integrationName: report.integrationName,
|
|
46
|
+
provider: report.provider,
|
|
47
|
+
model: report.model,
|
|
48
|
+
thinking: report.thinkingMode,
|
|
49
|
+
thinkingWhy: report.thinkingWhy,
|
|
50
|
+
streamMode: report.streamMode,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.js","sourceRoot":"","sources":["../../src/autopilot/attempt.ts"],"names":[],"mappings":"AAGA,mJAAmJ;AACnJ,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,KAAa,EAAsB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAClK,MAAM,IAAI,GAAG,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AAc,GAAG,CAAC,CAAC;QACnG,QAAQ,EAAE,cAAc,GAAG,CAAC;QAC5B,aAAa;QACb,eAAe;QACf,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QACrC,KAAK;QACL,QAAQ,EAAE,QAA4C;QACtD,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,UAAU,EAAE,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;KACzD,CAAC;AACJ,CAAC;AAED,iNAAiN;AACjN,MAAM,UAAU,aAAa,CAAC,MAAsB;IAClD,OAAO,gBAAgB,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,cAAc,EAAE,MAAM,CAAC,KAAK;QAC5B,cAAc,EAAE,MAAM,CAAC,UAAU;QACjC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,MAAM,CAAC,YAAY;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../../../src/autopilot/calls/recorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAA4B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../../../src/autopilot/calls/recorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,E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AQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BzG,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,gIAAgI;IAChI,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,uGAAuG;IACvG,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,oFAAoF;IACpF,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,+GAA+G;IAC/G,IAAI,OAAO,IAAI,OAAO,GAAG,IAAI,CAE5B;IAED,OAAO,CAAC,YAAY;IASpB,qHAAqH;IACrH,OAAO,CAAC,IAAI;IASZ;;;OAGG;IACH,OAAO,CAAC,IAAI;IAmBZ,iFAAiF;IACjF,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,aAAa;IASrB,yHAAyH;IACzH,OAAO,CAAC,aAAa;IAsBrB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,GAAG;IAQX,OAAO,CAAC,MAAM;IAMd,mIAAmI;IACnI,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,SAAS;IAOjB,yIAAyI;IACzI,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,YAAY;IA2CpB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,cAAc;CAkBvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clipWithEllipsis, normalizeErrorBody } from "../../ai/provider-error.js";
|
|
1
2
|
import { redactSecrets } from "../../ai/redact.js";
|
|
2
3
|
import { cutHead, endsWithHighSurrogate, suffixStart, utf8Length } from "./utf8.js";
|
|
3
4
|
import { AI_CALL_CHECKPOINT, AI_CALL_ERROR_CHARACTERS, AI_CALL_LIMITS, AI_CALLS_FORMAT_VERSION, aiCallIdOf, isSafeAiCallId, } from "./types.js";
|
|
@@ -348,6 +349,8 @@ export class CallRecorder {
|
|
|
348
349
|
model: this.short(attempt.model),
|
|
349
350
|
integrationId: this.short(attempt.integrationId),
|
|
350
351
|
endpoint: endpointOrigin(attempt.endpoint),
|
|
352
|
+
...(typeof attempt.apiVersion === "string" && /^[A-Za-z0-9][A-Za-z0-9._-]{0,39}$/.test(attempt.apiVersion) ? { apiVersion: attempt.apiVersion } : {}),
|
|
353
|
+
...(attempt.protocol === "responses" ? { protocol: "responses" } : {}),
|
|
351
354
|
stream: attempt.stream === true,
|
|
352
355
|
tools: attempt.tools === true,
|
|
353
356
|
firstByteMs: number(attempt.firstByteMs),
|
|
@@ -364,13 +367,25 @@ export class CallRecorder {
|
|
|
364
367
|
error: attempt.error
|
|
365
368
|
? {
|
|
366
369
|
name: this.short(attempt.error.name) ?? "Error",
|
|
367
|
-
message:
|
|
370
|
+
message: clipWithEllipsis(this.redact(attempt.error.message ?? ""), AI_CALL_ERROR_CHARACTERS),
|
|
368
371
|
status: number(attempt.error.status),
|
|
369
372
|
transient: attempt.error.transient === true,
|
|
370
373
|
timedOut: attempt.error.timedOut === true,
|
|
374
|
+
...(normalizeErrorBody(attempt.error.body, (value) => this.redact(value)) ? { body: normalizeErrorBody(attempt.error.body, (value) => this.redact(value)) } : {}),
|
|
371
375
|
}
|
|
372
376
|
: null,
|
|
373
377
|
partialCharacters: number(attempt.partialCharacters),
|
|
378
|
+
...(attempt.skip ? { skip: this.cleanSkip(attempt.skip) } : {}),
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
cleanSkip(skip) {
|
|
382
|
+
const promptTokens = number(skip.promptTokens);
|
|
383
|
+
const windowTokens = number(skip.windowTokens);
|
|
384
|
+
return {
|
|
385
|
+
reason: skip.reason,
|
|
386
|
+
...(skip.why ? { why: skip.why } : {}),
|
|
387
|
+
...(promptTokens !== null ? { promptTokens } : {}),
|
|
388
|
+
...(windowTokens !== null ? { windowTokens } : {}),
|
|
374
389
|
};
|
|
375
390
|
}
|
|
376
391
|
cleanTransport(transport) {
|