@relayfx/sdk 0.0.37 → 0.0.39
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 +337 -285
- package/dist/types/relay/client.d.ts +118 -5
- package/dist/types/relay/operation.d.ts +8 -8
- package/dist/types/runtime/address/address-resolution-service.d.ts +4 -4
- package/dist/types/runtime/agent/agent-loop-service.d.ts +2 -21
- package/dist/types/runtime/agent/agent-registry-service.d.ts +4 -4
- package/dist/types/runtime/child/spawn-child-run-tool.d.ts +2 -2
- package/dist/types/runtime/cluster/execution-entity.d.ts +6 -6
- package/dist/types/runtime/execution/execution-service.d.ts +1 -1
- package/dist/types/runtime/tool/tool-runtime-service.d.ts +36 -9
- package/dist/types/runtime/workflow/execution-workflow.d.ts +4 -4
- package/dist/types/schema/agent-schema.d.ts +14 -14
- package/dist/types/schema/execution-schema.d.ts +2 -2
- package/dist/types/schema/ids-schema.d.ts +3 -3
- package/dist/types/store-sql/agent/agent-definition-repository.d.ts +8 -8
- package/dist/types/store-sql/execution/execution-repository.d.ts +2 -2
- package/dist/types/store-sql/schema/relay-schema.d.ts +6 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,8 +39,10 @@ __export(exports_client, {
|
|
|
39
39
|
startExecutionByAgentDefinition: () => startExecutionByAgentDefinition,
|
|
40
40
|
startExecutionByAddress: () => startExecutionByAddress,
|
|
41
41
|
startExecution: () => startExecution,
|
|
42
|
+
start: () => start2,
|
|
42
43
|
spawnChildRun: () => spawnChildRun2,
|
|
43
44
|
send: () => send3,
|
|
45
|
+
run: () => run5,
|
|
44
46
|
routeExecution: () => routeExecution,
|
|
45
47
|
resolveToolApproval: () => resolveToolApproval,
|
|
46
48
|
resolvePermission: () => resolvePermission,
|
|
@@ -70,6 +72,7 @@ __export(exports_client, {
|
|
|
70
72
|
claimEnvelopeReady: () => claimEnvelopeReady,
|
|
71
73
|
cancelSchedule: () => cancelSchedule,
|
|
72
74
|
cancelExecution: () => cancelExecution2,
|
|
75
|
+
agent: () => agent,
|
|
73
76
|
ackEnvelopeReady: () => ackEnvelopeReady,
|
|
74
77
|
Service: () => Service50,
|
|
75
78
|
ClientError: () => ClientError
|
|
@@ -128,7 +131,7 @@ __export(exports_ids_schema, {
|
|
|
128
131
|
EnvelopeReadyId: () => EnvelopeReadyId,
|
|
129
132
|
EnvelopeId: () => EnvelopeId,
|
|
130
133
|
ChildExecutionId: () => ChildExecutionId,
|
|
131
|
-
|
|
134
|
+
AgentId: () => AgentId,
|
|
132
135
|
AddressId: () => AddressId,
|
|
133
136
|
AddressBookEntryId: () => AddressBookEntryId
|
|
134
137
|
});
|
|
@@ -143,7 +146,7 @@ var AddressId = id("Relay.AddressId");
|
|
|
143
146
|
var TenantId = id("Relay.TenantId");
|
|
144
147
|
var SystemTenantId = TenantId.make("system");
|
|
145
148
|
var AddressBookEntryId = id("Relay.AddressBookEntryId");
|
|
146
|
-
var
|
|
149
|
+
var AgentId = id("Relay.AgentId");
|
|
147
150
|
var SkillDefinitionId = id("Relay.SkillDefinitionId");
|
|
148
151
|
var EnvelopeId = id("Relay.EnvelopeId");
|
|
149
152
|
var EnvelopeReadyId = id("Relay.EnvelopeReadyId");
|
|
@@ -409,7 +412,7 @@ var define = (input) => ({
|
|
|
409
412
|
}
|
|
410
413
|
});
|
|
411
414
|
var DefinitionRecord = Schema5.Struct({
|
|
412
|
-
id:
|
|
415
|
+
id: AgentId,
|
|
413
416
|
current_revision: DefinitionRevision,
|
|
414
417
|
definition: Definition2,
|
|
415
418
|
tool_input_schema_digests: Schema5.optionalKey(ToolInputSchemaDigests),
|
|
@@ -417,14 +420,14 @@ var DefinitionRecord = Schema5.Struct({
|
|
|
417
420
|
updated_at: TimestampMillis
|
|
418
421
|
}).annotate({ identifier: "Relay.Agent.DefinitionRecord" });
|
|
419
422
|
var DefinitionRevisionRecord = Schema5.Struct({
|
|
420
|
-
id:
|
|
423
|
+
id: AgentId,
|
|
421
424
|
revision: DefinitionRevision,
|
|
422
425
|
definition: Definition2,
|
|
423
426
|
tool_input_schema_digests: Schema5.optionalKey(ToolInputSchemaDigests),
|
|
424
427
|
created_at: TimestampMillis
|
|
425
428
|
}).annotate({ identifier: "Relay.Agent.DefinitionRevisionRecord" });
|
|
426
429
|
var RegisterDefinitionPayload = Schema5.Struct({
|
|
427
|
-
id:
|
|
430
|
+
id: AgentId,
|
|
428
431
|
definition: Definition2
|
|
429
432
|
}).annotate({ identifier: "Relay.Agent.RegisterDefinitionPayload" });
|
|
430
433
|
var DefinitionRegistered = Schema5.Struct({
|
|
@@ -576,7 +579,7 @@ var Execution = Schema8.Struct({
|
|
|
576
579
|
root_address_id: AddressId,
|
|
577
580
|
session_id: Schema8.optionalKey(SessionId),
|
|
578
581
|
status: ExecutionStatus,
|
|
579
|
-
agent_definition_id: Schema8.optionalKey(
|
|
582
|
+
agent_definition_id: Schema8.optionalKey(AgentId),
|
|
580
583
|
agent_definition_revision: Schema8.optionalKey(DefinitionRevision),
|
|
581
584
|
agent_definition_snapshot: Schema8.optionalKey(Definition2),
|
|
582
585
|
agent_definition_tool_input_schema_digests: Schema8.optionalKey(ToolInputSchemaDigests),
|
|
@@ -1282,7 +1285,7 @@ var rowDigests = (json) => nonEmptyDigests(decodeJson(json));
|
|
|
1282
1285
|
var toRecord2 = (row) => {
|
|
1283
1286
|
const toolInputSchemaDigests = rowDigests(row.tool_input_schema_digests_json);
|
|
1284
1287
|
return {
|
|
1285
|
-
id: exports_ids_schema.
|
|
1288
|
+
id: exports_ids_schema.AgentId.make(row.id),
|
|
1286
1289
|
currentRevision: row.current_revision,
|
|
1287
1290
|
definition: cloneDefinition(decodeJson(row.definition_json)),
|
|
1288
1291
|
...toolInputSchemaDigests === undefined ? {} : { toolInputSchemaDigests },
|
|
@@ -1293,7 +1296,7 @@ var toRecord2 = (row) => {
|
|
|
1293
1296
|
var toRevisionRecord = (row) => {
|
|
1294
1297
|
const toolInputSchemaDigests = rowDigests(row.tool_input_schema_digests_json);
|
|
1295
1298
|
return {
|
|
1296
|
-
id: exports_ids_schema.
|
|
1299
|
+
id: exports_ids_schema.AgentId.make(row.agent_definition_id),
|
|
1297
1300
|
revision: row.revision,
|
|
1298
1301
|
definition: cloneDefinition(decodeJson(row.definition_json)),
|
|
1299
1302
|
...toolInputSchemaDigests === undefined ? {} : { toolInputSchemaDigests },
|
|
@@ -3145,7 +3148,7 @@ var metadata4 = (input) => input ?? {};
|
|
|
3145
3148
|
var nonEmptyDigests2 = (digests) => digests === undefined || Object.keys(digests).length === 0 ? undefined : structuredClone(digests);
|
|
3146
3149
|
var hasCompleteAgentDefinitionPin = (input) => {
|
|
3147
3150
|
const present = [
|
|
3148
|
-
input.
|
|
3151
|
+
input.agentId !== undefined,
|
|
3149
3152
|
input.agentDefinitionRevision !== undefined,
|
|
3150
3153
|
input.agentDefinitionSnapshot !== undefined
|
|
3151
3154
|
];
|
|
@@ -3181,7 +3184,7 @@ var toRecord5 = (row) => {
|
|
|
3181
3184
|
rootAddressId: exports_ids_schema.AddressId.make(row.root_address_id),
|
|
3182
3185
|
...row.session_id === null || row.session_id === undefined ? {} : { sessionId: exports_ids_schema.SessionId.make(row.session_id) },
|
|
3183
3186
|
status: row.status,
|
|
3184
|
-
...row.agent_definition_id === null || row.agent_definition_id === undefined ? {} : {
|
|
3187
|
+
...row.agent_definition_id === null || row.agent_definition_id === undefined ? {} : { agentId: exports_ids_schema.AgentId.make(row.agent_definition_id) },
|
|
3185
3188
|
...row.agent_definition_revision === null || row.agent_definition_revision === undefined ? {} : { agentDefinitionRevision: row.agent_definition_revision },
|
|
3186
3189
|
...snapshotJson === null || snapshotJson === undefined ? {} : { agentDefinitionSnapshot: cloneAgentDefinition(decodeJson(snapshotJson)) },
|
|
3187
3190
|
...digests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: digests },
|
|
@@ -3231,7 +3234,7 @@ var layer11 = Layer12.effect(Service12, Effect12.gen(function* () {
|
|
|
3231
3234
|
${input.rootAddressId},
|
|
3232
3235
|
${input.sessionId ?? null},
|
|
3233
3236
|
${input.status},
|
|
3234
|
-
${input.
|
|
3237
|
+
${input.agentId ?? null},
|
|
3235
3238
|
${input.agentDefinitionRevision ?? null},
|
|
3236
3239
|
${input.agentDefinitionSnapshot === undefined ? null : encodeJson(input.agentDefinitionSnapshot)},
|
|
3237
3240
|
${encodeJson(input.agentDefinitionToolInputSchemaDigests ?? {})},
|
|
@@ -3337,7 +3340,7 @@ var memoryLayer9 = Layer12.sync(Service12, () => {
|
|
|
3337
3340
|
rootAddressId: input.rootAddressId,
|
|
3338
3341
|
...input.sessionId === undefined ? {} : { sessionId: input.sessionId },
|
|
3339
3342
|
status: input.status,
|
|
3340
|
-
...input.
|
|
3343
|
+
...input.agentId === undefined ? {} : { agentId: input.agentId },
|
|
3341
3344
|
...input.agentDefinitionRevision === undefined ? {} : { agentDefinitionRevision: input.agentDefinitionRevision },
|
|
3342
3345
|
...input.agentDefinitionSnapshot === undefined ? {} : { agentDefinitionSnapshot: cloneAgentDefinition(input.agentDefinitionSnapshot) },
|
|
3343
3346
|
...input.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: structuredClone(input.agentDefinitionToolInputSchemaDigests) },
|
|
@@ -4065,7 +4068,7 @@ var relayAgentDefinitions = pgTable("relay_agent_definitions", {
|
|
|
4065
4068
|
]);
|
|
4066
4069
|
var relayAgentDefinitionRevisions = pgTable("relay_agent_definition_revisions", {
|
|
4067
4070
|
tenantId: tenantId(),
|
|
4068
|
-
|
|
4071
|
+
agentId: text2("agent_definition_id").$type().notNull(),
|
|
4069
4072
|
revision: integer("revision").$type().notNull(),
|
|
4070
4073
|
name: text2("name").notNull(),
|
|
4071
4074
|
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
@@ -4073,10 +4076,10 @@ var relayAgentDefinitionRevisions = pgTable("relay_agent_definition_revisions",
|
|
|
4073
4076
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
4074
4077
|
}, (table) => [
|
|
4075
4078
|
primaryKey({
|
|
4076
|
-
columns: [table.tenantId, table.
|
|
4079
|
+
columns: [table.tenantId, table.agentId, table.revision],
|
|
4077
4080
|
name: "pk_relay_agent_definition_revisions"
|
|
4078
4081
|
}),
|
|
4079
|
-
index("idx_relay_agent_definition_revisions_definition").on(table.tenantId, table.
|
|
4082
|
+
index("idx_relay_agent_definition_revisions_definition").on(table.tenantId, table.agentId, table.revision)
|
|
4080
4083
|
]);
|
|
4081
4084
|
var relaySkillDefinitions = pgTable("relay_skill_definitions", {
|
|
4082
4085
|
tenantId: tenantId(),
|
|
@@ -4235,7 +4238,7 @@ var relayExecutions = pgTable("relay_executions", {
|
|
|
4235
4238
|
rootAddressId: text2("root_address_id").$type().notNull(),
|
|
4236
4239
|
sessionId: text2("session_id").$type(),
|
|
4237
4240
|
status: text2("status").$type().notNull(),
|
|
4238
|
-
|
|
4241
|
+
agentId: text2("agent_definition_id").$type(),
|
|
4239
4242
|
agentDefinitionRevision: integer("agent_definition_revision").$type(),
|
|
4240
4243
|
agentDefinitionSnapshotJson: jsonb("agent_definition_snapshot_json").$type(),
|
|
4241
4244
|
agentDefinitionToolInputSchemaDigestsJson: jsonb("agent_definition_tool_input_schema_digests_json").$type().notNull().default({}),
|
|
@@ -7218,15 +7221,16 @@ var digestDefinitions = Effect25.fn("ToolInputSchemaDigest.digestDefinitions")(f
|
|
|
7218
7221
|
// ../runtime/src/tool/tool-runtime-service.ts
|
|
7219
7222
|
var exports_tool_runtime_service = {};
|
|
7220
7223
|
__export(exports_tool_runtime_service, {
|
|
7224
|
+
toolFromRegistered: () => toolFromRegistered,
|
|
7225
|
+
tool: () => tool,
|
|
7221
7226
|
testLayer: () => testLayer23,
|
|
7222
7227
|
run: () => run,
|
|
7223
7228
|
registeredTools: () => registeredTools,
|
|
7224
7229
|
register: () => register2,
|
|
7225
7230
|
memoryLayer: () => memoryLayer23,
|
|
7226
7231
|
layer: () => layer23,
|
|
7232
|
+
dynamicTool: () => dynamicTool,
|
|
7227
7233
|
definitions: () => definitions,
|
|
7228
|
-
definitionFromAiTool: () => definitionFromAiTool,
|
|
7229
|
-
aiToolFromRegistered: () => aiToolFromRegistered,
|
|
7230
7234
|
ToolRuntimeError: () => ToolRuntimeError,
|
|
7231
7235
|
ToolPermissionDenied: () => ToolPermissionDenied,
|
|
7232
7236
|
ToolNotRegistered: () => ToolNotRegistered,
|
|
@@ -7237,7 +7241,7 @@ __export(exports_tool_runtime_service, {
|
|
|
7237
7241
|
Service: () => Service26
|
|
7238
7242
|
});
|
|
7239
7243
|
import * as Ai from "effect/unstable/ai";
|
|
7240
|
-
import { Chunk, Context as Context26, Effect as Effect28, HashSet as HashSet3, Layer as Layer26, Option as Option6, Ref as Ref6, Schema as Schema35
|
|
7244
|
+
import { Chunk, Context as Context26, Effect as Effect28, HashSet as HashSet3, Layer as Layer26, Option as Option6, Ref as Ref6, Schema as Schema35 } from "effect";
|
|
7241
7245
|
|
|
7242
7246
|
// ../runtime/src/execution/event-log-service.ts
|
|
7243
7247
|
var exports_event_log_service = {};
|
|
@@ -7789,9 +7793,9 @@ var ensureAllowed = (tool, input) => {
|
|
|
7789
7793
|
return Effect28.fail(new ToolPermissionDenied({ tool_name: input.call.name, permission_name: missing }));
|
|
7790
7794
|
};
|
|
7791
7795
|
var validateInput = (tool, input) => {
|
|
7792
|
-
if (tool.
|
|
7796
|
+
if (tool.validateInput === undefined)
|
|
7793
7797
|
return Effect28.void;
|
|
7794
|
-
return
|
|
7798
|
+
return tool.validateInput(input.call.input);
|
|
7795
7799
|
};
|
|
7796
7800
|
var mapRepositoryError4 = (error) => new ToolRuntimeError({ message: error._tag });
|
|
7797
7801
|
var mapEventLogError2 = (error) => new ToolRuntimeError({ message: error._tag });
|
|
@@ -7848,58 +7852,25 @@ var upsertTool = (registry, tool) => {
|
|
|
7848
7852
|
var registerTool = (tools, tool) => Ref6.update(tools, (registry) => upsertTool(registry, tool));
|
|
7849
7853
|
var jsonValue = (value) => Schema35.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
7850
7854
|
var fallbackParametersSchema = Schema35.Struct({});
|
|
7851
|
-
var
|
|
7855
|
+
var parametersForInputSchema = (inputSchema) => {
|
|
7852
7856
|
const schema = exports_tool_schema.parametersSchema(inputSchema);
|
|
7853
7857
|
return schema.ast._tag === "Unknown" ? { parameters: fallbackParametersSchema, jsonSchema: inputSchema } : { parameters: schema };
|
|
7854
7858
|
};
|
|
7855
7859
|
var attachJsonSchema = (tool, jsonSchema) => jsonSchema === undefined ? tool : Object.assign(tool, { jsonSchema });
|
|
7856
|
-
var
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
const parameters = parametersForRegisteredTool(tool.definition.input_schema);
|
|
7860
|
-
return attachJsonSchema(Ai.Tool.dynamic(tool.definition.name, {
|
|
7861
|
-
description: tool.definition.description,
|
|
7862
|
-
parameters: parameters.parameters,
|
|
7863
|
-
success: Schema35.Unknown,
|
|
7864
|
-
needsApproval: tool.definition.needs_approval
|
|
7865
|
-
}), parameters.jsonSchema);
|
|
7866
|
-
};
|
|
7867
|
-
var handlerForTool = (tool, input) => (params, context) => {
|
|
7868
|
-
const callInfo = ToolCallInfo.of({
|
|
7869
|
-
executionId: input.executionId,
|
|
7870
|
-
call: input.call,
|
|
7871
|
-
permissions: input.permissions,
|
|
7872
|
-
eventSequence: input.eventSequence,
|
|
7873
|
-
createdAt: input.createdAt
|
|
7874
|
-
});
|
|
7875
|
-
return (tool.handler === undefined ? tool.run(jsonValue(params), {
|
|
7860
|
+
var toolFromRegistered = (tool) => tool.tool;
|
|
7861
|
+
var finalToolResult = (tool, input) => Effect28.gen(function* () {
|
|
7862
|
+
const context = {
|
|
7876
7863
|
executionId: input.executionId,
|
|
7877
7864
|
call: input.call,
|
|
7878
7865
|
permissions: input.permissions,
|
|
7879
7866
|
eventSequence: input.eventSequence,
|
|
7880
7867
|
createdAt: input.createdAt
|
|
7881
|
-
}
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
const aiTool = aiToolFromRegistered(tool);
|
|
7885
|
-
const toolkit = Ai.Toolkit.make(aiTool);
|
|
7886
|
-
const handlers = { [tool.definition.name]: handlerForTool(tool, input) };
|
|
7887
|
-
return toolkit.pipe(Effect28.provide(toolkit.toLayer(handlers)), Effect28.map((withHandler) => withHandler));
|
|
7888
|
-
};
|
|
7889
|
-
var finalToolResult = (tool, input) => Effect28.gen(function* () {
|
|
7890
|
-
const toolkit = yield* toolkitForCall(tool, input);
|
|
7891
|
-
const stream2 = yield* toolkit.handle(tool.definition.name, input.call.input).pipe(Effect28.map((value) => value), Effect28.mapError((error) => preserveToolError(input.call.name, error)));
|
|
7892
|
-
const result = yield* stream2.pipe(Stream4.filter((item) => item.preliminary === false), Stream4.run(Sink.last()), Effect28.flatMap(Option6.match({
|
|
7893
|
-
onNone: () => Effect28.fail(new ToolExecutionFailed({
|
|
7894
|
-
tool_name: input.call.name,
|
|
7895
|
-
message: "Tool handler did not produce a final result"
|
|
7896
|
-
})),
|
|
7897
|
-
onSome: Effect28.succeed
|
|
7898
|
-
})), Effect28.mapError((error) => preserveToolError(input.call.name, error)));
|
|
7868
|
+
};
|
|
7869
|
+
const callInfo = ToolCallInfo.of(context);
|
|
7870
|
+
const output = yield* tool.run(input.call.input, context).pipe(Effect28.provideService(ToolCallInfo, callInfo), Effect28.mapError((error) => preserveToolError(input.call.name, error)));
|
|
7899
7871
|
return {
|
|
7900
7872
|
call_id: input.call.id,
|
|
7901
|
-
output: jsonValue(
|
|
7902
|
-
...result.isFailure ? { error: "Tool handler failed" } : {}
|
|
7873
|
+
output: jsonValue(output)
|
|
7903
7874
|
};
|
|
7904
7875
|
});
|
|
7905
7876
|
var approvalWaitId = (input) => exports_ids_schema.WaitId.make(`wait:approval:${input.call.id}`);
|
|
@@ -7973,38 +7944,85 @@ var recordRequested = (repository, eventLog, input) => repository.getCall(input.
|
|
|
7973
7944
|
return repository.recordCall({ executionId: input.executionId, call: input.call, createdAt: input.createdAt }).pipe(Effect28.mapError(mapRepositoryError4), Effect28.flatMap(() => appendIdempotentTo(eventLog, requestedEvent(input)).pipe(Effect28.mapError(mapEventLogError2))), Effect28.asVoid);
|
|
7974
7945
|
}));
|
|
7975
7946
|
var recordReceived = (repository, eventLog, input, result) => repository.recordResult({ result, createdAt: input.createdAt + 1 }).pipe(Effect28.catchTag("DuplicateToolResult", () => repository.getResult(result.call_id).pipe(Effect28.mapError(mapRepositoryError4), Effect28.flatMap((existing) => existing === undefined ? Effect28.fail(new ToolRuntimeError({ message: "DuplicateToolResult" })) : Effect28.succeed(existing)))), Effect28.mapError(preserveRecordResultError), Effect28.flatMap((record2) => appendIdempotentTo(eventLog, resultEvent(input, record2.result)).pipe(Effect28.mapError(mapEventLogError2), Effect28.as(record2.result))));
|
|
7976
|
-
var
|
|
7947
|
+
var nonEmptyName = (name) => Schema35.decodeUnknownSync(exports_shared_schema.NonEmptyString)(name);
|
|
7948
|
+
var definitionFromEffectTool = (tool, options) => ({
|
|
7977
7949
|
name: tool.name,
|
|
7978
7950
|
description: Ai.Tool.getDescription(tool) ?? "",
|
|
7979
7951
|
input_schema: jsonValue(Ai.Tool.getJsonSchema(tool)),
|
|
7980
7952
|
output_schema: jsonValue(Ai.Tool.getJsonSchemaFromSchema(tool.successSchema)),
|
|
7981
|
-
permissions
|
|
7982
|
-
}
|
|
7953
|
+
permissions: options.permissions ?? [],
|
|
7954
|
+
...options.requirements === undefined ? {} : { requirements: options.requirements },
|
|
7955
|
+
...options.needsApproval === undefined ? {} : { needs_approval: options.needsApproval },
|
|
7956
|
+
...options.metadata === undefined ? {} : { metadata: options.metadata }
|
|
7957
|
+
});
|
|
7958
|
+
var tool = (name, options) => {
|
|
7959
|
+
const effectTool = Ai.Tool.make(name, {
|
|
7960
|
+
description: options.description,
|
|
7961
|
+
parameters: options.input,
|
|
7962
|
+
success: options.output,
|
|
7963
|
+
failureMode: "return",
|
|
7964
|
+
needsApproval: options.needsApproval
|
|
7965
|
+
});
|
|
7966
|
+
const definition = definitionFromEffectTool(effectTool, options);
|
|
7967
|
+
return {
|
|
7968
|
+
name: nonEmptyName(name),
|
|
7969
|
+
definition,
|
|
7970
|
+
tool: effectTool,
|
|
7971
|
+
...options.requiredPermissions === undefined ? {} : { requiredPermissions: options.requiredPermissions },
|
|
7972
|
+
validateInput: (input) => Schema35.decodeUnknownEffect(options.input)(input).pipe(Effect28.mapError((error) => new ToolInputInvalid({ tool_name: name, message: error.message })), Effect28.asVoid),
|
|
7973
|
+
run: (input, context) => Schema35.decodeUnknownEffect(options.input)(input).pipe(Effect28.flatMap((decoded) => options.run(decoded, context)), Effect28.flatMap(Schema35.encodeUnknownEffect(options.output)), Effect28.map(jsonValue))
|
|
7974
|
+
};
|
|
7975
|
+
};
|
|
7976
|
+
var dynamicTool = (name, options) => {
|
|
7977
|
+
const parameters = parametersForInputSchema(options.inputSchema);
|
|
7978
|
+
const modelTool = attachJsonSchema(Ai.Tool.dynamic(name, {
|
|
7979
|
+
description: options.description,
|
|
7980
|
+
parameters: parameters.parameters,
|
|
7981
|
+
success: Schema35.Unknown,
|
|
7982
|
+
needsApproval: options.needsApproval
|
|
7983
|
+
}), parameters.jsonSchema);
|
|
7984
|
+
return {
|
|
7985
|
+
name: nonEmptyName(name),
|
|
7986
|
+
definition: {
|
|
7987
|
+
name: nonEmptyName(name),
|
|
7988
|
+
description: options.description,
|
|
7989
|
+
input_schema: options.inputSchema,
|
|
7990
|
+
output_schema: options.outputSchema,
|
|
7991
|
+
permissions: options.permissions ?? [],
|
|
7992
|
+
...options.requirements === undefined ? {} : { requirements: options.requirements },
|
|
7993
|
+
...options.needsApproval === undefined ? {} : { needs_approval: options.needsApproval },
|
|
7994
|
+
...options.metadata === undefined ? {} : { metadata: options.metadata }
|
|
7995
|
+
},
|
|
7996
|
+
tool: modelTool,
|
|
7997
|
+
...options.requiredPermissions === undefined ? {} : { requiredPermissions: options.requiredPermissions },
|
|
7998
|
+
run: options.run
|
|
7999
|
+
};
|
|
8000
|
+
};
|
|
7983
8001
|
var layer23 = (initialTools = []) => Layer26.effect(Service26, Effect28.gen(function* () {
|
|
7984
8002
|
const repository = yield* exports_tool_call_repository.Service;
|
|
7985
8003
|
const eventLog = yield* Service24;
|
|
7986
8004
|
const waits = yield* Service25;
|
|
7987
8005
|
const tools = yield* Ref6.make(initialTools.reduce(upsertTool, Chunk.empty()));
|
|
7988
8006
|
return Service26.of({
|
|
7989
|
-
register: Effect28.fn("ToolRuntime.register")((
|
|
7990
|
-
definitions: Ref6.get(tools).pipe(Effect28.map((registry) => Chunk.toReadonlyArray(Chunk.map(registry, (
|
|
8007
|
+
register: Effect28.fn("ToolRuntime.register")((registeredTool) => registerTool(tools, registeredTool)),
|
|
8008
|
+
definitions: Ref6.get(tools).pipe(Effect28.map((registry) => Chunk.toReadonlyArray(Chunk.map(registry, (registeredTool) => registeredTool.definition)))),
|
|
7991
8009
|
registeredTools: Ref6.get(tools).pipe(Effect28.map(Chunk.toReadonlyArray)),
|
|
7992
8010
|
run: Effect28.fn("ToolRuntime.run")(function* (input) {
|
|
7993
8011
|
const stored = yield* Ref6.get(tools);
|
|
7994
8012
|
const registry = (input.extraTools ?? []).reduce(upsertTool, stored);
|
|
7995
|
-
const
|
|
7996
|
-
if (
|
|
8013
|
+
const registeredTool = Chunk.findFirst(registry, sameToolName(input.call.name)).pipe(Option6.getOrUndefined);
|
|
8014
|
+
if (registeredTool === undefined) {
|
|
7997
8015
|
return yield* Effect28.fail(new ToolNotRegistered({ tool_name: input.call.name }));
|
|
7998
8016
|
}
|
|
7999
8017
|
const existingResult = yield* repository.getResult(input.call.id).pipe(Effect28.mapError(mapRepositoryError4));
|
|
8000
8018
|
if (existingResult !== undefined)
|
|
8001
8019
|
return existingResult.result;
|
|
8002
8020
|
return yield* Effect28.gen(function* () {
|
|
8003
|
-
yield* ensureAllowed(
|
|
8004
|
-
yield* validateInput(
|
|
8021
|
+
yield* ensureAllowed(registeredTool, input);
|
|
8022
|
+
yield* validateInput(registeredTool, input);
|
|
8005
8023
|
yield* recordRequested(repository, eventLog, input);
|
|
8006
8024
|
let effectiveInput = input;
|
|
8007
|
-
if (
|
|
8025
|
+
if (registeredTool.definition.needs_approval === true) {
|
|
8008
8026
|
const bypass = yield* hasPermissionApprovalBypass(waits, input);
|
|
8009
8027
|
if (!bypass) {
|
|
8010
8028
|
const decision = yield* resolveApproval(waits, eventLog, input);
|
|
@@ -8020,7 +8038,7 @@ var layer23 = (initialTools = []) => Layer26.effect(Service26, Effect28.gen(func
|
|
|
8020
8038
|
}
|
|
8021
8039
|
}
|
|
8022
8040
|
}
|
|
8023
|
-
const rawResult = yield* finalToolResult(
|
|
8041
|
+
const rawResult = yield* finalToolResult(registeredTool, effectiveInput);
|
|
8024
8042
|
const result = input.transformResult === undefined || rawResult.error !== undefined ? rawResult : yield* input.transformResult(rawResult);
|
|
8025
8043
|
const received = yield* recordReceived(repository, eventLog, effectiveInput, result);
|
|
8026
8044
|
yield* recordToolCall(input.call.name, result.error === undefined ? "success" : "failure");
|
|
@@ -8031,9 +8049,9 @@ var layer23 = (initialTools = []) => Layer26.effect(Service26, Effect28.gen(func
|
|
|
8031
8049
|
}));
|
|
8032
8050
|
var memoryLayer23 = (tools = []) => layer23(tools).pipe(Layer26.provide(layer22), Layer26.provide(exports_tool_call_repository.memoryLayer), Layer26.provide(exports_envelope_repository.memoryLayer), Layer26.provide(exports_schedule_repository.memoryLayer), Layer26.provide(memoryLayer21));
|
|
8033
8051
|
var testLayer23 = (implementation) => Layer26.succeed(Service26, Service26.of(implementation));
|
|
8034
|
-
var register2 = Effect28.fn("ToolRuntime.register.call")(function* (
|
|
8052
|
+
var register2 = Effect28.fn("ToolRuntime.register.call")(function* (registeredTool) {
|
|
8035
8053
|
const service = yield* Service26;
|
|
8036
|
-
return yield* service.register(
|
|
8054
|
+
return yield* service.register(registeredTool);
|
|
8037
8055
|
});
|
|
8038
8056
|
var definitions = Effect28.fn("ToolRuntime.definitions.call")(function* () {
|
|
8039
8057
|
const service = yield* Service26;
|
|
@@ -8214,7 +8232,7 @@ class AddressRouteKindMismatch extends Schema37.TaggedErrorClass()("AddressRoute
|
|
|
8214
8232
|
|
|
8215
8233
|
class AddressAgentDefinitionNotFound extends Schema37.TaggedErrorClass()("AddressAgentDefinitionNotFound", {
|
|
8216
8234
|
address_id: exports_ids_schema.AddressId,
|
|
8217
|
-
agent_definition_id: exports_ids_schema.
|
|
8235
|
+
agent_definition_id: exports_ids_schema.AgentId
|
|
8218
8236
|
}) {
|
|
8219
8237
|
}
|
|
8220
8238
|
|
|
@@ -8230,7 +8248,7 @@ var LocalAgentRoute = Schema37.Struct({
|
|
|
8230
8248
|
var LocalAgentTarget = Schema37.Struct({
|
|
8231
8249
|
address_id: exports_ids_schema.AddressId,
|
|
8232
8250
|
route: LocalAgentRoute,
|
|
8233
|
-
agent_definition_id: exports_ids_schema.
|
|
8251
|
+
agent_definition_id: exports_ids_schema.AgentId,
|
|
8234
8252
|
agent_definition_revision: exports_agent_schema.DefinitionRevision,
|
|
8235
8253
|
agent_definition_snapshot: exports_agent_schema.Definition,
|
|
8236
8254
|
tool_input_schema_digests: Schema37.optionalKey(exports_agent_schema.ToolInputSchemaDigests)
|
|
@@ -8266,22 +8284,22 @@ var layer25 = Layer28.effect(Service28, Effect30.gen(function* () {
|
|
|
8266
8284
|
return yield* Effect30.fail(new AddressRouteNotFound({ address_id: addressId }));
|
|
8267
8285
|
}
|
|
8268
8286
|
const route = yield* routeToLocalAgent(addressId, record2.route);
|
|
8269
|
-
const
|
|
8270
|
-
const definition = yield* agentRegistry.get(
|
|
8287
|
+
const agentId = yield* Schema37.decodeUnknownEffect(exports_ids_schema.AgentId)(route.route_key).pipe(Effect30.mapError((error) => new AddressResolutionError({ message: String(error) })));
|
|
8288
|
+
const definition = yield* agentRegistry.get(agentId).pipe(Effect30.mapError(mapAgentRegistryError));
|
|
8271
8289
|
if (definition === undefined) {
|
|
8272
8290
|
return yield* Effect30.fail(new AddressAgentDefinitionNotFound({
|
|
8273
8291
|
address_id: addressId,
|
|
8274
|
-
agent_definition_id:
|
|
8292
|
+
agent_definition_id: agentId
|
|
8275
8293
|
}));
|
|
8276
8294
|
}
|
|
8277
8295
|
yield* Effect30.annotateCurrentSpan({
|
|
8278
|
-
"relay.agent_definition.id":
|
|
8296
|
+
"relay.agent_definition.id": agentId,
|
|
8279
8297
|
"relay.agent_definition.revision": definition.current_revision
|
|
8280
8298
|
});
|
|
8281
8299
|
return {
|
|
8282
8300
|
address_id: addressId,
|
|
8283
8301
|
route,
|
|
8284
|
-
agent_definition_id:
|
|
8302
|
+
agent_definition_id: agentId,
|
|
8285
8303
|
agent_definition_revision: definition.current_revision,
|
|
8286
8304
|
agent_definition_snapshot: definition.definition,
|
|
8287
8305
|
...definition.tool_input_schema_digests === undefined ? {} : { tool_input_schema_digests: definition.tool_input_schema_digests }
|
|
@@ -8297,11 +8315,11 @@ var resolveLocalAgent = Effect30.fn("AddressResolution.resolveLocalAgent.call")(
|
|
|
8297
8315
|
// ../runtime/src/agent/agent-loop-service.ts
|
|
8298
8316
|
var exports_agent_loop_service = {};
|
|
8299
8317
|
__export(exports_agent_loop_service, {
|
|
8318
|
+
toolFromDefinition: () => toolFromDefinition,
|
|
8300
8319
|
testLayer: () => testLayer45,
|
|
8301
8320
|
run: () => run3,
|
|
8302
8321
|
mapBoundaryError: () => mapBoundaryError,
|
|
8303
8322
|
layer: () => layer44,
|
|
8304
|
-
aiToolFromDefinition: () => aiToolFromDefinition,
|
|
8305
8323
|
Service: () => Service41,
|
|
8306
8324
|
STRUCTURED_TURN_PROMPT: () => STRUCTURED_TURN_PROMPT,
|
|
8307
8325
|
AgentLoopWaitRequested: () => AgentLoopWaitRequested,
|
|
@@ -8319,7 +8337,7 @@ __export(exports_agent, {
|
|
|
8319
8337
|
generate: () => generate,
|
|
8320
8338
|
defaultObjectPrompt: () => defaultObjectPrompt
|
|
8321
8339
|
});
|
|
8322
|
-
import { Cause as Cause3, Effect as Effect44, Fiber, Option as Option15, Queue as Queue2, Ref as Ref10, Stream as
|
|
8340
|
+
import { Cause as Cause3, Effect as Effect44, Fiber, Option as Option15, Queue as Queue2, Ref as Ref10, Stream as Stream6 } from "effect";
|
|
8323
8341
|
import * as Ai6 from "effect/unstable/ai";
|
|
8324
8342
|
|
|
8325
8343
|
// ../../node_modules/.bun/@batonfx+core@0.1.1/node_modules/@batonfx/core/src/agent-event.ts
|
|
@@ -8890,7 +8908,7 @@ __export(exports_model_resilience, {
|
|
|
8890
8908
|
apply: () => apply,
|
|
8891
8909
|
ModelResilience: () => ModelResilience
|
|
8892
8910
|
});
|
|
8893
|
-
import { Cause, Context as Context36, Effect as Effect38, Layer as Layer36, Schedule as Schedule2, Stream as
|
|
8911
|
+
import { Cause, Context as Context36, Effect as Effect38, Layer as Layer36, Schedule as Schedule2, Stream as Stream4 } from "effect";
|
|
8894
8912
|
import * as Ai5 from "effect/unstable/ai";
|
|
8895
8913
|
|
|
8896
8914
|
class ModelResilience extends Context36.Service()("@batonfx/core/ModelResilience") {
|
|
@@ -8912,15 +8930,15 @@ var apply = (model, resilience) => ({
|
|
|
8912
8930
|
...model,
|
|
8913
8931
|
generateText: (options) => retryEffect(() => model.generateText(options), resilience),
|
|
8914
8932
|
generateObject: (options) => retryEffect(() => model.generateObject(options), resilience),
|
|
8915
|
-
streamText: (options) =>
|
|
8933
|
+
streamText: (options) => Stream4.suspend(() => {
|
|
8916
8934
|
let emitted = false;
|
|
8917
|
-
return model.streamText(options).pipe(
|
|
8935
|
+
return model.streamText(options).pipe(Stream4.tap(() => Effect38.sync(() => {
|
|
8918
8936
|
emitted = true;
|
|
8919
|
-
})),
|
|
8937
|
+
})), Stream4.catchCause((cause) => {
|
|
8920
8938
|
const error = Cause.squash(cause);
|
|
8921
|
-
return emitted ?
|
|
8939
|
+
return emitted ? Stream4.make(Ai5.Response.makePart("error", { error })) : Stream4.failCause(cause);
|
|
8922
8940
|
}));
|
|
8923
|
-
}).pipe(
|
|
8941
|
+
}).pipe(Stream4.retry(retryStreamSchedule(resilience)))
|
|
8924
8942
|
});
|
|
8925
8943
|
|
|
8926
8944
|
// ../../node_modules/.bun/@batonfx+core@0.1.1/node_modules/@batonfx/core/src/permissions.ts
|
|
@@ -8972,23 +8990,23 @@ var paramsText = (params) => {
|
|
|
8972
8990
|
const json = JSON.stringify(params);
|
|
8973
8991
|
return json === undefined ? String(params) : json;
|
|
8974
8992
|
};
|
|
8975
|
-
var matches = (pattern,
|
|
8993
|
+
var matches = (pattern, tool2, params) => {
|
|
8976
8994
|
const separator = pattern.indexOf(":");
|
|
8977
8995
|
if (separator === -1)
|
|
8978
|
-
return glob(pattern).test(
|
|
8996
|
+
return glob(pattern).test(tool2);
|
|
8979
8997
|
const toolPattern = pattern.slice(0, separator);
|
|
8980
8998
|
const paramsPattern = pattern.slice(separator + 1);
|
|
8981
|
-
return glob(toolPattern).test(
|
|
8999
|
+
return glob(toolPattern).test(tool2) && glob(paramsPattern).test(paramsText(params));
|
|
8982
9000
|
};
|
|
8983
|
-
var matchingRule = (ruleset,
|
|
9001
|
+
var matchingRule = (ruleset, tool2, params) => {
|
|
8984
9002
|
let matched;
|
|
8985
9003
|
for (const rule of ruleset.rules) {
|
|
8986
|
-
if (matches(rule.pattern,
|
|
9004
|
+
if (matches(rule.pattern, tool2, params))
|
|
8987
9005
|
matched = rule;
|
|
8988
9006
|
}
|
|
8989
9007
|
return matched;
|
|
8990
9008
|
};
|
|
8991
|
-
var evaluate = (ruleset,
|
|
9009
|
+
var evaluate = (ruleset, tool2, params) => matchingRule(ruleset, tool2, params)?.level ?? ruleset.fallback ?? "ask";
|
|
8992
9010
|
var tokenFor = (request) => `permission:${request.toolCallId ?? `${request.agentName}:${request.turn}:${request.tool}`}`;
|
|
8993
9011
|
var decisionFor = (ruleset, request) => {
|
|
8994
9012
|
const rule = matchingRule(ruleset, request.tool, request.params);
|
|
@@ -9068,7 +9086,7 @@ __export(exports_tool_executor, {
|
|
|
9068
9086
|
fromToolkit: () => fromToolkit,
|
|
9069
9087
|
ToolExecutor: () => ToolExecutor
|
|
9070
9088
|
});
|
|
9071
|
-
import { Cause as Cause2, Context as Context40, Effect as Effect42, Layer as Layer40, Option as Option14, Sink
|
|
9089
|
+
import { Cause as Cause2, Context as Context40, Effect as Effect42, Layer as Layer40, Option as Option14, Sink, Stream as Stream5 } from "effect";
|
|
9072
9090
|
|
|
9073
9091
|
class ToolExecutor extends Context40.Service()("@batonfx/core/ToolExecutor") {
|
|
9074
9092
|
}
|
|
@@ -9093,7 +9111,7 @@ var executeWithToolkit = (toolkit, request) => {
|
|
|
9093
9111
|
if (toolkit.tools[request.call.name] === undefined) {
|
|
9094
9112
|
return Effect42.succeed(failureOutcome(`Tool ${request.call.name} is not registered`));
|
|
9095
9113
|
}
|
|
9096
|
-
return toolkit.handle(request.call.name, request.call.params).pipe(Effect42.flatMap((results) => results.pipe(
|
|
9114
|
+
return toolkit.handle(request.call.name, request.call.params).pipe(Effect42.flatMap((results) => results.pipe(Stream5.filter((item) => item.preliminary === false), Stream5.run(Sink.last()))), Effect42.map(Option14.match({
|
|
9097
9115
|
onNone: () => failureOutcome("Tool handler did not produce a final result"),
|
|
9098
9116
|
onSome: (result) => result.isFailure ? failureOutcome(resultMessage(result.result)) : {
|
|
9099
9117
|
_tag: "Success",
|
|
@@ -9182,8 +9200,8 @@ var suspended = (call, token, reason) => new AgentSuspended({
|
|
|
9182
9200
|
});
|
|
9183
9201
|
var withSystem = (instructions, prompt) => Ai6.Prompt.fromMessages([Ai6.Prompt.makeMessage("system", { content: instructions }), ...prompt.content]);
|
|
9184
9202
|
var isUserMessagePart = (part) => part.type === "text" || part.type === "file";
|
|
9185
|
-
var approvalRequired = (
|
|
9186
|
-
const needsApproval =
|
|
9203
|
+
var approvalRequired = (tool2, call, messages) => {
|
|
9204
|
+
const needsApproval = tool2?.needsApproval;
|
|
9187
9205
|
if (needsApproval === undefined)
|
|
9188
9206
|
return Effect44.succeed(false);
|
|
9189
9207
|
if (typeof needsApproval === "boolean")
|
|
@@ -9213,7 +9231,7 @@ var applyPartChain = (chain, part, context) => Effect44.gen(function* () {
|
|
|
9213
9231
|
}
|
|
9214
9232
|
return current2;
|
|
9215
9233
|
});
|
|
9216
|
-
var streamInternal = (agent, options, structured) =>
|
|
9234
|
+
var streamInternal = (agent, options, structured) => Stream6.unwrap(Effect44.gen(function* () {
|
|
9217
9235
|
const executor = yield* ToolExecutor;
|
|
9218
9236
|
const approvals = yield* Approvals;
|
|
9219
9237
|
const chain = yield* ModelMiddleware;
|
|
@@ -9270,7 +9288,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9270
9288
|
const freshChat = options.history !== undefined ? Ai6.Chat.fromPrompt(options.history) : system !== undefined ? Ai6.Chat.fromPrompt([Ai6.Prompt.makeMessage("system", { content: system })]) : Ai6.Chat.empty;
|
|
9271
9289
|
const chat = persisted ?? (yield* freshChat);
|
|
9272
9290
|
const savePersisted = persisted === undefined ? Effect44.void : persisted.save.pipe(Effect44.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })));
|
|
9273
|
-
const failSuspended = (call, token, reason) =>
|
|
9291
|
+
const failSuspended = (call, token, reason) => Stream6.unwrap(savePersisted.pipe(Effect44.as(Stream6.fail(suspended(call, token, reason)))));
|
|
9274
9292
|
const state = {
|
|
9275
9293
|
text: "",
|
|
9276
9294
|
turn: 0,
|
|
@@ -9376,18 +9394,18 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9376
9394
|
case "Success":
|
|
9377
9395
|
return boundedSuccessResult(turn, call, outcome).pipe(Effect44.map((result) => {
|
|
9378
9396
|
state.pending.push(result);
|
|
9379
|
-
return
|
|
9397
|
+
return Stream6.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9380
9398
|
}));
|
|
9381
9399
|
case "Failure": {
|
|
9382
9400
|
const result = failedResult(call, outcome.message);
|
|
9383
9401
|
state.pending.push(result);
|
|
9384
|
-
return Effect44.succeed(
|
|
9402
|
+
return Effect44.succeed(Stream6.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]));
|
|
9385
9403
|
}
|
|
9386
9404
|
case "Suspend":
|
|
9387
9405
|
return Effect44.succeed(failSuspended(call, outcome.token, "tool-wait"));
|
|
9388
9406
|
}
|
|
9389
9407
|
};
|
|
9390
|
-
const executeApproved = (turn, call, request) =>
|
|
9408
|
+
const executeApproved = (turn, call, request) => Stream6.concat(Stream6.fromIterable([{ _tag: "ToolExecutionStarted", turn, call }]), Stream6.unwrap(Effect44.gen(function* () {
|
|
9391
9409
|
const progressQueue = yield* Queue2.unbounded();
|
|
9392
9410
|
const signal = yield* Effect44.abortSignal;
|
|
9393
9411
|
const context = ToolContext.of({
|
|
@@ -9405,29 +9423,29 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9405
9423
|
}
|
|
9406
9424
|
});
|
|
9407
9425
|
const fiber = yield* executor.execute(request).pipe(Effect44.provideService(ToolContext, context), Effect44.ensuring(Queue2.end(progressQueue).pipe(Effect44.asVoid)), Effect44.forkScoped({ startImmediately: true }));
|
|
9408
|
-
return
|
|
9426
|
+
return Stream6.concat(Stream6.fromQueue(progressQueue), Stream6.fromEffect(Fiber.join(fiber)).pipe(Stream6.flatMap((outcome) => Stream6.unwrap(outcomeEvents(turn, call, outcome)))));
|
|
9409
9427
|
})));
|
|
9410
9428
|
const permissionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9411
9429
|
const permissionDeniedEvents = (turn, call, reason) => {
|
|
9412
9430
|
const result = failedResult(call, reason ?? "Permission denied");
|
|
9413
9431
|
state.pending.push(result);
|
|
9414
|
-
return
|
|
9432
|
+
return Stream6.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9415
9433
|
};
|
|
9416
9434
|
const rememberAlways = (turn, call) => Effect44.serviceOption(RuleStore).pipe(Effect44.flatMap(Option15.match({
|
|
9417
9435
|
onNone: () => Effect44.void,
|
|
9418
9436
|
onSome: (store) => store.remember({ pattern: call.name, level: "allow" }).pipe(Effect44.mapError((error) => permissionError(turn, error)))
|
|
9419
9437
|
})));
|
|
9420
|
-
const approvalEvents = (turn, call, messages, request,
|
|
9438
|
+
const approvalEvents = (turn, call, messages, request, tool2) => Stream6.unwrap(approvalRequired(tool2, call, messages).pipe(Effect44.map((isRequired) => {
|
|
9421
9439
|
if (!isRequired)
|
|
9422
9440
|
return executeApproved(turn, call, request);
|
|
9423
|
-
return
|
|
9441
|
+
return Stream6.concat(Stream6.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream6.unwrap(approvals.check(request).pipe(Effect44.map((decision2) => {
|
|
9424
9442
|
switch (decision2._tag) {
|
|
9425
9443
|
case "Approved":
|
|
9426
9444
|
return executeApproved(turn, call, request);
|
|
9427
9445
|
case "Denied": {
|
|
9428
9446
|
const result = failedResult(call, decision2.reason ?? "Tool call denied");
|
|
9429
9447
|
state.pending.push(result);
|
|
9430
|
-
return
|
|
9448
|
+
return Stream6.fromIterable([
|
|
9431
9449
|
{ _tag: "ToolExecutionCompleted", turn, call, result }
|
|
9432
9450
|
]);
|
|
9433
9451
|
}
|
|
@@ -9443,7 +9461,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9443
9461
|
case "Denied":
|
|
9444
9462
|
return permissionDeniedEvents(turn, call, answer.reason);
|
|
9445
9463
|
case "Always":
|
|
9446
|
-
return
|
|
9464
|
+
return Stream6.unwrap(rememberAlways(turn, call).pipe(Effect44.as(executeApproved(turn, call, request))));
|
|
9447
9465
|
}
|
|
9448
9466
|
};
|
|
9449
9467
|
const permissionAskEvents = (turn, call, request, token) => {
|
|
@@ -9457,17 +9475,17 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9457
9475
|
};
|
|
9458
9476
|
if (Option15.isNone(permissionsService))
|
|
9459
9477
|
return failSuspended(call, token, "approval");
|
|
9460
|
-
return
|
|
9478
|
+
return Stream6.concat(Stream6.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream6.unwrap(permissionsService.value.await(pending).pipe(Effect44.mapError((error) => permissionError(turn, error)), Effect44.map(Option15.match({
|
|
9461
9479
|
onNone: () => failSuspended(call, token, "approval"),
|
|
9462
9480
|
onSome: (answer) => permissionAnsweredEvents(turn, call, request, answer)
|
|
9463
9481
|
})))));
|
|
9464
9482
|
};
|
|
9465
9483
|
const toolCallEvents = (turn, call, messages) => {
|
|
9466
9484
|
const request = { call, turn, agentName: agent.name, sessionId };
|
|
9467
|
-
const
|
|
9485
|
+
const tool2 = agent.toolkit.tools[call.name];
|
|
9468
9486
|
if (Option15.isNone(permissionsService))
|
|
9469
|
-
return approvalEvents(turn, call, messages, request,
|
|
9470
|
-
return
|
|
9487
|
+
return approvalEvents(turn, call, messages, request, tool2);
|
|
9488
|
+
return Stream6.unwrap(permissionsService.value.evaluate({
|
|
9471
9489
|
tool: call.name,
|
|
9472
9490
|
params: call.params,
|
|
9473
9491
|
agentName: agent.name,
|
|
@@ -9477,7 +9495,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9477
9495
|
}).pipe(Effect44.mapError((error) => permissionError(turn, error)), Effect44.map((decision2) => {
|
|
9478
9496
|
switch (decision2._tag) {
|
|
9479
9497
|
case "Allow":
|
|
9480
|
-
return approvalEvents(turn, call, messages, request,
|
|
9498
|
+
return approvalEvents(turn, call, messages, request, tool2);
|
|
9481
9499
|
case "Deny":
|
|
9482
9500
|
return permissionDeniedEvents(turn, call, decision2.reason);
|
|
9483
9501
|
case "Ask":
|
|
@@ -9515,56 +9533,56 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9515
9533
|
});
|
|
9516
9534
|
const partEvents = (turn, part, messages) => {
|
|
9517
9535
|
if (part.type === "error") {
|
|
9518
|
-
return
|
|
9536
|
+
return Stream6.fail(new AgentError({ message: errorMessage(part.error), turn, cause: part.error }));
|
|
9519
9537
|
}
|
|
9520
|
-
const modelPart =
|
|
9538
|
+
const modelPart = Stream6.fromIterable([{ _tag: "ModelPart", turn, part }]);
|
|
9521
9539
|
if (part.type === "tool-call") {
|
|
9522
9540
|
const call = part;
|
|
9523
|
-
return call.providerExecuted === true ? modelPart :
|
|
9541
|
+
return call.providerExecuted === true ? modelPart : Stream6.concat(modelPart, toolCallEvents(turn, call, messages));
|
|
9524
9542
|
}
|
|
9525
9543
|
if (part.type === "text-delta") {
|
|
9526
9544
|
state.text = `${state.text}${part.delta}`;
|
|
9527
9545
|
}
|
|
9528
9546
|
if (part.type === "finish") {
|
|
9529
|
-
return modelPart.pipe(
|
|
9547
|
+
return modelPart.pipe(Stream6.tap(() => captureFinishPart(part)));
|
|
9530
9548
|
}
|
|
9531
9549
|
return modelPart;
|
|
9532
9550
|
};
|
|
9533
|
-
const applyPartToEvents = (turn, part, messages) =>
|
|
9551
|
+
const applyPartToEvents = (turn, part, messages) => Stream6.unwrap(applyPartChain(chain, part, { agentName: agent.name, turn }).pipe(Effect44.map(Option15.match({
|
|
9534
9552
|
onSome: (transformed) => partEvents(turn, transformed, messages),
|
|
9535
|
-
onNone: () => part.type === "tool-call" ?
|
|
9553
|
+
onNone: () => part.type === "tool-call" ? Stream6.fail(new MiddlewareViolation({
|
|
9536
9554
|
turn,
|
|
9537
9555
|
detail: "ModelMiddleware dropped a tool-call part"
|
|
9538
|
-
})) :
|
|
9556
|
+
})) : Stream6.empty
|
|
9539
9557
|
}))));
|
|
9540
|
-
const activeToolkit = (activeTools) => Ai6.Toolkit.make(...Object.values(agent.toolkit.tools).filter((
|
|
9558
|
+
const activeToolkit = (activeTools) => Ai6.Toolkit.make(...Object.values(agent.toolkit.tools).filter((tool2) => activeTools.includes(tool2.name)));
|
|
9541
9559
|
const modelTurn = (turn, prompt, overrides) => {
|
|
9542
9560
|
const toolkit = overrides?.activeTools === undefined ? agent.toolkit : activeToolkit(overrides.activeTools);
|
|
9543
|
-
const attempt = (activePrompt, retryOverflow) =>
|
|
9561
|
+
const attempt = (activePrompt, retryOverflow) => Stream6.unwrap(Ref10.get(chat.history).pipe(Effect44.map((historyBeforeAttempt) => {
|
|
9544
9562
|
let emitted = false;
|
|
9545
9563
|
const messages = Ai6.Prompt.concat(historyBeforeAttempt, activePrompt).content;
|
|
9546
|
-
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(
|
|
9564
|
+
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(Stream6.map((part) => ({ part, messages })), Stream6.tap(() => Effect44.sync(() => {
|
|
9547
9565
|
emitted = true;
|
|
9548
|
-
})),
|
|
9566
|
+
})), Stream6.catchCause((cause) => {
|
|
9549
9567
|
if (Cause3.hasInterrupts(cause))
|
|
9550
|
-
return
|
|
9568
|
+
return Stream6.fromEffect(Effect44.interrupt);
|
|
9551
9569
|
const error = Cause3.squash(cause);
|
|
9552
9570
|
if (retryOverflow && !emitted && isContextOverflow(error) && Option15.isSome(compactionService)) {
|
|
9553
|
-
return
|
|
9571
|
+
return Stream6.unwrap(Effect44.gen(function* () {
|
|
9554
9572
|
yield* Ref10.set(chat.history, historyBeforeAttempt);
|
|
9555
9573
|
const compactedPrompt = yield* preparePrompt(turn, activePrompt, true);
|
|
9556
9574
|
return attempt(compactedPrompt, false);
|
|
9557
9575
|
}));
|
|
9558
9576
|
}
|
|
9559
|
-
return
|
|
9577
|
+
return Stream6.make({ part: Ai6.Response.makePart("error", { error }), messages });
|
|
9560
9578
|
}));
|
|
9561
9579
|
})));
|
|
9562
|
-
const parts =
|
|
9580
|
+
const parts = Stream6.unwrap(applyPromptChain(chain, Ai6.Prompt.make(prompt), { agentName: agent.name, turn }).pipe(Effect44.flatMap((transformedPrompt) => preparePrompt(turn, transformedPrompt, false)), Effect44.map((preparedPrompt) => attempt(preparedPrompt, true).pipe(Stream6.flatMap(({ part, messages }) => applyPartToEvents(turn, part, messages))))));
|
|
9563
9581
|
const resilientParts = Option15.match(resilienceService, {
|
|
9564
9582
|
onNone: () => parts,
|
|
9565
|
-
onSome: (resilience) =>
|
|
9583
|
+
onSome: (resilience) => Stream6.unwrap(Ai6.LanguageModel.LanguageModel.pipe(Effect44.map((model) => parts.pipe(Stream6.provideService(Ai6.LanguageModel.LanguageModel, apply(model, resilience))))))
|
|
9566
9584
|
});
|
|
9567
|
-
return overrides?.model === undefined ? resilientParts : resilientParts.pipe(
|
|
9585
|
+
return overrides?.model === undefined ? resilientParts : resilientParts.pipe(Stream6.provide(overrides.model));
|
|
9568
9586
|
};
|
|
9569
9587
|
const turnCompletedEvent = (turn, transcript) => ({
|
|
9570
9588
|
_tag: "TurnCompleted",
|
|
@@ -9579,7 +9597,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9579
9597
|
transcript,
|
|
9580
9598
|
...state.usage === undefined ? {} : { usage: state.usage }
|
|
9581
9599
|
});
|
|
9582
|
-
const structuredFinalEvents = (turn, config) =>
|
|
9600
|
+
const structuredFinalEvents = (turn, config) => Stream6.fromEffect(Effect44.gen(function* () {
|
|
9583
9601
|
const structuredTurn = turn + 1;
|
|
9584
9602
|
const transformedPrompt = yield* applyPromptChain(chain, Ai6.Prompt.make(config.objectPrompt), {
|
|
9585
9603
|
agentName: agent.name,
|
|
@@ -9601,7 +9619,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9601
9619
|
content: response.content
|
|
9602
9620
|
};
|
|
9603
9621
|
return [structuredOutput, terminalCompletedEvent(structuredTurn, transcript)];
|
|
9604
|
-
})).pipe(
|
|
9622
|
+
})).pipe(Stream6.flatMap((events) => Stream6.fromIterable(events)));
|
|
9605
9623
|
const promptFromSteeringMessages = (messages) => messages.reduce((prompt, message) => Ai6.Prompt.concat(prompt, message.prompt), Ai6.Prompt.empty);
|
|
9606
9624
|
const takeSteering = () => Option15.match(steeringService, {
|
|
9607
9625
|
onNone: () => Effect44.succeed([]),
|
|
@@ -9621,18 +9639,18 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9621
9639
|
const followUp = yield* takeFollowUp();
|
|
9622
9640
|
if (followUp.length > 0) {
|
|
9623
9641
|
return {
|
|
9624
|
-
events:
|
|
9642
|
+
events: Stream6.fromIterable([completed]),
|
|
9625
9643
|
next: { prompt: promptFromSteeringMessages(followUp) }
|
|
9626
9644
|
};
|
|
9627
9645
|
}
|
|
9628
9646
|
if (structured !== undefined) {
|
|
9629
9647
|
return {
|
|
9630
|
-
events:
|
|
9648
|
+
events: Stream6.concat(Stream6.fromIterable([completed]), structuredFinalEvents(turn, structured))
|
|
9631
9649
|
};
|
|
9632
9650
|
}
|
|
9633
9651
|
yield* savePersisted;
|
|
9634
9652
|
return {
|
|
9635
|
-
events:
|
|
9653
|
+
events: Stream6.fromIterable([completed, terminalCompletedEvent(turn, transcript)])
|
|
9636
9654
|
};
|
|
9637
9655
|
}
|
|
9638
9656
|
const decision2 = yield* agent.policy.decide({
|
|
@@ -9642,7 +9660,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9642
9660
|
});
|
|
9643
9661
|
if (decision2._tag === "Stop") {
|
|
9644
9662
|
return {
|
|
9645
|
-
events:
|
|
9663
|
+
events: Stream6.concat(Stream6.fromIterable([completed]), Stream6.fail(new TurnLimitExceeded({
|
|
9646
9664
|
turn: turn + 1,
|
|
9647
9665
|
pending: pending.map((result) => ({
|
|
9648
9666
|
tool_call_id: result.id,
|
|
@@ -9657,21 +9675,21 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9657
9675
|
const basePrompt = steering.length === 0 ? toolPrompt : Ai6.Prompt.concat(promptFromSteeringMessages(steering), toolPrompt);
|
|
9658
9676
|
const prompt = decision2.overrides?.instructions === undefined ? basePrompt : withSystem(decision2.overrides.instructions, basePrompt);
|
|
9659
9677
|
return {
|
|
9660
|
-
events:
|
|
9678
|
+
events: Stream6.fromIterable([completed]),
|
|
9661
9679
|
next: { prompt, ...decision2.overrides === undefined ? {} : { overrides: decision2.overrides } }
|
|
9662
9680
|
};
|
|
9663
9681
|
});
|
|
9664
|
-
const resetTurnState = (turn) =>
|
|
9682
|
+
const resetTurnState = (turn) => Stream6.sync(() => {
|
|
9665
9683
|
state.turn = turn;
|
|
9666
9684
|
state.finish = undefined;
|
|
9667
|
-
}).pipe(
|
|
9685
|
+
}).pipe(Stream6.drain);
|
|
9668
9686
|
const runTurn = (turn, prompt, overrides) => {
|
|
9669
9687
|
let next;
|
|
9670
|
-
const currentTurn =
|
|
9688
|
+
const currentTurn = Stream6.fromIterable([{ _tag: "TurnStarted", turn }]).pipe(Stream6.concat(resetTurnState(turn)), Stream6.concat(modelTurn(turn, prompt, overrides)), Stream6.concat(Stream6.unwrap(afterTurn(turn).pipe(Effect44.map((result) => {
|
|
9671
9689
|
next = result.next;
|
|
9672
9690
|
return result.events;
|
|
9673
|
-
})))),
|
|
9674
|
-
return
|
|
9691
|
+
})))), Stream6.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": turn } }));
|
|
9692
|
+
return Stream6.concat(currentTurn, Stream6.suspend(() => next === undefined ? Stream6.empty : runTurn(turn + 1, next.prompt, next.overrides)));
|
|
9675
9693
|
};
|
|
9676
9694
|
const resumeStream = (resume) => {
|
|
9677
9695
|
let next;
|
|
@@ -9681,36 +9699,36 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect44.gen
|
|
|
9681
9699
|
params: resume.call.params,
|
|
9682
9700
|
providerExecuted: false
|
|
9683
9701
|
});
|
|
9684
|
-
const currentTurn = resetTurnState(0).pipe(
|
|
9702
|
+
const currentTurn = resetTurnState(0).pipe(Stream6.concat(Stream6.unwrap(Ref10.get(chat.history).pipe(Effect44.map((history) => toolCallEvents(0, call, history.content))))), Stream6.concat(Stream6.unwrap(afterTurn(0).pipe(Effect44.map((result) => {
|
|
9685
9703
|
next = result.next;
|
|
9686
9704
|
return result.events;
|
|
9687
|
-
})))),
|
|
9688
|
-
return
|
|
9705
|
+
})))), Stream6.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": 0 } }));
|
|
9706
|
+
return Stream6.concat(currentTurn, Stream6.suspend(() => next === undefined ? Stream6.empty : runTurn(1, next.prompt, next.overrides)));
|
|
9689
9707
|
};
|
|
9690
9708
|
const baseInitialPrompt = seedSystem === undefined ? Ai6.Prompt.make(options.prompt) : withSystem(seedSystem, Ai6.Prompt.make(options.prompt));
|
|
9691
9709
|
const initialPrompt = options.resume === undefined ? yield* recallInitialPrompt(baseInitialPrompt) : baseInitialPrompt;
|
|
9692
9710
|
const runStream = options.resume === undefined ? runTurn(0, initialPrompt) : resumeStream(options.resume);
|
|
9693
|
-
return runStream.pipe(
|
|
9711
|
+
return runStream.pipe(Stream6.catchCause((cause) => {
|
|
9694
9712
|
if (Cause3.hasInterrupts(cause))
|
|
9695
|
-
return
|
|
9713
|
+
return Stream6.fromEffect(Effect44.interrupt);
|
|
9696
9714
|
const error = Cause3.squash(cause);
|
|
9697
9715
|
if (error instanceof AgentSuspended) {
|
|
9698
|
-
return
|
|
9716
|
+
return Stream6.unwrap(Ref10.get(chat.history).pipe(Effect44.map((transcript) => Stream6.concat(Stream6.fromIterable([turnCompletedEvent(state.turn, transcript)]), Stream6.failCause(cause)))));
|
|
9699
9717
|
}
|
|
9700
|
-
return
|
|
9718
|
+
return Stream6.failCause(cause);
|
|
9701
9719
|
}));
|
|
9702
|
-
})).pipe(
|
|
9720
|
+
})).pipe(Stream6.withSpan("Baton.Agent.run", { attributes: { "baton.agent.name": agent.name } }));
|
|
9703
9721
|
var stream2 = (agent, options) => streamInternal(agent, options, undefined);
|
|
9704
9722
|
var streamObject = (agent, options) => streamInternal(agent, options, {
|
|
9705
9723
|
schema: options.schema,
|
|
9706
9724
|
objectName: options.objectName ?? "output",
|
|
9707
9725
|
objectPrompt: options.objectPrompt ?? defaultObjectPrompt
|
|
9708
9726
|
});
|
|
9709
|
-
var generate = (agent, options) =>
|
|
9727
|
+
var generate = (agent, options) => Stream6.runLast(stream2(agent, options)).pipe(Effect44.flatMap(Option15.match({
|
|
9710
9728
|
onNone: () => Effect44.fail(new AgentError({ message: "Agent run ended without a Completed event", turn: 0 })),
|
|
9711
9729
|
onSome: (event) => event._tag === "Completed" ? Effect44.succeed({ text: event.text, turns: event.turns, transcript: event.transcript }) : Effect44.fail(new AgentError({ message: "Agent run ended without a Completed event", turn: 0 }))
|
|
9712
9730
|
})));
|
|
9713
|
-
var generateObject = (agent, options) =>
|
|
9731
|
+
var generateObject = (agent, options) => Stream6.runFold(streamObject(agent, options), () => ({
|
|
9714
9732
|
value: Option15.none(),
|
|
9715
9733
|
completed: Option15.none()
|
|
9716
9734
|
}), (acc, event) => {
|
|
@@ -9891,8 +9909,8 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
9891
9909
|
return selected;
|
|
9892
9910
|
};
|
|
9893
9911
|
// ../runtime/src/agent/agent-loop-service.ts
|
|
9894
|
-
import { Config as Config3, Context as Context54, Crypto as Crypto3, Effect as Effect67, HashSet as HashSet6, Layer as Layer60, Option as Option22, Ref as Ref18, Schema as Schema60, Stream as
|
|
9895
|
-
import * as
|
|
9912
|
+
import { Config as Config3, Context as Context54, Crypto as Crypto3, Effect as Effect67, HashSet as HashSet6, Layer as Layer60, Option as Option22, Ref as Ref18, Schema as Schema60, Stream as Stream7 } from "effect";
|
|
9913
|
+
import * as Ai16 from "effect/unstable/ai";
|
|
9896
9914
|
|
|
9897
9915
|
// ../runtime/src/child/child-run-service.ts
|
|
9898
9916
|
var exports_child_run_service = {};
|
|
@@ -10217,7 +10235,6 @@ var spawnDynamic = Effect51.fn("ChildRunService.spawnDynamic.call")(function* (i
|
|
|
10217
10235
|
|
|
10218
10236
|
// ../runtime/src/child/spawn-child-run-tool.ts
|
|
10219
10237
|
import { Effect as Effect52, Schema as Schema50 } from "effect";
|
|
10220
|
-
import * as Ai11 from "effect/unstable/ai";
|
|
10221
10238
|
var toolName = "spawn_child_run";
|
|
10222
10239
|
var permissionName = "relay.child_run.spawn";
|
|
10223
10240
|
var Input = Schema50.Struct({
|
|
@@ -10238,12 +10255,6 @@ var Output = Schema50.Struct({
|
|
|
10238
10255
|
var TransferInput = Schema50.Struct({
|
|
10239
10256
|
input: Schema50.optionalKey(Schema50.Array(exports_content_schema.Part))
|
|
10240
10257
|
}).annotate({ identifier: "Relay.SpawnChildRunTool.TransferInput" });
|
|
10241
|
-
var aiTool = Ai11.Tool.dynamic(toolName, {
|
|
10242
|
-
description: "Spawn a durable child run and wait for its terminal output.",
|
|
10243
|
-
parameters: Input,
|
|
10244
|
-
success: Output
|
|
10245
|
-
});
|
|
10246
|
-
var jsonValue2 = (value) => Schema50.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
10247
10258
|
var enabled = (agent) => agent.metadata?.multi_agent_enabled === true;
|
|
10248
10259
|
var parentContext = (agent) => ({
|
|
10249
10260
|
...agent.instructions === undefined ? {} : { instructions: agent.instructions },
|
|
@@ -10337,7 +10348,7 @@ var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (co
|
|
|
10337
10348
|
eventSequence: 0,
|
|
10338
10349
|
startedAt: (input.created_at ?? 0) + 2,
|
|
10339
10350
|
completedAt: (input.created_at ?? 0) + 2,
|
|
10340
|
-
|
|
10351
|
+
agentId: config.agentId,
|
|
10341
10352
|
agentDefinitionRevision: config.agentDefinitionRevision,
|
|
10342
10353
|
agentDefinitionSnapshot: definition,
|
|
10343
10354
|
...config.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: config.agentDefinitionToolInputSchemaDigests },
|
|
@@ -10362,11 +10373,10 @@ var resultFromTerminal = Effect52.fn("SpawnChildRunTool.resultFromTerminal")(fun
|
|
|
10362
10373
|
const status = yield* childStatus(wait);
|
|
10363
10374
|
const event = yield* terminalEvent(config.eventLog, wait.executionId, id2);
|
|
10364
10375
|
const output = event?.content ?? [];
|
|
10365
|
-
return
|
|
10376
|
+
return { child_execution_id: id2, status, output };
|
|
10366
10377
|
});
|
|
10367
|
-
var run2 =
|
|
10368
|
-
|
|
10369
|
-
if (fixedPresetName === undefined)
|
|
10378
|
+
var run2 = Effect52.fn("SpawnChildRunTool.run")(function* (config, activeToolName, input, context, enforceStaticOrDynamic) {
|
|
10379
|
+
if (enforceStaticOrDynamic)
|
|
10370
10380
|
yield* ensureStaticOrDynamic(input);
|
|
10371
10381
|
const id2 = childExecutionId(context);
|
|
10372
10382
|
const waitId = childWaitId(id2);
|
|
@@ -10406,44 +10416,36 @@ var run2 = (config, activeToolName = toolName, fixedPresetName) => Effect52.fn("
|
|
|
10406
10416
|
yield* dispatchChild(config, spawn, id2, definition, waitId);
|
|
10407
10417
|
return yield* Effect52.fail(new ToolExecutionWaitRequested({ tool_name: activeToolName, wait_id: waitId }));
|
|
10408
10418
|
});
|
|
10409
|
-
var registeredTool = (config) => ({
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
|
|
10413
|
-
},
|
|
10414
|
-
aiTool,
|
|
10419
|
+
var registeredTool = (config) => tool(toolName, {
|
|
10420
|
+
description: "Spawn a durable child run and wait for its terminal output.",
|
|
10421
|
+
input: Input,
|
|
10422
|
+
output: Output,
|
|
10423
|
+
permissions: [{ name: permissionName, value: true }],
|
|
10415
10424
|
requiredPermissions: [permissionName],
|
|
10416
|
-
|
|
10417
|
-
run: run2(config)
|
|
10425
|
+
metadata: { relay_core_tool: true },
|
|
10426
|
+
run: (input, context) => run2(config, toolName, input, context, true)
|
|
10418
10427
|
});
|
|
10419
10428
|
var transferToolName2 = (name) => `transfer_to_${name.trim().toLowerCase().replaceAll(/[^a-z0-9]+/g, "_").replaceAll(/^_+|_+$/g, "")}`;
|
|
10420
|
-
var transferAiTool = (name) => Ai11.Tool.dynamic(name, {
|
|
10421
|
-
description: "Transfer to a durable child run preset and wait for its terminal output.",
|
|
10422
|
-
parameters: TransferInput,
|
|
10423
|
-
success: Output
|
|
10424
|
-
});
|
|
10425
10429
|
var transferTools = (config) => (config.agent.handoff_targets ?? []).map((target) => {
|
|
10426
10430
|
const name = transferToolName2(target.name);
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
},
|
|
10433
|
-
aiTool: tool,
|
|
10431
|
+
return tool(name, {
|
|
10432
|
+
description: "Transfer to a durable child run preset and wait for its terminal output.",
|
|
10433
|
+
input: TransferInput,
|
|
10434
|
+
output: Output,
|
|
10435
|
+
permissions: [{ name: permissionName, value: true }],
|
|
10434
10436
|
requiredPermissions: [permissionName],
|
|
10435
|
-
|
|
10436
|
-
run: run2(config, name, target.preset_name)
|
|
10437
|
-
};
|
|
10437
|
+
metadata: { relay_core_tool: true, handoff_target: target.name, preset_name: target.preset_name },
|
|
10438
|
+
run: (input, context) => run2(config, name, { preset_name: target.preset_name, input: input.input ?? [] }, context, false)
|
|
10439
|
+
});
|
|
10438
10440
|
});
|
|
10439
10441
|
|
|
10440
10442
|
// ../runtime/src/memory/memory-service.ts
|
|
10441
10443
|
import { Clock as Clock3, Context as Context46, Effect as Effect54, Layer as Layer47, Schema as Schema52 } from "effect";
|
|
10442
|
-
import * as
|
|
10444
|
+
import * as Ai12 from "effect/unstable/ai";
|
|
10443
10445
|
|
|
10444
10446
|
// ../runtime/src/model/embedding-model-service.ts
|
|
10445
10447
|
import { Context as Context45, Effect as Effect53, Layer as Layer46, Ref as Ref13, Schema as Schema51 } from "effect";
|
|
10446
|
-
import * as
|
|
10448
|
+
import * as Ai11 from "effect/unstable/ai";
|
|
10447
10449
|
|
|
10448
10450
|
class EmbeddingModelNotRegistered extends Schema51.TaggedErrorClass()("EmbeddingModelNotRegistered", {
|
|
10449
10451
|
provider: Schema51.String,
|
|
@@ -10482,7 +10484,7 @@ var resolveDefault = (registrations2, options) => {
|
|
|
10482
10484
|
}
|
|
10483
10485
|
return registrations2.length === 1 ? registrations2[0] : undefined;
|
|
10484
10486
|
};
|
|
10485
|
-
var registrationFromLayer2 = (input) =>
|
|
10487
|
+
var registrationFromLayer2 = (input) => Ai11.Model.make(input.provider, input.model, input.layer).captureRequirements.pipe(Effect53.map((layer33) => toRegistration({
|
|
10486
10488
|
provider: input.provider,
|
|
10487
10489
|
model: input.model,
|
|
10488
10490
|
...input.registrationKey === undefined ? {} : { registrationKey: input.registrationKey },
|
|
@@ -10540,12 +10542,12 @@ var deterministicVector = (input, dimensions) => {
|
|
|
10540
10542
|
};
|
|
10541
10543
|
var deterministicLayer = (options = {}) => {
|
|
10542
10544
|
const dimensions = options.dimensions ?? 64;
|
|
10543
|
-
return Layer46.mergeAll(Layer46.effect(
|
|
10545
|
+
return Layer46.mergeAll(Layer46.effect(Ai11.EmbeddingModel.EmbeddingModel, Ai11.EmbeddingModel.make({
|
|
10544
10546
|
embedMany: ({ inputs }) => Effect53.succeed({
|
|
10545
10547
|
results: inputs.map((input) => deterministicVector(input, dimensions)),
|
|
10546
10548
|
usage: { inputTokens: inputs.reduce((total, input) => total + words(input).length, 0) }
|
|
10547
10549
|
})
|
|
10548
|
-
})), Layer46.succeed(
|
|
10550
|
+
})), Layer46.succeed(Ai11.EmbeddingModel.Dimensions, dimensions));
|
|
10549
10551
|
};
|
|
10550
10552
|
var deterministicRegistration = (options = {}) => registrationFromLayer2({
|
|
10551
10553
|
provider: options.provider ?? "test",
|
|
@@ -10575,7 +10577,7 @@ var memoryError = (error) => new exports_memory.MemoryError({
|
|
|
10575
10577
|
message: error instanceof Error ? `${error.name}: ${error.message}` : String(error)
|
|
10576
10578
|
});
|
|
10577
10579
|
var decodeSubject = (subject) => Schema52.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect54.mapError(memoryError));
|
|
10578
|
-
var textPart = (text3) =>
|
|
10580
|
+
var textPart = (text3) => Ai12.Prompt.makePart("text", { text: text3 });
|
|
10579
10581
|
var textFromParts = (parts) => parts.filter((part) => part.type === "text").map((part) => part.text).join(`
|
|
10580
10582
|
`).trim();
|
|
10581
10583
|
var latestUserText = (prompt) => {
|
|
@@ -10638,7 +10640,7 @@ var hashText = (input) => {
|
|
|
10638
10640
|
};
|
|
10639
10641
|
var memoryId = (input, text3) => `memory:${input.key.agent}:${input.key.subject}:${input.turn}:${hashText(`${input.key.agent}\x00${input.key.subject}\x00${input.turn}\x00${text3}`)}`;
|
|
10640
10642
|
var embed = (models, text3, options) => {
|
|
10641
|
-
const program =
|
|
10643
|
+
const program = Ai12.EmbeddingModel.EmbeddingModel.pipe(Effect54.flatMap((model) => model.embed(text3)));
|
|
10642
10644
|
return (options?.embeddingSelection === undefined ? models.provideDefault(program) : models.provide(options.embeddingSelection, program)).pipe(Effect54.mapError(memoryError));
|
|
10643
10645
|
};
|
|
10644
10646
|
var make6 = (options = {}) => Effect54.gen(function* () {
|
|
@@ -10769,11 +10771,11 @@ __export(exports_model_call_policy, {
|
|
|
10769
10771
|
Service: () => Service35
|
|
10770
10772
|
});
|
|
10771
10773
|
import { Context as Context48, Duration as Duration3, Layer as Layer49, Schedule as Schedule3 } from "effect";
|
|
10772
|
-
import * as
|
|
10774
|
+
import * as Ai13 from "effect/unstable/ai";
|
|
10773
10775
|
|
|
10774
10776
|
class Service35 extends Context48.Service()("@relayfx/runtime/ModelCallPolicy") {
|
|
10775
10777
|
}
|
|
10776
|
-
var isOutputValidationError = (error) =>
|
|
10778
|
+
var isOutputValidationError = (error) => Ai13.AiError.isAiError(error) ? error.reason._tag === "InvalidOutputError" : Ai13.AiError.isAiErrorReason(error) && error._tag === "InvalidOutputError";
|
|
10777
10779
|
var defaultClassify2 = (error) => isOutputValidationError(error) ? "terminal" : exports_model_resilience.defaultClassify(error);
|
|
10778
10780
|
var defaultSchedule = Schedule3.exponential(Duration3.seconds(1)).pipe(Schedule3.jittered, Schedule3.both(Schedule3.recurs(4)));
|
|
10779
10781
|
var make7 = (input) => ({
|
|
@@ -11014,7 +11016,7 @@ __export(exports_prompt_assembler_service, {
|
|
|
11014
11016
|
PromptAssemblerError: () => PromptAssemblerError
|
|
11015
11017
|
});
|
|
11016
11018
|
import { Context as Context53, Effect as Effect60, Layer as Layer54, Schema as Schema56 } from "effect";
|
|
11017
|
-
import * as
|
|
11019
|
+
import * as Ai14 from "effect/unstable/ai";
|
|
11018
11020
|
|
|
11019
11021
|
// ../runtime/src/content/artifact-store-service.ts
|
|
11020
11022
|
var exports_artifact_store_service = {};
|
|
@@ -11081,25 +11083,25 @@ class PromptAssemblerError extends Schema56.TaggedErrorClass()("PromptAssemblerE
|
|
|
11081
11083
|
|
|
11082
11084
|
class Service40 extends Context53.Service()("@relayfx/runtime/PromptAssembler") {
|
|
11083
11085
|
}
|
|
11084
|
-
var
|
|
11085
|
-
var stringifyJson = (value) => JSON.stringify(
|
|
11086
|
+
var jsonValue2 = (value) => Schema56.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
11087
|
+
var stringifyJson = (value) => JSON.stringify(jsonValue2(value));
|
|
11086
11088
|
var contentToPromptPart = (part) => {
|
|
11087
11089
|
const options = part.provider_options;
|
|
11088
11090
|
switch (part.type) {
|
|
11089
11091
|
case "text":
|
|
11090
|
-
return
|
|
11092
|
+
return Ai14.Prompt.makePart("text", { text: part.text, ...options === undefined ? {} : { options } });
|
|
11091
11093
|
case "structured":
|
|
11092
|
-
return
|
|
11094
|
+
return Ai14.Prompt.makePart("text", {
|
|
11093
11095
|
text: stringifyJson(part.value),
|
|
11094
11096
|
...options === undefined ? {} : { options }
|
|
11095
11097
|
});
|
|
11096
11098
|
case "tool-call":
|
|
11097
|
-
return
|
|
11099
|
+
return Ai14.Prompt.makePart("text", {
|
|
11098
11100
|
text: stringifyJson(part.call),
|
|
11099
11101
|
...options === undefined ? {} : { options }
|
|
11100
11102
|
});
|
|
11101
11103
|
case "tool-result":
|
|
11102
|
-
return
|
|
11104
|
+
return Ai14.Prompt.makePart("text", {
|
|
11103
11105
|
text: stringifyJson(part.result),
|
|
11104
11106
|
...options === undefined ? {} : { options }
|
|
11105
11107
|
});
|
|
@@ -11109,7 +11111,7 @@ var toAssemblerError = (error) => new PromptAssemblerError({
|
|
|
11109
11111
|
message: error.reason !== undefined ? `${error._tag}: ${error.reason}` : error.message !== undefined ? `${error._tag}: ${error.message}` : error._tag
|
|
11110
11112
|
});
|
|
11111
11113
|
var resolveBlobPart = (blobs, part) => blobs.resolve(part).pipe(Effect60.map((resolved) => [
|
|
11112
|
-
|
|
11114
|
+
Ai14.Prompt.makePart("file", {
|
|
11113
11115
|
mediaType: resolved.mediaType,
|
|
11114
11116
|
data: resolved._tag === "Bytes" ? resolved.bytes : resolved.url,
|
|
11115
11117
|
...resolved.fileName === undefined ? {} : { fileName: resolved.fileName },
|
|
@@ -11140,19 +11142,19 @@ var resolveContentPart = (blobs, artifacts, part) => {
|
|
|
11140
11142
|
return Effect60.succeed([contentToPromptPart(part)]);
|
|
11141
11143
|
}
|
|
11142
11144
|
};
|
|
11143
|
-
var toolSummary = (tools) => tools.map((
|
|
11144
|
-
name:
|
|
11145
|
-
description:
|
|
11146
|
-
permissions:
|
|
11145
|
+
var toolSummary = (tools) => tools.map((tool2) => ({
|
|
11146
|
+
name: tool2.name,
|
|
11147
|
+
description: tool2.description,
|
|
11148
|
+
permissions: tool2.permissions.map((permission) => permission.name)
|
|
11147
11149
|
}));
|
|
11148
11150
|
var defaultSystem = (agent, tools) => [`Agent: ${agent.name}`, agent.instructions ?? "", `Available tools: ${stringifyJson(toolSummary(tools))}`].filter((segment) => segment.length > 0).join(`
|
|
11149
11151
|
|
|
11150
11152
|
`);
|
|
11151
11153
|
var defaultPrompt = (blobs, artifacts, input) => Effect60.forEach(input, (part) => resolveContentPart(blobs, artifacts, part), { concurrency: 1 }).pipe(Effect60.map((parts) => {
|
|
11152
11154
|
const flat = parts.flat();
|
|
11153
|
-
return
|
|
11154
|
-
|
|
11155
|
-
content: flat.length === 0 ? [
|
|
11155
|
+
return Ai14.Prompt.fromMessages([
|
|
11156
|
+
Ai14.Prompt.makeMessage("user", {
|
|
11157
|
+
content: flat.length === 0 ? [Ai14.Prompt.makePart("text", { text: "" })] : flat
|
|
11156
11158
|
})
|
|
11157
11159
|
]);
|
|
11158
11160
|
}));
|
|
@@ -11226,14 +11228,14 @@ var layerFromEpoch = (epoch) => exports_instructions.layer(epoch.baseline.length
|
|
|
11226
11228
|
|
|
11227
11229
|
// ../runtime/src/agent/relay-permissions.ts
|
|
11228
11230
|
import { Clock as Clock6, Effect as Effect62, Equal as Equal2, Layer as Layer56, Option as Option19, Schema as Schema57 } from "effect";
|
|
11229
|
-
var
|
|
11231
|
+
var jsonValue3 = (value) => Schema57.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
|
|
11230
11232
|
var waitIdForToolCall = (toolCallId) => exports_ids_schema.WaitId.make(`wait:permission:${toolCallId}`);
|
|
11231
11233
|
var fallbackToolCallId = (request) => `${request.agentName}:${request.turn}:${request.tool}`;
|
|
11232
11234
|
var tokenFor2 = (request) => waitIdForToolCall(request.toolCallId ?? fallbackToolCallId(request));
|
|
11233
|
-
var matchingRule2 = (rules,
|
|
11235
|
+
var matchingRule2 = (rules, tool2, params) => {
|
|
11234
11236
|
let matched;
|
|
11235
11237
|
for (const rule of rules) {
|
|
11236
|
-
if (exports_permissions.matches(rule.pattern,
|
|
11238
|
+
if (exports_permissions.matches(rule.pattern, tool2, params))
|
|
11237
11239
|
matched = rule;
|
|
11238
11240
|
}
|
|
11239
11241
|
return matched;
|
|
@@ -11293,7 +11295,7 @@ var permissionRequestedEvent = (config, pending, waitId, sequence) => ({
|
|
|
11293
11295
|
tool_call_id: pending.toolCallId ?? pending.token,
|
|
11294
11296
|
tool_name: pending.tool,
|
|
11295
11297
|
wait_id: waitId,
|
|
11296
|
-
input:
|
|
11298
|
+
input: jsonValue3(pending.params),
|
|
11297
11299
|
agent_name: pending.agentName,
|
|
11298
11300
|
scope: config.scope
|
|
11299
11301
|
},
|
|
@@ -11359,7 +11361,7 @@ var createAsk = Effect62.fn("RelayPermissions.createAsk")(function* (config, pen
|
|
|
11359
11361
|
kind: "tool-permission",
|
|
11360
11362
|
tool_call_id: pending.toolCallId ?? pending.token,
|
|
11361
11363
|
tool_name: pending.tool,
|
|
11362
|
-
input:
|
|
11364
|
+
input: jsonValue3(pending.params),
|
|
11363
11365
|
agent_name: pending.agentName,
|
|
11364
11366
|
scope: config.scope
|
|
11365
11367
|
},
|
|
@@ -11409,9 +11411,9 @@ var layer40 = (config) => Layer56.mergeAll(Layer56.succeed(exports_permissions.P
|
|
|
11409
11411
|
|
|
11410
11412
|
// ../runtime/src/agent/relay-steering.ts
|
|
11411
11413
|
import { Clock as Clock7, Effect as Effect63, Layer as Layer57, Schema as Schema58 } from "effect";
|
|
11412
|
-
import * as
|
|
11413
|
-
var
|
|
11414
|
-
var stringifyJson2 = (value) => JSON.stringify(
|
|
11414
|
+
import * as Ai15 from "effect/unstable/ai";
|
|
11415
|
+
var jsonValue4 = (value) => Schema58.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
11416
|
+
var stringifyJson2 = (value) => JSON.stringify(jsonValue4(value));
|
|
11415
11417
|
var createdAtForSequence2 = (config, sequence) => config.startedAt + sequence - config.eventSequence;
|
|
11416
11418
|
var drainId = (config, kind, sequence) => `drain:${config.executionId}:steering:${kind}:sequence:${sequence}`;
|
|
11417
11419
|
var purePromptPart = (part) => {
|
|
@@ -11428,22 +11430,22 @@ var purePromptPart = (part) => {
|
|
|
11428
11430
|
};
|
|
11429
11431
|
var contentToPromptPart2 = (part) => {
|
|
11430
11432
|
const pure = purePromptPart(part);
|
|
11431
|
-
return pure === undefined ?
|
|
11433
|
+
return pure === undefined ? Ai15.Prompt.makePart("text", { text: stringifyJson2(part) }) : contentToPromptPart(pure);
|
|
11432
11434
|
};
|
|
11433
|
-
var promptForContent = (content) =>
|
|
11434
|
-
|
|
11435
|
-
content: content.length === 0 ? [
|
|
11435
|
+
var promptForContent = (content) => Ai15.Prompt.fromMessages([
|
|
11436
|
+
Ai15.Prompt.makeMessage("user", {
|
|
11437
|
+
content: content.length === 0 ? [Ai15.Prompt.makePart("text", { text: "" })] : content.map((part) => contentToPromptPart2(part))
|
|
11436
11438
|
})
|
|
11437
11439
|
]);
|
|
11438
11440
|
var promptTextParts = (prompt) => prompt.content.flatMap((message) => typeof message.content === "string" ? [exports_content_schema.text(message.content)] : message.content.flatMap((part) => part.type === "text" ? [exports_content_schema.text(part.text)] : []));
|
|
11439
11441
|
var contentFromMessage = (message) => {
|
|
11440
11442
|
if (typeof message.prompt === "string")
|
|
11441
11443
|
return [exports_content_schema.text(message.prompt)];
|
|
11442
|
-
const prompt =
|
|
11444
|
+
const prompt = Ai15.Prompt.make(message.prompt);
|
|
11443
11445
|
const textParts = promptTextParts(prompt);
|
|
11444
11446
|
if (textParts.length > 0)
|
|
11445
11447
|
return textParts;
|
|
11446
|
-
return [exports_content_schema.text(stringifyJson2(Schema58.encodeSync(
|
|
11448
|
+
return [exports_content_schema.text(stringifyJson2(Schema58.encodeSync(Ai15.Prompt.Prompt)(prompt)))];
|
|
11447
11449
|
};
|
|
11448
11450
|
var steeringReceivedEvent = (config, kind, drain2, messages, sequence) => ({
|
|
11449
11451
|
id: exports_ids_schema.EventId.make(`event:${drain2.drainId}:received`),
|
|
@@ -11489,7 +11491,7 @@ var layer41 = (config) => Layer57.succeed(exports_steering.Steering, exports_ste
|
|
|
11489
11491
|
|
|
11490
11492
|
// ../runtime/src/agent/relay-tool-executor.ts
|
|
11491
11493
|
import { Effect as Effect64, Layer as Layer58, Option as Option20, Schema as Schema59 } from "effect";
|
|
11492
|
-
var
|
|
11494
|
+
var jsonValue5 = (value) => Schema59.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
11493
11495
|
var errorDetail = (error) => {
|
|
11494
11496
|
switch (error._tag) {
|
|
11495
11497
|
case "ToolNotRegistered":
|
|
@@ -11514,7 +11516,7 @@ var hasRequestedEvent = (config, callId) => config.eventLog.findByCursor({
|
|
|
11514
11516
|
var boundResult = (config, result) => {
|
|
11515
11517
|
if (config.toolOutputMaxBytes === undefined)
|
|
11516
11518
|
return Effect64.succeed(result);
|
|
11517
|
-
return exports_tool_output.bound({ _tag: "Success", result: result.output, encodedResult: result.output }, { toolCallId: result.call_id, maxBytes: config.toolOutputMaxBytes }).pipe(Effect64.map((bounded) => ({ ...result, output:
|
|
11519
|
+
return exports_tool_output.bound({ _tag: "Success", result: result.output, encodedResult: result.output }, { toolCallId: result.call_id, maxBytes: config.toolOutputMaxBytes }).pipe(Effect64.map((bounded) => ({ ...result, output: jsonValue5(bounded.encodedResult) })), Effect64.mapError((error) => new ToolRuntimeError({ message: error.message })));
|
|
11518
11520
|
};
|
|
11519
11521
|
var make10 = (config) => ({
|
|
11520
11522
|
execute: (request) => Effect64.gen(function* () {
|
|
@@ -11522,7 +11524,7 @@ var make10 = (config) => ({
|
|
|
11522
11524
|
const call = {
|
|
11523
11525
|
id: exports_ids_schema.ToolCallId.make(request.call.id),
|
|
11524
11526
|
name: request.call.name,
|
|
11525
|
-
input:
|
|
11527
|
+
input: jsonValue5(request.call.params)
|
|
11526
11528
|
};
|
|
11527
11529
|
const resumed = config.resumedToolCallId === call.id;
|
|
11528
11530
|
const existingRequest = resumed ? yield* hasRequestedEvent(config, call.id) : false;
|
|
@@ -11618,11 +11620,11 @@ class AgentLoopBudgetExceeded extends Schema60.TaggedErrorClass()("AgentLoopBudg
|
|
|
11618
11620
|
|
|
11619
11621
|
class Service41 extends Context54.Service()("@relayfx/runtime/AgentLoop") {
|
|
11620
11622
|
}
|
|
11621
|
-
var
|
|
11623
|
+
var jsonValue6 = (value) => Schema60.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
11622
11624
|
var toolNames = (agent) => HashSet6.fromIterable(agent.tool_names);
|
|
11623
11625
|
var availableRegisteredTools = (agent, registered) => {
|
|
11624
11626
|
const names = toolNames(agent);
|
|
11625
|
-
return registered.filter((
|
|
11627
|
+
return registered.filter((tool2) => tool2.definition.name !== toolName && HashSet6.has(names, tool2.definition.name));
|
|
11626
11628
|
};
|
|
11627
11629
|
var strictToolSchemaDigestConfig = Config3.boolean("RELAY_AGENT_TOOL_SCHEMA_DIGEST_STRICT").pipe(Config3.withDefault(false));
|
|
11628
11630
|
var validateToolInputSchemaDigests = Effect67.fn("AgentLoop.validateToolInputSchemaDigests")(function* (input, definitions2) {
|
|
@@ -11650,7 +11652,7 @@ var validateToolInputSchemaDigests = Effect67.fn("AgentLoop.validateToolInputSch
|
|
|
11650
11652
|
var childRunCoreTools = (input, childRuns, eventLog, waits) => {
|
|
11651
11653
|
if (!enabled(input.agent))
|
|
11652
11654
|
return Effect67.succeed([]);
|
|
11653
|
-
if (input.
|
|
11655
|
+
if (input.agentId === undefined || input.agentDefinitionRevision === undefined || input.dispatchChildRun === undefined) {
|
|
11654
11656
|
return Effect67.fail(new AgentLoopError({
|
|
11655
11657
|
message: "spawn_child_run requires a pinned agent definition and child dispatcher",
|
|
11656
11658
|
next_event_sequence: input.eventSequence + 1
|
|
@@ -11659,7 +11661,7 @@ var childRunCoreTools = (input, childRuns, eventLog, waits) => {
|
|
|
11659
11661
|
return Effect67.succeed([
|
|
11660
11662
|
registeredTool({
|
|
11661
11663
|
agent: input.agent,
|
|
11662
|
-
|
|
11664
|
+
agentId: input.agentId,
|
|
11663
11665
|
agentDefinitionRevision: input.agentDefinitionRevision,
|
|
11664
11666
|
...input.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: input.agentDefinitionToolInputSchemaDigests },
|
|
11665
11667
|
childRuns,
|
|
@@ -11669,7 +11671,7 @@ var childRunCoreTools = (input, childRuns, eventLog, waits) => {
|
|
|
11669
11671
|
}),
|
|
11670
11672
|
...transferTools({
|
|
11671
11673
|
agent: input.agent,
|
|
11672
|
-
|
|
11674
|
+
agentId: input.agentId,
|
|
11673
11675
|
agentDefinitionRevision: input.agentDefinitionRevision,
|
|
11674
11676
|
...input.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: input.agentDefinitionToolInputSchemaDigests },
|
|
11675
11677
|
childRuns,
|
|
@@ -11801,17 +11803,26 @@ var runStructuredTurn = Effect67.fn("AgentLoop.runStructuredTurn")(function* (la
|
|
|
11801
11803
|
schema: registration.schema,
|
|
11802
11804
|
objectName: "output"
|
|
11803
11805
|
})).pipe(Effect67.mapError((error) => error instanceof AgentLoopError ? error : loopError(error, sequence)));
|
|
11804
|
-
return
|
|
11806
|
+
return jsonValue6(response.value);
|
|
11805
11807
|
});
|
|
11806
11808
|
var loopError = (error, nextEventSequence2) => new AgentLoopError({
|
|
11807
11809
|
message: error instanceof Error ? `${error.name}: ${error.message}` : String(error),
|
|
11808
11810
|
next_event_sequence: nextEventSequence2
|
|
11809
11811
|
});
|
|
11810
11812
|
var appendEvent = (eventLog, event, nextEventSequence2) => appendIdempotentTo(eventLog, event).pipe(Effect67.mapError((error) => loopError(error, nextEventSequence2)));
|
|
11811
|
-
var
|
|
11812
|
-
|
|
11813
|
+
var toolFromDefinition = (definition) => dynamicTool(definition.name, {
|
|
11814
|
+
description: definition.description,
|
|
11815
|
+
inputSchema: definition.input_schema,
|
|
11816
|
+
outputSchema: definition.output_schema,
|
|
11817
|
+
permissions: definition.permissions,
|
|
11818
|
+
...definition.requirements === undefined ? {} : { requirements: definition.requirements },
|
|
11819
|
+
...definition.needs_approval === undefined ? {} : { needsApproval: definition.needs_approval },
|
|
11820
|
+
...definition.metadata === undefined ? {} : { metadata: definition.metadata },
|
|
11821
|
+
run: () => Effect67.die("model-facing toolkit is not executed")
|
|
11822
|
+
}).tool;
|
|
11823
|
+
var toolkitFromRegistered = (registered) => Ai16.Toolkit.make(...registered.map(toolFromRegistered));
|
|
11813
11824
|
var persistTranscript = (chats, input, transcript) => Effect67.gen(function* () {
|
|
11814
|
-
const chat = yield*
|
|
11825
|
+
const chat = yield* Ai16.Chat.fromPrompt(transcript);
|
|
11815
11826
|
const exportData = yield* chat.export.pipe(Effect67.mapError((error) => loopError(error, input.eventSequence + 1)));
|
|
11816
11827
|
yield* chats.save({ executionId: input.executionId, exportData, updatedAt: input.completedAt }).pipe(Effect67.mapError((error) => loopError(error, input.eventSequence + 1)));
|
|
11817
11828
|
});
|
|
@@ -11823,7 +11834,7 @@ var restoreHistory = Effect67.fn("AgentLoop.restoreHistory")(function* (chats, i
|
|
|
11823
11834
|
next_event_sequence: input.eventSequence + 1
|
|
11824
11835
|
}));
|
|
11825
11836
|
}
|
|
11826
|
-
const chat = yield*
|
|
11837
|
+
const chat = yield* Ai16.Chat.fromExport(record2.exportData).pipe(Effect67.mapError((error) => loopError(error, input.eventSequence + 1)));
|
|
11827
11838
|
return yield* Ref18.get(chat.history);
|
|
11828
11839
|
});
|
|
11829
11840
|
var saveContextEpoch = Effect67.fn("AgentLoop.saveContextEpoch")(function* (epochs, input, epoch) {
|
|
@@ -11850,7 +11861,7 @@ var mapBatonRunError = (error, current2) => {
|
|
|
11850
11861
|
tool_call: {
|
|
11851
11862
|
id: exports_ids_schema.ToolCallId.make(error.tool_call_id),
|
|
11852
11863
|
name: error.tool_name,
|
|
11853
|
-
input:
|
|
11864
|
+
input: jsonValue6(error.tool_params)
|
|
11854
11865
|
},
|
|
11855
11866
|
next_event_sequence: current2
|
|
11856
11867
|
});
|
|
@@ -11887,9 +11898,9 @@ var terminalMemoryTranscript = (prompt, text3) => {
|
|
|
11887
11898
|
return;
|
|
11888
11899
|
if (promptHasAssistantText(prompt, text3))
|
|
11889
11900
|
return prompt;
|
|
11890
|
-
return
|
|
11901
|
+
return Ai16.Prompt.fromMessages([
|
|
11891
11902
|
...prompt.content,
|
|
11892
|
-
|
|
11903
|
+
Ai16.Prompt.makeMessage("assistant", { content: [Ai16.Prompt.makePart("text", { text: text3 })] })
|
|
11893
11904
|
]);
|
|
11894
11905
|
};
|
|
11895
11906
|
var recallOnlyMemory = (memory) => exports_memory.Memory.of({
|
|
@@ -11936,7 +11947,7 @@ var layer44 = Layer60.effect(Service41, Effect67.gen(function* () {
|
|
|
11936
11947
|
const permissionRules = yield* Effect67.serviceOption(exports_permission_rule_repository.Service);
|
|
11937
11948
|
const steeringRepository = yield* Effect67.serviceOption(exports_steering_repository.Service);
|
|
11938
11949
|
const waits = yield* Effect67.serviceOption(Service25);
|
|
11939
|
-
const tokenizer = yield* Effect67.serviceOption(
|
|
11950
|
+
const tokenizer = yield* Effect67.serviceOption(Ai16.Tokenizer.Tokenizer);
|
|
11940
11951
|
return Service41.of({
|
|
11941
11952
|
run: Effect67.fn("AgentLoop.run")(function* (input) {
|
|
11942
11953
|
const existing = yield* existingOutput(eventLog, input);
|
|
@@ -11948,12 +11959,12 @@ var layer44 = Layer60.effect(Service41, Effect67.gen(function* () {
|
|
|
11948
11959
|
next_event_sequence: input.eventSequence + 1
|
|
11949
11960
|
})) : yield* childRunCoreTools(input, childRuns.value, eventLog, waits.value);
|
|
11950
11961
|
const registered = [...availableRegisteredTools(input.agent, yield* tools.registeredTools), ...coreTools];
|
|
11951
|
-
const definitions2 = registered.map((
|
|
11962
|
+
const definitions2 = registered.map((tool2) => tool2.definition);
|
|
11952
11963
|
yield* validateToolInputSchemaDigests(input, definitions2);
|
|
11953
11964
|
yield* appendEvent(eventLog, inputPreparedEvent(input, definitions2), input.eventSequence + 1);
|
|
11954
11965
|
const toolOutputMaxBytes = yield* effectiveToolOutputMaxBytes(input);
|
|
11955
11966
|
const compactionOptions = yield* effectiveCompactionOptions(input);
|
|
11956
|
-
const runTokenizer = yield* Effect67.serviceOption(
|
|
11967
|
+
const runTokenizer = yield* Effect67.serviceOption(Ai16.Tokenizer.Tokenizer);
|
|
11957
11968
|
const activeTokenizer = Option22.isSome(runTokenizer) ? runTokenizer : tokenizer;
|
|
11958
11969
|
const allocator = yield* make12(input.eventSequence + 1);
|
|
11959
11970
|
const toolkit = toolkitFromRegistered(registered);
|
|
@@ -12132,13 +12143,13 @@ var layer44 = Layer60.effect(Service41, Effect67.gen(function* () {
|
|
|
12132
12143
|
}
|
|
12133
12144
|
});
|
|
12134
12145
|
const runFold = Effect67.gen(function* () {
|
|
12135
|
-
const base = yield*
|
|
12146
|
+
const base = yield* Ai16.LanguageModel.LanguageModel;
|
|
12136
12147
|
const sessionStore = input.sessionId !== undefined && Option22.isSome(sessionRepository) ? yield* make8(input.sessionId, input.sessionEntryScope ?? input.executionId).pipe(Effect67.provideService(exports_session_repository.Service, sessionRepository.value)) : undefined;
|
|
12137
|
-
const folded = exports_agent.stream(agent, batonOptions).pipe(
|
|
12148
|
+
const folded = exports_agent.stream(agent, batonOptions).pipe(Stream7.runFoldEffect(() => ({ text: "", transcript: undefined, turn: undefined, tokensUsed: seededTokens }), foldEvent), Effect67.provideService(Ai16.LanguageModel.LanguageModel, base), Effect67.provideService(exports_model_resilience.ModelResilience, policy), Effect67.provide(executorLayer), Effect67.provide(layer39), Effect67.provide(exports_model_middleware.identityLayer), Effect67.provide(instructionsLayer), Effect67.provide(permissionsLayer), Effect67.provide(steeringLayer));
|
|
12138
12149
|
const withToolOutput = toolOutputStore === undefined ? folded : folded.pipe(Effect67.provideService(exports_tool_output.ToolOutputStore, toolOutputStore));
|
|
12139
12150
|
const withCompaction = compactionService === undefined ? withToolOutput : withToolOutput.pipe(Effect67.provideService(exports_compaction.Compaction, compactionService));
|
|
12140
12151
|
const withSession = sessionStore === undefined ? withCompaction : withCompaction.pipe(Effect67.provideService(exports_session.SessionStore, sessionStore));
|
|
12141
|
-
const withTokenizer = Option22.isNone(activeTokenizer) ? withSession : withSession.pipe(Effect67.provideService(
|
|
12152
|
+
const withTokenizer = Option22.isNone(activeTokenizer) ? withSession : withSession.pipe(Effect67.provideService(Ai16.Tokenizer.Tokenizer, activeTokenizer.value));
|
|
12142
12153
|
return yield* memory !== undefined && Option22.isSome(durableMemory) ? withTokenizer.pipe(Effect67.provideService(exports_memory.Memory, recallOnlyMemory(durableMemory.value))) : withTokenizer;
|
|
12143
12154
|
});
|
|
12144
12155
|
const finalState = yield* languageModels.provideForAgent(input.agent, runFold).pipe(Effect67.catch((error) => allocator.current.pipe(Effect67.flatMap((current2) => Effect67.fail(mapBoundaryError(error, current2))))));
|
|
@@ -12150,7 +12161,7 @@ var layer44 = Layer60.effect(Service41, Effect67.gen(function* () {
|
|
|
12150
12161
|
}
|
|
12151
12162
|
}
|
|
12152
12163
|
const schemaRef = input.agent.output_schema_ref;
|
|
12153
|
-
const structuredOutput = schemaRef === undefined || finalState.transcript === undefined ? undefined : yield*
|
|
12164
|
+
const structuredOutput = schemaRef === undefined || finalState.transcript === undefined ? undefined : yield* Ai16.Chat.fromPrompt(finalState.transcript).pipe(Effect67.flatMap((chat) => runStructuredTurn(languageModels, schemas, chat, input, schemaRef, completedSequence + 1)));
|
|
12154
12165
|
const structuredPart = structuredOutput === undefined || schemaRef === undefined ? [] : [{ type: "structured", value: structuredOutput, schema_ref: schemaRef }];
|
|
12155
12166
|
yield* appendEvent(eventLog, outputCompletedEvent(input, [...completedContent(finalState.text), ...structuredPart], finalState.text, completedSequence, structuredOutput), completedSequence + 1);
|
|
12156
12167
|
return {
|
|
@@ -12362,8 +12373,8 @@ var validateDefinition2 = Effect69.fn("SkillRegistry.validateDefinition")(functi
|
|
|
12362
12373
|
yield* requireOptionalText2(definition.frontmatter.agent, "definition.frontmatter.agent");
|
|
12363
12374
|
yield* requireOptionalText2(definition.frontmatter.model, "definition.frontmatter.model");
|
|
12364
12375
|
yield* requireText2(definition.body, "definition.body");
|
|
12365
|
-
for (const
|
|
12366
|
-
yield* requireText2(
|
|
12376
|
+
for (const tool2 of definition.frontmatter.allowed_tools ?? []) {
|
|
12377
|
+
yield* requireText2(tool2, "definition.frontmatter.allowed_tools[]");
|
|
12367
12378
|
}
|
|
12368
12379
|
for (const path2 of definition.frontmatter.paths ?? []) {
|
|
12369
12380
|
yield* requireText2(path2, "definition.frontmatter.paths[]");
|
|
@@ -12495,7 +12506,7 @@ __export(exports_execution_service, {
|
|
|
12495
12506
|
Service: () => Service44,
|
|
12496
12507
|
ExecutionServiceError: () => ExecutionServiceError
|
|
12497
12508
|
});
|
|
12498
|
-
import { Clock as Clock9, Context as Context57, Effect as Effect70, Layer as Layer63, Option as Option24, Schema as Schema63, Stream as
|
|
12509
|
+
import { Clock as Clock9, Context as Context57, Effect as Effect70, Layer as Layer63, Option as Option24, Schema as Schema63, Stream as Stream8 } from "effect";
|
|
12499
12510
|
import { ShardingConfig } from "effect/unstable/cluster";
|
|
12500
12511
|
class ExecutionServiceError extends Schema63.TaggedErrorClass()("ExecutionServiceError", {
|
|
12501
12512
|
message: Schema63.String,
|
|
@@ -12510,7 +12521,7 @@ var toExecution = (record2) => ({
|
|
|
12510
12521
|
root_address_id: record2.rootAddressId,
|
|
12511
12522
|
...record2.sessionId === undefined ? {} : { session_id: record2.sessionId },
|
|
12512
12523
|
status: record2.status,
|
|
12513
|
-
...record2.
|
|
12524
|
+
...record2.agentId === undefined ? {} : { agent_definition_id: record2.agentId },
|
|
12514
12525
|
...record2.agentDefinitionRevision === undefined ? {} : { agent_definition_revision: record2.agentDefinitionRevision },
|
|
12515
12526
|
...record2.agentDefinitionSnapshot === undefined ? {} : { agent_definition_snapshot: record2.agentDefinitionSnapshot },
|
|
12516
12527
|
...record2.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agent_definition_tool_input_schema_digests: record2.agentDefinitionToolInputSchemaDigests },
|
|
@@ -12524,7 +12535,7 @@ var mapChildRunError2 = (error) => new ExecutionServiceError({ message: error._t
|
|
|
12524
12535
|
var childExecutionId2 = (input) => input.child_execution_id ?? exports_ids_schema.ChildExecutionId.make(`${input.execution_id}:child:${input.address_id}`);
|
|
12525
12536
|
var hasCompleteAgentDefinitionPin2 = (input) => {
|
|
12526
12537
|
const present = [
|
|
12527
|
-
input.
|
|
12538
|
+
input.agentId !== undefined,
|
|
12528
12539
|
input.agentDefinitionRevision !== undefined,
|
|
12529
12540
|
input.agentDefinitionSnapshot !== undefined
|
|
12530
12541
|
];
|
|
@@ -12533,7 +12544,7 @@ var hasCompleteAgentDefinitionPin2 = (input) => {
|
|
|
12533
12544
|
};
|
|
12534
12545
|
var validateAcceptInput = (input) => !hasCompleteAgentDefinitionPin2(input) ? Effect70.fail(new ExecutionServiceError({
|
|
12535
12546
|
message: "agent definition pin must include id, revision, and snapshot together"
|
|
12536
|
-
})) : input.agentDefinitionToolInputSchemaDigests !== undefined && input.
|
|
12547
|
+
})) : input.agentDefinitionToolInputSchemaDigests !== undefined && input.agentId === undefined ? Effect70.fail(new ExecutionServiceError({
|
|
12537
12548
|
message: "agent definition tool input schema digests require a complete agent definition pin"
|
|
12538
12549
|
})) : Effect70.void;
|
|
12539
12550
|
var childContext = (input) => ({
|
|
@@ -12595,7 +12606,7 @@ var acceptedEvent = (input) => ({
|
|
|
12595
12606
|
data: {
|
|
12596
12607
|
root_address_id: input.rootAddressId,
|
|
12597
12608
|
...input.sessionId === undefined ? {} : { session_id: input.sessionId },
|
|
12598
|
-
...input.
|
|
12609
|
+
...input.agentId === undefined ? {} : { agent_definition_id: input.agentId },
|
|
12599
12610
|
...input.agentDefinitionRevision === undefined ? {} : { agent_definition_revision: input.agentDefinitionRevision },
|
|
12600
12611
|
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
12601
12612
|
},
|
|
@@ -12699,7 +12710,7 @@ var layer46 = Layer63.effect(Service44, Effect70.gen(function* () {
|
|
|
12699
12710
|
...input.sessionId === undefined ? {} : { sessionId: input.sessionId },
|
|
12700
12711
|
status: "queued",
|
|
12701
12712
|
createdAt: input.createdAt,
|
|
12702
|
-
...input.
|
|
12713
|
+
...input.agentId === undefined ? {} : { agentId: input.agentId },
|
|
12703
12714
|
...input.agentDefinitionRevision === undefined ? {} : { agentDefinitionRevision: input.agentDefinitionRevision },
|
|
12704
12715
|
...input.agentDefinitionSnapshot === undefined ? {} : { agentDefinitionSnapshot: input.agentDefinitionSnapshot },
|
|
12705
12716
|
...input.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: input.agentDefinitionToolInputSchemaDigests },
|
|
@@ -12791,7 +12802,7 @@ var layer46 = Layer63.effect(Service44, Effect70.gen(function* () {
|
|
|
12791
12802
|
...override === undefined ? {} : { override }
|
|
12792
12803
|
}).pipe(Effect70.mapError(mapChildRunError2));
|
|
12793
12804
|
}),
|
|
12794
|
-
stream: (input) => eventLog.stream(input).pipe(
|
|
12805
|
+
stream: (input) => eventLog.stream(input).pipe(Stream8.take(input.limit ?? 1000), Stream8.mapError((error) => mapEventLogError4(error)))
|
|
12795
12806
|
});
|
|
12796
12807
|
}));
|
|
12797
12808
|
var memoryLayer32 = layer46.pipe(Layer63.provide(layer32), Layer63.provide(exports_execution_repository.memoryLayer), Layer63.provide(exports_session_repository.memoryLayer), Layer63.provide(exports_child_execution_repository.memoryLayer), Layer63.provide(memoryLayer21), Layer63.provide(ShardingConfig.layer({ runnerAddress: Option24.none() })));
|
|
@@ -12816,7 +12827,7 @@ var spawnChildRun = Effect70.fn("ExecutionService.spawnChildRun.call")(function*
|
|
|
12816
12827
|
const service = yield* Service44;
|
|
12817
12828
|
return yield* service.spawnChildRun(input);
|
|
12818
12829
|
});
|
|
12819
|
-
var stream3 = (input) =>
|
|
12830
|
+
var stream3 = (input) => Stream8.unwrap(Service44.pipe(Effect70.map((service) => service.stream(input))));
|
|
12820
12831
|
|
|
12821
12832
|
// ../runtime/src/workspace/workspace-planner-service.ts
|
|
12822
12833
|
import { Context as Context59, Effect as Effect72, HashSet as HashSet7, Layer as Layer65, Option as Option25, Schema as Schema65 } from "effect";
|
|
@@ -13062,7 +13073,7 @@ var StartInput = Schema66.Struct({
|
|
|
13062
13073
|
event_sequence: exports_execution_schema.ExecutionEventSequence,
|
|
13063
13074
|
started_at: exports_shared_schema.TimestampMillis,
|
|
13064
13075
|
completed_at: exports_shared_schema.TimestampMillis,
|
|
13065
|
-
agent_definition_id: Schema66.optionalKey(exports_ids_schema.
|
|
13076
|
+
agent_definition_id: Schema66.optionalKey(exports_ids_schema.AgentId),
|
|
13066
13077
|
agent_definition_revision: Schema66.optionalKey(exports_agent_schema.DefinitionRevision),
|
|
13067
13078
|
agent_definition_snapshot: Schema66.optionalKey(exports_agent_schema.Definition),
|
|
13068
13079
|
agent_definition_tool_input_schema_digests: Schema66.optionalKey(exports_agent_schema.ToolInputSchemaDigests),
|
|
@@ -13227,7 +13238,7 @@ var acceptExecution = (input) => Activity.make({
|
|
|
13227
13238
|
...input.session_id === undefined ? {} : { sessionId: input.session_id },
|
|
13228
13239
|
eventSequence: input.event_sequence,
|
|
13229
13240
|
createdAt: input.started_at,
|
|
13230
|
-
...input.agent_definition_id === undefined ? {} : {
|
|
13241
|
+
...input.agent_definition_id === undefined ? {} : { agentId: input.agent_definition_id },
|
|
13231
13242
|
...input.agent_definition_revision === undefined ? {} : { agentDefinitionRevision: input.agent_definition_revision },
|
|
13232
13243
|
...input.agent_definition_snapshot === undefined ? {} : { agentDefinitionSnapshot: input.agent_definition_snapshot },
|
|
13233
13244
|
...input.agent_definition_tool_input_schema_digests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: input.agent_definition_tool_input_schema_digests },
|
|
@@ -13504,7 +13515,7 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
13504
13515
|
sessionEntryScope: sessionEntryScope(input, turn)
|
|
13505
13516
|
},
|
|
13506
13517
|
agent: input.agent_definition_snapshot,
|
|
13507
|
-
...input.agent_definition_id === undefined ? {} : {
|
|
13518
|
+
...input.agent_definition_id === undefined ? {} : { agentId: input.agent_definition_id },
|
|
13508
13519
|
...input.agent_definition_revision === undefined ? {} : { agentDefinitionRevision: input.agent_definition_revision },
|
|
13509
13520
|
...input.agent_definition_tool_input_schema_digests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: input.agent_definition_tool_input_schema_digests },
|
|
13510
13521
|
input: input.input ?? [],
|
|
@@ -13523,7 +13534,7 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
13523
13534
|
event_sequence: child.eventSequence,
|
|
13524
13535
|
started_at: child.startedAt,
|
|
13525
13536
|
completed_at: child.completedAt,
|
|
13526
|
-
agent_definition_id: child.
|
|
13537
|
+
agent_definition_id: child.agentId,
|
|
13527
13538
|
agent_definition_revision: child.agentDefinitionRevision,
|
|
13528
13539
|
agent_definition_snapshot: child.agentDefinitionSnapshot,
|
|
13529
13540
|
...child.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agent_definition_tool_input_schema_digests: child.agentDefinitionToolInputSchemaDigests },
|
|
@@ -14057,7 +14068,7 @@ __export(exports_runner_runtime_service, {
|
|
|
14057
14068
|
DatabaseMode: () => DatabaseMode,
|
|
14058
14069
|
ClusterConfigMismatch: () => ClusterConfigMismatch
|
|
14059
14070
|
});
|
|
14060
|
-
import { Config as Config5, Context as Context62, Crypto as Crypto4, Duration as Duration5, Effect as Effect77, Layer as Layer69, Option as Option27, Schema as Schema70, Stream as
|
|
14071
|
+
import { Config as Config5, Context as Context62, Crypto as Crypto4, Duration as Duration5, Effect as Effect77, Layer as Layer69, Option as Option27, Schema as Schema70, Stream as Stream9 } from "effect";
|
|
14061
14072
|
import {
|
|
14062
14073
|
ClusterWorkflowEngine,
|
|
14063
14074
|
HttpRunner,
|
|
@@ -14075,7 +14086,7 @@ import { FetchHttpClient } from "effect/unstable/http";
|
|
|
14075
14086
|
import * as SqlClient43 from "effect/unstable/sql/SqlClient";
|
|
14076
14087
|
import { RpcSerialization } from "effect/unstable/rpc";
|
|
14077
14088
|
import { WorkflowEngine } from "effect/unstable/workflow";
|
|
14078
|
-
import * as
|
|
14089
|
+
import * as Ai17 from "effect/unstable/ai";
|
|
14079
14090
|
|
|
14080
14091
|
// ../runtime/src/schedule/scheduler-service.ts
|
|
14081
14092
|
var exports_scheduler_service = {};
|
|
@@ -14501,9 +14512,9 @@ var sqlClientCheckLayer = Layer69.effect(Service49, Effect77.gen(function* () {
|
|
|
14501
14512
|
const checkDatabase = yield* databaseHealthCheck;
|
|
14502
14513
|
return yield* makeClientService(dialect2, checkDatabase);
|
|
14503
14514
|
}));
|
|
14504
|
-
var deterministicTestModelLayer = Layer69.effect(
|
|
14515
|
+
var deterministicTestModelLayer = Layer69.effect(Ai17.LanguageModel.LanguageModel, Ai17.LanguageModel.make({
|
|
14505
14516
|
generateText: () => Effect77.succeed([{ type: "text", text: "deterministic test response" }]),
|
|
14506
|
-
streamText: () =>
|
|
14517
|
+
streamText: () => Stream9.make({ type: "text-delta", id: "text", delta: "deterministic test response" })
|
|
14507
14518
|
}));
|
|
14508
14519
|
var testLanguageModelLayer = layerFromRegistrationEffects3([
|
|
14509
14520
|
registrationFromLayer3({
|
|
@@ -14874,7 +14885,7 @@ var guard = Effect78.fn("ActivityVersionRegistry.guard")(function* (input) {
|
|
|
14874
14885
|
}));
|
|
14875
14886
|
});
|
|
14876
14887
|
// src/client.ts
|
|
14877
|
-
import { Clock as Clock11, Context as Context63, Effect as Effect79, Layer as Layer70, Option as Option28, Schema as Schema72, SchemaGetter, SchemaIssue, Stream as
|
|
14888
|
+
import { Clock as Clock11, Context as Context63, Effect as Effect79, Layer as Layer70, Option as Option28, Schema as Schema72, SchemaGetter, SchemaIssue, Stream as Stream10 } from "effect";
|
|
14878
14889
|
import { EntityId, ShardId, Sharding as Sharding2, ShardingConfig as ShardingConfig3 } from "effect/unstable/cluster";
|
|
14879
14890
|
|
|
14880
14891
|
class ClientError extends Schema72.TaggedErrorClass()("ClientError", {
|
|
@@ -14925,7 +14936,7 @@ var toConversationSummary = (record2) => ({
|
|
|
14925
14936
|
...record2.sessionId === undefined ? {} : { session_id: record2.sessionId },
|
|
14926
14937
|
status: record2.status,
|
|
14927
14938
|
kind: conversationKind(record2.metadata),
|
|
14928
|
-
...record2.
|
|
14939
|
+
...record2.agentId === undefined ? {} : { agent_definition_id: record2.agentId },
|
|
14929
14940
|
metadata: record2.metadata,
|
|
14930
14941
|
created_at: record2.createdAt,
|
|
14931
14942
|
updated_at: record2.updatedAt
|
|
@@ -14935,7 +14946,7 @@ var toExecutionView = (record2) => ({
|
|
|
14935
14946
|
root_address_id: record2.rootAddressId,
|
|
14936
14947
|
...record2.sessionId === undefined ? {} : { session_id: record2.sessionId },
|
|
14937
14948
|
status: record2.status,
|
|
14938
|
-
...record2.
|
|
14949
|
+
...record2.agentId === undefined ? {} : { agent_definition_id: record2.agentId },
|
|
14939
14950
|
...record2.agentDefinitionRevision === undefined ? {} : { agent_definition_revision: record2.agentDefinitionRevision },
|
|
14940
14951
|
...record2.agentDefinitionSnapshot === undefined ? {} : { agent_definition_snapshot: record2.agentDefinitionSnapshot },
|
|
14941
14952
|
...record2.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agent_definition_tool_input_schema_digests: record2.agentDefinitionToolInputSchemaDigests },
|
|
@@ -14962,6 +14973,10 @@ var toSessionSummary = (record2) => ({
|
|
|
14962
14973
|
updated_at: record2.updatedAt
|
|
14963
14974
|
});
|
|
14964
14975
|
var executionIdFromIdempotencyKey = (idempotencyKey) => exports_ids_schema.ExecutionId.make(`execution:${idempotencyKey}`);
|
|
14976
|
+
var agentIdFromSlug = (slug) => exports_ids_schema.AgentId.make(`agent:${slug}`);
|
|
14977
|
+
var addressIdFromSlug = (slug) => exports_ids_schema.AddressId.make(`address:${slug}`);
|
|
14978
|
+
var addressIdFromTarget = (target) => typeof target === "string" ? exports_ids_schema.AddressId.make(target) : target.address_id;
|
|
14979
|
+
var idempotencyKeyFromStart = (addressId, input, now) => input.idempotency_key ?? input.execution_id ?? `${addressId}:${now}`;
|
|
14965
14980
|
var metadataWithIdempotencyKey = (metadata11, idempotencyKey) => ({
|
|
14966
14981
|
...metadata11,
|
|
14967
14982
|
idempotency_key: idempotencyKey
|
|
@@ -15084,11 +15099,11 @@ var parentDefinitionPin = Effect79.fn("Client.parentDefinitionPin")(function* (e
|
|
|
15084
15099
|
if (record2 === undefined) {
|
|
15085
15100
|
return yield* new ClientError({ message: `Execution not found: ${executionId}` });
|
|
15086
15101
|
}
|
|
15087
|
-
if (record2.
|
|
15102
|
+
if (record2.agentId === undefined || record2.agentDefinitionRevision === undefined || record2.agentDefinitionSnapshot === undefined) {
|
|
15088
15103
|
return yield* new ClientError({ message: `Parent execution is not pinned to an agent definition: ${executionId}` });
|
|
15089
15104
|
}
|
|
15090
15105
|
return {
|
|
15091
|
-
|
|
15106
|
+
agentId: record2.agentId,
|
|
15092
15107
|
agentDefinitionRevision: record2.agentDefinitionRevision,
|
|
15093
15108
|
agentDefinitionSnapshot: record2.agentDefinitionSnapshot,
|
|
15094
15109
|
...record2.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agentDefinitionToolInputSchemaDigests: record2.agentDefinitionToolInputSchemaDigests }
|
|
@@ -15101,7 +15116,7 @@ var childStartInput = (input, accepted2, pin, definition, createdAt, parentWaitI
|
|
|
15101
15116
|
event_sequence: 0,
|
|
15102
15117
|
started_at: createdAt,
|
|
15103
15118
|
completed_at: createdAt,
|
|
15104
|
-
agent_definition_id: pin.
|
|
15119
|
+
agent_definition_id: pin.agentId,
|
|
15105
15120
|
agent_definition_revision: pin.agentDefinitionRevision,
|
|
15106
15121
|
agent_definition_snapshot: definition,
|
|
15107
15122
|
...pin.agentDefinitionToolInputSchemaDigests === undefined ? {} : { agent_definition_tool_input_schema_digests: pin.agentDefinitionToolInputSchemaDigests },
|
|
@@ -15302,7 +15317,7 @@ var layerFromRuntime = Layer70.effect(Service50, Effect79.gen(function* () {
|
|
|
15302
15317
|
executionId: input.execution_id,
|
|
15303
15318
|
...input.after_cursor === undefined ? {} : { afterCursor: input.after_cursor },
|
|
15304
15319
|
...input.limit === undefined ? {} : { limit: input.limit }
|
|
15305
|
-
}).pipe(
|
|
15320
|
+
}).pipe(Stream10.mapError(toClientError)),
|
|
15306
15321
|
wake: Effect79.fn("Client.runtime.wake")(function* (input) {
|
|
15307
15322
|
return yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, input);
|
|
15308
15323
|
}),
|
|
@@ -15420,6 +15435,19 @@ var registerAgent = Effect79.fn("Client.registerAgent.call")(function* (input) {
|
|
|
15420
15435
|
const service = yield* Service50;
|
|
15421
15436
|
return yield* service.registerAgent(input);
|
|
15422
15437
|
});
|
|
15438
|
+
var agent = Effect79.fn("Client.agent.call")(function* (slug, input) {
|
|
15439
|
+
const id2 = input.id ?? agentIdFromSlug(slug);
|
|
15440
|
+
const address = input.address ?? addressIdFromSlug(slug);
|
|
15441
|
+
const { id: _id, address: _address, name, permissions, ...definitionInput } = input;
|
|
15442
|
+
const registered = yield* registerAgent({
|
|
15443
|
+
...definitionInput,
|
|
15444
|
+
id: id2,
|
|
15445
|
+
address,
|
|
15446
|
+
name: name ?? slug,
|
|
15447
|
+
permissions: permissions ?? []
|
|
15448
|
+
});
|
|
15449
|
+
return { id: id2, address_id: address, record: registered.record };
|
|
15450
|
+
});
|
|
15423
15451
|
var getAgentDefinition = Effect79.fn("Client.getAgentDefinition.call")(function* (id2) {
|
|
15424
15452
|
const service = yield* Service50;
|
|
15425
15453
|
return yield* service.getAgentDefinition(id2);
|
|
@@ -15468,6 +15496,30 @@ var startExecutionByAgentDefinition = Effect79.fn("Client.startExecutionByAgentD
|
|
|
15468
15496
|
const service = yield* Service50;
|
|
15469
15497
|
return yield* service.startExecutionByAgentDefinition(input);
|
|
15470
15498
|
});
|
|
15499
|
+
var start2 = Effect79.fn("Client.start.call")(function* (target, input = {}) {
|
|
15500
|
+
const addressId = addressIdFromTarget(target);
|
|
15501
|
+
const now = yield* Clock11.currentTimeMillis;
|
|
15502
|
+
const startedAt = input.started_at ?? now;
|
|
15503
|
+
const completedAt = input.completed_at ?? startedAt;
|
|
15504
|
+
const idempotencyKey = idempotencyKeyFromStart(addressId, input, startedAt);
|
|
15505
|
+
return yield* startExecutionByAddress({
|
|
15506
|
+
address_id: addressId,
|
|
15507
|
+
...input.session_id === undefined ? {} : { session_id: input.session_id },
|
|
15508
|
+
...input.input === undefined ? {} : { input: input.input },
|
|
15509
|
+
idempotency_key: idempotencyKey,
|
|
15510
|
+
...input.execution_id === undefined ? {} : { execution_id: input.execution_id },
|
|
15511
|
+
...input.event_sequence === undefined ? {} : { event_sequence: input.event_sequence },
|
|
15512
|
+
started_at: startedAt,
|
|
15513
|
+
completed_at: completedAt,
|
|
15514
|
+
...input.wait_id === undefined ? {} : { wait_id: input.wait_id },
|
|
15515
|
+
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
15516
|
+
});
|
|
15517
|
+
});
|
|
15518
|
+
var run5 = (target, input = {}) => Stream10.unwrap(start2(target, input).pipe(Effect79.map((started) => streamExecution({
|
|
15519
|
+
execution_id: started.execution_id,
|
|
15520
|
+
...input.after_cursor === undefined ? {} : { after_cursor: input.after_cursor },
|
|
15521
|
+
...input.limit === undefined ? {} : { limit: input.limit }
|
|
15522
|
+
}))));
|
|
15471
15523
|
var cancelExecution2 = Effect79.fn("Client.cancelExecution.call")(function* (input) {
|
|
15472
15524
|
const service = yield* Service50;
|
|
15473
15525
|
return yield* service.cancelExecution(input);
|
|
@@ -15512,7 +15564,7 @@ var send3 = Effect79.fn("Client.send.call")(function* (input) {
|
|
|
15512
15564
|
const service = yield* Service50;
|
|
15513
15565
|
return yield* service.send(input);
|
|
15514
15566
|
});
|
|
15515
|
-
var streamExecution = (input) =>
|
|
15567
|
+
var streamExecution = (input) => Stream10.unwrap(Service50.pipe(Effect79.map((service) => service.streamExecution(input))));
|
|
15516
15568
|
var wake2 = Effect79.fn("Client.wake.call")(function* (input) {
|
|
15517
15569
|
const service = yield* Service50;
|
|
15518
15570
|
return yield* service.wake(input);
|
|
@@ -15678,7 +15730,7 @@ var StartExecutionInput = Schema73.Struct({
|
|
|
15678
15730
|
event_sequence: exports_execution_schema.ExecutionEventSequence,
|
|
15679
15731
|
started_at: exports_shared_schema.TimestampMillis,
|
|
15680
15732
|
completed_at: exports_shared_schema.TimestampMillis,
|
|
15681
|
-
agent_definition_id: Schema73.optionalKey(exports_ids_schema.
|
|
15733
|
+
agent_definition_id: Schema73.optionalKey(exports_ids_schema.AgentId),
|
|
15682
15734
|
agent_definition_revision: Schema73.optionalKey(exports_agent_schema.DefinitionRevision),
|
|
15683
15735
|
agent_definition_snapshot: Schema73.optionalKey(exports_agent_schema.Definition),
|
|
15684
15736
|
agent_definition_tool_input_schema_digests: Schema73.optionalKey(exports_agent_schema.ToolInputSchemaDigests),
|
|
@@ -15867,7 +15919,7 @@ var ConversationSummary = Schema73.Struct({
|
|
|
15867
15919
|
session_id: Schema73.optionalKey(exports_ids_schema.SessionId),
|
|
15868
15920
|
status: exports_execution_schema.ExecutionStatus,
|
|
15869
15921
|
kind: ConversationKind,
|
|
15870
|
-
agent_definition_id: Schema73.optionalKey(exports_ids_schema.
|
|
15922
|
+
agent_definition_id: Schema73.optionalKey(exports_ids_schema.AgentId),
|
|
15871
15923
|
metadata: exports_shared_schema.Metadata,
|
|
15872
15924
|
created_at: exports_shared_schema.TimestampMillis,
|
|
15873
15925
|
updated_at: exports_shared_schema.TimestampMillis
|
|
@@ -15969,8 +16021,8 @@ var anthropicClientLayerConfig = Anthropic.AnthropicClient.layerConfig;
|
|
|
15969
16021
|
var withAnthropic = (options) => exports_model_registry.layerFromRegistrationEffects([anthropic(options)]).pipe(Layer72.provide(Anthropic.AnthropicClient.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer72.provide(FetchHttpClient2.layer));
|
|
15970
16022
|
// ../../node_modules/.bun/@batonfx+providers@0.1.1/node_modules/@batonfx/providers/src/deterministic.ts
|
|
15971
16023
|
import * as OpenAi2 from "@effect/ai-openai";
|
|
15972
|
-
import { Effect as Effect81, Layer as Layer74, Option as Option29, Stream as
|
|
15973
|
-
import * as
|
|
16024
|
+
import { Effect as Effect81, Layer as Layer74, Option as Option29, Stream as Stream11 } from "effect";
|
|
16025
|
+
import * as Ai18 from "effect/unstable/ai";
|
|
15974
16026
|
import { FetchHttpClient as FetchHttpClient4 } from "effect/unstable/http";
|
|
15975
16027
|
|
|
15976
16028
|
// ../../node_modules/.bun/@batonfx+providers@0.1.1/node_modules/@batonfx/providers/src/openai.ts
|
|
@@ -15991,9 +16043,9 @@ var openAiClientLayerConfig = OpenAi.OpenAiClient.layerConfig;
|
|
|
15991
16043
|
var withOpenAi = (options) => exports_model_registry.layerFromRegistrationEffects([openAi(options)]).pipe(Layer73.provide(OpenAi.OpenAiClient.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer73.provide(FetchHttpClient3.layer));
|
|
15992
16044
|
|
|
15993
16045
|
// ../../node_modules/.bun/@batonfx+providers@0.1.1/node_modules/@batonfx/providers/src/deterministic.ts
|
|
15994
|
-
var deterministicModelLayer = Layer74.effect(
|
|
16046
|
+
var deterministicModelLayer = Layer74.effect(Ai18.LanguageModel.LanguageModel, Ai18.LanguageModel.make({
|
|
15995
16047
|
generateText: () => Effect81.succeed([{ type: "text", text: "deterministic response" }]),
|
|
15996
|
-
streamText: () =>
|
|
16048
|
+
streamText: () => Stream11.make(Ai18.Response.makePart("text-delta", { id: "text", delta: "deterministic response" }))
|
|
15997
16049
|
}));
|
|
15998
16050
|
var deterministicModel = (input = {}) => exports_model_registry.registrationFromLayer({
|
|
15999
16051
|
provider: input.provider ?? "deterministic",
|