@autumnsgrove/lyra 0.0.0-stage → 0.1.0
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/dist/adapters/cloudflare/index.d.ts +11 -0
- package/dist/adapters/cloudflare/index.d.ts.map +1 -0
- package/dist/adapters/cloudflare/index.js +11 -0
- package/dist/adapters/cloudflare/index.js.map +1 -0
- package/dist/adapters/cloudflare/secrets.d.ts +15 -0
- package/dist/adapters/cloudflare/secrets.d.ts.map +1 -0
- package/dist/adapters/cloudflare/secrets.js +24 -0
- package/dist/adapters/cloudflare/secrets.js.map +1 -0
- package/dist/adapters/cloudflare/storage.d.ts +43 -0
- package/dist/adapters/cloudflare/storage.d.ts.map +1 -0
- package/dist/adapters/cloudflare/storage.js +89 -0
- package/dist/adapters/cloudflare/storage.js.map +1 -0
- package/dist/adapters/cloudflare/waking.d.ts +34 -0
- package/dist/adapters/cloudflare/waking.d.ts.map +1 -0
- package/dist/adapters/cloudflare/waking.js +63 -0
- package/dist/adapters/cloudflare/waking.js.map +1 -0
- package/dist/adapters/memory/ids.d.ts +12 -0
- package/dist/adapters/memory/ids.d.ts.map +1 -0
- package/dist/adapters/memory/ids.js +20 -0
- package/dist/adapters/memory/ids.js.map +1 -0
- package/dist/adapters/memory/index.d.ts +13 -0
- package/dist/adapters/memory/index.d.ts.map +1 -0
- package/dist/adapters/memory/index.js +13 -0
- package/dist/adapters/memory/index.js.map +1 -0
- package/dist/adapters/memory/secrets.d.ts +14 -0
- package/dist/adapters/memory/secrets.d.ts.map +1 -0
- package/dist/adapters/memory/secrets.js +19 -0
- package/dist/adapters/memory/secrets.js.map +1 -0
- package/dist/adapters/memory/storage.d.ts +24 -0
- package/dist/adapters/memory/storage.d.ts.map +1 -0
- package/dist/adapters/memory/storage.js +40 -0
- package/dist/adapters/memory/storage.js.map +1 -0
- package/dist/adapters/memory/waking.d.ts +21 -0
- package/dist/adapters/memory/waking.d.ts.map +1 -0
- package/dist/adapters/memory/waking.js +29 -0
- package/dist/adapters/memory/waking.js.map +1 -0
- package/dist/core/clock.d.ts +22 -0
- package/dist/core/clock.d.ts.map +1 -0
- package/dist/core/clock.js +10 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/conversation.d.ts +28 -0
- package/dist/core/conversation.d.ts.map +1 -0
- package/dist/core/conversation.js +9 -0
- package/dist/core/conversation.js.map +1 -0
- package/dist/core/decode-reply.d.ts +28 -0
- package/dist/core/decode-reply.d.ts.map +1 -0
- package/dist/core/decode-reply.js +158 -0
- package/dist/core/decode-reply.js.map +1 -0
- package/dist/core/define-recipe.d.ts +54 -0
- package/dist/core/define-recipe.d.ts.map +1 -0
- package/dist/core/define-recipe.js +96 -0
- package/dist/core/define-recipe.js.map +1 -0
- package/dist/core/events.d.ts +98 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/events.js +14 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/execute-tools.d.ts +61 -0
- package/dist/core/execute-tools.d.ts.map +1 -0
- package/dist/core/execute-tools.js +147 -0
- package/dist/core/execute-tools.js.map +1 -0
- package/dist/core/finish.d.ts +53 -0
- package/dist/core/finish.d.ts.map +1 -0
- package/dist/core/finish.js +106 -0
- package/dist/core/finish.js.map +1 -0
- package/dist/core/handles.d.ts +34 -0
- package/dist/core/handles.d.ts.map +1 -0
- package/dist/core/handles.js +81 -0
- package/dist/core/handles.js.map +1 -0
- package/dist/core/json.d.ts +19 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +41 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/limits.d.ts +53 -0
- package/dist/core/limits.d.ts.map +1 -0
- package/dist/core/limits.js +81 -0
- package/dist/core/limits.js.map +1 -0
- package/dist/core/model.d.ts +66 -0
- package/dist/core/model.d.ts.map +1 -0
- package/dist/core/model.js +10 -0
- package/dist/core/model.js.map +1 -0
- package/dist/core/recipe.d.ts +45 -0
- package/dist/core/recipe.d.ts.map +1 -0
- package/dist/core/recipe.js +102 -0
- package/dist/core/recipe.js.map +1 -0
- package/dist/core/result.d.ts +38 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +35 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/resume.d.ts +71 -0
- package/dist/core/resume.d.ts.map +1 -0
- package/dist/core/resume.js +133 -0
- package/dist/core/resume.js.map +1 -0
- package/dist/core/run-handle.d.ts +39 -0
- package/dist/core/run-handle.d.ts.map +1 -0
- package/dist/core/run-handle.js +101 -0
- package/dist/core/run-handle.js.map +1 -0
- package/dist/core/run.d.ts +136 -0
- package/dist/core/run.d.ts.map +1 -0
- package/dist/core/run.js +1095 -0
- package/dist/core/run.js.map +1 -0
- package/dist/core/runtime.d.ts +81 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +201 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/schema.d.ts +119 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +469 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/slots.d.ts +32 -0
- package/dist/core/slots.d.ts.map +1 -0
- package/dist/core/slots.js +10 -0
- package/dist/core/slots.js.map +1 -0
- package/dist/core/state.d.ts +18 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +53 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/system-clock.d.ts +17 -0
- package/dist/core/system-clock.d.ts.map +1 -0
- package/dist/core/system-clock.js +59 -0
- package/dist/core/system-clock.js.map +1 -0
- package/dist/core/tool.d.ts +74 -0
- package/dist/core/tool.d.ts.map +1 -0
- package/dist/core/tool.js +48 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/record/entries.d.ts +152 -0
- package/dist/record/entries.d.ts.map +1 -0
- package/dist/record/entries.js +497 -0
- package/dist/record/entries.js.map +1 -0
- package/dist/record/load.d.ts +29 -0
- package/dist/record/load.d.ts.map +1 -0
- package/dist/record/load.js +106 -0
- package/dist/record/load.js.map +1 -0
- package/dist/record/replay.d.ts +16 -0
- package/dist/record/replay.d.ts.map +1 -0
- package/dist/record/replay.js +63 -0
- package/dist/record/replay.js.map +1 -0
- package/dist/record/truncate.d.ts +25 -0
- package/dist/record/truncate.d.ts.map +1 -0
- package/dist/record/truncate.js +167 -0
- package/dist/record/truncate.js.map +1 -0
- package/dist/testkit/clock.d.ts +19 -0
- package/dist/testkit/clock.d.ts.map +1 -0
- package/dist/testkit/clock.js +77 -0
- package/dist/testkit/clock.js.map +1 -0
- package/dist/testkit/crashing-storage.d.ts +23 -0
- package/dist/testkit/crashing-storage.d.ts.map +1 -0
- package/dist/testkit/crashing-storage.js +39 -0
- package/dist/testkit/crashing-storage.js.map +1 -0
- package/dist/testkit/index.d.ts +15 -0
- package/dist/testkit/index.d.ts.map +1 -0
- package/dist/testkit/index.js +15 -0
- package/dist/testkit/index.js.map +1 -0
- package/dist/testkit/model.d.ts +53 -0
- package/dist/testkit/model.d.ts.map +1 -0
- package/dist/testkit/model.js +80 -0
- package/dist/testkit/model.js.map +1 -0
- package/dist/testkit/scenario.d.ts +55 -0
- package/dist/testkit/scenario.d.ts.map +1 -0
- package/dist/testkit/scenario.js +505 -0
- package/dist/testkit/scenario.js.map +1 -0
- package/dist/testkit/storage.d.ts +18 -0
- package/dist/testkit/storage.d.ts.map +1 -0
- package/dist/testkit/storage.js +27 -0
- package/dist/testkit/storage.js.map +1 -0
- package/dist/testkit/timeline-recipe.d.ts +59 -0
- package/dist/testkit/timeline-recipe.d.ts.map +1 -0
- package/dist/testkit/timeline-recipe.js +322 -0
- package/dist/testkit/timeline-recipe.js.map +1 -0
- package/dist/testkit/tools.d.ts +47 -0
- package/dist/testkit/tools.d.ts.map +1 -0
- package/dist/testkit/tools.js +82 -0
- package/dist/testkit/tools.js.map +1 -0
- package/package.json +42 -5
- package/README.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limits (docs/limits-and-interruptions.md, LIM01 to LIM05 and LIM07; decisions
|
|
3
|
+
* 18 and 22).
|
|
4
|
+
*
|
|
5
|
+
* Every limit is optional and there is none by default. Reaching one parks the run
|
|
6
|
+
* rather than killing it, so the work done so far is kept and a person can resume
|
|
7
|
+
* it with a larger allowance. The check happens before each model request, which
|
|
8
|
+
* is the only place a run can pause without cutting a step in half.
|
|
9
|
+
*
|
|
10
|
+
* Time is active time, measured from a status on the injected clock, so a parked
|
|
11
|
+
* run costs nothing. A cost limit counts reported cost of any source; when a reply
|
|
12
|
+
* reports none the total is understated, so the limit stops being enforced for the
|
|
13
|
+
* run and the record says so once (decision 15).
|
|
14
|
+
*/
|
|
15
|
+
import { fail, ok } from "./result.js";
|
|
16
|
+
/**
|
|
17
|
+
* The order limits are checked in, and so the one named when several are reached
|
|
18
|
+
* at once. It is fixed rather than incidental so the same state always writes the
|
|
19
|
+
* same detail.
|
|
20
|
+
*/
|
|
21
|
+
export const LIMIT_DETAILS = ["steps", "tokens", "time", "cost"];
|
|
22
|
+
function isPositiveInteger(value) {
|
|
23
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
24
|
+
}
|
|
25
|
+
function isPositiveNumber(value) {
|
|
26
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A limit a recipe set, checked once when the run is created so a bad config fails
|
|
30
|
+
* fast instead of parking a run before it does anything (LIM03).
|
|
31
|
+
*/
|
|
32
|
+
export function validateLimits(limits) {
|
|
33
|
+
const checked = {};
|
|
34
|
+
if (limits.steps !== undefined) {
|
|
35
|
+
if (!isPositiveInteger(limits.steps)) {
|
|
36
|
+
return fail("bad_request", "a limit's steps must be a positive whole number");
|
|
37
|
+
}
|
|
38
|
+
checked.steps = limits.steps;
|
|
39
|
+
}
|
|
40
|
+
if (limits.tokens !== undefined) {
|
|
41
|
+
if (!isPositiveInteger(limits.tokens)) {
|
|
42
|
+
return fail("bad_request", "a limit's tokens must be a positive whole number");
|
|
43
|
+
}
|
|
44
|
+
checked.tokens = limits.tokens;
|
|
45
|
+
}
|
|
46
|
+
if (limits.timeMs !== undefined) {
|
|
47
|
+
if (!isPositiveInteger(limits.timeMs)) {
|
|
48
|
+
return fail("bad_request", "a limit's timeMs must be a positive whole number");
|
|
49
|
+
}
|
|
50
|
+
checked.timeMs = limits.timeMs;
|
|
51
|
+
}
|
|
52
|
+
if (limits.cost !== undefined) {
|
|
53
|
+
if (!isPositiveNumber(limits.cost)) {
|
|
54
|
+
return fail("bad_request", "a limit's cost must be a positive number");
|
|
55
|
+
}
|
|
56
|
+
checked.cost = limits.cost;
|
|
57
|
+
}
|
|
58
|
+
return ok(checked);
|
|
59
|
+
}
|
|
60
|
+
/** The first limit the run has reached, or nothing when it may keep going (LIM01). */
|
|
61
|
+
export function reachedLimit(limits, progress) {
|
|
62
|
+
if (limits === undefined) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (limits.steps !== undefined && progress.turns >= limits.steps) {
|
|
66
|
+
return "steps";
|
|
67
|
+
}
|
|
68
|
+
if (limits.tokens !== undefined && progress.tokens >= limits.tokens) {
|
|
69
|
+
return "tokens";
|
|
70
|
+
}
|
|
71
|
+
if (limits.timeMs !== undefined && progress.activeMs >= limits.timeMs) {
|
|
72
|
+
return "time";
|
|
73
|
+
}
|
|
74
|
+
// An unmeasurable cost total is not a limit: the run notes it and carries on
|
|
75
|
+
// rather than pretending the limit works (LIM05).
|
|
76
|
+
if (limits.cost !== undefined && progress.cost.known && progress.cost.amount >= limits.cost) {
|
|
77
|
+
return "cost";
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/core/limits.ts"],"names":[],"mappings":"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OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Model slot: the one contract every model adapter meets.
|
|
3
|
+
*
|
|
4
|
+
* Lumen's adapter, the OpenAI-style adapter and the scripted fake all answer a
|
|
5
|
+
* `ModelRequest` with a `ModelReply`. The request carries no task, no tier, no
|
|
6
|
+
* tenant and no quota idea, so an adapter cannot leak its host into the core
|
|
7
|
+
* (docs/adapters.md, "What it costs").
|
|
8
|
+
*/
|
|
9
|
+
import type { ConversationMessage } from "./conversation.js";
|
|
10
|
+
import type { JsonObject } from "./json.js";
|
|
11
|
+
import type { LyraError, Result } from "./result.js";
|
|
12
|
+
/**
|
|
13
|
+
* Tokens are always reported. Cost only when it is known, and it says where it
|
|
14
|
+
* came from, because an allowance and a provider invoice are not the same thing
|
|
15
|
+
* (docs/adapters.md, decision 15).
|
|
16
|
+
*/
|
|
17
|
+
export interface Usage {
|
|
18
|
+
inputTokens: number;
|
|
19
|
+
outputTokens: number;
|
|
20
|
+
cost?: {
|
|
21
|
+
amount: number;
|
|
22
|
+
currency: "USD";
|
|
23
|
+
source: "provider" | "allowance" | "catalog";
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export type FinishReason = "stop" | "length" | "tool_calls" | "content_filter" | "other";
|
|
27
|
+
/** A JSON Schema object, as plain data. Validating it is step 3's job. */
|
|
28
|
+
export interface ToolSpec {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
parameters: JsonObject;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A tool request from the model. `arguments` stays raw text: a model can send
|
|
35
|
+
* invalid JSON, and that is a fact of life the loop hands back, not a crash.
|
|
36
|
+
*/
|
|
37
|
+
export interface ToolCall {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
arguments: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ModelRequest {
|
|
43
|
+
system: string;
|
|
44
|
+
messages: ConversationMessage[];
|
|
45
|
+
tools: ToolSpec[];
|
|
46
|
+
/** Lets a recipe name a fallback model (decision 58). */
|
|
47
|
+
model?: string;
|
|
48
|
+
signal: AbortSignal;
|
|
49
|
+
}
|
|
50
|
+
export interface ModelReply {
|
|
51
|
+
text: string;
|
|
52
|
+
reasoning?: string;
|
|
53
|
+
toolCalls: ToolCall[];
|
|
54
|
+
usage: Usage;
|
|
55
|
+
finishReason: FinishReason;
|
|
56
|
+
model: string;
|
|
57
|
+
}
|
|
58
|
+
/** A model failure. `retryable` is what step 2 reads to decide whether to try again. */
|
|
59
|
+
export interface ModelError extends LyraError {
|
|
60
|
+
retryable: boolean;
|
|
61
|
+
retryAfterMs?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ModelSlot {
|
|
64
|
+
complete(request: ModelRequest): Promise<Result<ModelReply, ModelError>>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,KAAK,CAAC;QAChB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;KAC7C,CAAC;CACF;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,gBAAgB,GAAG,OAAO,CAAC;AAEzF,0EAA0E;AAC1E,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wFAAwF;AACxF,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Model slot: the one contract every model adapter meets.
|
|
3
|
+
*
|
|
4
|
+
* Lumen's adapter, the OpenAI-style adapter and the scripted fake all answer a
|
|
5
|
+
* `ModelRequest` with a `ModelReply`. The request carries no task, no tier, no
|
|
6
|
+
* tenant and no quota idea, so an adapter cannot leak its host into the core
|
|
7
|
+
* (docs/adapters.md, "What it costs").
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The recipe's pin (docs/run-record.md, decision 91; REC05 to REC09).
|
|
3
|
+
*
|
|
4
|
+
* A run can outlive a deploy, and deploys evict a Durable Object once or twice a
|
|
5
|
+
* day, so a resume often runs on code that is newer than the run. The header pins
|
|
6
|
+
* what the run started with, and a resume compares the current definition to it:
|
|
7
|
+
* the same tools and instructions continue, a reworded prompt or a new version is
|
|
8
|
+
* noted, and a changed tool set stops for a person, because a tool the record
|
|
9
|
+
* already used may no longer exist.
|
|
10
|
+
*
|
|
11
|
+
* The hashes are SHA-256 over canonical JSON (keys sorted at every level) of the
|
|
12
|
+
* tool names and their argument schemas, and of the instructions' text. Descriptions
|
|
13
|
+
* are left out on purpose: rewording a description does not change what a tool
|
|
14
|
+
* does, so it must not stop a run. `crypto.subtle` is web-standard, so this works on
|
|
15
|
+
* Workers and on Node, and being async is the price of not growing a dependency.
|
|
16
|
+
*/
|
|
17
|
+
import type { RecipeStamp, ToolStamp } from "../record/entries.js";
|
|
18
|
+
import type { ToolSpec } from "./model.js";
|
|
19
|
+
/** JSON with object keys sorted at every level, so the same value always hashes the same. */
|
|
20
|
+
export declare function canonicalJson(value: unknown): string;
|
|
21
|
+
/** One tool's pin: its name and the hash of its name and arguments, never its description. */
|
|
22
|
+
export declare function stampTool(spec: ToolSpec): Promise<ToolStamp>;
|
|
23
|
+
export interface RecipeDefinition {
|
|
24
|
+
name: string;
|
|
25
|
+
version: number;
|
|
26
|
+
/** The instructions the model is given, which is the run's `system` text. */
|
|
27
|
+
instructions: string;
|
|
28
|
+
tools: readonly ToolSpec[];
|
|
29
|
+
}
|
|
30
|
+
export declare function pinRecipe(definition: RecipeDefinition): Promise<RecipeStamp>;
|
|
31
|
+
export interface RecipeChange {
|
|
32
|
+
added: string[];
|
|
33
|
+
removed: string[];
|
|
34
|
+
changed: string[];
|
|
35
|
+
}
|
|
36
|
+
/** What changed between two pins' tool sets, by name. */
|
|
37
|
+
export declare function compareTools(before: readonly ToolStamp[] | undefined, after: readonly ToolStamp[] | undefined): RecipeChange;
|
|
38
|
+
/**
|
|
39
|
+
* One line naming what moved, for a parked status's `detail`, or for the
|
|
40
|
+
* `recipe_updated` entry that says a run carried on. A tool the record already used
|
|
41
|
+
* and no longer has is flagged, because that is the case the pin exists to catch:
|
|
42
|
+
* the model may ask for it and nothing would answer.
|
|
43
|
+
*/
|
|
44
|
+
export declare function describeChange(change: RecipeChange, used: ReadonlySet<string>): string;
|
|
45
|
+
//# sourceMappingURL=recipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipe.d.ts","sourceRoot":"","sources":["../../src/core/recipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAepD;AAOD,8FAA8F;AAC9F,wBAAsB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAGlE;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC3B;AAED,wBAAsB,SAAS,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CAalF;AAED,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,yDAAyD;AACzD,wBAAgB,YAAY,CAC3B,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EACxC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,GACrC,YAAY,CAqBd;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAgBtF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The recipe's pin (docs/run-record.md, decision 91; REC05 to REC09).
|
|
3
|
+
*
|
|
4
|
+
* A run can outlive a deploy, and deploys evict a Durable Object once or twice a
|
|
5
|
+
* day, so a resume often runs on code that is newer than the run. The header pins
|
|
6
|
+
* what the run started with, and a resume compares the current definition to it:
|
|
7
|
+
* the same tools and instructions continue, a reworded prompt or a new version is
|
|
8
|
+
* noted, and a changed tool set stops for a person, because a tool the record
|
|
9
|
+
* already used may no longer exist.
|
|
10
|
+
*
|
|
11
|
+
* The hashes are SHA-256 over canonical JSON (keys sorted at every level) of the
|
|
12
|
+
* tool names and their argument schemas, and of the instructions' text. Descriptions
|
|
13
|
+
* are left out on purpose: rewording a description does not change what a tool
|
|
14
|
+
* does, so it must not stop a run. `crypto.subtle` is web-standard, so this works on
|
|
15
|
+
* Workers and on Node, and being async is the price of not growing a dependency.
|
|
16
|
+
*/
|
|
17
|
+
const encoder = new TextEncoder();
|
|
18
|
+
/** JSON with object keys sorted at every level, so the same value always hashes the same. */
|
|
19
|
+
export function canonicalJson(value) {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
return "null";
|
|
22
|
+
}
|
|
23
|
+
if (value === null || typeof value !== "object") {
|
|
24
|
+
return JSON.stringify(value) ?? "null";
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
28
|
+
}
|
|
29
|
+
const object = value;
|
|
30
|
+
const keys = Object.keys(object).sort();
|
|
31
|
+
return `{${keys
|
|
32
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key])}`)
|
|
33
|
+
.join(",")}}`;
|
|
34
|
+
}
|
|
35
|
+
async function sha256Hex(text) {
|
|
36
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(text));
|
|
37
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
38
|
+
}
|
|
39
|
+
/** One tool's pin: its name and the hash of its name and arguments, never its description. */
|
|
40
|
+
export async function stampTool(spec) {
|
|
41
|
+
const hash = await sha256Hex(canonicalJson({ name: spec.name, parameters: spec.parameters }));
|
|
42
|
+
return { name: spec.name, hash };
|
|
43
|
+
}
|
|
44
|
+
export async function pinRecipe(definition) {
|
|
45
|
+
const stamps = [];
|
|
46
|
+
for (const spec of definition.tools) {
|
|
47
|
+
stamps.push(await stampTool(spec));
|
|
48
|
+
}
|
|
49
|
+
stamps.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
|
|
50
|
+
return {
|
|
51
|
+
name: definition.name,
|
|
52
|
+
version: definition.version,
|
|
53
|
+
toolSetHash: await sha256Hex(canonicalJson(stamps)),
|
|
54
|
+
instructionsHash: await sha256Hex(definition.instructions),
|
|
55
|
+
tools: stamps,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** What changed between two pins' tool sets, by name. */
|
|
59
|
+
export function compareTools(before, after) {
|
|
60
|
+
const old = new Map((before ?? []).map((tool) => [tool.name, tool.hash]));
|
|
61
|
+
const now = new Map((after ?? []).map((tool) => [tool.name, tool.hash]));
|
|
62
|
+
const added = [];
|
|
63
|
+
const removed = [];
|
|
64
|
+
const changed = [];
|
|
65
|
+
for (const [name, hash] of now) {
|
|
66
|
+
const previous = old.get(name);
|
|
67
|
+
if (previous === undefined) {
|
|
68
|
+
added.push(name);
|
|
69
|
+
}
|
|
70
|
+
else if (previous !== hash) {
|
|
71
|
+
changed.push(name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const name of old.keys()) {
|
|
75
|
+
if (!now.has(name)) {
|
|
76
|
+
removed.push(name);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { added: added.sort(), removed: removed.sort(), changed: changed.sort() };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One line naming what moved, for a parked status's `detail`, or for the
|
|
83
|
+
* `recipe_updated` entry that says a run carried on. A tool the record already used
|
|
84
|
+
* and no longer has is flagged, because that is the case the pin exists to catch:
|
|
85
|
+
* the model may ask for it and nothing would answer.
|
|
86
|
+
*/
|
|
87
|
+
export function describeChange(change, used) {
|
|
88
|
+
const parts = [];
|
|
89
|
+
if (change.added.length > 0) {
|
|
90
|
+
parts.push(`added ${change.added.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
if (change.removed.length > 0) {
|
|
93
|
+
parts.push(`removed ${change.removed
|
|
94
|
+
.map((name) => (used.has(name) ? `${name} (was used)` : name))
|
|
95
|
+
.join(", ")}`);
|
|
96
|
+
}
|
|
97
|
+
if (change.changed.length > 0) {
|
|
98
|
+
parts.push(`changed ${change.changed.join(", ")}`);
|
|
99
|
+
}
|
|
100
|
+
return parts.length === 0 ? "the instructions changed" : parts.join("; ");
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipe.js","sourceRoot":"","sources":["../../src/core/recipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAAC,KAAc;IAC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,IAAI,CAAC,SAAS,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CACT,WAAW,MAAM,CAAC,OAAO;aACvB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aAC7D,IAAI,CAAC,IAAI,CAAC,EAAE,CACd,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure is data (docs/core-loop.md, "Failure is a value").
|
|
3
|
+
*
|
|
4
|
+
* Nothing in the core throws across a module boundary. A function that can fail
|
|
5
|
+
* returns a `Result`, and the caller has to look at it, so a model error, a
|
|
6
|
+
* failed save or a dead tool cannot take the loop down by surprise.
|
|
7
|
+
*/
|
|
8
|
+
/** Nova's eight stable codes, plus `conflict` (docs/decisions.md, decision 83). */
|
|
9
|
+
export declare const ERROR_CODES: readonly ["bad_request", "busy", "not_found", "permission_denied", "unsupported", "timeout", "provider_error", "internal", "conflict"];
|
|
10
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
11
|
+
export declare function isErrorCode(value: unknown): value is ErrorCode;
|
|
12
|
+
export interface LyraError {
|
|
13
|
+
code: ErrorCode;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
export type Result<T, E = LyraError> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
value: T;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: E;
|
|
22
|
+
};
|
|
23
|
+
/** The success half, spelled out so its type stays narrow. */
|
|
24
|
+
export declare function ok<T>(value: T): {
|
|
25
|
+
ok: true;
|
|
26
|
+
value: T;
|
|
27
|
+
};
|
|
28
|
+
/** The failure half. */
|
|
29
|
+
export declare function err<E>(error: E): {
|
|
30
|
+
ok: false;
|
|
31
|
+
error: E;
|
|
32
|
+
};
|
|
33
|
+
/** A failure with a code, which is the common case. */
|
|
34
|
+
export declare function fail(code: ErrorCode, message: string): {
|
|
35
|
+
ok: false;
|
|
36
|
+
error: LyraError;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mFAAmF;AACnF,eAAO,MAAM,WAAW,YACvB,aAAa,EACb,MAAM,EACN,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,UAAU,CACD,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAExF,8DAA8D;AAC9D,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAEtD;AAED,wBAAwB;AACxB,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAExD;AAED,uDAAuD;AACvD,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAEtF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure is data (docs/core-loop.md, "Failure is a value").
|
|
3
|
+
*
|
|
4
|
+
* Nothing in the core throws across a module boundary. A function that can fail
|
|
5
|
+
* returns a `Result`, and the caller has to look at it, so a model error, a
|
|
6
|
+
* failed save or a dead tool cannot take the loop down by surprise.
|
|
7
|
+
*/
|
|
8
|
+
/** Nova's eight stable codes, plus `conflict` (docs/decisions.md, decision 83). */
|
|
9
|
+
export const ERROR_CODES = [
|
|
10
|
+
"bad_request",
|
|
11
|
+
"busy",
|
|
12
|
+
"not_found",
|
|
13
|
+
"permission_denied",
|
|
14
|
+
"unsupported",
|
|
15
|
+
"timeout",
|
|
16
|
+
"provider_error",
|
|
17
|
+
"internal",
|
|
18
|
+
"conflict",
|
|
19
|
+
];
|
|
20
|
+
export function isErrorCode(value) {
|
|
21
|
+
return ERROR_CODES.some((code) => code === value);
|
|
22
|
+
}
|
|
23
|
+
/** The success half, spelled out so its type stays narrow. */
|
|
24
|
+
export function ok(value) {
|
|
25
|
+
return { ok: true, value };
|
|
26
|
+
}
|
|
27
|
+
/** The failure half. */
|
|
28
|
+
export function err(error) {
|
|
29
|
+
return { ok: false, error };
|
|
30
|
+
}
|
|
31
|
+
/** A failure with a code, which is the common case. */
|
|
32
|
+
export function fail(code, message) {
|
|
33
|
+
return err({ code, message });
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mFAAmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,aAAa;IACb,MAAM;IACN,WAAW;IACX,mBAAmB;IACnB,aAAa;IACb,SAAS;IACT,gBAAgB;IAChB,UAAU;IACV,UAAU;CACD,CAAC;AAIX,MAAM,UAAU,WAAW,CAAC,KAAc;IACzC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;AACnD,CAAC;AASD,8DAA8D;AAC9D,MAAM,UAAU,EAAE,CAAI,KAAQ;IAC7B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,wBAAwB;AACxB,MAAM,UAAU,GAAG,CAAI,KAAQ;IAC9B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,IAAI,CAAC,IAAe,EAAE,OAAe;IACpD,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a run back out of its record (decisions 20, 23, 24).
|
|
3
|
+
*
|
|
4
|
+
* A resume is not a new run: it continues the conversation the record replayed,
|
|
5
|
+
* with the turns and tokens already spent counted, so a limit means the same thing
|
|
6
|
+
* across an interruption. Everything here is derived from the record and nothing is
|
|
7
|
+
* guessed: a record with no usable header is refused rather than given an invented
|
|
8
|
+
* run id, and an entry kind this build does not know is part of the chain but not
|
|
9
|
+
* the conversation.
|
|
10
|
+
*
|
|
11
|
+
* The record cannot say whether a killed tool ran, so the last assistant turn's
|
|
12
|
+
* calls that have no result after it are reported rather than assumed
|
|
13
|
+
* (`unansweredCalls`), and the loop decides what may be repeated (decision 24).
|
|
14
|
+
* A result can be missing even when a later call's result was saved, because a
|
|
15
|
+
* batch saves each answer as it arrives, which is why this looks at the whole tail
|
|
16
|
+
* and not only at the last entry.
|
|
17
|
+
*/
|
|
18
|
+
import type { RecipeStamp, RecordEntry, StatusEntry } from "../record/entries.js";
|
|
19
|
+
import { type JsonValue } from "./json.js";
|
|
20
|
+
import { type LoadedRecord } from "../record/load.js";
|
|
21
|
+
import type { Ids } from "./clock.js";
|
|
22
|
+
import type { ConversationMessage } from "./conversation.js";
|
|
23
|
+
import type { ToolCall, Usage } from "./model.js";
|
|
24
|
+
import { type Result } from "./result.js";
|
|
25
|
+
export interface ResumeSeed {
|
|
26
|
+
record: LoadedRecord;
|
|
27
|
+
/** The conversation to continue, exactly as the model last saw it. */
|
|
28
|
+
messages: ConversationMessage[];
|
|
29
|
+
/** The id of the last entry, which is what the next entry's `parent` is. */
|
|
30
|
+
parent: string | null;
|
|
31
|
+
/** Model turns already taken. */
|
|
32
|
+
turns: number;
|
|
33
|
+
/** What each reply reported, oldest first, so the totals survive a resume. */
|
|
34
|
+
usages: Usage[];
|
|
35
|
+
/** Active milliseconds already spent in closed segments of the run. */
|
|
36
|
+
activeMs: number;
|
|
37
|
+
/** The last status on the path. */
|
|
38
|
+
status: StatusEntry | undefined;
|
|
39
|
+
/** The last message-shaped entry on the path, which decides what happens next. */
|
|
40
|
+
last: RecordEntry | undefined;
|
|
41
|
+
/** Tool names the record already holds a call for, on the path. */
|
|
42
|
+
usedTools: ReadonlySet<string>;
|
|
43
|
+
/** Calls of the last assistant turn that have no result saved after it. */
|
|
44
|
+
unansweredCalls: ToolCall[];
|
|
45
|
+
/**
|
|
46
|
+
* The run's last act was a tool result that passed the done-check (decision 25).
|
|
47
|
+
* Only when it is the last message: a follow-up saved after it means the run has
|
|
48
|
+
* more to do, and a resume that stopped there would silently drop it.
|
|
49
|
+
*/
|
|
50
|
+
finished: boolean;
|
|
51
|
+
/** The pin the run was last held to: the header's, or the latest `recipe_updated`'s. */
|
|
52
|
+
pin: RecipeStamp | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The task's input as JSON, from the `task` message's details, so a resume can run
|
|
55
|
+
* the recipe's `setup` again. Absent on a record written before step 3, and on one
|
|
56
|
+
* whose task message never landed (decision 112).
|
|
57
|
+
*/
|
|
58
|
+
input: JsonValue | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Move the id source past every id the record already holds.
|
|
62
|
+
*
|
|
63
|
+
* The record is the truth about which ids are taken, and a host's `Ids` has no
|
|
64
|
+
* memory of a previous process: a counter starts again at one, and a resume that
|
|
65
|
+
* wrote `e1` into a record that already had one would have its line skipped as a
|
|
66
|
+
* duplicate, losing a step. This advances a counter until it is clear of the record
|
|
67
|
+
* and costs a random source one draw, which is why it is a loop rather than a check.
|
|
68
|
+
*/
|
|
69
|
+
export declare function reserveIds(ids: Ids, entries: readonly RecordEntry[]): void;
|
|
70
|
+
export declare function readResumeSeed(lines: readonly string[]): Result<ResumeSeed>;
|
|
71
|
+
//# sourceMappingURL=resume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.d.ts","sourceRoot":"","sources":["../../src/core/resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAEX,WAAW,EACX,WAAW,EACX,WAAW,EAEX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACvE,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@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a run back out of its record (decisions 20, 23, 24).
|
|
3
|
+
*
|
|
4
|
+
* A resume is not a new run: it continues the conversation the record replayed,
|
|
5
|
+
* with the turns and tokens already spent counted, so a limit means the same thing
|
|
6
|
+
* across an interruption. Everything here is derived from the record and nothing is
|
|
7
|
+
* guessed: a record with no usable header is refused rather than given an invented
|
|
8
|
+
* run id, and an entry kind this build does not know is part of the chain but not
|
|
9
|
+
* the conversation.
|
|
10
|
+
*
|
|
11
|
+
* The record cannot say whether a killed tool ran, so the last assistant turn's
|
|
12
|
+
* calls that have no result after it are reported rather than assumed
|
|
13
|
+
* (`unansweredCalls`), and the loop decides what may be repeated (decision 24).
|
|
14
|
+
* A result can be missing even when a later call's result was saved, because a
|
|
15
|
+
* batch saves each answer as it arrives, which is why this looks at the whole tail
|
|
16
|
+
* and not only at the last entry.
|
|
17
|
+
*/
|
|
18
|
+
import { isJsonValue, isPlainObject } from "./json.js";
|
|
19
|
+
import { loadRecord } from "../record/load.js";
|
|
20
|
+
import { activePath, replayConversation } from "../record/replay.js";
|
|
21
|
+
import { ok } from "./result.js";
|
|
22
|
+
/** The input saved on a `task` message, if it is there and shaped as this build writes it. */
|
|
23
|
+
function inputOf(message) {
|
|
24
|
+
const details = message?.details;
|
|
25
|
+
if (!isPlainObject(details) || !Object.prototype.hasOwnProperty.call(details, "input")) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const input = details["input"];
|
|
29
|
+
return isJsonValue(input) ? input : undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Move the id source past every id the record already holds.
|
|
33
|
+
*
|
|
34
|
+
* The record is the truth about which ids are taken, and a host's `Ids` has no
|
|
35
|
+
* memory of a previous process: a counter starts again at one, and a resume that
|
|
36
|
+
* wrote `e1` into a record that already had one would have its line skipped as a
|
|
37
|
+
* duplicate, losing a step. This advances a counter until it is clear of the record
|
|
38
|
+
* and costs a random source one draw, which is why it is a loop rather than a check.
|
|
39
|
+
*/
|
|
40
|
+
export function reserveIds(ids, entries) {
|
|
41
|
+
const used = new Set(entries.map((entry) => entry.id));
|
|
42
|
+
// A finite source that can only answer with used ids must not hang the resume; the
|
|
43
|
+
// loader skips a duplicate rather than crashing, so giving up is safe.
|
|
44
|
+
for (let attempt = 0; attempt <= used.size; attempt += 1) {
|
|
45
|
+
if (!used.has(ids.next("e"))) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function readResumeSeed(lines) {
|
|
51
|
+
const loaded = loadRecord([...lines]);
|
|
52
|
+
if (!loaded.ok) {
|
|
53
|
+
return loaded;
|
|
54
|
+
}
|
|
55
|
+
const path = activePath(loaded.value.entries);
|
|
56
|
+
let turns = 0;
|
|
57
|
+
const usages = [];
|
|
58
|
+
let activeMs = 0;
|
|
59
|
+
let openSegment;
|
|
60
|
+
let status;
|
|
61
|
+
let last;
|
|
62
|
+
let assistant;
|
|
63
|
+
let pin = loaded.value.header.recipe;
|
|
64
|
+
let taskMessage;
|
|
65
|
+
const usedTools = new Set();
|
|
66
|
+
for (const [index, entry] of path.entries()) {
|
|
67
|
+
switch (entry.type) {
|
|
68
|
+
case "status":
|
|
69
|
+
status = entry;
|
|
70
|
+
if (entry.state === "running" || entry.state === "resumed") {
|
|
71
|
+
openSegment = entry.ts;
|
|
72
|
+
}
|
|
73
|
+
else if (openSegment !== undefined) {
|
|
74
|
+
// A parked, done or failed segment is time the run did not spend working.
|
|
75
|
+
activeMs += Math.max(0, entry.ts - openSegment);
|
|
76
|
+
openSegment = undefined;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "assistant_message":
|
|
80
|
+
turns += 1;
|
|
81
|
+
usages.push(entry.usage);
|
|
82
|
+
for (const call of entry.toolCalls) {
|
|
83
|
+
usedTools.add(call.name);
|
|
84
|
+
}
|
|
85
|
+
assistant = { entry, index };
|
|
86
|
+
last = entry;
|
|
87
|
+
break;
|
|
88
|
+
case "user_message":
|
|
89
|
+
if (entry.label === "task" && taskMessage === undefined) {
|
|
90
|
+
taskMessage = entry;
|
|
91
|
+
}
|
|
92
|
+
last = entry;
|
|
93
|
+
break;
|
|
94
|
+
case "tool_message":
|
|
95
|
+
last = entry;
|
|
96
|
+
break;
|
|
97
|
+
case "recipe_updated":
|
|
98
|
+
pin = entry.to;
|
|
99
|
+
break;
|
|
100
|
+
case "fallback":
|
|
101
|
+
case "note":
|
|
102
|
+
case "unknown":
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const answeredAfter = new Set();
|
|
107
|
+
if (assistant !== undefined) {
|
|
108
|
+
for (const [index, entry] of path.entries()) {
|
|
109
|
+
if (index > assistant.index && entry.type === "tool_message") {
|
|
110
|
+
answeredAfter.add(entry.toolCallId);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const unansweredCalls = assistant === undefined
|
|
115
|
+
? []
|
|
116
|
+
: assistant.entry.toolCalls.filter((call) => !answeredAfter.has(call.id));
|
|
117
|
+
return ok({
|
|
118
|
+
record: loaded.value,
|
|
119
|
+
messages: replayConversation(loaded.value.entries),
|
|
120
|
+
parent: loaded.value.entries.at(-1)?.id ?? null,
|
|
121
|
+
turns,
|
|
122
|
+
usages,
|
|
123
|
+
activeMs,
|
|
124
|
+
status,
|
|
125
|
+
last,
|
|
126
|
+
usedTools,
|
|
127
|
+
unansweredCalls,
|
|
128
|
+
finished: last?.type === "tool_message" && last.done === true,
|
|
129
|
+
pin,
|
|
130
|
+
input: inputOf(taskMessage),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.js","sourceRoot":"","sources":["../../src/core/resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAk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