@namzu/sdk 1.1.0 → 1.3.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 (153) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  3. package/dist/bridge/a2a/mapper.js +2 -0
  4. package/dist/bridge/a2a/mapper.js.map +1 -1
  5. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  6. package/dist/bridge/sse/mapper.js +4 -0
  7. package/dist/bridge/sse/mapper.js.map +1 -1
  8. package/dist/{runtime/query → constants}/continuation.d.ts +5 -0
  9. package/dist/constants/continuation.d.ts.map +1 -0
  10. package/dist/{runtime/query → constants}/continuation.js +5 -0
  11. package/dist/constants/continuation.js.map +1 -0
  12. package/dist/constants/index.d.ts +1 -0
  13. package/dist/constants/index.d.ts.map +1 -1
  14. package/dist/constants/index.js +1 -0
  15. package/dist/constants/index.js.map +1 -1
  16. package/dist/manager/run/persistence.d.ts +11 -0
  17. package/dist/manager/run/persistence.d.ts.map +1 -1
  18. package/dist/manager/run/persistence.js +30 -1
  19. package/dist/manager/run/persistence.js.map +1 -1
  20. package/dist/provider/__tests__/registry.test.d.ts +5 -0
  21. package/dist/provider/__tests__/registry.test.d.ts.map +1 -1
  22. package/dist/provider/__tests__/registry.test.js +186 -1
  23. package/dist/provider/__tests__/registry.test.js.map +1 -1
  24. package/dist/provider/capabilities.d.ts +27 -0
  25. package/dist/provider/capabilities.d.ts.map +1 -0
  26. package/dist/provider/capabilities.js +29 -0
  27. package/dist/provider/capabilities.js.map +1 -0
  28. package/dist/provider/index.d.ts +3 -1
  29. package/dist/provider/index.d.ts.map +1 -1
  30. package/dist/provider/index.js +2 -1
  31. package/dist/provider/index.js.map +1 -1
  32. package/dist/provider/registry.d.ts +81 -1
  33. package/dist/provider/registry.d.ts.map +1 -1
  34. package/dist/provider/registry.js +173 -7
  35. package/dist/provider/registry.js.map +1 -1
  36. package/dist/public-runtime.d.ts +3 -2
  37. package/dist/public-runtime.d.ts.map +1 -1
  38. package/dist/public-runtime.js +2 -2
  39. package/dist/public-runtime.js.map +1 -1
  40. package/dist/run/reporter.d.ts.map +1 -1
  41. package/dist/run/reporter.js +8 -0
  42. package/dist/run/reporter.js.map +1 -1
  43. package/dist/runtime/query/__tests__/capability-negotiation.test.d.ts +2 -0
  44. package/dist/runtime/query/__tests__/capability-negotiation.test.d.ts.map +1 -0
  45. package/dist/runtime/query/__tests__/capability-negotiation.test.js +184 -0
  46. package/dist/runtime/query/__tests__/capability-negotiation.test.js.map +1 -0
  47. package/dist/runtime/query/__tests__/checkpoint-store.test.d.ts +2 -0
  48. package/dist/runtime/query/__tests__/checkpoint-store.test.d.ts.map +1 -0
  49. package/dist/runtime/query/__tests__/checkpoint-store.test.js +259 -0
  50. package/dist/runtime/query/__tests__/checkpoint-store.test.js.map +1 -0
  51. package/dist/runtime/query/__tests__/checkpoint.test.js +9 -3
  52. package/dist/runtime/query/__tests__/checkpoint.test.js.map +1 -1
  53. package/dist/runtime/query/__tests__/orphan-task-turn-end.test.d.ts +2 -0
  54. package/dist/runtime/query/__tests__/orphan-task-turn-end.test.d.ts.map +1 -0
  55. package/dist/runtime/query/__tests__/orphan-task-turn-end.test.js +110 -0
  56. package/dist/runtime/query/__tests__/orphan-task-turn-end.test.js.map +1 -0
  57. package/dist/runtime/query/checkpoint.d.ts +16 -2
  58. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  59. package/dist/runtime/query/checkpoint.js +21 -7
  60. package/dist/runtime/query/checkpoint.js.map +1 -1
  61. package/dist/runtime/query/context.d.ts +7 -0
  62. package/dist/runtime/query/context.d.ts.map +1 -1
  63. package/dist/runtime/query/context.js +1 -0
  64. package/dist/runtime/query/context.js.map +1 -1
  65. package/dist/runtime/query/index.d.ts +20 -0
  66. package/dist/runtime/query/index.d.ts.map +1 -1
  67. package/dist/runtime/query/index.js +75 -6
  68. package/dist/runtime/query/index.js.map +1 -1
  69. package/dist/runtime/query/iteration/index.d.ts +3 -57
  70. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  71. package/dist/runtime/query/iteration/index.js +246 -735
  72. package/dist/runtime/query/iteration/index.js.map +1 -1
  73. package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
  74. package/dist/runtime/query/iteration/phases/checkpoint.js +22 -0
  75. package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
  76. package/dist/runtime/query/iteration/phases/context.d.ts +1 -2
  77. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  78. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  79. package/dist/runtime/query/iteration/stream-turn.d.ts +35 -0
  80. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -0
  81. package/dist/runtime/query/iteration/stream-turn.js +341 -0
  82. package/dist/runtime/query/iteration/stream-turn.js.map +1 -0
  83. package/dist/runtime/query/replay/list.d.ts +17 -1
  84. package/dist/runtime/query/replay/list.d.ts.map +1 -1
  85. package/dist/runtime/query/replay/list.js +21 -4
  86. package/dist/runtime/query/replay/list.js.map +1 -1
  87. package/dist/runtime/query/replay/prepare.d.ts +10 -0
  88. package/dist/runtime/query/replay/prepare.d.ts.map +1 -1
  89. package/dist/runtime/query/replay/prepare.js +20 -4
  90. package/dist/runtime/query/replay/prepare.js.map +1 -1
  91. package/dist/store/index.d.ts +1 -0
  92. package/dist/store/index.d.ts.map +1 -1
  93. package/dist/store/index.js +1 -0
  94. package/dist/store/index.js.map +1 -1
  95. package/dist/store/run/checkpoint-disk.d.ts +28 -0
  96. package/dist/store/run/checkpoint-disk.d.ts.map +1 -0
  97. package/dist/store/run/checkpoint-disk.js +55 -0
  98. package/dist/store/run/checkpoint-disk.js.map +1 -0
  99. package/dist/types/provider/config.d.ts +51 -0
  100. package/dist/types/provider/config.d.ts.map +1 -1
  101. package/dist/types/provider/index.d.ts +1 -1
  102. package/dist/types/provider/index.d.ts.map +1 -1
  103. package/dist/types/provider/interface.d.ts +10 -0
  104. package/dist/types/provider/interface.d.ts.map +1 -1
  105. package/dist/types/run/checkpoint-store.d.ts +64 -0
  106. package/dist/types/run/checkpoint-store.d.ts.map +1 -0
  107. package/dist/types/run/checkpoint-store.js +12 -0
  108. package/dist/types/run/checkpoint-store.js.map +1 -0
  109. package/dist/types/run/config.d.ts +27 -0
  110. package/dist/types/run/config.d.ts.map +1 -1
  111. package/dist/types/run/events.d.ts +6 -0
  112. package/dist/types/run/events.d.ts.map +1 -1
  113. package/dist/types/run/events.js.map +1 -1
  114. package/dist/types/run/index.d.ts +1 -0
  115. package/dist/types/run/index.d.ts.map +1 -1
  116. package/dist/types/run/index.js +1 -0
  117. package/dist/types/run/index.js.map +1 -1
  118. package/package.json +1 -1
  119. package/src/bridge/a2a/mapper.ts +3 -0
  120. package/src/bridge/sse/mapper.ts +5 -0
  121. package/src/{runtime/query → constants}/continuation.ts +5 -0
  122. package/src/constants/index.ts +1 -0
  123. package/src/manager/run/persistence.ts +34 -1
  124. package/src/provider/__tests__/registry.test.ts +266 -1
  125. package/src/provider/capabilities.ts +47 -0
  126. package/src/provider/index.ts +12 -1
  127. package/src/provider/registry.ts +202 -7
  128. package/src/public-runtime.ts +6 -0
  129. package/src/run/reporter.ts +9 -0
  130. package/src/runtime/query/__tests__/capability-negotiation.test.ts +248 -0
  131. package/src/runtime/query/__tests__/checkpoint-store.test.ts +322 -0
  132. package/src/runtime/query/__tests__/checkpoint.test.ts +15 -6
  133. package/src/runtime/query/__tests__/orphan-task-turn-end.test.ts +127 -0
  134. package/src/runtime/query/checkpoint.ts +23 -9
  135. package/src/runtime/query/context.ts +9 -0
  136. package/src/runtime/query/index.ts +115 -28
  137. package/src/runtime/query/iteration/index.ts +298 -905
  138. package/src/runtime/query/iteration/phases/checkpoint.ts +25 -0
  139. package/src/runtime/query/iteration/phases/context.ts +1 -3
  140. package/src/runtime/query/iteration/stream-turn.ts +396 -0
  141. package/src/runtime/query/replay/list.ts +38 -4
  142. package/src/runtime/query/replay/prepare.ts +37 -4
  143. package/src/store/index.ts +1 -0
  144. package/src/store/run/checkpoint-disk.ts +67 -0
  145. package/src/types/provider/config.ts +54 -0
  146. package/src/types/provider/index.ts +3 -0
  147. package/src/types/provider/interface.ts +11 -0
  148. package/src/types/run/checkpoint-store.ts +72 -0
  149. package/src/types/run/config.ts +30 -0
  150. package/src/types/run/events.ts +13 -0
  151. package/src/types/run/index.ts +1 -0
  152. package/dist/runtime/query/continuation.d.ts.map +0 -1
  153. package/dist/runtime/query/continuation.js.map +0 -1
