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
|
@@ -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,C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AAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,KAAK,CAAC;gBAAE,QAAQ,EAAE;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,SAAS,EAAE,MAAM,CAAA;iBAAE,CAAA;aAAE,CAAC,CAAA;SAAE,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/I,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAgB9D;AAED;;;;GAIG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,IAAI,CAAS;IACrB,8EAA8E;IAC9E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,mHAAmH;IACnH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IAEvB,mEAAmE;IACnE,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,+HAA+H;IAC/H,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,SAAK,GAAG,cAAc,GAAG,SAAS;IAiD3D,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,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,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AAC;CACF"}
|
package/dist/ai/router.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type AiChatModelConfig, type AiIntegrationConfig, type AiPricingConfig, type AiReasoningParameter, type AiRuntimeConfig, type AiThinking } from "./config.js";
|
|
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";
|
|
2
3
|
export interface AiCandidate {
|
|
3
4
|
integration: AiIntegrationConfig;
|
|
4
5
|
model: string;
|
|
@@ -13,6 +14,14 @@ export interface AiCandidate {
|
|
|
13
14
|
supportsVision?: boolean;
|
|
14
15
|
/** How the model's thinking level is sent (see `AiChatModelConfig.reasoningParameter`); absent when the model does not say: `reasoning_effort`. */
|
|
15
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;
|
|
16
25
|
/**
|
|
17
26
|
* The thinking level for this candidate: its route target's, else its integration's (`automatic` is a choice that sends nothing). Absent when
|
|
18
27
|
* neither says: the request carries no level.
|
|
@@ -21,10 +30,25 @@ export interface AiCandidate {
|
|
|
21
30
|
}
|
|
22
31
|
/** Chat models of an integration, tolerant of the legacy single-model fields. */
|
|
23
32
|
export declare function integrationChatModels(integration: AiIntegrationConfig): AiChatModelConfig[];
|
|
33
|
+
/** One place of the route of a task: the candidate that stands in it, or the target of the author that cannot be called and why. */
|
|
34
|
+
export interface AiRouteEntry {
|
|
35
|
+
/** The place in the route as the author wrote it: the primary is 0, then the fallbacks in order. A task with no route written has the order the router chose. */
|
|
36
|
+
position: number;
|
|
37
|
+
candidate?: AiCandidate;
|
|
38
|
+
/** The target as the author wrote it, for a route that is written. */
|
|
39
|
+
target?: AiRouteTarget;
|
|
40
|
+
unusable?: AiUnusableWhy;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
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
|
|
44
|
+
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary; otherwise models tagged with the
|
|
45
|
+
* capability, then the default writing integration, then any `default` model. At most `maxCandidates` candidates (the same one twice counts once), and the entries
|
|
46
|
+
* that cannot be called do not count.
|
|
47
|
+
*/
|
|
48
|
+
export declare function describeAiRoute(config: AiRuntimeConfig, capability: string): AiRouteEntry[];
|
|
24
49
|
/**
|
|
25
|
-
* Ordered models to try for a capability
|
|
26
|
-
*
|
|
27
|
-
* capability, then the default writing integration, then any `default` model.
|
|
50
|
+
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone;
|
|
51
|
+
* otherwise models tagged with the capability, then the default writing integration, then any `default` model.
|
|
28
52
|
*/
|
|
29
53
|
export declare function resolveAiCandidates(config: AiRuntimeConfig, capability: string): AiCandidate[];
|
|
30
54
|
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","source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xB,sEAAsE;IACtE,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,EAAE,CA8C3F;AAED;;;GAGG;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,4 @@
|
|
|
1
|
-
import { normalizeReasoningParameter, normalizeThinking } from "./config.js";
|
|
1
|
+
import { normalizeApiProtocol, normalizeEndpointUrl, normalizeReasoningParameter, normalizeThinking } from "./config.js";
|
|
2
2
|
/** Chat models of an integration, tolerant of the legacy single-model fields. */
|
|
3
3
|
export function integrationChatModels(integration) {
|
|
4
4
|
if (integration.chatModels?.length)
|
|
@@ -16,6 +16,7 @@ function supports(model, capability) {
|
|
|
16
16
|
function candidate(integration, model, target) {
|
|
17
17
|
const thinking = normalizeThinking(target?.thinking) ?? normalizeThinking(integration.thinking);
|
|
18
18
|
const reasoningParameter = normalizeReasoningParameter(model.reasoningParameter);
|
|
19
|
+
const apiVersion = typeof model.apiVersion === "string" ? model.apiVersion.trim() : "";
|
|
19
20
|
return {
|
|
20
21
|
integration,
|
|
21
22
|
model: model.name,
|
|
@@ -28,17 +29,26 @@ function candidate(integration, model, target) {
|
|
|
28
29
|
...(typeof model.supportsReasoning === "boolean" ? { supportsReasoning: model.supportsReasoning } : {}),
|
|
29
30
|
...(typeof model.supportsVision === "boolean" ? { supportsVision: model.supportsVision } : {}),
|
|
30
31
|
...(reasoningParameter ? { reasoningParameter } : {}),
|
|
32
|
+
...(model.noThinkingWithTools === true || model.noThinkingWithTools === "none" ? { noThinkingWithTools: model.noThinkingWithTools } : {}),
|
|
33
|
+
...(apiVersion ? { apiVersion } : {}),
|
|
34
|
+
...(normalizeApiProtocol(model.apiProtocol) ? { apiProtocol: "responses" } : {}),
|
|
35
|
+
...(normalizeEndpointUrl(model.endpointUrl) ? { endpointUrl: normalizeEndpointUrl(model.endpointUrl) } : {}),
|
|
31
36
|
...(thinking ? { thinking } : {}),
|
|
32
37
|
};
|
|
33
38
|
}
|
|
34
|
-
|
|
39
|
+
/** What a target the author wrote is: a candidate that can be called, or the reason why it cannot (its integration is gone, its provider cannot chat here, its model is not in the integration, the model is not allowed the task). */
|
|
40
|
+
function resolveTarget(config, target, capability) {
|
|
35
41
|
const integration = config.aiIntegrations.find((entry) => entry.id === target.integrationId);
|
|
36
|
-
if (!integration
|
|
37
|
-
return
|
|
42
|
+
if (!integration)
|
|
43
|
+
return { unusable: "integration-missing" };
|
|
44
|
+
if (integration.provider === "m365_copilot")
|
|
45
|
+
return { unusable: "provider-unsupported" };
|
|
38
46
|
const model = integrationChatModels(integration).find((entry) => entry.name === target.model.trim());
|
|
39
|
-
if (!model
|
|
40
|
-
return
|
|
41
|
-
|
|
47
|
+
if (!model)
|
|
48
|
+
return { unusable: "model-missing" };
|
|
49
|
+
if (!supports(model, capability))
|
|
50
|
+
return { unusable: "task-not-allowed" };
|
|
51
|
+
return { candidate: candidate(integration, model, target) };
|
|
42
52
|
}
|
|
43
53
|
function writingIntegration(config) {
|
|
44
54
|
const integrations = config.aiIntegrations;
|
|
@@ -52,50 +62,74 @@ function pick(integration, capability) {
|
|
|
52
62
|
return models.find((model) => model.capabilities.includes(capability)) ?? models.find((model) => model.capabilities.includes("default"));
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* capability, then the default writing integration, then any `default` model.
|
|
65
|
+
* 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
|
|
66
|
+
* be called keeps its place with the reason (`unusable`), so that the one that is called instead is never taken for the primary; otherwise models tagged with the
|
|
67
|
+
* capability, then the default writing integration, then any `default` model. At most `maxCandidates` candidates (the same one twice counts once), and the entries
|
|
68
|
+
* that cannot be called do not count.
|
|
58
69
|
*/
|
|
59
|
-
export function
|
|
70
|
+
export function describeAiRoute(config, capability) {
|
|
60
71
|
const limit = Math.max(1, Math.min(8, config.routingExecution?.maxCandidates ?? config.maxCandidates ?? 4));
|
|
61
72
|
const route = config.taskRouting?.[capability];
|
|
62
73
|
const seen = new Set();
|
|
63
|
-
const
|
|
64
|
-
|
|
74
|
+
const entries = [];
|
|
75
|
+
let usable = 0;
|
|
76
|
+
const push = (position, entry, target) => {
|
|
65
77
|
if (!entry || entry.integration.provider === "m365_copilot")
|
|
66
78
|
return;
|
|
67
79
|
const key = `${entry.integration.id}::${entry.model}`;
|
|
68
|
-
if (seen.has(key))
|
|
80
|
+
if (seen.has(key) || usable >= limit)
|
|
69
81
|
return;
|
|
70
82
|
seen.add(key);
|
|
71
|
-
|
|
83
|
+
usable += 1;
|
|
84
|
+
entries.push({ position, candidate: entry, ...(target ? { target } : {}) });
|
|
72
85
|
};
|
|
73
86
|
if (route && (route.primary || route.fallbacks?.length)) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
[...(route.primary ? [route.primary] : []), ...(route.fallbacks ?? [])].forEach((target, position) => {
|
|
88
|
+
const found = resolveTarget(config, target, capability);
|
|
89
|
+
if ("unusable" in found)
|
|
90
|
+
entries.push({ position, target, unusable: found.unusable });
|
|
91
|
+
else
|
|
92
|
+
push(position, found.candidate, target);
|
|
93
|
+
});
|
|
94
|
+
return entries;
|
|
77
95
|
}
|
|
96
|
+
const chosen = [];
|
|
97
|
+
const add = (entry) => {
|
|
98
|
+
if (!entry || entry.integration.provider === "m365_copilot")
|
|
99
|
+
return;
|
|
100
|
+
if (chosen.some((other) => other.integration.id === entry.integration.id && other.model === entry.model))
|
|
101
|
+
return;
|
|
102
|
+
chosen.push(entry);
|
|
103
|
+
};
|
|
78
104
|
if (capability === "review") {
|
|
79
105
|
const review = config.aiIntegrations.find((entry) => entry.id === config.defaultReviewIntegrationId);
|
|
80
106
|
const model = review ? pick(review, "review") : undefined;
|
|
81
107
|
if (review && model)
|
|
82
|
-
|
|
108
|
+
add(candidate(review, model));
|
|
83
109
|
}
|
|
84
110
|
for (const integration of config.aiIntegrations) {
|
|
85
111
|
const exact = integrationChatModels(integration).find((model) => model.capabilities.includes(capability));
|
|
86
112
|
if (exact)
|
|
87
|
-
|
|
113
|
+
add(candidate(integration, exact));
|
|
88
114
|
}
|
|
89
115
|
const preferred = writingIntegration(config);
|
|
90
116
|
const preferredModel = preferred ? pick(preferred, capability) : undefined;
|
|
91
117
|
if (preferred && preferredModel)
|
|
92
|
-
|
|
118
|
+
add(candidate(preferred, preferredModel));
|
|
93
119
|
for (const integration of config.aiIntegrations) {
|
|
94
120
|
const model = pick(integration, capability);
|
|
95
121
|
if (model)
|
|
96
|
-
|
|
122
|
+
add(candidate(integration, model));
|
|
97
123
|
}
|
|
98
|
-
|
|
124
|
+
chosen.slice(0, limit).forEach((entry, position) => entries.push({ position, candidate: entry }));
|
|
125
|
+
return entries;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Ordered models to try for a capability (`describeAiRoute` without the targets that cannot be called): an explicit route (primary + fallbacks) is used alone;
|
|
129
|
+
* otherwise models tagged with the capability, then the default writing integration, then any `default` model.
|
|
130
|
+
*/
|
|
131
|
+
export function resolveAiCandidates(config, capability) {
|
|
132
|
+
return describeAiRoute(config, capability).flatMap((entry) => (entry.candidate ? [entry.candidate] : []));
|
|
99
133
|
}
|
|
100
134
|
export function hasAiCandidates(config, capability) {
|
|
101
135
|
return resolveAiCandidates(config, capability).length > 0;
|
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,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ist/ai/routing.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AiRuntimeConfig } from "./config.js";
|
|
2
2
|
import { type ChatRequest } from "./request.js";
|
|
3
3
|
import { type AiCandidate } from "./router.js";
|
|
4
|
-
import { AiProviderError, type AiRequest } from "./types.js";
|
|
4
|
+
import { AiProviderError, type AiLeftOutReason, type AiRequest, type AiRouteStep } from "./types.js";
|
|
5
5
|
/** What a fallback's privacy boundary is: the integration (one provider account). Same as the web app's `candidateBoundary`. */
|
|
6
6
|
export declare function candidateBoundary(candidate: Pick<AiCandidate, "integration">): string;
|
|
7
7
|
/** With `sameBoundaryOnly`, only the candidates in the primary's boundary remain. */
|
|
@@ -19,7 +19,7 @@ export interface AttemptEstimate {
|
|
|
19
19
|
/** A candidate with the request it would be sent and what that attempt would use at most. */
|
|
20
20
|
export interface PlannedAttempt {
|
|
21
21
|
candidate: AiCandidate;
|
|
22
|
-
/** Position in the route
|
|
22
|
+
/** Position in the route as the author wrote it: 0 is the primary (a target that cannot be called keeps its place). */
|
|
23
23
|
index: number;
|
|
24
24
|
/** `null` when the integration cannot be called (the attempt fails with `buildError`). */
|
|
25
25
|
built: ChatRequest | null;
|
|
@@ -31,7 +31,7 @@ export interface PlannedAttempt {
|
|
|
31
31
|
/** A candidate that will not be asked, and why: with "Tools only" on, a structured request skips a model marked as without tool calls. */
|
|
32
32
|
export interface SkippedAttempt {
|
|
33
33
|
candidate: AiCandidate;
|
|
34
|
-
/** Position in the route
|
|
34
|
+
/** Position in the route as the author wrote it: 0 is the primary. */
|
|
35
35
|
index: number;
|
|
36
36
|
reason: "no-tool-calls";
|
|
37
37
|
}
|
|
@@ -44,15 +44,25 @@ export interface AttemptPlan {
|
|
|
44
44
|
excludedByBoundary: number;
|
|
45
45
|
/** Candidates left out because "Tools only" is on and they are marked as without tool calls; empty for a request without a function. */
|
|
46
46
|
skipped: SkippedAttempt[];
|
|
47
|
+
/**
|
|
48
|
+
* Everything of the route that the plan leaves out, each with its place in the route and why (see `AiRouteStep`): the targets that cannot be called, the fallbacks the privacy policy
|
|
49
|
+
* keeps back, the models "Tools only" skips, the ones whose context window cannot hold the prompt and the ones the routing limits cut. In the order of the route.
|
|
50
|
+
*/
|
|
51
|
+
leftOut: AiRouteStep[];
|
|
47
52
|
}
|
|
53
|
+
/** 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. */
|
|
54
|
+
export declare function leftOutStep(candidate: AiCandidate, position: number, reason: AiLeftOutReason, secrets: readonly string[], githubModelsBaseUrl?: string, extra?: Partial<AiRouteStep>): AiRouteStep;
|
|
55
|
+
/** The route of a failed plan, in the order the author wrote it: what a host puts on the error it ends with. */
|
|
56
|
+
export declare function sortedRoute(steps: readonly AiRouteStep[]): AiRouteStep[];
|
|
48
57
|
export declare function routingLimits(config: AiRuntimeConfig): RoutingLimits;
|
|
49
58
|
/**
|
|
50
|
-
* The candidates a call will try, in order, with the request each would get: the route's order, minus the fallbacks the
|
|
59
|
+
* 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
|
|
51
60
|
* privacy policy excludes, minus (for a structured request, with "Tools only" on, which is the default) the models marked as without
|
|
52
61
|
* tool calls, minus the candidates whose context window cannot hold the prompt (a prompt is never cut),
|
|
53
62
|
* kept while the estimated attempts stay within the token and cost limits. A prompt no window holds, a first attempt
|
|
54
63
|
* that alone exceeds the limits, or a route where no model can call a function, is refused before anything is sent.
|
|
55
64
|
* 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.
|
|
65
|
+
* 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.
|
|
56
66
|
*/
|
|
57
67
|
export declare function planAttempts(config: AiRuntimeConfig, request: AiRequest, githubModelsBaseUrl?: string): AttemptPlan;
|
|
58
68
|
//# sourceMappingURL=routing.d.ts.map
|
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,WAAW,EAAE,aAAa,CAAC,GAAG,MAAM,CAErF;AAED,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,oBAAoB,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAI7J;AAED,iFAAiF;AACjF,MAAM,WAAW,aAAa;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6FAA6F;AAC7F,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,WAAW,CAAC;IACvB,uHAAuH;IACvH,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,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