@namzu/sdk 20.4.0 → 21.0.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/CHANGELOG.md +179 -0
- package/dist/bridge/sse/mapper.d.ts +19 -0
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +9 -1
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/contracts/schemas.d.ts +10 -10
- package/dist/manager/run/persistence.d.ts +26 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +40 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/public-runtime.d.ts +4 -0
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +16 -0
- package/dist/public-runtime.js.map +1 -1
- package/dist/run/drain.d.ts +194 -0
- package/dist/run/drain.d.ts.map +1 -0
- package/dist/run/drain.js +228 -0
- package/dist/run/drain.js.map +1 -0
- package/dist/run/index.d.ts +2 -0
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +1 -0
- package/dist/run/index.js.map +1 -1
- package/dist/runtime/query/events.d.ts +12 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +61 -3
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/index.d.ts +36 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +32 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/resume-run.d.ts +25 -0
- package/dist/runtime/query/resume-run.d.ts.map +1 -1
- package/dist/runtime/query/resume-run.js +15 -3
- package/dist/runtime/query/resume-run.js.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/run/conformance.d.ts +159 -0
- package/dist/store/run/conformance.d.ts.map +1 -0
- package/dist/store/run/conformance.js +451 -0
- package/dist/store/run/conformance.js.map +1 -0
- package/dist/store/run/disk.d.ts +30 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +101 -0
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/memory.d.ts +5 -4
- package/dist/store/run/memory.d.ts.map +1 -1
- package/dist/store/run/memory.js +30 -1
- package/dist/store/run/memory.js.map +1 -1
- package/dist/types/doctor/check.d.ts +28 -2
- package/dist/types/doctor/check.d.ts.map +1 -1
- package/dist/types/run/event-cursor.d.ts +90 -0
- package/dist/types/run/event-cursor.d.ts.map +1 -0
- package/dist/types/run/event-cursor.js +47 -0
- package/dist/types/run/event-cursor.js.map +1 -0
- package/dist/types/run/events.d.ts +71 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/store.d.ts +41 -1
- package/dist/types/run/store.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/bridge/sse/mapper.ts +28 -1
- package/src/manager/run/persistence.ts +43 -0
- package/src/public-runtime.ts +22 -0
- package/src/run/drain.ts +393 -0
- package/src/run/index.ts +3 -0
- package/src/runtime/query/events.ts +68 -4
- package/src/runtime/query/index.ts +87 -0
- package/src/runtime/query/resume-run.ts +67 -12
- package/src/store/index.ts +1 -1
- package/src/store/run/conformance.ts +705 -0
- package/src/store/run/disk.ts +106 -2
- package/src/store/run/memory.ts +35 -5
- package/src/types/doctor/check.ts +28 -2
- package/src/types/run/event-cursor.ts +118 -0
- package/src/types/run/events.ts +80 -3
- package/src/types/run/index.ts +1 -0
- package/src/types/run/store.ts +43 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PendingDecision } from '../../types/hitl/index.js'
|
|
2
2
|
import type { CheckpointStore, ClaimFence } from '../../types/run/checkpoint-store.js'
|
|
3
3
|
import type { Run } from '../../types/run/entity.js'
|
|
4
|
+
import type { RunEventReplay } from '../../types/run/event-cursor.js'
|
|
5
|
+
import type { RunEventListener } from '../../types/run/events.js'
|
|
4
6
|
import type { RunState } from '../../types/run/state.js'
|
|
5
7
|
import { type QueryParams, drainQuery } from './index.js'
|
|
6
8
|
import { type RunStateScope, loadRunState } from './run-state.js'
|
|
@@ -23,7 +25,21 @@ export type ResumeOutcome =
|
|
|
23
25
|
readonly pending: PendingDecision
|
|
24
26
|
readonly state: RunState
|
|
25
27
|
}
|
|
26
|
-
| {
|
|
28
|
+
| {
|
|
29
|
+
readonly resumed: true
|
|
30
|
+
readonly run: Run
|
|
31
|
+
readonly state: RunState
|
|
32
|
+
/**
|
|
33
|
+
* What became of {@link ResumeRunParams.eventCursor}. Absent when no
|
|
34
|
+
* cursor was supplied.
|
|
35
|
+
*
|
|
36
|
+
* Reported rather than thrown: a stale cursor is the client's
|
|
37
|
+
* problem and the run still had to be resumed. A caller that sees
|
|
38
|
+
* `unavailable` re-derives its view from the run's transcript
|
|
39
|
+
* instead of folding a hole into it.
|
|
40
|
+
*/
|
|
41
|
+
readonly replay?: RunEventReplay
|
|
42
|
+
}
|
|
27
43
|
|
|
28
44
|
/**
|
|
29
45
|
* The half of a run that cannot be serialized, plus where to look.
|
|
@@ -52,6 +68,20 @@ export interface ResumeRunParams
|
|
|
52
68
|
* Absent means the parked checkpoint if there is one, else the newest.
|
|
53
69
|
*/
|
|
54
70
|
readonly checkpointId?: RunState['checkpointId']
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Where to send the resumed run's events.
|
|
74
|
+
*
|
|
75
|
+
* This call had none, and the consequence was total: it drains the run to
|
|
76
|
+
* completion and every event the run emits — every tool call, every park,
|
|
77
|
+
* every token update — was discarded, because `drainQuery` forwards to a
|
|
78
|
+
* listener and none was ever passed. So the one API for continuing a run
|
|
79
|
+
* another process started could not show anybody what the run was doing.
|
|
80
|
+
*
|
|
81
|
+
* It is also what makes {@link ResumeRunParams.eventCursor} mean anything:
|
|
82
|
+
* a catch-up delivered into a stream nobody receives is not a catch-up.
|
|
83
|
+
*/
|
|
84
|
+
readonly listener?: RunEventListener
|
|
55
85
|
}
|
|
56
86
|
|
|
57
87
|
/**
|
|
@@ -76,7 +106,16 @@ export interface ResumeRunParams
|
|
|
76
106
|
* resumed past without the answer it is waiting for.
|
|
77
107
|
*/
|
|
78
108
|
export async function resumeRun(params: ResumeRunParams): Promise<ResumeOutcome> {
|
|
79
|
-
const {
|
|
109
|
+
const {
|
|
110
|
+
scope,
|
|
111
|
+
checkpointStore,
|
|
112
|
+
checkpointId,
|
|
113
|
+
pendingDecision,
|
|
114
|
+
claimFence,
|
|
115
|
+
listener,
|
|
116
|
+
onEventReplay,
|
|
117
|
+
...rest
|
|
118
|
+
} = params
|
|
80
119
|
|
|
81
120
|
const state = await loadRunState(checkpointStore, scope, checkpointId)
|
|
82
121
|
if (!state?.checkpointId) return { resumed: false, reason: 'no-checkpoint' }
|
|
@@ -89,15 +128,31 @@ export async function resumeRun(params: ResumeRunParams): Promise<ResumeOutcome>
|
|
|
89
128
|
return { resumed: false, reason: 'awaiting-decision', pending: outstanding, state }
|
|
90
129
|
}
|
|
91
130
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
let replay: RunEventReplay | undefined
|
|
132
|
+
|
|
133
|
+
const run = await drainQuery(
|
|
134
|
+
{
|
|
135
|
+
...rest,
|
|
136
|
+
messages: [],
|
|
137
|
+
runId: state.runId,
|
|
138
|
+
// Forwarded, and it is not cosmetic: the run store nests a sub-run's
|
|
139
|
+
// evidence under `<parent>/children/<run>`, so resuming a sub-run
|
|
140
|
+
// without this binds `<base>/<run>` instead — a second, empty
|
|
141
|
+
// transcript under a run id that already has one, a sequence that
|
|
142
|
+
// restarts at 1, and a catch-up that reports a live run as having
|
|
143
|
+
// produced nothing.
|
|
144
|
+
...(state.parentRunId !== undefined ? { parentRunId: state.parentRunId } : {}),
|
|
145
|
+
resumeFromCheckpoint: state.checkpointId,
|
|
146
|
+
checkpointStore,
|
|
147
|
+
...(claimFence !== undefined ? { claimFence } : {}),
|
|
148
|
+
...(pendingDecision ? { pendingDecision } : {}),
|
|
149
|
+
onEventReplay: (verdict: RunEventReplay) => {
|
|
150
|
+
replay = verdict
|
|
151
|
+
onEventReplay?.(verdict)
|
|
152
|
+
},
|
|
153
|
+
} as QueryParams,
|
|
154
|
+
listener,
|
|
155
|
+
)
|
|
101
156
|
|
|
102
|
-
return { resumed: true, run, state }
|
|
157
|
+
return { resumed: true, run, state, ...(replay !== undefined ? { replay } : {}) }
|
|
103
158
|
}
|
package/src/store/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { InMemoryStore } from './InMemoryStore.js'
|
|
2
2
|
export type { Identifiable, Timestamped } from './InMemoryStore.js'
|
|
3
3
|
|
|
4
|
-
export { RunDiskStore } from './run/disk.js'
|
|
4
|
+
export { RunDiskStore, readRunEventsIn } from './run/disk.js'
|
|
5
5
|
export { InMemoryRunStore } from './run/memory.js'
|
|
6
6
|
export { DiskCheckpointStore } from './run/checkpoint-disk.js'
|
|
7
7
|
export type { DiskCheckpointStoreAttribution } from './run/checkpoint-disk.js'
|