@relayfx/sdk 0.2.11 → 0.2.12
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/dist/ai.js +2 -2
- package/dist/{index-jg4xh3fx.js → index-236a3f4t.js} +12 -6
- package/dist/{index-fhqr1n44.js → index-33d4k6kk.js} +152 -100
- package/dist/{index-tpwr0wmj.js → index-aph699jp.js} +7 -7
- package/dist/index.js +3 -3
- package/dist/sqlite.js +2 -2
- package/dist/types/relay/client.d.ts +4 -2
- package/dist/types/relay/operation.d.ts +33 -3
- package/dist/types/runtime/address/address-resolution-service.d.ts +10 -0
- package/dist/types/runtime/agent/agent-loop-service.d.ts +4 -6
- package/dist/types/runtime/child/child-run-service.d.ts +3 -0
- package/dist/types/runtime/child/spawn-child-run-tool.d.ts +5 -0
- package/dist/types/runtime/workflow/execution-workflow.d.ts +20 -0
- package/dist/types/schema/agent-schema.d.ts +83 -0
- package/dist/types/schema/child-orchestration-schema.d.ts +15 -0
- package/dist/types/schema/execution-schema.d.ts +42 -2
- package/package.json +3 -3
|
@@ -309,6 +309,7 @@ __export(exports_agent_schema, {
|
|
|
309
309
|
DefinitionRecord: () => DefinitionRecord,
|
|
310
310
|
DefinitionList: () => DefinitionList,
|
|
311
311
|
Definition: () => Definition2,
|
|
312
|
+
CompactionPolicy: () => CompactionPolicy,
|
|
312
313
|
ChildRunWorkspacePolicy: () => ChildRunWorkspacePolicy,
|
|
313
314
|
ChildRunPreset: () => ChildRunPreset
|
|
314
315
|
});
|
|
@@ -323,6 +324,12 @@ var ModelSelection = Schema5.Struct({
|
|
|
323
324
|
request_options: Schema5.optionalKey(Metadata),
|
|
324
325
|
metadata: Schema5.optionalKey(Metadata)
|
|
325
326
|
}).annotate({ identifier: "Relay.Agent.ModelSelection" });
|
|
327
|
+
var PositiveSafeInteger = Schema5.Number.check(Schema5.makeFilter((value) => Number.isSafeInteger(value) && value > 0 ? undefined : "must be a positive safe integer"));
|
|
328
|
+
var CompactionPolicy = Schema5.Struct({
|
|
329
|
+
context_window: PositiveSafeInteger,
|
|
330
|
+
reserve_tokens: PositiveSafeInteger,
|
|
331
|
+
keep_recent_tokens: PositiveSafeInteger
|
|
332
|
+
}).check(Schema5.makeFilter((policy) => policy.reserve_tokens + policy.keep_recent_tokens < policy.context_window ? undefined : "reserve_tokens + keep_recent_tokens must be less than context_window")).annotate({ identifier: "Relay.Agent.CompactionPolicy" });
|
|
326
333
|
var ChildRunWorkspacePolicy = Schema5.Struct({
|
|
327
334
|
mode: Schema5.Literals(["share", "fork"]),
|
|
328
335
|
fallback: Schema5.optionalKey(Schema5.Literals(["fail", "fresh"]))
|
|
@@ -330,6 +337,7 @@ var ChildRunWorkspacePolicy = Schema5.Struct({
|
|
|
330
337
|
var ChildRunPreset = Schema5.Struct({
|
|
331
338
|
instructions: Schema5.optionalKey(Schema5.String),
|
|
332
339
|
model: Schema5.optionalKey(ModelSelection),
|
|
340
|
+
compaction_policy: Schema5.optionalKey(CompactionPolicy),
|
|
333
341
|
tool_names: Schema5.optionalKey(Schema5.Array(Schema5.String)),
|
|
334
342
|
permissions: Schema5.optionalKey(Schema5.Array(Schema5.String)),
|
|
335
343
|
workspace_policy: Schema5.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -413,6 +421,7 @@ var DefinitionSchema = Schema5.Struct({
|
|
|
413
421
|
skill_definition_ids: Schema5.optionalKey(Schema5.Array(SkillDefinitionId)),
|
|
414
422
|
permission_rules: Schema5.optionalKey(PermissionRuleset),
|
|
415
423
|
turn_policy: Schema5.optionalKey(TurnPolicySnapshot),
|
|
424
|
+
compaction_policy: Schema5.optionalKey(CompactionPolicy),
|
|
416
425
|
max_tool_turns: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(1))),
|
|
417
426
|
max_wait_turns: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(0))),
|
|
418
427
|
token_budget: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(1))),
|
|
@@ -433,6 +442,7 @@ var define = (input) => ({
|
|
|
433
442
|
...input.skill_definition_ids === undefined ? {} : { skill_definition_ids: input.skill_definition_ids },
|
|
434
443
|
...input.permission_rules === undefined ? {} : { permission_rules: input.permission_rules },
|
|
435
444
|
...input.turn_policy === undefined ? {} : { turn_policy: input.turn_policy },
|
|
445
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
436
446
|
...input.max_tool_turns === undefined ? {} : { max_tool_turns: input.max_tool_turns },
|
|
437
447
|
...input.max_wait_turns === undefined ? {} : { max_wait_turns: input.max_wait_turns },
|
|
438
448
|
...input.token_budget === undefined ? {} : { token_budget: input.token_budget },
|
|
@@ -576,6 +586,7 @@ var ExecutionEventSequence = Schema7.Int.check(Schema7.isGreaterThanOrEqualTo(0)
|
|
|
576
586
|
var ChildRunContext = Schema7.Struct({
|
|
577
587
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
578
588
|
model: Schema7.optionalKey(ModelSelection),
|
|
589
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
579
590
|
tool_names: Schema7.Array(Schema7.String),
|
|
580
591
|
permissions: Schema7.Array(Schema7.String),
|
|
581
592
|
output_schema_ref: Schema7.optionalKey(Schema7.String),
|
|
@@ -584,6 +595,7 @@ var ChildRunContext = Schema7.Struct({
|
|
|
584
595
|
var ChildRunOverride = Schema7.Struct({
|
|
585
596
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
586
597
|
model: Schema7.optionalKey(ModelSelection),
|
|
598
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
587
599
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
588
600
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
589
601
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -600,6 +612,7 @@ var SpawnChildRunInput = Schema7.Struct({
|
|
|
600
612
|
preset_name: Schema7.optionalKey(NonEmptyString),
|
|
601
613
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
602
614
|
model: Schema7.optionalKey(ModelSelection),
|
|
615
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
603
616
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
604
617
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
605
618
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -623,6 +636,7 @@ var ExecutionEventType = Schema7.Literals([
|
|
|
623
636
|
"model.input.prepared",
|
|
624
637
|
"model.output.delta",
|
|
625
638
|
"model.reasoning.delta",
|
|
639
|
+
"model.toolcall.delta",
|
|
626
640
|
"model.output.completed",
|
|
627
641
|
"model.usage.reported",
|
|
628
642
|
"budget.exceeded",
|
|
@@ -11457,7 +11471,7 @@ var resolveLocalAgent = Effect37.fn("AddressResolution.resolveLocalAgent.call")(
|
|
|
11457
11471
|
return yield* service.resolveLocalAgent(addressId);
|
|
11458
11472
|
});
|
|
11459
11473
|
|
|
11460
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11474
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent-event.js
|
|
11461
11475
|
var exports_agent_event = {};
|
|
11462
11476
|
__export(exports_agent_event, {
|
|
11463
11477
|
addUsage: () => addUsage,
|
|
@@ -11514,7 +11528,7 @@ class AgentSuspended extends Schema52.TaggedErrorClass()("@batonfx/core/AgentSus
|
|
|
11514
11528
|
}) {
|
|
11515
11529
|
}
|
|
11516
11530
|
|
|
11517
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11531
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-context.js
|
|
11518
11532
|
var exports_tool_context = {};
|
|
11519
11533
|
__export(exports_tool_context, {
|
|
11520
11534
|
testLayer: () => testLayer32,
|
|
@@ -11532,7 +11546,7 @@ var layerDefault = Layer35.sync(ToolContext, () => ToolContext.of({
|
|
|
11532
11546
|
}));
|
|
11533
11547
|
var testLayer32 = (implementation) => Layer35.succeed(ToolContext, ToolContext.of(implementation));
|
|
11534
11548
|
|
|
11535
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11549
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-executor.js
|
|
11536
11550
|
var exports_tool_executor = {};
|
|
11537
11551
|
__export(exports_tool_executor, {
|
|
11538
11552
|
testLayer: () => testLayer33,
|
|
@@ -11659,7 +11673,7 @@ function router(routes) {
|
|
|
11659
11673
|
}
|
|
11660
11674
|
var testLayer33 = (implementation) => Layer36.succeed(ToolExecutor, ToolExecutor.of(implementation));
|
|
11661
11675
|
|
|
11662
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11676
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/approvals.js
|
|
11663
11677
|
var exports_approvals = {};
|
|
11664
11678
|
__export(exports_approvals, {
|
|
11665
11679
|
testLayer: () => testLayer34,
|
|
@@ -11674,7 +11688,7 @@ var autoApprove = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect4
|
|
|
11674
11688
|
var denyAll = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect40.succeed({ _tag: "Denied" }) }));
|
|
11675
11689
|
var testLayer34 = (implementation) => Layer37.succeed(Approvals, Approvals.of(implementation));
|
|
11676
11690
|
|
|
11677
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11691
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/session.js
|
|
11678
11692
|
var exports_session = {};
|
|
11679
11693
|
__export(exports_session, {
|
|
11680
11694
|
testLayer: () => testLayer35,
|
|
@@ -11847,7 +11861,7 @@ var memoryLayer32 = Layer38.effect(SessionStore, Ref10.make(initialState).pipe(E
|
|
|
11847
11861
|
}))));
|
|
11848
11862
|
var testLayer35 = (implementation) => Layer38.succeed(SessionStore, SessionStore.of(implementation));
|
|
11849
11863
|
|
|
11850
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11864
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-output.js
|
|
11851
11865
|
var exports_tool_output = {};
|
|
11852
11866
|
__export(exports_tool_output, {
|
|
11853
11867
|
testLayer: () => testLayer36,
|
|
@@ -11906,7 +11920,7 @@ var bound = (result, options) => Effect42.gen(function* () {
|
|
|
11906
11920
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
11907
11921
|
});
|
|
11908
11922
|
|
|
11909
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11923
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/compaction.js
|
|
11910
11924
|
var exports_compaction = {};
|
|
11911
11925
|
__export(exports_compaction, {
|
|
11912
11926
|
truncate: () => truncate,
|
|
@@ -12177,7 +12191,7 @@ var truncate = (maxTokens) => ({
|
|
|
12177
12191
|
var testLayer37 = (implementation) => Layer40.succeed(Compaction, Compaction.of(implementation));
|
|
12178
12192
|
var isContextOverflow = (error5) => /context|token|prompt/i.test(error5 instanceof Error ? `${error5.name}: ${error5.message}` : String(error5)) && /overflow|exceed|exceeded|maximum|too large|too long|length/i.test(error5 instanceof Error ? `${error5.name}: ${error5.message}` : String(error5));
|
|
12179
12193
|
|
|
12180
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12194
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/instructions.js
|
|
12181
12195
|
var exports_instructions = {};
|
|
12182
12196
|
__export(exports_instructions, {
|
|
12183
12197
|
testLayer: () => testLayer38,
|
|
@@ -12225,7 +12239,7 @@ var renderUpdate = (epoch, context) => Effect44.gen(function* () {
|
|
|
12225
12239
|
var layer33 = (sources) => Layer41.succeed(Instructions, Instructions.of({ sources: [...sources] }));
|
|
12226
12240
|
var testLayer38 = (implementation) => Layer41.succeed(Instructions, Instructions.of(implementation));
|
|
12227
12241
|
|
|
12228
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12242
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/memory.js
|
|
12229
12243
|
var exports_memory = {};
|
|
12230
12244
|
__export(exports_memory, {
|
|
12231
12245
|
testLayer: () => testLayer39,
|
|
@@ -12257,7 +12271,7 @@ var merge = (first, second) => ({
|
|
|
12257
12271
|
var noopLayer = Layer42.succeed(Memory, Memory.of(noop));
|
|
12258
12272
|
var testLayer39 = (implementation) => Layer42.succeed(Memory, Memory.of(implementation));
|
|
12259
12273
|
|
|
12260
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12274
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-middleware.js
|
|
12261
12275
|
var exports_model_middleware = {};
|
|
12262
12276
|
__export(exports_model_middleware, {
|
|
12263
12277
|
layer: () => layer34,
|
|
@@ -12271,7 +12285,7 @@ class ModelMiddleware extends Context43.Service()("@batonfx/core/ModelMiddleware
|
|
|
12271
12285
|
var identityLayer = Layer43.succeed(ModelMiddleware, []);
|
|
12272
12286
|
var layer34 = (middleware) => Layer43.succeed(ModelMiddleware, middleware);
|
|
12273
12287
|
|
|
12274
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12288
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-registry.js
|
|
12275
12289
|
var exports_model_registry = {};
|
|
12276
12290
|
__export(exports_model_registry, {
|
|
12277
12291
|
testLayer: () => testLayer40,
|
|
@@ -12360,7 +12374,7 @@ var provide = (selection, effect) => Effect47.gen(function* () {
|
|
|
12360
12374
|
return yield* service.provide(selection, effect);
|
|
12361
12375
|
});
|
|
12362
12376
|
|
|
12363
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12377
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-resilience.js
|
|
12364
12378
|
var exports_model_resilience = {};
|
|
12365
12379
|
__export(exports_model_resilience, {
|
|
12366
12380
|
testLayer: () => testLayer41,
|
|
@@ -12406,7 +12420,7 @@ var apply = (model, resilience) => ({
|
|
|
12406
12420
|
}).pipe(Stream8.retry(retryStreamSchedule(resilience)))
|
|
12407
12421
|
});
|
|
12408
12422
|
|
|
12409
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12423
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/permissions.js
|
|
12410
12424
|
var exports_permissions = {};
|
|
12411
12425
|
__export(exports_permissions, {
|
|
12412
12426
|
testLayer: () => testLayer42,
|
|
@@ -12536,7 +12550,7 @@ var ruleStoreMemory = (initialRules = []) => Layer46.effect(RuleStore, Ref13.mak
|
|
|
12536
12550
|
var ruleStoreTestLayer = (implementation) => Layer46.succeed(RuleStore, RuleStore.of(implementation));
|
|
12537
12551
|
var testLayer42 = (implementation) => Layer46.succeed(Permissions, Permissions.of(implementation));
|
|
12538
12552
|
|
|
12539
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12553
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/skill-source.js
|
|
12540
12554
|
var exports_skill_source = {};
|
|
12541
12555
|
__export(exports_skill_source, {
|
|
12542
12556
|
testLayer: () => testLayer43,
|
|
@@ -12616,7 +12630,7 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
12616
12630
|
return selected;
|
|
12617
12631
|
};
|
|
12618
12632
|
|
|
12619
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12633
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/steering.js
|
|
12620
12634
|
var exports_steering = {};
|
|
12621
12635
|
__export(exports_steering, {
|
|
12622
12636
|
testLayer: () => testLayer44,
|
|
@@ -12674,7 +12688,7 @@ var layer38 = (options = {}) => Layer48.effect(Steering, Effect51.gen(function*
|
|
|
12674
12688
|
}));
|
|
12675
12689
|
var testLayer44 = (implementation) => Layer48.succeed(Steering, Steering.of(implementation));
|
|
12676
12690
|
|
|
12677
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12691
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/turn-policy.js
|
|
12678
12692
|
var exports_turn_policy = {};
|
|
12679
12693
|
__export(exports_turn_policy, {
|
|
12680
12694
|
untilToolCall: () => untilToolCall,
|
|
@@ -12723,7 +12737,7 @@ var both = (first, second) => ({
|
|
|
12723
12737
|
});
|
|
12724
12738
|
var defaultPolicy = recurs(8);
|
|
12725
12739
|
|
|
12726
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12740
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent.js
|
|
12727
12741
|
var exports_agent = {};
|
|
12728
12742
|
__export(exports_agent, {
|
|
12729
12743
|
streamObject: () => streamObject,
|
|
@@ -12920,8 +12934,7 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12920
12934
|
turn: 0,
|
|
12921
12935
|
pending: [],
|
|
12922
12936
|
finish: undefined,
|
|
12923
|
-
usage: undefined
|
|
12924
|
-
contextTokens: undefined
|
|
12937
|
+
usage: undefined
|
|
12925
12938
|
};
|
|
12926
12939
|
const activatedSkillBodies = new Map;
|
|
12927
12940
|
const activatedSkillTools = new Map;
|
|
@@ -12972,10 +12985,8 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12972
12985
|
})
|
|
12973
12986
|
});
|
|
12974
12987
|
const countTokens = (turn, prompt) => {
|
|
12975
|
-
if (state.contextTokens !== undefined)
|
|
12976
|
-
return Effect53.succeed(state.contextTokens);
|
|
12977
12988
|
return Option18.match(tokenizerService, {
|
|
12978
|
-
onNone: () => Effect53.succeed(
|
|
12989
|
+
onNone: () => Effect53.succeed(Math.ceil(JSON.stringify(prompt.content).length / 4)),
|
|
12979
12990
|
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(Effect53.map((tokens) => tokens.length), Effect53.mapError((error5) => new AgentError({ message: errorMessage(error5), turn, cause: error5 })))
|
|
12980
12991
|
});
|
|
12981
12992
|
};
|
|
@@ -13184,7 +13195,6 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
13184
13195
|
reason: part.reason
|
|
13185
13196
|
};
|
|
13186
13197
|
state.usage = state.usage === undefined ? part.usage : addUsage(state.usage, part.usage);
|
|
13187
|
-
state.contextTokens = part.usage.inputTokens.total ?? state.contextTokens;
|
|
13188
13198
|
Telemetry.addGenAIAnnotations(span, {
|
|
13189
13199
|
operation: { name: "chat" },
|
|
13190
13200
|
usage: {
|
|
@@ -13438,7 +13448,7 @@ var generateObject = (agent, options) => Stream9.runFold(streamObject(agent, opt
|
|
|
13438
13448
|
})
|
|
13439
13449
|
})));
|
|
13440
13450
|
|
|
13441
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13451
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent-tool.js
|
|
13442
13452
|
var exports_agent_tool = {};
|
|
13443
13453
|
__export(exports_agent_tool, {
|
|
13444
13454
|
asTool: () => asTool
|
|
@@ -13494,7 +13504,7 @@ var asTool = (agent, options = {}) => {
|
|
|
13494
13504
|
return lazyHandled(toolkit, name, handler);
|
|
13495
13505
|
};
|
|
13496
13506
|
|
|
13497
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13507
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/guardrail.js
|
|
13498
13508
|
var exports_guardrail = {};
|
|
13499
13509
|
__export(exports_guardrail, {
|
|
13500
13510
|
validateInput: () => validateInput2,
|
|
@@ -13575,7 +13585,7 @@ var filterOutput = (keep) => ({
|
|
|
13575
13585
|
transformPart: (part, context) => Effect55.succeed(part.type === "tool-call" || keep(part, context) ? Option19.some(part) : Option19.none())
|
|
13576
13586
|
});
|
|
13577
13587
|
|
|
13578
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13588
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/handoff.js
|
|
13579
13589
|
var exports_handoff = {};
|
|
13580
13590
|
__export(exports_handoff, {
|
|
13581
13591
|
transferTool: () => transferTool,
|
|
@@ -13639,7 +13649,7 @@ var supervisor = (options) => {
|
|
|
13639
13649
|
};
|
|
13640
13650
|
};
|
|
13641
13651
|
|
|
13642
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13652
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/index.js
|
|
13643
13653
|
import { AiError as AiError3, Chat as Chat2, EmbeddingModel, IdGenerator, LanguageModel as LanguageModel6, Model as Model2, Prompt as Prompt12, Response as Response8, ResponseIdTracker, Telemetry as Telemetry2, Tokenizer as Tokenizer3, Tool as Tool8, Toolkit as Toolkit7 } from "effect/unstable/ai";
|
|
13644
13654
|
|
|
13645
13655
|
// ../runtime/src/child/child-run-service.ts
|
|
@@ -13750,6 +13760,7 @@ var resolveContext = (parent, override) => {
|
|
|
13750
13760
|
const permissions = override?.permissions ?? parent.permissions;
|
|
13751
13761
|
const instructions = override?.instructions ?? parent.instructions;
|
|
13752
13762
|
const model = override?.model ?? parent.model;
|
|
13763
|
+
const compactionPolicy = override?.compactionPolicy ?? parent.compactionPolicy;
|
|
13753
13764
|
const workspacePolicy = override?.workspacePolicy;
|
|
13754
13765
|
const outputSchemaRef = override?.outputSchemaRef ?? parent.outputSchemaRef;
|
|
13755
13766
|
const broadenedTool = subsetViolation(parent.toolNames, toolNames);
|
|
@@ -13769,6 +13780,7 @@ var resolveContext = (parent, override) => {
|
|
|
13769
13780
|
},
|
|
13770
13781
|
...instructions === undefined ? {} : { instructions },
|
|
13771
13782
|
...model === undefined ? {} : { model },
|
|
13783
|
+
...compactionPolicy === undefined ? {} : { compactionPolicy },
|
|
13772
13784
|
...workspacePolicy === undefined ? {} : { workspacePolicy },
|
|
13773
13785
|
...outputSchemaRef === undefined ? {} : { outputSchemaRef }
|
|
13774
13786
|
});
|
|
@@ -13916,12 +13928,14 @@ var agentContextFromSchema = (input) => ({
|
|
|
13916
13928
|
permissions: input.permissions,
|
|
13917
13929
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13918
13930
|
...input.model === undefined ? {} : { model: input.model },
|
|
13931
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13919
13932
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
13920
13933
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13921
13934
|
});
|
|
13922
13935
|
var overrideFromSchema = (input) => ({
|
|
13923
13936
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13924
13937
|
...input.model === undefined ? {} : { model: input.model },
|
|
13938
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13925
13939
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
13926
13940
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
13927
13941
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -13929,7 +13943,7 @@ var overrideFromSchema = (input) => ({
|
|
|
13929
13943
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13930
13944
|
});
|
|
13931
13945
|
var dynamicOverrideFromSpawn = (input) => {
|
|
13932
|
-
if (input.instructions === undefined && input.model === undefined && input.tool_names === undefined && input.permissions === undefined && input.workspace_policy === undefined && input.output_schema_ref === undefined && input.metadata === undefined) {
|
|
13946
|
+
if (input.instructions === undefined && input.model === undefined && input.compaction_policy === undefined && input.tool_names === undefined && input.permissions === undefined && input.workspace_policy === undefined && input.output_schema_ref === undefined && input.metadata === undefined) {
|
|
13933
13947
|
return;
|
|
13934
13948
|
}
|
|
13935
13949
|
return overrideFromSchema(input);
|
|
@@ -13951,6 +13965,7 @@ var childDefinition = (parentDefinition, context) => context.model === undefined
|
|
|
13951
13965
|
tool_names: [...context.toolNames],
|
|
13952
13966
|
permissions: parentDefinition.permissions.filter((permission) => context.permissions.includes(permission.name)),
|
|
13953
13967
|
child_run_presets: {},
|
|
13968
|
+
...context.compactionPolicy === undefined ? {} : { compaction_policy: context.compactionPolicy },
|
|
13954
13969
|
...parentDefinition.turn_policy === undefined ? {} : { turn_policy: parentDefinition.turn_policy },
|
|
13955
13970
|
...parentDefinition.max_tool_turns === undefined ? {} : { max_tool_turns: parentDefinition.max_tool_turns },
|
|
13956
13971
|
...parentDefinition.max_wait_turns === undefined ? {} : { max_wait_turns: parentDefinition.max_wait_turns },
|
|
@@ -14531,12 +14546,14 @@ var childContext = (input) => ({
|
|
|
14531
14546
|
permissions: input.permissions,
|
|
14532
14547
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14533
14548
|
...input.model === undefined ? {} : { model: input.model },
|
|
14549
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14534
14550
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
14535
14551
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
14536
14552
|
});
|
|
14537
14553
|
var childOverride = (input) => ({
|
|
14538
14554
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14539
14555
|
...input.model === undefined ? {} : { model: input.model },
|
|
14556
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14540
14557
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
14541
14558
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14542
14559
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -14544,12 +14561,13 @@ var childOverride = (input) => ({
|
|
|
14544
14561
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
14545
14562
|
});
|
|
14546
14563
|
var dynamicOverride = (input) => {
|
|
14547
|
-
if (input.instructions === undefined && input.model === undefined && input.tool_names === undefined && input.permissions === undefined && input.workspace_policy === undefined && input.output_schema_ref === undefined && input.metadata === undefined) {
|
|
14564
|
+
if (input.instructions === undefined && input.model === undefined && input.compaction_policy === undefined && input.tool_names === undefined && input.permissions === undefined && input.workspace_policy === undefined && input.output_schema_ref === undefined && input.metadata === undefined) {
|
|
14548
14565
|
return;
|
|
14549
14566
|
}
|
|
14550
14567
|
return childOverride({
|
|
14551
14568
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14552
14569
|
...input.model === undefined ? {} : { model: input.model },
|
|
14570
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
14553
14571
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
14554
14572
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14555
14573
|
...input.workspace_policy === undefined ? {} : { workspace_policy: input.workspace_policy },
|
|
@@ -14866,8 +14884,8 @@ __export(exports_agent_loop_service, {
|
|
|
14866
14884
|
AgentLoopError: () => AgentLoopError,
|
|
14867
14885
|
AgentLoopBudgetExceeded: () => AgentLoopBudgetExceeded
|
|
14868
14886
|
});
|
|
14869
|
-
import { Config as Config4, Context as Context67, Crypto as Crypto3, Effect as Effect87, HashSet as HashSet6, Layer as Layer73, Option as Option25, Ref as Ref21, Schema as Schema89, Stream as Stream12 } from "effect";
|
|
14870
|
-
import { Chat as Chat3, LanguageModel as LanguageModel7, Prompt as Prompt16, Tokenizer as Tokenizer4, Toolkit as Toolkit8 } from "effect/unstable/ai";
|
|
14887
|
+
import { Cause as Cause5, Config as Config4, Context as Context67, Crypto as Crypto3, Effect as Effect87, HashSet as HashSet6, Layer as Layer73, Option as Option25, Ref as Ref21, Schema as Schema89, Stream as Stream12 } from "effect";
|
|
14888
|
+
import { AiError as AiError5, Chat as Chat3, LanguageModel as LanguageModel7, Prompt as Prompt16, Tokenizer as Tokenizer4, Toolkit as Toolkit8 } from "effect/unstable/ai";
|
|
14871
14889
|
|
|
14872
14890
|
// ../runtime/src/child/spawn-child-run-tool.ts
|
|
14873
14891
|
import { Effect as Effect66, Schema as Schema73 } from "effect";
|
|
@@ -14877,6 +14895,7 @@ var Input2 = Schema73.Struct({
|
|
|
14877
14895
|
preset_name: Schema73.optionalKey(exports_shared_schema.NonEmptyString),
|
|
14878
14896
|
instructions: Schema73.optionalKey(Schema73.String),
|
|
14879
14897
|
model: Schema73.optionalKey(exports_agent_schema.ModelSelection),
|
|
14898
|
+
compaction_policy: Schema73.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
14880
14899
|
tool_names: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14881
14900
|
permissions: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14882
14901
|
output_schema_ref: Schema73.optionalKey(Schema73.String),
|
|
@@ -14899,6 +14918,7 @@ var ModelInput = Schema73.Struct({
|
|
|
14899
14918
|
model: Schema73.String,
|
|
14900
14919
|
registration_key: Schema73.optionalKey(Schema73.String)
|
|
14901
14920
|
}))),
|
|
14921
|
+
compaction_policy: Schema73.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
14902
14922
|
tool_names: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14903
14923
|
permissions: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14904
14924
|
output_schema_ref: Schema73.optionalKey(Schema73.NullOr(Schema73.String)),
|
|
@@ -14920,6 +14940,7 @@ var enabled = (agent) => agent.metadata?.multi_agent_enabled === true;
|
|
|
14920
14940
|
var parentContext = (agent) => ({
|
|
14921
14941
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
14922
14942
|
model: agent.model,
|
|
14943
|
+
...agent.compaction_policy === undefined ? {} : { compaction_policy: agent.compaction_policy },
|
|
14923
14944
|
tool_names: agent.tool_names,
|
|
14924
14945
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
14925
14946
|
...agent.output_schema_ref === undefined ? {} : { output_schema_ref: agent.output_schema_ref },
|
|
@@ -14928,12 +14949,13 @@ var parentContext = (agent) => ({
|
|
|
14928
14949
|
var serviceParentContext = (agent) => ({
|
|
14929
14950
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
14930
14951
|
model: agent.model,
|
|
14952
|
+
...agent.compaction_policy === undefined ? {} : { compactionPolicy: agent.compaction_policy },
|
|
14931
14953
|
toolNames: agent.tool_names,
|
|
14932
14954
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
14933
14955
|
...agent.output_schema_ref === undefined ? {} : { outputSchemaRef: agent.output_schema_ref },
|
|
14934
14956
|
...agent.metadata === undefined ? {} : { metadata: agent.metadata }
|
|
14935
14957
|
});
|
|
14936
|
-
var hasDynamicOverride = (input) => input.instructions !== undefined || input.model !== undefined || input.tool_names !== undefined || input.permissions !== undefined || input.output_schema_ref !== undefined || input.metadata !== undefined;
|
|
14958
|
+
var hasDynamicOverride = (input) => input.instructions !== undefined || input.model !== undefined || input.compaction_policy !== undefined || input.tool_names !== undefined || input.permissions !== undefined || input.output_schema_ref !== undefined || input.metadata !== undefined;
|
|
14937
14959
|
var childExecutionId2 = (context) => exports_ids_schema.ChildExecutionId.make(`${context.executionId}:child:${context.call.id}`);
|
|
14938
14960
|
var childAddressId = (id2) => exports_ids_schema.AddressId.make(`address:child:${id2}`);
|
|
14939
14961
|
var childWaitId = (id2) => exports_ids_schema.WaitId.make(`wait:child:${id2}`);
|
|
@@ -14949,6 +14971,7 @@ var spawnInput = (config, input, context, id2) => ({
|
|
|
14949
14971
|
...input.preset_name === undefined ? {} : { preset_name: input.preset_name },
|
|
14950
14972
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14951
14973
|
...input.model === undefined ? {} : { model: input.model },
|
|
14974
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
14952
14975
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
14953
14976
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14954
14977
|
...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
|
|
@@ -14968,6 +14991,7 @@ var childOverride2 = (input) => {
|
|
|
14968
14991
|
return {
|
|
14969
14992
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14970
14993
|
...input.model === undefined ? {} : { model: input.model },
|
|
14994
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14971
14995
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
14972
14996
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14973
14997
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
@@ -14979,6 +15003,7 @@ var presetMap2 = (agent) => new Map(Object.entries(agent.child_run_presets ?? {}
|
|
|
14979
15003
|
{
|
|
14980
15004
|
...preset.instructions === undefined ? {} : { instructions: preset.instructions },
|
|
14981
15005
|
...preset.model === undefined ? {} : { model: preset.model },
|
|
15006
|
+
...preset.compaction_policy === undefined ? {} : { compactionPolicy: preset.compaction_policy },
|
|
14982
15007
|
...preset.tool_names === undefined ? {} : { toolNames: preset.tool_names },
|
|
14983
15008
|
...preset.permissions === undefined ? {} : { permissions: preset.permissions },
|
|
14984
15009
|
...preset.workspace_policy === undefined ? {} : { workspacePolicy: preset.workspace_policy },
|
|
@@ -17096,6 +17121,20 @@ var reasoningDeltaEvent = (input, part, deltaIndex) => {
|
|
|
17096
17121
|
created_at: input.startedAt + deltaIndex + 1
|
|
17097
17122
|
};
|
|
17098
17123
|
};
|
|
17124
|
+
var toolCallDeltaEvent = (input, part, toolCallName, sequence, deltaIndex) => ({
|
|
17125
|
+
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`),
|
|
17126
|
+
execution_id: input.executionId,
|
|
17127
|
+
type: "model.toolcall.delta",
|
|
17128
|
+
sequence,
|
|
17129
|
+
cursor: `${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`,
|
|
17130
|
+
data: {
|
|
17131
|
+
tool_call_id: part.id,
|
|
17132
|
+
...toolCallName === undefined ? {} : { tool_name: toolCallName },
|
|
17133
|
+
delta: part.delta,
|
|
17134
|
+
delta_index: deltaIndex
|
|
17135
|
+
},
|
|
17136
|
+
created_at: input.startedAt + (sequence - input.eventSequence)
|
|
17137
|
+
});
|
|
17099
17138
|
var outputCompletedEvent = (input, content, outputText, sequence, structuredOutput) => ({
|
|
17100
17139
|
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:output-completed`),
|
|
17101
17140
|
execution_id: input.executionId,
|
|
@@ -17169,6 +17208,35 @@ var restoreHistory = Effect87.fn("AgentLoop.restoreHistory")(function* (chats, i
|
|
|
17169
17208
|
const chat = yield* Chat3.fromExport(record2.exportData).pipe(Effect87.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17170
17209
|
return yield* Ref21.get(chat.history);
|
|
17171
17210
|
});
|
|
17211
|
+
var toolCallDecodeMaxRetriesConfig = Config4.int("RELAY_AGENT_TOOL_CALL_DECODE_MAX_RETRIES").pipe(Config4.withDefault(2));
|
|
17212
|
+
var isToolCallDecodeError = (error5) => AiError5.isAiError(error5) && error5.method === "streamText" && error5.reason._tag === "InvalidOutputError";
|
|
17213
|
+
var toolCallDecodeFeedback = (error5, availableToolNames) => {
|
|
17214
|
+
const tools = availableToolNames.length === 0 ? "(no tools are available)" : availableToolNames.join(", ");
|
|
17215
|
+
return Prompt16.fromMessages([
|
|
17216
|
+
Prompt16.makeMessage("user", {
|
|
17217
|
+
content: [
|
|
17218
|
+
Prompt16.makePart("text", {
|
|
17219
|
+
text: `Your previous response contained an invalid tool call: ${error5.reason.message}. Only call these tools with arguments matching their input schemas: ${tools}. Re-issue the intended tool calls.`
|
|
17220
|
+
})
|
|
17221
|
+
]
|
|
17222
|
+
})
|
|
17223
|
+
]);
|
|
17224
|
+
};
|
|
17225
|
+
var withToolCallDecodeResilience = (base2, availableToolNames, maxRetries) => ({
|
|
17226
|
+
...base2,
|
|
17227
|
+
streamText: (options) => {
|
|
17228
|
+
const attempt = (prompt, retriesLeft) => Stream12.suspend(() => {
|
|
17229
|
+
let emitted = false;
|
|
17230
|
+
return base2.streamText({ ...options, prompt }).pipe(Stream12.tap(() => Effect87.sync(() => void (emitted = true))), Stream12.catchCause((cause) => {
|
|
17231
|
+
if (Cause5.hasInterrupts(cause))
|
|
17232
|
+
return Stream12.failCause(cause);
|
|
17233
|
+
const error5 = Cause5.squash(cause);
|
|
17234
|
+
return !emitted && retriesLeft > 0 && isToolCallDecodeError(error5) ? attempt(Prompt16.concat(Prompt16.make(prompt), toolCallDecodeFeedback(error5, availableToolNames)), retriesLeft - 1) : Stream12.failCause(cause);
|
|
17235
|
+
}));
|
|
17236
|
+
});
|
|
17237
|
+
return attempt(options.prompt, maxRetries);
|
|
17238
|
+
}
|
|
17239
|
+
});
|
|
17172
17240
|
var saveContextEpoch = Effect87.fn("AgentLoop.saveContextEpoch")(function* (epochs, input, epoch) {
|
|
17173
17241
|
yield* epochs.save({
|
|
17174
17242
|
executionId: input.executionId,
|
|
@@ -17249,20 +17317,11 @@ var decodeOptionalNumber = (value, key4, valid) => {
|
|
|
17249
17317
|
return Effect87.fail(new AgentLoopError({ message: `${key4} metadata value is invalid` }));
|
|
17250
17318
|
};
|
|
17251
17319
|
var effectiveToolOutputMaxBytes = (input) => input.toolOutputMaxBytes !== undefined ? Effect87.succeed(input.toolOutputMaxBytes ?? undefined) : decodeOptionalNumber(metadataValue(input.agent.metadata, "tool_output_max_bytes"), "tool_output_max_bytes", (value) => value >= 0);
|
|
17252
|
-
var
|
|
17253
|
-
|
|
17254
|
-
|
|
17255
|
-
|
|
17256
|
-
|
|
17257
|
-
const reserveTokens = yield* decodeOptionalNumber(metadataValue(input.agent.metadata, "compaction_reserve_tokens"), "compaction_reserve_tokens", (value) => value >= 0);
|
|
17258
|
-
const keepRecentTokens = yield* decodeOptionalNumber(metadataValue(input.agent.metadata, "compaction_keep_recent_tokens"), "compaction_keep_recent_tokens", (value) => value >= 0);
|
|
17259
|
-
return {
|
|
17260
|
-
...contextWindow === undefined ? {} : { contextWindow },
|
|
17261
|
-
...reserveTokens === undefined ? {} : { reserveTokens },
|
|
17262
|
-
...keepRecentTokens === undefined ? {} : { keepRecentTokens }
|
|
17263
|
-
};
|
|
17264
|
-
});
|
|
17265
|
-
var effectiveCompactionOptions = (input) => input.compaction !== undefined ? Effect87.succeed(input.compaction ?? undefined) : compactionOptionsFromAgentMetadata(input);
|
|
17320
|
+
var compactionOptions = (agent) => agent.compaction_policy === undefined ? undefined : {
|
|
17321
|
+
contextWindow: agent.compaction_policy.context_window,
|
|
17322
|
+
reserveTokens: agent.compaction_policy.reserve_tokens,
|
|
17323
|
+
keepRecentTokens: agent.compaction_policy.keep_recent_tokens
|
|
17324
|
+
};
|
|
17266
17325
|
var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
17267
17326
|
const eventLog = yield* Service30;
|
|
17268
17327
|
const languageModels = yield* Service38;
|
|
@@ -17321,9 +17380,11 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17321
17380
|
const registered = [...availableRegisteredTools(input.agent, yield* tools.registeredTools), ...allCoreTools];
|
|
17322
17381
|
const definitions2 = registered.map((tool2) => tool2.definition);
|
|
17323
17382
|
yield* validateToolInputSchemaDigests(input, definitions2);
|
|
17383
|
+
const toolCallDecodeMaxRetries = yield* toolCallDecodeMaxRetriesConfig.pipe(Effect87.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17324
17384
|
yield* appendEvent(eventLog, inputPreparedEvent(input, definitions2), input.eventSequence + 1);
|
|
17325
17385
|
const toolOutputMaxBytes = yield* effectiveToolOutputMaxBytes(input);
|
|
17326
|
-
const
|
|
17386
|
+
const compactionPolicy = input.agent.compaction_policy;
|
|
17387
|
+
const activeCompactionOptions = compactionOptions(input.agent);
|
|
17327
17388
|
const runTokenizer = yield* Effect87.serviceOption(Tokenizer4.Tokenizer);
|
|
17328
17389
|
const activeTokenizer = Option25.isSome(runTokenizer) ? runTokenizer : tokenizer;
|
|
17329
17390
|
const allocator = yield* make12(input.eventSequence + 1);
|
|
@@ -17396,25 +17457,25 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17396
17457
|
next_event_sequence: input.eventSequence + 1
|
|
17397
17458
|
}));
|
|
17398
17459
|
}
|
|
17399
|
-
if (
|
|
17460
|
+
if (activeCompactionOptions !== undefined && input.sessionId === undefined) {
|
|
17400
17461
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17401
17462
|
message: "Execution compaction requires session_id",
|
|
17402
17463
|
next_event_sequence: input.eventSequence + 1
|
|
17403
17464
|
}));
|
|
17404
17465
|
}
|
|
17405
|
-
if (
|
|
17466
|
+
if (activeCompactionOptions !== undefined && Option25.isNone(sessionRepository)) {
|
|
17406
17467
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17407
17468
|
message: "Execution compaction requires SessionRepository in context",
|
|
17408
17469
|
next_event_sequence: input.eventSequence + 1
|
|
17409
17470
|
}));
|
|
17410
17471
|
}
|
|
17411
|
-
if (
|
|
17472
|
+
if (activeCompactionOptions !== undefined && Option25.isNone(compactionRepository)) {
|
|
17412
17473
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17413
17474
|
message: "Execution compaction requires CompactionRepository in context",
|
|
17414
17475
|
next_event_sequence: input.eventSequence + 1
|
|
17415
17476
|
}));
|
|
17416
17477
|
}
|
|
17417
|
-
const batonCompaction =
|
|
17478
|
+
const batonCompaction = compactionPolicy === undefined ? undefined : { contextWindow: compactionPolicy.context_window };
|
|
17418
17479
|
const batonOptions = {
|
|
17419
17480
|
...options,
|
|
17420
17481
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
@@ -17433,12 +17494,12 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17433
17494
|
...allCoreTools.length === 0 ? {} : { extraTools: allCoreTools }
|
|
17434
17495
|
});
|
|
17435
17496
|
const activeBlobStore = toolOutputMaxBytes === undefined || Option25.isNone(blobStore) ? undefined : blobStore.value;
|
|
17436
|
-
const activeCompactionRepository =
|
|
17497
|
+
const activeCompactionRepository = activeCompactionOptions === undefined || Option25.isNone(compactionRepository) ? undefined : compactionRepository.value;
|
|
17437
17498
|
const toolOutputStore = toolOutputMaxBytes === undefined ? undefined : exports_tool_output.ToolOutputStore.of(make11(activeBlobStore));
|
|
17438
|
-
const compactionService =
|
|
17499
|
+
const compactionService = activeCompactionOptions === undefined ? undefined : exports_compaction.Compaction.of(make9({
|
|
17439
17500
|
executionId: input.executionId,
|
|
17440
17501
|
repository: activeCompactionRepository,
|
|
17441
|
-
options:
|
|
17502
|
+
options: activeCompactionOptions
|
|
17442
17503
|
}));
|
|
17443
17504
|
if (memory !== undefined && Option25.isNone(durableMemory)) {
|
|
17444
17505
|
return yield* Effect87.fail(new AgentLoopError({
|
|
@@ -17446,6 +17507,16 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17446
17507
|
next_event_sequence: input.eventSequence + 1
|
|
17447
17508
|
}));
|
|
17448
17509
|
}
|
|
17510
|
+
const tokenBudget = input.agent.token_budget;
|
|
17511
|
+
const enforceBudget = (state) => tokenBudget === undefined || state.tokensUsed < tokenBudget ? Effect87.void : Effect87.gen(function* () {
|
|
17512
|
+
const budgetSequence = yield* allocator.allocate(1);
|
|
17513
|
+
yield* appendEvent(eventLog, budgetExceededEvent(input, state.tokensUsed, tokenBudget, budgetSequence), budgetSequence + 1);
|
|
17514
|
+
return yield* Effect87.fail(new AgentLoopBudgetExceeded({
|
|
17515
|
+
tokens_used: state.tokensUsed,
|
|
17516
|
+
token_budget: tokenBudget,
|
|
17517
|
+
next_event_sequence: budgetSequence + 1
|
|
17518
|
+
}));
|
|
17519
|
+
});
|
|
17449
17520
|
const foldEvent = (state, event) => Effect87.gen(function* () {
|
|
17450
17521
|
switch (event._tag) {
|
|
17451
17522
|
case "ModelPart": {
|
|
@@ -17462,6 +17533,18 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17462
17533
|
yield* appendEvent(eventLog, reasoningDeltaEvent(input, part, deltaIndex), sequence + 1);
|
|
17463
17534
|
return state;
|
|
17464
17535
|
}
|
|
17536
|
+
if (part.type === "tool-params-start") {
|
|
17537
|
+
return { ...state, toolCallNames: { ...state.toolCallNames, [part.id]: part.name } };
|
|
17538
|
+
}
|
|
17539
|
+
if (part.type === "tool-params-delta") {
|
|
17540
|
+
const sequence = yield* allocator.allocate(1);
|
|
17541
|
+
const deltaIndex = state.toolCallDeltaIndexes[part.id] ?? 0;
|
|
17542
|
+
yield* appendEvent(eventLog, toolCallDeltaEvent(input, part, state.toolCallNames[part.id], sequence, deltaIndex), sequence + 1);
|
|
17543
|
+
return {
|
|
17544
|
+
...state,
|
|
17545
|
+
toolCallDeltaIndexes: { ...state.toolCallDeltaIndexes, [part.id]: deltaIndex + 1 }
|
|
17546
|
+
};
|
|
17547
|
+
}
|
|
17465
17548
|
if (part.type === "finish") {
|
|
17466
17549
|
const finish = part;
|
|
17467
17550
|
const sequence = yield* allocator.allocate(1);
|
|
@@ -17481,19 +17564,13 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17481
17564
|
return state;
|
|
17482
17565
|
}
|
|
17483
17566
|
case "TurnStarted": {
|
|
17484
|
-
if (
|
|
17485
|
-
|
|
17486
|
-
yield* appendEvent(eventLog, budgetExceededEvent(input, state.tokensUsed, input.agent.token_budget, budgetSequence), budgetSequence + 1);
|
|
17487
|
-
return yield* Effect87.fail(new AgentLoopBudgetExceeded({
|
|
17488
|
-
tokens_used: state.tokensUsed,
|
|
17489
|
-
token_budget: input.agent.token_budget,
|
|
17490
|
-
next_event_sequence: budgetSequence + 1
|
|
17491
|
-
}));
|
|
17492
|
-
}
|
|
17567
|
+
if (event.turn > 0)
|
|
17568
|
+
yield* enforceBudget(state);
|
|
17493
17569
|
return state;
|
|
17494
17570
|
}
|
|
17495
17571
|
case "TurnCompleted": {
|
|
17496
17572
|
yield* persistTranscript(chats, input, event.transcript);
|
|
17573
|
+
yield* enforceBudget(state);
|
|
17497
17574
|
return { ...state, transcript: event.transcript, turn: event.turn };
|
|
17498
17575
|
}
|
|
17499
17576
|
case "Completed": {
|
|
@@ -17504,9 +17581,16 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17504
17581
|
}
|
|
17505
17582
|
});
|
|
17506
17583
|
const runFold = Effect87.gen(function* () {
|
|
17507
|
-
const base2 = yield* LanguageModel7.LanguageModel;
|
|
17584
|
+
const base2 = withToolCallDecodeResilience(yield* LanguageModel7.LanguageModel, definitions2.map((definition) => definition.name), toolCallDecodeMaxRetries);
|
|
17508
17585
|
const sessionStore = input.sessionId !== undefined && Option25.isSome(sessionRepository) ? yield* make8(input.sessionId, input.sessionEntryScope ?? input.executionId).pipe(Effect87.provideService(exports_session_repository.Service, sessionRepository.value)) : undefined;
|
|
17509
|
-
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream12.runFoldEffect(() => ({
|
|
17586
|
+
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream12.runFoldEffect(() => ({
|
|
17587
|
+
text: "",
|
|
17588
|
+
transcript: undefined,
|
|
17589
|
+
turn: undefined,
|
|
17590
|
+
tokensUsed: seededTokens,
|
|
17591
|
+
toolCallNames: {},
|
|
17592
|
+
toolCallDeltaIndexes: {}
|
|
17593
|
+
}), foldEvent), Effect87.provideService(LanguageModel7.LanguageModel, base2), Effect87.provideService(exports_model_resilience.ModelResilience, policy), Effect87.provide(executorLayer), Effect87.provide(handlerLayer), Effect87.provide(layer52), Effect87.provide(exports_model_middleware.identityLayer), Effect87.provide(instructionsLayer), Effect87.provide(permissionsLayer), Effect87.provide(steeringLayer));
|
|
17510
17594
|
const withToolOutput = toolOutputStore === undefined ? folded : folded.pipe(Effect87.provideService(exports_tool_output.ToolOutputStore, toolOutputStore));
|
|
17511
17595
|
const withCompaction = compactionService === undefined ? withToolOutput : withToolOutput.pipe(Effect87.provideService(exports_compaction.Compaction, compactionService));
|
|
17512
17596
|
const withSession = sessionStore === undefined ? withCompaction : withCompaction.pipe(Effect87.provideService(exports_session.SessionStore, sessionStore));
|
|
@@ -18290,10 +18374,6 @@ var missingAgentSnapshot = () => new ExecutionWorkflowFailed({ message: "Agent s
|
|
|
18290
18374
|
var memorySubjectMetadataKey = "memory_subject_id";
|
|
18291
18375
|
var steeringEnabledMetadataKey = "steering_enabled";
|
|
18292
18376
|
var toolOutputMaxBytesMetadataKey = "tool_output_max_bytes";
|
|
18293
|
-
var compactionEnabledMetadataKey = "compaction_enabled";
|
|
18294
|
-
var compactionContextWindowMetadataKey = "compaction_context_window";
|
|
18295
|
-
var compactionReserveTokensMetadataKey = "compaction_reserve_tokens";
|
|
18296
|
-
var compactionKeepRecentTokensMetadataKey = "compaction_keep_recent_tokens";
|
|
18297
18377
|
var continueAsNewAfterTurnsMetadataKey = "continue_as_new_after_turns";
|
|
18298
18378
|
var workflowGenerationMetadataKey = "workflow_generation";
|
|
18299
18379
|
var workflowGenerationForStart = (input) => input.workflow_generation ?? 0;
|
|
@@ -18312,7 +18392,6 @@ var metadataSetting = (input, key4) => {
|
|
|
18312
18392
|
return input.agent_snapshot?.metadata?.[key4];
|
|
18313
18393
|
return;
|
|
18314
18394
|
};
|
|
18315
|
-
var executionMetadataSetting = (input, key4) => hasMetadataKey(input.metadata, key4) ? input.metadata?.[key4] : undefined;
|
|
18316
18395
|
var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
18317
18396
|
if (value === undefined)
|
|
18318
18397
|
return Effect93.succeed(undefined);
|
|
@@ -18325,31 +18404,6 @@ var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
|
18325
18404
|
var optionalNumberForStart = (input, key4, valid) => decodeOptionalNumberSetting(metadataSetting(input, key4), key4, valid).pipe(Effect93.map((value) => value === null ? undefined : value));
|
|
18326
18405
|
var continueAsNewAfterTurnsForStart = (input) => optionalNumberForStart(input, continueAsNewAfterTurnsMetadataKey, (value) => Number.isInteger(value) && value > 0);
|
|
18327
18406
|
var toolOutputMaxBytesForStart = (input) => decodeOptionalNumberSetting(metadataSetting(input, toolOutputMaxBytesMetadataKey), toolOutputMaxBytesMetadataKey, (value) => value >= 0);
|
|
18328
|
-
var decodeCompactionEnabled = (value) => {
|
|
18329
|
-
if (value === undefined)
|
|
18330
|
-
return Effect93.succeed(undefined);
|
|
18331
|
-
if (value === null || value === false)
|
|
18332
|
-
return Effect93.succeed(null);
|
|
18333
|
-
if (value === true)
|
|
18334
|
-
return Effect93.succeed(true);
|
|
18335
|
-
return Effect93.fail(new ExecutionWorkflowFailed({ message: "compaction_enabled metadata value must be true or false" }));
|
|
18336
|
-
};
|
|
18337
|
-
var compactionForStart = Effect93.fn("ExecutionWorkflow.compactionForStart")(function* (input) {
|
|
18338
|
-
const executionEnabled = yield* decodeCompactionEnabled(executionMetadataSetting(input, compactionEnabledMetadataKey));
|
|
18339
|
-
if (executionEnabled === null)
|
|
18340
|
-
return null;
|
|
18341
|
-
const agentEnabled = yield* decodeCompactionEnabled(input.agent_snapshot?.metadata?.[compactionEnabledMetadataKey]);
|
|
18342
|
-
if (executionEnabled !== true && agentEnabled !== true)
|
|
18343
|
-
return;
|
|
18344
|
-
const contextWindow = yield* optionalNumberForStart(input, compactionContextWindowMetadataKey, (value) => value > 0);
|
|
18345
|
-
const reserveTokens = yield* optionalNumberForStart(input, compactionReserveTokensMetadataKey, (value) => value >= 0);
|
|
18346
|
-
const keepRecentTokens = yield* optionalNumberForStart(input, compactionKeepRecentTokensMetadataKey, (value) => value >= 0);
|
|
18347
|
-
return {
|
|
18348
|
-
...contextWindow === undefined ? {} : { contextWindow },
|
|
18349
|
-
...reserveTokens === undefined ? {} : { reserveTokens },
|
|
18350
|
-
...keepRecentTokens === undefined ? {} : { keepRecentTokens }
|
|
18351
|
-
};
|
|
18352
|
-
});
|
|
18353
18407
|
var decodeMemorySubject = (value) => typeof value === "string" ? Schema93.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(value).pipe(Effect93.mapError(() => new ExecutionWorkflowFailed({ message: `Invalid memory_subject_id metadata value: ${value}` }))) : Effect93.fail(new ExecutionWorkflowFailed({ message: "memory_subject_id metadata value must be a string" }));
|
|
18354
18408
|
var memorySubjectForStart = Effect93.fn("ExecutionWorkflow.memorySubjectForStart")(function* (input) {
|
|
18355
18409
|
const executionSubject = memorySubjectFromMetadata(input.metadata);
|
|
@@ -18421,7 +18475,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
18421
18475
|
const runEventSequence = yield* nextEventSequence4(eventLog, input.execution_id);
|
|
18422
18476
|
const memorySubjectId = yield* memorySubjectForStart(input);
|
|
18423
18477
|
const toolOutputMaxBytes = yield* toolOutputMaxBytesForStart(input);
|
|
18424
|
-
const compaction = yield* compactionForStart(input);
|
|
18425
18478
|
const skillDefinitionIds = input.agent_snapshot.skill_definition_ids ?? [];
|
|
18426
18479
|
const loopProgram = agentLoop.run({
|
|
18427
18480
|
executionId: input.execution_id,
|
|
@@ -18437,7 +18490,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
18437
18490
|
...pendingToolCall === undefined ? {} : { resumeToolCall: pendingToolCall },
|
|
18438
18491
|
...memorySubjectId === undefined ? {} : { memorySubjectId },
|
|
18439
18492
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
18440
|
-
...compaction === undefined ? {} : { compaction },
|
|
18441
18493
|
eventSequence: runEventSequence + 1,
|
|
18442
18494
|
startedAt: input.started_at,
|
|
18443
18495
|
completedAt: input.completed_at,
|
|
@@ -19408,7 +19460,6 @@ var layer66 = Layer85.effect(Service65, Effect99.gen(function* () {
|
|
|
19408
19460
|
entity_kind: input.kind,
|
|
19409
19461
|
entity_key: input.key,
|
|
19410
19462
|
entity_generation: instance.generation,
|
|
19411
|
-
compaction_enabled: input.metadata?.compaction_enabled ?? kind.metadata?.compaction_enabled ?? true,
|
|
19412
19463
|
...kind.state_enabled === undefined ? {} : { state_enabled: kind.state_enabled },
|
|
19413
19464
|
...kind.continue_as_new_after_turns === undefined ? {} : { continue_as_new_after_turns: kind.continue_as_new_after_turns }
|
|
19414
19465
|
};
|
|
@@ -19905,7 +19956,7 @@ __export(exports_definition_runtime, {
|
|
|
19905
19956
|
PinnedDefinitionMismatch: () => PinnedDefinitionMismatch,
|
|
19906
19957
|
HandlerService: () => HandlerService2
|
|
19907
19958
|
});
|
|
19908
|
-
import { Cause as
|
|
19959
|
+
import { Cause as Cause6, Clock as Clock17, Context as Context81, Effect as Effect102, Exit as Exit3, Layer as Layer88, Option as Option31, Schema as Schema103 } from "effect";
|
|
19909
19960
|
|
|
19910
19961
|
class UnsupportedOperation extends Schema103.TaggedErrorClass()("UnsupportedWorkflowOperation", { operation_id: exports_ids_schema.WorkflowOperationId, kind: Schema103.String }) {
|
|
19911
19962
|
}
|
|
@@ -20227,7 +20278,7 @@ var run5 = Effect102.fn("WorkflowDefinitionRuntime.run")(function* (executionId)
|
|
|
20227
20278
|
});
|
|
20228
20279
|
const result = yield* Effect102.exit(execute(revision.definition.entry_operation_id));
|
|
20229
20280
|
if (Exit3.isFailure(result)) {
|
|
20230
|
-
const failure3 =
|
|
20281
|
+
const failure3 = Cause6.findErrorOption(result.cause);
|
|
20231
20282
|
if (Option31.isSome(failure3) && failure3.value instanceof WorkflowJoining)
|
|
20232
20283
|
return yield* result;
|
|
20233
20284
|
const currentRun = yield* repository.inspect(executionId);
|
|
@@ -20576,6 +20627,7 @@ var overrideOf = (child) => {
|
|
|
20576
20627
|
return {
|
|
20577
20628
|
...override?.instructions === undefined ? {} : { instructions: override.instructions },
|
|
20578
20629
|
...override?.model === undefined ? {} : { model: override.model },
|
|
20630
|
+
...override?.compaction_policy === undefined ? {} : { compactionPolicy: override.compaction_policy },
|
|
20579
20631
|
...override?.tool_names === undefined ? {} : { toolNames: override.tool_names },
|
|
20580
20632
|
...override?.permissions === undefined ? {} : { permissions: override.permissions },
|
|
20581
20633
|
...override?.workspace_policy === undefined ? {} : { workspacePolicy: override.workspace_policy },
|