@zhixuan92/multi-model-agent-core 0.1.1 → 0.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 (82) hide show
  1. package/README.md +0 -6
  2. package/dist/config/schema.d.ts +73 -45
  3. package/dist/config/schema.d.ts.map +1 -1
  4. package/dist/config/schema.js +14 -0
  5. package/dist/config/schema.js.map +1 -1
  6. package/dist/context/context-block-store.d.ts +75 -0
  7. package/dist/context/context-block-store.d.ts.map +1 -0
  8. package/dist/context/context-block-store.js +82 -0
  9. package/dist/context/context-block-store.js.map +1 -0
  10. package/dist/context/expand-context-blocks.d.ts +20 -0
  11. package/dist/context/expand-context-blocks.d.ts.map +1 -0
  12. package/dist/context/expand-context-blocks.js +46 -0
  13. package/dist/context/expand-context-blocks.js.map +1 -0
  14. package/dist/delegate-with-escalation.d.ts +34 -0
  15. package/dist/delegate-with-escalation.d.ts.map +1 -0
  16. package/dist/delegate-with-escalation.js +172 -0
  17. package/dist/delegate-with-escalation.js.map +1 -0
  18. package/dist/index.d.ts +4 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/model-profiles.json +42 -4
  23. package/dist/provider.d.ts.map +1 -1
  24. package/dist/provider.js +7 -1
  25. package/dist/provider.js.map +1 -1
  26. package/dist/routing/model-profiles.d.ts +9 -4
  27. package/dist/routing/model-profiles.d.ts.map +1 -1
  28. package/dist/routing/model-profiles.js +8 -0
  29. package/dist/routing/model-profiles.js.map +1 -1
  30. package/dist/run-tasks.d.ts +26 -2
  31. package/dist/run-tasks.d.ts.map +1 -1
  32. package/dist/run-tasks.js +61 -19
  33. package/dist/run-tasks.js.map +1 -1
  34. package/dist/runners/claude-runner.d.ts.map +1 -1
  35. package/dist/runners/claude-runner.js +721 -32
  36. package/dist/runners/claude-runner.js.map +1 -1
  37. package/dist/runners/codex-runner.d.ts.map +1 -1
  38. package/dist/runners/codex-runner.js +541 -48
  39. package/dist/runners/codex-runner.js.map +1 -1
  40. package/dist/runners/error-classification.d.ts +30 -0
  41. package/dist/runners/error-classification.d.ts.map +1 -0
  42. package/dist/runners/error-classification.js +72 -0
  43. package/dist/runners/error-classification.js.map +1 -0
  44. package/dist/runners/injection-type.d.ts +22 -0
  45. package/dist/runners/injection-type.d.ts.map +1 -0
  46. package/dist/runners/injection-type.js +34 -0
  47. package/dist/runners/injection-type.js.map +1 -0
  48. package/dist/runners/openai-runner.d.ts +5 -0
  49. package/dist/runners/openai-runner.d.ts.map +1 -1
  50. package/dist/runners/openai-runner.js +608 -36
  51. package/dist/runners/openai-runner.js.map +1 -1
  52. package/dist/runners/prevention.d.ts +41 -0
  53. package/dist/runners/prevention.d.ts.map +1 -0
  54. package/dist/runners/prevention.js +68 -0
  55. package/dist/runners/prevention.js.map +1 -0
  56. package/dist/runners/supervision.d.ts +137 -0
  57. package/dist/runners/supervision.d.ts.map +1 -0
  58. package/dist/runners/supervision.js +345 -0
  59. package/dist/runners/supervision.js.map +1 -0
  60. package/dist/tools/claude-adapter.d.ts.map +1 -1
  61. package/dist/tools/claude-adapter.js +6 -3
  62. package/dist/tools/claude-adapter.js.map +1 -1
  63. package/dist/tools/definitions.d.ts +3 -1
  64. package/dist/tools/definitions.d.ts.map +1 -1
  65. package/dist/tools/definitions.js +57 -5
  66. package/dist/tools/definitions.js.map +1 -1
  67. package/dist/tools/openai-adapter.d.ts.map +1 -1
  68. package/dist/tools/openai-adapter.js +6 -3
  69. package/dist/tools/openai-adapter.js.map +1 -1
  70. package/dist/tools/scratchpad.d.ts +28 -0
  71. package/dist/tools/scratchpad.d.ts.map +1 -0
  72. package/dist/tools/scratchpad.js +49 -0
  73. package/dist/tools/scratchpad.js.map +1 -0
  74. package/dist/tools/tracker.d.ts +42 -2
  75. package/dist/tools/tracker.d.ts.map +1 -1
  76. package/dist/tools/tracker.js +63 -5
  77. package/dist/tools/tracker.js.map +1 -1
  78. package/dist/types.d.ts +261 -2
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js +43 -1
  81. package/dist/types.js.map +1 -1
  82. package/package.json +7 -3