@@ -35,10 +35,28 @@ export interface MockProviderConfig {
35
35
  responseDelayMs?: number
36
36
  }
37
37
 
38
+ /**
39
+ * What a provider DRIVER actually does with the request — not what the
40
+ * vendor API could theoretically support. A driver that never reads
41
+ * `params.tools` declares `supportsTools: false` even if the backing
42
+ * service has a tools endpoint; a driver that drops `attachments`
43
+ * declares `supportsVision: false` even for a multimodal model.
44
+ *
45
+ * The query runtime consults these before each run (see
46
+ * `resolveProviderCapabilities` in `provider/capabilities.ts`) so
47
+ * degradation is loud instead of silent.
48
+ */
38
49
  export interface ProviderCapabilities {
39
50
  supportsTools: boolean
40
51
  supportsStreaming: boolean
41
52
  supportsFunctionCalling: boolean
53
+ /**
54
+ * Whether the driver maps user-message image `attachments` into the
55
+ * provider request. Optional for compatibility with pre-existing
56
+ * declarations: absent ⇒ treated as vision-capable (permissive
57
+ * default — the runtime only warns when a driver explicitly says no).
58
+ */
59
+ supportsVision?: boolean
42
60
  maxOutputTokens?: number
43
61
  }
44
62
 
@@ -52,4 +70,40 @@ export interface RegisterOptions {
52
70
  replace?: boolean
53
71
  }
