@relayfx/sdk 0.0.45 → 0.0.47
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
CHANGED
|
@@ -3553,6 +3553,7 @@ __export(exports_memory_repository, {
|
|
|
3553
3553
|
query: () => query,
|
|
3554
3554
|
memoryLayer: () => memoryLayer11,
|
|
3555
3555
|
layer: () => layer13,
|
|
3556
|
+
forget: () => forget,
|
|
3556
3557
|
Service: () => Service14,
|
|
3557
3558
|
MemoryRow: () => MemoryRow,
|
|
3558
3559
|
MemoryRepositoryError: () => MemoryRepositoryError
|
|
@@ -3721,7 +3722,17 @@ var layer13 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
|
3721
3722
|
const decoded = yield* Effect14.forEach(rows, decodeRow9);
|
|
3722
3723
|
return yield* rankMatches(decoded.map(toRecord7), input.embedding, input.topK);
|
|
3723
3724
|
});
|
|
3724
|
-
|
|
3725
|
+
const forget = Effect14.fn("MemoryRepository.forget")(function* (input) {
|
|
3726
|
+
const tenantId = yield* current();
|
|
3727
|
+
yield* (input.id === undefined ? sql2`
|
|
3728
|
+
DELETE FROM relay_memory_records
|
|
3729
|
+
WHERE tenant_id = ${tenantId} AND agent = ${input.agent} AND subject = ${input.subject}
|
|
3730
|
+
` : sql2`
|
|
3731
|
+
DELETE FROM relay_memory_records
|
|
3732
|
+
WHERE tenant_id = ${tenantId} AND agent = ${input.agent} AND subject = ${input.subject} AND id = ${input.id}
|
|
3733
|
+
`).pipe(Effect14.asVoid, Effect14.mapError(toRepositoryError10));
|
|
3734
|
+
});
|
|
3735
|
+
return Service14.of({ upsert: upsert2, query, forget });
|
|
3725
3736
|
}));
|
|
3726
3737
|
var memoryLayer11 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
3727
3738
|
const records = yield* Ref2.make(new Map);
|
|
@@ -3751,7 +3762,20 @@ var memoryLayer11 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
|
3751
3762
|
const scoped = Array.from(current2.values()).filter((record2) => record2.agent === input.agent && record2.subject === input.subject).map(cloneRecord4);
|
|
3752
3763
|
return yield* rankMatches(scoped, input.embedding, input.topK);
|
|
3753
3764
|
});
|
|
3754
|
-
|
|
3765
|
+
const forget = Effect14.fn("MemoryRepository.memory.forget")(function* (input) {
|
|
3766
|
+
yield* Ref2.update(records, (current2) => {
|
|
3767
|
+
const next = new Map(current2);
|
|
3768
|
+
for (const [id2, record2] of current2) {
|
|
3769
|
+
if (record2.agent !== input.agent || record2.subject !== input.subject)
|
|
3770
|
+
continue;
|
|
3771
|
+
if (input.id !== undefined && id2 !== input.id)
|
|
3772
|
+
continue;
|
|
3773
|
+
next.delete(id2);
|
|
3774
|
+
}
|
|
3775
|
+
return next;
|
|
3776
|
+
});
|
|
3777
|
+
});
|
|
3778
|
+
return Service14.of({ upsert: upsert2, query, forget });
|
|
3755
3779
|
}));
|
|
3756
3780
|
var testLayer11 = (implementation) => Layer14.succeed(Service14, Service14.of(implementation));
|
|
3757
3781
|
var upsert2 = Effect14.fn("MemoryRepository.upsert.call")(function* (input) {
|
|
@@ -3762,6 +3786,10 @@ var query = Effect14.fn("MemoryRepository.query.call")(function* (input) {
|
|
|
3762
3786
|
const repository = yield* Service14;
|
|
3763
3787
|
return yield* repository.query(input);
|
|
3764
3788
|
});
|
|
3789
|
+
var forget = Effect14.fn("MemoryRepository.forget.call")(function* (input) {
|
|
3790
|
+
const repository = yield* Service14;
|
|
3791
|
+
return yield* repository.forget(input);
|
|
3792
|
+
});
|
|
3765
3793
|
// ../store-sql/src/permission/permission-rule-repository.ts
|
|
3766
3794
|
var exports_permission_rule_repository = {};
|
|
3767
3795
|
__export(exports_permission_rule_repository, {
|
|
@@ -8453,7 +8481,7 @@ __export(exports_agent_loop_service, {
|
|
|
8453
8481
|
AgentLoopBudgetExceeded: () => AgentLoopBudgetExceeded
|
|
8454
8482
|
});
|
|
8455
8483
|
|
|
8456
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8484
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent.ts
|
|
8457
8485
|
var exports_agent = {};
|
|
8458
8486
|
__export(exports_agent, {
|
|
8459
8487
|
streamObject: () => streamObject,
|
|
@@ -8463,10 +8491,10 @@ __export(exports_agent, {
|
|
|
8463
8491
|
generate: () => generate,
|
|
8464
8492
|
defaultObjectPrompt: () => defaultObjectPrompt
|
|
8465
8493
|
});
|
|
8466
|
-
import { Cause as Cause3, Effect as
|
|
8467
|
-
import { Chat, LanguageModel as
|
|
8494
|
+
import { Cause as Cause3, Effect as Effect46, Fiber, Option as Option16, Queue as Queue2, Ref as Ref11, Schema as Schema48, Stream as Stream7 } from "effect";
|
|
8495
|
+
import { Chat, LanguageModel as LanguageModel4, Prompt as Prompt4, Response as Response3, Telemetry, Tokenizer as Tokenizer2, Tool as Tool4, Toolkit as Toolkit3 } from "effect/unstable/ai";
|
|
8468
8496
|
|
|
8469
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8497
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent-event.ts
|
|
8470
8498
|
var exports_agent_event = {};
|
|
8471
8499
|
__export(exports_agent_event, {
|
|
8472
8500
|
addUsage: () => addUsage,
|
|
@@ -8523,7 +8551,7 @@ class AgentSuspended extends Schema38.TaggedErrorClass()("@batonfx/core/AgentSus
|
|
|
8523
8551
|
}) {
|
|
8524
8552
|
}
|
|
8525
8553
|
|
|
8526
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8554
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/approvals.ts
|
|
8527
8555
|
var exports_approvals = {};
|
|
8528
8556
|
__export(exports_approvals, {
|
|
8529
8557
|
testLayer: () => testLayer26,
|
|
@@ -8539,7 +8567,7 @@ var autoApprove = Layer29.succeed(Approvals, Approvals.of({ check: () => Effect3
|
|
|
8539
8567
|
var denyAll = Layer29.succeed(Approvals, Approvals.of({ check: () => Effect31.succeed({ _tag: "Denied" }) }));
|
|
8540
8568
|
var testLayer26 = (implementation) => Layer29.succeed(Approvals, Approvals.of(implementation));
|
|
8541
8569
|
|
|
8542
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8570
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/compaction.ts
|
|
8543
8571
|
var exports_compaction = {};
|
|
8544
8572
|
__export(exports_compaction, {
|
|
8545
8573
|
truncate: () => truncate,
|
|
@@ -8557,7 +8585,7 @@ __export(exports_compaction, {
|
|
|
8557
8585
|
import { Context as Context32, Effect as Effect34, Layer as Layer32, Option as Option10, Schema as Schema41 } from "effect";
|
|
8558
8586
|
import { LanguageModel, Prompt as Prompt3, Tokenizer, Toolkit as Toolkit2 } from "effect/unstable/ai";
|
|
8559
8587
|
|
|
8560
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8588
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/session.ts
|
|
8561
8589
|
var exports_session = {};
|
|
8562
8590
|
__export(exports_session, {
|
|
8563
8591
|
testLayer: () => testLayer27,
|
|
@@ -8730,7 +8758,7 @@ var memoryLayer24 = Layer30.effect(SessionStore, Ref7.make(initialState).pipe(Ef
|
|
|
8730
8758
|
}))));
|
|
8731
8759
|
var testLayer27 = (implementation) => Layer30.succeed(SessionStore, SessionStore.of(implementation));
|
|
8732
8760
|
|
|
8733
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8761
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-output.ts
|
|
8734
8762
|
var exports_tool_output = {};
|
|
8735
8763
|
__export(exports_tool_output, {
|
|
8736
8764
|
testLayer: () => testLayer28,
|
|
@@ -8790,7 +8818,7 @@ var bound = (result, options) => Effect33.gen(function* () {
|
|
|
8790
8818
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
8791
8819
|
});
|
|
8792
8820
|
|
|
8793
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8821
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/compaction.ts
|
|
8794
8822
|
var DEFAULT_RESERVE_TOKENS = 16384;
|
|
8795
8823
|
var DEFAULT_KEEP_RECENT_TOKENS = 20000;
|
|
8796
8824
|
var SUMMARY_TEMPLATE = `Summarize the conversation so another agent can continue seamlessly.
|
|
@@ -8973,7 +9001,7 @@ var truncate = (maxTokens) => ({
|
|
|
8973
9001
|
var testLayer29 = (implementation) => Layer32.succeed(Compaction, Compaction.of(implementation));
|
|
8974
9002
|
var isContextOverflow = (error) => /context|token|prompt/i.test(error instanceof Error ? `${error.name}: ${error.message}` : String(error)) && /overflow|exceed|exceeded|maximum|too large|too long|length/i.test(error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
8975
9003
|
|
|
8976
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9004
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/instructions.ts
|
|
8977
9005
|
var exports_instructions = {};
|
|
8978
9006
|
__export(exports_instructions, {
|
|
8979
9007
|
testLayer: () => testLayer30,
|
|
@@ -9022,7 +9050,7 @@ var renderUpdate = (epoch, context) => Effect35.gen(function* () {
|
|
|
9022
9050
|
var layer27 = (sources) => Layer33.succeed(Instructions, Instructions.of({ sources: [...sources] }));
|
|
9023
9051
|
var testLayer30 = (implementation) => Layer33.succeed(Instructions, Instructions.of(implementation));
|
|
9024
9052
|
|
|
9025
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9053
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/memory.ts
|
|
9026
9054
|
var exports_memory = {};
|
|
9027
9055
|
__export(exports_memory, {
|
|
9028
9056
|
testLayer: () => testLayer31,
|
|
@@ -9042,16 +9070,18 @@ class Memory extends Context34.Service()("@batonfx/core/Memory") {
|
|
|
9042
9070
|
}
|
|
9043
9071
|
var noop = {
|
|
9044
9072
|
recall: () => Effect36.succeed([]),
|
|
9045
|
-
remember: () => Effect36.void
|
|
9073
|
+
remember: () => Effect36.void,
|
|
9074
|
+
forget: () => Effect36.void
|
|
9046
9075
|
};
|
|
9047
9076
|
var merge = (first, second) => ({
|
|
9048
9077
|
recall: (input) => Effect36.all([first.recall(input), second.recall(input)]).pipe(Effect36.map(([firstItems, secondItems]) => [...firstItems, ...secondItems])),
|
|
9049
|
-
remember: (input) => Effect36.all([first.remember(input), second.remember(input)], { discard: true })
|
|
9078
|
+
remember: (input) => Effect36.all([first.remember(input), second.remember(input)], { discard: true }),
|
|
9079
|
+
forget: (input) => Effect36.all([first.forget(input), second.forget(input)], { discard: true })
|
|
9050
9080
|
});
|
|
9051
9081
|
var noopLayer = Layer34.succeed(Memory, Memory.of(noop));
|
|
9052
9082
|
var testLayer31 = (implementation) => Layer34.succeed(Memory, Memory.of(implementation));
|
|
9053
9083
|
|
|
9054
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9084
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-middleware.ts
|
|
9055
9085
|
var exports_model_middleware = {};
|
|
9056
9086
|
__export(exports_model_middleware, {
|
|
9057
9087
|
layer: () => layer28,
|
|
@@ -9065,21 +9095,110 @@ class ModelMiddleware extends Context35.Service()("@batonfx/core/ModelMiddleware
|
|
|
9065
9095
|
var identityLayer = Layer35.succeed(ModelMiddleware, []);
|
|
9066
9096
|
var layer28 = (middleware) => Layer35.succeed(ModelMiddleware, middleware);
|
|
9067
9097
|
|
|
9068
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9098
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-registry.ts
|
|
9099
|
+
var exports_model_registry = {};
|
|
9100
|
+
__export(exports_model_registry, {
|
|
9101
|
+
testLayer: () => testLayer32,
|
|
9102
|
+
registrations: () => registrations,
|
|
9103
|
+
registrationFromLayer: () => registrationFromLayer,
|
|
9104
|
+
register: () => register4,
|
|
9105
|
+
provide: () => provide,
|
|
9106
|
+
memoryLayer: () => memoryLayer25,
|
|
9107
|
+
layerFromRegistrationEffects: () => layerFromRegistrationEffects,
|
|
9108
|
+
layer: () => layer29,
|
|
9109
|
+
combine: () => combine,
|
|
9110
|
+
Service: () => Service29,
|
|
9111
|
+
LanguageModelNotRegistered: () => LanguageModelNotRegistered
|
|
9112
|
+
});
|
|
9113
|
+
import { Chunk as Chunk2, Context as Context36, Effect as Effect38, Layer as Layer36, Option as Option13, Ref as Ref9, Schema as Schema43, Semaphore as Semaphore3 } from "effect";
|
|
9114
|
+
import { Model } from "effect/unstable/ai";
|
|
9115
|
+
|
|
9116
|
+
class LanguageModelNotRegistered extends Schema43.TaggedErrorClass()("LanguageModelNotRegistered", {
|
|
9117
|
+
provider: Schema43.String,
|
|
9118
|
+
model: Schema43.String,
|
|
9119
|
+
registration_key: Schema43.optionalKey(Schema43.String)
|
|
9120
|
+
}) {
|
|
9121
|
+
}
|
|
9122
|
+
|
|
9123
|
+
class Service29 extends Context36.Service()("@batonfx/core/ModelRegistry") {
|
|
9124
|
+
}
|
|
9125
|
+
var registrationVariantKey = (value) => value.registrationKey ?? null;
|
|
9126
|
+
var selectionVariantKey = (selection) => selection.registrationKey ?? null;
|
|
9127
|
+
var registryIdentity = (registration) => JSON.stringify([registration.provider, registration.model, registrationVariantKey(registration)]);
|
|
9128
|
+
var matchesSelection = (selection) => (registration) => registration.provider === selection.provider && registration.model === selection.model && registrationVariantKey(registration) === selectionVariantKey(selection);
|
|
9129
|
+
var upsertRegistration = (registry, registration) => {
|
|
9130
|
+
const key2 = registryIdentity(registration);
|
|
9131
|
+
const exists = Option13.isSome(Chunk2.findFirst(registry, (item) => registryIdentity(item) === key2));
|
|
9132
|
+
if (!exists)
|
|
9133
|
+
return Chunk2.append(registry, registration);
|
|
9134
|
+
return Chunk2.map(registry, (item) => registryIdentity(item) === key2 ? registration : item);
|
|
9135
|
+
};
|
|
9136
|
+
var findRegistration = (registry, selection) => Chunk2.findFirst(registry, matchesSelection(selection)).pipe(Option13.getOrUndefined);
|
|
9137
|
+
var registrationFromLayer = (input) => Model.make(input.provider, input.model, input.layer).captureRequirements.pipe(Effect38.map((layer29) => ({
|
|
9138
|
+
provider: input.provider,
|
|
9139
|
+
model: input.model,
|
|
9140
|
+
layer: layer29,
|
|
9141
|
+
...input.registrationKey === undefined ? {} : { registrationKey: input.registrationKey },
|
|
9142
|
+
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
9143
|
+
})));
|
|
9144
|
+
var layer29 = (initialRegistrations = [], options) => Layer36.effect(Service29, Effect38.gen(function* () {
|
|
9145
|
+
const registry = yield* Ref9.make(initialRegistrations.reduce(upsertRegistration, Chunk2.empty()));
|
|
9146
|
+
const semaphore = options?.maxConcurrentModelCalls === undefined ? undefined : yield* Semaphore3.make(options.maxConcurrentModelCalls);
|
|
9147
|
+
const register4 = Effect38.fn("ModelRegistry.register")(function* (input) {
|
|
9148
|
+
yield* Ref9.update(registry, (items) => upsertRegistration(items, input.registration));
|
|
9149
|
+
});
|
|
9150
|
+
const registrations = Ref9.get(registry).pipe(Effect38.map(Chunk2.toReadonlyArray));
|
|
9151
|
+
const provide = Effect38.fn("ModelRegistry.provide")(function* (selection, effect) {
|
|
9152
|
+
const items = yield* Ref9.get(registry);
|
|
9153
|
+
const registration = findRegistration(items, selection);
|
|
9154
|
+
if (registration === undefined) {
|
|
9155
|
+
return yield* Effect38.fail(new LanguageModelNotRegistered({
|
|
9156
|
+
provider: selection.provider,
|
|
9157
|
+
model: selection.model,
|
|
9158
|
+
...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
|
|
9159
|
+
}));
|
|
9160
|
+
}
|
|
9161
|
+
const provided = effect.pipe(Effect38.provide(registration.layer));
|
|
9162
|
+
return yield* semaphore === undefined ? provided : semaphore.withPermits(1)(provided);
|
|
9163
|
+
});
|
|
9164
|
+
return Service29.of({
|
|
9165
|
+
register: register4,
|
|
9166
|
+
registrations,
|
|
9167
|
+
provide
|
|
9168
|
+
});
|
|
9169
|
+
}));
|
|
9170
|
+
var layerFromRegistrationEffects = (registrations, options) => Layer36.unwrap(Effect38.all(registrations).pipe(Effect38.map((items) => layer29(items, options))));
|
|
9171
|
+
var combine = (registries, options) => Layer36.unwrap(Effect38.forEach(registries, (registry) => Layer36.build(registry).pipe(Effect38.flatMap((context) => Context36.get(context, Service29).registrations))).pipe(Effect38.map((groups) => layer29(groups.flat(), options))));
|
|
9172
|
+
var memoryLayer25 = layer29;
|
|
9173
|
+
var testLayer32 = (implementation) => Layer36.succeed(Service29, Service29.of(implementation));
|
|
9174
|
+
var register4 = Effect38.fn("ModelRegistry.register.call")(function* (input) {
|
|
9175
|
+
const service = yield* Service29;
|
|
9176
|
+
return yield* service.register(input);
|
|
9177
|
+
});
|
|
9178
|
+
var registrations = Effect38.fn("ModelRegistry.registrations.call")(function* () {
|
|
9179
|
+
const service = yield* Service29;
|
|
9180
|
+
return yield* service.registrations;
|
|
9181
|
+
});
|
|
9182
|
+
var provide = (selection, effect) => Effect38.gen(function* () {
|
|
9183
|
+
const service = yield* Service29;
|
|
9184
|
+
return yield* service.provide(selection, effect);
|
|
9185
|
+
});
|
|
9186
|
+
|
|
9187
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-resilience.ts
|
|
9069
9188
|
var exports_model_resilience = {};
|
|
9070
9189
|
__export(exports_model_resilience, {
|
|
9071
|
-
testLayer: () =>
|
|
9190
|
+
testLayer: () => testLayer33,
|
|
9072
9191
|
none: () => none,
|
|
9073
9192
|
make: () => make3,
|
|
9074
|
-
layer: () =>
|
|
9193
|
+
layer: () => layer30,
|
|
9075
9194
|
defaultClassify: () => defaultClassify,
|
|
9076
9195
|
apply: () => apply,
|
|
9077
9196
|
ModelResilience: () => ModelResilience
|
|
9078
9197
|
});
|
|
9079
|
-
import { Cause, Context as
|
|
9198
|
+
import { Cause, Context as Context37, Effect as Effect39, Layer as Layer37, Schedule as Schedule2, Stream as Stream5 } from "effect";
|
|
9080
9199
|
import { AiError, Response as Response2 } from "effect/unstable/ai";
|
|
9081
9200
|
|
|
9082
|
-
class ModelResilience extends
|
|
9201
|
+
class ModelResilience extends Context37.Service()("@batonfx/core/ModelResilience") {
|
|
9083
9202
|
}
|
|
9084
9203
|
var defaultClassify = (error) => AiError.isAiError(error) && error.isRetryable ? "transient" : "terminal";
|
|
9085
9204
|
var none = { classify: () => "terminal", retrySchedule: Schedule2.recurs(0) };
|
|
@@ -9087,9 +9206,9 @@ var make3 = (input) => ({
|
|
|
9087
9206
|
classify: input?.classify ?? defaultClassify,
|
|
9088
9207
|
retrySchedule: input?.retrySchedule ?? none.retrySchedule
|
|
9089
9208
|
});
|
|
9090
|
-
var
|
|
9091
|
-
var
|
|
9092
|
-
var retryEffect = (effect, resilience) =>
|
|
9209
|
+
var layer30 = (input) => Layer37.succeed(ModelResilience, ModelResilience.of(make3(input)));
|
|
9210
|
+
var testLayer33 = (implementation) => Layer37.succeed(ModelResilience, ModelResilience.of(implementation));
|
|
9211
|
+
var retryEffect = (effect, resilience) => Effect39.suspend(effect).pipe(Effect39.retry({
|
|
9093
9212
|
schedule: resilience.retrySchedule,
|
|
9094
9213
|
while: (error) => resilience.classify(error) === "transient"
|
|
9095
9214
|
}));
|
|
@@ -9100,7 +9219,7 @@ var apply = (model, resilience) => ({
|
|
|
9100
9219
|
generateObject: (options) => retryEffect(() => model.generateObject(options), resilience),
|
|
9101
9220
|
streamText: (options) => Stream5.suspend(() => {
|
|
9102
9221
|
let emitted = false;
|
|
9103
|
-
return model.streamText(options).pipe(Stream5.tap(() =>
|
|
9222
|
+
return model.streamText(options).pipe(Stream5.tap(() => Effect39.sync(() => {
|
|
9104
9223
|
emitted = true;
|
|
9105
9224
|
})), Stream5.catchCause((cause) => {
|
|
9106
9225
|
if (Cause.hasInterrupts(cause))
|
|
@@ -9111,10 +9230,10 @@ var apply = (model, resilience) => ({
|
|
|
9111
9230
|
}).pipe(Stream5.retry(retryStreamSchedule(resilience)))
|
|
9112
9231
|
});
|
|
9113
9232
|
|
|
9114
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9233
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/permissions.ts
|
|
9115
9234
|
var exports_permissions = {};
|
|
9116
9235
|
__export(exports_permissions, {
|
|
9117
|
-
testLayer: () =>
|
|
9236
|
+
testLayer: () => testLayer34,
|
|
9118
9237
|
ruleStoreTestLayer: () => ruleStoreTestLayer,
|
|
9119
9238
|
ruleStoreMemory: () => ruleStoreMemory,
|
|
9120
9239
|
matches: () => matches,
|
|
@@ -9126,17 +9245,17 @@ __export(exports_permissions, {
|
|
|
9126
9245
|
Permissions: () => Permissions,
|
|
9127
9246
|
PermissionError: () => PermissionError
|
|
9128
9247
|
});
|
|
9129
|
-
import { Context as
|
|
9248
|
+
import { Context as Context38, Effect as Effect40, Layer as Layer38, Option as Option14, Ref as Ref10, Schema as Schema44 } from "effect";
|
|
9130
9249
|
|
|
9131
|
-
class PermissionError extends
|
|
9132
|
-
message:
|
|
9250
|
+
class PermissionError extends Schema44.TaggedErrorClass()("@batonfx/core/PermissionError", {
|
|
9251
|
+
message: Schema44.String
|
|
9133
9252
|
}) {
|
|
9134
9253
|
}
|
|
9135
9254
|
|
|
9136
|
-
class Permissions extends
|
|
9255
|
+
class Permissions extends Context38.Service()("@batonfx/core/Permissions") {
|
|
9137
9256
|
}
|
|
9138
9257
|
|
|
9139
|
-
class RuleStore extends
|
|
9258
|
+
class RuleStore extends Context38.Service()("@batonfx/core/PermissionRuleStore") {
|
|
9140
9259
|
}
|
|
9141
9260
|
var escapeRegExp = (value) => value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
9142
9261
|
var glob = (pattern) => new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`);
|
|
@@ -9223,28 +9342,28 @@ var decisionFor = (ruleset, request) => {
|
|
|
9223
9342
|
return { _tag: "Ask", token: tokenFor(request) };
|
|
9224
9343
|
}
|
|
9225
9344
|
};
|
|
9226
|
-
var fromRuleset = (ruleset) =>
|
|
9227
|
-
evaluate: (request) =>
|
|
9228
|
-
await: () =>
|
|
9345
|
+
var fromRuleset = (ruleset) => Layer38.succeed(Permissions, Permissions.of({
|
|
9346
|
+
evaluate: (request) => Effect40.succeed(decisionFor(ruleset, request)),
|
|
9347
|
+
await: () => Effect40.succeed(Option14.none())
|
|
9229
9348
|
}));
|
|
9230
|
-
var allowAll =
|
|
9231
|
-
evaluate: () =>
|
|
9232
|
-
await: () =>
|
|
9349
|
+
var allowAll = Layer38.succeed(Permissions, Permissions.of({
|
|
9350
|
+
evaluate: () => Effect40.succeed({ _tag: "Allow" }),
|
|
9351
|
+
await: () => Effect40.succeed(Option14.none())
|
|
9233
9352
|
}));
|
|
9234
|
-
var interactive = (options) =>
|
|
9235
|
-
evaluate: (request) =>
|
|
9236
|
-
await: (pending) => options.onAsk(pending).pipe(
|
|
9353
|
+
var interactive = (options) => Layer38.succeed(Permissions, Permissions.of({
|
|
9354
|
+
evaluate: (request) => Effect40.succeed(decisionFor(options.ruleset, request)),
|
|
9355
|
+
await: (pending) => options.onAsk(pending).pipe(Effect40.map(Option14.some))
|
|
9237
9356
|
}));
|
|
9238
|
-
var ruleStoreMemory = (initialRules = []) =>
|
|
9239
|
-
remember: (rule) =>
|
|
9357
|
+
var ruleStoreMemory = (initialRules = []) => Layer38.effect(RuleStore, Ref10.make(initialRules).pipe(Effect40.map((rules) => RuleStore.of({
|
|
9358
|
+
remember: (rule) => Ref10.update(rules, (current2) => [...current2, rule])
|
|
9240
9359
|
}))));
|
|
9241
|
-
var ruleStoreTestLayer = (implementation) =>
|
|
9242
|
-
var
|
|
9360
|
+
var ruleStoreTestLayer = (implementation) => Layer38.succeed(RuleStore, RuleStore.of(implementation));
|
|
9361
|
+
var testLayer34 = (implementation) => Layer38.succeed(Permissions, Permissions.of(implementation));
|
|
9243
9362
|
|
|
9244
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9363
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/skill-source.ts
|
|
9245
9364
|
var exports_skill_source = {};
|
|
9246
9365
|
__export(exports_skill_source, {
|
|
9247
|
-
testLayer: () =>
|
|
9366
|
+
testLayer: () => testLayer35,
|
|
9248
9367
|
selectListings: () => selectListings,
|
|
9249
9368
|
makeListing: () => makeListing,
|
|
9250
9369
|
fromSkills: () => fromSkills,
|
|
@@ -9253,29 +9372,29 @@ __export(exports_skill_source, {
|
|
|
9253
9372
|
SkillSource: () => SkillSource,
|
|
9254
9373
|
DESCRIPTION_CAP: () => DESCRIPTION_CAP
|
|
9255
9374
|
});
|
|
9256
|
-
import { Context as
|
|
9375
|
+
import { Context as Context39, Effect as Effect41, Layer as Layer39, Schema as Schema45 } from "effect";
|
|
9257
9376
|
|
|
9258
|
-
class SkillSourceError extends
|
|
9259
|
-
source:
|
|
9260
|
-
message:
|
|
9261
|
-
cause:
|
|
9377
|
+
class SkillSourceError extends Schema45.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
9378
|
+
source: Schema45.String,
|
|
9379
|
+
message: Schema45.String,
|
|
9380
|
+
cause: Schema45.optionalKey(Schema45.Defect())
|
|
9262
9381
|
}) {
|
|
9263
9382
|
}
|
|
9264
9383
|
var DESCRIPTION_CAP = 1536;
|
|
9265
9384
|
|
|
9266
|
-
class SkillSource extends
|
|
9385
|
+
class SkillSource extends Context39.Service()("@batonfx/core/SkillSource") {
|
|
9267
9386
|
}
|
|
9268
9387
|
var makeListing = (frontmatter, descriptionCap = DESCRIPTION_CAP) => `- ${frontmatter.name}: ${frontmatter.description.slice(0, Math.max(0, descriptionCap))}`;
|
|
9269
9388
|
var fromSkills = (skills) => {
|
|
9270
9389
|
const all = [...skills];
|
|
9271
9390
|
const byName = new Map(all.map((skill) => [skill.frontmatter.name, skill]));
|
|
9272
|
-
return
|
|
9273
|
-
all:
|
|
9274
|
-
get: (name) =>
|
|
9391
|
+
return Layer39.succeed(SkillSource, SkillSource.of({
|
|
9392
|
+
all: Effect41.succeed(all),
|
|
9393
|
+
get: (name) => Effect41.succeed(byName.get(name))
|
|
9275
9394
|
}));
|
|
9276
9395
|
};
|
|
9277
9396
|
var empty = fromSkills([]);
|
|
9278
|
-
var
|
|
9397
|
+
var testLayer35 = (implementation) => Layer39.succeed(SkillSource, SkillSource.of(implementation));
|
|
9279
9398
|
var estimatedTokens = (listing) => Math.ceil(listing.length / 4);
|
|
9280
9399
|
var usageRank = (skill, recentlyUsed) => {
|
|
9281
9400
|
const index2 = recentlyUsed.indexOf(skill.frontmatter.name);
|
|
@@ -9299,22 +9418,22 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
9299
9418
|
return selected;
|
|
9300
9419
|
};
|
|
9301
9420
|
|
|
9302
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9421
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/steering.ts
|
|
9303
9422
|
var exports_steering = {};
|
|
9304
9423
|
__export(exports_steering, {
|
|
9305
|
-
testLayer: () =>
|
|
9306
|
-
layer: () =>
|
|
9424
|
+
testLayer: () => testLayer36,
|
|
9425
|
+
layer: () => layer31,
|
|
9307
9426
|
SteeringQueueFull: () => SteeringQueueFull,
|
|
9308
9427
|
Steering: () => Steering
|
|
9309
9428
|
});
|
|
9310
|
-
import { Context as
|
|
9429
|
+
import { Context as Context40, Effect as Effect42, Exit, Layer as Layer40, Queue, Schema as Schema46 } from "effect";
|
|
9311
9430
|
|
|
9312
|
-
class Steering extends
|
|
9431
|
+
class Steering extends Context40.Service()("@batonfx/core/Steering") {
|
|
9313
9432
|
}
|
|
9314
9433
|
|
|
9315
|
-
class SteeringQueueFull extends
|
|
9316
|
-
queue:
|
|
9317
|
-
capacity:
|
|
9434
|
+
class SteeringQueueFull extends Schema46.TaggedErrorClass()("@batonfx/core/SteeringQueueFull", {
|
|
9435
|
+
queue: Schema46.Literals(["steering", "followUp"]),
|
|
9436
|
+
capacity: Schema46.Number
|
|
9318
9437
|
}) {
|
|
9319
9438
|
}
|
|
9320
9439
|
var resolvePolicy = (policy, mode) => ({
|
|
@@ -9333,18 +9452,18 @@ var queueStrategy = (strategy) => {
|
|
|
9333
9452
|
return "suspend";
|
|
9334
9453
|
}
|
|
9335
9454
|
};
|
|
9336
|
-
var makeQueue = (name, policy) => (policy.capacity === undefined ? Queue.unbounded() : Queue.make({ capacity: policy.capacity, strategy: queueStrategy(policy.onFull) })).pipe(
|
|
9337
|
-
var offer = (runtime, message) => Queue.offer(runtime.queue, message).pipe(
|
|
9455
|
+
var makeQueue = (name, policy) => (policy.capacity === undefined ? Queue.unbounded() : Queue.make({ capacity: policy.capacity, strategy: queueStrategy(policy.onFull) })).pipe(Effect42.map((queue) => ({ name, queue, policy })));
|
|
9456
|
+
var offer = (runtime, message) => Queue.offer(runtime.queue, message).pipe(Effect42.flatMap((offered) => {
|
|
9338
9457
|
if (offered || runtime.policy.capacity === undefined || runtime.policy.onFull !== "fail")
|
|
9339
|
-
return
|
|
9340
|
-
return
|
|
9458
|
+
return Effect42.void;
|
|
9459
|
+
return Effect42.fail(new SteeringQueueFull({ queue: runtime.name, capacity: runtime.policy.capacity }));
|
|
9341
9460
|
}));
|
|
9342
|
-
var drainOne = (queue) =>
|
|
9461
|
+
var drainOne = (queue) => Effect42.sync(() => {
|
|
9343
9462
|
const taken = Queue.takeUnsafe(queue);
|
|
9344
9463
|
return taken === undefined || !Exit.isSuccess(taken) ? [] : [taken.value];
|
|
9345
9464
|
});
|
|
9346
9465
|
var drain = (queue, mode) => mode === "all" ? Queue.clear(queue) : drainOne(queue);
|
|
9347
|
-
var
|
|
9466
|
+
var layer31 = (options = {}) => Layer40.effect(Steering, Effect42.gen(function* () {
|
|
9348
9467
|
const steeringQueue = yield* makeQueue("steering", resolvePolicy(options.steering, "all"));
|
|
9349
9468
|
const followUpQueue = yield* makeQueue("followUp", resolvePolicy(options.followUp, "one-at-a-time"));
|
|
9350
9469
|
return Steering.of({
|
|
@@ -9354,30 +9473,30 @@ var layer30 = (options = {}) => Layer39.effect(Steering, Effect41.gen(function*
|
|
|
9354
9473
|
takeFollowUp: () => drain(followUpQueue.queue, followUpQueue.policy.mode)
|
|
9355
9474
|
});
|
|
9356
9475
|
}));
|
|
9357
|
-
var
|
|
9476
|
+
var testLayer36 = (implementation) => Layer40.succeed(Steering, Steering.of(implementation));
|
|
9358
9477
|
|
|
9359
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9478
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-context.ts
|
|
9360
9479
|
var exports_tool_context = {};
|
|
9361
9480
|
__export(exports_tool_context, {
|
|
9362
|
-
testLayer: () =>
|
|
9481
|
+
testLayer: () => testLayer37,
|
|
9363
9482
|
layerDefault: () => layerDefault,
|
|
9364
9483
|
ToolContext: () => ToolContext
|
|
9365
9484
|
});
|
|
9366
|
-
import { Context as
|
|
9485
|
+
import { Context as Context41, Effect as Effect43, Layer as Layer41 } from "effect";
|
|
9367
9486
|
|
|
9368
|
-
class ToolContext extends
|
|
9487
|
+
class ToolContext extends Context41.Service()("@batonfx/core/ToolContext") {
|
|
9369
9488
|
}
|
|
9370
|
-
var layerDefault =
|
|
9489
|
+
var layerDefault = Layer41.sync(ToolContext, () => ToolContext.of({
|
|
9371
9490
|
signal: new AbortController().signal,
|
|
9372
|
-
emit: () =>
|
|
9491
|
+
emit: () => Effect43.void,
|
|
9373
9492
|
sessionId: "local"
|
|
9374
9493
|
}));
|
|
9375
|
-
var
|
|
9494
|
+
var testLayer37 = (implementation) => Layer41.succeed(ToolContext, ToolContext.of(implementation));
|
|
9376
9495
|
|
|
9377
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9496
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-executor.ts
|
|
9378
9497
|
var exports_tool_executor = {};
|
|
9379
9498
|
__export(exports_tool_executor, {
|
|
9380
|
-
testLayer: () =>
|
|
9499
|
+
testLayer: () => testLayer38,
|
|
9381
9500
|
sandbox: () => sandbox,
|
|
9382
9501
|
router: () => router,
|
|
9383
9502
|
routeToolkit: () => routeToolkit,
|
|
@@ -9389,8 +9508,8 @@ __export(exports_tool_executor, {
|
|
|
9389
9508
|
client: () => client,
|
|
9390
9509
|
ToolExecutor: () => ToolExecutor
|
|
9391
9510
|
});
|
|
9392
|
-
import { Cause as Cause2, Context as
|
|
9393
|
-
class ToolExecutor extends
|
|
9511
|
+
import { Cause as Cause2, Context as Context42, Effect as Effect44, Layer as Layer42, Option as Option15, Schema as Schema47, Sink as Sink2, Stream as Stream6 } from "effect";
|
|
9512
|
+
class ToolExecutor extends Context42.Service()("@batonfx/core/ToolExecutor") {
|
|
9394
9513
|
}
|
|
9395
9514
|
var failureMessage = (cause) => {
|
|
9396
9515
|
const error = Cause2.squash(cause);
|
|
@@ -9412,47 +9531,47 @@ var resultMessage = (result) => {
|
|
|
9412
9531
|
var schemaMessage = (error) => error instanceof Error ? error.message : typeof error === "string" ? error : resultMessage(error);
|
|
9413
9532
|
var decodeSuccess = (tool2, result) => {
|
|
9414
9533
|
const successSchema = tool2.successSchema;
|
|
9415
|
-
if (!
|
|
9416
|
-
return
|
|
9534
|
+
if (!Schema47.isSchema(successSchema)) {
|
|
9535
|
+
return Effect44.succeed({ _tag: "Success", result, encodedResult: result });
|
|
9417
9536
|
}
|
|
9418
|
-
return
|
|
9537
|
+
return Schema47.decodeUnknownEffect(successSchema)(result).pipe(Effect44.flatMap((decoded) => Schema47.encodeUnknownEffect(successSchema)(decoded).pipe(Effect44.map((encoded) => ({ _tag: "Success", result: decoded, encodedResult: encoded })))), Effect44.catchCause((cause) => Effect44.succeed(failureOutcome(`invalid client result: ${schemaMessage(Cause2.squash(cause))}`))));
|
|
9419
9538
|
};
|
|
9420
9539
|
var placementOutcome = (placement, tool2, response) => {
|
|
9421
9540
|
switch (response._tag) {
|
|
9422
9541
|
case "Failure":
|
|
9423
|
-
return
|
|
9542
|
+
return Effect44.succeed(failureOutcome(response.message));
|
|
9424
9543
|
case "Suspend":
|
|
9425
|
-
return
|
|
9544
|
+
return Effect44.succeed({ _tag: "Suspend", token: response.token });
|
|
9426
9545
|
case "Success":
|
|
9427
|
-
return decodeSuccess(tool2, response.result).pipe(
|
|
9546
|
+
return decodeSuccess(tool2, response.result).pipe(Effect44.map((outcome) => outcome._tag === "Failure" ? failureOutcome(outcome.message.replace("invalid client result", `invalid ${placement} result`)) : outcome));
|
|
9428
9547
|
}
|
|
9429
9548
|
};
|
|
9430
9549
|
var executeWithToolkit = (toolkit, request) => {
|
|
9431
9550
|
if (toolkit.tools[request.call.name] === undefined) {
|
|
9432
|
-
return
|
|
9551
|
+
return Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`));
|
|
9433
9552
|
}
|
|
9434
|
-
return toolkit.handle(request.call.name, request.call.params).pipe(
|
|
9553
|
+
return toolkit.handle(request.call.name, request.call.params).pipe(Effect44.flatMap((results) => results.pipe(Stream6.filter((item) => item.preliminary === false), Stream6.run(Sink2.last()))), Effect44.map(Option15.match({
|
|
9435
9554
|
onNone: () => failureOutcome("Tool handler did not produce a final result"),
|
|
9436
9555
|
onSome: (result) => result.isFailure ? failureOutcome(resultMessage(result.result)) : {
|
|
9437
9556
|
_tag: "Success",
|
|
9438
9557
|
result: result.result,
|
|
9439
9558
|
encodedResult: result.encodedResult
|
|
9440
9559
|
}
|
|
9441
|
-
})),
|
|
9560
|
+
})), Effect44.catchCause((cause) => {
|
|
9442
9561
|
if (Cause2.hasInterrupts(cause))
|
|
9443
|
-
return
|
|
9562
|
+
return Effect44.interrupt;
|
|
9444
9563
|
const error = Cause2.squash(cause);
|
|
9445
9564
|
if (error instanceof AgentSuspended) {
|
|
9446
|
-
return
|
|
9565
|
+
return Effect44.succeed({ _tag: "Suspend", token: error.token });
|
|
9447
9566
|
}
|
|
9448
|
-
return
|
|
9567
|
+
return Effect44.succeed(failureOutcome(failureMessage(cause)));
|
|
9449
9568
|
}));
|
|
9450
9569
|
};
|
|
9451
9570
|
function executeToolkit(toolkit, request) {
|
|
9452
|
-
return ("handle" in toolkit ?
|
|
9571
|
+
return ("handle" in toolkit ? Effect44.succeed(toolkit) : toolkit).pipe(Effect44.flatMap((handled) => executeWithToolkit(handled, request)));
|
|
9453
9572
|
}
|
|
9454
9573
|
function fromToolkit(toolkit) {
|
|
9455
|
-
return
|
|
9574
|
+
return Layer42.effect(ToolExecutor, ("handle" in toolkit ? Effect44.succeed(toolkit) : toolkit).pipe(Effect44.map((handled) => ToolExecutor.of({
|
|
9456
9575
|
execute: (request) => executeWithToolkit(handled, request)
|
|
9457
9576
|
}))));
|
|
9458
9577
|
}
|
|
@@ -9471,10 +9590,10 @@ var placementRoute = (placement, options) => {
|
|
|
9471
9590
|
execute: (request) => {
|
|
9472
9591
|
const tool2 = options.toolkit.tools[request.call.name];
|
|
9473
9592
|
if (tool2 === undefined)
|
|
9474
|
-
return
|
|
9593
|
+
return Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`));
|
|
9475
9594
|
const effect = options.execute({ ...request, placement, tool: tool2 });
|
|
9476
|
-
const scheduled = "schedule" in options && options.schedule !== undefined ?
|
|
9477
|
-
return scheduled.pipe(
|
|
9595
|
+
const scheduled = "schedule" in options && options.schedule !== undefined ? Effect44.retry(effect, options.schedule) : effect;
|
|
9596
|
+
return scheduled.pipe(Effect44.flatMap((response) => placementOutcome(placement, tool2, response)), Effect44.catchCause((cause) => Cause2.hasInterrupts(cause) ? Effect44.interrupt : Effect44.succeed(failureOutcome(`${placement} tool infrastructure failed: ${failureMessage(cause)}`))));
|
|
9478
9597
|
}
|
|
9479
9598
|
});
|
|
9480
9599
|
};
|
|
@@ -9487,20 +9606,20 @@ function routeToolkit(toolkit) {
|
|
|
9487
9606
|
tools: Object.keys(handled.tools),
|
|
9488
9607
|
execute: (request) => executeWithToolkit(handled, request)
|
|
9489
9608
|
});
|
|
9490
|
-
return "handle" in toolkit ? makeRoute(toolkit) : toolkit.pipe(
|
|
9609
|
+
return "handle" in toolkit ? makeRoute(toolkit) : toolkit.pipe(Effect44.map(makeRoute));
|
|
9491
9610
|
}
|
|
9492
|
-
var routeInputEffect = (input) =>
|
|
9611
|
+
var routeInputEffect = (input) => Effect44.isEffect(input) ? input : Effect44.succeed(input);
|
|
9493
9612
|
function router(routes) {
|
|
9494
|
-
return
|
|
9613
|
+
return Layer42.effect(ToolExecutor, Effect44.all(Array.from(routes, routeInputEffect)).pipe(Effect44.map((resolved) => ToolExecutor.of({
|
|
9495
9614
|
execute: (request) => {
|
|
9496
9615
|
const matched = resolved.find((candidate) => candidate.matches(request));
|
|
9497
|
-
return matched === undefined ?
|
|
9616
|
+
return matched === undefined ? Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`)) : matched.execute(request);
|
|
9498
9617
|
}
|
|
9499
9618
|
}))));
|
|
9500
9619
|
}
|
|
9501
|
-
var
|
|
9620
|
+
var testLayer38 = (implementation) => Layer42.succeed(ToolExecutor, ToolExecutor.of(implementation));
|
|
9502
9621
|
|
|
9503
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9622
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/turn-policy.ts
|
|
9504
9623
|
var exports_turn_policy = {};
|
|
9505
9624
|
__export(exports_turn_policy, {
|
|
9506
9625
|
untilToolCall: () => untilToolCall,
|
|
@@ -9510,7 +9629,7 @@ __export(exports_turn_policy, {
|
|
|
9510
9629
|
decision: () => decision,
|
|
9511
9630
|
both: () => both
|
|
9512
9631
|
});
|
|
9513
|
-
import { Effect as
|
|
9632
|
+
import { Effect as Effect45 } from "effect";
|
|
9514
9633
|
var decision = {
|
|
9515
9634
|
continue: (overrides) => ({
|
|
9516
9635
|
_tag: "Continue",
|
|
@@ -9519,8 +9638,8 @@ var decision = {
|
|
|
9519
9638
|
stop: { _tag: "Stop" }
|
|
9520
9639
|
};
|
|
9521
9640
|
var make4 = (decide) => ({ decide });
|
|
9522
|
-
var recurs = (n) => make4((info) =>
|
|
9523
|
-
var untilToolCall = (name) => make4((info) =>
|
|
9641
|
+
var recurs = (n) => make4((info) => Effect45.succeed(info.turn < n + 1 ? decision.continue() : decision.stop));
|
|
9642
|
+
var untilToolCall = (name) => make4((info) => Effect45.succeed(info.pendingToolResults.some((result) => result.name === name) ? decision.stop : decision.continue()));
|
|
9524
9643
|
var mergeOverrides = (first, second) => {
|
|
9525
9644
|
if (first === undefined)
|
|
9526
9645
|
return second;
|
|
@@ -9528,7 +9647,7 @@ var mergeOverrides = (first, second) => {
|
|
|
9528
9647
|
return first;
|
|
9529
9648
|
return { ...first, ...second };
|
|
9530
9649
|
};
|
|
9531
|
-
var both = (first, second) => make4((info) =>
|
|
9650
|
+
var both = (first, second) => make4((info) => Effect45.gen(function* () {
|
|
9532
9651
|
const left = yield* first.decide(info);
|
|
9533
9652
|
if (left._tag === "Stop")
|
|
9534
9653
|
return decision.stop;
|
|
@@ -9539,14 +9658,17 @@ var both = (first, second) => make4((info) => Effect44.gen(function* () {
|
|
|
9539
9658
|
}));
|
|
9540
9659
|
var defaultPolicy = recurs(8);
|
|
9541
9660
|
|
|
9542
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9661
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent.ts
|
|
9543
9662
|
function make5(nameOrOptions, options = {}) {
|
|
9544
9663
|
const resolved = typeof nameOrOptions === "string" ? { ...options, name: nameOrOptions } : nameOrOptions;
|
|
9545
9664
|
return {
|
|
9546
9665
|
name: resolved.name,
|
|
9547
9666
|
...resolved.instructions === undefined ? {} : { instructions: resolved.instructions },
|
|
9548
9667
|
toolkit: resolved.toolkit ?? Toolkit3.empty,
|
|
9549
|
-
policy: resolved.policy ?? defaultPolicy
|
|
9668
|
+
policy: resolved.policy ?? defaultPolicy,
|
|
9669
|
+
...resolved.model === undefined ? {} : { model: resolved.model },
|
|
9670
|
+
...resolved.memory === undefined ? {} : { memory: resolved.memory },
|
|
9671
|
+
...resolved.metadata === undefined ? {} : { metadata: resolved.metadata }
|
|
9550
9672
|
};
|
|
9551
9673
|
}
|
|
9552
9674
|
var defaultObjectPrompt = "Return the final structured output for the task above.";
|
|
@@ -9558,14 +9680,14 @@ var steeringDrainedEvent = (turn, queue, messages) => ({
|
|
|
9558
9680
|
});
|
|
9559
9681
|
var skillListingBudgetTokens = 2048;
|
|
9560
9682
|
var activateSkillToolName = "activate_skill";
|
|
9561
|
-
var activateSkillParameters =
|
|
9683
|
+
var activateSkillParameters = Schema48.Struct({ name: Schema48.String });
|
|
9562
9684
|
var activateSkillTool = Tool4.make(activateSkillToolName, {
|
|
9563
9685
|
description: "Load the full body for one listed Baton skill by name before applying that skill.",
|
|
9564
9686
|
parameters: activateSkillParameters,
|
|
9565
|
-
success:
|
|
9566
|
-
name:
|
|
9567
|
-
body:
|
|
9568
|
-
allowedTools:
|
|
9687
|
+
success: Schema48.Struct({
|
|
9688
|
+
name: Schema48.String,
|
|
9689
|
+
body: Schema48.String,
|
|
9690
|
+
allowedTools: Schema48.Array(Schema48.String)
|
|
9569
9691
|
})
|
|
9570
9692
|
});
|
|
9571
9693
|
var errorMessage = (error) => error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
@@ -9612,15 +9734,15 @@ var isUserMessagePart = (part) => part.type === "text" || part.type === "file";
|
|
|
9612
9734
|
var approvalRequired = (tool2, call, messages) => {
|
|
9613
9735
|
const needsApproval = tool2?.needsApproval;
|
|
9614
9736
|
if (needsApproval === undefined)
|
|
9615
|
-
return
|
|
9737
|
+
return Effect46.succeed(false);
|
|
9616
9738
|
if (typeof needsApproval === "boolean")
|
|
9617
|
-
return
|
|
9618
|
-
return
|
|
9739
|
+
return Effect46.succeed(needsApproval);
|
|
9740
|
+
return Effect46.suspend(() => {
|
|
9619
9741
|
const result = needsApproval(call.params, { toolCallId: call.id, messages });
|
|
9620
|
-
return
|
|
9621
|
-
}).pipe(
|
|
9742
|
+
return Effect46.isEffect(result) ? result : Effect46.succeed(result);
|
|
9743
|
+
}).pipe(Effect46.catchCause((cause) => Cause3.hasInterrupts(cause) ? Effect46.interrupt : Effect46.succeed(true)));
|
|
9622
9744
|
};
|
|
9623
|
-
var applyPromptChain = (chain, prompt, context) =>
|
|
9745
|
+
var applyPromptChain = (chain, prompt, context) => Effect46.gen(function* () {
|
|
9624
9746
|
let current2 = prompt;
|
|
9625
9747
|
for (const middleware of chain) {
|
|
9626
9748
|
if (middleware.transformPrompt !== undefined) {
|
|
@@ -9629,10 +9751,10 @@ var applyPromptChain = (chain, prompt, context) => Effect45.gen(function* () {
|
|
|
9629
9751
|
}
|
|
9630
9752
|
return current2;
|
|
9631
9753
|
});
|
|
9632
|
-
var applyPartChain = (chain, part, context) =>
|
|
9633
|
-
let current2 =
|
|
9754
|
+
var applyPartChain = (chain, part, context) => Effect46.gen(function* () {
|
|
9755
|
+
let current2 = Option16.some(part);
|
|
9634
9756
|
for (const middleware of chain) {
|
|
9635
|
-
if (
|
|
9757
|
+
if (Option16.isNone(current2))
|
|
9636
9758
|
break;
|
|
9637
9759
|
if (middleware.transformPart !== undefined) {
|
|
9638
9760
|
current2 = yield* middleware.transformPart(current2.value, context);
|
|
@@ -9640,74 +9762,83 @@ var applyPartChain = (chain, part, context) => Effect45.gen(function* () {
|
|
|
9640
9762
|
}
|
|
9641
9763
|
return current2;
|
|
9642
9764
|
});
|
|
9643
|
-
var streamInternal = (agent, options, structured) => Stream7.unwrap(
|
|
9644
|
-
const executor = yield*
|
|
9645
|
-
const approvals = yield*
|
|
9646
|
-
const chain = yield*
|
|
9765
|
+
var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect46.gen(function* () {
|
|
9766
|
+
const executor = yield* Effect46.serviceOption(ToolExecutor);
|
|
9767
|
+
const approvals = yield* Effect46.serviceOption(Approvals);
|
|
9768
|
+
const chain = yield* Effect46.serviceOption(ModelMiddleware).pipe(Effect46.map(Option16.match({ onNone: () => [], onSome: (service) => service })));
|
|
9647
9769
|
if (options.history !== undefined && options.persistence !== undefined) {
|
|
9648
|
-
return yield*
|
|
9770
|
+
return yield* Effect46.fail(new AgentError({
|
|
9649
9771
|
message: "RunOptions.history and RunOptions.persistence are mutually exclusive",
|
|
9650
9772
|
turn: 0
|
|
9651
9773
|
}));
|
|
9652
9774
|
}
|
|
9653
9775
|
if (options.toolOutputMaxBytes !== undefined && (!Number.isFinite(options.toolOutputMaxBytes) || options.toolOutputMaxBytes < 0)) {
|
|
9654
|
-
return yield*
|
|
9776
|
+
return yield* Effect46.fail(new AgentError({
|
|
9655
9777
|
message: "RunOptions.toolOutputMaxBytes must be a non-negative finite number",
|
|
9656
9778
|
turn: 0
|
|
9657
9779
|
}));
|
|
9658
9780
|
}
|
|
9659
9781
|
if (options.compaction?.contextWindow !== undefined && (!Number.isFinite(options.compaction.contextWindow) || options.compaction.contextWindow <= 0)) {
|
|
9660
|
-
return yield*
|
|
9782
|
+
return yield* Effect46.fail(new AgentError({
|
|
9661
9783
|
message: "RunOptions.compaction.contextWindow must be a positive finite number",
|
|
9662
9784
|
turn: 0
|
|
9663
9785
|
}));
|
|
9664
9786
|
}
|
|
9665
9787
|
const sessionId = options.sessionId ?? "local";
|
|
9666
|
-
const instructionsService = yield*
|
|
9667
|
-
const skillSourceService = yield*
|
|
9668
|
-
const skillRuntime =
|
|
9788
|
+
const instructionsService = yield* Effect46.serviceOption(Instructions);
|
|
9789
|
+
const skillSourceService = yield* Effect46.serviceOption(SkillSource);
|
|
9790
|
+
const skillRuntime = Option16.isNone(skillSourceService) ? undefined : {
|
|
9669
9791
|
source: skillSourceService.value,
|
|
9670
|
-
skills: yield* skillSourceService.value.all.pipe(
|
|
9792
|
+
skills: yield* skillSourceService.value.all.pipe(Effect46.mapError((error) => new AgentError({ message: error.message, turn: 0, cause: error })))
|
|
9671
9793
|
};
|
|
9672
9794
|
const selectedSkills = skillRuntime === undefined ? [] : selectListings(skillRuntime.skills, skillListingBudgetTokens, []);
|
|
9673
9795
|
const skillListings = selectedSkills.map((skill) => skill.listing).join(`
|
|
9674
9796
|
`);
|
|
9675
9797
|
const hasActivatableSkills = selectedSkills.length > 0;
|
|
9676
|
-
const instructionsEpoch = options.system === undefined && options.history === undefined &&
|
|
9798
|
+
const instructionsEpoch = options.system === undefined && options.history === undefined && Option16.isSome(instructionsService) ? yield* openEpoch(instructionsService.value, { agentName: agent.name, turn: 0 }) : undefined;
|
|
9677
9799
|
const baseSystem = options.system ?? (instructionsEpoch === undefined ? agent.instructions : instructionsEpoch.baseline.length === 0 ? agent.instructions : instructionsEpoch.baseline);
|
|
9678
9800
|
const system = appendInstructionFragment(baseSystem, options.history === undefined && skillListings.length > 0 ? skillListingsInstructions(skillListings) : undefined);
|
|
9679
|
-
const persistenceService = yield*
|
|
9680
|
-
const resilienceService = yield*
|
|
9681
|
-
const
|
|
9682
|
-
const
|
|
9683
|
-
const
|
|
9684
|
-
const
|
|
9685
|
-
const
|
|
9686
|
-
const
|
|
9801
|
+
const persistenceService = yield* Effect46.serviceOption(Chat.Persistence);
|
|
9802
|
+
const resilienceService = yield* Effect46.serviceOption(ModelResilience);
|
|
9803
|
+
const modelRegistryService = yield* Effect46.serviceOption(Service29);
|
|
9804
|
+
const permissionsService = yield* Effect46.serviceOption(Permissions);
|
|
9805
|
+
const steeringService = yield* Effect46.serviceOption(Steering);
|
|
9806
|
+
const compactionService = yield* Effect46.serviceOption(Compaction);
|
|
9807
|
+
const memoryService = yield* Effect46.serviceOption(Memory);
|
|
9808
|
+
const sessionService = yield* Effect46.serviceOption(SessionStore);
|
|
9809
|
+
const tokenizerService = yield* Effect46.serviceOption(Tokenizer2.Tokenizer);
|
|
9687
9810
|
const persistenceOptions = options.persistence;
|
|
9688
|
-
const memoryOptions = options.memory;
|
|
9811
|
+
const memoryOptions = options.memory ?? (agent.memory === undefined ? undefined : { key: agent.memory });
|
|
9812
|
+
const agentModel = agent.model;
|
|
9813
|
+
const agentModelContext = agentModel === undefined ? undefined : yield* Option16.match(modelRegistryService, {
|
|
9814
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9815
|
+
message: "Agent.model requires ModelRegistry in context",
|
|
9816
|
+
turn: 0
|
|
9817
|
+
})),
|
|
9818
|
+
onSome: (registry) => registry.provide(agentModel, Effect46.context()).pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })))
|
|
9819
|
+
});
|
|
9689
9820
|
const memoryRuntime = memoryOptions === undefined ? undefined : {
|
|
9690
9821
|
key: memoryOptions.key,
|
|
9691
|
-
service: yield*
|
|
9692
|
-
onNone: () =>
|
|
9693
|
-
message: "RunOptions.memory requires Memory in context",
|
|
9822
|
+
service: yield* Option16.match(memoryService, {
|
|
9823
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9824
|
+
message: options.memory === undefined ? "Agent.memory requires Memory in context" : "RunOptions.memory requires Memory in context",
|
|
9694
9825
|
turn: 0
|
|
9695
9826
|
})),
|
|
9696
|
-
onSome:
|
|
9827
|
+
onSome: Effect46.succeed
|
|
9697
9828
|
})
|
|
9698
9829
|
};
|
|
9699
|
-
const persisted = persistenceOptions === undefined ? undefined : yield*
|
|
9700
|
-
onNone: () =>
|
|
9830
|
+
const persisted = persistenceOptions === undefined ? undefined : yield* Option16.match(persistenceService, {
|
|
9831
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9701
9832
|
message: "RunOptions.persistence requires Chat.Persistence in context",
|
|
9702
9833
|
turn: 0
|
|
9703
9834
|
})),
|
|
9704
|
-
onSome: (service) => service.getOrCreate(persistenceOptions.chatId, persistenceOptions.timeToLive === undefined ? undefined : { timeToLive: persistenceOptions.timeToLive }).pipe(
|
|
9835
|
+
onSome: (service) => service.getOrCreate(persistenceOptions.chatId, persistenceOptions.timeToLive === undefined ? undefined : { timeToLive: persistenceOptions.timeToLive }).pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })))
|
|
9705
9836
|
});
|
|
9706
|
-
const seedSystem = persisted !== undefined && system !== undefined && (yield*
|
|
9837
|
+
const seedSystem = persisted !== undefined && system !== undefined && (yield* Ref11.get(persisted.history)).content.length === 0 ? system : undefined;
|
|
9707
9838
|
const freshChat = options.history !== undefined ? Chat.fromPrompt(options.history) : system !== undefined ? Chat.fromPrompt([Prompt4.makeMessage("system", { content: system })]) : Chat.empty;
|
|
9708
9839
|
const chat = persisted ?? (yield* freshChat);
|
|
9709
|
-
const savePersisted = persisted === undefined ?
|
|
9710
|
-
const failSuspended = (call, token, reason) => Stream7.unwrap(savePersisted.pipe(
|
|
9840
|
+
const savePersisted = persisted === undefined ? Effect46.void : persisted.save.pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })));
|
|
9841
|
+
const failSuspended = (call, token, reason) => Stream7.unwrap(savePersisted.pipe(Effect46.as(Stream7.fail(suspended(call, token, reason)))));
|
|
9711
9842
|
const state = {
|
|
9712
9843
|
text: "",
|
|
9713
9844
|
turn: 0,
|
|
@@ -9720,20 +9851,20 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9720
9851
|
const activatedSkillTools = new Map;
|
|
9721
9852
|
let sessionSyncedMessages = 0;
|
|
9722
9853
|
let sessionInitialized = false;
|
|
9723
|
-
const activeSession =
|
|
9854
|
+
const activeSession = Option16.isSome(compactionService) ? sessionService : Option16.none();
|
|
9724
9855
|
const sessionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9725
9856
|
const compactionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9726
9857
|
const memoryError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9727
9858
|
const skillError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9728
9859
|
const isSkillActivationCall = (call) => call.name === activateSkillToolName && skillRuntime !== undefined && hasActivatableSkills;
|
|
9729
|
-
const insertRecalledItems = (turn, prompt, items) =>
|
|
9860
|
+
const insertRecalledItems = (turn, prompt, items) => Effect46.gen(function* () {
|
|
9730
9861
|
const parts = items.flatMap((item) => item.parts);
|
|
9731
9862
|
if (parts.length === 0)
|
|
9732
9863
|
return prompt;
|
|
9733
9864
|
const userParts = [];
|
|
9734
9865
|
for (const part of parts) {
|
|
9735
9866
|
if (!isUserMessagePart(part)) {
|
|
9736
|
-
return yield*
|
|
9867
|
+
return yield* Effect46.fail(new AgentError({
|
|
9737
9868
|
message: `Memory recalled unsupported prompt part type: ${part.type}`,
|
|
9738
9869
|
turn
|
|
9739
9870
|
}));
|
|
@@ -9744,12 +9875,12 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9744
9875
|
const [first, ...rest] = prompt.content;
|
|
9745
9876
|
return first?.role === "system" ? Prompt4.fromMessages([first, memoryMessage2, ...rest]) : Prompt4.fromMessages([memoryMessage2, ...prompt.content]);
|
|
9746
9877
|
});
|
|
9747
|
-
const recallInitialPrompt = (prompt) => memoryRuntime === undefined ?
|
|
9748
|
-
const rememberTurn = (turn, transcript, terminal) => memoryRuntime === undefined ?
|
|
9749
|
-
const syncSession = (turn, transcript) =>
|
|
9750
|
-
onNone: () =>
|
|
9751
|
-
onSome: (session) =>
|
|
9752
|
-
const existingPath = yield* session.path().pipe(
|
|
9878
|
+
const recallInitialPrompt = (prompt) => memoryRuntime === undefined ? Effect46.succeed(prompt) : memoryRuntime.service.recall({ key: memoryRuntime.key, turn: 0, prompt }).pipe(Effect46.mapError((error) => memoryError(0, error)), Effect46.flatMap((items) => insertRecalledItems(0, prompt, items)));
|
|
9879
|
+
const rememberTurn = (turn, transcript, terminal) => memoryRuntime === undefined ? Effect46.void : memoryRuntime.service.remember({ key: memoryRuntime.key, turn, transcript, terminal }).pipe(Effect46.mapError((error) => memoryError(turn, error)));
|
|
9880
|
+
const syncSession = (turn, transcript) => Option16.match(activeSession, {
|
|
9881
|
+
onNone: () => Effect46.succeed([]),
|
|
9882
|
+
onSome: (session) => Effect46.gen(function* () {
|
|
9883
|
+
const existingPath = yield* session.path().pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9753
9884
|
if (!sessionInitialized) {
|
|
9754
9885
|
sessionInitialized = true;
|
|
9755
9886
|
if (existingPath.length > 0) {
|
|
@@ -9758,40 +9889,40 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9758
9889
|
}
|
|
9759
9890
|
}
|
|
9760
9891
|
for (const message of transcript.content.slice(sessionSyncedMessages)) {
|
|
9761
|
-
yield* session.append({ _tag: "Message", message }).pipe(
|
|
9892
|
+
yield* session.append({ _tag: "Message", message }).pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9762
9893
|
}
|
|
9763
9894
|
sessionSyncedMessages = transcript.content.length;
|
|
9764
|
-
return yield* session.path().pipe(
|
|
9895
|
+
return yield* session.path().pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9765
9896
|
})
|
|
9766
9897
|
});
|
|
9767
9898
|
const countTokens = (turn, prompt) => {
|
|
9768
9899
|
if (state.contextTokens !== undefined)
|
|
9769
|
-
return
|
|
9770
|
-
return
|
|
9771
|
-
onNone: () =>
|
|
9772
|
-
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(
|
|
9900
|
+
return Effect46.succeed(state.contextTokens);
|
|
9901
|
+
return Option16.match(tokenizerService, {
|
|
9902
|
+
onNone: () => Effect46.succeed(0),
|
|
9903
|
+
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(Effect46.map((tokens) => tokens.length), Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn, cause: error })))
|
|
9773
9904
|
});
|
|
9774
9905
|
};
|
|
9775
|
-
const compactionUsage = (turn, history, prompt) => countTokens(turn, Prompt4.concat(history, prompt)).pipe(
|
|
9906
|
+
const compactionUsage = (turn, history, prompt) => countTokens(turn, Prompt4.concat(history, prompt)).pipe(Effect46.map((contextTokens) => ({
|
|
9776
9907
|
contextTokens,
|
|
9777
9908
|
contextWindow: options.compaction?.contextWindow ?? Number.POSITIVE_INFINITY,
|
|
9778
9909
|
reserveTokens: DEFAULT_RESERVE_TOKENS
|
|
9779
9910
|
})));
|
|
9780
|
-
const applyCompactionResult = (turn, result) =>
|
|
9781
|
-
yield*
|
|
9911
|
+
const applyCompactionResult = (turn, result) => Effect46.gen(function* () {
|
|
9912
|
+
yield* Ref11.set(chat.history, result.history);
|
|
9782
9913
|
sessionSyncedMessages = result.history.content.length;
|
|
9783
|
-
if (result._tag === "Summarize" &&
|
|
9914
|
+
if (result._tag === "Summarize" && Option16.isSome(activeSession)) {
|
|
9784
9915
|
yield* activeSession.value.append({
|
|
9785
9916
|
_tag: "Compaction",
|
|
9786
9917
|
summary: result.summary,
|
|
9787
9918
|
firstKeptEntryId: result.firstKeptEntryId
|
|
9788
|
-
}).pipe(
|
|
9919
|
+
}).pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9789
9920
|
}
|
|
9790
9921
|
});
|
|
9791
|
-
const preparePrompt = (turn, prompt, overflow) =>
|
|
9792
|
-
onNone: () =>
|
|
9793
|
-
onSome: (compaction) =>
|
|
9794
|
-
const history = yield*
|
|
9922
|
+
const preparePrompt = (turn, prompt, overflow) => Option16.match(compactionService, {
|
|
9923
|
+
onNone: () => Effect46.succeed(prompt),
|
|
9924
|
+
onSome: (compaction) => Effect46.gen(function* () {
|
|
9925
|
+
const history = yield* Ref11.get(chat.history);
|
|
9795
9926
|
const path2 = yield* syncSession(turn, history);
|
|
9796
9927
|
const usage = yield* compactionUsage(turn, history, prompt);
|
|
9797
9928
|
const compacted = yield* compaction.maybeCompact({
|
|
@@ -9804,28 +9935,28 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9804
9935
|
usage,
|
|
9805
9936
|
overflow,
|
|
9806
9937
|
...options.toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes: options.toolOutputMaxBytes }
|
|
9807
|
-
}).pipe(
|
|
9808
|
-
if (
|
|
9938
|
+
}).pipe(Effect46.mapError((error) => compactionError(turn, error)));
|
|
9939
|
+
if (Option16.isNone(compacted))
|
|
9809
9940
|
return prompt;
|
|
9810
9941
|
yield* applyCompactionResult(turn, compacted.value);
|
|
9811
9942
|
return compacted.value.prompt;
|
|
9812
9943
|
})
|
|
9813
9944
|
});
|
|
9814
|
-
const boundedSuccessResult = (turn, call, outcome) => (options.toolOutputMaxBytes === undefined ?
|
|
9945
|
+
const boundedSuccessResult = (turn, call, outcome) => (options.toolOutputMaxBytes === undefined ? Effect46.succeed(outcome) : bound(outcome, { toolCallId: call.id, maxBytes: options.toolOutputMaxBytes }).pipe(Effect46.mapError((error) => new AgentError({ message: error.message, turn, cause: error })))).pipe(Effect46.map((bounded) => successResult(call, bounded)));
|
|
9815
9946
|
const outcomeEvents = (turn, call, outcome) => {
|
|
9816
9947
|
switch (outcome._tag) {
|
|
9817
9948
|
case "Success":
|
|
9818
|
-
return (isSkillActivationCall(call) ?
|
|
9949
|
+
return (isSkillActivationCall(call) ? Effect46.succeed(successResult(call, outcome)) : boundedSuccessResult(turn, call, outcome)).pipe(Effect46.map((result) => {
|
|
9819
9950
|
state.pending.push(result);
|
|
9820
9951
|
return Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9821
9952
|
}));
|
|
9822
9953
|
case "Failure": {
|
|
9823
9954
|
const result = failedResult(call, outcome.message);
|
|
9824
9955
|
state.pending.push(result);
|
|
9825
|
-
return
|
|
9956
|
+
return Effect46.succeed(Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]));
|
|
9826
9957
|
}
|
|
9827
9958
|
case "Suspend":
|
|
9828
|
-
return
|
|
9959
|
+
return Effect46.succeed(failSuspended(call, outcome.token, "tool-wait"));
|
|
9829
9960
|
}
|
|
9830
9961
|
};
|
|
9831
9962
|
const defaultExecute = (request) => {
|
|
@@ -9833,11 +9964,11 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9833
9964
|
return executeToolkit(agent.toolkit, request);
|
|
9834
9965
|
}
|
|
9835
9966
|
const activated = activatedSkillTools.get(request.call.name);
|
|
9836
|
-
return activated === undefined ?
|
|
9967
|
+
return activated === undefined ? Effect46.succeed({ _tag: "Failure", message: `Tool ${request.call.name} is not registered` }) : executeToolkit(Toolkit3.make(activated), request);
|
|
9837
9968
|
};
|
|
9838
|
-
const executeApproved = (turn, call, request) => Stream7.concat(Stream7.fromIterable([{ _tag: "ToolExecutionStarted", turn, call }]), Stream7.unwrap(
|
|
9969
|
+
const executeApproved = (turn, call, request) => Stream7.concat(Stream7.fromIterable([{ _tag: "ToolExecutionStarted", turn, call }]), Stream7.unwrap(Effect46.gen(function* () {
|
|
9839
9970
|
const progressQueue = yield* Queue2.unbounded();
|
|
9840
|
-
const signal = yield*
|
|
9971
|
+
const signal = yield* Effect46.abortSignal;
|
|
9841
9972
|
const context = ToolContext.of({
|
|
9842
9973
|
signal,
|
|
9843
9974
|
sessionId,
|
|
@@ -9849,14 +9980,14 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9849
9980
|
...progress.message === undefined ? {} : { message: progress.message },
|
|
9850
9981
|
...progress.data === undefined ? {} : { data: progress.data }
|
|
9851
9982
|
};
|
|
9852
|
-
return Queue2.offer(progressQueue, event).pipe(
|
|
9983
|
+
return Queue2.offer(progressQueue, event).pipe(Effect46.asVoid);
|
|
9853
9984
|
}
|
|
9854
9985
|
});
|
|
9855
|
-
const execution = isSkillActivationCall(call) ? activateSkillOutcome(turn, call) :
|
|
9986
|
+
const execution = isSkillActivationCall(call) ? activateSkillOutcome(turn, call) : Option16.match(executor, {
|
|
9856
9987
|
onNone: () => defaultExecute(request),
|
|
9857
9988
|
onSome: (service) => service.execute(request)
|
|
9858
9989
|
});
|
|
9859
|
-
const fiber = yield* execution.pipe(
|
|
9990
|
+
const fiber = yield* execution.pipe(Effect46.provideService(ToolContext, context), Effect46.ensuring(Queue2.end(progressQueue).pipe(Effect46.asVoid)), Effect46.forkScoped({ startImmediately: true }));
|
|
9860
9991
|
return Stream7.concat(Stream7.fromQueue(progressQueue), Stream7.fromEffect(Fiber.join(fiber)).pipe(Stream7.flatMap((outcome) => Stream7.unwrap(outcomeEvents(turn, call, outcome)))));
|
|
9861
9992
|
})));
|
|
9862
9993
|
const permissionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
@@ -9865,13 +9996,13 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9865
9996
|
state.pending.push(result);
|
|
9866
9997
|
return Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9867
9998
|
};
|
|
9868
|
-
const activateSkillOutcome = (turn, call) =>
|
|
9999
|
+
const activateSkillOutcome = (turn, call) => Effect46.gen(function* () {
|
|
9869
10000
|
if (skillRuntime === undefined)
|
|
9870
10001
|
return { _tag: "Failure", message: "SkillSource is not available" };
|
|
9871
|
-
const params =
|
|
9872
|
-
if (
|
|
10002
|
+
const params = Schema48.decodeUnknownOption(activateSkillParameters)(call.params);
|
|
10003
|
+
if (Option16.isNone(params))
|
|
9873
10004
|
return { _tag: "Failure", message: "Skill activation requires a name" };
|
|
9874
|
-
const skill = yield* skillRuntime.source.get(params.value.name).pipe(
|
|
10005
|
+
const skill = yield* skillRuntime.source.get(params.value.name).pipe(Effect46.mapError((error) => skillError(turn, error)));
|
|
9875
10006
|
if (skill === undefined)
|
|
9876
10007
|
return { _tag: "Failure", message: `Skill not found: ${params.value.name}` };
|
|
9877
10008
|
if (skill.frontmatter.disableModelInvocation === true) {
|
|
@@ -9879,7 +10010,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9879
10010
|
}
|
|
9880
10011
|
let body = activatedSkillBodies.get(skill.frontmatter.name);
|
|
9881
10012
|
if (body === undefined) {
|
|
9882
|
-
body = yield* skill.body.pipe(
|
|
10013
|
+
body = yield* skill.body.pipe(Effect46.mapError((error) => skillError(turn, error)));
|
|
9883
10014
|
activatedSkillBodies.set(skill.frontmatter.name, body);
|
|
9884
10015
|
for (const tool2 of skill.tools) {
|
|
9885
10016
|
activatedSkillTools.set(tool2.name, tool2);
|
|
@@ -9892,14 +10023,14 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9892
10023
|
};
|
|
9893
10024
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
9894
10025
|
});
|
|
9895
|
-
const rememberAlways = (turn, call) =>
|
|
9896
|
-
onNone: () =>
|
|
9897
|
-
onSome: (store) => store.remember({ pattern: call.name, level: "allow" }).pipe(
|
|
10026
|
+
const rememberAlways = (turn, call) => Effect46.serviceOption(RuleStore).pipe(Effect46.flatMap(Option16.match({
|
|
10027
|
+
onNone: () => Effect46.void,
|
|
10028
|
+
onSome: (store) => store.remember({ pattern: call.name, level: "allow" }).pipe(Effect46.mapError((error) => permissionError(turn, error)))
|
|
9898
10029
|
})));
|
|
9899
|
-
const approvalEvents = (turn, call, messages, request, tool2) => Stream7.unwrap(approvalRequired(tool2, call, messages).pipe(
|
|
10030
|
+
const approvalEvents = (turn, call, messages, request, tool2) => Stream7.unwrap(approvalRequired(tool2, call, messages).pipe(Effect46.map((isRequired) => {
|
|
9900
10031
|
if (!isRequired)
|
|
9901
10032
|
return executeApproved(turn, call, request);
|
|
9902
|
-
if (
|
|
10033
|
+
if (Option16.isNone(approvals)) {
|
|
9903
10034
|
const result = failedResult(call, "Approvals service is required for approval-gated tools");
|
|
9904
10035
|
state.pending.push(result);
|
|
9905
10036
|
return Stream7.fromIterable([
|
|
@@ -9907,7 +10038,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9907
10038
|
{ _tag: "ToolExecutionCompleted", turn, call, result }
|
|
9908
10039
|
]);
|
|
9909
10040
|
}
|
|
9910
|
-
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(approvals.value.check(request).pipe(
|
|
10041
|
+
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(approvals.value.check(request).pipe(Effect46.map((decision2) => {
|
|
9911
10042
|
switch (decision2._tag) {
|
|
9912
10043
|
case "Approved":
|
|
9913
10044
|
return executeApproved(turn, call, request);
|
|
@@ -9928,7 +10059,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9928
10059
|
case "Denied":
|
|
9929
10060
|
return permissionDeniedEvents(turn, call, answer.reason);
|
|
9930
10061
|
case "Always":
|
|
9931
|
-
return Stream7.unwrap(rememberAlways(turn, call).pipe(
|
|
10062
|
+
return Stream7.unwrap(rememberAlways(turn, call).pipe(Effect46.as(executeApproved(turn, call, request))));
|
|
9932
10063
|
}
|
|
9933
10064
|
};
|
|
9934
10065
|
const permissionAskEvents = (turn, call, request, token) => {
|
|
@@ -9940,9 +10071,9 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9940
10071
|
turn,
|
|
9941
10072
|
toolCallId: call.id
|
|
9942
10073
|
};
|
|
9943
|
-
if (
|
|
10074
|
+
if (Option16.isNone(permissionsService))
|
|
9944
10075
|
return failSuspended(call, token, "approval");
|
|
9945
|
-
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(permissionsService.value.await(pending).pipe(
|
|
10076
|
+
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(permissionsService.value.await(pending).pipe(Effect46.mapError((error) => permissionError(turn, error)), Effect46.map(Option16.match({
|
|
9946
10077
|
onNone: () => failSuspended(call, token, "approval"),
|
|
9947
10078
|
onSome: (answer) => permissionAnsweredEvents(turn, call, request, answer)
|
|
9948
10079
|
})))));
|
|
@@ -9950,7 +10081,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9950
10081
|
const toolCallEvents = (turn, call, messages) => {
|
|
9951
10082
|
const request = { call, turn, agentName: agent.name, sessionId };
|
|
9952
10083
|
const tool2 = currentToolkit().tools[call.name];
|
|
9953
|
-
if (
|
|
10084
|
+
if (Option16.isNone(permissionsService))
|
|
9954
10085
|
return approvalEvents(turn, call, messages, request, tool2);
|
|
9955
10086
|
return Stream7.unwrap(permissionsService.value.evaluate({
|
|
9956
10087
|
tool: call.name,
|
|
@@ -9959,7 +10090,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9959
10090
|
turn,
|
|
9960
10091
|
toolCallId: call.id,
|
|
9961
10092
|
sessionId
|
|
9962
|
-
}).pipe(
|
|
10093
|
+
}).pipe(Effect46.mapError((error) => permissionError(turn, error)), Effect46.map((decision2) => {
|
|
9963
10094
|
switch (decision2._tag) {
|
|
9964
10095
|
case "Allow":
|
|
9965
10096
|
return approvalEvents(turn, call, messages, request, tool2);
|
|
@@ -9970,8 +10101,8 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9970
10101
|
}
|
|
9971
10102
|
})));
|
|
9972
10103
|
};
|
|
9973
|
-
const captureFinishPart = (part) =>
|
|
9974
|
-
const span = yield*
|
|
10104
|
+
const captureFinishPart = (part) => Effect46.gen(function* () {
|
|
10105
|
+
const span = yield* Effect46.currentSpan;
|
|
9975
10106
|
state.finish = {
|
|
9976
10107
|
usage: state.finish === undefined ? part.usage : addUsage(state.finish.usage, part.usage),
|
|
9977
10108
|
reason: part.reason
|
|
@@ -9986,18 +10117,20 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9986
10117
|
},
|
|
9987
10118
|
response: { finishReasons: [part.reason] }
|
|
9988
10119
|
});
|
|
9989
|
-
}).pipe(
|
|
9990
|
-
const captureStructuredUsage = (content) =>
|
|
10120
|
+
}).pipe(Effect46.orDie);
|
|
10121
|
+
const captureStructuredUsage = (content) => Effect46.sync(() => {
|
|
9991
10122
|
for (const part of content) {
|
|
9992
10123
|
if (part.type === "finish") {
|
|
9993
10124
|
state.usage = state.usage === undefined ? part.usage : addUsage(state.usage, part.usage);
|
|
9994
10125
|
}
|
|
9995
10126
|
}
|
|
9996
10127
|
});
|
|
9997
|
-
const withModelResilience = (effect) =>
|
|
10128
|
+
const withModelResilience = (effect) => Option16.match(resilienceService, {
|
|
9998
10129
|
onNone: () => effect,
|
|
9999
|
-
onSome: (resilience) =>
|
|
10130
|
+
onSome: (resilience) => Effect46.flatMap(LanguageModel4.LanguageModel, (model) => effect.pipe(Effect46.provideService(LanguageModel4.LanguageModel, apply(model, resilience))))
|
|
10000
10131
|
});
|
|
10132
|
+
const withAgentModel = (effect) => agentModelContext === undefined ? effect : effect.pipe(Effect46.provide(agentModelContext));
|
|
10133
|
+
const provideAgentModel = (stream2) => agentModelContext === undefined ? stream2 : stream2.pipe(Stream7.provideContext(agentModelContext));
|
|
10001
10134
|
const partEvents = (turn, part, messages) => {
|
|
10002
10135
|
if (part.type === "error") {
|
|
10003
10136
|
return Stream7.fail(new AgentError({ message: errorMessage(part.error), turn, cause: part.error }));
|
|
@@ -10015,7 +10148,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10015
10148
|
}
|
|
10016
10149
|
return modelPart;
|
|
10017
10150
|
};
|
|
10018
|
-
const applyPartToEvents = (turn, part, messages) => Stream7.unwrap(applyPartChain(chain, part, { agentName: agent.name, turn }).pipe(
|
|
10151
|
+
const applyPartToEvents = (turn, part, messages) => Stream7.unwrap(applyPartChain(chain, part, { agentName: agent.name, turn }).pipe(Effect46.map(Option16.match({
|
|
10019
10152
|
onSome: (transformed) => partEvents(turn, transformed, messages),
|
|
10020
10153
|
onNone: () => part.type === "tool-call" ? Stream7.fail(new MiddlewareViolation({
|
|
10021
10154
|
turn,
|
|
@@ -10026,18 +10159,18 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10026
10159
|
const activeToolkit = (activeTools) => Toolkit3.make(...Object.values(currentToolkit().tools).filter((tool2) => activeTools.includes(tool2.name)));
|
|
10027
10160
|
const modelTurn = (turn, prompt, overrides) => {
|
|
10028
10161
|
const toolkit = overrides?.activeTools === undefined ? currentToolkit() : activeToolkit(overrides.activeTools);
|
|
10029
|
-
const attempt = (activePrompt, retryOverflow) => Stream7.unwrap(
|
|
10162
|
+
const attempt = (activePrompt, retryOverflow) => Stream7.unwrap(Ref11.get(chat.history).pipe(Effect46.map((historyBeforeAttempt) => {
|
|
10030
10163
|
let emitted = false;
|
|
10031
10164
|
const messages = Prompt4.concat(historyBeforeAttempt, activePrompt).content;
|
|
10032
|
-
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(Stream7.map((part) => ({ part, messages })), Stream7.tap(() =>
|
|
10165
|
+
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(Stream7.map((part) => ({ part, messages })), Stream7.tap(() => Effect46.sync(() => {
|
|
10033
10166
|
emitted = true;
|
|
10034
10167
|
})), Stream7.catchCause((cause) => {
|
|
10035
10168
|
if (Cause3.hasInterrupts(cause))
|
|
10036
|
-
return Stream7.fromEffect(
|
|
10169
|
+
return Stream7.fromEffect(Effect46.interrupt);
|
|
10037
10170
|
const error = Cause3.squash(cause);
|
|
10038
|
-
if (retryOverflow && !emitted && isContextOverflow(error) &&
|
|
10039
|
-
return Stream7.unwrap(
|
|
10040
|
-
yield*
|
|
10171
|
+
if (retryOverflow && !emitted && isContextOverflow(error) && Option16.isSome(compactionService)) {
|
|
10172
|
+
return Stream7.unwrap(Effect46.gen(function* () {
|
|
10173
|
+
yield* Ref11.set(chat.history, historyBeforeAttempt);
|
|
10041
10174
|
const compactedPrompt = yield* preparePrompt(turn, activePrompt, true);
|
|
10042
10175
|
return attempt(compactedPrompt, false);
|
|
10043
10176
|
}));
|
|
@@ -10045,12 +10178,12 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10045
10178
|
return Stream7.make({ part: Response3.makePart("error", { error }), messages });
|
|
10046
10179
|
}));
|
|
10047
10180
|
})));
|
|
10048
|
-
const parts = Stream7.unwrap(applyPromptChain(chain, Prompt4.make(prompt), { agentName: agent.name, turn }).pipe(
|
|
10049
|
-
const resilientParts =
|
|
10181
|
+
const parts = Stream7.unwrap(applyPromptChain(chain, Prompt4.make(prompt), { agentName: agent.name, turn }).pipe(Effect46.flatMap((transformedPrompt) => preparePrompt(turn, transformedPrompt, false)), Effect46.map((preparedPrompt) => attempt(preparedPrompt, true).pipe(Stream7.flatMap(({ part, messages }) => applyPartToEvents(turn, part, messages))))));
|
|
10182
|
+
const resilientParts = Option16.match(resilienceService, {
|
|
10050
10183
|
onNone: () => parts,
|
|
10051
|
-
onSome: (resilience) => Stream7.unwrap(
|
|
10184
|
+
onSome: (resilience) => Stream7.unwrap(LanguageModel4.LanguageModel.pipe(Effect46.map((model) => parts.pipe(Stream7.provideService(LanguageModel4.LanguageModel, apply(model, resilience))))))
|
|
10052
10185
|
});
|
|
10053
|
-
return overrides?.model === undefined ? resilientParts : resilientParts.pipe(Stream7.provide(overrides.model));
|
|
10186
|
+
return overrides?.model === undefined ? provideAgentModel(resilientParts) : resilientParts.pipe(Stream7.provide(overrides.model));
|
|
10054
10187
|
};
|
|
10055
10188
|
const turnCompletedEvent = (turn, transcript) => ({
|
|
10056
10189
|
_tag: "TurnCompleted",
|
|
@@ -10065,21 +10198,21 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10065
10198
|
transcript,
|
|
10066
10199
|
...state.usage === undefined ? {} : { usage: state.usage }
|
|
10067
10200
|
});
|
|
10068
|
-
const structuredFinalEvents = (turn, config) => Stream7.fromEffect(
|
|
10201
|
+
const structuredFinalEvents = (turn, config) => Stream7.fromEffect(Effect46.gen(function* () {
|
|
10069
10202
|
const structuredTurn = turn + 1;
|
|
10070
10203
|
const transformedPrompt = yield* applyPromptChain(chain, Prompt4.make(config.objectPrompt), {
|
|
10071
10204
|
agentName: agent.name,
|
|
10072
10205
|
turn: structuredTurn
|
|
10073
10206
|
});
|
|
10074
|
-
const response = yield* withModelResilience(chat.generateObject({
|
|
10207
|
+
const response = yield* withAgentModel(withModelResilience(chat.generateObject({
|
|
10075
10208
|
prompt: transformedPrompt,
|
|
10076
10209
|
schema: config.schema,
|
|
10077
10210
|
objectName: config.objectName,
|
|
10078
10211
|
toolChoice: "none"
|
|
10079
|
-
})).pipe(
|
|
10212
|
+
}))).pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: structuredTurn, cause: error })));
|
|
10080
10213
|
yield* captureStructuredUsage(response.content);
|
|
10081
10214
|
yield* savePersisted;
|
|
10082
|
-
const transcript = yield*
|
|
10215
|
+
const transcript = yield* Ref11.get(chat.history);
|
|
10083
10216
|
const structuredOutput = {
|
|
10084
10217
|
_tag: "StructuredOutput",
|
|
10085
10218
|
turn: structuredTurn,
|
|
@@ -10089,16 +10222,16 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10089
10222
|
return [structuredOutput, terminalCompletedEvent(structuredTurn, transcript)];
|
|
10090
10223
|
})).pipe(Stream7.flatMap((events) => Stream7.fromIterable(events)));
|
|
10091
10224
|
const promptFromSteeringMessages = (messages) => messages.reduce((prompt, message) => Prompt4.concat(prompt, message.prompt), Prompt4.empty);
|
|
10092
|
-
const takeSteering = () =>
|
|
10093
|
-
onNone: () =>
|
|
10225
|
+
const takeSteering = () => Option16.match(steeringService, {
|
|
10226
|
+
onNone: () => Effect46.succeed([]),
|
|
10094
10227
|
onSome: (service) => service.takeSteering()
|
|
10095
10228
|
});
|
|
10096
|
-
const takeFollowUp = () =>
|
|
10097
|
-
onNone: () =>
|
|
10229
|
+
const takeFollowUp = () => Option16.match(steeringService, {
|
|
10230
|
+
onNone: () => Effect46.succeed([]),
|
|
10098
10231
|
onSome: (service) => service.takeFollowUp()
|
|
10099
10232
|
});
|
|
10100
|
-
const afterTurn = (turn) =>
|
|
10101
|
-
const transcript = yield*
|
|
10233
|
+
const afterTurn = (turn) => Effect46.gen(function* () {
|
|
10234
|
+
const transcript = yield* Ref11.get(chat.history);
|
|
10102
10235
|
yield* syncSession(turn, transcript);
|
|
10103
10236
|
const pending = state.pending;
|
|
10104
10237
|
yield* rememberTurn(turn, transcript, pending.length === 0);
|
|
@@ -10153,7 +10286,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10153
10286
|
}).pipe(Stream7.drain);
|
|
10154
10287
|
const runTurn = (turn, prompt, overrides) => {
|
|
10155
10288
|
let next;
|
|
10156
|
-
const currentTurn = Stream7.fromIterable([{ _tag: "TurnStarted", turn }]).pipe(Stream7.concat(resetTurnState(turn)), Stream7.concat(modelTurn(turn, prompt, overrides)), Stream7.concat(Stream7.unwrap(afterTurn(turn).pipe(
|
|
10289
|
+
const currentTurn = Stream7.fromIterable([{ _tag: "TurnStarted", turn }]).pipe(Stream7.concat(resetTurnState(turn)), Stream7.concat(modelTurn(turn, prompt, overrides)), Stream7.concat(Stream7.unwrap(afterTurn(turn).pipe(Effect46.map((result) => {
|
|
10157
10290
|
next = result.next;
|
|
10158
10291
|
return result.events;
|
|
10159
10292
|
})))), Stream7.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": turn } }));
|
|
@@ -10167,7 +10300,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10167
10300
|
params: resume.call.params,
|
|
10168
10301
|
providerExecuted: false
|
|
10169
10302
|
});
|
|
10170
|
-
const currentTurn = resetTurnState(0).pipe(Stream7.concat(Stream7.unwrap(
|
|
10303
|
+
const currentTurn = resetTurnState(0).pipe(Stream7.concat(Stream7.unwrap(Ref11.get(chat.history).pipe(Effect46.map((history) => toolCallEvents(0, call, history.content))))), Stream7.concat(Stream7.unwrap(afterTurn(0).pipe(Effect46.map((result) => {
|
|
10171
10304
|
next = result.next;
|
|
10172
10305
|
return result.events;
|
|
10173
10306
|
})))), Stream7.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": 0 } }));
|
|
@@ -10178,10 +10311,10 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10178
10311
|
const runStream = options.resume === undefined ? runTurn(0, initialPrompt) : resumeStream(options.resume);
|
|
10179
10312
|
return runStream.pipe(Stream7.catchCause((cause) => {
|
|
10180
10313
|
if (Cause3.hasInterrupts(cause))
|
|
10181
|
-
return Stream7.fromEffect(
|
|
10314
|
+
return Stream7.fromEffect(Effect46.interrupt);
|
|
10182
10315
|
const error = Cause3.squash(cause);
|
|
10183
10316
|
if (error instanceof AgentSuspended) {
|
|
10184
|
-
return Stream7.unwrap(
|
|
10317
|
+
return Stream7.unwrap(Ref11.get(chat.history).pipe(Effect46.map((transcript) => Stream7.concat(Stream7.fromIterable([turnCompletedEvent(state.turn, transcript)]), Stream7.failCause(cause)))));
|
|
10185
10318
|
}
|
|
10186
10319
|
return Stream7.failCause(cause);
|
|
10187
10320
|
}));
|
|
@@ -10192,29 +10325,29 @@ var streamObject = (agent, options) => streamInternal(agent, options, {
|
|
|
10192
10325
|
objectName: options.objectName ?? "output",
|
|
10193
10326
|
objectPrompt: options.objectPrompt ?? defaultObjectPrompt
|
|
10194
10327
|
});
|
|
10195
|
-
var generate = (agent, options) => Stream7.runLast(stream2(agent, options)).pipe(
|
|
10196
|
-
onNone: () =>
|
|
10197
|
-
onSome: (event) => event._tag === "Completed" ?
|
|
10328
|
+
var generate = (agent, options) => Stream7.runLast(stream2(agent, options)).pipe(Effect46.flatMap(Option16.match({
|
|
10329
|
+
onNone: () => Effect46.fail(new AgentError({ message: "Agent run ended without a Completed event", turn: 0 })),
|
|
10330
|
+
onSome: (event) => event._tag === "Completed" ? Effect46.succeed({ text: event.text, turns: event.turns, transcript: event.transcript }) : Effect46.fail(new AgentError({ message: "Agent run ended without a Completed event", turn: 0 }))
|
|
10198
10331
|
})));
|
|
10199
10332
|
var generateObject = (agent, options) => Stream7.runFold(streamObject(agent, options), () => ({
|
|
10200
|
-
value:
|
|
10201
|
-
completed:
|
|
10333
|
+
value: Option16.none(),
|
|
10334
|
+
completed: Option16.none()
|
|
10202
10335
|
}), (acc, event) => {
|
|
10203
10336
|
if (event._tag === "StructuredOutput") {
|
|
10204
|
-
return { ...acc, value:
|
|
10337
|
+
return { ...acc, value: Option16.some(event.value) };
|
|
10205
10338
|
}
|
|
10206
10339
|
if (event._tag === "Completed") {
|
|
10207
|
-
return { ...acc, completed:
|
|
10340
|
+
return { ...acc, completed: Option16.some(event) };
|
|
10208
10341
|
}
|
|
10209
10342
|
return acc;
|
|
10210
|
-
}).pipe(
|
|
10211
|
-
onNone: () =>
|
|
10212
|
-
onSome: (event) =>
|
|
10213
|
-
onNone: () =>
|
|
10343
|
+
}).pipe(Effect46.flatMap(({ value, completed }) => Option16.match(completed, {
|
|
10344
|
+
onNone: () => Effect46.fail(new AgentError({ message: "Agent object run ended without a Completed event", turn: 0 })),
|
|
10345
|
+
onSome: (event) => Option16.match(value, {
|
|
10346
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
10214
10347
|
message: "Agent object run ended without a StructuredOutput event",
|
|
10215
10348
|
turn: 0
|
|
10216
10349
|
})),
|
|
10217
|
-
onSome: (typedValue) =>
|
|
10350
|
+
onSome: (typedValue) => Effect46.succeed({
|
|
10218
10351
|
text: event.text,
|
|
10219
10352
|
turns: event.turns,
|
|
10220
10353
|
transcript: event.transcript,
|
|
@@ -10222,14 +10355,14 @@ var generateObject = (agent, options) => Stream7.runFold(streamObject(agent, opt
|
|
|
10222
10355
|
})
|
|
10223
10356
|
})
|
|
10224
10357
|
})));
|
|
10225
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10358
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent-tool.ts
|
|
10226
10359
|
var exports_agent_tool = {};
|
|
10227
10360
|
__export(exports_agent_tool, {
|
|
10228
10361
|
asTool: () => asTool
|
|
10229
10362
|
});
|
|
10230
|
-
import { Cause as Cause4, Effect as
|
|
10363
|
+
import { Cause as Cause4, Effect as Effect47, Schema as Schema49 } from "effect";
|
|
10231
10364
|
import { Tool as Tool5, Toolkit as Toolkit4 } from "effect/unstable/ai";
|
|
10232
|
-
var defaultParameters =
|
|
10365
|
+
var defaultParameters = Schema49.Struct({ prompt: Schema49.String });
|
|
10233
10366
|
var errorMessage2 = (error) => {
|
|
10234
10367
|
if (error instanceof AgentSuspended) {
|
|
10235
10368
|
return `suspended on ${error.tool_name}: ${error.reason}`;
|
|
@@ -10248,39 +10381,39 @@ var errorMessage2 = (error) => {
|
|
|
10248
10381
|
var causeMessage = (agentName, cause) => `sub-agent '${agentName}' could not complete: ${errorMessage2(Cause4.squash(cause))}`;
|
|
10249
10382
|
var lazyHandled = (toolkit, name, handler) => ({
|
|
10250
10383
|
tools: toolkit.tools,
|
|
10251
|
-
handle: (toolName, params) => toolkit.pipe(
|
|
10384
|
+
handle: (toolName, params) => toolkit.pipe(Effect47.provide(toolkit.toLayer({
|
|
10252
10385
|
[name]: handler
|
|
10253
|
-
})),
|
|
10386
|
+
})), Effect47.flatMap((handled) => handled.handle(toolName, params)))
|
|
10254
10387
|
});
|
|
10255
10388
|
var asTool = (agent, options = {}) => {
|
|
10256
10389
|
const name = options.name ?? agent.name;
|
|
10257
10390
|
const parameters = options.parameters ?? defaultParameters;
|
|
10258
|
-
const success2 = options.success ??
|
|
10391
|
+
const success2 = options.success ?? Schema49.String;
|
|
10259
10392
|
const toPrompt = options.toPrompt ?? ((params) => params.prompt);
|
|
10260
10393
|
const fromResult = options.fromResult ?? ((result) => result.text);
|
|
10261
10394
|
const tool2 = Tool5.make(name, {
|
|
10262
10395
|
...options.description === undefined ? {} : { description: options.description },
|
|
10263
10396
|
parameters,
|
|
10264
10397
|
success: success2,
|
|
10265
|
-
failure:
|
|
10398
|
+
failure: Schema49.String,
|
|
10266
10399
|
failureMode: "return"
|
|
10267
10400
|
});
|
|
10268
10401
|
const toolkit = Toolkit4.make(tool2);
|
|
10269
|
-
const handler = (params) =>
|
|
10270
|
-
const prompt = yield*
|
|
10271
|
-
const result = yield* generate(agent, { prompt }).pipe(
|
|
10402
|
+
const handler = (params) => Effect47.gen(function* () {
|
|
10403
|
+
const prompt = yield* Effect47.try({ try: () => toPrompt(params), catch: errorMessage2 });
|
|
10404
|
+
const result = yield* generate(agent, { prompt }).pipe(Effect47.catchCause((cause) => {
|
|
10272
10405
|
if (Cause4.hasInterrupts(cause))
|
|
10273
|
-
return
|
|
10406
|
+
return Effect47.interrupt;
|
|
10274
10407
|
const error = Cause4.squash(cause);
|
|
10275
10408
|
if (error instanceof AgentSuspended)
|
|
10276
|
-
return
|
|
10277
|
-
return
|
|
10409
|
+
return Effect47.die(error);
|
|
10410
|
+
return Effect47.fail(causeMessage(agent.name, cause));
|
|
10278
10411
|
}));
|
|
10279
|
-
return yield*
|
|
10412
|
+
return yield* Effect47.try({ try: () => fromResult(result), catch: errorMessage2 });
|
|
10280
10413
|
});
|
|
10281
10414
|
return lazyHandled(toolkit, name, handler);
|
|
10282
10415
|
};
|
|
10283
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10416
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/guardrail.ts
|
|
10284
10417
|
var exports_guardrail = {};
|
|
10285
10418
|
__export(exports_guardrail, {
|
|
10286
10419
|
validateInput: () => validateInput2,
|
|
@@ -10288,7 +10421,7 @@ __export(exports_guardrail, {
|
|
|
10288
10421
|
redactInput: () => redactInput,
|
|
10289
10422
|
filterOutput: () => filterOutput
|
|
10290
10423
|
});
|
|
10291
|
-
import { Effect as
|
|
10424
|
+
import { Effect as Effect48, Option as Option17 } from "effect";
|
|
10292
10425
|
import { Prompt as Prompt6, Response as Response4 } from "effect/unstable/ai";
|
|
10293
10426
|
var replacement = (options) => options.replacement ?? "[redacted]";
|
|
10294
10427
|
var redactText = (text3, options) => text3.replace(options.pattern, replacement(options));
|
|
@@ -10338,19 +10471,19 @@ var redactPromptText = (prompt, options) => Prompt6.fromMessages(prompt.content.
|
|
|
10338
10471
|
}
|
|
10339
10472
|
}));
|
|
10340
10473
|
var validateInput2 = (check2) => ({
|
|
10341
|
-
transformPrompt: (prompt, context) => check2(prompt, context).pipe(
|
|
10342
|
-
onNone: () =>
|
|
10343
|
-
onSome: (reason) =>
|
|
10474
|
+
transformPrompt: (prompt, context) => check2(prompt, context).pipe(Effect48.flatMap(Option17.match({
|
|
10475
|
+
onNone: () => Effect48.succeed(prompt),
|
|
10476
|
+
onSome: (reason) => Effect48.fail(new AgentError({ message: `Input guardrail blocked: ${reason}`, turn: context.turn }))
|
|
10344
10477
|
})))
|
|
10345
10478
|
});
|
|
10346
10479
|
var redactInput = (options) => ({
|
|
10347
|
-
transformPrompt: (prompt) =>
|
|
10480
|
+
transformPrompt: (prompt) => Effect48.succeed(redactPromptText(prompt, options))
|
|
10348
10481
|
});
|
|
10349
10482
|
var redactOutput = (options) => ({
|
|
10350
10483
|
transformPart: (part) => {
|
|
10351
10484
|
if (part.type !== "text-delta")
|
|
10352
|
-
return
|
|
10353
|
-
return
|
|
10485
|
+
return Effect48.succeed(Option17.some(part));
|
|
10486
|
+
return Effect48.succeed(Option17.some(Response4.makePart("text-delta", {
|
|
10354
10487
|
id: part.id,
|
|
10355
10488
|
delta: redactText(part.delta, options),
|
|
10356
10489
|
metadata: part.metadata
|
|
@@ -10358,22 +10491,22 @@ var redactOutput = (options) => ({
|
|
|
10358
10491
|
}
|
|
10359
10492
|
});
|
|
10360
10493
|
var filterOutput = (keep) => ({
|
|
10361
|
-
transformPart: (part, context) =>
|
|
10494
|
+
transformPart: (part, context) => Effect48.succeed(part.type === "tool-call" || keep(part, context) ? Option17.some(part) : Option17.none())
|
|
10362
10495
|
});
|
|
10363
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10496
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/handoff.ts
|
|
10364
10497
|
var exports_handoff = {};
|
|
10365
10498
|
__export(exports_handoff, {
|
|
10366
10499
|
transferTool: () => transferTool,
|
|
10367
10500
|
supervisor: () => supervisor,
|
|
10368
10501
|
fanOut: () => fanOut
|
|
10369
10502
|
});
|
|
10370
|
-
import { Effect as
|
|
10503
|
+
import { Effect as Effect49, Schema as Schema50 } from "effect";
|
|
10371
10504
|
import { AiError as AiError2, Toolkit as Toolkit5 } from "effect/unstable/ai";
|
|
10372
|
-
var defaultTransferParameters =
|
|
10505
|
+
var defaultTransferParameters = Schema50.Struct({ prompt: Schema50.String });
|
|
10373
10506
|
var transferName = (agentName) => `transfer_to_${agentName}`;
|
|
10374
10507
|
var positiveConcurrency = (value) => {
|
|
10375
10508
|
const concurrency = value ?? 4;
|
|
10376
|
-
return Number.isInteger(concurrency) && concurrency > 0 ?
|
|
10509
|
+
return Number.isInteger(concurrency) && concurrency > 0 ? Effect49.succeed(concurrency) : Effect49.fail(new AgentError({
|
|
10377
10510
|
message: "Handoff.fanOut concurrency must be a positive integer",
|
|
10378
10511
|
turn: 0
|
|
10379
10512
|
}));
|
|
@@ -10387,7 +10520,7 @@ var mergeHandled = (toolkits) => {
|
|
|
10387
10520
|
tools,
|
|
10388
10521
|
handle: (name, params) => {
|
|
10389
10522
|
const toolkit = toolkits.find((candidate) => candidate.tools[name] !== undefined);
|
|
10390
|
-
return toolkit === undefined ?
|
|
10523
|
+
return toolkit === undefined ? Effect49.fail(AiError2.make({
|
|
10391
10524
|
module: "Handoff",
|
|
10392
10525
|
method: `${String(name)}.handle`,
|
|
10393
10526
|
reason: new AiError2.ToolNotFoundError({
|
|
@@ -10407,7 +10540,7 @@ var transferTool = (target, options = {}) => asTool(target, {
|
|
|
10407
10540
|
...options.toPrompt === undefined ? {} : { toPrompt: options.toPrompt },
|
|
10408
10541
|
...options.fromResult === undefined ? {} : { fromResult: options.fromResult }
|
|
10409
10542
|
});
|
|
10410
|
-
var fanOut = (children, options = {}) => positiveConcurrency(options.concurrency).pipe(
|
|
10543
|
+
var fanOut = (children, options = {}) => positiveConcurrency(options.concurrency).pipe(Effect49.flatMap((concurrency) => Effect49.forEach(children, (child) => generate(child.agent, { ...child.options, prompt: child.prompt }), {
|
|
10411
10544
|
concurrency
|
|
10412
10545
|
})));
|
|
10413
10546
|
var supervisor = (options) => {
|
|
@@ -10423,96 +10556,8 @@ var supervisor = (options) => {
|
|
|
10423
10556
|
toolkit
|
|
10424
10557
|
};
|
|
10425
10558
|
};
|
|
10426
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.3/node_modules/@batonfx/core/src/model-registry.ts
|
|
10427
|
-
var exports_model_registry = {};
|
|
10428
|
-
__export(exports_model_registry, {
|
|
10429
|
-
testLayer: () => testLayer38,
|
|
10430
|
-
registrations: () => registrations,
|
|
10431
|
-
registrationFromLayer: () => registrationFromLayer,
|
|
10432
|
-
register: () => register4,
|
|
10433
|
-
provide: () => provide,
|
|
10434
|
-
memoryLayer: () => memoryLayer25,
|
|
10435
|
-
layerFromRegistrationEffects: () => layerFromRegistrationEffects,
|
|
10436
|
-
layer: () => layer31,
|
|
10437
|
-
combine: () => combine,
|
|
10438
|
-
Service: () => Service29,
|
|
10439
|
-
LanguageModelNotRegistered: () => LanguageModelNotRegistered
|
|
10440
|
-
});
|
|
10441
|
-
import { Chunk as Chunk2, Context as Context42, Effect as Effect49, Layer as Layer43, Option as Option17, Ref as Ref11, Schema as Schema50, Semaphore as Semaphore3 } from "effect";
|
|
10442
|
-
import { Model } from "effect/unstable/ai";
|
|
10443
|
-
|
|
10444
|
-
class LanguageModelNotRegistered extends Schema50.TaggedErrorClass()("LanguageModelNotRegistered", {
|
|
10445
|
-
provider: Schema50.String,
|
|
10446
|
-
model: Schema50.String,
|
|
10447
|
-
registration_key: Schema50.optionalKey(Schema50.String)
|
|
10448
|
-
}) {
|
|
10449
|
-
}
|
|
10450
10559
|
|
|
10451
|
-
|
|
10452
|
-
}
|
|
10453
|
-
var registrationVariantKey = (value) => value.registrationKey ?? null;
|
|
10454
|
-
var selectionVariantKey = (selection) => selection.registrationKey ?? null;
|
|
10455
|
-
var registryIdentity = (registration) => JSON.stringify([registration.provider, registration.model, registrationVariantKey(registration)]);
|
|
10456
|
-
var matchesSelection = (selection) => (registration) => registration.provider === selection.provider && registration.model === selection.model && registrationVariantKey(registration) === selectionVariantKey(selection);
|
|
10457
|
-
var upsertRegistration = (registry, registration) => {
|
|
10458
|
-
const key2 = registryIdentity(registration);
|
|
10459
|
-
const exists = Option17.isSome(Chunk2.findFirst(registry, (item) => registryIdentity(item) === key2));
|
|
10460
|
-
if (!exists)
|
|
10461
|
-
return Chunk2.append(registry, registration);
|
|
10462
|
-
return Chunk2.map(registry, (item) => registryIdentity(item) === key2 ? registration : item);
|
|
10463
|
-
};
|
|
10464
|
-
var findRegistration = (registry, selection) => Chunk2.findFirst(registry, matchesSelection(selection)).pipe(Option17.getOrUndefined);
|
|
10465
|
-
var registrationFromLayer = (input) => Model.make(input.provider, input.model, input.layer).captureRequirements.pipe(Effect49.map((layer31) => ({
|
|
10466
|
-
provider: input.provider,
|
|
10467
|
-
model: input.model,
|
|
10468
|
-
layer: layer31,
|
|
10469
|
-
...input.registrationKey === undefined ? {} : { registrationKey: input.registrationKey },
|
|
10470
|
-
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
10471
|
-
})));
|
|
10472
|
-
var layer31 = (initialRegistrations = [], options) => Layer43.effect(Service29, Effect49.gen(function* () {
|
|
10473
|
-
const registry = yield* Ref11.make(initialRegistrations.reduce(upsertRegistration, Chunk2.empty()));
|
|
10474
|
-
const semaphore = options?.maxConcurrentModelCalls === undefined ? undefined : yield* Semaphore3.make(options.maxConcurrentModelCalls);
|
|
10475
|
-
const register4 = Effect49.fn("ModelRegistry.register")(function* (input) {
|
|
10476
|
-
yield* Ref11.update(registry, (items) => upsertRegistration(items, input.registration));
|
|
10477
|
-
});
|
|
10478
|
-
const registrations = Ref11.get(registry).pipe(Effect49.map(Chunk2.toReadonlyArray));
|
|
10479
|
-
const provide = Effect49.fn("ModelRegistry.provide")(function* (selection, effect) {
|
|
10480
|
-
const items = yield* Ref11.get(registry);
|
|
10481
|
-
const registration = findRegistration(items, selection);
|
|
10482
|
-
if (registration === undefined) {
|
|
10483
|
-
return yield* Effect49.fail(new LanguageModelNotRegistered({
|
|
10484
|
-
provider: selection.provider,
|
|
10485
|
-
model: selection.model,
|
|
10486
|
-
...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
|
|
10487
|
-
}));
|
|
10488
|
-
}
|
|
10489
|
-
const provided = effect.pipe(Effect49.provide(registration.layer));
|
|
10490
|
-
return yield* semaphore === undefined ? provided : semaphore.withPermits(1)(provided);
|
|
10491
|
-
});
|
|
10492
|
-
return Service29.of({
|
|
10493
|
-
register: register4,
|
|
10494
|
-
registrations,
|
|
10495
|
-
provide
|
|
10496
|
-
});
|
|
10497
|
-
}));
|
|
10498
|
-
var layerFromRegistrationEffects = (registrations, options) => Layer43.unwrap(Effect49.all(registrations).pipe(Effect49.map((items) => layer31(items, options))));
|
|
10499
|
-
var combine = (registries, options) => Layer43.unwrap(Effect49.forEach(registries, (registry) => Layer43.build(registry).pipe(Effect49.flatMap((context) => Context42.get(context, Service29).registrations))).pipe(Effect49.map((groups) => layer31(groups.flat(), options))));
|
|
10500
|
-
var memoryLayer25 = layer31;
|
|
10501
|
-
var testLayer38 = (implementation) => Layer43.succeed(Service29, Service29.of(implementation));
|
|
10502
|
-
var register4 = Effect49.fn("ModelRegistry.register.call")(function* (input) {
|
|
10503
|
-
const service = yield* Service29;
|
|
10504
|
-
return yield* service.register(input);
|
|
10505
|
-
});
|
|
10506
|
-
var registrations = Effect49.fn("ModelRegistry.registrations.call")(function* () {
|
|
10507
|
-
const service = yield* Service29;
|
|
10508
|
-
return yield* service.registrations;
|
|
10509
|
-
});
|
|
10510
|
-
var provide = (selection, effect) => Effect49.gen(function* () {
|
|
10511
|
-
const service = yield* Service29;
|
|
10512
|
-
return yield* service.provide(selection, effect);
|
|
10513
|
-
});
|
|
10514
|
-
|
|
10515
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.3/node_modules/@batonfx/core/src/index.ts
|
|
10560
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/index.ts
|
|
10516
10561
|
import {
|
|
10517
10562
|
AiError as AiError3,
|
|
10518
10563
|
Chat as Chat2,
|
|
@@ -11308,7 +11353,15 @@ var make6 = (options = {}) => Effect54.gen(function* () {
|
|
|
11308
11353
|
createdAt
|
|
11309
11354
|
}).pipe(Effect54.mapError(memoryError));
|
|
11310
11355
|
});
|
|
11311
|
-
|
|
11356
|
+
const forget2 = Effect54.fn("MemoryService.forget")(function* (input) {
|
|
11357
|
+
const subject = yield* decodeSubject(input.key.subject);
|
|
11358
|
+
yield* repository.forget({
|
|
11359
|
+
agent: input.key.agent,
|
|
11360
|
+
subject,
|
|
11361
|
+
...input.id === undefined ? {} : { id: input.id }
|
|
11362
|
+
}).pipe(Effect54.mapError(memoryError));
|
|
11363
|
+
});
|
|
11364
|
+
return { recall, remember: remember2, forget: forget2 };
|
|
11312
11365
|
});
|
|
11313
11366
|
var serviceLayer = (options) => Layer47.effect(Service33, make6(options).pipe(Effect54.map(Service33.of)));
|
|
11314
11367
|
var batonLayer = Layer47.effect(exports_memory.Memory, Effect54.gen(function* () {
|
|
@@ -11324,6 +11377,10 @@ var remember2 = Effect54.fn("MemoryService.remember.call")(function* (input) {
|
|
|
11324
11377
|
const service = yield* Service33;
|
|
11325
11378
|
return yield* service.remember(input);
|
|
11326
11379
|
});
|
|
11380
|
+
var forget2 = Effect54.fn("MemoryService.forget.call")(function* (input) {
|
|
11381
|
+
const service = yield* Service33;
|
|
11382
|
+
return yield* service.forget(input);
|
|
11383
|
+
});
|
|
11327
11384
|
|
|
11328
11385
|
// ../runtime/src/model/language-model-service.ts
|
|
11329
11386
|
var exports_language_model_service = {};
|
|
@@ -12639,7 +12696,8 @@ var terminalMemoryTranscript = (prompt, text3) => {
|
|
|
12639
12696
|
};
|
|
12640
12697
|
var recallOnlyMemory = (memory) => exports_memory.Memory.of({
|
|
12641
12698
|
recall: memory.recall,
|
|
12642
|
-
remember: () => Effect67.void
|
|
12699
|
+
remember: () => Effect67.void,
|
|
12700
|
+
forget: () => Effect67.void
|
|
12643
12701
|
});
|
|
12644
12702
|
var metadataValue = (metadata11, key2) => metadata11?.[key2];
|
|
12645
12703
|
var decodeOptionalNumber = (value, key2, valid) => {
|
|
@@ -15735,14 +15793,42 @@ var toolRefsFromBatonAgent = (agent) => {
|
|
|
15735
15793
|
const tools = agent.toolkit.tools;
|
|
15736
15794
|
return Object.values(tools).map((tool2) => ({ name: tool2.name }));
|
|
15737
15795
|
};
|
|
15738
|
-
var
|
|
15796
|
+
var modelSelectionFromBatonAgent = (selection) => ({
|
|
15797
|
+
provider: selection.provider,
|
|
15798
|
+
model: selection.model,
|
|
15799
|
+
...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
|
|
15800
|
+
});
|
|
15801
|
+
var decodeBatonAgentName = (name) => Schema75.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect79.mapError(() => new ClientError({ message: "Baton agent name must not be blank" })));
|
|
15802
|
+
var decodeBatonAgentMetadata = (metadata11) => metadata11 === undefined ? Effect79.succeed(undefined) : Schema75.decodeUnknownEffect(exports_shared_schema.Metadata)(metadata11).pipe(Effect79.mapError(() => new ClientError({ message: "Baton agent metadata must be JSON metadata" })));
|
|
15803
|
+
var decodeBatonMemorySubject = (subject) => Schema75.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect79.mapError(() => new ClientError({ message: "Baton agent memory subject must be a MemorySubjectId" })));
|
|
15804
|
+
var metadataFromBatonAgent = Effect79.fn("Client.metadataFromBatonAgent")(function* (input) {
|
|
15805
|
+
const agentMetadata = yield* decodeBatonAgentMetadata(input.agent.metadata);
|
|
15806
|
+
const memorySubject = input.agent.memory === undefined ? undefined : yield* decodeBatonMemorySubject(input.agent.memory.subject);
|
|
15807
|
+
const metadata11 = {
|
|
15808
|
+
...agentMetadata,
|
|
15809
|
+
...memorySubject === undefined ? {} : { memory_subject_id: memorySubject },
|
|
15810
|
+
...input.metadata
|
|
15811
|
+
};
|
|
15812
|
+
return Object.keys(metadata11).length === 0 ? undefined : metadata11;
|
|
15813
|
+
});
|
|
15814
|
+
var modelSelectionFromRegisterInput = (input) => {
|
|
15815
|
+
if (input.model !== undefined)
|
|
15816
|
+
return Effect79.succeed(input.model);
|
|
15817
|
+
if (input.agent.model !== undefined)
|
|
15818
|
+
return Effect79.succeed(modelSelectionFromBatonAgent(input.agent.model));
|
|
15819
|
+
return Effect79.fail(new ClientError({ message: "Client.registerAgent requires model or agent.model" }));
|
|
15820
|
+
};
|
|
15821
|
+
var registerAgentPayload = Effect79.fn("Client.registerAgentPayload")(function* (input) {
|
|
15739
15822
|
if (!isRegisterBatonAgentInput(input))
|
|
15740
15823
|
return exports_agent_schema.define(input);
|
|
15824
|
+
const name = yield* decodeBatonAgentName(input.agent.name);
|
|
15825
|
+
const model = yield* modelSelectionFromRegisterInput(input);
|
|
15826
|
+
const metadata11 = yield* metadataFromBatonAgent(input);
|
|
15741
15827
|
return exports_agent_schema.define({
|
|
15742
15828
|
id: input.id,
|
|
15743
|
-
name
|
|
15829
|
+
name,
|
|
15744
15830
|
...input.agent.instructions === undefined ? {} : { instructions: input.agent.instructions },
|
|
15745
|
-
model
|
|
15831
|
+
model,
|
|
15746
15832
|
tools: toolRefsFromBatonAgent(input.agent),
|
|
15747
15833
|
permissions: input.permissions ?? [],
|
|
15748
15834
|
...input.skill_definition_ids === undefined ? {} : { skill_definition_ids: input.skill_definition_ids },
|
|
@@ -15753,9 +15839,9 @@ var registerAgentPayload = (input) => {
|
|
|
15753
15839
|
...input.child_run_presets === undefined ? {} : { child_run_presets: input.child_run_presets },
|
|
15754
15840
|
...input.handoff_targets === undefined ? {} : { handoff_targets: input.handoff_targets },
|
|
15755
15841
|
...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
|
|
15756
|
-
...
|
|
15842
|
+
...metadata11 === undefined ? {} : { metadata: metadata11 }
|
|
15757
15843
|
});
|
|
15758
|
-
};
|
|
15844
|
+
});
|
|
15759
15845
|
var agentDefinitionNotFound = (id2) => new ClientError({ message: `Agent not found: ${id2}` });
|
|
15760
15846
|
var wakeMetadata = (input) => ({
|
|
15761
15847
|
...input.metadata,
|
|
@@ -15893,7 +15979,7 @@ var layerFromRuntime = Layer70.effect(Service50, Effect79.gen(function* () {
|
|
|
15893
15979
|
const skillRegistry = yield* exports_skill_registry_service.Service;
|
|
15894
15980
|
return Service50.of({
|
|
15895
15981
|
registerAgent: Effect79.fn("Client.runtime.registerAgent")(function* (input) {
|
|
15896
|
-
const payload = registerAgentPayload(input);
|
|
15982
|
+
const payload = yield* registerAgentPayload(input);
|
|
15897
15983
|
const registered = yield* agentRegistry.register(payload).pipe(Effect79.mapError(toClientError));
|
|
15898
15984
|
if (input.address !== undefined) {
|
|
15899
15985
|
yield* addressBook.register(input.address, { kind: "local-agent", route_key: payload.id }).pipe(Effect79.mapError(toClientError));
|
|
@@ -16720,7 +16806,7 @@ __export(exports_language_model_registration, {
|
|
|
16720
16806
|
anthropic: () => anthropic
|
|
16721
16807
|
});
|
|
16722
16808
|
|
|
16723
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16809
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/anthropic.ts
|
|
16724
16810
|
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic";
|
|
16725
16811
|
import { Layer as Layer72 } from "effect";
|
|
16726
16812
|
import { FetchHttpClient as FetchHttpClient2 } from "effect/unstable/http";
|
|
@@ -16736,13 +16822,13 @@ var anthropic = (input) => exports_model_registry.registrationFromLayer({
|
|
|
16736
16822
|
});
|
|
16737
16823
|
var anthropicClientLayerConfig = AnthropicClient.layerConfig;
|
|
16738
16824
|
var withAnthropic = (options) => exports_model_registry.layerFromRegistrationEffects([anthropic(options)]).pipe(Layer72.provide(AnthropicClient.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer72.provide(FetchHttpClient2.layer));
|
|
16739
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16825
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/deterministic.ts
|
|
16740
16826
|
import { OpenAiClient as OpenAiClient3 } from "@effect/ai-openai";
|
|
16741
16827
|
import { Effect as Effect81, Layer as Layer74, Option as Option29, Stream as Stream12 } from "effect";
|
|
16742
16828
|
import { LanguageModel as LanguageModel8, Response as Response7 } from "effect/unstable/ai";
|
|
16743
16829
|
import { FetchHttpClient as FetchHttpClient4 } from "effect/unstable/http";
|
|
16744
16830
|
|
|
16745
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16831
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openai.ts
|
|
16746
16832
|
import { OpenAiClient as OpenAiClient2, OpenAiLanguageModel } from "@effect/ai-openai";
|
|
16747
16833
|
import { Layer as Layer73 } from "effect";
|
|
16748
16834
|
import { FetchHttpClient as FetchHttpClient3 } from "effect/unstable/http";
|
|
@@ -16759,7 +16845,7 @@ var openAi = (input) => exports_model_registry.registrationFromLayer({
|
|
|
16759
16845
|
var openAiClientLayerConfig2 = OpenAiClient2.layerConfig;
|
|
16760
16846
|
var withOpenAi = (options) => exports_model_registry.layerFromRegistrationEffects([openAi(options)]).pipe(Layer73.provide(OpenAiClient2.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer73.provide(FetchHttpClient3.layer));
|
|
16761
16847
|
|
|
16762
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16848
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/deterministic.ts
|
|
16763
16849
|
var deterministicModelLayer = Layer74.effect(LanguageModel8.LanguageModel, LanguageModel8.make({
|
|
16764
16850
|
generateText: () => Effect81.succeed([{ type: "text", text: "deterministic response" }]),
|
|
16765
16851
|
streamText: () => Stream12.make(Response7.makePart("text-delta", { id: "text", delta: "deterministic response" }))
|
|
@@ -16783,7 +16869,7 @@ var withOpenAiOrDeterministic = (options) => Layer74.unwrap(Effect81.gen(functio
|
|
|
16783
16869
|
...Option29.isSome(openAiRegistration) ? [openAiRegistration.value] : []
|
|
16784
16870
|
]);
|
|
16785
16871
|
}));
|
|
16786
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16872
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openai-compat.ts
|
|
16787
16873
|
import { OpenAiClient as OpenAiClient4, OpenAiLanguageModel as OpenAiLanguageModel2 } from "@effect/ai-openai-compat";
|
|
16788
16874
|
import { Config as Config8, Layer as Layer75 } from "effect";
|
|
16789
16875
|
import { FetchHttpClient as FetchHttpClient5 } from "effect/unstable/http";
|
|
@@ -16804,7 +16890,7 @@ var clientLayerConfig = (options) => OpenAiClient4.layerConfig({
|
|
|
16804
16890
|
...options.baseUrl === undefined ? {} : { apiUrl: Config8.succeed(options.baseUrl) }
|
|
16805
16891
|
});
|
|
16806
16892
|
var withOpenAiCompatible = (options) => exports_model_registry.layerFromRegistrationEffects([openAiCompatible(options)]).pipe(Layer75.provide(clientLayerConfig(options)), Layer75.provide(FetchHttpClient5.layer));
|
|
16807
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
16893
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openrouter.ts
|
|
16808
16894
|
import { OpenRouterClient, OpenRouterLanguageModel } from "@effect/ai-openrouter";
|
|
16809
16895
|
import { Layer as Layer76 } from "effect";
|
|
16810
16896
|
import { FetchHttpClient as FetchHttpClient6 } from "effect/unstable/http";
|