fascicle 0.15.0 → 0.16.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 +114 -0
- package/README.md +8 -8
- package/dist/acp.d.ts +9 -2
- package/dist/acp.js +1538 -1472
- package/dist/acp.js.map +1 -1
- package/dist/{adapters-DNnzeLxr.js → adapters-CDUzZlby.js} +35 -13
- package/dist/adapters-CDUzZlby.js.map +1 -0
- package/dist/adapters.d.ts +8 -1
- package/dist/adapters.js +1 -1
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +15 -8
- package/dist/agents.js.map +1 -1
- package/dist/bin/fascicle-viewer.js +4 -1
- package/dist/console-CdB4pcFO.js +37 -0
- package/dist/console-CdB4pcFO.js.map +1 -0
- package/dist/{core-CDrz0NM1.js → core-CErsxGF6.js} +246 -147
- package/dist/core-CErsxGF6.js.map +1 -0
- package/dist/diagram_bin.js +2 -2
- package/dist/diagram_bin.js.map +1 -1
- package/dist/{engine-ha9xmgwE.js → engine-CR8q2IqV.js} +173 -67
- package/dist/engine-CR8q2IqV.js.map +1 -0
- package/dist/index.d.ts +529 -73
- package/dist/index.js +440 -137
- package/dist/index.js.map +1 -1
- package/dist/{invoke-px31fffH.js → invoke-COaeZ-vy.js} +6 -5
- package/dist/invoke-COaeZ-vy.js.map +1 -0
- package/dist/{json_schema_to_standard-BTWD0J6p.js → json_schema_to_standard-C4F4lXHE.js} +9 -12
- package/dist/json_schema_to_standard-C4F4lXHE.js.map +1 -0
- package/dist/{leading_system-DfJLqpGi.js → leading_system-PoHzNHuV.js} +28 -8
- package/dist/leading_system-PoHzNHuV.js.map +1 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.js +8 -4
- package/dist/mcp.js.map +1 -1
- package/dist/otel.js +10 -10
- package/dist/otel.js.map +1 -1
- package/dist/{search-CA_OqFeW.js → search-CpCJYMUm.js} +53 -6
- package/dist/search-CpCJYMUm.js.map +1 -0
- package/dist/search_worker.js +1 -1
- package/dist/stdio.js +7 -3
- package/dist/stdio.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +1 -1
- package/dist/{trajectory-Bm-mOtqw.d.ts → trajectory-BKGNxi7u.d.ts} +10 -9
- package/dist/{trajectory-BI-mrVFT.js → trajectory-DeURWIhj.js} +6 -5
- package/dist/trajectory-DeURWIhj.js.map +1 -0
- package/dist/{types-De-TVQxS.d.ts → types-Sw0oHW-_.d.ts} +6 -7
- package/dist/ui.d.ts +2 -1
- package/dist/ui.js +8 -1
- package/dist/ui.js.map +1 -1
- package/dist/viewer-app/assets/index-BYF5Dp7d.js +2 -0
- package/dist/viewer-app/index.html +2 -1
- package/dist/viewer.d.ts +26 -12
- package/dist/viewer.js +282 -63
- package/dist/viewer.js.map +1 -1
- package/package.json +4 -4
- package/dist/adapters-DNnzeLxr.js.map +0 -1
- package/dist/core-CDrz0NM1.js.map +0 -1
- package/dist/engine-ha9xmgwE.js.map +0 -1
- package/dist/invoke-px31fffH.js.map +0 -1
- package/dist/json_schema_to_standard-BTWD0J6p.js.map +0 -1
- package/dist/leading_system-DfJLqpGi.js.map +0 -1
- package/dist/search-CA_OqFeW.js.map +0 -1
- package/dist/trajectory-BI-mrVFT.js.map +0 -1
- package/dist/viewer-app/assets/index-Fnh5HKSU.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as describe_cycle_error, C as
|
|
2
|
-
import { t as create_engine } from "./engine-
|
|
3
|
-
import { a as is_run_end_event, c as is_step_replayed_event, i as is_map_item_failed_event, l as parse_trajectory_event, n as is_custom_trajectory_event, o as is_span_end_event, r as is_emit_event, s as is_span_start_event, t as is_checkpoint_event } from "./trajectory-
|
|
4
|
-
import { a as http_logger, n as tee_logger, o as filesystem_logger } from "./adapters-
|
|
5
|
-
import { A as tool_error, C as provider_capability_error, D as rate_limit_error, E as provider_required_error, O as schema_validation_error, S as provider_auth_error, T as provider_not_configured_error, _ as engine_config_error, b as model_required_error, g as claude_cli_error, k as tool_approval_denied_error, u as default_normalize_usage, v as engine_disposed_error, w as provider_error, x as on_chunk_error, y as incomplete_generation_error } from "./leading_system-
|
|
1
|
+
import { A as describe_cycle_error, C as durable, D as describe, E as run, F as suspended_error, I as timeout_error, L as STEP_KINDS, M as flow_changed_error, N as resume_validation_error, O as is_step, P as run_not_found_error, R as is_step_kind, S as suggest_step_id, _ as parallel, a as suspend, b as assert_valid_step_id, c as loop, d as retry, g as branch, h as map, i as use, j as error_path, k as aborted_error, l as timeout, m as pipe, n as scope, o as checkpoint, r as stash, s as compose, t as chain, u as fallback, v as sequence, x as is_valid_step_id, y as step, z as resolve_display_name } from "./core-CErsxGF6.js";
|
|
2
|
+
import { t as create_engine } from "./engine-CR8q2IqV.js";
|
|
3
|
+
import { a as is_run_end_event, c as is_step_replayed_event, i as is_map_item_failed_event, l as parse_trajectory_event, n as is_custom_trajectory_event, o as is_span_end_event, r as is_emit_event, s as is_span_start_event, t as is_checkpoint_event } from "./trajectory-DeURWIhj.js";
|
|
4
|
+
import { a as http_logger, n as tee_logger, o as filesystem_logger } from "./adapters-CDUzZlby.js";
|
|
5
|
+
import { A as tool_error, C as provider_capability_error, D as rate_limit_error, E as provider_required_error, O as schema_validation_error, S as provider_auth_error, T as provider_not_configured_error, _ as engine_config_error, b as model_required_error, g as claude_cli_error, j as turn_timeout_error, k as tool_approval_denied_error, u as default_normalize_usage, v as engine_disposed_error, w as provider_error, x as on_chunk_error, y as incomplete_generation_error } from "./leading_system-PoHzNHuV.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
8
8
|
import { dirname, join } from "node:path";
|
|
@@ -18,7 +18,7 @@ const flow_schema = {
|
|
|
18
18
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
19
19
|
"$id": "https://robmclarty.dev/schemas/flow-schema.json",
|
|
20
20
|
"title": "fascicle Flow DSL",
|
|
21
|
-
"description": "YAML/JSON representation of a composition tree. Documentation-only in v1.
|
|
21
|
+
"description": "YAML/JSON representation of a composition tree. Documentation-only in v1.",
|
|
22
22
|
"type": "array",
|
|
23
23
|
"items": { "$ref": "#/$defs/compose_entry" },
|
|
24
24
|
"$defs": {
|
|
@@ -46,6 +46,10 @@ const flow_schema = {
|
|
|
46
46
|
{ "required": ["ensemble"] },
|
|
47
47
|
{ "required": ["tournament"] },
|
|
48
48
|
{ "required": ["consensus"] },
|
|
49
|
+
{ "required": ["ensemble_step"] },
|
|
50
|
+
{ "required": ["gate"] },
|
|
51
|
+
{ "required": ["improve"] },
|
|
52
|
+
{ "required": ["learn"] },
|
|
49
53
|
{ "required": ["checkpoint"] },
|
|
50
54
|
{ "required": ["suspend"] },
|
|
51
55
|
{ "required": ["scope"] },
|
|
@@ -68,6 +72,10 @@ const flow_schema = {
|
|
|
68
72
|
"ensemble": { "$ref": "#/$defs/ensemble_config" },
|
|
69
73
|
"tournament": { "$ref": "#/$defs/tournament_config" },
|
|
70
74
|
"consensus": { "$ref": "#/$defs/consensus_config" },
|
|
75
|
+
"ensemble_step": { "$ref": "#/$defs/ensemble_step_config" },
|
|
76
|
+
"gate": { "$ref": "#/$defs/gate_config" },
|
|
77
|
+
"improve": { "$ref": "#/$defs/improve_config" },
|
|
78
|
+
"learn": { "$ref": "#/$defs/learn_config" },
|
|
71
79
|
"checkpoint": { "$ref": "#/$defs/checkpoint_config" },
|
|
72
80
|
"suspend": { "$ref": "#/$defs/suspend_config" },
|
|
73
81
|
"scope": { "$ref": "#/$defs/scope_config" },
|
|
@@ -80,9 +88,24 @@ const flow_schema = {
|
|
|
80
88
|
"required": ["fn"],
|
|
81
89
|
"properties": {
|
|
82
90
|
"id": { "type": "string" },
|
|
83
|
-
"fn": { "type": "string" }
|
|
91
|
+
"fn": { "type": "string" },
|
|
92
|
+
"name": { "type": "string" },
|
|
93
|
+
"description": { "type": "string" },
|
|
94
|
+
"side_effect": { "type": "boolean" },
|
|
95
|
+
"port_labels": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"properties": {
|
|
98
|
+
"in": { "type": "string" },
|
|
99
|
+
"out": { "type": "string" }
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"arm": { "$ref": "#/$defs/arms" }
|
|
84
103
|
}
|
|
85
104
|
},
|
|
105
|
+
"arms": { "anyOf": [{ "$ref": "#/$defs/node" }, {
|
|
106
|
+
"type": "array",
|
|
107
|
+
"items": { "$ref": "#/$defs/node" }
|
|
108
|
+
}] },
|
|
86
109
|
"sequence_config": {
|
|
87
110
|
"type": "array",
|
|
88
111
|
"items": { "$ref": "#/$defs/node" }
|
|
@@ -99,6 +122,8 @@ const flow_schema = {
|
|
|
99
122
|
"otherwise"
|
|
100
123
|
],
|
|
101
124
|
"properties": {
|
|
125
|
+
"name": { "type": "string" },
|
|
126
|
+
"description": { "type": "string" },
|
|
102
127
|
"when": { "type": "string" },
|
|
103
128
|
"then": { "$ref": "#/$defs/node" },
|
|
104
129
|
"otherwise": { "$ref": "#/$defs/node" }
|
|
@@ -108,6 +133,8 @@ const flow_schema = {
|
|
|
108
133
|
"type": "object",
|
|
109
134
|
"required": ["items", "do"],
|
|
110
135
|
"properties": {
|
|
136
|
+
"name": { "type": "string" },
|
|
137
|
+
"description": { "type": "string" },
|
|
111
138
|
"items": { "type": "string" },
|
|
112
139
|
"do": { "$ref": "#/$defs/node" },
|
|
113
140
|
"concurrency": {
|
|
@@ -121,6 +148,8 @@ const flow_schema = {
|
|
|
121
148
|
"type": "object",
|
|
122
149
|
"required": ["of", "fn"],
|
|
123
150
|
"properties": {
|
|
151
|
+
"name": { "type": "string" },
|
|
152
|
+
"description": { "type": "string" },
|
|
124
153
|
"of": { "$ref": "#/$defs/node" },
|
|
125
154
|
"fn": { "type": "string" }
|
|
126
155
|
}
|
|
@@ -129,6 +158,8 @@ const flow_schema = {
|
|
|
129
158
|
"type": "object",
|
|
130
159
|
"required": ["do", "max_attempts"],
|
|
131
160
|
"properties": {
|
|
161
|
+
"name": { "type": "string" },
|
|
162
|
+
"description": { "type": "string" },
|
|
132
163
|
"do": { "$ref": "#/$defs/node" },
|
|
133
164
|
"max_attempts": {
|
|
134
165
|
"type": "integer",
|
|
@@ -137,21 +168,36 @@ const flow_schema = {
|
|
|
137
168
|
"backoff_ms": {
|
|
138
169
|
"type": "integer",
|
|
139
170
|
"minimum": 0
|
|
140
|
-
}
|
|
171
|
+
},
|
|
172
|
+
"max_delay_ms": {
|
|
173
|
+
"type": "integer",
|
|
174
|
+
"minimum": 0
|
|
175
|
+
},
|
|
176
|
+
"jitter": { "type": "boolean" },
|
|
177
|
+
"when": { "type": "string" },
|
|
178
|
+
"on_error": { "type": "string" },
|
|
179
|
+
"project": { "type": "string" }
|
|
141
180
|
}
|
|
142
181
|
},
|
|
143
182
|
"fallback_config": {
|
|
144
183
|
"type": "object",
|
|
145
184
|
"required": ["primary", "backup"],
|
|
146
185
|
"properties": {
|
|
186
|
+
"name": { "type": "string" },
|
|
187
|
+
"description": { "type": "string" },
|
|
147
188
|
"primary": { "$ref": "#/$defs/node" },
|
|
148
|
-
"backup": { "$ref": "#/$defs/node" }
|
|
189
|
+
"backup": { "$ref": "#/$defs/node" },
|
|
190
|
+
"when": { "type": "string" },
|
|
191
|
+
"handoff": { "type": "string" },
|
|
192
|
+
"project": { "type": "string" }
|
|
149
193
|
}
|
|
150
194
|
},
|
|
151
195
|
"timeout_config": {
|
|
152
196
|
"type": "object",
|
|
153
197
|
"required": ["do", "ms"],
|
|
154
198
|
"properties": {
|
|
199
|
+
"name": { "type": "string" },
|
|
200
|
+
"description": { "type": "string" },
|
|
155
201
|
"do": { "$ref": "#/$defs/node" },
|
|
156
202
|
"ms": {
|
|
157
203
|
"type": "integer",
|
|
@@ -167,20 +213,27 @@ const flow_schema = {
|
|
|
167
213
|
"type": "string",
|
|
168
214
|
"minLength": 1
|
|
169
215
|
},
|
|
216
|
+
"description": { "type": "string" },
|
|
170
217
|
"do": { "$ref": "#/$defs/node" }
|
|
171
218
|
}
|
|
172
219
|
},
|
|
173
220
|
"loop_config": {
|
|
174
221
|
"type": "object",
|
|
175
|
-
"required": [
|
|
222
|
+
"required": [
|
|
223
|
+
"init",
|
|
224
|
+
"body",
|
|
225
|
+
"finish",
|
|
226
|
+
"max_rounds"
|
|
227
|
+
],
|
|
176
228
|
"properties": {
|
|
177
229
|
"name": {
|
|
178
230
|
"type": "string",
|
|
179
231
|
"minLength": 1
|
|
180
232
|
},
|
|
233
|
+
"description": { "type": "string" },
|
|
181
234
|
"init": { "type": "string" },
|
|
182
235
|
"body": { "$ref": "#/$defs/node" },
|
|
183
|
-
"guard": { "$ref": "#/$defs/node" },
|
|
236
|
+
"guard": { "anyOf": [{ "$ref": "#/$defs/node" }, { "type": "string" }] },
|
|
184
237
|
"finish": { "type": "string" },
|
|
185
238
|
"max_rounds": {
|
|
186
239
|
"type": "integer",
|
|
@@ -197,19 +250,24 @@ const flow_schema = {
|
|
|
197
250
|
"max_rounds"
|
|
198
251
|
],
|
|
199
252
|
"properties": {
|
|
253
|
+
"name": { "type": "string" },
|
|
254
|
+
"description": { "type": "string" },
|
|
200
255
|
"build": { "$ref": "#/$defs/node" },
|
|
201
256
|
"critique": { "$ref": "#/$defs/node" },
|
|
202
257
|
"accept": { "type": "string" },
|
|
203
258
|
"max_rounds": {
|
|
204
259
|
"type": "integer",
|
|
205
260
|
"minimum": 1
|
|
206
|
-
}
|
|
261
|
+
},
|
|
262
|
+
"project": { "type": "string" }
|
|
207
263
|
}
|
|
208
264
|
},
|
|
209
265
|
"ensemble_config": {
|
|
210
266
|
"type": "object",
|
|
211
267
|
"required": ["members", "score"],
|
|
212
268
|
"properties": {
|
|
269
|
+
"name": { "type": "string" },
|
|
270
|
+
"description": { "type": "string" },
|
|
213
271
|
"members": {
|
|
214
272
|
"type": "object",
|
|
215
273
|
"additionalProperties": { "$ref": "#/$defs/node" }
|
|
@@ -218,18 +276,22 @@ const flow_schema = {
|
|
|
218
276
|
"select": {
|
|
219
277
|
"type": "string",
|
|
220
278
|
"enum": ["max", "min"]
|
|
221
|
-
}
|
|
279
|
+
},
|
|
280
|
+
"project": { "type": "string" }
|
|
222
281
|
}
|
|
223
282
|
},
|
|
224
283
|
"tournament_config": {
|
|
225
284
|
"type": "object",
|
|
226
285
|
"required": ["members", "compare"],
|
|
227
286
|
"properties": {
|
|
287
|
+
"name": { "type": "string" },
|
|
288
|
+
"description": { "type": "string" },
|
|
228
289
|
"members": {
|
|
229
290
|
"type": "object",
|
|
230
291
|
"additionalProperties": { "$ref": "#/$defs/node" }
|
|
231
292
|
},
|
|
232
|
-
"compare": { "type": "string" }
|
|
293
|
+
"compare": { "type": "string" },
|
|
294
|
+
"project": { "type": "string" }
|
|
233
295
|
}
|
|
234
296
|
},
|
|
235
297
|
"consensus_config": {
|
|
@@ -240,6 +302,8 @@ const flow_schema = {
|
|
|
240
302
|
"max_rounds"
|
|
241
303
|
],
|
|
242
304
|
"properties": {
|
|
305
|
+
"name": { "type": "string" },
|
|
306
|
+
"description": { "type": "string" },
|
|
243
307
|
"members": {
|
|
244
308
|
"type": "object",
|
|
245
309
|
"additionalProperties": { "$ref": "#/$defs/node" }
|
|
@@ -248,15 +312,173 @@ const flow_schema = {
|
|
|
248
312
|
"max_rounds": {
|
|
249
313
|
"type": "integer",
|
|
250
314
|
"minimum": 1
|
|
315
|
+
},
|
|
316
|
+
"project": { "type": "string" }
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
"ensemble_step_config": {
|
|
320
|
+
"type": "object",
|
|
321
|
+
"required": [
|
|
322
|
+
"members",
|
|
323
|
+
"score",
|
|
324
|
+
"rank_by"
|
|
325
|
+
],
|
|
326
|
+
"properties": {
|
|
327
|
+
"name": { "type": "string" },
|
|
328
|
+
"description": { "type": "string" },
|
|
329
|
+
"members": {
|
|
330
|
+
"type": "object",
|
|
331
|
+
"additionalProperties": { "$ref": "#/$defs/node" }
|
|
332
|
+
},
|
|
333
|
+
"score": { "$ref": "#/$defs/node" },
|
|
334
|
+
"rank_by": { "type": "string" },
|
|
335
|
+
"select": {
|
|
336
|
+
"type": "string",
|
|
337
|
+
"enum": ["max", "min"]
|
|
338
|
+
},
|
|
339
|
+
"project": { "type": "string" }
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
"gate_config": {
|
|
343
|
+
"type": "object",
|
|
344
|
+
"required": ["do", "id"],
|
|
345
|
+
"properties": {
|
|
346
|
+
"id": { "type": "string" },
|
|
347
|
+
"name": { "type": "string" },
|
|
348
|
+
"description": { "type": "string" },
|
|
349
|
+
"do": { "$ref": "#/$defs/node" },
|
|
350
|
+
"store": { "type": "string" },
|
|
351
|
+
"format": { "type": "string" }
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
"improve_config": {
|
|
355
|
+
"type": "object",
|
|
356
|
+
"required": [
|
|
357
|
+
"seed",
|
|
358
|
+
"propose",
|
|
359
|
+
"score",
|
|
360
|
+
"budget"
|
|
361
|
+
],
|
|
362
|
+
"properties": {
|
|
363
|
+
"name": { "type": "string" },
|
|
364
|
+
"description": { "type": "string" },
|
|
365
|
+
"seed": { "$ref": "#/$defs/node" },
|
|
366
|
+
"propose": { "$ref": "#/$defs/node" },
|
|
367
|
+
"score": { "$ref": "#/$defs/node" },
|
|
368
|
+
"budget": { "$ref": "#/$defs/improve_budget" },
|
|
369
|
+
"epsilon": { "type": "number" },
|
|
370
|
+
"proposers_per_round": {
|
|
371
|
+
"type": "integer",
|
|
372
|
+
"minimum": 1
|
|
373
|
+
},
|
|
374
|
+
"lessons_capacity": {
|
|
375
|
+
"type": "integer",
|
|
376
|
+
"minimum": 0
|
|
377
|
+
},
|
|
378
|
+
"project": { "type": "string" }
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
"improve_budget": {
|
|
382
|
+
"type": "object",
|
|
383
|
+
"required": ["max_rounds", "patience"],
|
|
384
|
+
"properties": {
|
|
385
|
+
"max_rounds": {
|
|
386
|
+
"type": "integer",
|
|
387
|
+
"minimum": 1
|
|
388
|
+
},
|
|
389
|
+
"max_wallclock_ms": {
|
|
390
|
+
"type": "integer",
|
|
391
|
+
"minimum": 0
|
|
392
|
+
},
|
|
393
|
+
"patience": {
|
|
394
|
+
"type": "integer",
|
|
395
|
+
"minimum": 0
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
"learn_config": {
|
|
400
|
+
"type": "object",
|
|
401
|
+
"required": [
|
|
402
|
+
"flow",
|
|
403
|
+
"source",
|
|
404
|
+
"analyzer"
|
|
405
|
+
],
|
|
406
|
+
"properties": {
|
|
407
|
+
"name": { "type": "string" },
|
|
408
|
+
"description": { "type": "string" },
|
|
409
|
+
"flow": { "$ref": "#/$defs/node" },
|
|
410
|
+
"source": { "$ref": "#/$defs/learn_source" },
|
|
411
|
+
"analyzer": { "$ref": "#/$defs/node" },
|
|
412
|
+
"filter": { "type": "string" },
|
|
413
|
+
"max_events": {
|
|
414
|
+
"type": "integer",
|
|
415
|
+
"minimum": 1
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
"learn_source": {
|
|
420
|
+
"type": "object",
|
|
421
|
+
"oneOf": [
|
|
422
|
+
{ "$ref": "#/$defs/learn_events_source" },
|
|
423
|
+
{ "$ref": "#/$defs/learn_paths_source" },
|
|
424
|
+
{ "$ref": "#/$defs/learn_dir_source" }
|
|
425
|
+
]
|
|
426
|
+
},
|
|
427
|
+
"learn_events_source": {
|
|
428
|
+
"type": "object",
|
|
429
|
+
"required": ["kind", "events"],
|
|
430
|
+
"properties": {
|
|
431
|
+
"kind": {
|
|
432
|
+
"type": "string",
|
|
433
|
+
"enum": ["events"]
|
|
434
|
+
},
|
|
435
|
+
"events": {
|
|
436
|
+
"type": "array",
|
|
437
|
+
"items": {
|
|
438
|
+
"type": "object",
|
|
439
|
+
"required": ["kind"],
|
|
440
|
+
"properties": { "kind": { "type": "string" } }
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
"learn_paths_source": {
|
|
446
|
+
"type": "object",
|
|
447
|
+
"required": ["kind", "paths"],
|
|
448
|
+
"properties": {
|
|
449
|
+
"kind": {
|
|
450
|
+
"type": "string",
|
|
451
|
+
"enum": ["paths"]
|
|
452
|
+
},
|
|
453
|
+
"paths": {
|
|
454
|
+
"type": "array",
|
|
455
|
+
"items": { "type": "string" }
|
|
251
456
|
}
|
|
252
457
|
}
|
|
253
458
|
},
|
|
459
|
+
"learn_dir_source": {
|
|
460
|
+
"type": "object",
|
|
461
|
+
"required": ["kind", "dir"],
|
|
462
|
+
"properties": {
|
|
463
|
+
"kind": {
|
|
464
|
+
"type": "string",
|
|
465
|
+
"enum": ["dir"]
|
|
466
|
+
},
|
|
467
|
+
"dir": { "type": "string" }
|
|
468
|
+
}
|
|
469
|
+
},
|
|
254
470
|
"checkpoint_config": {
|
|
255
471
|
"type": "object",
|
|
256
472
|
"required": ["do", "key"],
|
|
257
473
|
"properties": {
|
|
474
|
+
"name": { "type": "string" },
|
|
475
|
+
"description": { "type": "string" },
|
|
258
476
|
"do": { "$ref": "#/$defs/node" },
|
|
259
|
-
"key": { "type": "string" }
|
|
477
|
+
"key": { "type": "string" },
|
|
478
|
+
"on_write_error": {
|
|
479
|
+
"type": "string",
|
|
480
|
+
"enum": ["record", "fail"]
|
|
481
|
+
}
|
|
260
482
|
}
|
|
261
483
|
},
|
|
262
484
|
"suspend_config": {
|
|
@@ -269,6 +491,8 @@ const flow_schema = {
|
|
|
269
491
|
],
|
|
270
492
|
"properties": {
|
|
271
493
|
"id": { "type": "string" },
|
|
494
|
+
"name": { "type": "string" },
|
|
495
|
+
"description": { "type": "string" },
|
|
272
496
|
"on": { "type": "string" },
|
|
273
497
|
"resume_schema": { "type": "string" },
|
|
274
498
|
"combine": { "type": "string" },
|
|
@@ -281,24 +505,34 @@ const flow_schema = {
|
|
|
281
505
|
},
|
|
282
506
|
"scope_entry": {
|
|
283
507
|
"type": "object",
|
|
284
|
-
"oneOf": [
|
|
285
|
-
"
|
|
286
|
-
"
|
|
287
|
-
"
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
508
|
+
"oneOf": [
|
|
509
|
+
{ "$ref": "#/$defs/stash_entry" },
|
|
510
|
+
{ "$ref": "#/$defs/use_entry" },
|
|
511
|
+
{ "$ref": "#/$defs/node" }
|
|
512
|
+
]
|
|
513
|
+
},
|
|
514
|
+
"stash_entry": {
|
|
515
|
+
"type": "object",
|
|
516
|
+
"required": ["stash", "do"],
|
|
517
|
+
"properties": {
|
|
518
|
+
"name": { "type": "string" },
|
|
519
|
+
"description": { "type": "string" },
|
|
520
|
+
"stash": { "type": "string" },
|
|
521
|
+
"do": { "$ref": "#/$defs/node" }
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
"use_entry": {
|
|
525
|
+
"type": "object",
|
|
526
|
+
"required": ["use", "fn"],
|
|
527
|
+
"properties": {
|
|
528
|
+
"name": { "type": "string" },
|
|
529
|
+
"description": { "type": "string" },
|
|
530
|
+
"use": {
|
|
531
|
+
"type": "array",
|
|
532
|
+
"items": { "type": "string" }
|
|
533
|
+
},
|
|
534
|
+
"fn": { "type": "string" }
|
|
535
|
+
}
|
|
302
536
|
},
|
|
303
537
|
"chain_config": {
|
|
304
538
|
"type": "object",
|
|
@@ -314,21 +548,45 @@ const flow_schema = {
|
|
|
314
548
|
},
|
|
315
549
|
"chain_entry": {
|
|
316
550
|
"type": "object",
|
|
317
|
-
"oneOf": [
|
|
318
|
-
"
|
|
319
|
-
"
|
|
320
|
-
"
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
"
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
551
|
+
"oneOf": [
|
|
552
|
+
{ "$ref": "#/$defs/chain_step_entry" },
|
|
553
|
+
{ "$ref": "#/$defs/chain_arm_entry" },
|
|
554
|
+
{ "$ref": "#/$defs/chain_stage_entry" }
|
|
555
|
+
]
|
|
556
|
+
},
|
|
557
|
+
"chain_step_entry": {
|
|
558
|
+
"type": "object",
|
|
559
|
+
"required": ["step", "fn"],
|
|
560
|
+
"properties": {
|
|
561
|
+
"name": { "type": "string" },
|
|
562
|
+
"description": { "type": "string" },
|
|
563
|
+
"step": { "type": "string" },
|
|
564
|
+
"fn": { "type": "string" },
|
|
565
|
+
"arm": { "$ref": "#/$defs/arms" }
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
"chain_arm_entry": {
|
|
569
|
+
"type": "object",
|
|
570
|
+
"required": [
|
|
571
|
+
"step",
|
|
572
|
+
"arm",
|
|
573
|
+
"select"
|
|
574
|
+
],
|
|
575
|
+
"properties": {
|
|
576
|
+
"name": { "type": "string" },
|
|
577
|
+
"description": { "type": "string" },
|
|
578
|
+
"step": { "type": "string" },
|
|
579
|
+
"arm": { "$ref": "#/$defs/node" },
|
|
580
|
+
"select": { "type": "string" }
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
"chain_stage_entry": {
|
|
584
|
+
"type": "object",
|
|
585
|
+
"required": ["stage"],
|
|
586
|
+
"properties": {
|
|
587
|
+
"stage": { "type": "string" },
|
|
588
|
+
"project": { "type": "string" }
|
|
589
|
+
}
|
|
332
590
|
}
|
|
333
591
|
}
|
|
334
592
|
};
|
|
@@ -494,7 +752,9 @@ function consensus(config) {
|
|
|
494
752
|
*
|
|
495
753
|
* `select` picks the highest (`'max'`, the default) or lowest (`'min'`)
|
|
496
754
|
* score. Tie-breaking is "any tied result is acceptable": the first member
|
|
497
|
-
* (in `members` key order) holding the best score wins.
|
|
755
|
+
* (in `members` key order) holding the best score wins. A member that
|
|
756
|
+
* returns `undefined` is scored like any other, and a NaN score stays in the
|
|
757
|
+
* score map but never wins, so a field whose every score is NaN throws. `project` maps the
|
|
498
758
|
* `{ winner, scores }` envelope into the step's output (for example, `(r) =>
|
|
499
759
|
* r.winner`); omitted, the envelope itself is the output.
|
|
500
760
|
*
|
|
@@ -507,34 +767,21 @@ function ensemble(config) {
|
|
|
507
767
|
const score_fn = config.score;
|
|
508
768
|
const keys = Object.keys(config.members);
|
|
509
769
|
const project = config.project ?? ((r) => r);
|
|
770
|
+
if (keys.length === 0) throw new Error("ensemble: at least one member required");
|
|
510
771
|
const fan_out = parallel(config.members);
|
|
511
772
|
const pick = step("pick_winner", async (results) => {
|
|
512
773
|
const scores = {};
|
|
774
|
+
const ranked = [];
|
|
513
775
|
for (const k of keys) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
scores[k] =
|
|
776
|
+
if (!Object.hasOwn(results, k)) continue;
|
|
777
|
+
const score = await score_fn(results[k], k);
|
|
778
|
+
scores[k] = score;
|
|
779
|
+
ranked.push([k, score]);
|
|
517
780
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
for (const k of keys) {
|
|
521
|
-
const current = scores[k];
|
|
522
|
-
if (current === void 0) continue;
|
|
523
|
-
if (winner_score === void 0) {
|
|
524
|
-
winner_key = k;
|
|
525
|
-
winner_score = current;
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
if (select === "max" ? current > winner_score : current < winner_score) {
|
|
529
|
-
winner_key = k;
|
|
530
|
-
winner_score = current;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (winner_key === void 0) throw new Error("ensemble: no members produced a result");
|
|
534
|
-
const winner = results[winner_key];
|
|
535
|
-
if (winner === void 0) throw new Error("ensemble: winner missing from results");
|
|
781
|
+
const winner_key = best_of(ranked, select);
|
|
782
|
+
if (winner_key === void 0) throw new Error("ensemble: every score was NaN, so no member can win; make score return a number for each result");
|
|
536
783
|
return project({
|
|
537
|
-
winner,
|
|
784
|
+
winner: results[winner_key],
|
|
538
785
|
scores
|
|
539
786
|
});
|
|
540
787
|
});
|
|
@@ -544,6 +791,20 @@ function ensemble(config) {
|
|
|
544
791
|
description: config.description
|
|
545
792
|
});
|
|
546
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
* The member whose score is best under `select`, the first in `ranked` order
|
|
796
|
+
* on a tie, or `undefined` when every score is NaN. A NaN score never wins,
|
|
797
|
+
* wherever it falls, because no reading of "best" includes it.
|
|
798
|
+
*/
|
|
799
|
+
function best_of(ranked, select) {
|
|
800
|
+
let best;
|
|
801
|
+
for (const entry of ranked) {
|
|
802
|
+
const score = entry[1];
|
|
803
|
+
if (Number.isNaN(score)) continue;
|
|
804
|
+
if (best === void 0 || (select === "max" ? score > best[1] : score < best[1])) best = entry;
|
|
805
|
+
}
|
|
806
|
+
return best?.[0];
|
|
807
|
+
}
|
|
547
808
|
//#endregion
|
|
548
809
|
//#region src/composites/ensemble_step.ts
|
|
549
810
|
/**
|
|
@@ -559,7 +820,9 @@ const ITEM_KEY = "__ensemble_step_item";
|
|
|
559
820
|
* example, a separate model call, a sub-flow, anything that wants its own
|
|
560
821
|
* trajectory span and abort routing). The `score` step is dispatched once per
|
|
561
822
|
* member result; `rank_by` projects a number out of the structured scored output;
|
|
562
|
-
* `select` picks the highest (`'max'`, default) or lowest (`'min'`) rank.
|
|
823
|
+
* `select` picks the highest (`'max'`, default) or lowest (`'min'`) rank. A
|
|
824
|
+
* member that returns `undefined` is scored like any other, and a NaN rank
|
|
825
|
+
* never wins, so a field whose every rank is NaN throws.
|
|
563
826
|
*
|
|
564
827
|
* The result carries `winner_scored`, the structured output from the round's
|
|
565
828
|
* scoring run preserved verbatim, so callers never pay to re-score the
|
|
@@ -592,7 +855,7 @@ function ensemble_step(config) {
|
|
|
592
855
|
]);
|
|
593
856
|
const to_pairs = step("ensemble_step_to_pairs", (results) => {
|
|
594
857
|
const out = [];
|
|
595
|
-
for (const id of keys) if (id
|
|
858
|
+
for (const id of keys) if (Object.hasOwn(results, id)) out.push({
|
|
596
859
|
id,
|
|
597
860
|
value: results[id]
|
|
598
861
|
});
|
|
@@ -605,25 +868,23 @@ function ensemble_step(config) {
|
|
|
605
868
|
const pick = use([RESULTS_KEY], (vars, scored_pairs) => {
|
|
606
869
|
const results = vars[RESULTS_KEY];
|
|
607
870
|
const scored = {};
|
|
608
|
-
let
|
|
609
|
-
let
|
|
610
|
-
let winner_scored;
|
|
871
|
+
let best;
|
|
872
|
+
let best_rank = NaN;
|
|
611
873
|
for (const pair of scored_pairs) {
|
|
612
874
|
scored[pair.id] = pair.scored;
|
|
613
875
|
const rank = rank_by(pair.scored);
|
|
614
|
-
if (
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
876
|
+
if (Number.isNaN(rank)) continue;
|
|
877
|
+
if (best === void 0 || (select === "max" ? rank > best_rank : rank < best_rank)) {
|
|
878
|
+
best = pair;
|
|
879
|
+
best_rank = rank;
|
|
618
880
|
}
|
|
619
881
|
}
|
|
620
|
-
if (
|
|
621
|
-
const winner = results[
|
|
622
|
-
if (winner === void 0) throw new Error("ensemble_step: winner missing from results");
|
|
882
|
+
if (best === void 0) throw new Error("ensemble_step: every score ranked NaN, so no member can win; make rank_by return a number for each score");
|
|
883
|
+
const winner = results[best.id];
|
|
623
884
|
return project({
|
|
624
|
-
winner_id,
|
|
885
|
+
winner_id: best.id,
|
|
625
886
|
winner,
|
|
626
|
-
winner_scored,
|
|
887
|
+
winner_scored: best.scored,
|
|
627
888
|
scored
|
|
628
889
|
});
|
|
629
890
|
});
|
|
@@ -658,6 +919,11 @@ function ensemble_step(config) {
|
|
|
658
919
|
* checkpoint and resume docs make for fixed string keys). Inherited from
|
|
659
920
|
* `checkpoint`: a stored `null`/`undefined` counts as a miss, and the inner
|
|
660
921
|
* step must be named.
|
|
922
|
+
* - A failed write fails the run: the checkpoint takes
|
|
923
|
+
* `on_write_error: 'fail'`, so the run stops before it suspends rather than
|
|
924
|
+
* ask for approval of a result that the store never kept, which a resume
|
|
925
|
+
* would replace by running `inner` again. A hand-built checkpoint before a
|
|
926
|
+
* `suspend` that shows its result should pass `'fail'` for the same reason.
|
|
661
927
|
* - Suspend payload: follows the library's suspend contract, which raises
|
|
662
928
|
* `{ input }` on the `suspended_error`. Here that `input` is
|
|
663
929
|
* `format(result)` when `format` is given and the raw result otherwise, so
|
|
@@ -711,7 +977,9 @@ function bind_store(persisted, store) {
|
|
|
711
977
|
* unchanged; the decision itself is discarded. On a re-run against the same
|
|
712
978
|
* store, the checkpoint absorbs the replay so `inner` never re-executes.
|
|
713
979
|
* Throws at construction time when `inner` is anonymous, because the cached
|
|
714
|
-
* result must map back to a stable step.
|
|
980
|
+
* result must map back to a stable step, and when `config.id` isn't an
|
|
981
|
+
* identifier, which it checks under its own name before its `suspend` sees
|
|
982
|
+
* the id.
|
|
715
983
|
*
|
|
716
984
|
* Implemented as a `compose`d `scope`: the checkpointed result is stashed,
|
|
717
985
|
* projected into the approver's view, and handed to `suspend`; the suspend's
|
|
@@ -721,7 +989,11 @@ function bind_store(persisted, store) {
|
|
|
721
989
|
function gate(inner, config) {
|
|
722
990
|
if (inner.anonymous === true) throw new Error("gate requires a named inner step, got anonymous — give the inner step an id with step('id', fn)");
|
|
723
991
|
const { id, store, format } = config;
|
|
724
|
-
|
|
992
|
+
assert_valid_step_id(id, "gate id", "put the label in name");
|
|
993
|
+
const checkpointed = checkpoint(inner, {
|
|
994
|
+
key: `gate:${id}`,
|
|
995
|
+
on_write_error: "fail"
|
|
996
|
+
});
|
|
725
997
|
const persisted = store === void 0 ? checkpointed : bind_store(checkpointed, store);
|
|
726
998
|
const restore = use(["result"], (vars) => {
|
|
727
999
|
return vars["result"];
|
|
@@ -769,7 +1041,7 @@ const PRIOR_KEY = "__improve_prior";
|
|
|
769
1041
|
* itself is the output.
|
|
770
1042
|
*
|
|
771
1043
|
* Implemented as a `compose`d `scope` of (seed) -> (init state) -> (loop) ->
|
|
772
|
-
* (
|
|
1044
|
+
* (record stop). The loop body is itself a small `scope` that snapshots prior
|
|
773
1045
|
* state, builds a round input, dispatches the proposers + scorer via
|
|
774
1046
|
* `ensemble_step`, and merges the outcome back into state via `use`.
|
|
775
1047
|
* State threading is the entire job.
|
|
@@ -841,7 +1113,7 @@ function improve(config) {
|
|
|
841
1113
|
const next_round = prior.round + 1;
|
|
842
1114
|
const better = scored.score > prior.parent_score + epsilon;
|
|
843
1115
|
const accepted = scored.accepted && better;
|
|
844
|
-
const next_lessons = !accepted && scored.reason !== void 0 ? [...prior.lessons, {
|
|
1116
|
+
const next_lessons = !accepted && scored.reason !== void 0 && lessons_capacity > 0 ? [...prior.lessons, {
|
|
845
1117
|
round: next_round,
|
|
846
1118
|
proposer_id: scored.candidate.proposer_id,
|
|
847
1119
|
reason: scored.reason
|
|
@@ -941,7 +1213,7 @@ function improve(config) {
|
|
|
941
1213
|
* `describe(flow)`, and returns the analyzer's proposals plus summary metadata
|
|
942
1214
|
* (events considered, distinct run ids).
|
|
943
1215
|
*
|
|
944
|
-
*
|
|
1216
|
+
* `improve` is the *online* counterpart of this pattern: propose →
|
|
945
1217
|
* score → accept/reject inside a single run. `learn` is the *offline*
|
|
946
1218
|
* counterpart: reflect on what already happened across one or many recorded
|
|
947
1219
|
* runs without an evaluator in the loop.
|
|
@@ -1007,14 +1279,16 @@ async function read_jsonl(file_path, ctx) {
|
|
|
1007
1279
|
return events;
|
|
1008
1280
|
}
|
|
1009
1281
|
/**
|
|
1010
|
-
* Throw the abort reason
|
|
1011
|
-
*
|
|
1282
|
+
* Throw the abort reason when the run has been cancelled.
|
|
1283
|
+
*
|
|
1284
|
+
* Mirrors core's abort shape: an `Error` reason propagates verbatim, anything
|
|
1285
|
+
* else is wrapped in `aborted_error`, so a caller aborting with its own cause
|
|
1286
|
+
* sees that instance rather than a copy.
|
|
1012
1287
|
*/
|
|
1013
1288
|
function throw_if_aborted$1(ctx) {
|
|
1014
1289
|
if (!ctx.abort.aborted) return;
|
|
1015
1290
|
const reason = ctx.abort.reason;
|
|
1016
|
-
|
|
1017
|
-
throw new aborted_error("aborted", reason === void 0 ? {} : { reason });
|
|
1291
|
+
throw reason instanceof Error ? reason : new aborted_error("aborted", { reason });
|
|
1018
1292
|
}
|
|
1019
1293
|
/**
|
|
1020
1294
|
* Materialize a `TrajectorySource` into an event array.
|
|
@@ -1171,10 +1445,8 @@ async function play_round(current, results, compare, round, bracket) {
|
|
|
1171
1445
|
next_round.push(a_id);
|
|
1172
1446
|
continue;
|
|
1173
1447
|
}
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1176
|
-
if (a_val === void 0 || b_val === void 0) throw new Error("tournament: missing result for match");
|
|
1177
|
-
const winner_id = await compare(a_val, b_val) === "a" ? a_id : b_id;
|
|
1448
|
+
if (!Object.hasOwn(results, a_id) || !Object.hasOwn(results, b_id)) throw new Error("tournament: missing result for match");
|
|
1449
|
+
const winner_id = await compare(results[a_id], results[b_id]) === "a" ? a_id : b_id;
|
|
1178
1450
|
bracket.push({
|
|
1179
1451
|
round,
|
|
1180
1452
|
a_id,
|
|
@@ -1192,18 +1464,17 @@ async function play_round(current, results, compare, round, bracket) {
|
|
|
1192
1464
|
function winner_of(current, results) {
|
|
1193
1465
|
const final_id = current[0];
|
|
1194
1466
|
if (final_id === void 0) throw new Error("tournament: no winner");
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
return winner;
|
|
1467
|
+
if (!Object.hasOwn(results, final_id)) throw new Error("tournament: winner missing from results");
|
|
1468
|
+
return results[final_id];
|
|
1198
1469
|
}
|
|
1199
1470
|
//#endregion
|
|
1200
1471
|
//#region src/composites/errors.ts
|
|
1201
1472
|
/**
|
|
1202
1473
|
* Typed errors for the composites layer.
|
|
1203
1474
|
*
|
|
1204
|
-
* Listed
|
|
1205
|
-
*
|
|
1206
|
-
*
|
|
1475
|
+
* Listed with the other modules' `errors.ts` files in the `no-class` rule
|
|
1476
|
+
* ignores: `instanceof` branching is how a caller tells a benched flow's usage
|
|
1477
|
+
* error apart from a case failure.
|
|
1207
1478
|
*/
|
|
1208
1479
|
var bench_suspend_error = class extends Error {
|
|
1209
1480
|
kind = "bench_suspend_error";
|
|
@@ -1448,7 +1719,8 @@ function normalize_score(raw) {
|
|
|
1448
1719
|
}
|
|
1449
1720
|
/**
|
|
1450
1721
|
* Extracts the numeric value from a score-shaped entry, tolerating both bare
|
|
1451
|
-
* numbers and `{ score }` objects since `S` is caller-defined.
|
|
1722
|
+
* numbers and `{ score }` objects since `S` is caller-defined. Anything else
|
|
1723
|
+
* (missing, non-finite, non-numeric) has no value. Shared with `regression`.
|
|
1452
1724
|
*/
|
|
1453
1725
|
function score_value_of(s) {
|
|
1454
1726
|
if (s === void 0 || s === null) return void 0;
|
|
@@ -1526,7 +1798,7 @@ function resolve_concurrency(value, n_cases) {
|
|
|
1526
1798
|
* the same way spans and `describe` do, then falling back to identity.
|
|
1527
1799
|
*/
|
|
1528
1800
|
function describe_flow_name(flow) {
|
|
1529
|
-
return resolve_display_name(flow, flow.id
|
|
1801
|
+
return resolve_display_name(flow, flow.id);
|
|
1530
1802
|
}
|
|
1531
1803
|
/**
|
|
1532
1804
|
* Short random base36 suffix to keep default run ids unique across
|
|
@@ -1675,7 +1947,7 @@ function render_prompt(rubric, scale, args) {
|
|
|
1675
1947
|
* score into the configured scale rather than rejecting out-of-range values.
|
|
1676
1948
|
*/
|
|
1677
1949
|
function parse_score(reply, scale) {
|
|
1678
|
-
const candidate = extract_json_object(reply
|
|
1950
|
+
const candidate = extract_json_object(reply);
|
|
1679
1951
|
if (candidate === void 0) return void 0;
|
|
1680
1952
|
let parsed;
|
|
1681
1953
|
try {
|
|
@@ -1695,16 +1967,47 @@ function parse_score(reply, scale) {
|
|
|
1695
1967
|
};
|
|
1696
1968
|
}
|
|
1697
1969
|
/**
|
|
1698
|
-
* Pulls the
|
|
1699
|
-
* in prose or code fences
|
|
1700
|
-
*
|
|
1970
|
+
* Pulls the first balanced `{...}` slice out of a reply that may wrap the
|
|
1971
|
+
* JSON in prose or code fences on either side. The scan starts at the first
|
|
1972
|
+
* `{` and skips braces inside string literals, so a `}` in a reason doesn't
|
|
1973
|
+
* end the object early and a `{` in trailing prose doesn't extend it.
|
|
1974
|
+
* Returns `undefined` when the reply has no `{` or the first one never
|
|
1975
|
+
* closes.
|
|
1701
1976
|
*/
|
|
1702
1977
|
function extract_json_object(text) {
|
|
1703
|
-
if (text.startsWith("{")) return text;
|
|
1704
1978
|
const start = text.indexOf("{");
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
return text.slice(start, end + 1);
|
|
1979
|
+
if (start === -1) return void 0;
|
|
1980
|
+
const end = find_object_end(text, start);
|
|
1981
|
+
return end === void 0 ? void 0 : text.slice(start, end + 1);
|
|
1982
|
+
}
|
|
1983
|
+
/**
|
|
1984
|
+
* Index of the `}` that closes the object opened at `start`, counting only
|
|
1985
|
+
* braces outside string literals, or `undefined` when the text ends first.
|
|
1986
|
+
*/
|
|
1987
|
+
function find_object_end(text, start) {
|
|
1988
|
+
let depth = 0;
|
|
1989
|
+
for (let i = start; i < text.length; i += 1) {
|
|
1990
|
+
const ch = text[i];
|
|
1991
|
+
if (ch === "\"") i = find_string_end(text, i);
|
|
1992
|
+
else if (ch === "{") depth += 1;
|
|
1993
|
+
else if (ch === "}") {
|
|
1994
|
+
depth -= 1;
|
|
1995
|
+
if (depth === 0) return i;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Index of the quote that closes the string literal opened at `open`,
|
|
2001
|
+
* stepping over backslash escapes, or the text's length when the string
|
|
2002
|
+
* never closes.
|
|
2003
|
+
*/
|
|
2004
|
+
function find_string_end(text, open) {
|
|
2005
|
+
for (let i = open + 1; i < text.length; i += 1) {
|
|
2006
|
+
const ch = text[i];
|
|
2007
|
+
if (ch === "\\") i += 1;
|
|
2008
|
+
else if (ch === "\"") return i;
|
|
2009
|
+
}
|
|
2010
|
+
return text.length;
|
|
1708
2011
|
}
|
|
1709
2012
|
//#endregion
|
|
1710
2013
|
//#region src/composites/regression.ts
|
|
@@ -1809,15 +2112,16 @@ function compute_per_case(current, baseline, score_threshold, cost_threshold) {
|
|
|
1809
2112
|
}
|
|
1810
2113
|
/**
|
|
1811
2114
|
* Compute per-judge score deltas for one case pair across the union of judge
|
|
1812
|
-
* names on both sides
|
|
1813
|
-
*
|
|
2115
|
+
* names on both sides, flagging a regression when any judge's score drops
|
|
2116
|
+
* beyond the threshold. A missing side, or an entry with no finite score,
|
|
2117
|
+
* scores 0 so every delta stays well-defined.
|
|
1814
2118
|
*/
|
|
1815
2119
|
function compute_score_deltas(c, b, score_threshold) {
|
|
1816
2120
|
const score_deltas = {};
|
|
1817
2121
|
let any_regression = false;
|
|
1818
2122
|
const judge_names = /* @__PURE__ */ new Set([...Object.keys(c?.scores ?? {}), ...Object.keys(b?.scores ?? {})]);
|
|
1819
2123
|
for (const name of judge_names) {
|
|
1820
|
-
const delta =
|
|
2124
|
+
const delta = (score_value_of(c?.scores[name]) ?? 0) - (score_value_of(b?.scores[name]) ?? 0);
|
|
1821
2125
|
score_deltas[name] = delta;
|
|
1822
2126
|
if (delta < -score_threshold) any_regression = true;
|
|
1823
2127
|
}
|
|
@@ -1842,21 +2146,6 @@ function compute_cost_regression(c, b, cost_threshold) {
|
|
|
1842
2146
|
};
|
|
1843
2147
|
}
|
|
1844
2148
|
/**
|
|
1845
|
-
* Extract a finite numeric score from a raw score entry.
|
|
1846
|
-
*
|
|
1847
|
-
* Accepts a bare number or an object with a numeric `score` field; anything
|
|
1848
|
-
* else (missing, NaN, non-numeric) counts as 0 so deltas stay well-defined.
|
|
1849
|
-
*/
|
|
1850
|
-
function score_value(s) {
|
|
1851
|
-
if (s === void 0 || s === null) return 0;
|
|
1852
|
-
if (typeof s === "number") return Number.isFinite(s) ? s : 0;
|
|
1853
|
-
if (typeof s === "object" && "score" in s) {
|
|
1854
|
-
const v = s["score"];
|
|
1855
|
-
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
1856
|
-
}
|
|
1857
|
-
return 0;
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
2149
|
* Index case results by their `case_id` for pairwise lookup.
|
|
1861
2150
|
*/
|
|
1862
2151
|
function index_by_case_id(cases) {
|
|
@@ -1899,6 +2188,20 @@ function validate_report(value, path) {
|
|
|
1899
2188
|
if (!Array.isArray(v.cases) || typeof v.summary !== "object" || v.summary === null) throw new Error(`baseline at ${path} missing cases/summary`);
|
|
1900
2189
|
}
|
|
1901
2190
|
//#endregion
|
|
2191
|
+
//#region src/engine/define_tool.ts
|
|
2192
|
+
/**
|
|
2193
|
+
* Define a tool whose `execute` and `needs_approval` receive the input type
|
|
2194
|
+
* `input_schema` validates to, and return it as a plain `Tool` that any
|
|
2195
|
+
* `tools` list accepts. The widening is the one cast, and it is sound because
|
|
2196
|
+
* the tool loop validates every call's input against `input_schema` and
|
|
2197
|
+
* passes `execute` and `needs_approval` the validated value, never the raw
|
|
2198
|
+
* one; a call that fails validation goes back to the model as a tool error
|
|
2199
|
+
* and never reaches the tool. The spec comes back as the same object.
|
|
2200
|
+
*/
|
|
2201
|
+
function define_tool(spec) {
|
|
2202
|
+
return spec;
|
|
2203
|
+
}
|
|
2204
|
+
//#endregion
|
|
1902
2205
|
//#region src/engine/throughput.ts
|
|
1903
2206
|
/**
|
|
1904
2207
|
* Narrow the accepted source union to its array member. A user-defined guard
|
|
@@ -2141,10 +2444,10 @@ function model_call(cfg) {
|
|
|
2141
2444
|
if (cfg.top_p !== void 0) describe_config.top_p = cfg.top_p;
|
|
2142
2445
|
if (cfg.turn_timeout_ms !== void 0) describe_config.turn_timeout_ms = cfg.turn_timeout_ms;
|
|
2143
2446
|
const inner = step(step_id, async (input, ctx) => {
|
|
2144
|
-
if (ctx.abort.aborted)
|
|
2145
|
-
reason
|
|
2146
|
-
|
|
2147
|
-
}
|
|
2447
|
+
if (ctx.abort.aborted) {
|
|
2448
|
+
const reason = ctx.abort.reason;
|
|
2449
|
+
throw reason instanceof Error ? reason : new aborted_error("aborted before model_call", { reason });
|
|
2450
|
+
}
|
|
2148
2451
|
const opts = build_generate_options(cfg, typeof input === "string" ? [{
|
|
2149
2452
|
role: "user",
|
|
2150
2453
|
content: [{
|
|
@@ -2233,6 +2536,6 @@ function forward_standard_env() {
|
|
|
2233
2536
|
return out;
|
|
2234
2537
|
}
|
|
2235
2538
|
//#endregion
|
|
2236
|
-
export { STEP_KINDS, aborted_error, adversarial, assert_valid_step_id, bench, bench_suspend_error, branch, chain, checkpoint, claude_cli_error, claude_cli_reported, compose, consensus, create_engine, default_normalize_usage, describe, describe_cycle_error, durable, engine_config_error, engine_disposed_error, ensemble, ensemble_step, error_path, fallback, flow_changed_error, flow_schema, forward_standard_env, gate, improve, incomplete_generation_error, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step, is_step_kind, is_step_replayed_event, is_valid_step_id, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, model_step, normalize_score, on_chunk_error, parallel, parse_trajectory_event, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, provider_required_error, rate_limit_error, read_baseline, regression_compare, resolve_display_name, resume_validation_error, retry, run, run_not_found_error, schema_validation_error, scope, sequence, stash, step, suggest_step_id, suspend, suspended_error, throughput, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, use, write_baseline };
|
|
2539
|
+
export { STEP_KINDS, aborted_error, adversarial, assert_valid_step_id, bench, bench_suspend_error, branch, chain, checkpoint, claude_cli_error, claude_cli_reported, compose, consensus, create_engine, default_normalize_usage, define_tool, describe, describe_cycle_error, durable, engine_config_error, engine_disposed_error, ensemble, ensemble_step, error_path, fallback, flow_changed_error, flow_schema, forward_standard_env, gate, improve, incomplete_generation_error, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step, is_step_kind, is_step_replayed_event, is_valid_step_id, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, model_step, normalize_score, on_chunk_error, parallel, parse_trajectory_event, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, provider_required_error, rate_limit_error, read_baseline, regression_compare, resolve_display_name, resume_validation_error, retry, run, run_not_found_error, schema_validation_error, scope, sequence, stash, step, suggest_step_id, suspend, suspended_error, throughput, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, turn_timeout_error, use, write_baseline };
|
|
2237
2540
|
|
|
2238
2541
|
//# sourceMappingURL=index.js.map
|