narrarium-engine 0.1.17 → 0.1.21
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 +44 -20
- 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 +27 -3
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +228 -126
- 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 +16 -6
- package/dist/ai/router.d.ts.map +1 -1
- package/dist/ai/router.js +41 -12
- package/dist/ai/router.js.map +1 -1
- package/dist/ai/routing.d.ts.map +1 -1
- package/dist/ai/routing.js +11 -5
- package/dist/ai/routing.js.map +1 -1
- package/dist/ai/types.d.ts +40 -2
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +16 -0
- 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.map +1 -1
- package/dist/autopilot/calls/recorder.js +5 -1
- package/dist/autopilot/calls/recorder.js.map +1 -1
- package/dist/autopilot/calls/run-calls.d.ts.map +1 -1
- package/dist/autopilot/calls/run-calls.js +5 -0
- package/dist/autopilot/calls/run-calls.js.map +1 -1
- package/dist/autopilot/calls/types.d.ts +10 -3
- 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 +42 -0
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/estimate-texts.js +4 -4
- package/dist/autopilot/estimate-texts.js.map +1 -1
- package/dist/autopilot/frozen.d.ts.map +1 -1
- package/dist/autopilot/frozen.js +14 -9
- package/dist/autopilot/frozen.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/outline-check.js +4 -4
- package/dist/autopilot/outline-check.js.map +1 -1
- package/dist/autopilot/planner.js +4 -4
- package/dist/autopilot/planner.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/tasks.js +4 -4
- package/dist/autopilot/tasks.js.map +1 -1
- package/dist/autopilot/types.d.ts +81 -6
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js.map +1 -1
- package/dist/book/outline.d.ts.map +1 -1
- package/dist/book/outline.js +7 -6
- package/dist/book/outline.js.map +1 -1
- package/dist/book/paths.d.ts +5 -0
- package/dist/book/paths.d.ts.map +1 -1
- package/dist/book/paths.js +5 -0
- package/dist/book/paths.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/server/client.js +1 -1
- package/dist/server/client.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reading side of the Responses API: what its events and its bodies say, told in the shape the client already reads a reply in (the chunk of a Chat Completions stream: a piece of text, a piece of a function
|
|
3
|
+
* call, the reason a reply ended, the tokens it used, an error). A reply of the Responses API is then read, judged and reported by the very code that reads the other: the deadlines, the progress, the live JSON of a
|
|
4
|
+
* structured reply, the usage and the failures are the same for both protocols, and nothing in the client knows two ways of doing them.
|
|
5
|
+
*
|
|
6
|
+
* Pure: it calls nothing and keeps nothing but what it has read of one stream. Every field of a provider's JSON is read defensively: what is not what it should be is as if it were not there.
|
|
7
|
+
*/
|
|
8
|
+
/** What a piece of a reply is, in the form the client reads (see the module's description). */
|
|
9
|
+
export interface ResponsesChunk {
|
|
10
|
+
choices: Array<{
|
|
11
|
+
delta?: {
|
|
12
|
+
content?: string;
|
|
13
|
+
tool_calls?: Array<{
|
|
14
|
+
index: number;
|
|
15
|
+
function: {
|
|
16
|
+
name?: string;
|
|
17
|
+
arguments?: string;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
finish_reason?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** The tokens of the response, as the provider reports them (`input_tokens`, `output_tokens` and their details). */
|
|
24
|
+
usage?: unknown;
|
|
25
|
+
/** The failure the provider reports, in the shape of its error (`code`, `type`, `message`, `param`). */
|
|
26
|
+
error?: unknown;
|
|
27
|
+
/** What the model said when it refused to answer instead of answering. */
|
|
28
|
+
refusal?: string;
|
|
29
|
+
/** The characters of reasoning that this piece shows (only their number is kept, never the reasoning). */
|
|
30
|
+
reasoningCharacters?: number;
|
|
31
|
+
/** The tokens the model spent reasoning, as the provider counts them: its reasoning is not shown, so this is all there is to tell that it reasoned. */
|
|
32
|
+
reasoningTokens?: number;
|
|
33
|
+
}
|
|
34
|
+
/** What a whole response says, told as one reply: used by a reply that is not streamed, and by the last event of a stream for what its pieces did not bring. */
|
|
35
|
+
export interface ResponsesReading {
|
|
36
|
+
/** The `output_text` of its messages, joined. */
|
|
37
|
+
text: string;
|
|
38
|
+
refusal: string;
|
|
39
|
+
/** The function calls of its output, by the position of the item in it. */
|
|
40
|
+
calls: Array<{
|
|
41
|
+
index: number;
|
|
42
|
+
name: string;
|
|
43
|
+
arguments: string;
|
|
44
|
+
}>;
|
|
45
|
+
reasoningCharacters: number;
|
|
46
|
+
reasoningTokens?: number;
|
|
47
|
+
/** How the reply ended, as a finish reason of the client's vocabulary. */
|
|
48
|
+
finishReason: string;
|
|
49
|
+
usage?: unknown;
|
|
50
|
+
/** The failure of a response whose status is `failed`. */
|
|
51
|
+
error?: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A response read as one reply. Its status decides how it ended (`status` is the one the event that carried it says, else the response's own): `completed` is `stop`, or `tool_calls` when it has a function call,
|
|
55
|
+
* `incomplete` says why in `incomplete_details` (the output limit is `length`), `failed` brings its error, `cancelled` is an end that no reply survives, and a refusal with no text and no call is `refusal`. A response
|
|
56
|
+
* that says no status is what a server that only sends the output gives: it is read for the output it has.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readResponse(value: unknown, status?: "completed" | "incomplete" | "failed"): ResponsesReading;
|
|
59
|
+
/** A response that is not streamed, told in the form the client reads a Chat Completions body in (`choices[0].message`), so that the same code reads it. */
|
|
60
|
+
export interface ResponsesAsChat {
|
|
61
|
+
choices: Array<{
|
|
62
|
+
message: {
|
|
63
|
+
content: string;
|
|
64
|
+
tool_calls?: Array<{
|
|
65
|
+
function: {
|
|
66
|
+
name: string;
|
|
67
|
+
arguments: string;
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
finish_reason: string;
|
|
72
|
+
}>;
|
|
73
|
+
usage?: unknown;
|
|
74
|
+
error?: unknown;
|
|
75
|
+
refusal?: string;
|
|
76
|
+
reasoningCharacters: number;
|
|
77
|
+
reasoningTokens?: number;
|
|
78
|
+
}
|
|
79
|
+
export declare function responseAsChat(value: unknown): ResponsesAsChat;
|
|
80
|
+
/**
|
|
81
|
+
* The events of one stream of the Responses API, one after the other, each told as the chunk the client reads (or as nothing, for an event that says nothing the client needs: the response is created, a part of
|
|
82
|
+
* a message begins, an annotation, a tool of the provider's own). It keeps what it has already told, so that a server that sends the same words twice (as deltas and again whole, in a `done` event or in the
|
|
83
|
+
* last event) is read once, and one that sends them only whole is read too. A stream that has no `response.completed`, `response.incomplete` or `response.failed` (nor an `error`) did not end properly (`finished`).
|
|
84
|
+
*/
|
|
85
|
+
export declare class ResponsesStreamReader {
|
|
86
|
+
private done;
|
|
87
|
+
/** The pieces of text that arrived, by the output item and the part of it. */
|
|
88
|
+
private readonly texts;
|
|
89
|
+
/** The function calls whose arguments arrived (as deltas, or whole), by the position of the item in the output. */
|
|
90
|
+
private readonly callsWithArguments;
|
|
91
|
+
private reasoned;
|
|
92
|
+
private called;
|
|
93
|
+
/** The stream ended properly: the provider sent its last event. */
|
|
94
|
+
get finished(): boolean;
|
|
95
|
+
/** One event: its data, parsed, and the name of its `event:` line (the data's own `type` says the same, and is read first). */
|
|
96
|
+
read(data: unknown, event?: string): ResponsesChunk | undefined;
|
|
97
|
+
private key;
|
|
98
|
+
/**
|
|
99
|
+
* A function call, or a piece of one: its name, and its arguments. The arguments that come whole (in the event that adds the item, in the one that ends its arguments or in the one that ends the item) are
|
|
100
|
+
* told only when none arrived before: the deltas are the arguments, and what is said again is not added to them.
|
|
101
|
+
*/
|
|
102
|
+
private call;
|
|
103
|
+
/** The last event: the end of the reply, its usage, its failure, and whatever the pieces did not bring (a server that streams nothing and says everything here). */
|
|
104
|
+
private last;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/ai/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+FAA+F;AAC/F,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;QACb,KAAK,CAAC,EAAE;YACN,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,UAAU,CAAC,EAAE,KAAK,CAAC;gBAAE,KAAK,EAAE,MAAM,CAAC;gBAAC,QAAQ,EAAE;oBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;oBAAC,SAAS,CAAC,EAAE,MAAM,CAAA;iBAAE,CAAA;aAAE,CAAC,CAAC;SACxF,CAAC;QACF,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,oHAAoH;IACpH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wGAAwG;IACxG,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uJAAuJ;IACvJ,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAiCD,gKAAgK;AAChK,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KAAK,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CA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ACH,OAAO,CAAC,IAAI;IAQZ,oKAAoK;IACpK,OAAO,CAAC,IAAI;CAoBb"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reading side of the Responses API: what its events and its bodies say, told in the shape the client already reads a reply in (the chunk of a Chat Completions stream: a piece of text, a piece of a function
|
|
3
|
+
* call, the reason a reply ended, the tokens it used, an error). A reply of the Responses API is then read, judged and reported by the very code that reads the other: the deadlines, the progress, the live JSON of a
|
|
4
|
+
* structured reply, the usage and the failures are the same for both protocols, and nothing in the client knows two ways of doing them.
|
|
5
|
+
*
|
|
6
|
+
* Pure: it calls nothing and keeps nothing but what it has read of one stream. Every field of a provider's JSON is read defensively: what is not what it should be is as if it were not there.
|
|
7
|
+
*/
|
|
8
|
+
const record = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : {});
|
|
9
|
+
const text = (value) => (typeof value === "string" ? value : "");
|
|
10
|
+
const position = (value) => (typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0);
|
|
11
|
+
const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
|
|
12
|
+
/** What `incomplete_details.reason` says, as a finish reason of the client's vocabulary (`classifyFinishReason`): the output limit is `length`, a content filter is `content_filter`; any other reason is `incomplete`, which is no end that can be trusted. */
|
|
13
|
+
function incompleteReason(details) {
|
|
14
|
+
const reason = text(record(details).reason).trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
15
|
+
if (reason === "max_output_tokens" || reason === "max_tokens" || reason === "length")
|
|
16
|
+
return "length";
|
|
17
|
+
if (reason === "content_filter")
|
|
18
|
+
return "content_filter";
|
|
19
|
+
return "incomplete";
|
|
20
|
+
}
|
|
21
|
+
/** The text of the `output_text` parts of a message item, and what its `refusal` parts say, by the position of the part. */
|
|
22
|
+
function messageParts(item) {
|
|
23
|
+
const parts = Array.isArray(item.content) ? item.content : [];
|
|
24
|
+
return parts.map((part) => {
|
|
25
|
+
const entry = record(part);
|
|
26
|
+
return { text: entry.type === "output_text" ? text(entry.text) : "", refusal: entry.type === "refusal" ? text(entry.refusal) : "" };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** The characters of the reasoning that a reasoning item shows (its summary, and the reasoning itself when the model gives it): none for a reasoning that is encrypted. */
|
|
30
|
+
function reasoningLength(item) {
|
|
31
|
+
let characters = 0;
|
|
32
|
+
for (const list of [item.summary, item.content]) {
|
|
33
|
+
for (const entry of Array.isArray(list) ? list : [])
|
|
34
|
+
characters += text(record(entry).text).length;
|
|
35
|
+
}
|
|
36
|
+
return characters;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A response read as one reply. Its status decides how it ended (`status` is the one the event that carried it says, else the response's own): `completed` is `stop`, or `tool_calls` when it has a function call,
|
|
40
|
+
* `incomplete` says why in `incomplete_details` (the output limit is `length`), `failed` brings its error, `cancelled` is an end that no reply survives, and a refusal with no text and no call is `refusal`. A response
|
|
41
|
+
* that says no status is what a server that only sends the output gives: it is read for the output it has.
|
|
42
|
+
*/
|
|
43
|
+
export function readResponse(value, status) {
|
|
44
|
+
const response = record(value);
|
|
45
|
+
const output = Array.isArray(response.output) ? response.output : [];
|
|
46
|
+
const pieces = [];
|
|
47
|
+
const refusals = [];
|
|
48
|
+
const calls = [];
|
|
49
|
+
let reasoningCharacters = 0;
|
|
50
|
+
output.forEach((entry, at) => {
|
|
51
|
+
const item = record(entry);
|
|
52
|
+
if (item.type === "message") {
|
|
53
|
+
for (const part of messageParts(item)) {
|
|
54
|
+
if (part.text)
|
|
55
|
+
pieces.push(part.text);
|
|
56
|
+
if (part.refusal)
|
|
57
|
+
refusals.push(part.refusal);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (item.type === "function_call") {
|
|
61
|
+
calls.push({ index: at, name: text(item.name), arguments: text(item.arguments) });
|
|
62
|
+
}
|
|
63
|
+
else if (item.type === "reasoning") {
|
|
64
|
+
reasoningCharacters += reasoningLength(item);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const body = pieces.join("");
|
|
68
|
+
const refusal = refusals.join(" ").trim();
|
|
69
|
+
const state = status ?? text(response.status).trim().toLowerCase();
|
|
70
|
+
const usage = record(response.usage);
|
|
71
|
+
const reasoningTokens = count(record(usage.output_tokens_details).reasoning_tokens);
|
|
72
|
+
let finishReason;
|
|
73
|
+
let error;
|
|
74
|
+
if (state === "failed") {
|
|
75
|
+
finishReason = "failed";
|
|
76
|
+
error = response.error ?? undefined;
|
|
77
|
+
}
|
|
78
|
+
else if (state === "cancelled" || state === "canceled") {
|
|
79
|
+
finishReason = "cancelled";
|
|
80
|
+
}
|
|
81
|
+
else if (state === "incomplete") {
|
|
82
|
+
finishReason = incompleteReason(response.incomplete_details);
|
|
83
|
+
}
|
|
84
|
+
else if (refusal && !body.trim() && !calls.length) {
|
|
85
|
+
finishReason = "refusal";
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
finishReason = calls.length ? "tool_calls" : "stop";
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
text: body,
|
|
92
|
+
refusal,
|
|
93
|
+
calls,
|
|
94
|
+
reasoningCharacters,
|
|
95
|
+
...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
|
|
96
|
+
finishReason,
|
|
97
|
+
...(response.usage && typeof response.usage === "object" ? { usage: response.usage } : {}),
|
|
98
|
+
...(error ? { error } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function responseAsChat(value) {
|
|
102
|
+
const reading = readResponse(value);
|
|
103
|
+
return {
|
|
104
|
+
choices: [{
|
|
105
|
+
message: {
|
|
106
|
+
content: reading.text,
|
|
107
|
+
...(reading.calls.length ? { tool_calls: reading.calls.map((call) => ({ function: { name: call.name, arguments: call.arguments } })) } : {}),
|
|
108
|
+
},
|
|
109
|
+
finish_reason: reading.finishReason,
|
|
110
|
+
}],
|
|
111
|
+
...(reading.usage ? { usage: reading.usage } : {}),
|
|
112
|
+
...(reading.error ? { error: reading.error } : {}),
|
|
113
|
+
...(reading.refusal ? { refusal: reading.refusal } : {}),
|
|
114
|
+
reasoningCharacters: reading.reasoningCharacters,
|
|
115
|
+
...(reading.reasoningTokens !== undefined ? { reasoningTokens: reading.reasoningTokens } : {}),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The events of one stream of the Responses API, one after the other, each told as the chunk the client reads (or as nothing, for an event that says nothing the client needs: the response is created, a part of
|
|
120
|
+
* a message begins, an annotation, a tool of the provider's own). It keeps what it has already told, so that a server that sends the same words twice (as deltas and again whole, in a `done` event or in the
|
|
121
|
+
* last event) is read once, and one that sends them only whole is read too. A stream that has no `response.completed`, `response.incomplete` or `response.failed` (nor an `error`) did not end properly (`finished`).
|
|
122
|
+
*/
|
|
123
|
+
export class ResponsesStreamReader {
|
|
124
|
+
done = false;
|
|
125
|
+
/** The pieces of text that arrived, by the output item and the part of it. */
|
|
126
|
+
texts = new Set();
|
|
127
|
+
/** The function calls whose arguments arrived (as deltas, or whole), by the position of the item in the output. */
|
|
128
|
+
callsWithArguments = new Set();
|
|
129
|
+
reasoned = false;
|
|
130
|
+
called = false;
|
|
131
|
+
/** The stream ended properly: the provider sent its last event. */
|
|
132
|
+
get finished() {
|
|
133
|
+
return this.done;
|
|
134
|
+
}
|
|
135
|
+
/** One event: its data, parsed, and the name of its `event:` line (the data's own `type` says the same, and is read first). */
|
|
136
|
+
read(data, event = "") {
|
|
137
|
+
const value = record(data);
|
|
138
|
+
const type = text(value.type) || event;
|
|
139
|
+
switch (type) {
|
|
140
|
+
case "response.output_text.delta": {
|
|
141
|
+
const delta = text(value.delta);
|
|
142
|
+
if (!delta)
|
|
143
|
+
return undefined;
|
|
144
|
+
this.texts.add(this.key(value));
|
|
145
|
+
return { choices: [{ delta: { content: delta } }] };
|
|
146
|
+
}
|
|
147
|
+
case "response.output_text.done": {
|
|
148
|
+
const key = this.key(value);
|
|
149
|
+
const whole = text(value.text);
|
|
150
|
+
if (this.texts.has(key) || !whole)
|
|
151
|
+
return undefined;
|
|
152
|
+
this.texts.add(key);
|
|
153
|
+
return { choices: [{ delta: { content: whole } }] };
|
|
154
|
+
}
|
|
155
|
+
case "response.reasoning_summary_text.delta":
|
|
156
|
+
case "response.reasoning_text.delta": {
|
|
157
|
+
const delta = text(value.delta);
|
|
158
|
+
if (!delta)
|
|
159
|
+
return undefined;
|
|
160
|
+
this.reasoned = true;
|
|
161
|
+
return { choices: [], reasoningCharacters: delta.length };
|
|
162
|
+
}
|
|
163
|
+
case "response.output_item.added":
|
|
164
|
+
case "response.output_item.done": {
|
|
165
|
+
const item = record(value.item);
|
|
166
|
+
return item.type === "function_call" ? this.call(position(value.output_index), text(item.name), text(item.arguments)) : undefined;
|
|
167
|
+
}
|
|
168
|
+
case "response.function_call_arguments.delta": {
|
|
169
|
+
const delta = text(value.delta);
|
|
170
|
+
return delta ? this.call(position(value.output_index), "", delta, true) : undefined;
|
|
171
|
+
}
|
|
172
|
+
case "response.function_call_arguments.done":
|
|
173
|
+
return this.call(position(value.output_index), text(value.name), text(value.arguments));
|
|
174
|
+
case "response.completed":
|
|
175
|
+
return this.last(record(value.response), "completed");
|
|
176
|
+
case "response.incomplete":
|
|
177
|
+
return this.last(record(value.response), "incomplete");
|
|
178
|
+
case "response.failed":
|
|
179
|
+
return this.last(record(value.response), "failed");
|
|
180
|
+
case "error":
|
|
181
|
+
this.done = true;
|
|
182
|
+
return { choices: [], error: value.error ?? value };
|
|
183
|
+
default:
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
key(value) {
|
|
188
|
+
return `${position(value.output_index)}:${position(value.content_index)}`;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A function call, or a piece of one: its name, and its arguments. The arguments that come whole (in the event that adds the item, in the one that ends its arguments or in the one that ends the item) are
|
|
192
|
+
* told only when none arrived before: the deltas are the arguments, and what is said again is not added to them.
|
|
193
|
+
*/
|
|
194
|
+
call(index, name, args, piece = false) {
|
|
195
|
+
this.called = true;
|
|
196
|
+
const arguments_ = piece || !this.callsWithArguments.has(index) ? args : "";
|
|
197
|
+
if (arguments_)
|
|
198
|
+
this.callsWithArguments.add(index);
|
|
199
|
+
if (!name && !arguments_)
|
|
200
|
+
return undefined;
|
|
201
|
+
return { choices: [{ delta: { tool_calls: [{ index, function: { ...(name ? { name } : {}), ...(arguments_ ? { arguments: arguments_ } : {}) } }] } }] };
|
|
202
|
+
}
|
|
203
|
+
/** The last event: the end of the reply, its usage, its failure, and whatever the pieces did not bring (a server that streams nothing and says everything here). */
|
|
204
|
+
last(response, status) {
|
|
205
|
+
this.done = true;
|
|
206
|
+
const reading = readResponse(response, status);
|
|
207
|
+
// What the pieces did not bring is read from the output only when they brought nothing of its kind: an output that a server numbers in another way than its events could be read twice.
|
|
208
|
+
const delta = {
|
|
209
|
+
...(this.texts.size === 0 && reading.text ? { content: reading.text } : {}),
|
|
210
|
+
...(this.callsWithArguments.size === 0 ? { tool_calls: reading.calls.filter((call) => call.arguments).map((call) => ({ index: call.index, function: { name: call.name, arguments: call.arguments } })) } : {}),
|
|
211
|
+
};
|
|
212
|
+
if (!delta.tool_calls?.length)
|
|
213
|
+
delete delta.tool_calls;
|
|
214
|
+
// The calls that the stream told are calls the reply has, even when its last event leaves them out.
|
|
215
|
+
const finishReason = reading.finishReason === "stop" && this.called ? "tool_calls" : reading.finishReason;
|
|
216
|
+
return {
|
|
217
|
+
choices: [{ ...(Object.keys(delta).length ? { delta } : {}), finish_reason: finishReason }],
|
|
218
|
+
...(reading.usage ? { usage: reading.usage } : {}),
|
|
219
|
+
...(reading.refusal ? { refusal: reading.refusal } : {}),
|
|
220
|
+
...(!this.reasoned && reading.reasoningCharacters ? { reasoningCharacters: reading.reasoningCharacters } : {}),
|
|
221
|
+
...(reading.reasoningTokens !== undefined ? { reasoningTokens: reading.reasoningTokens } : {}),
|
|
222
|
+
...(finishReason === "failed" ? { error: reading.error ?? { code: "failed", message: "The provider reported that the response failed." } } : {}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/ai/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,MAAM,MAAM,GAAG,CAAC,KAAc,EAA2B,EAAE,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAgC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAClK,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAClF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9H,MAAM,KAAK,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE9I,gQAAgQ;AAChQ,SAAS,gBAAgB,CAAC,OAAgB;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACzF,IAAI,MAAM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CAAC,CAAC,CAAC,EAAE,CAAC;YAC9F,GAAG,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,iDAAiD,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjJ,CAAC;IACJ,CAAC;CACF"}
|
package/dist/ai/router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type AiChatModelConfig, type AiIntegrationConfig, type AiPricingConfig, type AiReasoningParameter, type AiRouteTarget, type AiRuntimeConfig, type AiThinking } from "./config.js";
|
|
2
|
-
import type
|
|
1
|
+
import { type AiChatModelConfig, type AiNoThinkingWithTools, type AiIntegrationConfig, type AiPricingConfig, type AiReasoningParameter, type AiRouteTarget, type AiRuntimeConfig, type AiThinking } from "./config.js";
|
|
2
|
+
import { type AiUnusableWhy } from "./types.js";
|
|
3
3
|
export interface AiCandidate {
|
|
4
4
|
integration: AiIntegrationConfig;
|
|
5
5
|
model: string;
|
|
@@ -14,6 +14,14 @@ export interface AiCandidate {
|
|
|
14
14
|
supportsVision?: boolean;
|
|
15
15
|
/** How the model's thinking level is sent (see `AiChatModelConfig.reasoningParameter`); absent when the model does not say: `reasoning_effort`. */
|
|
16
16
|
reasoningParameter?: AiReasoningParameter;
|
|
17
|
+
/** The model refuses thinking when the request carries tools, and how it is asked then (see `AiChatModelConfig.noThinkingWithTools`): configured, or learned by a call of this host. */
|
|
18
|
+
noThinkingWithTools?: AiNoThinkingWithTools;
|
|
19
|
+
/** The model's own API version (see `AiChatModelConfig.apiVersion`); absent: its integration's. `effectiveApiVersion(candidate.integration, candidate)` says which is used. */
|
|
20
|
+
apiVersion?: string;
|
|
21
|
+
/** The model is asked through the Responses API (see `AiChatModelConfig.apiProtocol`); absent: Chat Completions. */
|
|
22
|
+
apiProtocol?: "responses";
|
|
23
|
+
/** The address the model's requests go to, as it was written (see `AiChatModelConfig.endpointUrl`); absent: the one the engine builds from the integration. */
|
|
24
|
+
endpointUrl?: string;
|
|
17
25
|
/**
|
|
18
26
|
* The thinking level for this candidate: its route target's, else its integration's (`automatic` is a choice that sends nothing). Absent when
|
|
19
27
|
* neither says: the request carries no level.
|
|
@@ -33,14 +41,16 @@ export interface AiRouteEntry {
|
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* The route of a task place by place, with the rules of the web app's router: an explicit route (primary + fallbacks) is used alone, and a target of it that cannot
|
|
36
|
-
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary;
|
|
37
|
-
*
|
|
44
|
+
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary; a task with no route of its own that
|
|
45
|
+
* follows another (`AI_CAPABILITY_FOLLOWS`: Brainstorming the Copilot) uses the route of that one; otherwise models tagged with the capability, then those tagged with
|
|
46
|
+
* the one it follows, then the default writing integration, then any `default` model. At most `maxCandidates` candidates (the same one twice counts once), and the entries
|
|
38
47
|
* that cannot be called do not count.
|
|
39
48
|
*/
|
|
40
49
|
export declare function describeAiRoute(config: AiRuntimeConfig, capability: string): AiRouteEntry[];
|
|
41
50
|
/**
|
|
42
|
-
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone
|
|
43
|
-
* otherwise models tagged with the capability
|
|
51
|
+
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone, the
|
|
52
|
+
* task's own or, while it has none, the one of the task it follows; otherwise models tagged with the capability (then with the one it follows), then the default writing
|
|
53
|
+
* integration, then any `default` model.
|
|
44
54
|
*/
|
|
45
55
|
export declare function resolveAiCandidates(config: AiRuntimeConfig, capability: string): AiCandidate[];
|
|
46
56
|
export declare function hasAiCandidates(config: AiRuntimeConfig, capability: string): boolean;
|
package/dist/ai/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/ai/router.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/ai/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8F,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAoB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACrU,OAAO,EAAyB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,mBAAmB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sGAAsG;IACtG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mJAAmJ;IACnJ,kBAAkB,CAAC,EAAE,oBAAoB,CAAC;IAC1C,wLAAwL;IACxL,mBAAmB,CAAC,EAAE,qBAAqB,CAAC;IAC5C,+KAA+K;IAC/K,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oHAAoH;IACpH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,+JAA+J;IAC/J,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;CACvB;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,CAM3F;AA0ED,oIAAoI;AACpI,MAAM,WAAW,YAAY;IAC3B,iKAAiK;IACjK,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,sEAAsE;IACtE,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,EAAE,CAgD3F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,EAAE,CAE9F;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAEpF"}
|
package/dist/ai/router.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { normalizeReasoningParameter, normalizeThinking } from "./config.js";
|
|
1
|
+
import { normalizeApiProtocol, normalizeEndpointUrl, normalizeReasoningParameter, normalizeThinking } from "./config.js";
|
|
2
|
+
import { AI_CAPABILITY_FOLLOWS } from "./types.js";
|
|
2
3
|
/** Chat models of an integration, tolerant of the legacy single-model fields. */
|
|
3
4
|
export function integrationChatModels(integration) {
|
|
4
5
|
if (integration.chatModels?.length)
|
|
@@ -10,12 +11,26 @@ export function integrationChatModels(integration) {
|
|
|
10
11
|
models.push({ id: "legacy-review", name: integration.modelReview, capabilities: ["review"] });
|
|
11
12
|
return models;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The task, then the task it follows (`AI_CAPABILITY_FOLLOWS`): the order in which a task takes a route and a tag. Brainstorming takes its own route, else the
|
|
16
|
+
* Copilot's; a model tagged for it, else one tagged for the Copilot.
|
|
17
|
+
*/
|
|
18
|
+
function followOrder(capability) {
|
|
19
|
+
const follows = Object.prototype.hasOwnProperty.call(AI_CAPABILITY_FOLLOWS, capability) ? AI_CAPABILITY_FOLLOWS[capability] : undefined;
|
|
20
|
+
return follows === undefined ? [capability] : [capability, follows];
|
|
21
|
+
}
|
|
13
22
|
function supports(model, capability) {
|
|
14
|
-
return
|
|
23
|
+
return [...followOrder(capability), "default"].some((tag) => model.capabilities.includes(tag));
|
|
24
|
+
}
|
|
25
|
+
/** The route a task has, or, while it has none, the route of the task it follows. */
|
|
26
|
+
function routeOf(config, capability) {
|
|
27
|
+
const written = (route) => Boolean(route && (route.primary || route.fallbacks?.length));
|
|
28
|
+
return followOrder(capability).map((task) => config.taskRouting?.[task]).find(written) ?? config.taskRouting?.[capability];
|
|
15
29
|
}
|
|
16
30
|
function candidate(integration, model, target) {
|
|
17
31
|
const thinking = normalizeThinking(target?.thinking) ?? normalizeThinking(integration.thinking);
|
|
18
32
|
const reasoningParameter = normalizeReasoningParameter(model.reasoningParameter);
|
|
33
|
+
const apiVersion = typeof model.apiVersion === "string" ? model.apiVersion.trim() : "";
|
|
19
34
|
return {
|
|
20
35
|
integration,
|
|
21
36
|
model: model.name,
|
|
@@ -28,6 +43,10 @@ function candidate(integration, model, target) {
|
|
|
28
43
|
...(typeof model.supportsReasoning === "boolean" ? { supportsReasoning: model.supportsReasoning } : {}),
|
|
29
44
|
...(typeof model.supportsVision === "boolean" ? { supportsVision: model.supportsVision } : {}),
|
|
30
45
|
...(reasoningParameter ? { reasoningParameter } : {}),
|
|
46
|
+
...(model.noThinkingWithTools === true || model.noThinkingWithTools === "none" ? { noThinkingWithTools: model.noThinkingWithTools } : {}),
|
|
47
|
+
...(apiVersion ? { apiVersion } : {}),
|
|
48
|
+
...(normalizeApiProtocol(model.apiProtocol) ? { apiProtocol: "responses" } : {}),
|
|
49
|
+
...(normalizeEndpointUrl(model.endpointUrl) ? { endpointUrl: normalizeEndpointUrl(model.endpointUrl) } : {}),
|
|
31
50
|
...(thinking ? { thinking } : {}),
|
|
32
51
|
};
|
|
33
52
|
}
|
|
@@ -52,19 +71,26 @@ function writingIntegration(config) {
|
|
|
52
71
|
?? integrations.find((entry) => entry.id === config.defaultWritingIntegrationId)
|
|
53
72
|
?? integrations[0];
|
|
54
73
|
}
|
|
74
|
+
/** The model of an integration for a task: the first tagged for it, else for the task it follows, else the first `default` one. */
|
|
55
75
|
function pick(integration, capability) {
|
|
56
76
|
const models = integrationChatModels(integration);
|
|
57
|
-
|
|
77
|
+
for (const tag of [...followOrder(capability), "default"]) {
|
|
78
|
+
const model = models.find((entry) => entry.capabilities.includes(tag));
|
|
79
|
+
if (model)
|
|
80
|
+
return model;
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
58
83
|
}
|
|
59
84
|
/**
|
|
60
85
|
* The route of a task place by place, with the rules of the web app's router: an explicit route (primary + fallbacks) is used alone, and a target of it that cannot
|
|
61
|
-
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary;
|
|
62
|
-
*
|
|
86
|
+
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary; a task with no route of its own that
|
|
87
|
+
* follows another (`AI_CAPABILITY_FOLLOWS`: Brainstorming the Copilot) uses the route of that one; otherwise models tagged with the capability, then those tagged with
|
|
88
|
+
* the one it follows, then the default writing integration, then any `default` model. At most `maxCandidates` candidates (the same one twice counts once), and the entries
|
|
63
89
|
* that cannot be called do not count.
|
|
64
90
|
*/
|
|
65
91
|
export function describeAiRoute(config, capability) {
|
|
66
92
|
const limit = Math.max(1, Math.min(8, config.routingExecution?.maxCandidates ?? config.maxCandidates ?? 4));
|
|
67
|
-
const route = config
|
|
93
|
+
const route = routeOf(config, capability);
|
|
68
94
|
const seen = new Set();
|
|
69
95
|
const entries = [];
|
|
70
96
|
let usable = 0;
|
|
@@ -102,10 +128,12 @@ export function describeAiRoute(config, capability) {
|
|
|
102
128
|
if (review && model)
|
|
103
129
|
add(candidate(review, model));
|
|
104
130
|
}
|
|
105
|
-
for (const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
131
|
+
for (const tag of followOrder(capability)) {
|
|
132
|
+
for (const integration of config.aiIntegrations) {
|
|
133
|
+
const exact = integrationChatModels(integration).find((model) => model.capabilities.includes(tag));
|
|
134
|
+
if (exact)
|
|
135
|
+
add(candidate(integration, exact));
|
|
136
|
+
}
|
|
109
137
|
}
|
|
110
138
|
const preferred = writingIntegration(config);
|
|
111
139
|
const preferredModel = preferred ? pick(preferred, capability) : undefined;
|
|
@@ -120,8 +148,9 @@ export function describeAiRoute(config, capability) {
|
|
|
120
148
|
return entries;
|
|
121
149
|
}
|
|
122
150
|
/**
|
|
123
|
-
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone
|
|
124
|
-
* otherwise models tagged with the capability
|
|
151
|
+
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone, the
|
|
152
|
+
* task's own or, while it has none, the one of the task it follows; otherwise models tagged with the capability (then with the one it follows), then the default writing
|
|
153
|
+
* integration, then any `default` model.
|
|
125
154
|
*/
|
|
126
155
|
export function resolveAiCandidates(config, capability) {
|
|
127
156
|
return describeAiRoute(config, capability).flatMap((entry) => (entry.candidate ? [entry.candidate] : []));
|
package/dist/ai/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/ai/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/ai/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,iBAAiB,EAA8M,MAAM,aAAa,CAAC;AACrU,OAAO,EAAE,qBAAqB,EAAsB,MAAM,YAAY,CAAC;AA+BvE,iFAAiF;AACjF,MAAM,UAAU,qBAAqB,CAAC,WAAgC;IACpE,IAAI,WAAW,CAAC,UAAU,EAAE,MAAM;QAAE,OAAO,WAAW,CAAC,UAAU,CAAC;IAClE,M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AAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAClG,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAuB,EAAE,UAAkB;IAC7E,OAAO,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5G,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAuB,EAAE,UAAkB;IACzE,OAAO,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/ai/routing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/ai/routing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/ai/routing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAA2E,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACzH,OAAO,EAAmB,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AACnF,OAAO,EAAyB,eAAe,EAAkE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5L,gIAAgI;AAChI,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC,WAA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4JAA4J;AAC5J,wBAAgB,WAAW,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAetM;AAED,gHAAgH;AAChH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,CAExE;AAOD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAGpE;AAwCD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,WAAW,CAgFnH"}
|
package/dist/ai/routing.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { likelyMessageTokens, likelyTextTokens, resolveModelTokenBudgets } from "./budget.js";
|
|
2
2
|
import { redactSecrets } from "./redact.js";
|
|
3
|
-
import { buildChatRequest, effectiveAiBase, endpointOrigin } from "./request.js";
|
|
3
|
+
import { buildChatRequest, candidateDestination, effectiveAiBase, endpointOrigin } from "./request.js";
|
|
4
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`. */
|
|
@@ -16,7 +16,7 @@ export function applySameBoundaryPolicy(config, candidates) {
|
|
|
16
16
|
}
|
|
17
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
18
|
export function leftOutStep(candidate, position, reason, secrets, githubModelsBaseUrl, extra = {}) {
|
|
19
|
-
const endpoint =
|
|
19
|
+
const { endpoint, path, protocol } = candidateDestination(candidate, githubModelsBaseUrl);
|
|
20
20
|
return {
|
|
21
21
|
position,
|
|
22
22
|
integrationId: redactSecrets(candidate.integration.id, secrets),
|
|
@@ -25,6 +25,8 @@ export function leftOutStep(candidate, position, reason, secrets, githubModelsBa
|
|
|
25
25
|
model: redactSecrets(candidate.model, secrets),
|
|
26
26
|
outcome: "left-out",
|
|
27
27
|
...(endpoint ? { endpoint } : {}),
|
|
28
|
+
...(path ? { path: redactSecrets(path, secrets) } : {}),
|
|
29
|
+
...(protocol ? { protocol } : {}),
|
|
28
30
|
leftOut: reason,
|
|
29
31
|
...extra,
|
|
30
32
|
};
|
|
@@ -114,12 +116,16 @@ export function planAttempts(config, request, githubModelsBaseUrl) {
|
|
|
114
116
|
if (!allowed.length) {
|
|
115
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);
|
|
116
118
|
}
|
|
117
|
-
const planned = allowed.map((
|
|
118
|
-
const index = place(
|
|
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;
|
|
119
125
|
try {
|
|
120
126
|
const built = buildChatRequest(candidate, request, { githubModelsBaseUrl });
|
|
121
127
|
const tools = built.useTools ? likelyTextTokens(JSON.stringify(built.body.tools)) + 8 : 0;
|
|
122
|
-
const inputTokens = likelyMessageTokens(built.
|
|
128
|
+
const inputTokens = likelyMessageTokens(built.messages) + tools;
|
|
123
129
|
return { candidate, index, built, inputTokens, estimate: estimateAttempt(candidate, inputTokens, built.outputLimit) };
|
|
124
130
|
}
|
|
125
131
|
catch (error) {
|