narrarium-engine 0.1.12 → 0.1.14
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 +69 -5
- package/dist/ai/deadlines.d.ts.map +1 -1
- package/dist/ai/deadlines.js +25 -8
- package/dist/ai/deadlines.js.map +1 -1
- package/dist/ai/fetch-client.d.ts +19 -1
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +289 -74
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/types.d.ts +71 -0
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +19 -0
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/calls/index.d.ts +8 -0
- package/dist/autopilot/calls/index.d.ts.map +1 -0
- package/dist/autopilot/calls/index.js +8 -0
- package/dist/autopilot/calls/index.js.map +1 -0
- package/dist/autopilot/calls/memory-store.d.ts +38 -0
- package/dist/autopilot/calls/memory-store.d.ts.map +1 -0
- package/dist/autopilot/calls/memory-store.js +279 -0
- package/dist/autopilot/calls/memory-store.js.map +1 -0
- package/dist/autopilot/calls/port.d.ts +76 -0
- package/dist/autopilot/calls/port.d.ts.map +1 -0
- package/dist/autopilot/calls/port.js +28 -0
- package/dist/autopilot/calls/port.js.map +1 -0
- package/dist/autopilot/calls/recorder.d.ts +120 -0
- package/dist/autopilot/calls/recorder.d.ts.map +1 -0
- package/dist/autopilot/calls/recorder.js +400 -0
- package/dist/autopilot/calls/recorder.js.map +1 -0
- package/dist/autopilot/calls/retention.d.ts +27 -0
- package/dist/autopilot/calls/retention.d.ts.map +1 -0
- package/dist/autopilot/calls/retention.js +33 -0
- package/dist/autopilot/calls/retention.js.map +1 -0
- package/dist/autopilot/calls/run-calls.d.ts +106 -0
- package/dist/autopilot/calls/run-calls.d.ts.map +1 -0
- package/dist/autopilot/calls/run-calls.js +251 -0
- package/dist/autopilot/calls/run-calls.js.map +1 -0
- package/dist/autopilot/calls/types.d.ts +232 -0
- package/dist/autopilot/calls/types.d.ts.map +1 -0
- package/dist/autopilot/calls/types.js +53 -0
- package/dist/autopilot/calls/types.js.map +1 -0
- package/dist/autopilot/calls/utf8.d.ts +19 -0
- package/dist/autopilot/calls/utf8.d.ts.map +1 -0
- package/dist/autopilot/calls/utf8.js +91 -0
- package/dist/autopilot/calls/utf8.js.map +1 -0
- package/dist/autopilot/errors.d.ts.map +1 -1
- package/dist/autopilot/errors.js +60 -1
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/runner.d.ts +10 -0
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +109 -7
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +12 -0
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +4 -0
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/types.d.ts +60 -3
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/client.d.ts +42 -1
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +69 -1
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +44 -0
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +19 -0
- package/dist/server/protocol.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,251 @@
|
|
|
1
|
+
import { AiProviderError, AiStreamInterruptedError } from "../../ai/types.js";
|
|
2
|
+
import { isAbortError } from "../../util/abort.js";
|
|
3
|
+
import { CallRecorder } from "./recorder.js";
|
|
4
|
+
import { AI_CALL_BUDGETS } from "./types.js";
|
|
5
|
+
import { utf8Length } from "./utf8.js";
|
|
6
|
+
/**
|
|
7
|
+
* The records of one autopilot run: one recorder per AI call, the task headers, and the budget. A store failure stops the records for the rest of the
|
|
8
|
+
* run (reported once through `onFailure`); it never fails a step, and nothing waits for the store.
|
|
9
|
+
*/
|
|
10
|
+
export class RunCalls {
|
|
11
|
+
options;
|
|
12
|
+
stopped = false;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
get active() {
|
|
17
|
+
return !this.stopped;
|
|
18
|
+
}
|
|
19
|
+
saveTask(draft) {
|
|
20
|
+
if (this.stopped)
|
|
21
|
+
return;
|
|
22
|
+
this.settle(this.options.store.saveTask(draft));
|
|
23
|
+
}
|
|
24
|
+
prune() {
|
|
25
|
+
if (this.stopped)
|
|
26
|
+
return;
|
|
27
|
+
this.settle(this.options.store.prune(this.options.bookId, this.options.budgetBytes ?? AI_CALL_BUDGETS.browserPerBookBytes));
|
|
28
|
+
}
|
|
29
|
+
start(input) {
|
|
30
|
+
if (this.stopped)
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const recorder = new CallRecorder({
|
|
34
|
+
store: this.options.store,
|
|
35
|
+
bookId: this.options.bookId,
|
|
36
|
+
accountScope: this.options.accountScope,
|
|
37
|
+
runId: input.runId,
|
|
38
|
+
activityId: input.activityId,
|
|
39
|
+
seq: input.seq,
|
|
40
|
+
stepAttempt: input.stepAttempt,
|
|
41
|
+
task: input.task,
|
|
42
|
+
chapter: input.chapter,
|
|
43
|
+
scene: input.scene,
|
|
44
|
+
label: input.label,
|
|
45
|
+
capability: input.capability,
|
|
46
|
+
host: this.options.host,
|
|
47
|
+
system: input.system,
|
|
48
|
+
user: input.user,
|
|
49
|
+
request: { images: 0, tool: input.tool, toolSchemaHash: input.toolSchemaHash, structured: input.structured, maxOutputTokens: input.maxOutputTokens, temperature: input.temperature },
|
|
50
|
+
secrets: this.options.secrets(),
|
|
51
|
+
clock: { now: () => this.options.now().getTime(), setTimer: (callback, ms) => globalThis.setTimeout(callback, ms), clearTimer: (handle) => globalThis.clearTimeout(handle) },
|
|
52
|
+
onError: (error) => this.fail(error),
|
|
53
|
+
});
|
|
54
|
+
return new CallRecording(recorder, input, utf8Length(input.system), utf8Length(input.user), this.options.now);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.fail(error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
fail(error) {
|
|
62
|
+
if (this.stopped)
|
|
63
|
+
return;
|
|
64
|
+
this.stopped = true;
|
|
65
|
+
try {
|
|
66
|
+
this.options.onFailure(error);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// A listener that throws is not the store's failure.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
settle(result) {
|
|
73
|
+
result.then(undefined, (error) => this.fail(error));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* One AI call of a step: the recorder, and the provider attempts of the call. Its `onAttempt` and `onAttemptEnd` are the client's per-request hooks.
|
|
78
|
+
*
|
|
79
|
+
* Attempts and texts: the recorder numbers the texts it receives (a text attempt starts at a text that is not longer than the one before it, and
|
|
80
|
+
* at the first text). A provider attempt has the text attempt of the text it started, when it produced one (`textAttempt`), and no text otherwise.
|
|
81
|
+
* An attempt that fails after the model answered keeps its text as the text attempt it started; the next attempt starts a new one, because the
|
|
82
|
+
* client resets the text when a candidate fails.
|
|
83
|
+
*/
|
|
84
|
+
export class CallRecording {
|
|
85
|
+
recorder;
|
|
86
|
+
input;
|
|
87
|
+
now;
|
|
88
|
+
callId;
|
|
89
|
+
seq;
|
|
90
|
+
systemBytes;
|
|
91
|
+
userBytes;
|
|
92
|
+
startedMs;
|
|
93
|
+
open = new Map();
|
|
94
|
+
reports = [];
|
|
95
|
+
hooked = false;
|
|
96
|
+
index = 0;
|
|
97
|
+
result = null;
|
|
98
|
+
constructor(recorder, input, systemBytes, userBytes, now) {
|
|
99
|
+
this.recorder = recorder;
|
|
100
|
+
this.input = input;
|
|
101
|
+
this.now = now;
|
|
102
|
+
this.callId = recorder.callId;
|
|
103
|
+
this.seq = input.seq;
|
|
104
|
+
this.systemBytes = systemBytes;
|
|
105
|
+
this.userBytes = userBytes;
|
|
106
|
+
this.startedMs = now().getTime();
|
|
107
|
+
}
|
|
108
|
+
/** The cumulative text of the reply (`onText`), or of the arguments of a structured reply (`onStructuredText`). */
|
|
109
|
+
onText(text) {
|
|
110
|
+
this.recorder.onText(text);
|
|
111
|
+
}
|
|
112
|
+
onAttempt = (attempt) => {
|
|
113
|
+
this.hooked = true;
|
|
114
|
+
this.index += 1;
|
|
115
|
+
this.open.set(attempt.attemptId, { index: this.index, start: attempt, texts: this.recorder.textAttempts });
|
|
116
|
+
};
|
|
117
|
+
onAttemptEnd = (end) => {
|
|
118
|
+
const started = this.open.get(end.attemptId);
|
|
119
|
+
if (!started)
|
|
120
|
+
return;
|
|
121
|
+
this.open.delete(end.attemptId);
|
|
122
|
+
const textAttempt = this.recorder.textAttempts > started.texts ? this.recorder.textAttempts : null;
|
|
123
|
+
this.reports.push(reportOf(started.index, started.start, end, textAttempt));
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Ends the call: `status` is what happened (`statusOf`), and `response` or `error` is what the call gave. Idempotent. Returns what the call kept.
|
|
127
|
+
* Without the client's attempt hooks (a host that does not forward them) the attempt is taken from the response or the error.
|
|
128
|
+
*/
|
|
129
|
+
end(status, outcome = {}) {
|
|
130
|
+
if (this.result)
|
|
131
|
+
return this.result;
|
|
132
|
+
const attempts = this.hooked ? this.reports : this.synthesize(outcome.response, outcome.error);
|
|
133
|
+
const durationMs = this.now().getTime() - this.startedMs;
|
|
134
|
+
this.recorder.finish(status, attempts).catch(() => undefined);
|
|
135
|
+
const characters = this.recorder.responseCharacters;
|
|
136
|
+
this.result = { callId: this.callId, status, attempts: attempts.length, characters, storedBytes: this.recorder.storedBytes, partial: status !== "ok" && characters > 0, dropped: this.recorder.dropped, durationMs };
|
|
137
|
+
return this.result;
|
|
138
|
+
}
|
|
139
|
+
synthesize(response, error) {
|
|
140
|
+
const failure = error instanceof AiProviderError ? error : undefined;
|
|
141
|
+
const provider = failure?.provider ?? response?.provider ?? null;
|
|
142
|
+
const model = failure?.model ?? response?.model ?? null;
|
|
143
|
+
if (!provider && !model && !failure?.usage && !response)
|
|
144
|
+
return [];
|
|
145
|
+
return [{
|
|
146
|
+
index: 1,
|
|
147
|
+
textAttempt: this.recorder.textAttempts > 0 ? this.recorder.textAttempts : null,
|
|
148
|
+
provider,
|
|
149
|
+
model,
|
|
150
|
+
integrationId: failure?.integrationId ?? response?.integrationId ?? null,
|
|
151
|
+
endpoint: failure?.target?.endpoint ?? null,
|
|
152
|
+
stream: false,
|
|
153
|
+
tools: this.input.structured,
|
|
154
|
+
firstByteMs: null,
|
|
155
|
+
durationMs: this.now().getTime() - this.startedMs,
|
|
156
|
+
outcome: failure ? outcomeOfError(failure) : "ok",
|
|
157
|
+
finishReason: failure?.transport?.finishReason ?? null,
|
|
158
|
+
reasoningCharacters: null,
|
|
159
|
+
usage: failure?.usage ?? response?.usage ?? null,
|
|
160
|
+
usageKnown: failure?.usageKnown ?? response?.usageKnown ?? null,
|
|
161
|
+
cost: failure?.cost ?? response?.cost ?? null,
|
|
162
|
+
costKnown: failure?.costKnown ?? response?.costKnown ?? null,
|
|
163
|
+
currency: failure?.currency ?? response?.currency ?? null,
|
|
164
|
+
transport: failure?.transport ?? null,
|
|
165
|
+
error: failure ? errorOf(failure) : null,
|
|
166
|
+
partialCharacters: failure?.partialText ? failure.partialText.length : null,
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** The status of a call that ended with `error` (or none). An abort is `aborted`: the run stopped while the call was running. */
|
|
171
|
+
export function statusOf(error, aborted = false) {
|
|
172
|
+
if (!error)
|
|
173
|
+
return "ok";
|
|
174
|
+
if (aborted || isAbortError(error))
|
|
175
|
+
return "aborted";
|
|
176
|
+
if (error instanceof AiStreamInterruptedError)
|
|
177
|
+
return "interrupted";
|
|
178
|
+
return "failed";
|
|
179
|
+
}
|
|
180
|
+
/** A stable hash of a schema (FNV-1a, 8 hex digits): what a record keeps of a structured reply's schema, never the schema itself. */
|
|
181
|
+
export function schemaHashOf(value) {
|
|
182
|
+
const text = JSON.stringify(value) ?? "";
|
|
183
|
+
let hash = 0x811c9dc5;
|
|
184
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
185
|
+
hash ^= text.charCodeAt(index);
|
|
186
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
187
|
+
}
|
|
188
|
+
return hash.toString(16).padStart(8, "0");
|
|
189
|
+
}
|
|
190
|
+
function outcomeOfError(error) {
|
|
191
|
+
if (isAbortError(error))
|
|
192
|
+
return "aborted";
|
|
193
|
+
if (error instanceof AiStreamInterruptedError)
|
|
194
|
+
return "interrupted";
|
|
195
|
+
if (error instanceof AiProviderError && error.timedOut)
|
|
196
|
+
return "timeout";
|
|
197
|
+
return "failed";
|
|
198
|
+
}
|
|
199
|
+
function outcomeOfEnd(end) {
|
|
200
|
+
if (end.outcome === "ok")
|
|
201
|
+
return "ok";
|
|
202
|
+
if (end.outcome === "cancelled")
|
|
203
|
+
return "aborted";
|
|
204
|
+
if (end.failureKind === "timeout" || end.transport?.end === "timeout")
|
|
205
|
+
return "timeout";
|
|
206
|
+
if (end.transport?.end && end.transport.end !== "done")
|
|
207
|
+
return "interrupted";
|
|
208
|
+
return "failed";
|
|
209
|
+
}
|
|
210
|
+
function errorOf(error) {
|
|
211
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
212
|
+
const provider = error instanceof AiProviderError ? error : undefined;
|
|
213
|
+
return { name: failure.name, message: failure.message, status: provider?.status ?? null, transient: provider?.transient === true, timedOut: provider?.timedOut === true };
|
|
214
|
+
}
|
|
215
|
+
function reportOf(index, start, end, textAttempt) {
|
|
216
|
+
const outcome = outcomeOfEnd(end);
|
|
217
|
+
const failed = end.outcome !== "ok";
|
|
218
|
+
const transport = end.transport;
|
|
219
|
+
return {
|
|
220
|
+
index,
|
|
221
|
+
textAttempt,
|
|
222
|
+
provider: end.provider,
|
|
223
|
+
model: end.model,
|
|
224
|
+
integrationId: end.integrationId,
|
|
225
|
+
endpoint: start.endpoint,
|
|
226
|
+
stream: start.stream,
|
|
227
|
+
tools: start.tools,
|
|
228
|
+
firstByteMs: end.firstByteMs ?? null,
|
|
229
|
+
durationMs: end.durationMs,
|
|
230
|
+
outcome,
|
|
231
|
+
finishReason: end.finishReason ?? null,
|
|
232
|
+
reasoningCharacters: end.reasoningCharacters ?? null,
|
|
233
|
+
usage: end.usage ?? null,
|
|
234
|
+
usageKnown: end.usageKnown,
|
|
235
|
+
cost: end.cost ?? null,
|
|
236
|
+
costKnown: end.costKnown,
|
|
237
|
+
currency: end.currency ?? null,
|
|
238
|
+
transport: transport ?? null,
|
|
239
|
+
error: failed
|
|
240
|
+
? {
|
|
241
|
+
name: outcome === "interrupted" ? "AiStreamInterruptedError" : outcome === "timeout" ? "AiTimeoutError" : outcome === "aborted" ? "AbortError" : "AiProviderError",
|
|
242
|
+
message: end.error ?? "",
|
|
243
|
+
status: end.status ?? null,
|
|
244
|
+
transient: end.failureKind === "timeout" || end.status === 429 || (end.status ?? 0) >= 500,
|
|
245
|
+
timedOut: end.failureKind === "timeout",
|
|
246
|
+
}
|
|
247
|
+
: null,
|
|
248
|
+
partialCharacters: failed ? end.replyCharacters ?? end.partialText?.length ?? null : null,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=run-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-calls.js","sourceRoot":"","sources":["../../../src/autopilot/calls/run-calls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAgD,MAAM,mBAAmB,CAAC;AAE5H,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO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CAAC,WAAW,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI;KAC1F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { AutopilotTaskKind, AutopilotTransportDetail } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The record of every AI call of an autopilot task: what was sent (system and user, as sent, images as a placeholder), what came back while it
|
|
4
|
+
* streamed, and what each provider attempt did. The engine defines the shapes and the limits; hosts keep them (see `AiCallStore`, the port).
|
|
5
|
+
* Sizes are in bytes of UTF-8 unless a name says characters. Times are ISO 8601 strings in UTC.
|
|
6
|
+
*/
|
|
7
|
+
/** The version of the format of a record. A host that reads a record of another version keeps it as it is and says so. */
|
|
8
|
+
export declare const AI_CALLS_FORMAT_VERSION = 1;
|
|
9
|
+
/** The size limits of one call. The recorder enforces them; a host may store less but never more. */
|
|
10
|
+
export declare const AI_CALL_LIMITS: {
|
|
11
|
+
/** The system message: the first bytes of it are kept, the rest is dropped (`truncated`). */
|
|
12
|
+
readonly maxSystemBytes: number;
|
|
13
|
+
/** The user message: the first bytes of it are kept, the rest is dropped (`truncated`). */
|
|
14
|
+
readonly maxUserBytes: number;
|
|
15
|
+
/** The response of one provider attempt: its head, and its last `responseTailBytes`, when it is longer. */
|
|
16
|
+
readonly maxResponseBytes: number;
|
|
17
|
+
/** The end of a response longer than `maxResponseBytes` that is kept (at most an eighth of the limit). */
|
|
18
|
+
readonly responseTailBytes: number;
|
|
19
|
+
/** Everything of one call (system, user and every attempt's response). */
|
|
20
|
+
readonly maxCallBytes: number;
|
|
21
|
+
/** Calls kept for one task; a task that makes more keeps the first ones and says so in its header. */
|
|
22
|
+
readonly maxCallsPerTask: 64;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The budgets of the records, as data the hosts read. Budgets are per book unless a name says device. `minFreeDiskBytes` is the free disk a
|
|
26
|
+
* personal server keeps before it writes a record: under it, a call is recorded without its texts and the server says so once.
|
|
27
|
+
*/
|
|
28
|
+
export declare const AI_CALL_BUDGETS: {
|
|
29
|
+
readonly browserPerBookBytes: number;
|
|
30
|
+
readonly browserPerDeviceBytes: number;
|
|
31
|
+
readonly serverPerBookBytes: number;
|
|
32
|
+
readonly minFreeDiskBytes: number;
|
|
33
|
+
};
|
|
34
|
+
/** When the recorder sends the text it has received while the answer streams: every 2 seconds or every 16 KiB, whichever comes first, and always at the end. */
|
|
35
|
+
export declare const AI_CALL_CHECKPOINT: {
|
|
36
|
+
readonly intervalMs: 2000;
|
|
37
|
+
readonly bytes: number;
|
|
38
|
+
};
|
|
39
|
+
/** Where a call ran: in the browser (its IndexedDB) or on a personal server (its `books/<id>/ai-calls/`). */
|
|
40
|
+
export type AiCallHost = "browser" | "server";
|
|
41
|
+
/** The state of a call. `running` until it ends; the others are final. `partial` on the record says that its text stopped halfway. */
|
|
42
|
+
export type AiCallStatus = "running" | "ok" | "failed" | "interrupted" | "aborted";
|
|
43
|
+
/** How one provider attempt ended. `timeout` is a deadline that ran out (`start`, `idle` or `total`). */
|
|
44
|
+
export type AiCallAttemptOutcome = "ok" | "failed" | "interrupted" | "aborted" | "timeout";
|
|
45
|
+
/** The state of the task that holds calls. `stopped` is a task the author or the autopilot stopped. */
|
|
46
|
+
export type AiCallTaskStatus = "running" | "done" | "failed" | "stopped";
|
|
47
|
+
/** The field of a call whose text is kept: the system message, the user message, or the response of one provider attempt. */
|
|
48
|
+
export type AiCallField = "system" | "user" | "response";
|
|
49
|
+
/** Size and shape of one text, as it was given and as it is kept. `bytes` is the length of the original, `storedBytes` the length kept. */
|
|
50
|
+
export interface AiCallTextInfo {
|
|
51
|
+
characters: number;
|
|
52
|
+
bytes: number;
|
|
53
|
+
storedBytes: number;
|
|
54
|
+
truncated: boolean;
|
|
55
|
+
}
|
|
56
|
+
/** The request of a call, as sent. The texts themselves are kept by the store (`readText`), never in the record. */
|
|
57
|
+
export interface AiCallRequestInfo {
|
|
58
|
+
system: AiCallTextInfo;
|
|
59
|
+
user: AiCallTextInfo;
|
|
60
|
+
/** The images sent with the user message (each one is a placeholder in `user`). */
|
|
61
|
+
images: number;
|
|
62
|
+
/** The name of the function that carried a structured reply, and a hash of its schema. */
|
|
63
|
+
tool: string | null;
|
|
64
|
+
toolSchemaHash: string | null;
|
|
65
|
+
structured: boolean;
|
|
66
|
+
/** The output limit asked for, and the temperature, when the call set them. */
|
|
67
|
+
maxOutputTokens: number | null;
|
|
68
|
+
temperature: number | null;
|
|
69
|
+
}
|
|
70
|
+
/** The response of a call: the text of its last provider attempt that had text, and whether it stopped halfway. */
|
|
71
|
+
export interface AiCallResponseInfo {
|
|
72
|
+
text: AiCallTextInfo | null;
|
|
73
|
+
partial: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Tokens of one provider attempt (the engine's usage, `usageKnown` says whether the provider reported them). */
|
|
76
|
+
export interface AiCallUsage {
|
|
77
|
+
inputTokens: number;
|
|
78
|
+
outputTokens: number;
|
|
79
|
+
cachedInputTokens: number;
|
|
80
|
+
}
|
|
81
|
+
/** A cleaned error of one provider attempt: its words are redacted and short, and it never carries a key or a URL. */
|
|
82
|
+
export interface AiCallError {
|
|
83
|
+
name: string;
|
|
84
|
+
/** At most `AI_CALL_ERROR_CHARACTERS` characters, redacted. */
|
|
85
|
+
message: string;
|
|
86
|
+
status: number | null;
|
|
87
|
+
transient: boolean;
|
|
88
|
+
timedOut: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** The most characters of an error message that a record keeps. */
|
|
91
|
+
export declare const AI_CALL_ERROR_CHARACTERS = 500;
|
|
92
|
+
/**
|
|
93
|
+
* One provider attempt of a call. The index is the attempt in order, from 1. `textAttempt` says which response of the call holds its text (the
|
|
94
|
+
* recorder numbers the responses it saw, from 1; an attempt with no text has none), and `text` is that response's size, filled by the recorder.
|
|
95
|
+
* `endpoint` is the origin of the provider's address (`https://api.openai.com`), never a path, a query or a key. `reasoningCharacters` is the
|
|
96
|
+
* count of the reasoning, never its words.
|
|
97
|
+
*/
|
|
98
|
+
export interface AiCallAttempt {
|
|
99
|
+
index: number;
|
|
100
|
+
textAttempt: number | null;
|
|
101
|
+
text: AiCallTextInfo | null;
|
|
102
|
+
provider: string | null;
|
|
103
|
+
model: string | null;
|
|
104
|
+
integrationId: string | null;
|
|
105
|
+
endpoint: string | null;
|
|
106
|
+
stream: boolean;
|
|
107
|
+
tools: boolean;
|
|
108
|
+
firstByteMs: number | null;
|
|
109
|
+
durationMs: number | null;
|
|
110
|
+
outcome: AiCallAttemptOutcome;
|
|
111
|
+
finishReason: string | null;
|
|
112
|
+
reasoningCharacters: number | null;
|
|
113
|
+
usage: AiCallUsage | null;
|
|
114
|
+
usageKnown: boolean | null;
|
|
115
|
+
cost: number | null;
|
|
116
|
+
costKnown: boolean | null;
|
|
117
|
+
currency: string | null;
|
|
118
|
+
/** What the engine's client saw of the transport (its `transport` facts; the tail is cleaned of credentials). */
|
|
119
|
+
transport: AutopilotTransportDetail | null;
|
|
120
|
+
error: AiCallError | null;
|
|
121
|
+
partialCharacters: number | null;
|
|
122
|
+
}
|
|
123
|
+
/** The times of a call. `firstTextAt` is null when no text arrived. */
|
|
124
|
+
export interface AiCallTiming {
|
|
125
|
+
startedAt: string;
|
|
126
|
+
firstTextAt: string | null;
|
|
127
|
+
endedAt: string | null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* One AI call of one task. Its identity is `callId`, unique on the device or the server: `aiCallIdOf(activityId, seq)`. `seq` counts the calls of the
|
|
131
|
+
* task from 1, and `stepAttempt` counts the attempts of the step that made the call, from 1 (a retry of the step is a new activity, so it is 1 there).
|
|
132
|
+
* `accountScope` is the account the book belongs to in the browser (the store fences its writes by it) and null on a server.
|
|
133
|
+
* `storedBytes` is the size kept by the call: its system and user, and the responses of all its attempts.
|
|
134
|
+
*/
|
|
135
|
+
export interface AiCallRecord {
|
|
136
|
+
formatVersion: number;
|
|
137
|
+
callId: string;
|
|
138
|
+
bookId: string;
|
|
139
|
+
accountScope: string | null;
|
|
140
|
+
runId: string;
|
|
141
|
+
activityId: string;
|
|
142
|
+
seq: number;
|
|
143
|
+
stepAttempt: number;
|
|
144
|
+
task: AutopilotTaskKind;
|
|
145
|
+
chapter: number | null;
|
|
146
|
+
scene: number | null;
|
|
147
|
+
/** What the call is, in words (the label of the request). */
|
|
148
|
+
label: string;
|
|
149
|
+
/** The router capability of the call (`autopilot`, `review`...). */
|
|
150
|
+
capability: string;
|
|
151
|
+
host: AiCallHost;
|
|
152
|
+
request: AiCallRequestInfo;
|
|
153
|
+
status: AiCallStatus;
|
|
154
|
+
response: AiCallResponseInfo;
|
|
155
|
+
attempts: AiCallAttempt[];
|
|
156
|
+
timing: AiCallTiming;
|
|
157
|
+
storedBytes: number;
|
|
158
|
+
/** Set when the call kept less than it was given: `limit` (a text was longer than its limit, so its head and end were kept) or `disk` (a host was short of disk). */
|
|
159
|
+
dropped: AiCallDropReason | null;
|
|
160
|
+
}
|
|
161
|
+
/** Why a call kept less than it was given. */
|
|
162
|
+
export type AiCallDropReason = "limit" | "disk";
|
|
163
|
+
/**
|
|
164
|
+
* The task that holds calls. It outlives the 200 activities of `autopilot/activity.json`: the hosts keep it with its calls. `calls` and `bytes`
|
|
165
|
+
* are what the store holds for it (the store answers them; a writer does not set them). `pinned` is set by `keep`.
|
|
166
|
+
*/
|
|
167
|
+
export interface AiCallTaskHeader {
|
|
168
|
+
bookId: string;
|
|
169
|
+
activityId: string;
|
|
170
|
+
title: string;
|
|
171
|
+
kind: AutopilotTaskKind;
|
|
172
|
+
chapter: number | null;
|
|
173
|
+
scene: number | null;
|
|
174
|
+
status: AiCallTaskStatus;
|
|
175
|
+
startedAt: string;
|
|
176
|
+
endedAt: string | null;
|
|
177
|
+
calls: number;
|
|
178
|
+
bytes: number;
|
|
179
|
+
pinned: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** What a writer gives for a task header: the header without the numbers the store keeps and the pin that `keep` sets. */
|
|
182
|
+
export type AiCallTaskDraft = Omit<AiCallTaskHeader, "calls" | "bytes" | "pinned">;
|
|
183
|
+
/** A call as the port receives it when it begins: its record, and the system and user texts as they are kept (already limited and redacted). */
|
|
184
|
+
export interface AiCallBegin {
|
|
185
|
+
record: AiCallRecord;
|
|
186
|
+
system: string;
|
|
187
|
+
user: string;
|
|
188
|
+
}
|
|
189
|
+
/** What a call carries when it ends: its final status, times, attempts and sizes. Its texts were appended before. */
|
|
190
|
+
export type AiCallEnd = Pick<AiCallRecord, "status" | "response" | "attempts" | "timing" | "storedBytes" | "dropped">;
|
|
191
|
+
/** A task with its calls, in the order of `seq`. */
|
|
192
|
+
export interface AiCallTask {
|
|
193
|
+
header: AiCallTaskHeader;
|
|
194
|
+
calls: AiCallRecord[];
|
|
195
|
+
}
|
|
196
|
+
/** One page of task headers, newest first. `next` is the cursor of the next page, or null on the last one. */
|
|
197
|
+
export interface AiCallTaskPage {
|
|
198
|
+
tasks: AiCallTaskHeader[];
|
|
199
|
+
next: string | null;
|
|
200
|
+
}
|
|
201
|
+
/** A piece of kept text: from byte `from` to the end of what is kept (`size`), decoded. `complete` is true once the call has ended. */
|
|
202
|
+
export interface AiCallTextChunk {
|
|
203
|
+
text: string;
|
|
204
|
+
from: number;
|
|
205
|
+
next: number;
|
|
206
|
+
size: number;
|
|
207
|
+
complete: boolean;
|
|
208
|
+
}
|
|
209
|
+
/** The totals of a book: what its calls keep, and what the pinned tasks keep. */
|
|
210
|
+
export interface AiCallTotals {
|
|
211
|
+
bytes: number;
|
|
212
|
+
tasks: number;
|
|
213
|
+
calls: number;
|
|
214
|
+
pinnedTasks: number;
|
|
215
|
+
pinnedBytes: number;
|
|
216
|
+
}
|
|
217
|
+
/** What `prune` did: the tasks it dropped (oldest first) and what is kept now. `overBudget` is true when the pinned tasks alone exceed the budget. */
|
|
218
|
+
export interface AiCallPruneResult {
|
|
219
|
+
dropped: string[];
|
|
220
|
+
bytes: number;
|
|
221
|
+
pinnedTasks: number;
|
|
222
|
+
pinnedBytes: number;
|
|
223
|
+
overBudget: boolean;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The id of a call: its task's activity id and its number in the task, `activity_<uuid>-0003`. Only letters, digits, `_` and `-`, so a host can
|
|
227
|
+
* use it in a file name.
|
|
228
|
+
*/
|
|
229
|
+
export declare function aiCallIdOf(activityId: string, seq: number): string;
|
|
230
|
+
/** Whether an id is safe to use as a file name and in a URL: 1 to 160 letters, digits, `_` or `-`. */
|
|
231
|
+
export declare function isSafeAiCallId(id: string): boolean;
|
|
232
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/autopilot/calls/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE/E;;;;GAIG;AAEH,0HAA0H;AAC1H,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAKzC,qGAAqG;AACrG,eAAO,MAAM,cAAc;IACzB,6FAA6F;;IAE7F,2FAA2F;;IAE3F,2GAA2G;;IAE3G,0GAA0G;;IAE1G,0EAA0E;;IAE1E,sGAAsG;;CAE9F,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC;AAEX,gKAAgK;AAChK,eAAO,MAAM,kBAAkB;;;CAGrB,CAAC;AAEX,6GAA6G;AAC7G,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9C,sIAAsI;AACtI,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,CAAC;AAEnF,yGAAyG;AACzG,MAAM,MAAM,oBAAoB,GAAG,IAAI,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,CAAC;AAE3F,uGAAuG;AACvG,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC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sGAAsG;AACtG,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAElD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The record of every AI call of an autopilot task: what was sent (system and user, as sent, images as a placeholder), what came back while it
|
|
3
|
+
* streamed, and what each provider attempt did. The engine defines the shapes and the limits; hosts keep them (see `AiCallStore`, the port).
|
|
4
|
+
* Sizes are in bytes of UTF-8 unless a name says characters. Times are ISO 8601 strings in UTC.
|
|
5
|
+
*/
|
|
6
|
+
/** The version of the format of a record. A host that reads a record of another version keeps it as it is and says so. */
|
|
7
|
+
export const AI_CALLS_FORMAT_VERSION = 1;
|
|
8
|
+
const KIB = 1024;
|
|
9
|
+
const MIB = 1024 * KIB;
|
|
10
|
+
/** The size limits of one call. The recorder enforces them; a host may store less but never more. */
|
|
11
|
+
export const AI_CALL_LIMITS = {
|
|
12
|
+
/** The system message: the first bytes of it are kept, the rest is dropped (`truncated`). */
|
|
13
|
+
maxSystemBytes: 1 * MIB,
|
|
14
|
+
/** The user message: the first bytes of it are kept, the rest is dropped (`truncated`). */
|
|
15
|
+
maxUserBytes: 1 * MIB,
|
|
16
|
+
/** The response of one provider attempt: its head, and its last `responseTailBytes`, when it is longer. */
|
|
17
|
+
maxResponseBytes: 2 * MIB,
|
|
18
|
+
/** The end of a response longer than `maxResponseBytes` that is kept (at most an eighth of the limit). */
|
|
19
|
+
responseTailBytes: 256 * KIB,
|
|
20
|
+
/** Everything of one call (system, user and every attempt's response). */
|
|
21
|
+
maxCallBytes: 4 * MIB,
|
|
22
|
+
/** Calls kept for one task; a task that makes more keeps the first ones and says so in its header. */
|
|
23
|
+
maxCallsPerTask: 64,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The budgets of the records, as data the hosts read. Budgets are per book unless a name says device. `minFreeDiskBytes` is the free disk a
|
|
27
|
+
* personal server keeps before it writes a record: under it, a call is recorded without its texts and the server says so once.
|
|
28
|
+
*/
|
|
29
|
+
export const AI_CALL_BUDGETS = {
|
|
30
|
+
browserPerBookBytes: 256 * MIB,
|
|
31
|
+
browserPerDeviceBytes: 1024 * MIB,
|
|
32
|
+
serverPerBookBytes: 2048 * MIB,
|
|
33
|
+
minFreeDiskBytes: 1024 * MIB,
|
|
34
|
+
};
|
|
35
|
+
/** When the recorder sends the text it has received while the answer streams: every 2 seconds or every 16 KiB, whichever comes first, and always at the end. */
|
|
36
|
+
export const AI_CALL_CHECKPOINT = {
|
|
37
|
+
intervalMs: 2000,
|
|
38
|
+
bytes: 16 * KIB,
|
|
39
|
+
};
|
|
40
|
+
/** The most characters of an error message that a record keeps. */
|
|
41
|
+
export const AI_CALL_ERROR_CHARACTERS = 500;
|
|
42
|
+
/**
|
|
43
|
+
* The id of a call: its task's activity id and its number in the task, `activity_<uuid>-0003`. Only letters, digits, `_` and `-`, so a host can
|
|
44
|
+
* use it in a file name.
|
|
45
|
+
*/
|
|
46
|
+
export function aiCallIdOf(activityId, seq) {
|
|
47
|
+
return `${activityId}-${String(seq).padStart(4, "0")}`;
|
|
48
|
+
}
|
|
49
|
+
/** Whether an id is safe to use as a file name and in a URL: 1 to 160 letters, digits, `_` or `-`. */
|
|
50
|
+
export function isSafeAiCallId(id) {
|
|
51
|
+
return /^[A-Za-z0-9_-]{1,160}$/.test(id);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/autopilot/calls/types.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,0HAA0H;AAC1H,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;AAEvB,qGAAqG;AACrG,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,6FAA6F;IAC7F,cAAc,EAAE,CAAC,GAAG,GAAG;IACvB,2FAA2F;IAC3F,YAAY,EAAE,CAAC,GAAG,GAAG;IACrB,2GAA2G;IAC3G,gBAAgB,EAAE,CAAC,GAAG,GAAG;IACzB,0GAA0G;IAC1G,iBAAiB,EAAE,GAAG,GAAG,GAAG;IAC5B,0EAA0E;IAC1E,YAAY,EAAE,CAAC,GAAG,GAAG;IACrB,sGAAsG;IACtG,eAAe,EAAE,EAAE;CACX,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,mBAAmB,EAAE,GAAG,GAAG,GAAG;IAC9B,qBAAqB,EAAE,IAAI,GAAG,GAAG;IACjC,kBAAkB,EAAE,IAAI,GAAG,GAAG;IAC9B,gBAAgB,EAAE,IAAI,GAAG,GAAG;CACpB,CAAC;AAEX,gKAAgK;AAChK,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,EAAE,GAAG,GAAG;CACP,CAAC;AA+DX,mEAAmE;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAoJ5C;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,UAAkB,EAAE,GAAW;IACxD,OAAO,GAAG,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AACzD,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,OAAO,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTF-8 sizes and cuts of a JavaScript string, without encoding it: the recorder counts and cuts the text it receives in place. A lone surrogate
|
|
3
|
+
* counts as the replacement character (three bytes), as `TextEncoder` writes it; a pair counts as four. Cuts never split a pair.
|
|
4
|
+
*/
|
|
5
|
+
/** The UTF-8 bytes of `text` from index `from` to `to` (default: the end). */
|
|
6
|
+
export declare function utf8Length(text: string, from?: number, to?: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* The index where the longest run of whole characters from `from` that fits in `maxBytes` ends. It never splits a pair, so the text before
|
|
9
|
+
* it is valid UTF-8 and exactly `utf8Length(text, from, index)` bytes long (at most `maxBytes`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function cutHead(text: string, from: number, maxBytes: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* The index where the longest run of whole characters at the end of `text` that fits in `maxBytes` starts: `text.slice(index)` is valid UTF-8
|
|
14
|
+
* and at most `maxBytes` bytes long.
|
|
15
|
+
*/
|
|
16
|
+
export declare function suffixStart(text: string, maxBytes: number): number;
|
|
17
|
+
/** Whether the text ends with a high surrogate that a low one may still complete: the text is not cut there. */
|
|
18
|
+
export declare function endsWithHighSurrogate(text: string, end?: number): boolean;
|
|
19
|
+
//# sourceMappingURL=utf8.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../../src/autopilot/calls/utf8.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,EAAE,SAAc,GAAG,MAAM,CAc3E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkBlE;AAED,gHAAgH;AAChH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAc,GAAG,OAAO,CAE9E"}
|