effect-agent 0.1.0-beta.156 → 0.1.0-beta.157
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/{Admin-BjmupLN3.d.mts → Admin-BbTZHSLu.d.mts} +23 -11
- package/dist/{Agent-1DMSO_Fl.mjs → Agent-BMATXYsI.mjs} +9 -2
- package/dist/Agent-BMATXYsI.mjs.map +1 -0
- package/dist/{AgentRuntime-BAjT5gXl.d.mts → AgentRuntime-BPlAn5nA.d.mts} +6 -6
- package/dist/{AgentRuntime-IF_1GoUf.mjs → AgentRuntime-GQACxY_m.mjs} +21 -5
- package/dist/AgentRuntime-GQACxY_m.mjs.map +1 -0
- package/dist/{Digest-CaJ2RIsF.d.mts → Digest-CNHImGy0.d.mts} +2 -2
- package/dist/{DurableAgentRuntime-BQzYkFVy.mjs → DurableAgentRuntime-BAQvZK1e.mjs} +30 -18
- package/dist/DurableAgentRuntime-BAQvZK1e.mjs.map +1 -0
- package/dist/{EventSource-C8CKwQy5.d.mts → EventSource-CETtQTiH.d.mts} +3 -3
- package/dist/InMemory.d.mts +1 -1
- package/dist/{PreparedInputAdmission-CU1PzUVD.d.mts → PreparedInputAdmission-Swp9t800.d.mts} +4 -4
- package/dist/{Records-BrEpibum.d.mts → Records-BxGWRs-t.d.mts} +2 -2
- package/dist/{RunEvent-DV_llBcq.d.mts → RunEvent-D0aepYwN.d.mts} +2 -2
- package/dist/{RunEventSink-D5aVhISG.d.mts → RunEventSink-DsbcGXog.d.mts} +2 -2
- package/dist/{RunOptions-CkRYnlJa.d.mts → RunOptions-GjDlAuKh.d.mts} +5 -2
- package/dist/{Schedule-B_z7PMg-.d.mts → Schedule-B94iS2X3.d.mts} +2 -2
- package/dist/{Subagent-Dld4W1BY.d.mts → Subagent-CLaMeZKu.d.mts} +6 -6
- package/dist/{Subagent-CmFtZaeI.mjs → Subagent-JjcidJ7q.mjs} +2 -2
- package/dist/{Subagent-CmFtZaeI.mjs.map → Subagent-JjcidJ7q.mjs.map} +1 -1
- package/dist/{Subscription-BomcQ9_W.d.mts → Subscription-DaMCppa_.d.mts} +4 -4
- package/dist/{SubscriptionInput-gpZSR9vB.d.mts → SubscriptionInput-B0ZtrQoY.d.mts} +3 -3
- package/dist/{ThreadHistory-ZEu_ja6L.d.mts → ThreadHistory-FD-o4TsR.d.mts} +2 -2
- package/dist/{Usage-Dx0aknfk.d.mts → Usage-BNjPR7Zr.d.mts} +9 -1
- package/dist/{WorkerAdmission-CNbm4o_x.mjs → WorkerAdmission-N9hZV85Q.mjs} +2 -2
- package/dist/{WorkerAdmission-CNbm4o_x.mjs.map → WorkerAdmission-N9hZV85Q.mjs.map} +1 -1
- package/dist/{agent-registration-U3kmV7nW.mjs → agent-registration-BIOzAej4.mjs} +10 -1
- package/dist/agent-registration-BIOzAej4.mjs.map +1 -0
- package/dist/capabilities/Commands.d.mts +1 -1
- package/dist/capabilities/Redaction.d.mts +1 -1
- package/dist/capabilities/RunHooks.d.mts +1 -1
- package/dist/capabilities/Subagent.d.mts +1 -1
- package/dist/capabilities/Subagent.mjs +1 -1
- package/dist/capabilities/ToolDiscovery.d.mts +5 -0
- package/dist/capabilities/ToolDiscovery.mjs +18 -9
- package/dist/capabilities/ToolDiscovery.mjs.map +1 -1
- package/dist/capabilities/WebSearch.d.mts +5 -1
- package/dist/capabilities/WebSearch.mjs +9 -1
- package/dist/capabilities/WebSearch.mjs.map +1 -1
- package/dist/core/Agent.mjs +1 -1
- package/dist/core/RunEvent.d.mts +1 -1
- package/dist/core/Usage.d.mts +1 -1
- package/dist/core/Usage.mjs +22 -1
- package/dist/core/Usage.mjs.map +1 -1
- package/dist/durable/ActivityStore.d.mts +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/AgentRegistration.mjs +1 -1
- package/dist/durable/Certification.d.mts +1 -1
- package/dist/durable/CommittedActivity.d.mts +3 -3
- package/dist/durable/Digest.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +2 -2
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/LifecyclePublication.d.mts +1 -1
- package/dist/durable/LifecyclePublication.mjs +2 -2
- package/dist/durable/LifecyclePublication.mjs.map +1 -1
- package/dist/durable/MessageDelivery.d.mts +4 -4
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +41 -41
- package/dist/durable/PersistentHistory.d.mts +2 -2
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/Records.d.mts +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/RunJournal.d.mts +1 -1
- package/dist/durable/Schedule.d.mts +1 -1
- package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
- package/dist/durable/ScheduleTransition.d.mts +1 -1
- package/dist/durable/Scheduling.d.mts +3 -3
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +2 -2
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionInput.mjs +1 -1
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionTools.d.mts +4 -4
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/Subscriptions.d.mts +6 -6
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
- package/dist/durable/ThreadInvariants.d.mts +2 -2
- package/dist/durable/ThreadProjection.d.mts +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/WorkerAdmission.d.mts +2 -2
- package/dist/durable/WorkerAdmission.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +2 -2
- package/dist/engine/AgentRuntime.d.mts +1 -1
- package/dist/engine/AgentRuntime.mjs +1 -1
- package/dist/engine/RunEventSink.d.mts +1 -1
- package/dist/engine/RunOptions.d.mts +1 -1
- package/dist/engine/RunOptions.mjs +1 -0
- package/dist/engine/RunOptions.mjs.map +1 -1
- package/dist/engine/ThreadHistory.d.mts +1 -1
- package/dist/index.d.mts +15 -15
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/src/capabilities/ToolDiscovery.ts +24 -10
- package/src/capabilities/WebSearch.ts +15 -0
- package/src/core/Agent.ts +16 -2
- package/src/core/Usage.ts +41 -0
- package/src/durable/DurableAgentRuntime.ts +40 -12
- package/src/durable/LifecyclePublication.ts +15 -2
- package/src/durable/internal/agent-registration.ts +11 -0
- package/src/engine/RunOptions.ts +3 -0
- package/src/engine/internal/agent-runtime.ts +68 -5
- package/dist/Agent-1DMSO_Fl.mjs.map +0 -1
- package/dist/AgentRuntime-IF_1GoUf.mjs.map +0 -1
- package/dist/DurableAgentRuntime-BQzYkFVy.mjs.map +0 -1
- package/dist/agent-registration-U3kmV7nW.mjs.map +0 -1
package/src/core/Agent.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type Model,
|
|
7
7
|
type Prompt,
|
|
8
8
|
Tool,
|
|
9
|
-
|
|
9
|
+
Toolkit,
|
|
10
10
|
} from "effect/unstable/ai";
|
|
11
11
|
|
|
12
12
|
import type { AgentInputError, AgentOutputError, AgentRunDispositionError } from "./AgentError.ts";
|
|
@@ -569,9 +569,23 @@ export function make(
|
|
|
569
569
|
completionNames.add(declaration.tool);
|
|
570
570
|
}
|
|
571
571
|
|
|
572
|
+
const tools = Object.values(options.toolkit.tools);
|
|
573
|
+
|
|
574
|
+
const readonlyTools = tools.map((tool) =>
|
|
575
|
+
Tool.isProviderDefined(tool) &&
|
|
576
|
+
!tool.requiresHandler &&
|
|
577
|
+
["web_search", "web_search_preview", "file_search"].includes(tool.providerName)
|
|
578
|
+
? tool.annotate(Tool.Readonly, true)
|
|
579
|
+
: tool,
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
const toolkit = readonlyTools.some((tool, index) => tool !== tools[index])
|
|
583
|
+
? Toolkit.make(...readonlyTools)
|
|
584
|
+
: options.toolkit;
|
|
585
|
+
|
|
572
586
|
return Object.freeze({
|
|
573
587
|
...options,
|
|
574
|
-
toolkit: withUpdateTool(
|
|
588
|
+
toolkit: withUpdateTool(toolkit, options.updates),
|
|
575
589
|
policy: AgentPolicy.resolve(options.policy),
|
|
576
590
|
policyOverrides: Object.freeze({ ...options.policy }),
|
|
577
591
|
toolExposure:
|
package/src/core/Usage.ts
CHANGED
|
@@ -68,6 +68,8 @@ export class ModelCallUsage extends Schema.Class<ModelCallUsage>(
|
|
|
68
68
|
pricingStatus: Schema.optionalKey(Schema.Literals(["estimated", "unknown"])),
|
|
69
69
|
inputTokens: InputTokenUsage,
|
|
70
70
|
outputTokens: OutputTokenUsage,
|
|
71
|
+
/** Observed hosted web searches; excludes OpenAI page/find actions. Absent in legacy records. */
|
|
72
|
+
webSearchCalls: Schema.optionalKey(Schema.Natural),
|
|
71
73
|
costMicrousd: Schema.Natural,
|
|
72
74
|
}) {}
|
|
73
75
|
|
|
@@ -80,6 +82,8 @@ export class RunTotals extends Schema.Class<RunTotals>("@effect-agent/core/RunTo
|
|
|
80
82
|
modelCalls: Schema.Natural,
|
|
81
83
|
inputTokens: Schema.Natural,
|
|
82
84
|
outputTokens: Schema.Natural,
|
|
85
|
+
/** Observed hosted web searches; excludes OpenAI page/find actions. Absent in legacy records. */
|
|
86
|
+
webSearchCalls: Schema.optionalKey(Schema.Natural),
|
|
83
87
|
costMicrousd: Schema.Natural,
|
|
84
88
|
usageStatus: Schema.optionalKey(UsageCompleteness),
|
|
85
89
|
pricingStatus: Schema.optionalKey(UsageCompleteness),
|
|
@@ -104,6 +108,7 @@ export class ChildRunUsage extends Schema.Class<ChildRunUsage>("@effect-agent/co
|
|
|
104
108
|
export const emptyRunTotals = (): RunTotals =>
|
|
105
109
|
RunTotals.make({
|
|
106
110
|
modelCalls: 0,
|
|
111
|
+
webSearchCalls: 0,
|
|
107
112
|
inputTokens: 0,
|
|
108
113
|
outputTokens: 0,
|
|
109
114
|
costMicrousd: 0,
|
|
@@ -133,6 +138,8 @@ export class ModelUsageGroup extends Schema.Class<ModelUsageGroup>(
|
|
|
133
138
|
modelCalls: Schema.Natural.check(Schema.isGreaterThan(0)),
|
|
134
139
|
inputTokens: InputTokenUsage,
|
|
135
140
|
outputTokens: OutputTokenUsage,
|
|
141
|
+
/** Observed hosted web searches; excludes OpenAI page/find actions. Absent in legacy records. */
|
|
142
|
+
webSearchCalls: Schema.optionalKey(Schema.Natural),
|
|
136
143
|
costMicrousd: Schema.Natural,
|
|
137
144
|
}) {}
|
|
138
145
|
|
|
@@ -140,6 +147,8 @@ const RunUsageSummaryFields = Schema.Struct({
|
|
|
140
147
|
modelCalls: Schema.Natural,
|
|
141
148
|
inputTokens: InputTokenUsage,
|
|
142
149
|
outputTokens: OutputTokenUsage,
|
|
150
|
+
/** Observed hosted web searches; excludes OpenAI page/find actions. Absent in legacy records. */
|
|
151
|
+
webSearchCalls: Schema.optionalKey(Schema.Natural),
|
|
143
152
|
costMicrousd: Schema.Natural,
|
|
144
153
|
byModel: Schema.Array(ModelUsageGroup),
|
|
145
154
|
/** Coverage of recorded calls only; interruptions can make the Run less complete. */
|
|
@@ -162,6 +171,11 @@ const RunUsageSummaryFields = Schema.Struct({
|
|
|
162
171
|
|
|
163
172
|
return (
|
|
164
173
|
new Set(identities).size === identities.length &&
|
|
174
|
+
(summary.webSearchCalls === undefined ||
|
|
175
|
+
hasAdditiveTotal(
|
|
176
|
+
summary.webSearchCalls,
|
|
177
|
+
summary.byModel.map((group) => group.webSearchCalls ?? 0),
|
|
178
|
+
)) &&
|
|
165
179
|
hasAdditiveTotal(
|
|
166
180
|
summary.modelCalls,
|
|
167
181
|
summary.byModel.map((group) => group.modelCalls),
|
|
@@ -219,6 +233,7 @@ interface MutableUsageGroup {
|
|
|
219
233
|
readonly serviceTier?: string | undefined;
|
|
220
234
|
readonly pricingVersion?: string | undefined;
|
|
221
235
|
modelCalls: number;
|
|
236
|
+
webSearchCalls: number | undefined;
|
|
222
237
|
inputTokens: {
|
|
223
238
|
total: number;
|
|
224
239
|
uncached: number;
|
|
@@ -267,6 +282,7 @@ export const sumRunTotals = Effect.fn("sumRunTotals")(function* (
|
|
|
267
282
|
contributions: ReadonlyArray<RunTotals>,
|
|
268
283
|
): Effect.fn.Return<RunTotals, UsageAggregationError> {
|
|
269
284
|
let modelCalls = 0;
|
|
285
|
+
let webSearchCalls: number | undefined = 0;
|
|
270
286
|
let inputTokens = 0;
|
|
271
287
|
let outputTokens = 0;
|
|
272
288
|
let costMicrousd = 0;
|
|
@@ -282,6 +298,13 @@ export const sumRunTotals = Effect.fn("sumRunTotals")(function* (
|
|
|
282
298
|
);
|
|
283
299
|
|
|
284
300
|
modelCalls = yield* checkedAdd("modelCalls", modelCalls, value.modelCalls);
|
|
301
|
+
if (value.webSearchCalls === undefined && value.modelCalls > 0) webSearchCalls = undefined;
|
|
302
|
+
else if (webSearchCalls !== undefined)
|
|
303
|
+
webSearchCalls = yield* checkedAdd(
|
|
304
|
+
"webSearchCalls",
|
|
305
|
+
webSearchCalls,
|
|
306
|
+
value.webSearchCalls ?? 0,
|
|
307
|
+
);
|
|
285
308
|
inputTokens = yield* checkedAdd("inputTokens", inputTokens, value.inputTokens);
|
|
286
309
|
outputTokens = yield* checkedAdd("outputTokens", outputTokens, value.outputTokens);
|
|
287
310
|
costMicrousd = yield* checkedAdd("costMicrousd", costMicrousd, value.costMicrousd);
|
|
@@ -316,6 +339,7 @@ export const sumRunTotals = Effect.fn("sumRunTotals")(function* (
|
|
|
316
339
|
|
|
317
340
|
return RunTotals.make({
|
|
318
341
|
modelCalls,
|
|
342
|
+
...(webSearchCalls === undefined ? {} : { webSearchCalls }),
|
|
319
343
|
inputTokens,
|
|
320
344
|
outputTokens,
|
|
321
345
|
costMicrousd,
|
|
@@ -329,6 +353,7 @@ export const sumRunTotals = Effect.fn("sumRunTotals")(function* (
|
|
|
329
353
|
export const runTotalsFromSummary = (summary: RunUsageSummary): RunTotals =>
|
|
330
354
|
RunTotals.make({
|
|
331
355
|
modelCalls: summary.modelCalls,
|
|
356
|
+
...(summary.webSearchCalls === undefined ? {} : { webSearchCalls: summary.webSearchCalls }),
|
|
332
357
|
inputTokens: summary.inputTokens.total,
|
|
333
358
|
outputTokens: summary.outputTokens.total,
|
|
334
359
|
costMicrousd: summary.costMicrousd,
|
|
@@ -363,6 +388,10 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
363
388
|
const outputTokens = initial === undefined ? emptyOutputTokens() : { ...initial.outputTokens };
|
|
364
389
|
const groups = new Map<string, MutableUsageGroup>();
|
|
365
390
|
let modelCalls = initial?.modelCalls ?? 0;
|
|
391
|
+
|
|
392
|
+
let webSearchCalls =
|
|
393
|
+
initial === undefined || initial.modelCalls === 0 ? 0 : initial.webSearchCalls;
|
|
394
|
+
|
|
366
395
|
let costMicrousd = initial?.costMicrousd ?? 0;
|
|
367
396
|
const hasSeedCalls = modelCalls > 0;
|
|
368
397
|
|
|
@@ -387,6 +416,7 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
387
416
|
|
|
388
417
|
groups.set(key, {
|
|
389
418
|
...group,
|
|
419
|
+
webSearchCalls: group.webSearchCalls,
|
|
390
420
|
inputTokens: { ...group.inputTokens },
|
|
391
421
|
outputTokens: { ...group.outputTokens },
|
|
392
422
|
});
|
|
@@ -398,6 +428,10 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
398
428
|
allPricingUnknown &&= call.pricingStatus !== "estimated";
|
|
399
429
|
allPricingComplete &&= call.pricingStatus === "estimated";
|
|
400
430
|
modelCalls = yield* checkedAdd("modelCalls", modelCalls, 1);
|
|
431
|
+
webSearchCalls =
|
|
432
|
+
webSearchCalls === undefined || call.webSearchCalls === undefined
|
|
433
|
+
? undefined
|
|
434
|
+
: yield* checkedAdd("webSearchCalls", webSearchCalls, call.webSearchCalls);
|
|
401
435
|
inputTokens.total = yield* checkedAdd(
|
|
402
436
|
"inputTokens.total",
|
|
403
437
|
inputTokens.total,
|
|
@@ -453,6 +487,7 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
453
487
|
...(call.serviceTier === undefined ? {} : { serviceTier: call.serviceTier }),
|
|
454
488
|
...(call.pricingVersion === undefined ? {} : { pricingVersion: call.pricingVersion }),
|
|
455
489
|
modelCalls: 0,
|
|
490
|
+
webSearchCalls: 0,
|
|
456
491
|
inputTokens: emptyInputTokens(),
|
|
457
492
|
outputTokens: emptyOutputTokens(),
|
|
458
493
|
costMicrousd: 0,
|
|
@@ -460,6 +495,10 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
460
495
|
groups.set(key, group);
|
|
461
496
|
}
|
|
462
497
|
group.modelCalls = yield* checkedAdd("byModel.modelCalls", group.modelCalls, 1);
|
|
498
|
+
group.webSearchCalls =
|
|
499
|
+
group.webSearchCalls === undefined || call.webSearchCalls === undefined
|
|
500
|
+
? undefined
|
|
501
|
+
: yield* checkedAdd("byModel.webSearchCalls", group.webSearchCalls, call.webSearchCalls);
|
|
463
502
|
group.inputTokens.total = yield* checkedAdd(
|
|
464
503
|
"byModel.inputTokens.total",
|
|
465
504
|
group.inputTokens.total,
|
|
@@ -504,6 +543,7 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
504
543
|
|
|
505
544
|
return RunUsageSummary.make({
|
|
506
545
|
modelCalls,
|
|
546
|
+
...(webSearchCalls === undefined ? {} : { webSearchCalls }),
|
|
507
547
|
inputTokens: InputTokenUsage.make(inputTokens),
|
|
508
548
|
outputTokens: OutputTokenUsage.make(outputTokens),
|
|
509
549
|
costMicrousd,
|
|
@@ -520,6 +560,7 @@ export const summarizeModelUsage = Effect.fn("summarizeModelUsage")(function* (
|
|
|
520
560
|
...(group.serviceTier === undefined ? {} : { serviceTier: group.serviceTier }),
|
|
521
561
|
...(group.pricingVersion === undefined ? {} : { pricingVersion: group.pricingVersion }),
|
|
522
562
|
modelCalls: group.modelCalls,
|
|
563
|
+
...(group.webSearchCalls === undefined ? {} : { webSearchCalls: group.webSearchCalls }),
|
|
523
564
|
inputTokens: InputTokenUsage.make(group.inputTokens),
|
|
524
565
|
outputTokens: OutputTokenUsage.make(group.outputTokens),
|
|
525
566
|
costMicrousd: group.costMicrousd,
|
|
@@ -4559,6 +4559,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
4559
4559
|
ctx: AttemptAppendContext,
|
|
4560
4560
|
submission: SubmissionSnapshot,
|
|
4561
4561
|
tokenRef: Ref.Ref<OwnershipToken>,
|
|
4562
|
+
renewAtRef: Ref.Ref<number>,
|
|
4562
4563
|
records: ReadonlyArray<CanonicalRecordEnvelope>,
|
|
4563
4564
|
canonical: Stream.Stream<CanonicalRecordEnvelope, ThreadStoreError | ThreadNotMaterialized>,
|
|
4564
4565
|
canonicalThrough: CanonicalSequence,
|
|
@@ -5258,6 +5259,9 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
5258
5259
|
);
|
|
5259
5260
|
|
|
5260
5261
|
return RunUsageSummary.make({
|
|
5262
|
+
...(legacyCalls === 0 && detailed.webSearchCalls !== undefined
|
|
5263
|
+
? { webSearchCalls: detailed.webSearchCalls }
|
|
5264
|
+
: {}),
|
|
5261
5265
|
modelCalls,
|
|
5262
5266
|
inputTokens: InputTokenUsage.make({
|
|
5263
5267
|
total: inputTokens,
|
|
@@ -7798,18 +7802,33 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
7798
7802
|
// Liveness only: the lease keeps the claim visible; correctness stays with the epoch fence.
|
|
7799
7803
|
// OwnershipLost ends the race and interrupts the Run fiber cleanly.
|
|
7800
7804
|
const renewal = halt(
|
|
7801
|
-
Effect.
|
|
7802
|
-
|
|
7803
|
-
|
|
7805
|
+
Effect.gen(function* () {
|
|
7806
|
+
// Binding selection and preparation consume the acquired lease too. Carry the next
|
|
7807
|
+
// deadline across model continuations; an overdue first renewal must run immediately.
|
|
7808
|
+
const renewAt = yield* Ref.get(renewAtRef);
|
|
7809
|
+
const now = yield* Clock.currentTimeMillis;
|
|
7804
7810
|
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
)
|
|
7811
|
+
yield* Effect.sleep(Math.max(0, renewAt - now));
|
|
7812
|
+
yield* Effect.repeat(
|
|
7813
|
+
Effect.gen(function* () {
|
|
7814
|
+
const ownershipToken = yield* Ref.get(tokenRef);
|
|
7815
|
+
const renewingAt = yield* Clock.currentTimeMillis;
|
|
7816
|
+
|
|
7817
|
+
const renewal = yield* ledger.renewOwnership(
|
|
7818
|
+
RenewOwnershipRequest.make({ submissionId, ownershipToken }),
|
|
7819
|
+
);
|
|
7808
7820
|
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7821
|
+
yield* Ref.set(tokenRef, renewal.ownershipToken);
|
|
7822
|
+
yield* Ref.set(
|
|
7823
|
+
renewAtRef,
|
|
7824
|
+
renewingAt + Duration.toMillis(config.leaseRenewalInterval),
|
|
7825
|
+
);
|
|
7826
|
+
}).pipe(Effect.uninterruptible),
|
|
7827
|
+
{ schedule: Schedule.spaced(config.leaseRenewalInterval) },
|
|
7828
|
+
);
|
|
7829
|
+
|
|
7830
|
+
return yield* Effect.never;
|
|
7831
|
+
}),
|
|
7813
7832
|
);
|
|
7814
7833
|
|
|
7815
7834
|
const execution = Effect.raceFirst(consume, Effect.raceFirst(abortWatcher, renewal));
|
|
@@ -8031,6 +8050,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8031
8050
|
threadId: ThreadId,
|
|
8032
8051
|
claim: Claim,
|
|
8033
8052
|
tokenRef: Ref.Ref<OwnershipToken>,
|
|
8053
|
+
renewAtRef: Ref.Ref<number>,
|
|
8034
8054
|
resumeAfterRetention: () => void,
|
|
8035
8055
|
onHandoff: (nextSubmissionId: SubmissionId) => void,
|
|
8036
8056
|
yieldAfter?: DateTime.Utc,
|
|
@@ -8467,6 +8487,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8467
8487
|
ctx,
|
|
8468
8488
|
submission,
|
|
8469
8489
|
tokenRef,
|
|
8490
|
+
renewAtRef,
|
|
8470
8491
|
currentRecords,
|
|
8471
8492
|
canonical,
|
|
8472
8493
|
tail.tailSequence,
|
|
@@ -8647,6 +8668,8 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8647
8668
|
threadId: ThreadId,
|
|
8648
8669
|
handoff?: ClaimHandoff,
|
|
8649
8670
|
) {
|
|
8671
|
+
const acquiringAt = yield* Clock.currentTimeMillis;
|
|
8672
|
+
|
|
8650
8673
|
const claimed = yield* ledger.claim(
|
|
8651
8674
|
ClaimRequest.make({
|
|
8652
8675
|
threadId,
|
|
@@ -8659,6 +8682,10 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8659
8682
|
const claim = claimed.value;
|
|
8660
8683
|
const tokenRef = yield* Ref.make(claim.ownershipToken);
|
|
8661
8684
|
|
|
8685
|
+
const renewAtRef = yield* Ref.make(
|
|
8686
|
+
acquiringAt + Duration.toMillis(config.leaseRenewalInterval),
|
|
8687
|
+
);
|
|
8688
|
+
|
|
8662
8689
|
yield* Effect.addFinalizer(() =>
|
|
8663
8690
|
Ref.get(tokenRef).pipe(
|
|
8664
8691
|
Effect.flatMap((ownershipToken) =>
|
|
@@ -8681,7 +8708,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8681
8708
|
message: "The submission adapter did not honor the requested handoff",
|
|
8682
8709
|
});
|
|
8683
8710
|
|
|
8684
|
-
return Option.some({ claim, tokenRef });
|
|
8711
|
+
return Option.some({ claim, tokenRef, renewAtRef });
|
|
8685
8712
|
}, Effect.uninterruptible);
|
|
8686
8713
|
|
|
8687
8714
|
const processThreadHead = (
|
|
@@ -8701,7 +8728,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8701
8728
|
const claimed = yield* acquireClaim(threadId, handoff);
|
|
8702
8729
|
|
|
8703
8730
|
if (Option.isNone(claimed)) return Option.none();
|
|
8704
|
-
const { claim, tokenRef } = claimed.value;
|
|
8731
|
+
const { claim, tokenRef, renewAtRef } = claimed.value;
|
|
8705
8732
|
|
|
8706
8733
|
const attributes = {
|
|
8707
8734
|
threadId,
|
|
@@ -8781,6 +8808,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (
|
|
|
8781
8808
|
attemptThreadId,
|
|
8782
8809
|
attemptClaim,
|
|
8783
8810
|
tokenRef,
|
|
8811
|
+
renewAtRef,
|
|
8784
8812
|
() => {
|
|
8785
8813
|
resumeAfterRetention = true;
|
|
8786
8814
|
},
|
|
@@ -146,10 +146,13 @@ export type LifecyclePublicationBatch = typeof LifecyclePublicationBatch.Type;
|
|
|
146
146
|
|
|
147
147
|
/** Native recovery state, independent of Attempts. Hosts serialize drains per storage owner. */
|
|
148
148
|
export interface LifecyclePublicationStorage {
|
|
149
|
-
/** Select up to `limit` due owners, with a bounded pending prefix for each selected owner.
|
|
149
|
+
/** Select up to `limit` due owners, with a bounded pending prefix for each selected owner.
|
|
150
|
+
* `retainedOnly` excludes unmaterialized source facts, for a precommitted start prefix.
|
|
151
|
+
*/
|
|
150
152
|
readonly pending: (
|
|
151
153
|
nowMillis: number,
|
|
152
154
|
limit: number,
|
|
155
|
+
options?: { readonly retainedOnly?: boolean },
|
|
153
156
|
) => Effect.Effect<ReadonlyArray<LifecyclePublicationBatch>, LifecyclePublicationError>;
|
|
154
157
|
/** Atomically acknowledge the exact batch, retaining its identities and fingerprints. */
|
|
155
158
|
readonly acknowledge: (
|
|
@@ -166,6 +169,15 @@ export interface LifecyclePublicationStorage {
|
|
|
166
169
|
timeoutMillis: number,
|
|
167
170
|
) => Effect.Effect<boolean, LifecyclePublicationError>;
|
|
168
171
|
readonly pendingDeadline: Effect.Effect<Option.Option<number>, LifecyclePublicationError>;
|
|
172
|
+
/**
|
|
173
|
+
* Deadline for `pending(..., { retainedOnly: true })`, excluding unmaterialized source facts.
|
|
174
|
+
* Source-backed stores provide this when `pendingDeadline` also includes source intent.
|
|
175
|
+
* Otherwise `pendingDeadline` already describes retained work.
|
|
176
|
+
*/
|
|
177
|
+
readonly retainedPendingDeadline?: Effect.Effect<
|
|
178
|
+
Option.Option<number>,
|
|
179
|
+
LifecyclePublicationError
|
|
180
|
+
>;
|
|
169
181
|
/** Explicit operator retry after repairing a parked owner's destination. */
|
|
170
182
|
readonly retryParked: (
|
|
171
183
|
ownerThreadId: ThreadId,
|
|
@@ -259,9 +271,10 @@ export const drainLifecyclePublications = Effect.fn("LifecyclePublication.drain"
|
|
|
259
271
|
storage: LifecyclePublicationStorage,
|
|
260
272
|
timeoutMillis = 10_000,
|
|
261
273
|
limit = 4,
|
|
274
|
+
options?: { readonly retainedOnly?: boolean },
|
|
262
275
|
) {
|
|
263
276
|
const handler = yield* LifecyclePublicationHandler;
|
|
264
|
-
const pending = yield* storage.pending(yield* Clock.currentTimeMillis, limit);
|
|
277
|
+
const pending = yield* storage.pending(yield* Clock.currentTimeMillis, limit, options);
|
|
265
278
|
|
|
266
279
|
let failures: Cause.Cause<LifecyclePublicationError> = Cause.empty;
|
|
267
280
|
|
|
@@ -111,6 +111,17 @@ export const toolReplayContracts = Effect.fn("AgentRegistration.toolReplayContra
|
|
|
111
111
|
name: tool.name,
|
|
112
112
|
contract: {
|
|
113
113
|
version,
|
|
114
|
+
...(Tool.isProviderDefined(tool)
|
|
115
|
+
? {
|
|
116
|
+
provider: {
|
|
117
|
+
id: tool.id,
|
|
118
|
+
providerName: tool.providerName,
|
|
119
|
+
args: Schema.decodeUnknownSync(Schema.Json)(tool.args ?? null),
|
|
120
|
+
requiresHandler: tool.requiresHandler,
|
|
121
|
+
},
|
|
122
|
+
readonly: Context.get(tool.annotations, Tool.Readonly),
|
|
123
|
+
}
|
|
124
|
+
: {}),
|
|
114
125
|
parameters: jsonSchema(tool.parametersSchema),
|
|
115
126
|
success: jsonSchema(tool.successSchema),
|
|
116
127
|
failure: jsonSchema(tool.failureSchema),
|
package/src/engine/RunOptions.ts
CHANGED
|
@@ -348,6 +348,8 @@ export type RunCostEstimateValue = number | RunCostEstimate;
|
|
|
348
348
|
|
|
349
349
|
/** Model identity presented beside the legacy raw-usage estimator argument. */
|
|
350
350
|
export interface RunCostEstimateRequest {
|
|
351
|
+
/** Observed hosted web search calls, separately billed from tokens. */
|
|
352
|
+
readonly webSearchCalls?: number | undefined;
|
|
351
353
|
readonly provider: string;
|
|
352
354
|
/** Configured binding identity; only response.model identifies the returned model. */
|
|
353
355
|
readonly model: string;
|
|
@@ -816,6 +818,7 @@ export type RunTurnResumeSettledCall = typeof RunTurnResumeSettledCallSchema.Typ
|
|
|
816
818
|
export const RunResumeUsageSchema = Schema.Struct({
|
|
817
819
|
...RunPolicyUsage.fields,
|
|
818
820
|
modelCalls: Schema.Natural,
|
|
821
|
+
webSearchCalls: Schema.optionalKey(Schema.Natural),
|
|
819
822
|
inputTokens: Schema.Natural,
|
|
820
823
|
outputTokens: Schema.Natural,
|
|
821
824
|
lastInputTokens: Schema.Natural,
|
|
@@ -392,6 +392,7 @@ export const AgentResultSchema = <Output extends Schema.Top>(output: Output) =>
|
|
|
392
392
|
const runTotalsOf = (context: RunContext): RunTotals =>
|
|
393
393
|
RunTotals.make({
|
|
394
394
|
modelCalls: context.modelCalls,
|
|
395
|
+
...(context.webSearchCalls === undefined ? {} : { webSearchCalls: context.webSearchCalls }),
|
|
395
396
|
inputTokens: context.inputTokens,
|
|
396
397
|
outputTokens: context.outputTokens,
|
|
397
398
|
costMicrousd: context.costMicrousd,
|
|
@@ -560,6 +561,7 @@ interface RunContext {
|
|
|
560
561
|
usageStatus: typeof UsageCompleteness.Type;
|
|
561
562
|
pricingStatus: typeof UsageCompleteness.Type;
|
|
562
563
|
unobservedModelCalls: number;
|
|
564
|
+
webSearchCalls: number | undefined;
|
|
563
565
|
readonly childUsage: Map<RunId, Effect.Effect<RunUsageReport>>;
|
|
564
566
|
readonly liveChildren: Set<RunId>;
|
|
565
567
|
consecutiveToolFailures: number;
|
|
@@ -1439,6 +1441,7 @@ const decodeResumeUsage = Effect.fn("AgentRuntime.decodeResumeUsage")((input: un
|
|
|
1439
1441
|
"unobservedModelCalls",
|
|
1440
1442
|
"children",
|
|
1441
1443
|
"modelRestarts",
|
|
1444
|
+
"webSearchCalls",
|
|
1442
1445
|
] as const
|
|
1443
1446
|
)
|
|
1444
1447
|
.map((key) => [key, read(key, true)])
|
|
@@ -3310,6 +3313,12 @@ interface ConsumedUsage {
|
|
|
3310
3313
|
readonly modelUsage: ModelCallUsage;
|
|
3311
3314
|
}
|
|
3312
3315
|
|
|
3316
|
+
const isWebSearchAction = Schema.is(
|
|
3317
|
+
Schema.Struct({
|
|
3318
|
+
action: Schema.Struct({ type: Schema.Literal("search") }),
|
|
3319
|
+
}),
|
|
3320
|
+
);
|
|
3321
|
+
|
|
3313
3322
|
const ProviderUsage = Schema.Struct({
|
|
3314
3323
|
inputTokens: Schema.Struct({
|
|
3315
3324
|
uncached: Schema.optional(Schema.Natural),
|
|
@@ -3339,7 +3348,10 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3339
3348
|
toolCallCount: number,
|
|
3340
3349
|
turn: number,
|
|
3341
3350
|
options: RunOptions<HookError, HookRequirements>,
|
|
3342
|
-
response: Pick<
|
|
3351
|
+
response: Pick<
|
|
3352
|
+
RunCostEstimateRequest,
|
|
3353
|
+
"response" | "finishMetadata" | "purpose" | "webSearchCalls"
|
|
3354
|
+
> = {},
|
|
3343
3355
|
): Effect.Effect<
|
|
3344
3356
|
ConsumedUsage,
|
|
3345
3357
|
AgentPolicyError | ModelProtocolError | HookError,
|
|
@@ -3353,6 +3365,8 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3353
3365
|
});
|
|
3354
3366
|
}
|
|
3355
3367
|
|
|
3368
|
+
const webSearchCalls = yield* decodeProviderUsageTotal(response.webSearchCalls ?? 0);
|
|
3369
|
+
|
|
3356
3370
|
const providerUsage = yield* Schema.decodeEffect(ProviderUsage)(usage).pipe(
|
|
3357
3371
|
Effect.mapError(() => invalidProviderUsage()),
|
|
3358
3372
|
);
|
|
@@ -3457,7 +3471,13 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3457
3471
|
const estimate =
|
|
3458
3472
|
options.estimateCostMicrousd === undefined
|
|
3459
3473
|
? 0
|
|
3460
|
-
: yield* options.estimateCostMicrousd(usage, {
|
|
3474
|
+
: yield* options.estimateCostMicrousd(usage, {
|
|
3475
|
+
provider,
|
|
3476
|
+
model,
|
|
3477
|
+
usage,
|
|
3478
|
+
...response,
|
|
3479
|
+
webSearchCalls,
|
|
3480
|
+
});
|
|
3461
3481
|
|
|
3462
3482
|
const costMicrousd = typeof estimate === "number" ? estimate : estimate.costMicrousd;
|
|
3463
3483
|
|
|
@@ -3488,6 +3508,7 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3488
3508
|
}
|
|
3489
3509
|
|
|
3490
3510
|
const modelUsage = ModelCallUsage.make({
|
|
3511
|
+
webSearchCalls,
|
|
3491
3512
|
provider,
|
|
3492
3513
|
model,
|
|
3493
3514
|
...(response.response === undefined
|
|
@@ -3526,6 +3547,11 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3526
3547
|
|
|
3527
3548
|
const modelCalls = yield* decodeProviderUsageTotal(context.modelCalls + 1);
|
|
3528
3549
|
|
|
3550
|
+
const cumulativeWebSearchCalls =
|
|
3551
|
+
context.webSearchCalls === undefined
|
|
3552
|
+
? undefined
|
|
3553
|
+
: yield* decodeProviderUsageTotal(context.webSearchCalls + webSearchCalls);
|
|
3554
|
+
|
|
3529
3555
|
const cumulativeInputTokens = yield* decodeProviderUsageTotal(
|
|
3530
3556
|
context.inputTokens + inputTokens,
|
|
3531
3557
|
);
|
|
@@ -3555,6 +3581,7 @@ const consumeUsage = <AgentValue extends Agent.Any, HookError, HookRequirements>
|
|
|
3555
3581
|
pricingStatus === "estimated" ? "complete" : "unknown",
|
|
3556
3582
|
);
|
|
3557
3583
|
context.modelCalls = modelCalls;
|
|
3584
|
+
context.webSearchCalls = cumulativeWebSearchCalls;
|
|
3558
3585
|
context.inputTokens = cumulativeInputTokens;
|
|
3559
3586
|
context.outputTokens = cumulativeOutputTokens;
|
|
3560
3587
|
context.lastInputTokens = inputTokens;
|
|
@@ -4862,6 +4889,12 @@ const eventsForPart = Effect.fnUntraced(function* <Tools extends Record<string,
|
|
|
4862
4889
|
const toolCallId = yield* decodeToolCallId(part.id);
|
|
4863
4890
|
const tool = tools[part.name] as ToolUnion<Tools>;
|
|
4864
4891
|
|
|
4892
|
+
if (Tool.isProviderDefined(tool) && !tool.requiresHandler && !part.providerExecuted) {
|
|
4893
|
+
return yield* ModelProtocolError.make({
|
|
4894
|
+
message: `Tool ${part.name} must execute at the provider`,
|
|
4895
|
+
});
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4865
4898
|
const decoded = yield* Effect.result(
|
|
4866
4899
|
decodeToolCallParameters<Tools>(tool, part.name, part.params, "model"),
|
|
4867
4900
|
);
|
|
@@ -6216,6 +6249,30 @@ const makeTurn = <
|
|
|
6216
6249
|
return consumeUsage(agent, context, trace.usage, toolCallCount, turn, options, {
|
|
6217
6250
|
response: trace.response,
|
|
6218
6251
|
finishMetadata: trace.finishMetadata,
|
|
6252
|
+
webSearchCalls: new Set(
|
|
6253
|
+
trace.parts.flatMap((part) => {
|
|
6254
|
+
if (
|
|
6255
|
+
(part.type !== "tool-call" && part.type !== "tool-result") ||
|
|
6256
|
+
!part.providerExecuted
|
|
6257
|
+
)
|
|
6258
|
+
return [];
|
|
6259
|
+
const tool = agent.definition.toolkit.tools[part.name];
|
|
6260
|
+
|
|
6261
|
+
if (
|
|
6262
|
+
tool === undefined ||
|
|
6263
|
+
!Tool.isProviderDefined(tool) ||
|
|
6264
|
+
!["web_search", "web_search_preview"].includes(tool.providerName)
|
|
6265
|
+
)
|
|
6266
|
+
return [];
|
|
6267
|
+
|
|
6268
|
+
// OpenAI bills search actions, not opening/finding within returned pages.
|
|
6269
|
+
// Preview tools carry the action on results rather than call parameters.
|
|
6270
|
+
return !tool.id.startsWith("openai.") ||
|
|
6271
|
+
isWebSearchAction(part.type === "tool-call" ? part.params : part.result)
|
|
6272
|
+
? [part.id]
|
|
6273
|
+
: [];
|
|
6274
|
+
}),
|
|
6275
|
+
).size,
|
|
6219
6276
|
purpose: "turn",
|
|
6220
6277
|
}).pipe(
|
|
6221
6278
|
withCallModel,
|
|
@@ -7092,13 +7149,15 @@ const makeTurn = <
|
|
|
7092
7149
|
|
|
7093
7150
|
// Only the model stream is cancellable. It resolves no application Tools and
|
|
7094
7151
|
// closes its waiter before continuation can commit a response or start a Handler.
|
|
7095
|
-
//
|
|
7096
|
-
//
|
|
7152
|
+
// Hosted effects may happen before reporting a part. Only Tools explicitly
|
|
7153
|
+
// annotated Readonly are safe to discard and repeat.
|
|
7097
7154
|
const restartSignal =
|
|
7098
7155
|
policy.restartOnJoinedInput === true &&
|
|
7099
7156
|
context.modelRestarts < 2 &&
|
|
7100
7157
|
(options.durability === undefined || options.durability.commitModelRestart !== undefined) &&
|
|
7101
|
-
!Object.values(modelToolkit.tools).some(
|
|
7158
|
+
!Object.values(modelToolkit.tools).some(
|
|
7159
|
+
(tool) => Tool.isProviderDefined(tool) && !Context.get(tool.annotations, Tool.Readonly),
|
|
7160
|
+
)
|
|
7102
7161
|
? options.input?.awaitJoin
|
|
7103
7162
|
: undefined;
|
|
7104
7163
|
|
|
@@ -8248,6 +8307,10 @@ function streamWithCompletion<
|
|
|
8248
8307
|
// canonical response records so token budgets and the compaction
|
|
8249
8308
|
// trigger keep accounting across ownership changes.
|
|
8250
8309
|
modelCalls: resumeUsage?.modelCalls ?? 0,
|
|
8310
|
+
webSearchCalls:
|
|
8311
|
+
resumeUsage === undefined || resumeUsage.modelCalls === 0
|
|
8312
|
+
? 0
|
|
8313
|
+
: resumeUsage.webSearchCalls,
|
|
8251
8314
|
modelRestarts: resumeUsage?.modelRestarts ?? 0,
|
|
8252
8315
|
usageStatus:
|
|
8253
8316
|
resumeUsage?.usageStatus ?? (resumeUsage === undefined ? "complete" : "unknown"),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Agent-1DMSO_Fl.mjs","names":[],"sources":["../src/core/internal/agent-updates.ts","../src/core/Agent.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { Tool, Toolkit } from \"effect/unstable/ai\";\n\nimport { Emitter, UpdateError } from \"../AgentUpdates.ts\";\n\n/** Definition-owned native Tool. Runtime supplies its handler under the same identity. */\nexport const updateTool = <S extends Schema.Top>(schema: S) =>\n Tool.make(\"emit_update\", {\n description:\n \"Emit a structured intermediate update. Success acknowledges acceptance by this Run; \" +\n \"parent delivery and processing are separate. This does not complete the task.\",\n parameters: Schema.Struct({ value: schema }),\n success: Schema.Struct({ emitted: Schema.Literal(true) }),\n failure: UpdateError,\n failureMode: \"return\",\n }).addDependency(Emitter);\n\nexport type UpdateToolkit<\n T extends Toolkit.Any,\n S extends Schema.Top | undefined,\n> = S extends Schema.Top\n ? Toolkit.Toolkit<T[\"tools\"] & { readonly emit_update: ReturnType<typeof updateTool<S>> }>\n : T;\n\nexport const withUpdateTool = (\n toolkit: Toolkit.Any,\n schema: Schema.Top | undefined,\n): Toolkit.Any => {\n if (schema === undefined) return toolkit;\n if (Object.hasOwn(toolkit.tools, \"emit_update\"))\n throw new TypeError(\"emit_update is reserved for Agent updates\");\n\n return Toolkit.make(...Object.values(toolkit.tools), updateTool(schema));\n};\n","import type { Effect, Layer, Option, Schema } from \"effect\";\nimport * as S from \"effect/Schema\";\nimport {\n type AiError,\n type LanguageModel,\n type Model,\n type Prompt,\n Tool,\n type Toolkit,\n} from \"effect/unstable/ai\";\n\nimport type { AgentInputError, AgentOutputError, AgentRunDispositionError } from \"./AgentError.ts\";\nimport { AgentPolicy, type AgentPolicyInput } from \"./AgentPolicy.ts\";\nimport { AgentId } from \"./Identifiers.ts\";\nimport { type UpdateToolkit, withUpdateTool } from \"./internal/agent-updates.ts\";\nimport type { Configuration } from \"./ToolExposure.ts\";\n\n/** Prompt input produced directly or by an Effect that preserves its failure and requirements. */\nexport type InstructionResult<E = never, R = never> =\n | Prompt.RawInput\n | Effect.Effect<Prompt.RawInput, E, R>;\n\n/** Static prompt input or an input-dependent source evaluated once while preparing a run. */\nexport type InstructionSource<Input, E = never, R = never> =\n | Prompt.RawInput\n | ((input: Input) => InstructionResult<E, R>);\n\n/** Definition-owned projection from decoded Agent input to model-visible prompt content. */\nexport type InputPromptSource<Input, E = never, R = never> = (\n input: Input,\n) => InstructionResult<E, R>;\n\n/** Native services needed to execute and identify model calls. */\nexport type ModelServices = LanguageModel.LanguageModel | Model.ProviderName | Model.ModelName;\n\n/**\n * An optional capability on a provided LanguageModel service. The runtime supplies\n * only model-visible task context and eligible Tool descriptions after validating input.\n * The resolver owns retaining one choice per Thread, including across Runs and\n * recovery; it captures client requirements and returns a closed native Layer\n * that the interpreter acquires for the Run. Context hooks may prepare prompts\n * but cannot replace this model through a per-Turn modelCall.\n * Selection failures remain AiError values and all selector/client services stay in R.\n */\nexport interface ModelResolver extends LanguageModel.LanguageModel {\n readonly resolve: (request: {\n readonly threadId: string;\n readonly state: Schema.JsonObject;\n }) => Effect.Effect<Layer.Layer<ModelServices>, AiError.AiError>;\n}\n\n/** Detect the deferred resolver capability on a trusted, host-provided model service. */\nexport const isModelResolver = (model: LanguageModel.LanguageModel): model is ModelResolver =>\n \"resolve\" in model && typeof model.resolve === \"function\";\n\n/** Accepts native model Layers that provide generation and model identity. */\nexport type NativeModel<ModelValue> =\n ModelValue extends Layer.Layer<infer Provides, never, infer _Requires>\n ? ModelServices extends Provides\n ? ModelValue\n : never\n : never;\n\n/** Definition-owned boundary for selecting and validating an application run disposition. */\nexport interface RunDispositionDeclaration<Output, DispositionSchema extends Schema.Top> {\n /**\n * Opt background workers into one retained assignment. The encoded disposition must be\n * Worker.AssignmentDisposition: completed seals the worker, waiting leaves it steerable.\n * Failures and exhausted Runs seal as failed; aborting an active Run seals as cancelled.\n * The worker origin retains this choice. Omission preserves reusable workers.\n */\n readonly workerLifecycle?: \"assignment\" | undefined;\n /** Canonical Schema used to validate and encode the selected disposition. */\n readonly schema: DispositionSchema;\n /** Pure selection from decoded output. `undefined` declares none, except for assignments. */\n readonly fromOutput: (output: Output) => unknown;\n}\n\n/** Values available to a Definition-owned completion Tool projector after canonical decoding. */\nexport interface CompletionProjectionInput<Parameters = unknown, Result = unknown> {\n readonly parameters: Parameters;\n readonly result: Result;\n}\n\n/**\n * One application Tool whose successful result can complete its owning Agent when it is the\n * only application call. Provider-executed calls may accompany it only with terminal results.\n * Mixed, wholly unexecuted application batches are rejected with failed Tool results so the\n * model can correct them within ordinary Run budgets; completed provider results are retained.\n * Missing provider results and invalid pending resumed batches fail closed. The completion\n * designation never permits side-effect replay.\n */\nexport interface CompletionToolDeclaration<\n Parameters = unknown,\n Result = unknown,\n Output = unknown,\n> {\n readonly tool: string;\n /** Require native Tool use on every model Turn and this Tool for final completion. */\n readonly required?: boolean | undefined;\n readonly project: (input: CompletionProjectionInput<Parameters, Result>) => Output;\n}\n\ntype CompletionToolFor<ToolkitValue extends Toolkit.Any, Output> = {\n readonly [Name in keyof ToolkitValue[\"tools\"] & string]: CompletionToolDeclaration<\n Tool.Parameters<ToolkitValue[\"tools\"][Name]>,\n Tool.Success<ToolkitValue[\"tools\"][Name]>,\n Output\n > & { readonly tool: Name };\n}[keyof ToolkitValue[\"tools\"] & string];\n\n/**\n * An ordinary action Tool whose canonical success may satisfy the whole request.\n * Projectors must be pure and deterministic: recovery re-evaluates them. None preserves\n * ordinary continuation; Some is validated as the Agent output. These Tools must be the sole\n * application call; terminal provider results may accompany them. They never receive the\n * required completion Tool's exhaustion allowance.\n */\nexport interface CompletionFromToolDeclaration<\n Parameters = unknown,\n Result = unknown,\n Output = unknown,\n> {\n readonly tool: string;\n readonly project: (input: CompletionProjectionInput<Parameters, Result>) => Option.Option<Output>;\n}\n\ntype CompletionFromToolFor<ToolkitValue extends Toolkit.Any, Output> = {\n readonly [Name in keyof ToolkitValue[\"tools\"] & string]: CompletionFromToolDeclaration<\n Tool.Parameters<ToolkitValue[\"tools\"][Name]>,\n Tool.Success<ToolkitValue[\"tools\"][Name]>,\n Output\n > & { readonly tool: Name };\n}[keyof ToolkitValue[\"tools\"] & string];\n\n/** Immutable, model-agnostic schemas, behavior, tools, and bounds for an agent. */\nexport interface Definition<\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions,\n ToolkitValue extends Toolkit.Any,\n RunDispositionValue = undefined,\n InputPromptValue = undefined,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n> {\n /** Stable agent identity; changing it creates a distinct definition identity. */\n readonly id: AgentId;\n /** Canonical Schema for intermediate updates emitted by this Agent. */\n readonly updates?: UpdatesSchema;\n /** Canonical schema used to decode and encode run input. */\n readonly input: InputSchema;\n /** Canonical schema used to decode the final model output. */\n readonly output: OutputSchema;\n /**\n * Evaluated once while preparing each Run. OpenAI, xAI and native adapters advertising support\n * preserve chronological system messages, omitting exact repeats only when no distinct system\n * instruction intervenes. The actual selected model determines support on each call. Other\n * adapters group systems first and keep the last exact repeat, including provider options;\n * Anthropic requires an upstream adapter with mid-conversation system-message support.\n * Stored history is unchanged.\n */\n readonly instructions: Instructions;\n /** Optional projection from decoded input to model-visible native Effect AI prompt content. */\n readonly inputPrompt?: InputPromptValue | undefined;\n /** Native Effect AI toolkit whose failures and requirements remain visible. */\n readonly toolkit: ToolkitValue;\n readonly toolExposure?: Configuration | undefined;\n /** Finite execution bounds enforced by the runtime. */\n readonly policy: AgentPolicy;\n /** Explicit policy fields, retained so delegated runs can inherit omitted fields. */\n readonly policyOverrides?: Partial<AgentPolicyInput> | undefined;\n /** Optional successful Tool result that projects directly to the Agent output and settles. */\n readonly completion?: CompletionToolDeclaration | undefined;\n readonly completionFromTools?: ReadonlyArray<CompletionFromToolDeclaration> | undefined;\n readonly runDisposition?: RunDispositionValue | undefined;\n readonly description?: string | undefined;\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n}\n\n/** Options for a model-agnostic agent definition. */\nexport interface DefinitionOptions<\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions extends InstructionSource<InputSchema[\"Type\"], unknown, unknown>,\n ToolkitValue extends Toolkit.Any,\n RunDispositionValue extends\n | RunDispositionDeclaration<OutputSchema[\"Type\"], Schema.Top>\n | undefined = undefined,\n InputPromptValue extends InputPromptSource<InputSchema[\"Type\"], unknown, unknown> | undefined =\n undefined,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n> {\n readonly updates?: UpdatesSchema;\n readonly input: InputSchema;\n readonly output: OutputSchema;\n readonly instructions: Instructions;\n readonly inputPrompt?: InputPromptValue | undefined;\n readonly toolkit: ToolkitValue;\n readonly toolExposure?: Configuration | undefined;\n readonly policy?: Partial<AgentPolicyInput> | undefined;\n readonly completion?: CompletionToolFor<ToolkitValue, OutputSchema[\"Type\"]> | undefined;\n readonly completionFromTools?:\n | ReadonlyArray<CompletionFromToolFor<ToolkitValue, OutputSchema[\"Type\"]>>\n | undefined;\n readonly runDisposition?: RunDispositionValue | undefined;\n readonly description?: string | undefined;\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n}\n\ntype AnyDefinitionShape = Definition<\n Schema.Top,\n Schema.Top,\n unknown,\n Toolkit.Any,\n RunDispositionDeclaration<never, Schema.Top> | undefined,\n unknown,\n Schema.Top | undefined\n>;\n\n/** Immutable pairing of an agent definition with a native model Layer or thread resolver. */\nexport interface Binding<DefinitionValue extends AnyDefinitionShape, ModelValue> {\n readonly definition: DefinitionValue;\n readonly model: NativeModel<ModelValue>;\n}\n\ntype InstructionEffect<Instructions, Input> = Instructions extends (input: Input) => infer Result\n ? Result\n : Instructions;\n\ntype InputPromptEffect<InputPrompt, Input> = InputPrompt extends (input: Input) => infer Result\n ? Result\n : never;\n\ntype EffectError<Value> =\n Value extends Effect.Effect<infer _Success, infer Error, infer _Services> ? Error : never;\n\ntype EffectServices<Value> =\n Value extends Effect.Effect<infer _Success, infer _Error, infer Services> ? Services : never;\n\ntype ModelRequirements<Value> =\n Value extends Layer.Layer<infer _Provides, infer _Error, infer Services> ? Services : never;\n\n/** Constructors and type projections for definitions and runnable model bindings. */\n\n/** Type-erased definition used at generic framework boundaries. */\nexport type AnyDefinition = AnyDefinitionShape;\n\n/** Read-only interpreter program or binding used at inspection and projection boundaries. */\nexport interface Any {\n readonly definition: AnyDefinition;\n readonly model?: unknown;\n}\n\n/** Native Tool configuration for inspection; it does not predict an invocation's outcome. */\nexport const ToolInspection = S.Struct({\n name: S.String,\n failureMode: S.Literals([\"error\", \"return\"]),\n /** False for provider-executed Tools, whose results do not pass through local handlers. */\n requiresHandler: S.Boolean,\n});\n\nexport type ToolInspection = typeof ToolInspection.Type;\n\n/**\n * Inspect registered native Tools in declaration order without acquiring handlers or a Model.\n * This is the full Definition toolkit, before run-specific visibility or exposure filtering.\n * `failureMode` is Effect AI's configured mode, including its `\"error\"` default. Handler-level\n * recovery, programmatic invocation and Subagent containment can change where failures go;\n * consult execution diagnostics for the actual route. No arguments, results or services are read.\n */\nexport const inspectTools = (agent: AnyDefinition | Any): ReadonlyArray<ToolInspection> => {\n const definition = \"definition\" in agent ? agent.definition : agent;\n\n return Object.values(definition.toolkit.tools).map((tool) =>\n ToolInspection.make({\n name: tool.name,\n failureMode: tool.failureMode,\n requiresHandler: !Tool.isProviderDefined(tool) || tool.requiresHandler,\n }),\n );\n};\n\ntype DefinitionOf<AgentValue extends AnyDefinition | Any> = AgentValue extends {\n readonly definition: infer DefinitionValue extends AnyDefinition;\n}\n ? DefinitionValue\n : AgentValue;\n\ntype RunDispositionSchemaOf<DefinitionValue extends AnyDefinition> = [\n Exclude<DefinitionValue[\"runDisposition\"], undefined>,\n] extends [never]\n ? never\n : Exclude<DefinitionValue[\"runDisposition\"], undefined> extends RunDispositionDeclaration<\n never,\n infer DispositionSchema\n >\n ? DispositionSchema\n : never;\n\n/** Literal Agent ID, retained by Agent.make. */\nexport type Name<A extends AnyDefinition | Any> = DefinitionOf<A>[\"id\"] extends AgentId &\n (infer N extends string)\n ? N\n : string;\n\n/** Declared update Schema, or never for Agents without updates. */\nexport type UpdatesSchema<A extends AnyDefinition | Any> = Exclude<\n DefinitionOf<A>[\"updates\"],\n undefined\n>;\n\n/** Decoded intermediate update value. */\nexport type Update<A extends AnyDefinition | Any> = UpdatesSchema<A>[\"Type\"];\n\n/** Decoded input type of a definition or binding. */\nexport type Input<AgentValue extends AnyDefinition | Any> =\n DefinitionOf<AgentValue>[\"input\"][\"Type\"];\n\n/** Encoded input accepted by the primary execution operations. */\nexport type EncodedInput<AgentValue extends AnyDefinition | Any> =\n DefinitionOf<AgentValue>[\"input\"][\"Encoded\"];\n\n/** Decoded output type of a definition or binding. */\nexport type Output<AgentValue extends AnyDefinition | Any> =\n DefinitionOf<AgentValue>[\"output\"][\"Type\"];\n\n/** Input Schema carried by a definition or binding. */\nexport type InputSchema<AgentValue extends AnyDefinition | Any> = DefinitionOf<AgentValue>[\"input\"];\n\n/** Output Schema carried by a definition or binding. */\nexport type OutputSchema<AgentValue extends AnyDefinition | Any> =\n DefinitionOf<AgentValue>[\"output\"];\n\n/** Application run-disposition Schema carried by a definition or binding, or `never`. */\nexport type RunDispositionSchema<AgentValue extends AnyDefinition | Any> = RunDispositionSchemaOf<\n DefinitionOf<AgentValue>\n>;\n\n/** Decoded application run disposition declared by a definition or binding. */\nexport type RunDisposition<AgentValue extends AnyDefinition | Any> = [\n RunDispositionSchema<AgentValue>,\n] extends [never]\n ? never\n : RunDispositionSchema<AgentValue>[\"Type\"];\n\n/** Validation failure admitted only by definitions that declare a run disposition. */\nexport type RunDispositionFailure<AgentValue extends AnyDefinition | Any> = [\n RunDispositionSchemaOf<DefinitionOf<AgentValue>>,\n] extends [never]\n ? never\n : AgentRunDispositionError;\n\n/** Effect AI tool map carried by a definition or binding. */\nexport type Tools<AgentValue extends AnyDefinition | Any> = Toolkit.Tools<\n DefinitionOf<AgentValue>[\"toolkit\"]\n>;\n\ntype ApplicationTools<A extends AnyDefinition> = [UpdatesSchema<A>] extends [never]\n ? Tools<A>\n : Omit<Tools<A>, \"emit_update\">;\n\ntype ToolMapValues<ToolMap extends Record<string, Tool.Any>> = ToolMap extends unknown\n ? ToolMap[keyof ToolMap]\n : never;\n\n/** All possible tools, including keys present in only one definition or binding branch. */\nexport type ToolUnion<AgentValue extends AnyDefinition | Any> = ToolMapValues<Tools<AgentValue>>;\n\n/** Instruction, tool-handler, and Schema services required before a Model is bound. */\nexport type DefinitionRequirements<DefinitionValue extends AnyDefinition> =\n DefinitionValue extends unknown\n ?\n | EffectServices<InstructionEffect<DefinitionValue[\"instructions\"], Input<DefinitionValue>>>\n | EffectServices<InputPromptEffect<DefinitionValue[\"inputPrompt\"], Input<DefinitionValue>>>\n | Tool.HandlersFor<ApplicationTools<DefinitionValue>>\n | Tool.HandlerServices<ToolMapValues<ApplicationTools<DefinitionValue>>>\n // The interpreter canonically re-encodes decoded Tool parameters before recording them.\n | Tool.ParametersSchema<ToolUnion<DefinitionValue>>[\"EncodingServices\"]\n | Tool.SuccessSchema<ToolUnion<DefinitionValue>>[\"DecodingServices\"]\n | DefinitionValue[\"input\"][\"DecodingServices\"]\n | DefinitionValue[\"input\"][\"EncodingServices\"]\n | DefinitionValue[\"output\"][\"DecodingServices\"]\n | DefinitionValue[\"output\"][\"EncodingServices\"]\n | UpdatesSchema<DefinitionValue>[\"DecodingServices\"]\n | UpdatesSchema<DefinitionValue>[\"EncodingServices\"]\n | RunDispositionSchemaOf<DefinitionValue>[\"DecodingServices\"]\n | RunDispositionSchemaOf<DefinitionValue>[\"EncodingServices\"]\n : never;\n\n/** Definition services plus native model services, or a binding's model Layer requirements. */\nexport type Requirements<AgentValue extends AnyDefinition | Any> =\n | DefinitionRequirements<DefinitionOf<AgentValue>>\n | (AgentValue extends { readonly model: infer ModelValue }\n ? ModelRequirements<ModelValue>\n : ModelServices);\n\n// Distribute after unwrapping bindings too: withModel may itself contain a definition union.\ntype DefinitionFailure<DefinitionValue extends AnyDefinition> = DefinitionValue extends unknown\n ?\n | EffectError<InstructionEffect<DefinitionValue[\"instructions\"], Input<DefinitionValue>>>\n | EffectError<InputPromptEffect<DefinitionValue[\"inputPrompt\"], Input<DefinitionValue>>>\n | Tool.HandlerError<ToolUnion<DefinitionValue>>\n : never;\n\n/** Failures from every possible definition, preserving each branch's instruction input type. */\nexport type Failure<AgentValue extends AnyDefinition | Any> =\n | DefinitionFailure<DefinitionOf<AgentValue>>\n | AiError.AiError\n | AgentInputError\n | AgentOutputError\n | RunDispositionFailure<AgentValue>;\n\n/** Validate an agent ID and return a shallowly frozen, model-agnostic definition. */\nexport function make<\n const Name extends string,\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions extends InstructionSource<InputSchema[\"Type\"], unknown, unknown>,\n ToolkitValue extends Toolkit.Any,\n DispositionSchema extends Schema.Top,\n InputPromptValue extends InputPromptSource<InputSchema[\"Type\"], unknown, unknown> | undefined,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n>(\n id: Name,\n options: DefinitionOptions<\n InputSchema,\n OutputSchema,\n Instructions,\n ToolkitValue,\n RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>,\n InputPromptValue,\n UpdatesSchema\n > & {\n readonly runDisposition: RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>;\n readonly inputPrompt: InputPromptValue;\n },\n): Definition<\n InputSchema,\n OutputSchema,\n Instructions,\n UpdateToolkit<ToolkitValue, NoInfer<UpdatesSchema>>,\n RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>,\n InputPromptValue,\n NoInfer<UpdatesSchema>\n> & { readonly id: AgentId & Name };\n\nexport function make<\n const Name extends string,\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions extends InstructionSource<InputSchema[\"Type\"], unknown, unknown>,\n ToolkitValue extends Toolkit.Any,\n DispositionSchema extends Schema.Top,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n>(\n id: Name,\n options: DefinitionOptions<\n InputSchema,\n OutputSchema,\n Instructions,\n ToolkitValue,\n RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>,\n undefined,\n UpdatesSchema\n > & {\n readonly runDisposition: RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>;\n readonly inputPrompt?: undefined;\n },\n): Definition<\n InputSchema,\n OutputSchema,\n Instructions,\n UpdateToolkit<ToolkitValue, NoInfer<UpdatesSchema>>,\n RunDispositionDeclaration<OutputSchema[\"Type\"], DispositionSchema>,\n undefined,\n NoInfer<UpdatesSchema>\n> & { readonly id: AgentId & Name };\n\nexport function make<\n const Name extends string,\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions extends InstructionSource<InputSchema[\"Type\"], unknown, unknown>,\n ToolkitValue extends Toolkit.Any,\n InputPromptValue extends InputPromptSource<InputSchema[\"Type\"], unknown, unknown> | undefined,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n>(\n id: Name,\n options: DefinitionOptions<\n InputSchema,\n OutputSchema,\n Instructions,\n ToolkitValue,\n undefined,\n InputPromptValue,\n UpdatesSchema\n > & {\n readonly inputPrompt: InputPromptValue;\n readonly runDisposition?: undefined;\n },\n): Definition<\n InputSchema,\n OutputSchema,\n Instructions,\n UpdateToolkit<ToolkitValue, NoInfer<UpdatesSchema>>,\n undefined,\n InputPromptValue,\n NoInfer<UpdatesSchema>\n> & { readonly id: AgentId & Name };\n\nexport function make<\n const Name extends string,\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions extends InstructionSource<InputSchema[\"Type\"], unknown, unknown>,\n ToolkitValue extends Toolkit.Any,\n UpdatesSchema extends Schema.Top | undefined = undefined,\n>(\n id: Name,\n options: DefinitionOptions<\n InputSchema,\n OutputSchema,\n Instructions,\n ToolkitValue,\n undefined,\n undefined,\n UpdatesSchema\n > & {\n readonly inputPrompt?: undefined;\n readonly runDisposition?: undefined;\n },\n): Definition<\n InputSchema,\n OutputSchema,\n Instructions,\n UpdateToolkit<ToolkitValue, NoInfer<UpdatesSchema>>,\n undefined,\n undefined,\n NoInfer<UpdatesSchema>\n> & { readonly id: AgentId & Name };\n\nexport function make(\n id: string,\n options: {\n readonly updates?: Schema.Top | undefined;\n readonly input: Schema.Top;\n readonly output: Schema.Top;\n readonly instructions: unknown;\n readonly inputPrompt?: unknown;\n readonly toolkit: Toolkit.Any;\n readonly toolExposure?: Configuration | undefined;\n readonly policy?: Partial<AgentPolicyInput> | undefined;\n readonly completion?: CompletionToolDeclaration | undefined;\n readonly completionFromTools?: ReadonlyArray<CompletionFromToolDeclaration> | undefined;\n readonly runDisposition?: RunDispositionDeclaration<never, Schema.Top> | undefined;\n readonly description?: string | undefined;\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n },\n): AnyDefinition {\n const completionNames = new Set<string>();\n\n for (const declaration of options.completionFromTools ?? []) {\n if (declaration.tool === options.completion?.tool || completionNames.has(declaration.tool)) {\n throw new Error(`Tool ${declaration.tool} has more than one completion declaration`);\n }\n if (!Object.hasOwn(options.toolkit.tools, declaration.tool)) {\n throw new Error(`Unknown completion Tool ${declaration.tool}`);\n }\n completionNames.add(declaration.tool);\n }\n\n return Object.freeze({\n ...options,\n toolkit: withUpdateTool(options.toolkit, options.updates),\n policy: AgentPolicy.resolve(options.policy),\n policyOverrides: Object.freeze({ ...options.policy }),\n toolExposure:\n options.toolExposure === undefined\n ? undefined\n : Object.freeze({\n ...options.toolExposure,\n initialToolNames: Object.freeze([...(options.toolExposure.initialToolNames ?? [])]),\n }),\n id: S.decodeSync(AgentId)(id),\n metadata: options.metadata === undefined ? undefined : Object.freeze({ ...options.metadata }),\n completion:\n options.completion === undefined ? undefined : Object.freeze({ ...options.completion }),\n completionFromTools:\n options.completionFromTools === undefined\n ? undefined\n : Object.freeze(\n options.completionFromTools.map((declaration) => Object.freeze({ ...declaration })),\n ),\n runDisposition:\n options.runDisposition === undefined\n ? undefined\n : Object.freeze({ ...options.runDisposition }),\n });\n}\n\n/** Bind a native model or thread resolver without acquiring or hiding its requirements. */\nexport const withModel = <DefinitionValue extends AnyDefinition, ModelValue>(\n definition: DefinitionValue,\n model: NativeModel<ModelValue>,\n): Binding<DefinitionValue, ModelValue> =>\n Object.freeze({\n definition,\n model,\n });\n"],"mappings":";;;;;;;;;AAMA,MAAa,cAAoC,WAC/C,KAAK,KAAK,eAAe;CACvB,aACE;CAEF,YAAY,OAAO,OAAO,EAAE,OAAO,OAAO,CAAC;CAC3C,SAAS,OAAO,OAAO,EAAE,SAAS,OAAO,QAAQ,IAAI,EAAE,CAAC;CACxD,SAAS;CACT,aAAa;AACf,CAAC,CAAC,CAAC,cAAc,OAAO;AAS1B,MAAa,kBACX,SACA,WACgB;CAChB,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,IAAI,OAAO,OAAO,QAAQ,OAAO,aAAa,GAC5C,MAAM,IAAI,UAAU,2CAA2C;CAEjE,OAAO,QAAQ,KAAK,GAAG,OAAO,OAAO,QAAQ,KAAK,GAAG,WAAW,MAAM,CAAC;AACzE;;;;;;;;;;;ACmBA,MAAa,mBAAmB,UAC9B,aAAa,SAAS,OAAO,MAAM,YAAY;;AAyMjD,MAAa,iBAAiB,EAAE,OAAO;CACrC,MAAM,EAAE;CACR,aAAa,EAAE,SAAS,CAAC,SAAS,QAAQ,CAAC;;CAE3C,iBAAiB,EAAE;AACrB,CAAC;;;;;;;;AAWD,MAAa,gBAAgB,UAA8D;CACzF,MAAM,aAAa,gBAAgB,QAAQ,MAAM,aAAa;CAE9D,OAAO,OAAO,OAAO,WAAW,QAAQ,KAAK,CAAC,CAAC,KAAK,SAClD,eAAe,KAAK;EAClB,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,iBAAiB,CAAC,KAAK,kBAAkB,IAAI,KAAK,KAAK;CACzD,CAAC,CACH;AACF;AAqQA,SAAgB,KACd,IACA,SAee;CACf,MAAM,kCAAkB,IAAI,IAAY;CAExC,KAAK,MAAM,eAAe,QAAQ,uBAAuB,CAAC,GAAG;EAC3D,IAAI,YAAY,SAAS,QAAQ,YAAY,QAAQ,gBAAgB,IAAI,YAAY,IAAI,GACvF,MAAM,IAAI,MAAM,QAAQ,YAAY,KAAK,0CAA0C;EAErF,IAAI,CAAC,OAAO,OAAO,QAAQ,QAAQ,OAAO,YAAY,IAAI,GACxD,MAAM,IAAI,MAAM,2BAA2B,YAAY,MAAM;EAE/D,gBAAgB,IAAI,YAAY,IAAI;CACtC;CAEA,OAAO,OAAO,OAAO;EACnB,GAAG;EACH,SAAS,eAAe,QAAQ,SAAS,QAAQ,OAAO;EACxD,QAAQ,YAAY,QAAQ,QAAQ,MAAM;EAC1C,iBAAiB,OAAO,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC;EACpD,cACE,QAAQ,iBAAiB,KAAA,IACrB,KAAA,IACA,OAAO,OAAO;GACZ,GAAG,QAAQ;GACX,kBAAkB,OAAO,OAAO,CAAC,GAAI,QAAQ,aAAa,oBAAoB,CAAC,CAAE,CAAC;EACpF,CAAC;EACP,IAAI,EAAE,WAAW,OAAO,CAAC,CAAC,EAAE;EAC5B,UAAU,QAAQ,aAAa,KAAA,IAAY,KAAA,IAAY,OAAO,OAAO,EAAE,GAAG,QAAQ,SAAS,CAAC;EAC5F,YACE,QAAQ,eAAe,KAAA,IAAY,KAAA,IAAY,OAAO,OAAO,EAAE,GAAG,QAAQ,WAAW,CAAC;EACxF,qBACE,QAAQ,wBAAwB,KAAA,IAC5B,KAAA,IACA,OAAO,OACL,QAAQ,oBAAoB,KAAK,gBAAgB,OAAO,OAAO,EAAE,GAAG,YAAY,CAAC,CAAC,CACpF;EACN,gBACE,QAAQ,mBAAmB,KAAA,IACvB,KAAA,IACA,OAAO,OAAO,EAAE,GAAG,QAAQ,eAAe,CAAC;CACnD,CAAC;AACH;;AAGA,MAAa,aACX,YACA,UAEA,OAAO,OAAO;CACZ;CACA;AACF,CAAC"}
|