54
72
 
73
+ /**
74
+ * What a lazy loader must resolve to: a factory that constructs the
75
+ * provider, plus (optionally) the provider package's authoritative
76
+ * capability declaration resolved at load time.
77
+ *
78
+ * Designed so a host can map a dynamic import in one line:
79
+ *
80
+ * ```ts
81
+ * ProviderRegistry.registerLazy('anthropic', async () => {
82
+ * const m = await import('@namzu/anthropic')
83
+ * return { create: (c) => new m.AnthropicProvider(c), capabilities: m.ANTHROPIC_CAPABILITIES }
84
+ * })
85
+ * ```
86
+ */
87
+ export interface LazyProviderModule<C = unknown> {
88
+ create: (config: C) => LLMProvider
89
+ /**
90
+ * Authoritative type-level capabilities shipped by the loaded module.
91
+ * When present, replaces any registration-time hint in the registry.
92
+ */
93
+ capabilities?: ProviderCapabilities
94
+ }
95
+
96
+ export type LazyProviderLoader<C = unknown> = () => Promise<LazyProviderModule<C>>
97
+
98
+ export interface RegisterLazyOptions extends RegisterOptions {
99
+ /**
100
+ * Pre-load capability HINT so `ProviderRegistry.getCapabilities(type)`
101
+ * can answer without triggering the loader. Precedence (weakest first):
102
+ * this hint → the loaded module's `capabilities` → the constructed
103
+ * instance's own `LLMProvider.capabilities` (what the query runtime
104
+ * resolves via `resolveProviderCapabilities` and actually respects).
105
+ */
106
+ capabilities?: ProviderCapabilities
107
+ }
108
+
55
109
  export type LLMProviderConstructor<C = unknown> = new (config: C) => LLMProvider
@@ -16,5 +16,8 @@ export type {
16
16
  ProviderCapabilities,
17
17
  ProviderFactoryResult,
18
18
  RegisterOptions,
19
+ LazyProviderModule,
20
+ LazyProviderLoader,
21
+ RegisterLazyOptions,
19
22
  LLMProviderConstructor,
20
23
  } from './config.js'
