@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.
Files changed (83) hide show
  1. package/CHANGELOG.md +179 -0
  2. package/dist/bridge/sse/mapper.d.ts +19 -0
  3. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  4. package/dist/bridge/sse/mapper.js +9 -1
  5. package/dist/bridge/sse/mapper.js.map +1 -1
  6. package/dist/contracts/schemas.d.ts +10 -10
  7. package/dist/manager/run/persistence.d.ts +26 -0
  8. package/dist/manager/run/persistence.d.ts.map +1 -1
  9. package/dist/manager/run/persistence.js +40 -0
  10. package/dist/manager/run/persistence.js.map +1 -1
  11. package/dist/public-runtime.d.ts +4 -0
  12. package/dist/public-runtime.d.ts.map +1 -1
  13. package/dist/public-runtime.js +16 -0
  14. package/dist/public-runtime.js.map +1 -1
  15. package/dist/run/drain.d.ts +194 -0
  16. package/dist/run/drain.d.ts.map +1 -0
  17. package/dist/run/drain.js +228 -0
  18. package/dist/run/drain.js.map +1 -0
  19. package/dist/run/index.d.ts +2 -0
  20. package/dist/run/index.d.ts.map +1 -1
  21. package/dist/run/index.js +1 -0
  22. package/dist/run/index.js.map +1 -1
  23. package/dist/runtime/query/events.d.ts +12 -0
  24. package/dist/runtime/query/events.d.ts.map +1 -1
  25. package/dist/runtime/query/events.js +61 -3
  26. package/dist/runtime/query/events.js.map +1 -1
  27. package/dist/runtime/query/index.d.ts +36 -0
  28. package/dist/runtime/query/index.d.ts.map +1 -1
  29. package/dist/runtime/query/index.js +32 -0
  30. package/dist/runtime/query/index.js.map +1 -1
  31. package/dist/runtime/query/resume-run.d.ts +25 -0
  32. package/dist/runtime/query/resume-run.d.ts.map +1 -1
  33. package/dist/runtime/query/resume-run.js +15 -3
  34. package/dist/runtime/query/resume-run.js.map +1 -1
  35. package/dist/store/index.d.ts +1 -1
  36. package/dist/store/index.d.ts.map +1 -1
  37. package/dist/store/index.js +1 -1
  38. package/dist/store/index.js.map +1 -1
  39. package/dist/store/run/conformance.d.ts +159 -0
  40. package/dist/store/run/conformance.d.ts.map +1 -0
  41. package/dist/store/run/conformance.js +451 -0
  42. package/dist/store/run/conformance.js.map +1 -0
  43. package/dist/store/run/disk.d.ts +30 -2
  44. package/dist/store/run/disk.d.ts.map +1 -1
  45. package/dist/store/run/disk.js +101 -0
  46. package/dist/store/run/disk.js.map +1 -1
  47. package/dist/store/run/memory.d.ts +5 -4
  48. package/dist/store/run/memory.d.ts.map +1 -1
  49. package/dist/store/run/memory.js +30 -1
  50. package/dist/store/run/memory.js.map +1 -1
  51. package/dist/types/doctor/check.d.ts +28 -2
  52. package/dist/types/doctor/check.d.ts.map +1 -1
  53. package/dist/types/run/event-cursor.d.ts +90 -0
  54. package/dist/types/run/event-cursor.d.ts.map +1 -0
  55. package/dist/types/run/event-cursor.js +47 -0
  56. package/dist/types/run/event-cursor.js.map +1 -0
  57. package/dist/types/run/events.d.ts +71 -1
  58. package/dist/types/run/events.d.ts.map +1 -1
  59. package/dist/types/run/events.js.map +1 -1
  60. package/dist/types/run/index.d.ts +1 -0
  61. package/dist/types/run/index.d.ts.map +1 -1
  62. package/dist/types/run/index.js +1 -0
  63. package/dist/types/run/index.js.map +1 -1
  64. package/dist/types/run/store.d.ts +41 -1
  65. package/dist/types/run/store.d.ts.map +1 -1
  66. package/package.json +6 -1
  67. package/src/bridge/sse/mapper.ts +28 -1
  68. package/src/manager/run/persistence.ts +43 -0
  69. package/src/public-runtime.ts +22 -0
  70. package/src/run/drain.ts +393 -0
  71. package/src/run/index.ts +3 -0
  72. package/src/runtime/query/events.ts +68 -4
  73. package/src/runtime/query/index.ts +87 -0
  74. package/src/runtime/query/resume-run.ts +67 -12
  75. package/src/store/index.ts +1 -1
  76. package/src/store/run/conformance.ts +705 -0
  77. package/src/store/run/disk.ts +106 -2
  78. package/src/store/run/memory.ts +35 -5
  79. package/src/types/doctor/check.ts +28 -2
  80. package/src/types/run/event-cursor.ts +118 -0
  81. package/src/types/run/events.ts +80 -3
  82. package/src/types/run/index.ts +1 -0
  83. 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
- | { readonly resumed: true; readonly run: Run; readonly state: RunState }
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 { scope, checkpointStore, checkpointId, pendingDecision, claimFence, ...rest } = params
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
- const run = await drainQuery({
93
- ...rest,
94
- messages: [],
95
- runId: state.runId,
96
- resumeFromCheckpoint: state.checkpointId,
97
- checkpointStore,
98
- ...(claimFence !== undefined ? { claimFence } : {}),
99
- ...(pendingDecision ? { pendingDecision } : {}),
100
- } as QueryParams)
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
  }
@@ -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'