@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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's handle: how a person stops, steers or follows up on it (decisions 19,
|
|
3
|
+
* 27; STP01 to STP05).
|
|
4
|
+
*
|
|
5
|
+
* `runTask` stays the primitive and this is the thing a host holds. The handle owns
|
|
6
|
+
* the signal and the queues, so a command has somewhere to go between the
|
|
7
|
+
* synchronous start of the run and its end:
|
|
8
|
+
*
|
|
9
|
+
* - `abort()` fires the run's own signal, which cancels the request in flight or
|
|
10
|
+
* the tool that is running; a second one is a no-op.
|
|
11
|
+
* - `steer()` and `followUp()` are queued, never delivered on arrival, because
|
|
12
|
+
* writing a message between an assistant turn and its results would break the
|
|
13
|
+
* pairing a provider checks. The loop reads them at its gaps.
|
|
14
|
+
*
|
|
15
|
+
* Each queued text is measured against the record's entry cap when it is queued,
|
|
16
|
+
* not when it is written, so an oversized one is refused with `bad_request` and
|
|
17
|
+
* nothing is left half-queued. Its id and time are decided there too, so the
|
|
18
|
+
* measurement is the real entry rather than an estimate.
|
|
19
|
+
*/
|
|
20
|
+
import type { RunEventListener } from "./events.js";
|
|
21
|
+
import { type Result } from "./result.js";
|
|
22
|
+
import { type RunConfig, type RunResult } from "./run.js";
|
|
23
|
+
/** Everything a run needs except the two things the handle owns: the signal and the listener. */
|
|
24
|
+
export type RunSetup = Omit<RunConfig, "signal" | "onEvent" | "control">;
|
|
25
|
+
export interface RunHandle {
|
|
26
|
+
readonly runId: string;
|
|
27
|
+
/** Settles when the run has ended, with the result the loop reached. */
|
|
28
|
+
readonly outcome: Promise<RunResult>;
|
|
29
|
+
/** Stop the run. It parks as `stopped`, and a second abort does nothing. */
|
|
30
|
+
abort(): void;
|
|
31
|
+
/** Redirect the run at its next gap. Refused once it has ended. */
|
|
32
|
+
steer(text: string): Result<void>;
|
|
33
|
+
/** Say one more thing when the run would otherwise end. Refused once it has ended. */
|
|
34
|
+
followUp(text: string): Result<void>;
|
|
35
|
+
/** Watch this run. The returned function stops watching. */
|
|
36
|
+
subscribe(listener: RunEventListener): () => void;
|
|
37
|
+
}
|
|
38
|
+
export declare function createRun(setup: RunSetup): RunHandle;
|
|
39
|
+
//# sourceMappingURL=run-handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-handle.d.ts","sourceRoot":"","sources":["../../src/core/run-handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAIN,KAAK,SAAS,EAEd,KAAK,SAAS,EACd,MAAM,UAAU,CAAC;AAElB,iGAAiG;AACjG,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,CAAC;AAEzE,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,4EAA4E;IAC5E,KAAK,IAAI,IAAI,CAAC;IACd,mEAAmE;IACnE,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,4DAA4D;IAC5D,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAC;CAClD;AAUD,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CA+EpD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's handle: how a person stops, steers or follows up on it (decisions 19,
|
|
3
|
+
* 27; STP01 to STP05).
|
|
4
|
+
*
|
|
5
|
+
* `runTask` stays the primitive and this is the thing a host holds. The handle owns
|
|
6
|
+
* the signal and the queues, so a command has somewhere to go between the
|
|
7
|
+
* synchronous start of the run and its end:
|
|
8
|
+
*
|
|
9
|
+
* - `abort()` fires the run's own signal, which cancels the request in flight or
|
|
10
|
+
* the tool that is running; a second one is a no-op.
|
|
11
|
+
* - `steer()` and `followUp()` are queued, never delivered on arrival, because
|
|
12
|
+
* writing a message between an assistant turn and its results would break the
|
|
13
|
+
* pairing a provider checks. The loop reads them at its gaps.
|
|
14
|
+
*
|
|
15
|
+
* Each queued text is measured against the record's entry cap when it is queued,
|
|
16
|
+
* not when it is written, so an oversized one is refused with `bad_request` and
|
|
17
|
+
* nothing is left half-queued. Its id and time are decided there too, so the
|
|
18
|
+
* measurement is the real entry rather than an estimate.
|
|
19
|
+
*/
|
|
20
|
+
import { encodeEntry } from "../record/entries.js";
|
|
21
|
+
import { utf8Length } from "../record/truncate.js";
|
|
22
|
+
import { fail, ok } from "./result.js";
|
|
23
|
+
import { entryCapBytes, runTask, } from "./run.js";
|
|
24
|
+
/**
|
|
25
|
+
* The longest id the core can make is 39 characters (128 bits as hex with a
|
|
26
|
+
* prefix, decision 85), so a parent id is never longer than this placeholder.
|
|
27
|
+
* Measuring the queued entry with one means a text that passes here cannot
|
|
28
|
+
* overflow the entry when the real parent is linked in.
|
|
29
|
+
*/
|
|
30
|
+
const PARENT_PLACEHOLDER = "x".repeat(64);
|
|
31
|
+
export function createRun(setup) {
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const cap = entryCapBytes(setup.storage, setup.entryCapBytes);
|
|
34
|
+
const steers = [];
|
|
35
|
+
const followUps = [];
|
|
36
|
+
const listeners = new Set();
|
|
37
|
+
let ended = false;
|
|
38
|
+
const queue = (label, text) => {
|
|
39
|
+
if (ended) {
|
|
40
|
+
return fail("conflict", "the run has already ended");
|
|
41
|
+
}
|
|
42
|
+
const id = setup.ids.next("e");
|
|
43
|
+
const entry = {
|
|
44
|
+
type: "user_message",
|
|
45
|
+
id,
|
|
46
|
+
parent: PARENT_PLACEHOLDER,
|
|
47
|
+
ts: setup.clock.now(),
|
|
48
|
+
label,
|
|
49
|
+
text,
|
|
50
|
+
};
|
|
51
|
+
if (utf8Length(encodeEntry(entry)) > cap) {
|
|
52
|
+
return fail("bad_request", `the text is bigger than one record entry can hold (${cap} bytes)`);
|
|
53
|
+
}
|
|
54
|
+
(label === "steer" ? steers : followUps).push({ id, ts: entry.ts, text });
|
|
55
|
+
return ok(undefined);
|
|
56
|
+
};
|
|
57
|
+
const control = {
|
|
58
|
+
takeSteers: () => steers.splice(0, steers.length),
|
|
59
|
+
takeFollowUps: () => followUps.splice(0, followUps.length),
|
|
60
|
+
};
|
|
61
|
+
const outcome = runTask({
|
|
62
|
+
...setup,
|
|
63
|
+
signal: controller.signal,
|
|
64
|
+
control,
|
|
65
|
+
onEvent: (event) => {
|
|
66
|
+
// A listener is not allowed to be the reason a run fails (LOOP11), and one
|
|
67
|
+
// that throws must not stop the others from hearing.
|
|
68
|
+
for (const listener of [...listeners]) {
|
|
69
|
+
try {
|
|
70
|
+
listener(event);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Nothing to do: the loop already has the event.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
// The end is known when the loop's promise settles, which is after its closing
|
|
79
|
+
// status is saved, so a command after that point has nothing to join.
|
|
80
|
+
void outcome.then(() => {
|
|
81
|
+
ended = true;
|
|
82
|
+
}, () => {
|
|
83
|
+
ended = true;
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
runId: setup.runId,
|
|
87
|
+
outcome,
|
|
88
|
+
abort: () => {
|
|
89
|
+
controller.abort();
|
|
90
|
+
},
|
|
91
|
+
steer: (text) => queue("steer", text),
|
|
92
|
+
followUp: (text) => queue("follow_up", text),
|
|
93
|
+
subscribe(listener) {
|
|
94
|
+
listeners.add(listener);
|
|
95
|
+
return () => {
|
|
96
|
+
listeners.delete(listener);
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=run-handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-handle.js","sourceRoot":"","sources":["../../src/core/run-handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAyB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AACpD,OAAO,EACN,aAAa,EACb,OAAO,GAKP,MAAM,UAAU,CAAC;AAmBlB;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE1C,MAAM,UAAU,SAAS,CAAC,KAAe;IACxC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,MAAM,SAAS,GAAoB,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,IAAI,KAAK,GAAG,KAAK,CAAC;IAElB,MAAM,KAAK,GAAG,CAAC,KAA4B,EAAE,IAAY,EAAgB,EAAE;QAC1E,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAqB;YAC/B,IAAI,EAAE,cAAc;YACpB,EAAE;YACF,MAAM,EAAE,kBAAkB;YAC1B,EAAE,EAAE,KAAK,CAAC,KA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,IAAI,CAAC;IACd,CAAC,CACD,CAAC;IAEF,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO;QACP,KAAK,EAAE,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;QACD,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;QACrC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC;QAC5C,SAAS,CAAC,QAAQ;YACjB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACX,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The loop (docs/core-loop.md, "The loop").
|
|
3
|
+
*
|
|
4
|
+
* Ask the model what to do, run what it asked for, hand the results back, repeat
|
|
5
|
+
* until a tool accepts `finish` (decision 25). A run ends in exactly one of three
|
|
6
|
+
* ways — `done`, `parked` with a reason, or `failed` — and it writes its record as
|
|
7
|
+
* it goes: the assistant message is saved before any of its tools run, and each
|
|
8
|
+
* result right after its tool finishes, so an interruption never loses a step
|
|
9
|
+
* (decision 20).
|
|
10
|
+
*
|
|
11
|
+
* Every step is written before it happens. That is why an exception anywhere ends
|
|
12
|
+
* the run once, with `failed`, and `run_end` is still emitted: the record says how
|
|
13
|
+
* far it got, and a client that was watching is not left waiting.
|
|
14
|
+
*/
|
|
15
|
+
import type { Clock, Ids } from "./clock.js";
|
|
16
|
+
import type { RunEventListener, RunEndReason, ParkedReason } from "./events.js";
|
|
17
|
+
import { type Limits } from "./limits.js";
|
|
18
|
+
import type { JsonValue } from "./json.js";
|
|
19
|
+
import { type Validation } from "./schema.js";
|
|
20
|
+
import type { ModelSlot, Usage } from "./model.js";
|
|
21
|
+
import type { LyraError } from "./result.js";
|
|
22
|
+
import type { StorageSlot } from "./slots.js";
|
|
23
|
+
import type { Tool } from "./tool.js";
|
|
24
|
+
/** Five minutes, per docs/implementation/01-core-with-fakes.md, "Judgment calls already made". */
|
|
25
|
+
export declare const DEFAULT_TOOL_DEADLINE_MS = 300000;
|
|
26
|
+
/** One record entry is capped at 1 MiB (decision 90), because a row is 2 MB. */
|
|
27
|
+
export declare const DEFAULT_ENTRY_CAP_BYTES = 1048576;
|
|
28
|
+
/** The cap an entry has: the record's own, lowered to the storage's when that is smaller. */
|
|
29
|
+
export declare function entryCapBytes(storage: StorageSlot, requested?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* A steer or follow-up that is waiting to be written (decisions 19, 27). Its id and
|
|
32
|
+
* time are decided when it is queued, so its owner can check that the entry will
|
|
33
|
+
* fit before it promises to send it.
|
|
34
|
+
*/
|
|
35
|
+
export interface QueuedMessage {
|
|
36
|
+
id: string;
|
|
37
|
+
ts: number;
|
|
38
|
+
text: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What a run's owner may tell it while it runs. Both texts are read at the moments
|
|
42
|
+
* that keep the record paired, never on arrival: a steer at the gap before the next
|
|
43
|
+
* request, a follow-up when the run would otherwise end.
|
|
44
|
+
*/
|
|
45
|
+
export interface RunControl {
|
|
46
|
+
takeSteers(): QueuedMessage[];
|
|
47
|
+
takeFollowUps(): QueuedMessage[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The stuck safeguard (decision 25). It is on by default because a recipe has no
|
|
51
|
+
* limits unless it asks for them, and a loop that cannot make progress would spend
|
|
52
|
+
* a person's own key forever. `reminders` is how many nudges a model that stops
|
|
53
|
+
* without finishing gets; `sameFailure` is how many identical tool failures in a
|
|
54
|
+
* row stop the run.
|
|
55
|
+
*/
|
|
56
|
+
export interface StuckSettings {
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
reminders?: number;
|
|
59
|
+
sameFailure?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What a recipe's `setup` makes: the first message the model sees, and the state the
|
|
63
|
+
* run starts with. On a resume the same function runs again and the saved results
|
|
64
|
+
* are replayed through each tool's `apply` (decision 112).
|
|
65
|
+
*/
|
|
66
|
+
export interface TaskStart {
|
|
67
|
+
message: string;
|
|
68
|
+
state: unknown;
|
|
69
|
+
}
|
|
70
|
+
export interface RunConfig {
|
|
71
|
+
runId: string;
|
|
72
|
+
task: string;
|
|
73
|
+
host: string;
|
|
74
|
+
/** What the person asked for, saved as the first message when no recipe sets it. */
|
|
75
|
+
input: string;
|
|
76
|
+
/** The recipe's input as JSON, saved on the task message so a resume can rebuild. */
|
|
77
|
+
inputValue?: JsonValue;
|
|
78
|
+
/** The recipe's `setup`, when the run has one. */
|
|
79
|
+
setup?: (input: JsonValue) => TaskStart;
|
|
80
|
+
/**
|
|
81
|
+
* Checks the record's saved input against the recipe's schema before `setup` runs
|
|
82
|
+
* again. A record outlives a deploy, and an input schema can change, so the old
|
|
83
|
+
* input is not trusted just because it was ours (found in review, step 3).
|
|
84
|
+
*/
|
|
85
|
+
inputCheck?: (input: JsonValue) => Validation<JsonValue>;
|
|
86
|
+
system: string;
|
|
87
|
+
tools: readonly Tool[];
|
|
88
|
+
model: ModelSlot;
|
|
89
|
+
storage: StorageSlot;
|
|
90
|
+
clock: Clock;
|
|
91
|
+
ids: Ids;
|
|
92
|
+
/** The model a recipe names, when it names one. */
|
|
93
|
+
modelName?: string;
|
|
94
|
+
/** The model to move to when the first fails its retries (decision 58). */
|
|
95
|
+
fallbackModel?: string;
|
|
96
|
+
/** What the recipe allows before the run parks (decision 18, LIM01). */
|
|
97
|
+
limits?: Limits;
|
|
98
|
+
/** What the run's owner may steer or follow up with while it runs. */
|
|
99
|
+
control?: RunControl;
|
|
100
|
+
/** The stuck safeguard: on by default, because the default has no limits (decision 25). */
|
|
101
|
+
stuck?: StuckSettings;
|
|
102
|
+
/** The recipe this run is held to, whose pin goes in the header (decision 91). */
|
|
103
|
+
recipe?: {
|
|
104
|
+
name: string;
|
|
105
|
+
version: number;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Continue a record instead of starting one (decision 20). `by` decides what may
|
|
109
|
+
* be continued: an accident resumes on its own, everything else waits for a
|
|
110
|
+
* person (decision 23).
|
|
111
|
+
*/
|
|
112
|
+
resume?: {
|
|
113
|
+
lines: readonly string[];
|
|
114
|
+
by: "wake" | "person";
|
|
115
|
+
};
|
|
116
|
+
toolDeadlineMs?: number;
|
|
117
|
+
/** The record's entry cap. Lowered to the storage's own limit when that is smaller. */
|
|
118
|
+
entryCapBytes?: number;
|
|
119
|
+
signal?: AbortSignal;
|
|
120
|
+
onEvent?: RunEventListener;
|
|
121
|
+
}
|
|
122
|
+
export interface RunResult {
|
|
123
|
+
reason: RunEndReason;
|
|
124
|
+
parkedReason?: ParkedReason;
|
|
125
|
+
/** Which part of the reason stopped it, such as a limit's `steps` or `tokens`. */
|
|
126
|
+
parkedDetail?: string;
|
|
127
|
+
/** Summed over every reply. Cost is only carried when every reply reported one. */
|
|
128
|
+
usage: Usage;
|
|
129
|
+
/** How many times the model was asked. */
|
|
130
|
+
turns: number;
|
|
131
|
+
error?: LyraError;
|
|
132
|
+
/** The recipe's state when the run has one, live or rebuilt from the record. */
|
|
133
|
+
state?: unknown;
|
|
134
|
+
}
|
|
135
|
+
export declare function runTask(config: RunConfig): Promise<RunResult>;
|
|
136
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/core/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;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