@relayfx/test 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/index.js +156 -100
- 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 +2 -2
package/dist/index.js
CHANGED
|
@@ -185,6 +185,7 @@ __export(exports_agent_schema, {
|
|
|
185
185
|
DefinitionRecord: () => DefinitionRecord,
|
|
186
186
|
DefinitionList: () => DefinitionList,
|
|
187
187
|
Definition: () => Definition2,
|
|
188
|
+
CompactionPolicy: () => CompactionPolicy,
|
|
188
189
|
ChildRunWorkspacePolicy: () => ChildRunWorkspacePolicy,
|
|
189
190
|
ChildRunPreset: () => ChildRunPreset
|
|
190
191
|
});
|
|
@@ -336,6 +337,12 @@ var ModelSelection = Schema5.Struct({
|
|
|
336
337
|
request_options: Schema5.optionalKey(Metadata),
|
|
337
338
|
metadata: Schema5.optionalKey(Metadata)
|
|
338
339
|
}).annotate({ identifier: "Relay.Agent.ModelSelection" });
|
|
340
|
+
var PositiveSafeInteger = Schema5.Number.check(Schema5.makeFilter((value) => Number.isSafeInteger(value) && value > 0 ? undefined : "must be a positive safe integer"));
|
|
341
|
+
var CompactionPolicy = Schema5.Struct({
|
|
342
|
+
context_window: PositiveSafeInteger,
|
|
343
|
+
reserve_tokens: PositiveSafeInteger,
|
|
344
|
+
keep_recent_tokens: PositiveSafeInteger
|
|
345
|
+
}).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" });
|
|
339
346
|
var ChildRunWorkspacePolicy = Schema5.Struct({
|
|
340
347
|
mode: Schema5.Literals(["share", "fork"]),
|
|
341
348
|
fallback: Schema5.optionalKey(Schema5.Literals(["fail", "fresh"]))
|
|
@@ -343,6 +350,7 @@ var ChildRunWorkspacePolicy = Schema5.Struct({
|
|
|
343
350
|
var ChildRunPreset = Schema5.Struct({
|
|
344
351
|
instructions: Schema5.optionalKey(Schema5.String),
|
|
345
352
|
model: Schema5.optionalKey(ModelSelection),
|
|
353
|
+
compaction_policy: Schema5.optionalKey(CompactionPolicy),
|
|
346
354
|
tool_names: Schema5.optionalKey(Schema5.Array(Schema5.String)),
|
|
347
355
|
permissions: Schema5.optionalKey(Schema5.Array(Schema5.String)),
|
|
348
356
|
workspace_policy: Schema5.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -426,6 +434,7 @@ var DefinitionSchema = Schema5.Struct({
|
|
|
426
434
|
skill_definition_ids: Schema5.optionalKey(Schema5.Array(SkillDefinitionId)),
|
|
427
435
|
permission_rules: Schema5.optionalKey(PermissionRuleset),
|
|
428
436
|
turn_policy: Schema5.optionalKey(TurnPolicySnapshot),
|
|
437
|
+
compaction_policy: Schema5.optionalKey(CompactionPolicy),
|
|
429
438
|
max_tool_turns: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(1))),
|
|
430
439
|
max_wait_turns: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(0))),
|
|
431
440
|
token_budget: Schema5.optionalKey(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(1))),
|
|
@@ -446,6 +455,7 @@ var define = (input) => ({
|
|
|
446
455
|
...input.skill_definition_ids === undefined ? {} : { skill_definition_ids: input.skill_definition_ids },
|
|
447
456
|
...input.permission_rules === undefined ? {} : { permission_rules: input.permission_rules },
|
|
448
457
|
...input.turn_policy === undefined ? {} : { turn_policy: input.turn_policy },
|
|
458
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
449
459
|
...input.max_tool_turns === undefined ? {} : { max_tool_turns: input.max_tool_turns },
|
|
450
460
|
...input.max_wait_turns === undefined ? {} : { max_wait_turns: input.max_wait_turns },
|
|
451
461
|
...input.token_budget === undefined ? {} : { token_budget: input.token_budget },
|
|
@@ -499,6 +509,7 @@ import { Schema as Schema8 } from "effect";
|
|
|
499
509
|
// ../schema/src/execution-schema.ts
|
|
500
510
|
var exports_execution_schema = {};
|
|
501
511
|
__export(exports_execution_schema, {
|
|
512
|
+
childSessionId: () => childSessionId,
|
|
502
513
|
SpawnChildRunInput: () => SpawnChildRunInput,
|
|
503
514
|
ExecutionStatus: () => ExecutionStatus,
|
|
504
515
|
ExecutionEventType: () => ExecutionEventType,
|
|
@@ -603,6 +614,7 @@ var ExecutionEventSequence = Schema7.Int.check(Schema7.isGreaterThanOrEqualTo(0)
|
|
|
603
614
|
var ChildRunContext = Schema7.Struct({
|
|
604
615
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
605
616
|
model: Schema7.optionalKey(ModelSelection),
|
|
617
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
606
618
|
tool_names: Schema7.Array(Schema7.String),
|
|
607
619
|
permissions: Schema7.Array(Schema7.String),
|
|
608
620
|
output_schema_ref: Schema7.optionalKey(Schema7.String),
|
|
@@ -611,6 +623,7 @@ var ChildRunContext = Schema7.Struct({
|
|
|
611
623
|
var ChildRunOverride = Schema7.Struct({
|
|
612
624
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
613
625
|
model: Schema7.optionalKey(ModelSelection),
|
|
626
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
614
627
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
615
628
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
616
629
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -627,6 +640,7 @@ var SpawnChildRunInput = Schema7.Struct({
|
|
|
627
640
|
preset_name: Schema7.optionalKey(NonEmptyString),
|
|
628
641
|
instructions: Schema7.optionalKey(Schema7.String),
|
|
629
642
|
model: Schema7.optionalKey(ModelSelection),
|
|
643
|
+
compaction_policy: Schema7.optionalKey(CompactionPolicy),
|
|
630
644
|
tool_names: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
631
645
|
permissions: Schema7.optionalKey(Schema7.Array(Schema7.String)),
|
|
632
646
|
workspace_policy: Schema7.optionalKey(ChildRunWorkspacePolicy),
|
|
@@ -641,6 +655,7 @@ var ChildRunAccepted = Schema7.Struct({
|
|
|
641
655
|
child_execution_id: ChildExecutionId,
|
|
642
656
|
execution_id: ExecutionId
|
|
643
657
|
}).annotate({ identifier: "Relay.ChildRunAccepted" });
|
|
658
|
+
var childSessionId = (childExecutionId) => SessionId.make(`session:child:${childExecutionId}`);
|
|
644
659
|
var ExecutionEventType = Schema7.Literals([
|
|
645
660
|
"execution.accepted",
|
|
646
661
|
"execution.started",
|
|
@@ -650,6 +665,7 @@ var ExecutionEventType = Schema7.Literals([
|
|
|
650
665
|
"model.input.prepared",
|
|
651
666
|
"model.output.delta",
|
|
652
667
|
"model.reasoning.delta",
|
|
668
|
+
"model.toolcall.delta",
|
|
653
669
|
"model.output.completed",
|
|
654
670
|
"model.usage.reported",
|
|
655
671
|
"budget.exceeded",
|
|
@@ -11299,7 +11315,7 @@ var resolveLocalAgent = Effect37.fn("AddressResolution.resolveLocalAgent.call")(
|
|
|
11299
11315
|
const service = yield* Service34;
|
|
11300
11316
|
return yield* service.resolveLocalAgent(addressId);
|
|
11301
11317
|
});
|
|
11302
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11318
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent.js
|
|
11303
11319
|
var exports_agent = {};
|
|
11304
11320
|
__export(exports_agent, {
|
|
11305
11321
|
streamObject: () => streamObject,
|
|
@@ -11312,7 +11328,7 @@ __export(exports_agent, {
|
|
|
11312
11328
|
import { Cause as Cause3, Effect as Effect53, Fiber, Option as Option18, Queue as Queue2, Ref as Ref14, Schema as Schema62, Stream as Stream9 } from "effect";
|
|
11313
11329
|
import { Chat, LanguageModel as LanguageModel5, Prompt as Prompt8, Response as Response6, Telemetry, Tokenizer as Tokenizer2, Tool as Tool5, Toolkit as Toolkit4 } from "effect/unstable/ai";
|
|
11314
11330
|
|
|
11315
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11331
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent-event.js
|
|
11316
11332
|
var exports_agent_event = {};
|
|
11317
11333
|
__export(exports_agent_event, {
|
|
11318
11334
|
addUsage: () => addUsage,
|
|
@@ -11369,7 +11385,7 @@ class AgentSuspended extends Schema52.TaggedErrorClass()("@batonfx/core/AgentSus
|
|
|
11369
11385
|
}) {
|
|
11370
11386
|
}
|
|
11371
11387
|
|
|
11372
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11388
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/approvals.js
|
|
11373
11389
|
var exports_approvals = {};
|
|
11374
11390
|
__export(exports_approvals, {
|
|
11375
11391
|
testLayer: () => testLayer28,
|
|
@@ -11379,7 +11395,7 @@ __export(exports_approvals, {
|
|
|
11379
11395
|
});
|
|
11380
11396
|
import { Context as Context37, Effect as Effect40, Layer as Layer37 } from "effect";
|
|
11381
11397
|
|
|
11382
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11398
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-executor.js
|
|
11383
11399
|
var exports_tool_executor = {};
|
|
11384
11400
|
__export(exports_tool_executor, {
|
|
11385
11401
|
testLayer: () => testLayer27,
|
|
@@ -11397,7 +11413,7 @@ __export(exports_tool_executor, {
|
|
|
11397
11413
|
import { Cause, Context as Context36, Effect as Effect39, Layer as Layer36, Option as Option10, Schedule as Schedule3, Schema as Schema53, Sink as Sink2, Stream as Stream7 } from "effect";
|
|
11398
11414
|
import { Response as Response2, Tool as Tool3, Toolkit as Toolkit2 } from "effect/unstable/ai";
|
|
11399
11415
|
|
|
11400
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11416
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-context.js
|
|
11401
11417
|
import { Context as Context35, Effect as Effect38, Layer as Layer35 } from "effect";
|
|
11402
11418
|
|
|
11403
11419
|
class ToolContext extends Context35.Service()("@batonfx/core/ToolContext") {
|
|
@@ -11408,7 +11424,7 @@ var layerDefault = Layer35.sync(ToolContext, () => ToolContext.of({
|
|
|
11408
11424
|
sessionId: "local"
|
|
11409
11425
|
}));
|
|
11410
11426
|
|
|
11411
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11427
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-executor.js
|
|
11412
11428
|
class ToolExecutor extends Context36.Service()("@batonfx/core/ToolExecutor") {
|
|
11413
11429
|
}
|
|
11414
11430
|
var failureMessage = (cause) => {
|
|
@@ -11519,14 +11535,14 @@ function router(routes) {
|
|
|
11519
11535
|
}
|
|
11520
11536
|
var testLayer27 = (implementation) => Layer36.succeed(ToolExecutor, ToolExecutor.of(implementation));
|
|
11521
11537
|
|
|
11522
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11538
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/approvals.js
|
|
11523
11539
|
class Approvals extends Context37.Service()("@batonfx/core/Approvals") {
|
|
11524
11540
|
}
|
|
11525
11541
|
var autoApprove = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect40.succeed({ _tag: "Approved" }) }));
|
|
11526
11542
|
var denyAll = Layer37.succeed(Approvals, Approvals.of({ check: () => Effect40.succeed({ _tag: "Denied" }) }));
|
|
11527
11543
|
var testLayer28 = (implementation) => Layer37.succeed(Approvals, Approvals.of(implementation));
|
|
11528
11544
|
|
|
11529
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11545
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/compaction.js
|
|
11530
11546
|
var exports_compaction = {};
|
|
11531
11547
|
__export(exports_compaction, {
|
|
11532
11548
|
truncate: () => truncate,
|
|
@@ -11549,7 +11565,7 @@ __export(exports_compaction, {
|
|
|
11549
11565
|
import { Context as Context40, Effect as Effect43, Layer as Layer40, Option as Option13, Schema as Schema56 } from "effect";
|
|
11550
11566
|
import { LanguageModel, Prompt as Prompt3, Tokenizer, Toolkit as Toolkit3 } from "effect/unstable/ai";
|
|
11551
11567
|
|
|
11552
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11568
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/session.js
|
|
11553
11569
|
var exports_session = {};
|
|
11554
11570
|
__export(exports_session, {
|
|
11555
11571
|
testLayer: () => testLayer29,
|
|
@@ -11722,7 +11738,7 @@ var memoryLayer31 = Layer38.effect(SessionStore, Ref10.make(initialState).pipe(E
|
|
|
11722
11738
|
}))));
|
|
11723
11739
|
var testLayer29 = (implementation) => Layer38.succeed(SessionStore, SessionStore.of(implementation));
|
|
11724
11740
|
|
|
11725
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11741
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/tool-output.js
|
|
11726
11742
|
var exports_tool_output = {};
|
|
11727
11743
|
__export(exports_tool_output, {
|
|
11728
11744
|
testLayer: () => testLayer30,
|
|
@@ -11781,7 +11797,7 @@ var bound = (result, options) => Effect42.gen(function* () {
|
|
|
11781
11797
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
11782
11798
|
});
|
|
11783
11799
|
|
|
11784
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
11800
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/compaction.js
|
|
11785
11801
|
var DEFAULT_RESERVE_TOKENS = 16384;
|
|
11786
11802
|
var DEFAULT_KEEP_RECENT_TOKENS = 20000;
|
|
11787
11803
|
var SUMMARY_TEMPLATE = `Summarize the conversation so another agent can continue seamlessly.
|
|
@@ -12031,7 +12047,7 @@ var truncate = (maxTokens) => ({
|
|
|
12031
12047
|
var testLayer31 = (implementation) => Layer40.succeed(Compaction, Compaction.of(implementation));
|
|
12032
12048
|
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));
|
|
12033
12049
|
|
|
12034
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12050
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/instructions.js
|
|
12035
12051
|
var exports_instructions = {};
|
|
12036
12052
|
__export(exports_instructions, {
|
|
12037
12053
|
testLayer: () => testLayer32,
|
|
@@ -12079,7 +12095,7 @@ var renderUpdate = (epoch, context) => Effect44.gen(function* () {
|
|
|
12079
12095
|
var layer33 = (sources) => Layer41.succeed(Instructions, Instructions.of({ sources: [...sources] }));
|
|
12080
12096
|
var testLayer32 = (implementation) => Layer41.succeed(Instructions, Instructions.of(implementation));
|
|
12081
12097
|
|
|
12082
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12098
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/memory.js
|
|
12083
12099
|
var exports_memory = {};
|
|
12084
12100
|
__export(exports_memory, {
|
|
12085
12101
|
testLayer: () => testLayer33,
|
|
@@ -12111,7 +12127,7 @@ var merge = (first, second) => ({
|
|
|
12111
12127
|
var noopLayer = Layer42.succeed(Memory, Memory.of(noop));
|
|
12112
12128
|
var testLayer33 = (implementation) => Layer42.succeed(Memory, Memory.of(implementation));
|
|
12113
12129
|
|
|
12114
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12130
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-middleware.js
|
|
12115
12131
|
var exports_model_middleware = {};
|
|
12116
12132
|
__export(exports_model_middleware, {
|
|
12117
12133
|
layer: () => layer34,
|
|
@@ -12125,7 +12141,7 @@ class ModelMiddleware extends Context43.Service()("@batonfx/core/ModelMiddleware
|
|
|
12125
12141
|
var identityLayer = Layer43.succeed(ModelMiddleware, []);
|
|
12126
12142
|
var layer34 = (middleware) => Layer43.succeed(ModelMiddleware, middleware);
|
|
12127
12143
|
|
|
12128
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12144
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-registry.js
|
|
12129
12145
|
var exports_model_registry = {};
|
|
12130
12146
|
__export(exports_model_registry, {
|
|
12131
12147
|
testLayer: () => testLayer34,
|
|
@@ -12214,7 +12230,7 @@ var provide = (selection, effect) => Effect47.gen(function* () {
|
|
|
12214
12230
|
return yield* service.provide(selection, effect);
|
|
12215
12231
|
});
|
|
12216
12232
|
|
|
12217
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12233
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/model-resilience.js
|
|
12218
12234
|
var exports_model_resilience = {};
|
|
12219
12235
|
__export(exports_model_resilience, {
|
|
12220
12236
|
testLayer: () => testLayer35,
|
|
@@ -12260,7 +12276,7 @@ var apply = (model, resilience) => ({
|
|
|
12260
12276
|
}).pipe(Stream8.retry(retryStreamSchedule(resilience)))
|
|
12261
12277
|
});
|
|
12262
12278
|
|
|
12263
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12279
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/permissions.js
|
|
12264
12280
|
var exports_permissions = {};
|
|
12265
12281
|
__export(exports_permissions, {
|
|
12266
12282
|
testLayer: () => testLayer36,
|
|
@@ -12390,7 +12406,7 @@ var ruleStoreMemory = (initialRules = []) => Layer46.effect(RuleStore, Ref13.mak
|
|
|
12390
12406
|
var ruleStoreTestLayer = (implementation) => Layer46.succeed(RuleStore, RuleStore.of(implementation));
|
|
12391
12407
|
var testLayer36 = (implementation) => Layer46.succeed(Permissions, Permissions.of(implementation));
|
|
12392
12408
|
|
|
12393
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12409
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/skill-source.js
|
|
12394
12410
|
var exports_skill_source = {};
|
|
12395
12411
|
__export(exports_skill_source, {
|
|
12396
12412
|
testLayer: () => testLayer37,
|
|
@@ -12470,7 +12486,7 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
12470
12486
|
return selected;
|
|
12471
12487
|
};
|
|
12472
12488
|
|
|
12473
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12489
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/steering.js
|
|
12474
12490
|
var exports_steering = {};
|
|
12475
12491
|
__export(exports_steering, {
|
|
12476
12492
|
testLayer: () => testLayer38,
|
|
@@ -12528,7 +12544,7 @@ var layer38 = (options = {}) => Layer48.effect(Steering, Effect51.gen(function*
|
|
|
12528
12544
|
}));
|
|
12529
12545
|
var testLayer38 = (implementation) => Layer48.succeed(Steering, Steering.of(implementation));
|
|
12530
12546
|
|
|
12531
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12547
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/turn-policy.js
|
|
12532
12548
|
var exports_turn_policy = {};
|
|
12533
12549
|
__export(exports_turn_policy, {
|
|
12534
12550
|
untilToolCall: () => untilToolCall,
|
|
@@ -12577,7 +12593,7 @@ var both = (first, second) => ({
|
|
|
12577
12593
|
});
|
|
12578
12594
|
var defaultPolicy = recurs(8);
|
|
12579
12595
|
|
|
12580
|
-
// ../../node_modules/.bun/@batonfx+core@0.4.
|
|
12596
|
+
// ../../node_modules/.bun/@batonfx+core@0.4.3/node_modules/@batonfx/core/dist/agent.js
|
|
12581
12597
|
function make5(nameOrOptions, options = {}) {
|
|
12582
12598
|
const resolved = typeof nameOrOptions === "string" ? { ...options, name: nameOrOptions } : nameOrOptions;
|
|
12583
12599
|
return {
|
|
@@ -12763,8 +12779,7 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12763
12779
|
turn: 0,
|
|
12764
12780
|
pending: [],
|
|
12765
12781
|
finish: undefined,
|
|
12766
|
-
usage: undefined
|
|
12767
|
-
contextTokens: undefined
|
|
12782
|
+
usage: undefined
|
|
12768
12783
|
};
|
|
12769
12784
|
const activatedSkillBodies = new Map;
|
|
12770
12785
|
const activatedSkillTools = new Map;
|
|
@@ -12815,10 +12830,8 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
12815
12830
|
})
|
|
12816
12831
|
});
|
|
12817
12832
|
const countTokens = (turn, prompt) => {
|
|
12818
|
-
if (state.contextTokens !== undefined)
|
|
12819
|
-
return Effect53.succeed(state.contextTokens);
|
|
12820
12833
|
return Option18.match(tokenizerService, {
|
|
12821
|
-
onNone: () => Effect53.succeed(
|
|
12834
|
+
onNone: () => Effect53.succeed(Math.ceil(JSON.stringify(prompt.content).length / 4)),
|
|
12822
12835
|
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(Effect53.map((tokens) => tokens.length), Effect53.mapError((error5) => new AgentError({ message: errorMessage(error5), turn, cause: error5 })))
|
|
12823
12836
|
});
|
|
12824
12837
|
};
|
|
@@ -13027,7 +13040,6 @@ var streamInternal = (agent, options, structured) => Stream9.unwrap(Effect53.gen
|
|
|
13027
13040
|
reason: part.reason
|
|
13028
13041
|
};
|
|
13029
13042
|
state.usage = state.usage === undefined ? part.usage : addUsage(state.usage, part.usage);
|
|
13030
|
-
state.contextTokens = part.usage.inputTokens.total ?? state.contextTokens;
|
|
13031
13043
|
Telemetry.addGenAIAnnotations(span, {
|
|
13032
13044
|
operation: { name: "chat" },
|
|
13033
13045
|
usage: {
|
|
@@ -13281,8 +13293,8 @@ var generateObject = (agent, options) => Stream9.runFold(streamObject(agent, opt
|
|
|
13281
13293
|
})
|
|
13282
13294
|
})));
|
|
13283
13295
|
// ../runtime/src/agent/agent-loop-service.ts
|
|
13284
|
-
import { Config as Config4, Context as Context72, Crypto as Crypto3, Effect as Effect90, HashSet as HashSet7, Layer as Layer79, Option as Option27, Ref as Ref23, Schema as Schema91, Stream as Stream12 } from "effect";
|
|
13285
|
-
import { Chat as Chat3, LanguageModel as LanguageModel7, Prompt as Prompt13, Tokenizer as Tokenizer4, Toolkit as Toolkit6 } from "effect/unstable/ai";
|
|
13296
|
+
import { Cause as Cause4, Config as Config4, Context as Context72, Crypto as Crypto3, Effect as Effect90, HashSet as HashSet7, Layer as Layer79, Option as Option27, Ref as Ref23, Schema as Schema91, Stream as Stream12 } from "effect";
|
|
13297
|
+
import { AiError as AiError4, Chat as Chat3, LanguageModel as LanguageModel7, Prompt as Prompt13, Tokenizer as Tokenizer4, Toolkit as Toolkit6 } from "effect/unstable/ai";
|
|
13286
13298
|
|
|
13287
13299
|
// ../runtime/src/child/child-run-service.ts
|
|
13288
13300
|
import { Context as Context50, Effect as Effect55, HashSet as HashSet5, Layer as Layer51, Option as Option19, Result as Result2, Schema as Schema64 } from "effect";
|
|
@@ -13376,6 +13388,7 @@ var resolveContext = (parent, override) => {
|
|
|
13376
13388
|
const permissions = override?.permissions ?? parent.permissions;
|
|
13377
13389
|
const instructions = override?.instructions ?? parent.instructions;
|
|
13378
13390
|
const model = override?.model ?? parent.model;
|
|
13391
|
+
const compactionPolicy = override?.compactionPolicy ?? parent.compactionPolicy;
|
|
13379
13392
|
const workspacePolicy = override?.workspacePolicy;
|
|
13380
13393
|
const outputSchemaRef = override?.outputSchemaRef ?? parent.outputSchemaRef;
|
|
13381
13394
|
const broadenedTool = subsetViolation(parent.toolNames, toolNames);
|
|
@@ -13395,6 +13408,7 @@ var resolveContext = (parent, override) => {
|
|
|
13395
13408
|
},
|
|
13396
13409
|
...instructions === undefined ? {} : { instructions },
|
|
13397
13410
|
...model === undefined ? {} : { model },
|
|
13411
|
+
...compactionPolicy === undefined ? {} : { compactionPolicy },
|
|
13398
13412
|
...workspacePolicy === undefined ? {} : { workspacePolicy },
|
|
13399
13413
|
...outputSchemaRef === undefined ? {} : { outputSchemaRef }
|
|
13400
13414
|
});
|
|
@@ -13541,12 +13555,14 @@ var agentContextFromSchema = (input) => ({
|
|
|
13541
13555
|
permissions: input.permissions,
|
|
13542
13556
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13543
13557
|
...input.model === undefined ? {} : { model: input.model },
|
|
13558
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13544
13559
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
13545
13560
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13546
13561
|
});
|
|
13547
13562
|
var overrideFromSchema = (input) => ({
|
|
13548
13563
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13549
13564
|
...input.model === undefined ? {} : { model: input.model },
|
|
13565
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13550
13566
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
13551
13567
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
13552
13568
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -13554,7 +13570,7 @@ var overrideFromSchema = (input) => ({
|
|
|
13554
13570
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
13555
13571
|
});
|
|
13556
13572
|
var dynamicOverrideFromSpawn = (input) => {
|
|
13557
|
-
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) {
|
|
13573
|
+
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) {
|
|
13558
13574
|
return;
|
|
13559
13575
|
}
|
|
13560
13576
|
return overrideFromSchema(input);
|
|
@@ -13576,6 +13592,7 @@ var childDefinition = (parentDefinition, context) => context.model === undefined
|
|
|
13576
13592
|
tool_names: [...context.toolNames],
|
|
13577
13593
|
permissions: parentDefinition.permissions.filter((permission) => context.permissions.includes(permission.name)),
|
|
13578
13594
|
child_run_presets: {},
|
|
13595
|
+
...context.compactionPolicy === undefined ? {} : { compaction_policy: context.compactionPolicy },
|
|
13579
13596
|
...parentDefinition.turn_policy === undefined ? {} : { turn_policy: parentDefinition.turn_policy },
|
|
13580
13597
|
...parentDefinition.max_tool_turns === undefined ? {} : { max_tool_turns: parentDefinition.max_tool_turns },
|
|
13581
13598
|
...parentDefinition.max_wait_turns === undefined ? {} : { max_wait_turns: parentDefinition.max_wait_turns },
|
|
@@ -13600,6 +13617,7 @@ var Input = Schema65.Struct({
|
|
|
13600
13617
|
preset_name: Schema65.optionalKey(exports_shared_schema.NonEmptyString),
|
|
13601
13618
|
instructions: Schema65.optionalKey(Schema65.String),
|
|
13602
13619
|
model: Schema65.optionalKey(exports_agent_schema.ModelSelection),
|
|
13620
|
+
compaction_policy: Schema65.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
13603
13621
|
tool_names: Schema65.optionalKey(Schema65.Array(Schema65.String)),
|
|
13604
13622
|
permissions: Schema65.optionalKey(Schema65.Array(Schema65.String)),
|
|
13605
13623
|
output_schema_ref: Schema65.optionalKey(Schema65.String),
|
|
@@ -13622,6 +13640,7 @@ var ModelInput = Schema65.Struct({
|
|
|
13622
13640
|
model: Schema65.String,
|
|
13623
13641
|
registration_key: Schema65.optionalKey(Schema65.String)
|
|
13624
13642
|
}))),
|
|
13643
|
+
compaction_policy: Schema65.optionalKey(exports_agent_schema.CompactionPolicy),
|
|
13625
13644
|
tool_names: Schema65.optionalKey(Schema65.Array(Schema65.String)),
|
|
13626
13645
|
permissions: Schema65.optionalKey(Schema65.Array(Schema65.String)),
|
|
13627
13646
|
output_schema_ref: Schema65.optionalKey(Schema65.NullOr(Schema65.String)),
|
|
@@ -13643,6 +13662,7 @@ var enabled = (agent) => agent.metadata?.multi_agent_enabled === true;
|
|
|
13643
13662
|
var parentContext = (agent) => ({
|
|
13644
13663
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
13645
13664
|
model: agent.model,
|
|
13665
|
+
...agent.compaction_policy === undefined ? {} : { compaction_policy: agent.compaction_policy },
|
|
13646
13666
|
tool_names: agent.tool_names,
|
|
13647
13667
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
13648
13668
|
...agent.output_schema_ref === undefined ? {} : { output_schema_ref: agent.output_schema_ref },
|
|
@@ -13651,12 +13671,13 @@ var parentContext = (agent) => ({
|
|
|
13651
13671
|
var serviceParentContext = (agent) => ({
|
|
13652
13672
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
13653
13673
|
model: agent.model,
|
|
13674
|
+
...agent.compaction_policy === undefined ? {} : { compactionPolicy: agent.compaction_policy },
|
|
13654
13675
|
toolNames: agent.tool_names,
|
|
13655
13676
|
permissions: agent.permissions.map((permission) => permission.name),
|
|
13656
13677
|
...agent.output_schema_ref === undefined ? {} : { outputSchemaRef: agent.output_schema_ref },
|
|
13657
13678
|
...agent.metadata === undefined ? {} : { metadata: agent.metadata }
|
|
13658
13679
|
});
|
|
13659
|
-
var hasDynamicOverride = (input) => input.instructions !== undefined || input.model !== undefined || input.tool_names !== undefined || input.permissions !== undefined || input.output_schema_ref !== undefined || input.metadata !== undefined;
|
|
13680
|
+
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;
|
|
13660
13681
|
var childExecutionId = (context) => exports_ids_schema.ChildExecutionId.make(`${context.executionId}:child:${context.call.id}`);
|
|
13661
13682
|
var childAddressId = (id2) => exports_ids_schema.AddressId.make(`address:child:${id2}`);
|
|
13662
13683
|
var childWaitId = (id2) => exports_ids_schema.WaitId.make(`wait:child:${id2}`);
|
|
@@ -13672,6 +13693,7 @@ var spawnInput = (config, input, context, id2) => ({
|
|
|
13672
13693
|
...input.preset_name === undefined ? {} : { preset_name: input.preset_name },
|
|
13673
13694
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13674
13695
|
...input.model === undefined ? {} : { model: input.model },
|
|
13696
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
13675
13697
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
13676
13698
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
13677
13699
|
...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
|
|
@@ -13691,6 +13713,7 @@ var childOverride = (input) => {
|
|
|
13691
13713
|
return {
|
|
13692
13714
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
13693
13715
|
...input.model === undefined ? {} : { model: input.model },
|
|
13716
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
13694
13717
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
13695
13718
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
13696
13719
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
@@ -13702,6 +13725,7 @@ var presetMap = (agent) => new Map(Object.entries(agent.child_run_presets ?? {})
|
|
|
13702
13725
|
{
|
|
13703
13726
|
...preset.instructions === undefined ? {} : { instructions: preset.instructions },
|
|
13704
13727
|
...preset.model === undefined ? {} : { model: preset.model },
|
|
13728
|
+
...preset.compaction_policy === undefined ? {} : { compactionPolicy: preset.compaction_policy },
|
|
13705
13729
|
...preset.tool_names === undefined ? {} : { toolNames: preset.tool_names },
|
|
13706
13730
|
...preset.permissions === undefined ? {} : { permissions: preset.permissions },
|
|
13707
13731
|
...preset.workspace_policy === undefined ? {} : { workspacePolicy: preset.workspace_policy },
|
|
@@ -13728,6 +13752,7 @@ var dispatchChild = Effect56.fn("SpawnChildRunTool.dispatchChild")(function* (co
|
|
|
13728
13752
|
yield* config.dispatch({
|
|
13729
13753
|
executionId: exports_ids_schema.ExecutionId.make(id2),
|
|
13730
13754
|
rootAddressId: input.address_id,
|
|
13755
|
+
sessionId: exports_execution_schema.childSessionId(id2),
|
|
13731
13756
|
input: input.input ?? [],
|
|
13732
13757
|
eventSequence: 0,
|
|
13733
13758
|
startedAt: (input.created_at ?? 0) + 2,
|
|
@@ -15000,12 +15025,14 @@ var childContext = (input) => ({
|
|
|
15000
15025
|
permissions: input.permissions,
|
|
15001
15026
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
15002
15027
|
...input.model === undefined ? {} : { model: input.model },
|
|
15028
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
15003
15029
|
...input.output_schema_ref === undefined ? {} : { outputSchemaRef: input.output_schema_ref },
|
|
15004
15030
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
15005
15031
|
});
|
|
15006
15032
|
var childOverride2 = (input) => ({
|
|
15007
15033
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
15008
15034
|
...input.model === undefined ? {} : { model: input.model },
|
|
15035
|
+
...input.compaction_policy === undefined ? {} : { compactionPolicy: input.compaction_policy },
|
|
15009
15036
|
...input.tool_names === undefined ? {} : { toolNames: input.tool_names },
|
|
15010
15037
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
15011
15038
|
...input.workspace_policy === undefined ? {} : { workspacePolicy: input.workspace_policy },
|
|
@@ -15013,12 +15040,13 @@ var childOverride2 = (input) => ({
|
|
|
15013
15040
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
15014
15041
|
});
|
|
15015
15042
|
var dynamicOverride = (input) => {
|
|
15016
|
-
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) {
|
|
15043
|
+
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) {
|
|
15017
15044
|
return;
|
|
15018
15045
|
}
|
|
15019
15046
|
return childOverride2({
|
|
15020
15047
|
...input.instructions === undefined ? {} : { instructions: input.instructions },
|
|
15021
15048
|
...input.model === undefined ? {} : { model: input.model },
|
|
15049
|
+
...input.compaction_policy === undefined ? {} : { compaction_policy: input.compaction_policy },
|
|
15022
15050
|
...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
|
|
15023
15051
|
...input.permissions === undefined ? {} : { permissions: input.permissions },
|
|
15024
15052
|
...input.workspace_policy === undefined ? {} : { workspace_policy: input.workspace_policy },
|
|
@@ -15943,10 +15971,6 @@ var missingAgentSnapshot = () => new ExecutionWorkflowFailed({ message: "Agent s
|
|
|
15943
15971
|
var memorySubjectMetadataKey = "memory_subject_id";
|
|
15944
15972
|
var steeringEnabledMetadataKey = "steering_enabled";
|
|
15945
15973
|
var toolOutputMaxBytesMetadataKey = "tool_output_max_bytes";
|
|
15946
|
-
var compactionEnabledMetadataKey = "compaction_enabled";
|
|
15947
|
-
var compactionContextWindowMetadataKey = "compaction_context_window";
|
|
15948
|
-
var compactionReserveTokensMetadataKey = "compaction_reserve_tokens";
|
|
15949
|
-
var compactionKeepRecentTokensMetadataKey = "compaction_keep_recent_tokens";
|
|
15950
15974
|
var continueAsNewAfterTurnsMetadataKey = "continue_as_new_after_turns";
|
|
15951
15975
|
var workflowGenerationMetadataKey = "workflow_generation";
|
|
15952
15976
|
var workflowGenerationForStart = (input) => input.workflow_generation ?? 0;
|
|
@@ -15965,7 +15989,6 @@ var metadataSetting = (input, key4) => {
|
|
|
15965
15989
|
return input.agent_snapshot?.metadata?.[key4];
|
|
15966
15990
|
return;
|
|
15967
15991
|
};
|
|
15968
|
-
var executionMetadataSetting = (input, key4) => hasMetadataKey(input.metadata, key4) ? input.metadata?.[key4] : undefined;
|
|
15969
15992
|
var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
15970
15993
|
if (value === undefined)
|
|
15971
15994
|
return Effect74.succeed(undefined);
|
|
@@ -15978,31 +16001,6 @@ var decodeOptionalNumberSetting = (value, key4, valid) => {
|
|
|
15978
16001
|
var optionalNumberForStart = (input, key4, valid) => decodeOptionalNumberSetting(metadataSetting(input, key4), key4, valid).pipe(Effect74.map((value) => value === null ? undefined : value));
|
|
15979
16002
|
var continueAsNewAfterTurnsForStart = (input) => optionalNumberForStart(input, continueAsNewAfterTurnsMetadataKey, (value) => Number.isInteger(value) && value > 0);
|
|
15980
16003
|
var toolOutputMaxBytesForStart = (input) => decodeOptionalNumberSetting(metadataSetting(input, toolOutputMaxBytesMetadataKey), toolOutputMaxBytesMetadataKey, (value) => value >= 0);
|
|
15981
|
-
var decodeCompactionEnabled = (value) => {
|
|
15982
|
-
if (value === undefined)
|
|
15983
|
-
return Effect74.succeed(undefined);
|
|
15984
|
-
if (value === null || value === false)
|
|
15985
|
-
return Effect74.succeed(null);
|
|
15986
|
-
if (value === true)
|
|
15987
|
-
return Effect74.succeed(true);
|
|
15988
|
-
return Effect74.fail(new ExecutionWorkflowFailed({ message: "compaction_enabled metadata value must be true or false" }));
|
|
15989
|
-
};
|
|
15990
|
-
var compactionForStart = Effect74.fn("ExecutionWorkflow.compactionForStart")(function* (input) {
|
|
15991
|
-
const executionEnabled = yield* decodeCompactionEnabled(executionMetadataSetting(input, compactionEnabledMetadataKey));
|
|
15992
|
-
if (executionEnabled === null)
|
|
15993
|
-
return null;
|
|
15994
|
-
const agentEnabled = yield* decodeCompactionEnabled(input.agent_snapshot?.metadata?.[compactionEnabledMetadataKey]);
|
|
15995
|
-
if (executionEnabled !== true && agentEnabled !== true)
|
|
15996
|
-
return;
|
|
15997
|
-
const contextWindow = yield* optionalNumberForStart(input, compactionContextWindowMetadataKey, (value) => value > 0);
|
|
15998
|
-
const reserveTokens = yield* optionalNumberForStart(input, compactionReserveTokensMetadataKey, (value) => value >= 0);
|
|
15999
|
-
const keepRecentTokens = yield* optionalNumberForStart(input, compactionKeepRecentTokensMetadataKey, (value) => value >= 0);
|
|
16000
|
-
return {
|
|
16001
|
-
...contextWindow === undefined ? {} : { contextWindow },
|
|
16002
|
-
...reserveTokens === undefined ? {} : { reserveTokens },
|
|
16003
|
-
...keepRecentTokens === undefined ? {} : { keepRecentTokens }
|
|
16004
|
-
};
|
|
16005
|
-
});
|
|
16006
16004
|
var decodeMemorySubject = (value) => typeof value === "string" ? Schema79.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(value).pipe(Effect74.mapError(() => new ExecutionWorkflowFailed({ message: `Invalid memory_subject_id metadata value: ${value}` }))) : Effect74.fail(new ExecutionWorkflowFailed({ message: "memory_subject_id metadata value must be a string" }));
|
|
16007
16005
|
var memorySubjectForStart = Effect74.fn("ExecutionWorkflow.memorySubjectForStart")(function* (input) {
|
|
16008
16006
|
const executionSubject = memorySubjectFromMetadata(input.metadata);
|
|
@@ -16074,7 +16072,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
16074
16072
|
const runEventSequence = yield* nextEventSequence4(eventLog, input.execution_id);
|
|
16075
16073
|
const memorySubjectId = yield* memorySubjectForStart(input);
|
|
16076
16074
|
const toolOutputMaxBytes = yield* toolOutputMaxBytesForStart(input);
|
|
16077
|
-
const compaction = yield* compactionForStart(input);
|
|
16078
16075
|
const skillDefinitionIds = input.agent_snapshot.skill_definition_ids ?? [];
|
|
16079
16076
|
const loopProgram = agentLoop.run({
|
|
16080
16077
|
executionId: input.execution_id,
|
|
@@ -16090,7 +16087,6 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
16090
16087
|
...pendingToolCall === undefined ? {} : { resumeToolCall: pendingToolCall },
|
|
16091
16088
|
...memorySubjectId === undefined ? {} : { memorySubjectId },
|
|
16092
16089
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
16093
|
-
...compaction === undefined ? {} : { compaction },
|
|
16094
16090
|
eventSequence: runEventSequence + 1,
|
|
16095
16091
|
startedAt: input.started_at,
|
|
16096
16092
|
completedAt: input.completed_at,
|
|
@@ -16098,6 +16094,7 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
16098
16094
|
dispatchChildRun: (child) => StartExecutionWorkflow.execute({
|
|
16099
16095
|
execution_id: child.executionId,
|
|
16100
16096
|
root_address_id: child.rootAddressId,
|
|
16097
|
+
session_id: child.sessionId,
|
|
16101
16098
|
input: child.input,
|
|
16102
16099
|
event_sequence: child.eventSequence,
|
|
16103
16100
|
started_at: child.startedAt,
|
|
@@ -17751,6 +17748,20 @@ var reasoningDeltaEvent = (input, part, deltaIndex) => {
|
|
|
17751
17748
|
created_at: input.startedAt + deltaIndex + 1
|
|
17752
17749
|
};
|
|
17753
17750
|
};
|
|
17751
|
+
var toolCallDeltaEvent = (input, part, toolCallName, sequence, deltaIndex) => ({
|
|
17752
|
+
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`),
|
|
17753
|
+
execution_id: input.executionId,
|
|
17754
|
+
type: "model.toolcall.delta",
|
|
17755
|
+
sequence,
|
|
17756
|
+
cursor: `${input.executionId}:model:${sequence}:toolcall-delta:${part.id}:${deltaIndex}`,
|
|
17757
|
+
data: {
|
|
17758
|
+
tool_call_id: part.id,
|
|
17759
|
+
...toolCallName === undefined ? {} : { tool_name: toolCallName },
|
|
17760
|
+
delta: part.delta,
|
|
17761
|
+
delta_index: deltaIndex
|
|
17762
|
+
},
|
|
17763
|
+
created_at: input.startedAt + (sequence - input.eventSequence)
|
|
17764
|
+
});
|
|
17754
17765
|
var outputCompletedEvent = (input, content, outputText, sequence, structuredOutput) => ({
|
|
17755
17766
|
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:output-completed`),
|
|
17756
17767
|
execution_id: input.executionId,
|
|
@@ -17814,6 +17825,35 @@ var restoreHistory = Effect90.fn("AgentLoop.restoreHistory")(function* (chats, i
|
|
|
17814
17825
|
const chat = yield* Chat3.fromExport(record2.exportData).pipe(Effect90.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17815
17826
|
return yield* Ref23.get(chat.history);
|
|
17816
17827
|
});
|
|
17828
|
+
var toolCallDecodeMaxRetriesConfig = Config4.int("RELAY_AGENT_TOOL_CALL_DECODE_MAX_RETRIES").pipe(Config4.withDefault(2));
|
|
17829
|
+
var isToolCallDecodeError = (error5) => AiError4.isAiError(error5) && error5.method === "streamText" && error5.reason._tag === "InvalidOutputError";
|
|
17830
|
+
var toolCallDecodeFeedback = (error5, availableToolNames) => {
|
|
17831
|
+
const tools = availableToolNames.length === 0 ? "(no tools are available)" : availableToolNames.join(", ");
|
|
17832
|
+
return Prompt13.fromMessages([
|
|
17833
|
+
Prompt13.makeMessage("user", {
|
|
17834
|
+
content: [
|
|
17835
|
+
Prompt13.makePart("text", {
|
|
17836
|
+
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.`
|
|
17837
|
+
})
|
|
17838
|
+
]
|
|
17839
|
+
})
|
|
17840
|
+
]);
|
|
17841
|
+
};
|
|
17842
|
+
var withToolCallDecodeResilience = (base2, availableToolNames, maxRetries) => ({
|
|
17843
|
+
...base2,
|
|
17844
|
+
streamText: (options) => {
|
|
17845
|
+
const attempt = (prompt, retriesLeft) => Stream12.suspend(() => {
|
|
17846
|
+
let emitted = false;
|
|
17847
|
+
return base2.streamText({ ...options, prompt }).pipe(Stream12.tap(() => Effect90.sync(() => void (emitted = true))), Stream12.catchCause((cause) => {
|
|
17848
|
+
if (Cause4.hasInterrupts(cause))
|
|
17849
|
+
return Stream12.failCause(cause);
|
|
17850
|
+
const error5 = Cause4.squash(cause);
|
|
17851
|
+
return !emitted && retriesLeft > 0 && isToolCallDecodeError(error5) ? attempt(Prompt13.concat(Prompt13.make(prompt), toolCallDecodeFeedback(error5, availableToolNames)), retriesLeft - 1) : Stream12.failCause(cause);
|
|
17852
|
+
}));
|
|
17853
|
+
});
|
|
17854
|
+
return attempt(options.prompt, maxRetries);
|
|
17855
|
+
}
|
|
17856
|
+
});
|
|
17817
17857
|
var saveContextEpoch = Effect90.fn("AgentLoop.saveContextEpoch")(function* (epochs, input, epoch) {
|
|
17818
17858
|
yield* epochs.save({
|
|
17819
17859
|
executionId: input.executionId,
|
|
@@ -17894,20 +17934,11 @@ var decodeOptionalNumber = (value, key4, valid) => {
|
|
|
17894
17934
|
return Effect90.fail(new AgentLoopError2({ message: `${key4} metadata value is invalid` }));
|
|
17895
17935
|
};
|
|
17896
17936
|
var effectiveToolOutputMaxBytes = (input) => input.toolOutputMaxBytes !== undefined ? Effect90.succeed(input.toolOutputMaxBytes ?? undefined) : decodeOptionalNumber(metadataValue(input.agent.metadata, "tool_output_max_bytes"), "tool_output_max_bytes", (value) => value >= 0);
|
|
17897
|
-
var
|
|
17898
|
-
|
|
17899
|
-
|
|
17900
|
-
|
|
17901
|
-
|
|
17902
|
-
const reserveTokens = yield* decodeOptionalNumber(metadataValue(input.agent.metadata, "compaction_reserve_tokens"), "compaction_reserve_tokens", (value) => value >= 0);
|
|
17903
|
-
const keepRecentTokens = yield* decodeOptionalNumber(metadataValue(input.agent.metadata, "compaction_keep_recent_tokens"), "compaction_keep_recent_tokens", (value) => value >= 0);
|
|
17904
|
-
return {
|
|
17905
|
-
...contextWindow === undefined ? {} : { contextWindow },
|
|
17906
|
-
...reserveTokens === undefined ? {} : { reserveTokens },
|
|
17907
|
-
...keepRecentTokens === undefined ? {} : { keepRecentTokens }
|
|
17908
|
-
};
|
|
17909
|
-
});
|
|
17910
|
-
var effectiveCompactionOptions = (input) => input.compaction !== undefined ? Effect90.succeed(input.compaction ?? undefined) : compactionOptionsFromAgentMetadata(input);
|
|
17937
|
+
var compactionOptions = (agent) => agent.compaction_policy === undefined ? undefined : {
|
|
17938
|
+
contextWindow: agent.compaction_policy.context_window,
|
|
17939
|
+
reserveTokens: agent.compaction_policy.reserve_tokens,
|
|
17940
|
+
keepRecentTokens: agent.compaction_policy.keep_recent_tokens
|
|
17941
|
+
};
|
|
17911
17942
|
var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
17912
17943
|
const eventLog = yield* Service30;
|
|
17913
17944
|
const languageModels = yield* Service40;
|
|
@@ -17966,9 +17997,11 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
17966
17997
|
const registered = [...availableRegisteredTools(input.agent, yield* tools.registeredTools), ...allCoreTools];
|
|
17967
17998
|
const definitions2 = registered.map((tool2) => tool2.definition);
|
|
17968
17999
|
yield* validateToolInputSchemaDigests(input, definitions2);
|
|
18000
|
+
const toolCallDecodeMaxRetries = yield* toolCallDecodeMaxRetriesConfig.pipe(Effect90.mapError((error5) => loopError(error5, input.eventSequence + 1)));
|
|
17969
18001
|
yield* appendEvent(eventLog, inputPreparedEvent(input, definitions2), input.eventSequence + 1);
|
|
17970
18002
|
const toolOutputMaxBytes = yield* effectiveToolOutputMaxBytes(input);
|
|
17971
|
-
const
|
|
18003
|
+
const compactionPolicy = input.agent.compaction_policy;
|
|
18004
|
+
const activeCompactionOptions = compactionOptions(input.agent);
|
|
17972
18005
|
const runTokenizer = yield* Effect90.serviceOption(Tokenizer4.Tokenizer);
|
|
17973
18006
|
const activeTokenizer = Option27.isSome(runTokenizer) ? runTokenizer : tokenizer;
|
|
17974
18007
|
const allocator = yield* make14(input.eventSequence + 1);
|
|
@@ -18041,25 +18074,25 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18041
18074
|
next_event_sequence: input.eventSequence + 1
|
|
18042
18075
|
}));
|
|
18043
18076
|
}
|
|
18044
|
-
if (
|
|
18077
|
+
if (activeCompactionOptions !== undefined && input.sessionId === undefined) {
|
|
18045
18078
|
return yield* Effect90.fail(new AgentLoopError2({
|
|
18046
18079
|
message: "Execution compaction requires session_id",
|
|
18047
18080
|
next_event_sequence: input.eventSequence + 1
|
|
18048
18081
|
}));
|
|
18049
18082
|
}
|
|
18050
|
-
if (
|
|
18083
|
+
if (activeCompactionOptions !== undefined && Option27.isNone(sessionRepository)) {
|
|
18051
18084
|
return yield* Effect90.fail(new AgentLoopError2({
|
|
18052
18085
|
message: "Execution compaction requires SessionRepository in context",
|
|
18053
18086
|
next_event_sequence: input.eventSequence + 1
|
|
18054
18087
|
}));
|
|
18055
18088
|
}
|
|
18056
|
-
if (
|
|
18089
|
+
if (activeCompactionOptions !== undefined && Option27.isNone(compactionRepository)) {
|
|
18057
18090
|
return yield* Effect90.fail(new AgentLoopError2({
|
|
18058
18091
|
message: "Execution compaction requires CompactionRepository in context",
|
|
18059
18092
|
next_event_sequence: input.eventSequence + 1
|
|
18060
18093
|
}));
|
|
18061
18094
|
}
|
|
18062
|
-
const batonCompaction =
|
|
18095
|
+
const batonCompaction = compactionPolicy === undefined ? undefined : { contextWindow: compactionPolicy.context_window };
|
|
18063
18096
|
const batonOptions = {
|
|
18064
18097
|
...options,
|
|
18065
18098
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
@@ -18078,12 +18111,12 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18078
18111
|
...allCoreTools.length === 0 ? {} : { extraTools: allCoreTools }
|
|
18079
18112
|
});
|
|
18080
18113
|
const activeBlobStore = toolOutputMaxBytes === undefined || Option27.isNone(blobStore) ? undefined : blobStore.value;
|
|
18081
|
-
const activeCompactionRepository =
|
|
18114
|
+
const activeCompactionRepository = activeCompactionOptions === undefined || Option27.isNone(compactionRepository) ? undefined : compactionRepository.value;
|
|
18082
18115
|
const toolOutputStore = toolOutputMaxBytes === undefined ? undefined : exports_tool_output.ToolOutputStore.of(make13(activeBlobStore));
|
|
18083
|
-
const compactionService =
|
|
18116
|
+
const compactionService = activeCompactionOptions === undefined ? undefined : exports_compaction.Compaction.of(make11({
|
|
18084
18117
|
executionId: input.executionId,
|
|
18085
18118
|
repository: activeCompactionRepository,
|
|
18086
|
-
options:
|
|
18119
|
+
options: activeCompactionOptions
|
|
18087
18120
|
}));
|
|
18088
18121
|
if (memory !== undefined && Option27.isNone(durableMemory)) {
|
|
18089
18122
|
return yield* Effect90.fail(new AgentLoopError2({
|
|
@@ -18091,6 +18124,16 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18091
18124
|
next_event_sequence: input.eventSequence + 1
|
|
18092
18125
|
}));
|
|
18093
18126
|
}
|
|
18127
|
+
const tokenBudget = input.agent.token_budget;
|
|
18128
|
+
const enforceBudget = (state) => tokenBudget === undefined || state.tokensUsed < tokenBudget ? Effect90.void : Effect90.gen(function* () {
|
|
18129
|
+
const budgetSequence = yield* allocator.allocate(1);
|
|
18130
|
+
yield* appendEvent(eventLog, budgetExceededEvent(input, state.tokensUsed, tokenBudget, budgetSequence), budgetSequence + 1);
|
|
18131
|
+
return yield* Effect90.fail(new AgentLoopBudgetExceeded2({
|
|
18132
|
+
tokens_used: state.tokensUsed,
|
|
18133
|
+
token_budget: tokenBudget,
|
|
18134
|
+
next_event_sequence: budgetSequence + 1
|
|
18135
|
+
}));
|
|
18136
|
+
});
|
|
18094
18137
|
const foldEvent = (state, event) => Effect90.gen(function* () {
|
|
18095
18138
|
switch (event._tag) {
|
|
18096
18139
|
case "ModelPart": {
|
|
@@ -18107,6 +18150,18 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18107
18150
|
yield* appendEvent(eventLog, reasoningDeltaEvent(input, part, deltaIndex), sequence + 1);
|
|
18108
18151
|
return state;
|
|
18109
18152
|
}
|
|
18153
|
+
if (part.type === "tool-params-start") {
|
|
18154
|
+
return { ...state, toolCallNames: { ...state.toolCallNames, [part.id]: part.name } };
|
|
18155
|
+
}
|
|
18156
|
+
if (part.type === "tool-params-delta") {
|
|
18157
|
+
const sequence = yield* allocator.allocate(1);
|
|
18158
|
+
const deltaIndex = state.toolCallDeltaIndexes[part.id] ?? 0;
|
|
18159
|
+
yield* appendEvent(eventLog, toolCallDeltaEvent(input, part, state.toolCallNames[part.id], sequence, deltaIndex), sequence + 1);
|
|
18160
|
+
return {
|
|
18161
|
+
...state,
|
|
18162
|
+
toolCallDeltaIndexes: { ...state.toolCallDeltaIndexes, [part.id]: deltaIndex + 1 }
|
|
18163
|
+
};
|
|
18164
|
+
}
|
|
18110
18165
|
if (part.type === "finish") {
|
|
18111
18166
|
const finish = part;
|
|
18112
18167
|
const sequence = yield* allocator.allocate(1);
|
|
@@ -18126,19 +18181,13 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18126
18181
|
return state;
|
|
18127
18182
|
}
|
|
18128
18183
|
case "TurnStarted": {
|
|
18129
|
-
if (
|
|
18130
|
-
|
|
18131
|
-
yield* appendEvent(eventLog, budgetExceededEvent(input, state.tokensUsed, input.agent.token_budget, budgetSequence), budgetSequence + 1);
|
|
18132
|
-
return yield* Effect90.fail(new AgentLoopBudgetExceeded2({
|
|
18133
|
-
tokens_used: state.tokensUsed,
|
|
18134
|
-
token_budget: input.agent.token_budget,
|
|
18135
|
-
next_event_sequence: budgetSequence + 1
|
|
18136
|
-
}));
|
|
18137
|
-
}
|
|
18184
|
+
if (event.turn > 0)
|
|
18185
|
+
yield* enforceBudget(state);
|
|
18138
18186
|
return state;
|
|
18139
18187
|
}
|
|
18140
18188
|
case "TurnCompleted": {
|
|
18141
18189
|
yield* persistTranscript(chats, input, event.transcript);
|
|
18190
|
+
yield* enforceBudget(state);
|
|
18142
18191
|
return { ...state, transcript: event.transcript, turn: event.turn };
|
|
18143
18192
|
}
|
|
18144
18193
|
case "Completed": {
|
|
@@ -18149,9 +18198,16 @@ var layer59 = Layer79.effect(Service54, Effect90.gen(function* () {
|
|
|
18149
18198
|
}
|
|
18150
18199
|
});
|
|
18151
18200
|
const runFold = Effect90.gen(function* () {
|
|
18152
|
-
const base2 = yield* LanguageModel7.LanguageModel;
|
|
18201
|
+
const base2 = withToolCallDecodeResilience(yield* LanguageModel7.LanguageModel, definitions2.map((definition) => definition.name), toolCallDecodeMaxRetries);
|
|
18153
18202
|
const sessionStore = input.sessionId !== undefined && Option27.isSome(sessionRepository) ? yield* make8(input.sessionId, input.sessionEntryScope ?? input.executionId).pipe(Effect90.provideService(exports_session_repository.Service, sessionRepository.value)) : undefined;
|
|
18154
|
-
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream12.runFoldEffect(() => ({
|
|
18203
|
+
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream12.runFoldEffect(() => ({
|
|
18204
|
+
text: "",
|
|
18205
|
+
transcript: undefined,
|
|
18206
|
+
turn: undefined,
|
|
18207
|
+
tokensUsed: seededTokens,
|
|
18208
|
+
toolCallNames: {},
|
|
18209
|
+
toolCallDeltaIndexes: {}
|
|
18210
|
+
}), foldEvent), Effect90.provideService(LanguageModel7.LanguageModel, base2), Effect90.provideService(exports_model_resilience.ModelResilience, policy), Effect90.provide(executorLayer), Effect90.provide(handlerLayer), Effect90.provide(layer54), Effect90.provide(exports_model_middleware.identityLayer), Effect90.provide(instructionsLayer), Effect90.provide(permissionsLayer), Effect90.provide(steeringLayer));
|
|
18155
18211
|
const withToolOutput = toolOutputStore === undefined ? folded : folded.pipe(Effect90.provideService(exports_tool_output.ToolOutputStore, toolOutputStore));
|
|
18156
18212
|
const withCompaction = compactionService === undefined ? withToolOutput : withToolOutput.pipe(Effect90.provideService(exports_compaction.Compaction, compactionService));
|
|
18157
18213
|
const withSession = sessionStore === undefined ? withCompaction : withCompaction.pipe(Effect90.provideService(exports_session.SessionStore, sessionStore));
|
|
@@ -18198,6 +18254,7 @@ var overrideOf = (child) => {
|
|
|
18198
18254
|
return {
|
|
18199
18255
|
...override?.instructions === undefined ? {} : { instructions: override.instructions },
|
|
18200
18256
|
...override?.model === undefined ? {} : { model: override.model },
|
|
18257
|
+
...override?.compaction_policy === undefined ? {} : { compactionPolicy: override.compaction_policy },
|
|
18201
18258
|
...override?.tool_names === undefined ? {} : { toolNames: override.tool_names },
|
|
18202
18259
|
...override?.permissions === undefined ? {} : { permissions: override.permissions },
|
|
18203
18260
|
...override?.workspace_policy === undefined ? {} : { workspacePolicy: override.workspace_policy },
|
|
@@ -18529,7 +18586,6 @@ var layer65 = Layer84.effect(Service64, Effect95.gen(function* () {
|
|
|
18529
18586
|
entity_kind: input.kind,
|
|
18530
18587
|
entity_key: input.key,
|
|
18531
18588
|
entity_generation: instance.generation,
|
|
18532
|
-
compaction_enabled: input.metadata?.compaction_enabled ?? kind.metadata?.compaction_enabled ?? true,
|
|
18533
18589
|
...kind.state_enabled === undefined ? {} : { state_enabled: kind.state_enabled },
|
|
18534
18590
|
...kind.continue_as_new_after_turns === undefined ? {} : { continue_as_new_after_turns: kind.continue_as_new_after_turns }
|
|
18535
18591
|
};
|
|
@@ -19253,7 +19309,7 @@ var check = Effect99.fn("RunnerRuntime.check.call")(function* () {
|
|
|
19253
19309
|
return yield* service.check();
|
|
19254
19310
|
});
|
|
19255
19311
|
// ../runtime/src/workflow/definition-runtime.ts
|
|
19256
|
-
import { Cause as
|
|
19312
|
+
import { Cause as Cause5, Clock as Clock17, Context as Context82, Effect as Effect100, Exit as Exit3, Layer as Layer89, Option as Option30, Schema as Schema102 } from "effect";
|
|
19257
19313
|
|
|
19258
19314
|
class UnsupportedOperation extends Schema102.TaggedErrorClass()("UnsupportedWorkflowOperation", { operation_id: exports_ids_schema.WorkflowOperationId, kind: Schema102.String }) {
|
|
19259
19315
|
}
|
|
@@ -19575,7 +19631,7 @@ var run5 = Effect100.fn("WorkflowDefinitionRuntime.run")(function* (executionId)
|
|
|
19575
19631
|
});
|
|
19576
19632
|
const result = yield* Effect100.exit(execute(revision.definition.entry_operation_id));
|
|
19577
19633
|
if (Exit3.isFailure(result)) {
|
|
19578
|
-
const failure3 =
|
|
19634
|
+
const failure3 = Cause5.findErrorOption(result.cause);
|
|
19579
19635
|
if (Option30.isSome(failure3) && failure3.value instanceof WorkflowJoining)
|
|
19580
19636
|
return yield* result;
|
|
19581
19637
|
const currentRun = yield* repository.inspect(executionId);
|