@@ -1,6 +1,7 @@
1
1
  import type { DoctorCheckResult } from '../doctor/index.js'
2
2
 
3
3
  import type { ChatCompletionParams } from './chat.js'
4
+ import type { ProviderCapabilities } from './config.js'
4
5
  import type { ModelInfo } from './model.js'
5
6
  import type { StreamChunk } from './stream.js'
6
7
 
@@ -8,6 +9,16 @@ export interface LLMProvider {
8
9
  readonly id: string
9
10
  readonly name: string
10
11
 
12
+ /**
13
+ * Honest declaration of what this DRIVER does with the request
14
+ * (tools passed through? attachments mapped?) — not what the vendor
15
+ * API supports. Optional so third-party providers that predate the
16
+ * field keep working: the runtime resolves an absent declaration to
17
+ * {@link import('../../provider/capabilities.js').PERMISSIVE_PROVIDER_CAPABILITIES},
18
+ * i.e. today's behavior (assume everything works, never warn).
19
+ */
20
+ readonly capabilities?: ProviderCapabilities
21
+
11
22
  /**
12
23
  * The single LLM entry point. Returns an async iterable of
13
24
  * {@link StreamChunk} carrying text deltas, tool-call argument
@@ -0,0 +1,72 @@
1
+ /**
2
+ * CheckpointStore — persistence contract for iteration checkpoints.
3
+ *
4
+ * Mirrors the {@link import('../session/store.js').SessionStore} precedent:
5
+ * a narrow interface the kernel consumes, with the built-in disk layout as
6
+ * the default implementation and host-injected backends (e.g. Postgres) as
7
+ * drop-in replacements. Every accessor takes an explicit
8
+ * {@link CheckpointRunScope} so a shared backend can key rows by the full
9
+ * five-layer attribution (Convention #17) instead of a filesystem path.
10
+ */
11
+
12
+ import type { CheckpointId, IterationCheckpoint } from '../hitl/index.js'
13
+ import type { RunId, SessionId, TenantId } from '../ids/index.js'
14
+ import type { ProjectId } from '../session/ids.js'
15
+
16
+ /**
17
+ * Identifies the run whose checkpoints are being addressed.
18
+ *
19
+ * The full Tenant → Project → Session → Run scope is required so shared
20
+ * backends can enforce isolation; the built-in
21
+ * {@link import('../../store/run/checkpoint-disk.js').DiskCheckpointStore}
22
+ * is path-addressed (its `baseDir` already encodes project/session) and
23
+ * only consults `runId`/`parentRunId` for directory layout.
24
+ */
25
+ export interface CheckpointRunScope {
26
+ /** Isolation boundary (Convention #17). */
27
+ tenantId: TenantId
28
+ /** Long-lived goal scope the run belongs to. */
29
+ projectId: ProjectId
30
+ /** Session the run is attributed to. */
31
+ sessionId: SessionId
32
+ /** Run whose checkpoints are addressed. */
33
+ runId: RunId
34
+ /**
35
+ * Present for sub-runs. Hierarchical stores may use it for layout (the
36
+ * disk store nests sub-run directories under
37
+ * `<parentRunId>/children/<runId>`); flat stores can ignore it.
38
+ */
39
+ parentRunId?: RunId
40
+ }
41
+
42
+ /**
43
+ * Persistence contract consumed by
44
+ * {@link import('../../runtime/query/checkpoint.js').CheckpointManager} and
45
+ * the replay entry points (`listCheckpoints` / `prepareReplayState`).
46
+ *
47
+ * Read accessors return `null` / an empty array when nothing exists for the
48
+ * supplied scope — callers branch on missing explicitly, never on a thrown
49
+ * not-found error. `deleteCheckpoint` is idempotent: deleting an absent
50
+ * checkpoint succeeds as a no-op (mirrors the disk store's ENOENT
51
+ * swallowing).
52
+ */
53
+ export interface CheckpointStore {
54
+ /** Persist one checkpoint. Overwrites an existing checkpoint with the same id. */
55
+ writeCheckpoint(scope: CheckpointRunScope, checkpoint: IterationCheckpoint): Promise<void>
56
+
57
+ /** Load a single checkpoint by id. Returns `null` when it does not exist. */
58
+ readCheckpoint(
59
+ scope: CheckpointRunScope,
60
+ checkpointId: CheckpointId,
61
+ ): Promise<IterationCheckpoint | null>
62
+
63
+ /**
64
+ * All checkpoints for the run, sorted by `createdAt` ascending (the
65
+ * ordering the disk store guarantees and `CheckpointManager.prune`
66
+ * relies on for oldest-first deletion).
67
+ */
68
+ listCheckpoints(scope: CheckpointRunScope): Promise<IterationCheckpoint[]>
69
+
70
+ /** Delete a checkpoint by id. Absent checkpoints succeed as a no-op. */
71
+ deleteCheckpoint(scope: CheckpointRunScope, checkpointId: CheckpointId): Promise<void>
72
+ }
@@ -3,6 +3,7 @@ import type { Logger } from '../../utils/logger.js'
3
3
  import type { RunId, SessionId, TenantId } from '../ids/index.js'
4
4
  import type { PermissionMode } from '../permission/index.js'
5
5
  import type { ProjectId, ThreadId } from '../session/ids.js'
6
+ import type { CheckpointStore } from './checkpoint-store.js'
6
7
 
7
8
  export interface AgentRunConfig {
8
9
  model: string
@@ -19,6 +20,27 @@ export interface AgentRunConfig {
19
20
  memoryLimitMb?: number
20
21
  maxProcesses?: number
21
22
  }
23
+
24
+ /**
25
+ * Iteration-checkpoint cadence: create a checkpoint on every Nth
26
+ * tool-call iteration (iterations 1, 1+N, 1+2N, …). Default `1` —
27
+ * a checkpoint per iteration, today's behavior. Values < 1 are
28
+ * treated as 1. Off-cadence iterations also skip the HITL
29
+ * `iteration_checkpoint` park (there is no checkpoint id to park on).
30
+ * Tool-review and plan-approval checkpoints are unaffected — those
31
+ * exist to anchor a pending HITL decision, not for growth control.
32
+ */
33
+ checkpointEvery?: number
34
+
35
+ /**
36
+ * After creating an iteration checkpoint, prune the run's checkpoint
37
+ * set down to the newest N (oldest-first deletion across ALL of the
38
+ * run's checkpoints, including tool-review/plan ones). Default
39
+ * `undefined` — never prune, today's behavior. Each checkpoint copies
40
+ * the full message array, so long tool-heavy runs grow O(iterations ×
41
+ * history) without this.
42
+ */
43
+ pruneKeepLast?: number
22
44
  }
23
45
 
24
46
  /**
@@ -45,6 +67,14 @@ export interface RunPersistenceConfig {
45
67
  parentRunId?: RunId
46
68
 
47
69
  depth?: number
70
+
71
+ /**
72
+ * Optional checkpoint persistence override. Defaults to the disk
73
+ * layout under `outputDir` (a
74
+ * {@link import('../../store/run/checkpoint-disk.js').DiskCheckpointStore});
75
+ * hosts inject a scope-keyed backend (e.g. Postgres) here.
76
+ */
77
+ checkpointStore?: CheckpointStore
48
78
  }