package/README.md CHANGED
@@ -10,12 +10,6 @@ This is the building-block library. If you just want to run the MCP server, inst
10
10
  npm install @zhixuan92/multi-model-agent-core
11
11
  ```
12
12
 
13
- If you plan to use `openai-compatible` providers, also install the optional peer dependencies:
14
-
15
- ```bash
16
- npm install @openai/agents openai
17
- ```
18
-
19
13
  Requires Node `>= 22`. ESM only.
20
14
 
21
15
  ## What's exported
@@ -4,10 +4,10 @@ export declare const codexProviderConfigSchema: z.ZodObject<{
4
4
  type: z.ZodLiteral<"codex">;
5
5
  model: z.ZodString;
6
6
  effort: z.ZodOptional<z.ZodEnum<{
7
- none: "none";
8
- low: "low";
9
- medium: "medium";
10
7
  high: "high";
8
+ medium: "medium";
9
+ low: "low";
10
+ none: "none";
11
11
  }>>;
12
12
  maxTurns: z.ZodOptional<z.ZodNumber>;
13
13
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -21,20 +21,23 @@ export declare const codexProviderConfigSchema: z.ZodObject<{
21
21
  code_interpreter: "code_interpreter";
22
22
  }>>>;
23
23
  costTier: z.ZodOptional<z.ZodEnum<{
24
- low: "low";
25
- medium: "medium";
26
24
  high: "high";
25
+ medium: "medium";
26
+ low: "low";
27
27
  free: "free";
28
28
  }>>;
29
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
30
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
31
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
29
32
  }, z.core.$strip>;
30
33
  export declare const claudeProviderConfigSchema: z.ZodObject<{
31
34
  type: z.ZodLiteral<"claude">;
32
35
  model: z.ZodString;
33
36
  effort: z.ZodOptional<z.ZodEnum<{
34
- none: "none";
35
- low: "low";
36
- medium: "medium";
37
37
  high: "high";
38
+ medium: "medium";
39
+ low: "low";
40
+ none: "none";
38
41
  }>>;
39
42
  maxTurns: z.ZodOptional<z.ZodNumber>;
40
43
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -48,11 +51,14 @@ export declare const claudeProviderConfigSchema: z.ZodObject<{
48
51
  code_interpreter: "code_interpreter";
49
52
  }>>>;
50
53
  costTier: z.ZodOptional<z.ZodEnum<{
51
- low: "low";
52
- medium: "medium";
53
54
  high: "high";
55
+ medium: "medium";
56
+ low: "low";
54
57
  free: "free";
55
58
  }>>;
59
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
60
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
61
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
56
62
  }, z.core.$strip>;
57
63
  export declare const openAICompatibleProviderConfigSchema: z.ZodObject<{
58
64
  type: z.ZodLiteral<"openai-compatible">;
@@ -61,10 +67,10 @@ export declare const openAICompatibleProviderConfigSchema: z.ZodObject<{
61
67
  apiKey: z.ZodOptional<z.ZodString>;
62
68
  apiKeyEnv: z.ZodOptional<z.ZodString>;
63
69
  effort: z.ZodOptional<z.ZodEnum<{
64
- none: "none";
65
- low: "low";
66
- medium: "medium";
67
70
  high: "high";
71
+ medium: "medium";
72
+ low: "low";
73
+ none: "none";
68
74
  }>>;
69
75
  maxTurns: z.ZodOptional<z.ZodNumber>;
70
76
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -78,20 +84,23 @@ export declare const openAICompatibleProviderConfigSchema: z.ZodObject<{
78
84
  code_interpreter: "code_interpreter";
79
85
  }>>>;
80
86
  costTier: z.ZodOptional<z.ZodEnum<{
81
- low: "low";
82
- medium: "medium";
83
87
  high: "high";
88
+ medium: "medium";
89
+ low: "low";
84
90
  free: "free";
85
91
  }>>;
92
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
93
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
94
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
86
95
  }, z.core.$strip>;
87
96
  export declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
88
97
  type: z.ZodLiteral<"codex">;
89
98
  model: z.ZodString;
90
99
  effort: z.ZodOptional<z.ZodEnum<{
91
- none: "none";
92
- low: "low";
93
- medium: "medium";
94
100
  high: "high";
101
+ medium: "medium";
102
+ low: "low";
103
+ none: "none";
95
104
  }>>;
96
105
  maxTurns: z.ZodOptional<z.ZodNumber>;
97
106
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -105,19 +114,22 @@ export declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
105
114
  code_interpreter: "code_interpreter";
106
115
  }>>>;
107
116
  costTier: z.ZodOptional<z.ZodEnum<{
108
- low: "low";
109
- medium: "medium";
110
117
  high: "high";
118
+ medium: "medium";
119
+ low: "low";
111
120
  free: "free";
112
121
  }>>;
122
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
123
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
124
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
113
125
  }, z.core.$strip>, z.ZodObject<{
114
126
  type: z.ZodLiteral<"claude">;
115
127
  model: z.ZodString;
116
128
  effort: z.ZodOptional<z.ZodEnum<{
117
- none: "none";
118
- low: "low";
119
- medium: "medium";
120
129
  high: "high";
130
+ medium: "medium";
131
+ low: "low";
132
+ none: "none";
121
133
  }>>;
122
134
  maxTurns: z.ZodOptional<z.ZodNumber>;
123
135
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -131,11 +143,14 @@ export declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
131
143
  code_interpreter: "code_interpreter";
132
144
  }>>>;
133
145
  costTier: z.ZodOptional<z.ZodEnum<{
134
- low: "low";
135
- medium: "medium";
136
146
  high: "high";
147
+ medium: "medium";
148
+ low: "low";
137
149
  free: "free";
138
150
  }>>;
151
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
152
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
153
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
139
154
  }, z.core.$strip>, z.ZodObject<{
140
155
  type: z.ZodLiteral<"openai-compatible">;
141
156
  model: z.ZodString;
@@ -143,10 +158,10 @@ export declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
143
158
  apiKey: z.ZodOptional<z.ZodString>;
144
159
  apiKeyEnv: z.ZodOptional<z.ZodString>;
145
160
  effort: z.ZodOptional<z.ZodEnum<{
146
- none: "none";
147
- low: "low";
148
- medium: "medium";
149
161
  high: "high";
162
+ medium: "medium";
163
+ low: "low";
164
+ none: "none";
150
165
  }>>;
151
166
  maxTurns: z.ZodOptional<z.ZodNumber>;
152
167
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -160,21 +175,24 @@ export declare const providerConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
160
175
  code_interpreter: "code_interpreter";
161
176
  }>>>;
162
177
  costTier: z.ZodOptional<z.ZodEnum<{
163
- low: "low";
164
- medium: "medium";
165
178
  high: "high";
179
+ medium: "medium";
180
+ low: "low";
166
181
  free: "free";
167
182
  }>>;
183
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
184
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
185
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
168
186
  }, z.core.$strip>], "type">;
169
187
  export declare const multiModelConfigSchema: z.ZodObject<{
170
188
  providers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
171
189
  type: z.ZodLiteral<"codex">;
172
190
  model: z.ZodString;
173
191
  effort: z.ZodOptional<z.ZodEnum<{
174
- none: "none";
175
- low: "low";
176
- medium: "medium";
177
192
  high: "high";
193
+ medium: "medium";
194
+ low: "low";
195
+ none: "none";
178
196
  }>>;
179
197
  maxTurns: z.ZodOptional<z.ZodNumber>;
180
198
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -188,19 +206,22 @@ export declare const multiModelConfigSchema: z.ZodObject<{
188
206
  code_interpreter: "code_interpreter";
189
207
  }>>>;
190
208
  costTier: z.ZodOptional<z.ZodEnum<{
191
- low: "low";
192
- medium: "medium";
193
209
  high: "high";
210
+ medium: "medium";
211
+ low: "low";
194
212
  free: "free";
195
213
  }>>;
214
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
215
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
216
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
196
217
  }, z.core.$strip>, z.ZodObject<{
197
218
  type: z.ZodLiteral<"claude">;
198
219
  model: z.ZodString;
199
220
  effort: z.ZodOptional<z.ZodEnum<{
200
- none: "none";
201
- low: "low";
202
- medium: "medium";
203
221
  high: "high";
222
+ medium: "medium";
223
+ low: "low";
224
+ none: "none";
204
225
  }>>;
205
226
  maxTurns: z.ZodOptional<z.ZodNumber>;
206
227
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -214,11 +235,14 @@ export declare const multiModelConfigSchema: z.ZodObject<{
214
235
  code_interpreter: "code_interpreter";
215
236
  }>>>;
216
237
  costTier: z.ZodOptional<z.ZodEnum<{
217
- low: "low";
218
- medium: "medium";
219
238
  high: "high";
239
+ medium: "medium";
240
+ low: "low";
220
241
  free: "free";
221
242
  }>>;
243
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
244
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
245
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
222
246
  }, z.core.$strip>, z.ZodObject<{
223
247
  type: z.ZodLiteral<"openai-compatible">;
224
248
  model: z.ZodString;
@@ -226,10 +250,10 @@ export declare const multiModelConfigSchema: z.ZodObject<{
226
250
  apiKey: z.ZodOptional<z.ZodString>;
227
251
  apiKeyEnv: z.ZodOptional<z.ZodString>;
228
252
  effort: z.ZodOptional<z.ZodEnum<{
229
- none: "none";
230
- low: "low";
231
- medium: "medium";
232
253
  high: "high";
254
+ medium: "medium";
255
+ low: "low";
256
+ none: "none";
233
257
  }>>;
234
258
  maxTurns: z.ZodOptional<z.ZodNumber>;
235
259
  timeoutMs: z.ZodOptional<z.ZodNumber>;
@@ -243,11 +267,14 @@ export declare const multiModelConfigSchema: z.ZodObject<{
243
267
  code_interpreter: "code_interpreter";
244
268
  }>>>;
245
269
  costTier: z.ZodOptional<z.ZodEnum<{
246
- low: "low";
247
- medium: "medium";
248
270
  high: "high";
271
+ medium: "medium";
272
+ low: "low";
249
273
  free: "free";
250
274
  }>>;
275
+ inputCostPerMTok: z.ZodOptional<z.ZodNumber>;
276
+ outputCostPerMTok: z.ZodOptional<z.ZodNumber>;
277
+ inputTokenSoftLimit: z.ZodOptional<z.ZodNumber>;
251
278
  }, z.core.$strip>], "type">>>;
252
279
  defaults: z.ZodDefault<z.ZodObject<{
253
280
  maxTurns: z.ZodDefault<z.ZodNumber>;
@@ -256,6 +283,7 @@ export declare const multiModelConfigSchema: z.ZodObject<{
256
283
  none: "none";
257
284
  full: "full";
258
285
  }>>;
286
+ largeResponseThresholdChars: z.ZodOptional<z.ZodNumber>;
259
287
  }, z.core.$strip>>;
260
288
  }, z.core.$strip>;
261
289
  export interface ParsedConfigSuccess {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAGV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AASrB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;iBASpC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;iBASrC,CAAC;AAEH,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAY/C,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC;AAEH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,CAAA;IACxB,OAAO,EAAE,IAAI,CAAA;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG,mBAAmB,CAAA;AAEzE;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAE1D"}
@@ -4,6 +4,10 @@ const effortSchema = z.enum(['none', 'low', 'medium', 'high']);
4
4
  const costTierSchema = z.enum(['free', 'low', 'medium', 'high']);
5
5
  const hostedToolsSchema = z.array(z.enum(['web_search', 'image_generation', 'code_interpreter']));
6
6
  const sandboxPolicySchema = z.enum(['none', 'cwd-only']).optional();
7
+ // Per-million-token pricing for cost computation. Must be non-negative; zero
8
+ // is allowed (free providers can set both rates to 0 to get a deterministic
9
+ // costUSD: 0 instead of null).
10
+ const tokenCostSchema = z.number().nonnegative().finite().optional();
7
11
  export const codexProviderConfigSchema = z.object({
8
12
  type: z.literal('codex'),
9
13
  model: z.string(),
@@ -13,6 +17,9 @@ export const codexProviderConfigSchema = z.object({
13
17
  sandboxPolicy: sandboxPolicySchema,
14
18
  hostedTools: hostedToolsSchema.optional(),
15
19
  costTier: costTierSchema.optional(),
20
+ inputCostPerMTok: tokenCostSchema,
21
+ outputCostPerMTok: tokenCostSchema,
22
+ inputTokenSoftLimit: z.number().int().positive().optional(),
16
23
  });
17
24
  export const claudeProviderConfigSchema = z.object({
18
25
  type: z.literal('claude'),
@@ -23,6 +30,9 @@ export const claudeProviderConfigSchema = z.object({
23
30
  sandboxPolicy: sandboxPolicySchema,
24
31
  hostedTools: hostedToolsSchema.optional(),
25
32
  costTier: costTierSchema.optional(),
33
+ inputCostPerMTok: tokenCostSchema,
34
+ outputCostPerMTok: tokenCostSchema,
35
+ inputTokenSoftLimit: z.number().int().positive().optional(),
26
36
  });
27
37
  export const openAICompatibleProviderConfigSchema = z.object({
28
38
  type: z.literal('openai-compatible'),
@@ -36,6 +46,9 @@ export const openAICompatibleProviderConfigSchema = z.object({
36
46
  sandboxPolicy: sandboxPolicySchema,
37
47
  hostedTools: hostedToolsSchema.optional(),
38
48
  costTier: costTierSchema.optional(),
49
+ inputCostPerMTok: tokenCostSchema,
50
+ outputCostPerMTok: tokenCostSchema,
51
+ inputTokenSoftLimit: z.number().int().positive().optional(),
39
52
  });
40
53
  export const providerConfigSchema = z.discriminatedUnion('type', [
41
54
  codexProviderConfigSchema,
@@ -47,6 +60,7 @@ const defaultsSchema = z.object({
47
60
  maxTurns: z.number().int().positive().default(200),
48
61
  timeoutMs: z.number().int().positive().default(600_000),
49
62
  tools: z.enum(['none', 'full']).default('full'),
63
+ largeResponseThresholdChars: z.number().int().positive().optional(),
50
64
  }).default(() => ({ maxTurns: 200, timeoutMs: 600_000, tools: 'full' }));
51
65
  export const multiModelConfigSchema = z.object({
52
66
  providers: z.record(z.string(), providerConfigSchema).default({}),
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,mCAAmC;AAEnC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/D,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACjE,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAClG,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAA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,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;IAClD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IACvD,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAC/C,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACpE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAe,EAAE,CAAC,CAAC,CAAC;AAElF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACjE,QAAQ,EAAE,cAAc;CACzB,CAAC,CAAC;AAcH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Metadata describing a successful `register(...)` call. The orchestrator
3
+ * and MCP tool surfaces return this to the caller so they can reference
4
+ * the stored block later (by id) and independently verify its content
5
+ * (via sha256).
6
+ */
7
+ export interface RegisteredBlock {
8
+ id: string;
9
+ lengthChars: number;
10
+ sha256: string;
11
+ }
12
+ /**
13
+ * Minimal store contract for reusable context blocks.
14
+ *
15
+ * The intent is to let a caller register a large brief once, then reference
16
+ * it by id from many subsequent dispatches without re-transmitting the
17
+ * content on every call. See `expandContextBlocks` for the resolution
18
+ * step that turns `TaskSpec.contextBlockIds` into prompt text.
19
+ */
20
+ export interface ContextBlockStore {
21
+ /** Store `content` under an explicit id (idempotent replace) or a new
22
+ * UUID. Returns the id, length, and sha256 hash. */
23
+ register(content: string, opts?: {
24
+ id?: string;
25
+ }): RegisteredBlock;
26
+ /** Fetch content by id. Returns `undefined` if the id is unknown or
27
+ * the entry has expired. Touches the LRU access time on success. */
28
+ get(id: string): string | undefined;
29
+ /** Delete an entry. Returns `true` if the entry existed. */
30
+ delete(id: string): boolean;
31
+ }
32
+ /**
33
+ * Thrown by `expandContextBlocks` when a task references a block id that
34
+ * cannot be resolved against the store (missing, expired, or evicted).
35
+ * Callers are expected to surface this to the user so they can re-register
36
+ * the block and retry.
37
+ */
38
+ export declare class ContextBlockNotFoundError extends Error {
39
+ readonly id: string;
40
+ constructor(id: string);
41
+ }
42
+ export interface InMemoryContextBlockStoreOptions {
43
+ /** TTL in milliseconds. Defaults to 30 minutes. */
44
+ ttlMs?: number;
45
+ /** Max number of entries before LRU eviction. Defaults to 100. */
46
+ maxEntries?: number;
47
+ }
48
+ /**
49
+ * In-memory implementation with two bounds:
50
+ * 1. A TTL (time-to-live) from `addedAtMs` — checked lazily on `get`.
51
+ * 2. An LRU cap on entry count — enforced eagerly after every `register`.
52
+ *
53
+ * Both bounds are intentional: the TTL prevents stale briefs from lingering
54
+ * after a long-running session; the LRU cap prevents memory growth from a
55
+ * chatty caller that never explicitly deletes anything. The eviction loop
56
+ * is O(n) per insertion but `n <= maxEntries` (defaults to 100), so we
57
+ * keep the implementation simple.
58
+ *
59
+ * `Date.now()` is read directly (not through a clock abstraction) so tests
60
+ * can drive time forward with Vitest's fake timers.
61
+ */
62
+ export declare class InMemoryContextBlockStore implements ContextBlockStore {
63
+ private entries;
64
+ private ttlMs;
65
+ private maxEntries;
66
+ private tick;
67
+ constructor(opts?: InMemoryContextBlockStoreOptions);
68
+ register(content: string, opts?: {
69
+ id?: string;
70
+ }): RegisteredBlock;
71
+ get(id: string): string | undefined;
72
+ delete(id: string): boolean;
73
+ private evictIfOverBound;
74
+ }
75
+ //# sourceMappingURL=context-block-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-block-store.d.ts","sourceRoot":"","sources":["../../src/context/context-block-store.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC;yDACqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,CAAC;IACnE;yEACqE;IACrE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC,4DAA4D;IAC5D,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;aACtB,EAAE,EAAE,MAAM;gBAAV,EAAE,EAAE,MAAM;CAIvC;AAcD,MAAM,WAAW,gCAAgC;IAC/C,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAK;gBAEL,IAAI,GAAE,gCAAqC;IAKvD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,eAAe;IAYtE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAYnC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B,OAAO,CAAC,gBAAgB;CAczB"}
@@ -0,0 +1,82 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ /**
3
+ * Thrown by `expandContextBlocks` when a task references a block id that
4
+ * cannot be resolved against the store (missing, expired, or evicted).
5
+ * Callers are expected to surface this to the user so they can re-register
6
+ * the block and retry.
7
+ */
8
+ export class ContextBlockNotFoundError extends Error {
9
+ id;
10
+ constructor(id) {
11
+ super(`context block "${id}" is unknown or expired`);
12
+ this.id = id;
13
+ this.name = 'ContextBlockNotFoundError';
14
+ }
15
+ }
16
+ /**
17
+ * In-memory implementation with two bounds:
18
+ * 1. A TTL (time-to-live) from `addedAtMs` — checked lazily on `get`.
19
+ * 2. An LRU cap on entry count — enforced eagerly after every `register`.
20
+ *
21
+ * Both bounds are intentional: the TTL prevents stale briefs from lingering
22
+ * after a long-running session; the LRU cap prevents memory growth from a
23
+ * chatty caller that never explicitly deletes anything. The eviction loop
24
+ * is O(n) per insertion but `n <= maxEntries` (defaults to 100), so we
25
+ * keep the implementation simple.
26
+ *
27
+ * `Date.now()` is read directly (not through a clock abstraction) so tests
28
+ * can drive time forward with Vitest's fake timers.
29
+ */
30
+ export class InMemoryContextBlockStore {
31
+ entries = new Map();
32
+ ttlMs;
33
+ maxEntries;
34
+ tick = 0;
35
+ constructor(opts = {}) {
36
+ this.ttlMs = opts.ttlMs ?? 30 * 60 * 1000;
37
+ this.maxEntries = opts.maxEntries ?? 100;
38
+ }
39
+ register(content, opts = {}) {
40
+ const id = opts.id ?? randomUUID();
41
+ const now = Date.now();
42
+ this.entries.set(id, { content, addedAtMs: now, lastAccessTick: ++this.tick });
43
+ this.evictIfOverBound();
44
+ return {
45
+ id,
46
+ lengthChars: content.length,
47
+ sha256: createHash('sha256').update(content).digest('hex'),
48
+ };
49
+ }
50
+ get(id) {
51
+ const entry = this.entries.get(id);
52
+ if (!entry)
53
+ return undefined;
54
+ const now = Date.now();
55
+ if (now - entry.addedAtMs > this.ttlMs) {
56
+ this.entries.delete(id);
57
+ return undefined;
58
+ }
59
+ entry.lastAccessTick = ++this.tick;
60
+ return entry.content;
61
+ }
62
+ delete(id) {
63
+ return this.entries.delete(id);
64
+ }
65
+ evictIfOverBound() {
66
+ while (this.entries.size > this.maxEntries) {
67
+ let oldestId;
68
+ let oldestTick = Infinity;
69
+ for (const [id, entry] of this.entries) {
70
+ if (entry.lastAccessTick < oldestTick) {
71
+ oldestTick = entry.lastAccessTick;
72
+ oldestId = id;
73
+ }
74
+ }
75
+ if (oldestId)
76
+ this.entries.delete(oldestId);
77
+ else
78
+ break;
79
+ }
80
+ }
81
+ }
82
+ //# sourceMappingURL=context-block-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-block-store.js","sourceRoot":"","sources":["../../src/context/context-block-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiCrD;;;;;GAKG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACtB;IAA5B,YAA4B,EAAU;QACpC,KAAK,CAAC,kBAAkB,EAAE,yBAAyB,CAAC,CAAC;QAD3B,OAAE,GAAF,EAAE,CAAQ;QAEpC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAqBD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,yBAAyB;IAC5B,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACnC,KAAK,CAAS;IACd,UAAU,CAAS;IACnB,IAAI,GAAG,CAAC,CAAC;IAEjB,YAAY,OAAyC,EAAE;QACrD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,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B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,QAA4B,CAAC;YACjC,IAAI,UAAU,GAAG,QAAQ,CAAC;YAC1B,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACvC,IAAI,KAAK,CAAC,cAAc,GAAG,UAAU,EAAE,CAAC;oBACtC,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC;oBAClC,QAAQ,GAAG,EAAE,CAAC;gBAChB,CAAC;YACH,CAAC;YACD,IAAI,QAAQ;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;;gBACvC,MAAM;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { type ContextBlockStore } from './context-block-store.js';
2
+ import type { TaskSpec } from '../types.js';
3
+ /**
4
+ * Expands a task's `contextBlockIds` against a `ContextBlockStore`,
5
+ * returning a NEW `TaskSpec` whose `prompt` has the resolved blocks
6
+ * prepended (in the order they appear in `contextBlockIds`) with
7
+ * `SEPARATOR` between each block and before the original prompt.
8
+ *
9
+ * The returned task has `contextBlockIds` removed so downstream code
10
+ * cannot accidentally double-expand.
11
+ *
12
+ * If the task has no `contextBlockIds` (or the array is empty), or if
13
+ * no store is provided, the task is returned unchanged — the caller
14
+ * does not have to special-case the no-op path.
15
+ *
16
+ * Throws `ContextBlockNotFoundError` synchronously on the first missing
17
+ * id so the caller gets a clear error pointing to the offending block.
18
+ */
19
+ export declare function expandContextBlocks(task: TaskSpec, store: ContextBlockStore | undefined): TaskSpec;
20
+ //# sourceMappingURL=expand-context-blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expand-context-blocks.d.ts","sourceRoot":"","sources":["../../src/context/expand-context-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAU5C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,iBAAiB,GAAG,SAAS,GACnC,QAAQ,CAoBV"}
@@ -0,0 +1,46 @@
1
+ import { ContextBlockNotFoundError } from './context-block-store.js';
2
+ /**
3
+ * Separator inserted between resolved blocks and between the last block
4
+ * and the original prompt. Exact string is load-bearing — tests assert on
5
+ * it, and the hash inputs in `onInitialRequest` depend on the rendered
6
+ * prompt being byte-stable across dispatches.
7
+ */
8
+ const SEPARATOR = '\n\n---\n\n';
9
+ /**
10
+ * Expands a task's `contextBlockIds` against a `ContextBlockStore`,
11
+ * returning a NEW `TaskSpec` whose `prompt` has the resolved blocks
12
+ * prepended (in the order they appear in `contextBlockIds`) with
13
+ * `SEPARATOR` between each block and before the original prompt.
14
+ *
15
+ * The returned task has `contextBlockIds` removed so downstream code
16
+ * cannot accidentally double-expand.
17
+ *
18
+ * If the task has no `contextBlockIds` (or the array is empty), or if
19
+ * no store is provided, the task is returned unchanged — the caller
20
+ * does not have to special-case the no-op path.
21
+ *
22
+ * Throws `ContextBlockNotFoundError` synchronously on the first missing
23
+ * id so the caller gets a clear error pointing to the offending block.
24
+ */
25
+ export function expandContextBlocks(task, store) {
26
+ if (!task.contextBlockIds || task.contextBlockIds.length === 0)
27
+ return task;
28
+ if (!store)
29
+ return task;
30
+ const blocks = [];
31
+ for (const id of task.contextBlockIds) {
32
+ const content = store.get(id);
33
+ if (content === undefined) {
34
+ throw new ContextBlockNotFoundError(id);
35
+ }
36
+ blocks.push(content);
37
+ }
38
+ const expanded = blocks.join(SEPARATOR) + SEPARATOR + task.prompt;
39
+ // Strip contextBlockIds from the returned task so a second pass through
40
+ // expandContextBlocks is a no-op (defence in depth against double-
41
+ // expansion if runtime-plumbing calls it twice).
42
+ const { contextBlockIds, ...rest } = task;
43
+ void contextBlockIds;
44
+ return { ...rest, prompt: expanded };
45
+ }
46
+ //# sourceMappingURL=expand-context-blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expand-context-blocks.js","sourceRoot":"","sources":["../../src/context/expand-context-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAA0B,MAAM,0BAA0B,CAAC;AAG7F;;;;;GAKG;AACH,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAc,EACd,KAAoC;IAEpC,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,yBAAyB,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IAClE,wEAAwE;IACxE,mEAAmE;IACnE,iDAAiD;IACjD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC1C,KAAK,eAAe,CAAC;IACrB,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { TaskSpec, RunResult, Provider, MultiModelConfig, ProgressEvent } from './types.js';
2
+ export interface DelegateOptions {
3
+ /** When true, the orchestrator does not walk the chain on failure —
4
+ * the first (and only) provider's result is returned as-is. */
5
+ explicitlyPinned?: boolean;
6
+ /** Optional in-flight progress sink. When provided, it is threaded into
7
+ * every `provider.run(...)` call so runners can emit turn/tool/injection
8
+ * events, and the orchestrator itself emits one `escalation_start` event
9
+ * between attempts whenever it hops to the next provider in the chain.
10
+ * The callback MUST NOT throw. See `ProgressEvent` for variants. */
11
+ onProgress?: (event: ProgressEvent) => void;
12
+ }
13
+ /**
14
+ * Build the escalation chain for an auto-routed task. Returns all eligible
15
+ * providers sorted cheapest-first with alphabetical tiebreak — this mirrors
16
+ * `selectProviderForTask`'s ordering so the first element of the chain is the
17
+ * same provider auto-routing would have picked.
18
+ *
19
+ * Eligibility (capability + tier filters) is handled entirely by
20
+ * `getProviderEligibility`; we just drop the ineligible entries.
21
+ */
22
+ export declare function buildEscalationChain(task: TaskSpec, config: MultiModelConfig): Provider[];
23
+ /**
24
+ * Walks the provider chain for an auto-routed task. Returns the first
25
+ * successful result; if all attempts fail, returns the best salvageable
26
+ * output (longest non-empty) with status 'incomplete' and the full
27
+ * escalation log.
28
+ *
29
+ * For explicitly-pinned tasks, the chain has length 1 and there is no
30
+ * walking — the pinned provider's result is returned as-is. See spec
31
+ * Part A.4.
32
+ */
33
+ export declare function delegateWithEscalation(task: TaskSpec, chain: Provider[], options?: DelegateOptions): Promise<RunResult>;
34
+ //# sourceMappingURL=delegate-with-escalation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegate-with-escalation.d.ts","sourceRoot":"","sources":["../src/delegate-with-escalation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EAER,gBAAgB,EAEhB,aAAa,EACd,MAAM,YAAY,CAAC;AAKpB,MAAM,WAAW,eAAe;IAC9B;oEACgE;IAChE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;yEAIqE;IACrE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7C;AASD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,gBAAgB,GACvB,QAAQ,EAAE,CAYZ;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,SAAS,CAAC,CAgJpB"}