@relayfx/sdk 0.2.11 → 0.2.13
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-fhqr1n44.js → index-3e4cs8s6.js} +156 -100
- package/dist/{index-tpwr0wmj.js → index-kghdnamr.js} +7 -7
- package/dist/{index-jg4xh3fx.js → index-rmaq3qc8.js} +11 -6
- 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 +6 -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 +44 -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 },
|
|
@@ -537,6 +547,7 @@ var text = (value) => ({ type: "text", text: value });
|
|
|
537
547
|
// ../schema/src/execution-schema.ts
|
|
538
548
|
var exports_execution_schema = {};
|
|
539
549
|
__export(exports_execution_schema, {
|
|
550
|
+
childSessionId: () => childSessionId,
|
|
540
551
|
SpawnChildRunInput: () => SpawnChildRunInput,
|
|
541
552
|
ExecutionStatus: () => ExecutionStatus,
|
|
542
553
|
ExecutionEventType: () => ExecutionEventType,
|
|
@@ -576,6 +587,7 @@ var ExecutionEventSequence = Schema7.Int.check(Schema7.isGreaterThanOrEqualTo(0)
|
|
|
576
587
|
var ChildRunContext = Schema7.Struct({
|
|
577
588
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
578
589
|
model: Schema7.optionalKey(ModelSelection),
|
|
590
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
579
591
|
tool_names: Schema7.Array(Schema7.String),
|
|
580
592
|
permissions: Schema7.Array(Schema7.String),
|
|
581
593
|
output_schema_ref: Schema7.optionalKey(Schema7.String),
|
|
@@ -584,6 +596,7 @@ var ChildRunContext = Schema7.Struct({
|
|
|
584
596
|
var ChildRunOverride = Schema7.Struct({
|
|
585
597
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
586
598
|
model: Schema7.optionalKey(ModelSelection),
|
|
599
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
587
600
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
588
601
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
589
602
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -600,6 +613,7 @@ var SpawnChildRunInput = Schema7.Struct({
|
|
|
600
613
|
preset_name: Schema7.optionalKey(NonEmptyString),
|
|
601
614
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
602
615
|
model: Schema7.optionalKey(ModelSelection),
|
|
616
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
603
617
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
604
618
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
605
619
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -614,6 +628,7 @@ var ChildRunAccepted = Schema7.Struct({
|
|
|
614
628
|
child_execution_id: ChildExecutionId,
|
|
615
629
|
execution_id: ExecutionId
|
|
616
630
|
}).annotate({ identifier: "Relay.ChildRunAccepted" });
|
|
631
|
+
var childSessionId = (childExecutionId) => SessionId.make(`session:child:${childExecutionId}`);
|
|
617
632
|
var ExecutionEventType = Schema7.Literals([
|
|
618
633
|
"execution.accepted",
|
|
619
634
|
"execution.started",
|
|
@@ -623,6 +638,7 @@ var ExecutionEventType = Schema7.Literals([
|
|
|
623
638
|
"model.input.prepared",
|
|
624
639
|
"model.output.delta",
|
|
625
640
|
"model.reasoning.delta",
|
|
641
|
+
"model.toolcall.delta",
|
|
626
642
|
"model.output.completed",
|
|
627
643
|
"model.usage.reported",
|
|
628
644
|
"budget.exceeded",
|
|
@@ -11457,7 +11473,7 @@ var resolveLocalAgent = Effect37.fn("AddressResolution.resolveLocalAgent.call")(
|
|
|
11457
11473
|
return yield* service.resolveLocalAgent(addressId);
|
|
11458
11474
|
});
|
|
11459
11475
|
|
|
11460
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11476
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent-event.js
|
|
11461
11477
|
var exports_agent_event = {};
|
|
11462
11478
|
__export(exports_agent_event, {
|
|
11463
11479
|
addUsage: () => addUsage,
|
|
@@ -11514,7 +11530,7 @@ class AgentSuspended extends Schema52.TaggedErrorClass()("@batonfx/core/AgentSus
|
|
|
11514
11530
|
}) {
|
|
11515
11531
|
}
|
|
11516
11532
|
|
|
11517
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11533
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-context.js
|
|
11518
11534
|
var exports_tool_context = {};
|
|
11519
11535
|
__export(exports_tool_context, {
|
|
11520
11536
|
testLayer: () => testLayer32,
|
|
@@ -11532,7 +11548,7 @@ var layerDefault = Layer35.sync(ToolContext, () => ToolContext.of({
|
|
|
11532
11548
|
}));
|
|
11533
11549
|
var testLayer32 = (implementation) => Layer35.succeed(ToolContext, ToolContext.of(implementation));
|
|
11534
11550
|
|
|
11535
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11551
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-executor.js
|
|
11536
11552
|
var exports_tool_executor = {};
|
|
11537
11553
|
__export(exports_tool_executor, {
|
|
11538
11554
|
testLayer: () => testLayer33,
|
|
@@ -11659,7 +11675,7 @@ function router(routes) {
|
|
|
11659
11675
|
}
|
|
11660
11676
|
var testLayer33 = (implementation) => Layer36.succeed(ToolExecutor, ToolExecutor.of(implementation));
|
|
11661
11677
|
|
|
11662
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11678
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/approvals.js
|
|
11663
11679
|
var exports_approvals = {};
|
|
11664
11680
|
__export(exports_approvals, {
|
|
11665
11681
|
testLayer: () => testLayer34,
|
|
@@ -11674,7 +11690,7 @@ var autoApprove = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect4
|
|
|
11674
11690
|
var denyAll = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect40.succeed({ _tag: "Denied" }) }));
|
|
11675
11691
|
var testLayer34 = (implementation) => Layer37.succeed(Approvals, Approvals.of(implementation));
|
|
11676
11692
|
|
|
11677
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11693
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/session.js
|
|
11678
11694
|
var exports_session = {};
|
|
11679
11695
|
__export(exports_session, {
|
|
11680
11696
|
testLayer: () => testLayer35,
|
|
@@ -11847,7 +11863,7 @@ var memoryLayer32 = Layer38.effect(SessionStore, Ref10.make(initialState).pipe(E
|
|
|
11847
11863
|
}))));
|
|
11848
11864
|
var testLayer35 = (implementation) => Layer38.succeed(SessionStore, SessionStore.of(implementation));
|
|
11849
11865
|
|
|
11850
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11866
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-output.js
|
|
11851
11867
|
var exports_tool_output = {};
|
|
11852
11868
|
__export(exports_tool_output, {
|
|
11853
11869
|
testLayer: () => testLayer36,
|
|
@@ -11906,7 +11922,7 @@ var bound = (result, options) => Effect42.gen(function* () {
|
|
|
11906
11922
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
11907
11923
|
});
|
|
11908
11924
|
|
|
11909
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11925
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/compaction.js
|
|
11910
11926
|
var exports_compaction = {};
|
|
11911
11927
|
__export(exports_compaction, {
|
|
11912
11928
|
truncate: () => truncate,
|
|
@@ -12177,7 +12193,7 @@ var truncate = (maxTokens) => ({
|
|
|
12177
12193
|
var testLayer37 = (implementation) => Layer40.succeed(Compaction, Compaction.of(implementation));
|
|
12178
12194
|
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
12195
|
|
|
12180
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12196
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/instructions.js
|
|
12181
12197
|
var exports_instructions = {};
|
|
12182
12198
|
__export(exports_instructions, {
|
|
12183
12199
|
testLayer: () => testLayer38,
|
|
@@ -12225,7 +12241,7 @@ var renderUpdate = (epoch, context) => Effect44.gen(function* () {
|
|
|
12225
12241
|
var layer33 = (sources) => Layer41.succeed(Instructions, Instructions.of({ sources: [...sources] }));
|
|
12226
12242
|
var testLayer38 = (implementation) => Layer41.succeed(Instructions, Instructions.of(implementation));
|
|
12227
12243
|
|
|
12228
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12244
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/memory.js
|
|
12229
12245
|
var exports_memory = {};
|
|
12230
12246
|
__export(exports_memory, {
|
|
12231
12247
|
testLayer: () => testLayer39,
|
|
@@ -12257,7 +12273,7 @@ var merge = (first, second) => ({
|
|
|
12257
12273
|
var noopLayer = Layer42.succeed(Memory, Memory.of(noop));
|
|
12258
12274
|
var testLayer39 = (implementation) => Layer42.succeed(Memory, Memory.of(implementation));
|
|
12259
12275
|
|
|
12260
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12276
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-middleware.js
|
|
12261
12277
|
var exports_model_middleware = {};
|
|
12262
12278
|
__export(exports_model_middleware, {
|
|
12263
12279
|
layer: () => layer34,
|
|
@@ -12271,7 +12287,7 @@ class ModelMiddleware extends Context43.Service()("@batonfx/core/ModelMiddleware
|
|
|
12271
12287
|
var identityLayer = Layer43.succeed(ModelMiddleware, []);
|
|
12272
12288
|
var layer34 = (middleware) => Layer43.succeed(ModelMiddleware, middleware);
|
|
12273
12289
|
|
|
12274
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12290
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-registry.js
|
|
12275
12291
|
var exports_model_registry = {};
|
|
12276
12292
|
__export(exports_model_registry, {
|
|
12277
12293
|
testLayer: () => testLayer40,
|
|
@@ -12360,7 +12376,7 @@ var provide = (selection, effect) => Effect47.gen(function* () {
|
|
|
12360
12376
|
return yield* service.provide(selection, effect);
|
|
12361
12377
|
});
|
|
12362
12378
|
|
|
12363
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12379
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-resilience.js
|
|
12364
12380
|
var exports_model_resilience = {};
|
|
12365
12381
|
__export(exports_model_resilience, {
|
|
12366
12382
|
testLayer: () => testLayer41,
|
|
@@ -12406,7 +12422,7 @@ var apply = (model, resilience) => ({
|
|
|
12406
12422
|
}).pipe(Stream8.retry(retryStreamSchedule(resilience)))
|
|
12407
12423
|
});
|
|
12408
12424
|
|
|
12409
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12425
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/permissions.js
|
|
12410
12426
|
var exports_permissions = {};
|
|
12411
12427
|
__export(exports_permissions, {
|
|
12412
12428
|
testLayer: () => testLayer42,
|
|
@@ -12536,7 +12552,7 @@ var ruleStoreMemory = (initialRules = []) => Layer46.effect(RuleStore, Ref13.mak
|
|
|
12536
12552
|
var ruleStoreTestLayer = (implementation) => Layer46.succeed(RuleStore, RuleStore.of(implementation));
|
|
12537
12553
|
var testLayer42 = (implementation) => Layer46.succeed(Permissions, Permissions.of(implementation));
|
|
12538
12554
|
|
|
12539
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12555
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/skill-source.js
|
|
12540
12556
|
var exports_skill_source = {};
|
|
12541
12557
|
__export(exports_skill_source, {
|
|
12542
12558
|
testLayer: () => testLayer43,
|
|
@@ -12616,7 +12632,7 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
12616
12632
|
return selected;
|
|
12617
12633
|
};
|
|
12618
12634
|
|
|
12619
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12635
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/steering.js
|
|
12620
12636
|
var exports_steering = {};
|
|
12621
12637
|
__export(exports_steering, {
|
|
12622
12638
|
testLayer: () => testLayer44,
|
|
@@ -12674,7 +12690,7 @@ var layer38 = (options = {}) => Layer48.effect(Steering, Effect51.gen(function*
|
|
|
12674
12690
|
}));
|
|
12675
12691
|
var testLayer44 = (implementation) => Layer48.succeed(Steering, Steering.of(implementation));
|
|
12676
12692
|
|
|
12677
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12693
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/turn-policy.js
|
|
12678
12694
|
var exports_turn_policy = {};
|
|
12679
12695
|
__export(exports_turn_policy, {
|
|
12680
12696
|
untilToolCall: () => untilToolCall,
|
|
@@ -12723,7 +12739,7 @@ var both = (first, second) => ({
|
|
|
12723
12739
|
});
|
|
12724
12740
|
var defaultPolicy = recurs(8);
|
|
12725
12741
|
|
|
12726
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12742
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent.js
|
|
12727
12743
|
var exports_agent = {};
|
|
12728
12744
|
__export(exports_agent, {
|
|
12729
12745
|
streamObject: () => streamObject,
|
|
@@ -12920,8 +12936,7 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12920
12936
|
turn: 0,
|
|
12921
12937
|
pending: [],
|
|
12922
12938
|
finish: undefined,
|
|
12923
|
-
usage: undefined
|
|
12924
|
-
contextTokens: undefined
|
|
12939
|
+
usage: undefined
|
|
12925
12940
|
};
|
|
12926
12941
|
const activatedSkillBodies = new Map;
|
|
12927
12942
|
const activatedSkillTools = new Map;
|
|
@@ -12972,10 +12987,8 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12972
12987
|
})
|
|
12973
12988
|
});
|
|
12974
12989
|
const countTokens = (turn, prompt) => {
|
|
12975
|
-
if (state.contextTokens !== undefined)
|
|
12976
|
-
return Effect53.succeed(state.contextTokens);
|
|
12977
12990
|
return Option18.match(tokenizerService, {
|
|
12978
|
-
onNone: () => Effect53.succeed(
|
|
12991
|
+
onNone: () => Effect53.succeed(Math.ceil(JSON.stringify(prompt.content).length / 4)),
|
|
12979
12992
|
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(Effect53.map((tokens) => tokens.length), Effect53.mapError((error5) => new AgentError({ message: errorMessage(error5), turn, cause: error5 })))
|
|
12980
12993
|
});
|
|
12981
12994
|
};
|
|
@@ -13184,7 +13197,6 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
13184
13197
|
reason: part.reason
|
|
13185
13198
|
};
|
|
13186
13199
|
state.usage = state.usage === undefined ? part.usage : addUsage(state.usage, part.usage);
|
|
13187
|
-
state.contextTokens = part.usage.inputTokens.total ?? state.contextTokens;
|
|
13188
13200
|
Telemetry.addGenAIAnnotations(span, {
|
|
13189
13201
|
operation: { name: "chat" },
|
|
13190
13202
|
usage: {
|
|
@@ -13438,7 +13450,7 @@ var generateObject = (agent, options) => Stream9.runFold(streamObject(agent, opt
|
|
|
13438
13450
|
})
|
|
13439
13451
|
})));
|
|
13440
13452
|
|
|
13441
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13453
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent-tool.js
|
|
13442
13454
|
var exports_agent_tool = {};
|
|
13443
13455
|
__export(exports_agent_tool, {
|
|
13444
13456
|
asTool: () => asTool
|
|
@@ -13494,7 +13506,7 @@ var asTool = (agent, options = {}) => {
|
|
|
13494
13506
|
return lazyHandled(toolkit, name, handler);
|
|
13495
13507
|
};
|
|
13496
13508
|
|
|
13497
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13509
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/guardrail.js
|
|
13498
13510
|
var exports_guardrail = {};
|
|
13499
13511
|
__export(exports_guardrail, {
|
|
13500
13512
|
validateInput: () => validateInput2,
|
|
@@ -13575,7 +13587,7 @@ var filterOutput = (keep) => ({
|
|
|
13575
13587
|
transformPart: (part, context) => Effect55.succeed(part.type === "tool-call" || keep(part, context) ? Option19.some(part) : Option19.none())
|
|
13576
13588
|
});
|
|
13577
13589
|
|
|
13578
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13590
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/handoff.js
|
|
13579
13591
|
var exports_handoff = {};
|
|
13580
13592
|
__export(exports_handoff, {
|
|
13581
13593
|
transferTool: () => transferTool,
|
|
@@ -13639,7 +13651,7 @@ var supervisor = (options) => {
|
|
|
13639
13651
|
};
|
|
13640
13652
|
};
|
|
13641
13653
|
|
|
13642
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
13654
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/index.js
|
|
13643
13655
|
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
13656
|
|
|
13645
13657
|
// ../runtime/src/child/child-run-service.ts
|
|
@@ -13750,6 +13762,7 @@ var resolveContext = (parent, override) => {
|
|
|
13750
13762
|
const permissions = override?.permissions ?? parent.permissions;
|
|
13751
13763
|
const instructions = override?.instructions ?? parent.instructions;
|
|
13752
13764
|
const model = override?.model ?? parent.model;
|
|
13765
|
+
const compactionPolicy = override?.compactionPolicy ?? parent.compactionPolicy;
|
|
13753
13766
|
const workspacePolicy = override?.workspacePolicy;
|
|
13754
13767
|
const outputSchemaRef = override?.outputSchemaRef ?? parent.outputSchemaRef;
|
|
13755
13768
|
const broadenedTool = subsetViolation(parent.toolNames, toolNames);
|
|
@@ -13769,6 +13782,7 @@ var resolveContext = (parent, override) => {
|
|
|
13769
13782
|
},
|
|
13770
13783
|
...instructions === undefined ? {} : { instructions },
|
|
13771
13784
|
...model === undefined ? {} : { model },
|
|
13785
|
+
...compactionPolicy === undefined ? {} : { compactionPolicy },
|
|
13772
13786
|
...workspacePolicy === undefined ? {} : { workspacePolicy },
|
|
13773
13787
|
...outputSchemaRef === undefined ? {} : { outputSchemaRef }
|
|
13774
13788
|
});
|
|
@@ -13916,12 +13930,14 @@ var agentContextFromSchema = (input) => ({
|
|
|
13916
13930
|
permissions: input.permissions,
|
|
13917
13931
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13918
13932
|
...input.model === undefined ? {} : { model: input.model },
|
|
13933
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13919
13934
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
13920
13935
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13921
13936
|
});
|
|
13922
13937
|
var overrideFromSchema = (input) => ({
|
|
13923
13938
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13924
13939
|
...input.model === undefined ? {} : { model: input.model },
|
|
13940
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13925
13941
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
13926
13942
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
13927
13943
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -13929,7 +13945,7 @@ var overrideFromSchema = (input) => ({
|
|
|
13929
13945
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13930
13946
|
});
|
|
13931
13947
|
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) {
|
|
13948
|
+
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
13949
|
return;
|
|
13934
13950
|
}
|
|
13935
13951
|
return overrideFromSchema(input);
|
|
@@ -13951,6 +13967,7 @@ var childDefinition = (parentDefinition, context) => context.model === undefined
|
|
|
13951
13967
|
tool_names: [...context.toolNames],
|
|
13952
13968
|
permissions: parentDefinition.permissions.filter((permission) => context.permissions.includes(permission.name)),
|
|
13953
13969
|
child_run_presets: {},
|
|
13970
|
+
...context.compactionPolicy === undefined ? {} : { compaction_policy: context.compactionPolicy },
|
|
13954
13971
|
...parentDefinition.turn_policy === undefined ? {} : { turn_policy: parentDefinition.turn_policy },
|
|
13955
13972
|
...parentDefinition.max_tool_turns === undefined ? {} : { max_tool_turns: parentDefinition.max_tool_turns },
|
|
13956
13973
|
...parentDefinition.max_wait_turns === undefined ? {} : { max_wait_turns: parentDefinition.max_wait_turns },
|
|
@@ -14531,12 +14548,14 @@ var childContext = (input) => ({
|
|
|
14531
14548
|
permissions: input.permissions,
|
|
14532
14549
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14533
14550
|
...input.model === undefined ? {} : { model: input.model },
|
|
14551
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14534
14552
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
14535
14553
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
14536
14554
|
});
|
|
14537
14555
|
var childOverride = (input) => ({
|
|
14538
14556
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14539
14557
|
...input.model === undefined ? {} : { model: input.model },
|
|
14558
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14540
14559
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
14541
14560
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14542
14561
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -14544,12 +14563,13 @@ var childOverride = (input) => ({
|
|
|
14544
14563
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
14545
14564
|
});
|
|
14546
14565
|
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) {
|
|
14566
|
+
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
14567
|
return;
|
|
14549
14568
|
}
|
|
14550
14569
|
return childOverride({
|
|
14551
14570
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14552
14571
|
...input.model === undefined ? {} : { model: input.model },
|
|
14572
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
14553
14573
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
14554
14574
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14555
14575
|
...input.workspace_policy === undefined ? {} : { workspace_policy: input.workspace_policy },
|
|
@@ -14866,8 +14886,8 @@ __export(exports_agent_loop_service, {
|
|
|
14866
14886
|
AgentLoopError: () => AgentLoopError,
|
|
14867
14887
|
AgentLoopBudgetExceeded: () => AgentLoopBudgetExceeded
|
|
14868
14888
|
});
|
|
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";
|
|
14889
|
+
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";
|
|
14890
|
+
import { AiError as AiError5, Chat as Chat3, LanguageModel as LanguageModel7, Prompt as Prompt16, Tokenizer as Tokenizer4, Toolkit as Toolkit8 } from "effect/unstable/ai";
|
|
14871
14891
|
|
|
14872
14892
|
// ../runtime/src/child/spawn-child-run-tool.ts
|
|
14873
14893
|
import { Effect as Effect66, Schema as Schema73 } from "effect";
|
|
@@ -14877,6 +14897,7 @@ var Input2 = Schema73.Struct({
|
|
|
14877
14897
|
preset_name: Schema73.optionalKey(exports_shared_schema.NonEmptyString),
|
|
14878
14898
|
instructions: Schema73.optionalKey(Schema73.String),
|
|
14879
14899
|
model: Schema73.optionalKey(exports_agent_schema.ModelSelection),
|
|
14900
|
+
compaction_policy: Schema73.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
14880
14901
|
tool_names: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14881
14902
|
permissions: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14882
14903
|
output_schema_ref: Schema73.optionalKey(Schema73.String),
|
|
@@ -14899,6 +14920,7 @@ var ModelInput = Schema73.Struct({
|
|
|
14899
14920
|
model: Schema73.String,
|
|
14900
14921
|
registration_key: Schema73.optionalKey(Schema73.String)
|
|
14901
14922
|
}))),
|
|
14923
|
+
compaction_policy: Schema73.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
14902
14924
|
tool_names: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14903
14925
|
permissions: Schema73.optionalKey(Schema73.Array(Schema73.String)),
|
|
14904
14926
|
output_schema_ref: Schema73.optionalKey(Schema73.NullOr(Schema73.String)),
|
|
@@ -14920,6 +14942,7 @@ var enabled = (agent) => agent.metadata?.multi_agent_enabled === true;
|
|
|
14920
14942
|
var parentContext = (agent) => ({
|
|
14921
14943
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
14922
14944
|
model: agent.model,
|
|
14945
|
+
...agent.compaction_policy === undefined ? {} : { compaction_policy: agent.compaction_policy },
|
|
14923
14946
|
tool_names: agent.tool_names,
|
|
14924
14947
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
14925
14948
|
...agent.output_schema_ref === undefined ? {} : { output_schema_ref: agent.output_schema_ref },
|
|
@@ -14928,12 +14951,13 @@ var parentContext = (agent) => ({
|
|
|
14928
14951
|
var serviceParentContext = (agent) => ({
|
|
14929
14952
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
14930
14953
|
model: agent.model,
|
|
14954
|
+
...agent.compaction_policy === undefined ? {} : { compactionPolicy: agent.compaction_policy },
|
|
14931
14955
|
toolNames: agent.tool_names,
|
|
14932
14956
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
14933
14957
|
...agent.output_schema_ref === undefined ? {} : { outputSchemaRef: agent.output_schema_ref },
|
|
14934
14958
|
...agent.metadata === undefined ? {} : { metadata: agent.metadata }
|
|
14935
14959
|
});
|
|
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;
|
|
14960
|
+
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
14961
|
var childExecutionId2 = (context) => exports_ids_schema.ChildExecutionId.make(`${context.executionId}:child:${context.call.id}`);
|
|
14938
14962
|
var childAddressId = (id2) => exports_ids_schema.AddressId.make(`address:child:${id2}`);
|
|
14939
14963
|
var childWaitId = (id2) => exports_ids_schema.WaitId.make(`wait:child:${id2}`);
|
|
@@ -14949,6 +14973,7 @@ var spawnInput = (config, input, context, id2) => ({
|
|
|
14949
14973
|
...input.preset_name === undefined ? {} : { preset_name: input.preset_name },
|
|
14950
14974
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14951
14975
|
...input.model === undefined ? {} : { model: input.model },
|
|
14976
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
14952
14977
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
14953
14978
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14954
14979
|
...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
|
|
@@ -14968,6 +14993,7 @@ var childOverride2 = (input) => {
|
|
|
14968
14993
|
return {
|
|
14969
14994
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
14970
14995
|
...input.model === undefined ? {} : { model: input.model },
|
|
14996
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
14971
14997
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
14972
14998
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
14973
14999
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
@@ -14979,6 +15005,7 @@ var presetMap2 = (agent) => new Map(Object.entries(agent.child_run_presets ?? {}
|
|
|
14979
15005
|
{
|
|
14980
15006
|
...preset.instructions === undefined ? {} : { instructions: preset.instructions },
|
|
14981
15007
|
...preset.model === undefined ? {} : { model: preset.model },
|
|
15008
|
+
...preset.compaction_policy === undefined ? {} : { compactionPolicy: preset.compaction_policy },
|
|
14982
15009
|
...preset.tool_names === undefined ? {} : { toolNames: preset.tool_names },
|
|
14983
15010
|
...preset.permissions === undefined ? {} : { permissions: preset.permissions },
|
|
14984
15011
|
...preset.workspace_policy === undefined ? {} : { workspacePolicy: preset.workspace_policy },
|
|
@@ -15005,6 +15032,7 @@ var dispatchChild = Effect66.fn("SpawnChildRunTool.dispatchChild")(function* (co
|
|
|
15005
15032
|
yield* config.dispatch({
|
|
15006
15033
|
executionId: exports_ids_schema.ExecutionId.make(id2),
|
|
15007
15034
|
rootAddressId: input.address_id,
|
|
15035
|
+
sessionId: exports_execution_schema.childSessionId(id2),
|
|
15008
15036
|
input: input.input ?? [],
|
|
15009
15037
|
eventSequence: 0,
|
|
15010
15038
|
startedAt: (input.created_at ?? 0) + 2,
|
|
@@ -17096,6 +17124,20 @@ var reasoningDeltaEvent = (input, part, deltaIndex) => {
|
|
|
17096
17124
|
created_at: input.startedAt + deltaIndex + 1
|
|
17097
17125
|
};
|
|
17098
17126
|
};
|
|
17127
|
+
var toolCallDeltaEvent = (input, part, toolCallName, sequence, deltaIndex) => ({
|
|
17128
|
+
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`),
|
|
17129
|
+
execution_id: input.executionId,
|
|
17130
|
+
type: "model.toolcall.delta",
|
|
17131
|
+
sequence,
|
|
17132
|
+
cursor: `${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`,
|
|
17133
|
+
data: {
|
|
17134
|
+
tool_call_id: part.id,
|
|
17135
|
+
...toolCallName === undefined ? {} : { tool_name: toolCallName },
|
|
17136
|
+
delta: part.delta,
|
|
17137
|
+
delta_index: deltaIndex
|
|
17138
|
+
},
|
|
17139
|
+
created_at: input.startedAt + (sequence - input.eventSequence)
|
|
17140
|
+
});
|
|
17099
17141
|
var outputCompletedEvent = (input, content, outputText, sequence, structuredOutput) => ({
|
|
17100
17142
|
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:output-completed`),
|
|
17101
17143
|
execution_id: input.executionId,
|
|
@@ -17169,6 +17211,35 @@ var restoreHistory = Effect87.fn("AgentLoop.restoreHistory")(function* (chats, i
|
|
|
17169
17211
|
const chat = yield* Chat3.fromExport(record2.exportData).pipe(Effect87.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17170
17212
|
return yield* Ref21.get(chat.history);
|
|
17171
17213
|
});
|
|
17214
|
+
var toolCallDecodeMaxRetriesConfig = Config4.int("RELAY_AGENT_TOOL_CALL_DECODE_MAX_RETRIES").pipe(Config4.withDefault(2));
|
|
17215
|
+
var isToolCallDecodeError = (error5) => AiError5.isAiError(error5) && error5.method === "streamText" && error5.reason._tag === "InvalidOutputError";
|
|
17216
|
+
var toolCallDecodeFeedback = (error5, availableToolNames) => {
|
|
17217
|
+
const tools = availableToolNames.length === 0 ? "(no tools are available)" : availableToolNames.join(", ");
|
|
17218
|
+
return Prompt16.fromMessages([
|
|
17219
|
+
Prompt16.makeMessage("user", {
|
|
17220
|
+
content: [
|
|
17221
|
+
Prompt16.makePart("text", {
|
|
17222
|
+
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.`
|
|
17223
|
+
})
|
|
17224
|
+
]
|
|
17225
|
+
})
|
|
17226
|
+
]);
|
|
17227
|
+
};
|
|
17228
|
+
var withToolCallDecodeResilience = (base2, availableToolNames, maxRetries) => ({
|
|
17229
|
+
...base2,
|
|
17230
|
+
streamText: (options) => {
|
|
17231
|
+
const attempt = (prompt, retriesLeft) => Stream12.suspend(() => {
|
|
17232
|
+
let emitted = false;
|
|
17233
|
+
return base2.streamText({ ...options, prompt }).pipe(Stream12.tap(() => Effect87.sync(() => void (emitted = true))), Stream12.catchCause((cause) => {
|
|
17234
|
+
if (Cause5.hasInterrupts(cause))
|
|
17235
|
+
return Stream12.failCause(cause);
|
|
17236
|
+
const error5 = Cause5.squash(cause);
|
|
17237
|
+
return !emitted && retriesLeft > 0 && isToolCallDecodeError(error5) ? attempt(Prompt16.concat(Prompt16.make(prompt), toolCallDecodeFeedback(error5, availableToolNames)), retriesLeft - 1) : Stream12.failCause(cause);
|
|
17238
|
+
}));
|
|
17239
|
+
});
|
|
17240
|
+
return attempt(options.prompt, maxRetries);
|
|
17241
|
+
}
|
|
17242
|
+
});
|
|
17172
17243
|
var saveContextEpoch = Effect87.fn("AgentLoop.saveContextEpoch")(function* (epochs, input, epoch) {
|
|
17173
17244
|
yield* epochs.save({
|
|
17174
17245
|
executionId: input.executionId,
|
|
@@ -17249,20 +17320,11 @@ var decodeOptionalNumber = (value, key4, valid) => {
|
|
|
17249
17320
|
return Effect87.fail(new AgentLoopError({ message: `${key4} metadata value is invalid` }));
|
|
17250
17321
|
};
|
|
17251
17322
|
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);
|
|
17323
|
+
var compactionOptions = (agent) => agent.compaction_policy === undefined ? undefined : {
|
|
17324
|
+
contextWindow: agent.compaction_policy.context_window,
|
|
17325
|
+
reserveTokens: agent.compaction_policy.reserve_tokens,
|
|
17326
|
+
keepRecentTokens: agent.compaction_policy.keep_recent_tokens
|
|
17327
|
+
};
|
|
17266
17328
|
var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
17267
17329
|
const eventLog = yield* Service30;
|
|
17268
17330
|
const languageModels = yield* Service38;
|
|
@@ -17321,9 +17383,11 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17321
17383
|
const registered = [...availableRegisteredTools(input.agent, yield* tools.registeredTools), ...allCoreTools];
|
|
17322
17384
|
const definitions2 = registered.map((tool2) => tool2.definition);
|
|
17323
17385
|
yield* validateToolInputSchemaDigests(input, definitions2);
|
|
17386
|
+
const toolCallDecodeMaxRetries = yield* toolCallDecodeMaxRetriesConfig.pipe(Effect87.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17324
17387
|
yield* appendEvent(eventLog, inputPreparedEvent(input, definitions2), input.eventSequence + 1);
|
|
17325
17388
|
const toolOutputMaxBytes = yield* effectiveToolOutputMaxBytes(input);
|
|
17326
|
-
const
|
|
17389
|
+
const compactionPolicy = input.agent.compaction_policy;
|
|
17390
|
+
const activeCompactionOptions = compactionOptions(input.agent);
|
|
17327
17391
|
const runTokenizer = yield* Effect87.serviceOption(Tokenizer4.Tokenizer);
|
|
17328
17392
|
const activeTokenizer = Option25.isSome(runTokenizer) ? runTokenizer : tokenizer;
|
|
17329
17393
|
const allocator = yield* make12(input.eventSequence + 1);
|
|
@@ -17396,25 +17460,25 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17396
17460
|
next_event_sequence: input.eventSequence + 1
|
|
17397
17461
|
}));
|
|
17398
17462
|
}
|
|
17399
|
-
if (
|
|
17463
|
+
if (activeCompactionOptions !== undefined && input.sessionId === undefined) {
|
|
17400
17464
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17401
17465
|
message: "Execution compaction requires session_id",
|
|
17402
17466
|
next_event_sequence: input.eventSequence + 1
|
|
17403
17467
|
}));
|
|
17404
17468
|
}
|
|
17405
|
-
if (
|
|
17469
|
+
if (activeCompactionOptions !== undefined && Option25.isNone(sessionRepository)) {
|
|
17406
17470
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17407
17471
|
message: "Execution compaction requires SessionRepository in context",
|
|
17408
17472
|
next_event_sequence: input.eventSequence + 1
|
|
17409
17473
|
}));
|
|
17410
17474
|
}
|
|
17411
|
-
if (
|
|
17475
|
+
if (activeCompactionOptions !== undefined && Option25.isNone(compactionRepository)) {
|
|
17412
17476
|
return yield* Effect87.fail(new AgentLoopError({
|
|
17413
17477
|
message: "Execution compaction requires CompactionRepository in context",
|
|
17414
17478
|
next_event_sequence: input.eventSequence + 1
|
|
17415
17479
|
}));
|
|
17416
17480
|
}
|
|
17417
|
-
const batonCompaction =
|
|
17481
|
+
const batonCompaction = compactionPolicy === undefined ? undefined : { contextWindow: compactionPolicy.context_window };
|
|
17418
17482
|
const batonOptions = {
|
|
17419
17483
|
...options,
|
|
17420
17484
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
@@ -17433,12 +17497,12 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17433
17497
|
...allCoreTools.length === 0 ? {} : { extraTools: allCoreTools }
|
|
17434
17498
|
});
|
|
17435
17499
|
const activeBlobStore = toolOutputMaxBytes === undefined || Option25.isNone(blobStore) ? undefined : blobStore.value;
|
|
17436
|
-
const activeCompactionRepository =
|
|
17500
|
+
const activeCompactionRepository = activeCompactionOptions === undefined || Option25.isNone(compactionRepository) ? undefined : compactionRepository.value;
|
|
17437
17501
|
const toolOutputStore = toolOutputMaxBytes === undefined ? undefined : exports_tool_output.ToolOutputStore.of(make11(activeBlobStore));
|
|
17438
|
-
const compactionService =
|
|
17502
|
+
const compactionService = activeCompactionOptions === undefined ? undefined : exports_compaction.Compaction.of(make9({
|
|
17439
17503
|
executionId: input.executionId,
|
|
17440
17504
|
repository: activeCompactionRepository,
|
|
17441
|
-
options:
|
|
17505
|
+
options: activeCompactionOptions
|
|
17442
17506
|
}));
|
|
17443
17507
|
if (memory !== undefined && Option25.isNone(durableMemory)) {
|
|
17444
17508
|
return yield* Effect87.fail(new AgentLoopError({
|
|
@@ -17446,6 +17510,16 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17446
17510
|
next_event_sequence: input.eventSequence + 1
|
|
17447
17511
|
}));
|
|
17448
17512
|
}
|
|
17513
|
+
const tokenBudget = input.agent.token_budget;
|
|
17514
|
+
const enforceBudget = (state) => tokenBudget === undefined || state.tokensUsed < tokenBudget ? Effect87.void : Effect87.gen(function* () {
|
|
17515
|
+
const budgetSequence = yield* allocator.allocate(1);
|
|
17516
|
+
yield* appendEvent(eventLog, budgetExceededEvent(input, state.tokensUsed, tokenBudget, budgetSequence), budgetSequence + 1);
|
|
17517
|
+
return yield* Effect87.fail(new AgentLoopBudgetExceeded({
|
|
17518
|
+
tokens_used: state.tokensUsed,
|
|
17519
|
+
token_budget: tokenBudget,
|
|
17520
|
+
next_event_sequence: budgetSequence + 1
|
|
17521
|
+
}));
|
|
17522
|
+
});
|
|
17449
17523
|
const foldEvent = (state, event) => Effect87.gen(function* () {
|
|
17450
17524
|
switch (event._tag) {
|
|
17451
17525
|
case "ModelPart": {
|
|
@@ -17462,6 +17536,18 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17462
17536
|
yield* appendEvent(eventLog, reasoningDeltaEvent(input, part, deltaIndex), sequence + 1);
|
|
17463
17537
|
return state;
|
|
17464
17538
|
}
|
|
17539
|
+
if (part.type === "tool-params-start") {
|
|
17540
|
+
return { ...state, toolCallNames: { ...state.toolCallNames, [part.id]: part.name } };
|
|
17541
|
+
}
|
|
17542
|
+
if (part.type === "tool-params-delta") {
|
|
17543
|
+
const sequence = yield* allocator.allocate(1);
|
|
17544
|
+
const deltaIndex = state.toolCallDeltaIndexes[part.id] ?? 0;
|
|
17545
|
+
yield* appendEvent(eventLog, toolCallDeltaEvent(input, part, state.toolCallNames[part.id], sequence, deltaIndex), sequence + 1);
|
|
17546
|
+
return {
|
|
17547
|
+
...state,
|
|
17548
|
+
toolCallDeltaIndexes: { ...state.toolCallDeltaIndexes, [part.id]: deltaIndex + 1 }
|
|
17549
|
+
};
|
|
17550
|
+
}
|
|
17465
17551
|
if (part.type === "finish") {
|
|
17466
17552
|
const finish = part;
|
|
17467
17553
|
const sequence = yield* allocator.allocate(1);
|
|
@@ -17481,19 +17567,13 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17481
17567
|
return state;
|
|
17482
17568
|
}
|
|
17483
17569
|
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
|
-
}
|
|
17570
|
+
if (event.turn > 0)
|
|
17571
|
+
yield* enforceBudget(state);
|
|
17493
17572
|
return state;
|
|
17494
17573
|
}
|
|
17495
17574
|
case "TurnCompleted": {
|
|
17496
17575
|
yield* persistTranscript(chats, input, event.transcript);
|
|
17576
|
+
yield* enforceBudget(state);
|
|
17497
17577
|
return { ...state, transcript: event.transcript, turn: event.turn };
|
|
17498
17578
|
}
|
|
17499
17579
|
case "Completed": {
|
|
@@ -17504,9 +17584,16 @@ var layer57 = Layer73.effect(Service54, Effect87.gen(function* () {
|
|
|
17504
17584
|
}
|
|
17505
17585
|
});
|
|
17506
17586
|
const runFold = Effect87.gen(function* () {
|
|
17507
|
-
const base2 = yield* LanguageModel7.LanguageModel;
|
|
17587
|
+
const base2 = withToolCallDecodeResilience(yield* LanguageModel7.LanguageModel, definitions2.map((definition) => definition.name), toolCallDecodeMaxRetries);
|
|
17508
17588
|
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(() => ({
|
|
17589
|
+
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream12.runFoldEffect(() => ({
|
|
17590
|
+
text: "",
|
|
17591
|
+
transcript: undefined,
|
|
17592
|
+
turn: undefined,
|
|
17593
|
+
tokensUsed: seededTokens,
|
|
17594
|
+
toolCallNames: {},
|
|
17595
|
+
toolCallDeltaIndexes: {}
|
|
17596
|
+
}), 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
17597
|
const withToolOutput = toolOutputStore === undefined ? folded : folded.pipe(Effect87.provideService(exports_tool_output.ToolOutputStore, toolOutputStore));
|
|
17511
17598
|
const withCompaction = compactionService === undefined ? withToolOutput : withToolOutput.pipe(Effect87.provideService(exports_compaction.Compaction, compactionService));
|
|
17512
17599
|
const withSession = sessionStore === undefined ? withCompaction : withCompaction.pipe(Effect87.provideService(exports_session.SessionStore, sessionStore));
|
|
@@ -18290,10 +18377,6 @@ var missingAgentSnapshot = () => new ExecutionWorkflowFailed({ message: "Agent s
|
|
|
18290
18377
|
var memorySubjectMetadataKey = "memory_subject_id";
|
|
18291
18378
|
var steeringEnabledMetadataKey = "steering_enabled";
|
|
18292
18379
|
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
18380
|
var continueAsNewAfterTurnsMetadataKey = "continue_as_new_after_turns";
|
|
18298
18381
|
var workflowGenerationMetadataKey = "workflow_generation";
|
|
18299
18382
|
var workflowGenerationForStart = (input) => input.workflow_generation ?? 0;
|
|
@@ -18312,7 +18395,6 @@ var metadataSetting = (input, key4) => {
|
|
|
18312
18395
|
return input.agent_snapshot?.metadata?.[key4];
|
|
18313
18396
|
return;
|
|
18314
18397
|
};
|
|
18315
|
-
var executionMetadataSetting = (input, key4) => hasMetadataKey(input.metadata, key4) ? input.metadata?.[key4] : undefined;
|
|
18316
18398
|
var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
18317
18399
|
if (value === undefined)
|
|
18318
18400
|
return Effect93.succeed(undefined);
|
|
@@ -18325,31 +18407,6 @@ var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
|
18325
18407
|
var optionalNumberForStart = (input, key4, valid) => decodeOptionalNumberSetting(metadataSetting(input, key4), key4, valid).pipe(Effect93.map((value) => value === null ? undefined : value));
|
|
18326
18408
|
var continueAsNewAfterTurnsForStart = (input) => optionalNumberForStart(input, continueAsNewAfterTurnsMetadataKey, (value) => Number.isInteger(value) && value > 0);
|
|
18327
18409
|
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
18410
|
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
18411
|
var memorySubjectForStart = Effect93.fn("ExecutionWorkflow.memorySubjectForStart")(function* (input) {
|
|
18355
18412
|
const executionSubject = memorySubjectFromMetadata(input.metadata);
|
|
@@ -18421,7 +18478,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
18421
18478
|
const runEventSequence = yield* nextEventSequence4(eventLog, input.execution_id);
|
|
18422
18479
|
const memorySubjectId = yield* memorySubjectForStart(input);
|
|
18423
18480
|
const toolOutputMaxBytes = yield* toolOutputMaxBytesForStart(input);
|
|
18424
|
-
const compaction = yield* compactionForStart(input);
|
|
18425
18481
|
const skillDefinitionIds = input.agent_snapshot.skill_definition_ids ?? [];
|
|
18426
18482
|
const loopProgram = agentLoop.run({
|
|
18427
18483
|
executionId: input.execution_id,
|
|
@@ -18437,7 +18493,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
18437
18493
|
...pendingToolCall === undefined ? {} : { resumeToolCall: pendingToolCall },
|
|
18438
18494
|
...memorySubjectId === undefined ? {} : { memorySubjectId },
|
|
18439
18495
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
18440
|
-
...compaction === undefined ? {} : { compaction },
|
|
18441
18496
|
eventSequence: runEventSequence + 1,
|
|
18442
18497
|
startedAt: input.started_at,
|
|
18443
18498
|
completedAt: input.completed_at,
|
|
@@ -18445,6 +18500,7 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
18445
18500
|
dispatchChildRun: (child) => StartExecutionWorkflow.execute({
|
|
18446
18501
|
execution_id: child.executionId,
|
|
18447
18502
|
root_address_id: child.rootAddressId,
|
|
18503
|
+
session_id: child.sessionId,
|
|
18448
18504
|
input: child.input,
|
|
18449
18505
|
event_sequence: child.eventSequence,
|
|
18450
18506
|
started_at: child.startedAt,
|
|
@@ -19408,7 +19464,6 @@ var layer66 = Layer85.effect(Service65, Effect99.gen(function* () {
|
|
|
19408
19464
|
entity_kind: input.kind,
|
|
19409
19465
|
entity_key: input.key,
|
|
19410
19466
|
entity_generation: instance.generation,
|
|
19411
|
-
compaction_enabled: input.metadata?.compaction_enabled ?? kind.metadata?.compaction_enabled ?? true,
|
|
19412
19467
|
...kind.state_enabled === undefined ? {} : { state_enabled: kind.state_enabled },
|
|
19413
19468
|
...kind.continue_as_new_after_turns === undefined ? {} : { continue_as_new_after_turns: kind.continue_as_new_after_turns }
|
|
19414
19469
|
};
|
|
@@ -19905,7 +19960,7 @@ __export(exports_definition_runtime, {
|
|
|
19905
19960
|
PinnedDefinitionMismatch: () => PinnedDefinitionMismatch,
|
|
19906
19961
|
HandlerService: () => HandlerService2
|
|
19907
19962
|
});
|
|
19908
|
-
import { Cause as
|
|
19963
|
+
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
19964
|
|
|
19910
19965
|
class UnsupportedOperation extends Schema103.TaggedErrorClass()("UnsupportedWorkflowOperation", { operation_id: exports_ids_schema.WorkflowOperationId, kind: Schema103.String }) {
|
|
19911
19966
|
}
|
|
@@ -20227,7 +20282,7 @@ var run5 = Effect102.fn("WorkflowDefinitionRuntime.run")(function* (executionId)
|
|
|
20227
20282
|
});
|
|
20228
20283
|
const result = yield* Effect102.exit(execute(revision.definition.entry_operation_id));
|
|
20229
20284
|
if (Exit3.isFailure(result)) {
|
|
20230
|
-
const failure3 =
|
|
20285
|
+
const failure3 = Cause6.findErrorOption(result.cause);
|
|
20231
20286
|
if (Option31.isSome(failure3) && failure3.value instanceof WorkflowJoining)
|
|
20232
20287
|
return yield* result;
|
|
20233
20288
|
const currentRun = yield* repository.inspect(executionId);
|
|
@@ -20576,6 +20631,7 @@ var overrideOf = (child) => {
|
|
|
20576
20631
|
return {
|
|
20577
20632
|
...override?.instructions === undefined ? {} : { instructions: override.instructions },
|
|
20578
20633
|
...override?.model === undefined ? {} : { model: override.model },
|
|
20634
|
+
...override?.compaction_policy === undefined ? {} : { compactionPolicy: override.compaction_policy },
|
|
20579
20635
|
...override?.tool_names === undefined ? {} : { toolNames: override.tool_names },
|
|
20580
20636
|
...override?.permissions === undefined ? {} : { permissions: override.permissions },
|
|
20581
20637
|
...override?.workspace_policy === undefined ? {} : { workspacePolicy: override.workspace_policy },
|