49
79
 
50
80
  export interface RunStoreConfig {
@@ -99,6 +99,19 @@ type CoreRunEvent =
99
99
  }
100
100
  | { type: 'run_completed'; runId: RunId; result: string }
101
101
  | { type: 'run_failed'; runId: RunId; error: string }
102
+ // Additive 2026-07 (provider capability negotiation): emitted once per
103
+ // run when the request asks for something the provider DRIVER declared
104
+ // it cannot do — tools registered against a no-tools driver (tool
105
+ // surfaces stripped so the model is never told about uncallable
106
+ // tools), or image attachments against a no-vision driver (attachments
107
+ // dropped). Hosts surface these so degradation is visible, not silent.
108
+ | {
109
+ type: 'capability_warning'
110
+ runId: RunId
111
+ capability: 'tools' | 'vision'
112
+ providerId: string
113
+ message: string
114
+ }
102
115
  | {
103
116
  type: 'token_usage_updated'
104
117
  runId: RunId
@@ -1,5 +1,6 @@
1
1
  export * from './stop-reason.js'
2
2
  export * from './config.js'
3
+ export * from './checkpoint-store.js'
3
4
  export * from './entity.js'
4
5
  export * from './replay.js'
5
6
  // Domain `RunStatus` (session-hierarchy.md §4.6 state machine). Safe to
@@ -1 +0,0 @@
1
- {"version":3,"file":"continuation.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/continuation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,8BAA8B,mHACiE,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../../src/runtime/query/continuation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAC1C,2GAA2G,CAAA"}