@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/ai.js
CHANGED
|
@@ -3500,6 +3500,7 @@ __export(exports_memory_repository, {
|
|
|
3500
3500
|
query: () => query,
|
|
3501
3501
|
memoryLayer: () => memoryLayer11,
|
|
3502
3502
|
layer: () => layer13,
|
|
3503
|
+
forget: () => forget,
|
|
3503
3504
|
Service: () => Service14,
|
|
3504
3505
|
MemoryRow: () => MemoryRow,
|
|
3505
3506
|
MemoryRepositoryError: () => MemoryRepositoryError
|
|
@@ -3668,7 +3669,17 @@ var layer13 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
|
3668
3669
|
const decoded = yield* Effect14.forEach(rows, decodeRow9);
|
|
3669
3670
|
return yield* rankMatches(decoded.map(toRecord7), input.embedding, input.topK);
|
|
3670
3671
|
});
|
|
3671
|
-
|
|
3672
|
+
const forget = Effect14.fn("MemoryRepository.forget")(function* (input) {
|
|
3673
|
+
const tenantId = yield* current();
|
|
3674
|
+
yield* (input.id === undefined ? sql2`
|
|
3675
|
+
DELETE FROM relay_memory_records
|
|
3676
|
+
WHERE tenant_id = ${tenantId} AND agent = ${input.agent} AND subject = ${input.subject}
|
|
3677
|
+
` : sql2`
|
|
3678
|
+
DELETE FROM relay_memory_records
|
|
3679
|
+
WHERE tenant_id = ${tenantId} AND agent = ${input.agent} AND subject = ${input.subject} AND id = ${input.id}
|
|
3680
|
+
`).pipe(Effect14.asVoid, Effect14.mapError(toRepositoryError10));
|
|
3681
|
+
});
|
|
3682
|
+
return Service14.of({ upsert: upsert2, query, forget });
|
|
3672
3683
|
}));
|
|
3673
3684
|
var memoryLayer11 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
3674
3685
|
const records = yield* Ref2.make(new Map);
|
|
@@ -3698,7 +3709,20 @@ var memoryLayer11 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
|
3698
3709
|
const scoped = Array.from(current2.values()).filter((record2) => record2.agent === input.agent && record2.subject === input.subject).map(cloneRecord4);
|
|
3699
3710
|
return yield* rankMatches(scoped, input.embedding, input.topK);
|
|
3700
3711
|
});
|
|
3701
|
-
|
|
3712
|
+
const forget = Effect14.fn("MemoryRepository.memory.forget")(function* (input) {
|
|
3713
|
+
yield* Ref2.update(records, (current2) => {
|
|
3714
|
+
const next = new Map(current2);
|
|
3715
|
+
for (const [id2, record2] of current2) {
|
|
3716
|
+
if (record2.agent !== input.agent || record2.subject !== input.subject)
|
|
3717
|
+
continue;
|
|
3718
|
+
if (input.id !== undefined && id2 !== input.id)
|
|
3719
|
+
continue;
|
|
3720
|
+
next.delete(id2);
|
|
3721
|
+
}
|
|
3722
|
+
return next;
|
|
3723
|
+
});
|
|
3724
|
+
});
|
|
3725
|
+
return Service14.of({ upsert: upsert2, query, forget });
|
|
3702
3726
|
}));
|
|
3703
3727
|
var testLayer11 = (implementation) => Layer14.succeed(Service14, Service14.of(implementation));
|
|
3704
3728
|
var upsert2 = Effect14.fn("MemoryRepository.upsert.call")(function* (input) {
|
|
@@ -3709,6 +3733,10 @@ var query = Effect14.fn("MemoryRepository.query.call")(function* (input) {
|
|
|
3709
3733
|
const repository = yield* Service14;
|
|
3710
3734
|
return yield* repository.query(input);
|
|
3711
3735
|
});
|
|
3736
|
+
var forget = Effect14.fn("MemoryRepository.forget.call")(function* (input) {
|
|
3737
|
+
const repository = yield* Service14;
|
|
3738
|
+
return yield* repository.forget(input);
|
|
3739
|
+
});
|
|
3712
3740
|
// ../store-sql/src/permission/permission-rule-repository.ts
|
|
3713
3741
|
var exports_permission_rule_repository = {};
|
|
3714
3742
|
__export(exports_permission_rule_repository, {
|
|
@@ -8400,7 +8428,7 @@ __export(exports_agent_loop_service, {
|
|
|
8400
8428
|
AgentLoopBudgetExceeded: () => AgentLoopBudgetExceeded
|
|
8401
8429
|
});
|
|
8402
8430
|
|
|
8403
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8431
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent.ts
|
|
8404
8432
|
var exports_agent = {};
|
|
8405
8433
|
__export(exports_agent, {
|
|
8406
8434
|
streamObject: () => streamObject,
|
|
@@ -8410,10 +8438,10 @@ __export(exports_agent, {
|
|
|
8410
8438
|
generate: () => generate,
|
|
8411
8439
|
defaultObjectPrompt: () => defaultObjectPrompt
|
|
8412
8440
|
});
|
|
8413
|
-
import { Cause as Cause3, Effect as
|
|
8414
|
-
import { Chat, LanguageModel as
|
|
8441
|
+
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";
|
|
8442
|
+
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";
|
|
8415
8443
|
|
|
8416
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8444
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent-event.ts
|
|
8417
8445
|
var exports_agent_event = {};
|
|
8418
8446
|
__export(exports_agent_event, {
|
|
8419
8447
|
addUsage: () => addUsage,
|
|
@@ -8470,7 +8498,7 @@ class AgentSuspended extends Schema38.TaggedErrorClass()("@batonfx/core/AgentSus
|
|
|
8470
8498
|
}) {
|
|
8471
8499
|
}
|
|
8472
8500
|
|
|
8473
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8501
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/approvals.ts
|
|
8474
8502
|
var exports_approvals = {};
|
|
8475
8503
|
__export(exports_approvals, {
|
|
8476
8504
|
testLayer: () => testLayer26,
|
|
@@ -8486,7 +8514,7 @@ var autoApprove = Layer29.succeed(Approvals, Approvals.of({ check: () => Effect3
|
|
|
8486
8514
|
var denyAll = Layer29.succeed(Approvals, Approvals.of({ check: () => Effect31.succeed({ _tag: "Denied" }) }));
|
|
8487
8515
|
var testLayer26 = (implementation) => Layer29.succeed(Approvals, Approvals.of(implementation));
|
|
8488
8516
|
|
|
8489
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8517
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/compaction.ts
|
|
8490
8518
|
var exports_compaction = {};
|
|
8491
8519
|
__export(exports_compaction, {
|
|
8492
8520
|
truncate: () => truncate,
|
|
@@ -8504,7 +8532,7 @@ __export(exports_compaction, {
|
|
|
8504
8532
|
import { Context as Context32, Effect as Effect34, Layer as Layer32, Option as Option10, Schema as Schema41 } from "effect";
|
|
8505
8533
|
import { LanguageModel, Prompt as Prompt3, Tokenizer, Toolkit as Toolkit2 } from "effect/unstable/ai";
|
|
8506
8534
|
|
|
8507
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8535
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/session.ts
|
|
8508
8536
|
var exports_session = {};
|
|
8509
8537
|
__export(exports_session, {
|
|
8510
8538
|
testLayer: () => testLayer27,
|
|
@@ -8677,7 +8705,7 @@ var memoryLayer24 = Layer30.effect(SessionStore, Ref7.make(initialState).pipe(Ef
|
|
|
8677
8705
|
}))));
|
|
8678
8706
|
var testLayer27 = (implementation) => Layer30.succeed(SessionStore, SessionStore.of(implementation));
|
|
8679
8707
|
|
|
8680
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8708
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-output.ts
|
|
8681
8709
|
var exports_tool_output = {};
|
|
8682
8710
|
__export(exports_tool_output, {
|
|
8683
8711
|
testLayer: () => testLayer28,
|
|
@@ -8737,7 +8765,7 @@ var bound = (result, options) => Effect33.gen(function* () {
|
|
|
8737
8765
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
8738
8766
|
});
|
|
8739
8767
|
|
|
8740
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8768
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/compaction.ts
|
|
8741
8769
|
var DEFAULT_RESERVE_TOKENS = 16384;
|
|
8742
8770
|
var DEFAULT_KEEP_RECENT_TOKENS = 20000;
|
|
8743
8771
|
var SUMMARY_TEMPLATE = `Summarize the conversation so another agent can continue seamlessly.
|
|
@@ -8920,7 +8948,7 @@ var truncate = (maxTokens) => ({
|
|
|
8920
8948
|
var testLayer29 = (implementation) => Layer32.succeed(Compaction, Compaction.of(implementation));
|
|
8921
8949
|
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));
|
|
8922
8950
|
|
|
8923
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
8951
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/instructions.ts
|
|
8924
8952
|
var exports_instructions = {};
|
|
8925
8953
|
__export(exports_instructions, {
|
|
8926
8954
|
testLayer: () => testLayer30,
|
|
@@ -8969,7 +8997,7 @@ var renderUpdate = (epoch, context) => Effect35.gen(function* () {
|
|
|
8969
8997
|
var layer27 = (sources) => Layer33.succeed(Instructions, Instructions.of({ sources: [...sources] }));
|
|
8970
8998
|
var testLayer30 = (implementation) => Layer33.succeed(Instructions, Instructions.of(implementation));
|
|
8971
8999
|
|
|
8972
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9000
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/memory.ts
|
|
8973
9001
|
var exports_memory = {};
|
|
8974
9002
|
__export(exports_memory, {
|
|
8975
9003
|
testLayer: () => testLayer31,
|
|
@@ -8989,16 +9017,18 @@ class Memory extends Context34.Service()("@batonfx/core/Memory") {
|
|
|
8989
9017
|
}
|
|
8990
9018
|
var noop = {
|
|
8991
9019
|
recall: () => Effect36.succeed([]),
|
|
8992
|
-
remember: () => Effect36.void
|
|
9020
|
+
remember: () => Effect36.void,
|
|
9021
|
+
forget: () => Effect36.void
|
|
8993
9022
|
};
|
|
8994
9023
|
var merge = (first, second) => ({
|
|
8995
9024
|
recall: (input) => Effect36.all([first.recall(input), second.recall(input)]).pipe(Effect36.map(([firstItems, secondItems]) => [...firstItems, ...secondItems])),
|
|
8996
|
-
remember: (input) => Effect36.all([first.remember(input), second.remember(input)], { discard: true })
|
|
9025
|
+
remember: (input) => Effect36.all([first.remember(input), second.remember(input)], { discard: true }),
|
|
9026
|
+
forget: (input) => Effect36.all([first.forget(input), second.forget(input)], { discard: true })
|
|
8997
9027
|
});
|
|
8998
9028
|
var noopLayer = Layer34.succeed(Memory, Memory.of(noop));
|
|
8999
9029
|
var testLayer31 = (implementation) => Layer34.succeed(Memory, Memory.of(implementation));
|
|
9000
9030
|
|
|
9001
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9031
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-middleware.ts
|
|
9002
9032
|
var exports_model_middleware = {};
|
|
9003
9033
|
__export(exports_model_middleware, {
|
|
9004
9034
|
layer: () => layer28,
|
|
@@ -9012,21 +9042,110 @@ class ModelMiddleware extends Context35.Service()("@batonfx/core/ModelMiddleware
|
|
|
9012
9042
|
var identityLayer = Layer35.succeed(ModelMiddleware, []);
|
|
9013
9043
|
var layer28 = (middleware) => Layer35.succeed(ModelMiddleware, middleware);
|
|
9014
9044
|
|
|
9015
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9045
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-registry.ts
|
|
9046
|
+
var exports_model_registry = {};
|
|
9047
|
+
__export(exports_model_registry, {
|
|
9048
|
+
testLayer: () => testLayer32,
|
|
9049
|
+
registrations: () => registrations,
|
|
9050
|
+
registrationFromLayer: () => registrationFromLayer,
|
|
9051
|
+
register: () => register4,
|
|
9052
|
+
provide: () => provide,
|
|
9053
|
+
memoryLayer: () => memoryLayer25,
|
|
9054
|
+
layerFromRegistrationEffects: () => layerFromRegistrationEffects,
|
|
9055
|
+
layer: () => layer29,
|
|
9056
|
+
combine: () => combine,
|
|
9057
|
+
Service: () => Service29,
|
|
9058
|
+
LanguageModelNotRegistered: () => LanguageModelNotRegistered
|
|
9059
|
+
});
|
|
9060
|
+
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";
|
|
9061
|
+
import { Model } from "effect/unstable/ai";
|
|
9062
|
+
|
|
9063
|
+
class LanguageModelNotRegistered extends Schema43.TaggedErrorClass()("LanguageModelNotRegistered", {
|
|
9064
|
+
provider: Schema43.String,
|
|
9065
|
+
model: Schema43.String,
|
|
9066
|
+
registration_key: Schema43.optionalKey(Schema43.String)
|
|
9067
|
+
}) {
|
|
9068
|
+
}
|
|
9069
|
+
|
|
9070
|
+
class Service29 extends Context36.Service()("@batonfx/core/ModelRegistry") {
|
|
9071
|
+
}
|
|
9072
|
+
var registrationVariantKey = (value) => value.registrationKey ?? null;
|
|
9073
|
+
var selectionVariantKey = (selection) => selection.registrationKey ?? null;
|
|
9074
|
+
var registryIdentity = (registration) => JSON.stringify([registration.provider, registration.model, registrationVariantKey(registration)]);
|
|
9075
|
+
var matchesSelection = (selection) => (registration) => registration.provider === selection.provider && registration.model === selection.model && registrationVariantKey(registration) === selectionVariantKey(selection);
|
|
9076
|
+
var upsertRegistration = (registry, registration) => {
|
|
9077
|
+
const key2 = registryIdentity(registration);
|
|
9078
|
+
const exists = Option13.isSome(Chunk2.findFirst(registry, (item) => registryIdentity(item) === key2));
|
|
9079
|
+
if (!exists)
|
|
9080
|
+
return Chunk2.append(registry, registration);
|
|
9081
|
+
return Chunk2.map(registry, (item) => registryIdentity(item) === key2 ? registration : item);
|
|
9082
|
+
};
|
|
9083
|
+
var findRegistration = (registry, selection) => Chunk2.findFirst(registry, matchesSelection(selection)).pipe(Option13.getOrUndefined);
|
|
9084
|
+
var registrationFromLayer = (input) => Model.make(input.provider, input.model, input.layer).captureRequirements.pipe(Effect38.map((layer29) => ({
|
|
9085
|
+
provider: input.provider,
|
|
9086
|
+
model: input.model,
|
|
9087
|
+
layer: layer29,
|
|
9088
|
+
...input.registrationKey === undefined ? {} : { registrationKey: input.registrationKey },
|
|
9089
|
+
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
9090
|
+
})));
|
|
9091
|
+
var layer29 = (initialRegistrations = [], options) => Layer36.effect(Service29, Effect38.gen(function* () {
|
|
9092
|
+
const registry = yield* Ref9.make(initialRegistrations.reduce(upsertRegistration, Chunk2.empty()));
|
|
9093
|
+
const semaphore = options?.maxConcurrentModelCalls === undefined ? undefined : yield* Semaphore3.make(options.maxConcurrentModelCalls);
|
|
9094
|
+
const register4 = Effect38.fn("ModelRegistry.register")(function* (input) {
|
|
9095
|
+
yield* Ref9.update(registry, (items) => upsertRegistration(items, input.registration));
|
|
9096
|
+
});
|
|
9097
|
+
const registrations = Ref9.get(registry).pipe(Effect38.map(Chunk2.toReadonlyArray));
|
|
9098
|
+
const provide = Effect38.fn("ModelRegistry.provide")(function* (selection, effect) {
|
|
9099
|
+
const items = yield* Ref9.get(registry);
|
|
9100
|
+
const registration = findRegistration(items, selection);
|
|
9101
|
+
if (registration === undefined) {
|
|
9102
|
+
return yield* Effect38.fail(new LanguageModelNotRegistered({
|
|
9103
|
+
provider: selection.provider,
|
|
9104
|
+
model: selection.model,
|
|
9105
|
+
...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
|
|
9106
|
+
}));
|
|
9107
|
+
}
|
|
9108
|
+
const provided = effect.pipe(Effect38.provide(registration.layer));
|
|
9109
|
+
return yield* semaphore === undefined ? provided : semaphore.withPermits(1)(provided);
|
|
9110
|
+
});
|
|
9111
|
+
return Service29.of({
|
|
9112
|
+
register: register4,
|
|
9113
|
+
registrations,
|
|
9114
|
+
provide
|
|
9115
|
+
});
|
|
9116
|
+
}));
|
|
9117
|
+
var layerFromRegistrationEffects = (registrations, options) => Layer36.unwrap(Effect38.all(registrations).pipe(Effect38.map((items) => layer29(items, options))));
|
|
9118
|
+
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))));
|
|
9119
|
+
var memoryLayer25 = layer29;
|
|
9120
|
+
var testLayer32 = (implementation) => Layer36.succeed(Service29, Service29.of(implementation));
|
|
9121
|
+
var register4 = Effect38.fn("ModelRegistry.register.call")(function* (input) {
|
|
9122
|
+
const service = yield* Service29;
|
|
9123
|
+
return yield* service.register(input);
|
|
9124
|
+
});
|
|
9125
|
+
var registrations = Effect38.fn("ModelRegistry.registrations.call")(function* () {
|
|
9126
|
+
const service = yield* Service29;
|
|
9127
|
+
return yield* service.registrations;
|
|
9128
|
+
});
|
|
9129
|
+
var provide = (selection, effect) => Effect38.gen(function* () {
|
|
9130
|
+
const service = yield* Service29;
|
|
9131
|
+
return yield* service.provide(selection, effect);
|
|
9132
|
+
});
|
|
9133
|
+
|
|
9134
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/model-resilience.ts
|
|
9016
9135
|
var exports_model_resilience = {};
|
|
9017
9136
|
__export(exports_model_resilience, {
|
|
9018
|
-
testLayer: () =>
|
|
9137
|
+
testLayer: () => testLayer33,
|
|
9019
9138
|
none: () => none,
|
|
9020
9139
|
make: () => make3,
|
|
9021
|
-
layer: () =>
|
|
9140
|
+
layer: () => layer30,
|
|
9022
9141
|
defaultClassify: () => defaultClassify,
|
|
9023
9142
|
apply: () => apply,
|
|
9024
9143
|
ModelResilience: () => ModelResilience
|
|
9025
9144
|
});
|
|
9026
|
-
import { Cause, Context as
|
|
9145
|
+
import { Cause, Context as Context37, Effect as Effect39, Layer as Layer37, Schedule as Schedule2, Stream as Stream5 } from "effect";
|
|
9027
9146
|
import { AiError, Response as Response2 } from "effect/unstable/ai";
|
|
9028
9147
|
|
|
9029
|
-
class ModelResilience extends
|
|
9148
|
+
class ModelResilience extends Context37.Service()("@batonfx/core/ModelResilience") {
|
|
9030
9149
|
}
|
|
9031
9150
|
var defaultClassify = (error) => AiError.isAiError(error) && error.isRetryable ? "transient" : "terminal";
|
|
9032
9151
|
var none = { classify: () => "terminal", retrySchedule: Schedule2.recurs(0) };
|
|
@@ -9034,9 +9153,9 @@ var make3 = (input) => ({
|
|
|
9034
9153
|
classify: input?.classify ?? defaultClassify,
|
|
9035
9154
|
retrySchedule: input?.retrySchedule ?? none.retrySchedule
|
|
9036
9155
|
});
|
|
9037
|
-
var
|
|
9038
|
-
var
|
|
9039
|
-
var retryEffect = (effect, resilience) =>
|
|
9156
|
+
var layer30 = (input) => Layer37.succeed(ModelResilience, ModelResilience.of(make3(input)));
|
|
9157
|
+
var testLayer33 = (implementation) => Layer37.succeed(ModelResilience, ModelResilience.of(implementation));
|
|
9158
|
+
var retryEffect = (effect, resilience) => Effect39.suspend(effect).pipe(Effect39.retry({
|
|
9040
9159
|
schedule: resilience.retrySchedule,
|
|
9041
9160
|
while: (error) => resilience.classify(error) === "transient"
|
|
9042
9161
|
}));
|
|
@@ -9047,7 +9166,7 @@ var apply = (model, resilience) => ({
|
|
|
9047
9166
|
generateObject: (options) => retryEffect(() => model.generateObject(options), resilience),
|
|
9048
9167
|
streamText: (options) => Stream5.suspend(() => {
|
|
9049
9168
|
let emitted = false;
|
|
9050
|
-
return model.streamText(options).pipe(Stream5.tap(() =>
|
|
9169
|
+
return model.streamText(options).pipe(Stream5.tap(() => Effect39.sync(() => {
|
|
9051
9170
|
emitted = true;
|
|
9052
9171
|
})), Stream5.catchCause((cause) => {
|
|
9053
9172
|
if (Cause.hasInterrupts(cause))
|
|
@@ -9058,10 +9177,10 @@ var apply = (model, resilience) => ({
|
|
|
9058
9177
|
}).pipe(Stream5.retry(retryStreamSchedule(resilience)))
|
|
9059
9178
|
});
|
|
9060
9179
|
|
|
9061
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9180
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/permissions.ts
|
|
9062
9181
|
var exports_permissions = {};
|
|
9063
9182
|
__export(exports_permissions, {
|
|
9064
|
-
testLayer: () =>
|
|
9183
|
+
testLayer: () => testLayer34,
|
|
9065
9184
|
ruleStoreTestLayer: () => ruleStoreTestLayer,
|
|
9066
9185
|
ruleStoreMemory: () => ruleStoreMemory,
|
|
9067
9186
|
matches: () => matches,
|
|
@@ -9073,17 +9192,17 @@ __export(exports_permissions, {
|
|
|
9073
9192
|
Permissions: () => Permissions,
|
|
9074
9193
|
PermissionError: () => PermissionError
|
|
9075
9194
|
});
|
|
9076
|
-
import { Context as
|
|
9195
|
+
import { Context as Context38, Effect as Effect40, Layer as Layer38, Option as Option14, Ref as Ref10, Schema as Schema44 } from "effect";
|
|
9077
9196
|
|
|
9078
|
-
class PermissionError extends
|
|
9079
|
-
message:
|
|
9197
|
+
class PermissionError extends Schema44.TaggedErrorClass()("@batonfx/core/PermissionError", {
|
|
9198
|
+
message: Schema44.String
|
|
9080
9199
|
}) {
|
|
9081
9200
|
}
|
|
9082
9201
|
|
|
9083
|
-
class Permissions extends
|
|
9202
|
+
class Permissions extends Context38.Service()("@batonfx/core/Permissions") {
|
|
9084
9203
|
}
|
|
9085
9204
|
|
|
9086
|
-
class RuleStore extends
|
|
9205
|
+
class RuleStore extends Context38.Service()("@batonfx/core/PermissionRuleStore") {
|
|
9087
9206
|
}
|
|
9088
9207
|
var escapeRegExp = (value) => value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
9089
9208
|
var glob = (pattern) => new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`);
|
|
@@ -9170,28 +9289,28 @@ var decisionFor = (ruleset, request) => {
|
|
|
9170
9289
|
return { _tag: "Ask", token: tokenFor(request) };
|
|
9171
9290
|
}
|
|
9172
9291
|
};
|
|
9173
|
-
var fromRuleset = (ruleset) =>
|
|
9174
|
-
evaluate: (request) =>
|
|
9175
|
-
await: () =>
|
|
9292
|
+
var fromRuleset = (ruleset) => Layer38.succeed(Permissions, Permissions.of({
|
|
9293
|
+
evaluate: (request) => Effect40.succeed(decisionFor(ruleset, request)),
|
|
9294
|
+
await: () => Effect40.succeed(Option14.none())
|
|
9176
9295
|
}));
|
|
9177
|
-
var allowAll =
|
|
9178
|
-
evaluate: () =>
|
|
9179
|
-
await: () =>
|
|
9296
|
+
var allowAll = Layer38.succeed(Permissions, Permissions.of({
|
|
9297
|
+
evaluate: () => Effect40.succeed({ _tag: "Allow" }),
|
|
9298
|
+
await: () => Effect40.succeed(Option14.none())
|
|
9180
9299
|
}));
|
|
9181
|
-
var interactive = (options) =>
|
|
9182
|
-
evaluate: (request) =>
|
|
9183
|
-
await: (pending) => options.onAsk(pending).pipe(
|
|
9300
|
+
var interactive = (options) => Layer38.succeed(Permissions, Permissions.of({
|
|
9301
|
+
evaluate: (request) => Effect40.succeed(decisionFor(options.ruleset, request)),
|
|
9302
|
+
await: (pending) => options.onAsk(pending).pipe(Effect40.map(Option14.some))
|
|
9184
9303
|
}));
|
|
9185
|
-
var ruleStoreMemory = (initialRules = []) =>
|
|
9186
|
-
remember: (rule) =>
|
|
9304
|
+
var ruleStoreMemory = (initialRules = []) => Layer38.effect(RuleStore, Ref10.make(initialRules).pipe(Effect40.map((rules) => RuleStore.of({
|
|
9305
|
+
remember: (rule) => Ref10.update(rules, (current2) => [...current2, rule])
|
|
9187
9306
|
}))));
|
|
9188
|
-
var ruleStoreTestLayer = (implementation) =>
|
|
9189
|
-
var
|
|
9307
|
+
var ruleStoreTestLayer = (implementation) => Layer38.succeed(RuleStore, RuleStore.of(implementation));
|
|
9308
|
+
var testLayer34 = (implementation) => Layer38.succeed(Permissions, Permissions.of(implementation));
|
|
9190
9309
|
|
|
9191
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9310
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/skill-source.ts
|
|
9192
9311
|
var exports_skill_source = {};
|
|
9193
9312
|
__export(exports_skill_source, {
|
|
9194
|
-
testLayer: () =>
|
|
9313
|
+
testLayer: () => testLayer35,
|
|
9195
9314
|
selectListings: () => selectListings,
|
|
9196
9315
|
makeListing: () => makeListing,
|
|
9197
9316
|
fromSkills: () => fromSkills,
|
|
@@ -9200,29 +9319,29 @@ __export(exports_skill_source, {
|
|
|
9200
9319
|
SkillSource: () => SkillSource,
|
|
9201
9320
|
DESCRIPTION_CAP: () => DESCRIPTION_CAP
|
|
9202
9321
|
});
|
|
9203
|
-
import { Context as
|
|
9322
|
+
import { Context as Context39, Effect as Effect41, Layer as Layer39, Schema as Schema45 } from "effect";
|
|
9204
9323
|
|
|
9205
|
-
class SkillSourceError extends
|
|
9206
|
-
source:
|
|
9207
|
-
message:
|
|
9208
|
-
cause:
|
|
9324
|
+
class SkillSourceError extends Schema45.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
9325
|
+
source: Schema45.String,
|
|
9326
|
+
message: Schema45.String,
|
|
9327
|
+
cause: Schema45.optionalKey(Schema45.Defect())
|
|
9209
9328
|
}) {
|
|
9210
9329
|
}
|
|
9211
9330
|
var DESCRIPTION_CAP = 1536;
|
|
9212
9331
|
|
|
9213
|
-
class SkillSource extends
|
|
9332
|
+
class SkillSource extends Context39.Service()("@batonfx/core/SkillSource") {
|
|
9214
9333
|
}
|
|
9215
9334
|
var makeListing = (frontmatter, descriptionCap = DESCRIPTION_CAP) => `- ${frontmatter.name}: ${frontmatter.description.slice(0, Math.max(0, descriptionCap))}`;
|
|
9216
9335
|
var fromSkills = (skills) => {
|
|
9217
9336
|
const all = [...skills];
|
|
9218
9337
|
const byName = new Map(all.map((skill) => [skill.frontmatter.name, skill]));
|
|
9219
|
-
return
|
|
9220
|
-
all:
|
|
9221
|
-
get: (name) =>
|
|
9338
|
+
return Layer39.succeed(SkillSource, SkillSource.of({
|
|
9339
|
+
all: Effect41.succeed(all),
|
|
9340
|
+
get: (name) => Effect41.succeed(byName.get(name))
|
|
9222
9341
|
}));
|
|
9223
9342
|
};
|
|
9224
9343
|
var empty = fromSkills([]);
|
|
9225
|
-
var
|
|
9344
|
+
var testLayer35 = (implementation) => Layer39.succeed(SkillSource, SkillSource.of(implementation));
|
|
9226
9345
|
var estimatedTokens = (listing) => Math.ceil(listing.length / 4);
|
|
9227
9346
|
var usageRank = (skill, recentlyUsed) => {
|
|
9228
9347
|
const index2 = recentlyUsed.indexOf(skill.frontmatter.name);
|
|
@@ -9246,22 +9365,22 @@ var selectListings = (skills, budgetTokens, recentlyUsed) => {
|
|
|
9246
9365
|
return selected;
|
|
9247
9366
|
};
|
|
9248
9367
|
|
|
9249
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9368
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/steering.ts
|
|
9250
9369
|
var exports_steering = {};
|
|
9251
9370
|
__export(exports_steering, {
|
|
9252
|
-
testLayer: () =>
|
|
9253
|
-
layer: () =>
|
|
9371
|
+
testLayer: () => testLayer36,
|
|
9372
|
+
layer: () => layer31,
|
|
9254
9373
|
SteeringQueueFull: () => SteeringQueueFull,
|
|
9255
9374
|
Steering: () => Steering
|
|
9256
9375
|
});
|
|
9257
|
-
import { Context as
|
|
9376
|
+
import { Context as Context40, Effect as Effect42, Exit, Layer as Layer40, Queue, Schema as Schema46 } from "effect";
|
|
9258
9377
|
|
|
9259
|
-
class Steering extends
|
|
9378
|
+
class Steering extends Context40.Service()("@batonfx/core/Steering") {
|
|
9260
9379
|
}
|
|
9261
9380
|
|
|
9262
|
-
class SteeringQueueFull extends
|
|
9263
|
-
queue:
|
|
9264
|
-
capacity:
|
|
9381
|
+
class SteeringQueueFull extends Schema46.TaggedErrorClass()("@batonfx/core/SteeringQueueFull", {
|
|
9382
|
+
queue: Schema46.Literals(["steering", "followUp"]),
|
|
9383
|
+
capacity: Schema46.Number
|
|
9265
9384
|
}) {
|
|
9266
9385
|
}
|
|
9267
9386
|
var resolvePolicy = (policy, mode) => ({
|
|
@@ -9280,18 +9399,18 @@ var queueStrategy = (strategy) => {
|
|
|
9280
9399
|
return "suspend";
|
|
9281
9400
|
}
|
|
9282
9401
|
};
|
|
9283
|
-
var makeQueue = (name, policy) => (policy.capacity === undefined ? Queue.unbounded() : Queue.make({ capacity: policy.capacity, strategy: queueStrategy(policy.onFull) })).pipe(
|
|
9284
|
-
var offer = (runtime, message) => Queue.offer(runtime.queue, message).pipe(
|
|
9402
|
+
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 })));
|
|
9403
|
+
var offer = (runtime, message) => Queue.offer(runtime.queue, message).pipe(Effect42.flatMap((offered) => {
|
|
9285
9404
|
if (offered || runtime.policy.capacity === undefined || runtime.policy.onFull !== "fail")
|
|
9286
|
-
return
|
|
9287
|
-
return
|
|
9405
|
+
return Effect42.void;
|
|
9406
|
+
return Effect42.fail(new SteeringQueueFull({ queue: runtime.name, capacity: runtime.policy.capacity }));
|
|
9288
9407
|
}));
|
|
9289
|
-
var drainOne = (queue) =>
|
|
9408
|
+
var drainOne = (queue) => Effect42.sync(() => {
|
|
9290
9409
|
const taken = Queue.takeUnsafe(queue);
|
|
9291
9410
|
return taken === undefined || !Exit.isSuccess(taken) ? [] : [taken.value];
|
|
9292
9411
|
});
|
|
9293
9412
|
var drain = (queue, mode) => mode === "all" ? Queue.clear(queue) : drainOne(queue);
|
|
9294
|
-
var
|
|
9413
|
+
var layer31 = (options = {}) => Layer40.effect(Steering, Effect42.gen(function* () {
|
|
9295
9414
|
const steeringQueue = yield* makeQueue("steering", resolvePolicy(options.steering, "all"));
|
|
9296
9415
|
const followUpQueue = yield* makeQueue("followUp", resolvePolicy(options.followUp, "one-at-a-time"));
|
|
9297
9416
|
return Steering.of({
|
|
@@ -9301,30 +9420,30 @@ var layer30 = (options = {}) => Layer39.effect(Steering, Effect41.gen(function*
|
|
|
9301
9420
|
takeFollowUp: () => drain(followUpQueue.queue, followUpQueue.policy.mode)
|
|
9302
9421
|
});
|
|
9303
9422
|
}));
|
|
9304
|
-
var
|
|
9423
|
+
var testLayer36 = (implementation) => Layer40.succeed(Steering, Steering.of(implementation));
|
|
9305
9424
|
|
|
9306
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9425
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-context.ts
|
|
9307
9426
|
var exports_tool_context = {};
|
|
9308
9427
|
__export(exports_tool_context, {
|
|
9309
|
-
testLayer: () =>
|
|
9428
|
+
testLayer: () => testLayer37,
|
|
9310
9429
|
layerDefault: () => layerDefault,
|
|
9311
9430
|
ToolContext: () => ToolContext
|
|
9312
9431
|
});
|
|
9313
|
-
import { Context as
|
|
9432
|
+
import { Context as Context41, Effect as Effect43, Layer as Layer41 } from "effect";
|
|
9314
9433
|
|
|
9315
|
-
class ToolContext extends
|
|
9434
|
+
class ToolContext extends Context41.Service()("@batonfx/core/ToolContext") {
|
|
9316
9435
|
}
|
|
9317
|
-
var layerDefault =
|
|
9436
|
+
var layerDefault = Layer41.sync(ToolContext, () => ToolContext.of({
|
|
9318
9437
|
signal: new AbortController().signal,
|
|
9319
|
-
emit: () =>
|
|
9438
|
+
emit: () => Effect43.void,
|
|
9320
9439
|
sessionId: "local"
|
|
9321
9440
|
}));
|
|
9322
|
-
var
|
|
9441
|
+
var testLayer37 = (implementation) => Layer41.succeed(ToolContext, ToolContext.of(implementation));
|
|
9323
9442
|
|
|
9324
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9443
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/tool-executor.ts
|
|
9325
9444
|
var exports_tool_executor = {};
|
|
9326
9445
|
__export(exports_tool_executor, {
|
|
9327
|
-
testLayer: () =>
|
|
9446
|
+
testLayer: () => testLayer38,
|
|
9328
9447
|
sandbox: () => sandbox,
|
|
9329
9448
|
router: () => router,
|
|
9330
9449
|
routeToolkit: () => routeToolkit,
|
|
@@ -9336,8 +9455,8 @@ __export(exports_tool_executor, {
|
|
|
9336
9455
|
client: () => client,
|
|
9337
9456
|
ToolExecutor: () => ToolExecutor
|
|
9338
9457
|
});
|
|
9339
|
-
import { Cause as Cause2, Context as
|
|
9340
|
-
class ToolExecutor extends
|
|
9458
|
+
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";
|
|
9459
|
+
class ToolExecutor extends Context42.Service()("@batonfx/core/ToolExecutor") {
|
|
9341
9460
|
}
|
|
9342
9461
|
var failureMessage = (cause) => {
|
|
9343
9462
|
const error = Cause2.squash(cause);
|
|
@@ -9359,47 +9478,47 @@ var resultMessage = (result) => {
|
|
|
9359
9478
|
var schemaMessage = (error) => error instanceof Error ? error.message : typeof error === "string" ? error : resultMessage(error);
|
|
9360
9479
|
var decodeSuccess = (tool2, result) => {
|
|
9361
9480
|
const successSchema = tool2.successSchema;
|
|
9362
|
-
if (!
|
|
9363
|
-
return
|
|
9481
|
+
if (!Schema47.isSchema(successSchema)) {
|
|
9482
|
+
return Effect44.succeed({ _tag: "Success", result, encodedResult: result });
|
|
9364
9483
|
}
|
|
9365
|
-
return
|
|
9484
|
+
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))}`))));
|
|
9366
9485
|
};
|
|
9367
9486
|
var placementOutcome = (placement, tool2, response) => {
|
|
9368
9487
|
switch (response._tag) {
|
|
9369
9488
|
case "Failure":
|
|
9370
|
-
return
|
|
9489
|
+
return Effect44.succeed(failureOutcome(response.message));
|
|
9371
9490
|
case "Suspend":
|
|
9372
|
-
return
|
|
9491
|
+
return Effect44.succeed({ _tag: "Suspend", token: response.token });
|
|
9373
9492
|
case "Success":
|
|
9374
|
-
return decodeSuccess(tool2, response.result).pipe(
|
|
9493
|
+
return decodeSuccess(tool2, response.result).pipe(Effect44.map((outcome) => outcome._tag === "Failure" ? failureOutcome(outcome.message.replace("invalid client result", `invalid ${placement} result`)) : outcome));
|
|
9375
9494
|
}
|
|
9376
9495
|
};
|
|
9377
9496
|
var executeWithToolkit = (toolkit, request) => {
|
|
9378
9497
|
if (toolkit.tools[request.call.name] === undefined) {
|
|
9379
|
-
return
|
|
9498
|
+
return Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`));
|
|
9380
9499
|
}
|
|
9381
|
-
return toolkit.handle(request.call.name, request.call.params).pipe(
|
|
9500
|
+
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({
|
|
9382
9501
|
onNone: () => failureOutcome("Tool handler did not produce a final result"),
|
|
9383
9502
|
onSome: (result) => result.isFailure ? failureOutcome(resultMessage(result.result)) : {
|
|
9384
9503
|
_tag: "Success",
|
|
9385
9504
|
result: result.result,
|
|
9386
9505
|
encodedResult: result.encodedResult
|
|
9387
9506
|
}
|
|
9388
|
-
})),
|
|
9507
|
+
})), Effect44.catchCause((cause) => {
|
|
9389
9508
|
if (Cause2.hasInterrupts(cause))
|
|
9390
|
-
return
|
|
9509
|
+
return Effect44.interrupt;
|
|
9391
9510
|
const error = Cause2.squash(cause);
|
|
9392
9511
|
if (error instanceof AgentSuspended) {
|
|
9393
|
-
return
|
|
9512
|
+
return Effect44.succeed({ _tag: "Suspend", token: error.token });
|
|
9394
9513
|
}
|
|
9395
|
-
return
|
|
9514
|
+
return Effect44.succeed(failureOutcome(failureMessage(cause)));
|
|
9396
9515
|
}));
|
|
9397
9516
|
};
|
|
9398
9517
|
function executeToolkit(toolkit, request) {
|
|
9399
|
-
return ("handle" in toolkit ?
|
|
9518
|
+
return ("handle" in toolkit ? Effect44.succeed(toolkit) : toolkit).pipe(Effect44.flatMap((handled) => executeWithToolkit(handled, request)));
|
|
9400
9519
|
}
|
|
9401
9520
|
function fromToolkit(toolkit) {
|
|
9402
|
-
return
|
|
9521
|
+
return Layer42.effect(ToolExecutor, ("handle" in toolkit ? Effect44.succeed(toolkit) : toolkit).pipe(Effect44.map((handled) => ToolExecutor.of({
|
|
9403
9522
|
execute: (request) => executeWithToolkit(handled, request)
|
|
9404
9523
|
}))));
|
|
9405
9524
|
}
|
|
@@ -9418,10 +9537,10 @@ var placementRoute = (placement, options) => {
|
|
|
9418
9537
|
execute: (request) => {
|
|
9419
9538
|
const tool2 = options.toolkit.tools[request.call.name];
|
|
9420
9539
|
if (tool2 === undefined)
|
|
9421
|
-
return
|
|
9540
|
+
return Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`));
|
|
9422
9541
|
const effect = options.execute({ ...request, placement, tool: tool2 });
|
|
9423
|
-
const scheduled = "schedule" in options && options.schedule !== undefined ?
|
|
9424
|
-
return scheduled.pipe(
|
|
9542
|
+
const scheduled = "schedule" in options && options.schedule !== undefined ? Effect44.retry(effect, options.schedule) : effect;
|
|
9543
|
+
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)}`))));
|
|
9425
9544
|
}
|
|
9426
9545
|
});
|
|
9427
9546
|
};
|
|
@@ -9434,20 +9553,20 @@ function routeToolkit(toolkit) {
|
|
|
9434
9553
|
tools: Object.keys(handled.tools),
|
|
9435
9554
|
execute: (request) => executeWithToolkit(handled, request)
|
|
9436
9555
|
});
|
|
9437
|
-
return "handle" in toolkit ? makeRoute(toolkit) : toolkit.pipe(
|
|
9556
|
+
return "handle" in toolkit ? makeRoute(toolkit) : toolkit.pipe(Effect44.map(makeRoute));
|
|
9438
9557
|
}
|
|
9439
|
-
var routeInputEffect = (input) =>
|
|
9558
|
+
var routeInputEffect = (input) => Effect44.isEffect(input) ? input : Effect44.succeed(input);
|
|
9440
9559
|
function router(routes) {
|
|
9441
|
-
return
|
|
9560
|
+
return Layer42.effect(ToolExecutor, Effect44.all(Array.from(routes, routeInputEffect)).pipe(Effect44.map((resolved) => ToolExecutor.of({
|
|
9442
9561
|
execute: (request) => {
|
|
9443
9562
|
const matched = resolved.find((candidate) => candidate.matches(request));
|
|
9444
|
-
return matched === undefined ?
|
|
9563
|
+
return matched === undefined ? Effect44.succeed(failureOutcome(`Tool ${request.call.name} is not registered`)) : matched.execute(request);
|
|
9445
9564
|
}
|
|
9446
9565
|
}))));
|
|
9447
9566
|
}
|
|
9448
|
-
var
|
|
9567
|
+
var testLayer38 = (implementation) => Layer42.succeed(ToolExecutor, ToolExecutor.of(implementation));
|
|
9449
9568
|
|
|
9450
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9569
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/turn-policy.ts
|
|
9451
9570
|
var exports_turn_policy = {};
|
|
9452
9571
|
__export(exports_turn_policy, {
|
|
9453
9572
|
untilToolCall: () => untilToolCall,
|
|
@@ -9457,7 +9576,7 @@ __export(exports_turn_policy, {
|
|
|
9457
9576
|
decision: () => decision,
|
|
9458
9577
|
both: () => both
|
|
9459
9578
|
});
|
|
9460
|
-
import { Effect as
|
|
9579
|
+
import { Effect as Effect45 } from "effect";
|
|
9461
9580
|
var decision = {
|
|
9462
9581
|
continue: (overrides) => ({
|
|
9463
9582
|
_tag: "Continue",
|
|
@@ -9466,8 +9585,8 @@ var decision = {
|
|
|
9466
9585
|
stop: { _tag: "Stop" }
|
|
9467
9586
|
};
|
|
9468
9587
|
var make4 = (decide) => ({ decide });
|
|
9469
|
-
var recurs = (n) => make4((info) =>
|
|
9470
|
-
var untilToolCall = (name) => make4((info) =>
|
|
9588
|
+
var recurs = (n) => make4((info) => Effect45.succeed(info.turn < n + 1 ? decision.continue() : decision.stop));
|
|
9589
|
+
var untilToolCall = (name) => make4((info) => Effect45.succeed(info.pendingToolResults.some((result) => result.name === name) ? decision.stop : decision.continue()));
|
|
9471
9590
|
var mergeOverrides = (first, second) => {
|
|
9472
9591
|
if (first === undefined)
|
|
9473
9592
|
return second;
|
|
@@ -9475,7 +9594,7 @@ var mergeOverrides = (first, second) => {
|
|
|
9475
9594
|
return first;
|
|
9476
9595
|
return { ...first, ...second };
|
|
9477
9596
|
};
|
|
9478
|
-
var both = (first, second) => make4((info) =>
|
|
9597
|
+
var both = (first, second) => make4((info) => Effect45.gen(function* () {
|
|
9479
9598
|
const left = yield* first.decide(info);
|
|
9480
9599
|
if (left._tag === "Stop")
|
|
9481
9600
|
return decision.stop;
|
|
@@ -9486,14 +9605,17 @@ var both = (first, second) => make4((info) => Effect44.gen(function* () {
|
|
|
9486
9605
|
}));
|
|
9487
9606
|
var defaultPolicy = recurs(8);
|
|
9488
9607
|
|
|
9489
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
9608
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent.ts
|
|
9490
9609
|
function make5(nameOrOptions, options = {}) {
|
|
9491
9610
|
const resolved = typeof nameOrOptions === "string" ? { ...options, name: nameOrOptions } : nameOrOptions;
|
|
9492
9611
|
return {
|
|
9493
9612
|
name: resolved.name,
|
|
9494
9613
|
...resolved.instructions === undefined ? {} : { instructions: resolved.instructions },
|
|
9495
9614
|
toolkit: resolved.toolkit ?? Toolkit3.empty,
|
|
9496
|
-
policy: resolved.policy ?? defaultPolicy
|
|
9615
|
+
policy: resolved.policy ?? defaultPolicy,
|
|
9616
|
+
...resolved.model === undefined ? {} : { model: resolved.model },
|
|
9617
|
+
...resolved.memory === undefined ? {} : { memory: resolved.memory },
|
|
9618
|
+
...resolved.metadata === undefined ? {} : { metadata: resolved.metadata }
|
|
9497
9619
|
};
|
|
9498
9620
|
}
|
|
9499
9621
|
var defaultObjectPrompt = "Return the final structured output for the task above.";
|
|
@@ -9505,14 +9627,14 @@ var steeringDrainedEvent = (turn, queue, messages) => ({
|
|
|
9505
9627
|
});
|
|
9506
9628
|
var skillListingBudgetTokens = 2048;
|
|
9507
9629
|
var activateSkillToolName = "activate_skill";
|
|
9508
|
-
var activateSkillParameters =
|
|
9630
|
+
var activateSkillParameters = Schema48.Struct({ name: Schema48.String });
|
|
9509
9631
|
var activateSkillTool = Tool4.make(activateSkillToolName, {
|
|
9510
9632
|
description: "Load the full body for one listed Baton skill by name before applying that skill.",
|
|
9511
9633
|
parameters: activateSkillParameters,
|
|
9512
|
-
success:
|
|
9513
|
-
name:
|
|
9514
|
-
body:
|
|
9515
|
-
allowedTools:
|
|
9634
|
+
success: Schema48.Struct({
|
|
9635
|
+
name: Schema48.String,
|
|
9636
|
+
body: Schema48.String,
|
|
9637
|
+
allowedTools: Schema48.Array(Schema48.String)
|
|
9516
9638
|
})
|
|
9517
9639
|
});
|
|
9518
9640
|
var errorMessage = (error) => error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
@@ -9559,15 +9681,15 @@ var isUserMessagePart = (part) => part.type === "text" || part.type === "file";
|
|
|
9559
9681
|
var approvalRequired = (tool2, call, messages) => {
|
|
9560
9682
|
const needsApproval = tool2?.needsApproval;
|
|
9561
9683
|
if (needsApproval === undefined)
|
|
9562
|
-
return
|
|
9684
|
+
return Effect46.succeed(false);
|
|
9563
9685
|
if (typeof needsApproval === "boolean")
|
|
9564
|
-
return
|
|
9565
|
-
return
|
|
9686
|
+
return Effect46.succeed(needsApproval);
|
|
9687
|
+
return Effect46.suspend(() => {
|
|
9566
9688
|
const result = needsApproval(call.params, { toolCallId: call.id, messages });
|
|
9567
|
-
return
|
|
9568
|
-
}).pipe(
|
|
9689
|
+
return Effect46.isEffect(result) ? result : Effect46.succeed(result);
|
|
9690
|
+
}).pipe(Effect46.catchCause((cause) => Cause3.hasInterrupts(cause) ? Effect46.interrupt : Effect46.succeed(true)));
|
|
9569
9691
|
};
|
|
9570
|
-
var applyPromptChain = (chain, prompt, context) =>
|
|
9692
|
+
var applyPromptChain = (chain, prompt, context) => Effect46.gen(function* () {
|
|
9571
9693
|
let current2 = prompt;
|
|
9572
9694
|
for (const middleware of chain) {
|
|
9573
9695
|
if (middleware.transformPrompt !== undefined) {
|
|
@@ -9576,10 +9698,10 @@ var applyPromptChain = (chain, prompt, context) => Effect45.gen(function* () {
|
|
|
9576
9698
|
}
|
|
9577
9699
|
return current2;
|
|
9578
9700
|
});
|
|
9579
|
-
var applyPartChain = (chain, part, context) =>
|
|
9580
|
-
let current2 =
|
|
9701
|
+
var applyPartChain = (chain, part, context) => Effect46.gen(function* () {
|
|
9702
|
+
let current2 = Option16.some(part);
|
|
9581
9703
|
for (const middleware of chain) {
|
|
9582
|
-
if (
|
|
9704
|
+
if (Option16.isNone(current2))
|
|
9583
9705
|
break;
|
|
9584
9706
|
if (middleware.transformPart !== undefined) {
|
|
9585
9707
|
current2 = yield* middleware.transformPart(current2.value, context);
|
|
@@ -9587,74 +9709,83 @@ var applyPartChain = (chain, part, context) => Effect45.gen(function* () {
|
|
|
9587
9709
|
}
|
|
9588
9710
|
return current2;
|
|
9589
9711
|
});
|
|
9590
|
-
var streamInternal = (agent, options, structured) => Stream7.unwrap(
|
|
9591
|
-
const executor = yield*
|
|
9592
|
-
const approvals = yield*
|
|
9593
|
-
const chain = yield*
|
|
9712
|
+
var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect46.gen(function* () {
|
|
9713
|
+
const executor = yield* Effect46.serviceOption(ToolExecutor);
|
|
9714
|
+
const approvals = yield* Effect46.serviceOption(Approvals);
|
|
9715
|
+
const chain = yield* Effect46.serviceOption(ModelMiddleware).pipe(Effect46.map(Option16.match({ onNone: () => [], onSome: (service) => service })));
|
|
9594
9716
|
if (options.history !== undefined && options.persistence !== undefined) {
|
|
9595
|
-
return yield*
|
|
9717
|
+
return yield* Effect46.fail(new AgentError({
|
|
9596
9718
|
message: "RunOptions.history and RunOptions.persistence are mutually exclusive",
|
|
9597
9719
|
turn: 0
|
|
9598
9720
|
}));
|
|
9599
9721
|
}
|
|
9600
9722
|
if (options.toolOutputMaxBytes !== undefined && (!Number.isFinite(options.toolOutputMaxBytes) || options.toolOutputMaxBytes < 0)) {
|
|
9601
|
-
return yield*
|
|
9723
|
+
return yield* Effect46.fail(new AgentError({
|
|
9602
9724
|
message: "RunOptions.toolOutputMaxBytes must be a non-negative finite number",
|
|
9603
9725
|
turn: 0
|
|
9604
9726
|
}));
|
|
9605
9727
|
}
|
|
9606
9728
|
if (options.compaction?.contextWindow !== undefined && (!Number.isFinite(options.compaction.contextWindow) || options.compaction.contextWindow <= 0)) {
|
|
9607
|
-
return yield*
|
|
9729
|
+
return yield* Effect46.fail(new AgentError({
|
|
9608
9730
|
message: "RunOptions.compaction.contextWindow must be a positive finite number",
|
|
9609
9731
|
turn: 0
|
|
9610
9732
|
}));
|
|
9611
9733
|
}
|
|
9612
9734
|
const sessionId = options.sessionId ?? "local";
|
|
9613
|
-
const instructionsService = yield*
|
|
9614
|
-
const skillSourceService = yield*
|
|
9615
|
-
const skillRuntime =
|
|
9735
|
+
const instructionsService = yield* Effect46.serviceOption(Instructions);
|
|
9736
|
+
const skillSourceService = yield* Effect46.serviceOption(SkillSource);
|
|
9737
|
+
const skillRuntime = Option16.isNone(skillSourceService) ? undefined : {
|
|
9616
9738
|
source: skillSourceService.value,
|
|
9617
|
-
skills: yield* skillSourceService.value.all.pipe(
|
|
9739
|
+
skills: yield* skillSourceService.value.all.pipe(Effect46.mapError((error) => new AgentError({ message: error.message, turn: 0, cause: error })))
|
|
9618
9740
|
};
|
|
9619
9741
|
const selectedSkills = skillRuntime === undefined ? [] : selectListings(skillRuntime.skills, skillListingBudgetTokens, []);
|
|
9620
9742
|
const skillListings = selectedSkills.map((skill) => skill.listing).join(`
|
|
9621
9743
|
`);
|
|
9622
9744
|
const hasActivatableSkills = selectedSkills.length > 0;
|
|
9623
|
-
const instructionsEpoch = options.system === undefined && options.history === undefined &&
|
|
9745
|
+
const instructionsEpoch = options.system === undefined && options.history === undefined && Option16.isSome(instructionsService) ? yield* openEpoch(instructionsService.value, { agentName: agent.name, turn: 0 }) : undefined;
|
|
9624
9746
|
const baseSystem = options.system ?? (instructionsEpoch === undefined ? agent.instructions : instructionsEpoch.baseline.length === 0 ? agent.instructions : instructionsEpoch.baseline);
|
|
9625
9747
|
const system = appendInstructionFragment(baseSystem, options.history === undefined && skillListings.length > 0 ? skillListingsInstructions(skillListings) : undefined);
|
|
9626
|
-
const persistenceService = yield*
|
|
9627
|
-
const resilienceService = yield*
|
|
9628
|
-
const
|
|
9629
|
-
const
|
|
9630
|
-
const
|
|
9631
|
-
const
|
|
9632
|
-
const
|
|
9633
|
-
const
|
|
9748
|
+
const persistenceService = yield* Effect46.serviceOption(Chat.Persistence);
|
|
9749
|
+
const resilienceService = yield* Effect46.serviceOption(ModelResilience);
|
|
9750
|
+
const modelRegistryService = yield* Effect46.serviceOption(Service29);
|
|
9751
|
+
const permissionsService = yield* Effect46.serviceOption(Permissions);
|
|
9752
|
+
const steeringService = yield* Effect46.serviceOption(Steering);
|
|
9753
|
+
const compactionService = yield* Effect46.serviceOption(Compaction);
|
|
9754
|
+
const memoryService = yield* Effect46.serviceOption(Memory);
|
|
9755
|
+
const sessionService = yield* Effect46.serviceOption(SessionStore);
|
|
9756
|
+
const tokenizerService = yield* Effect46.serviceOption(Tokenizer2.Tokenizer);
|
|
9634
9757
|
const persistenceOptions = options.persistence;
|
|
9635
|
-
const memoryOptions = options.memory;
|
|
9758
|
+
const memoryOptions = options.memory ?? (agent.memory === undefined ? undefined : { key: agent.memory });
|
|
9759
|
+
const agentModel = agent.model;
|
|
9760
|
+
const agentModelContext = agentModel === undefined ? undefined : yield* Option16.match(modelRegistryService, {
|
|
9761
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9762
|
+
message: "Agent.model requires ModelRegistry in context",
|
|
9763
|
+
turn: 0
|
|
9764
|
+
})),
|
|
9765
|
+
onSome: (registry) => registry.provide(agentModel, Effect46.context()).pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })))
|
|
9766
|
+
});
|
|
9636
9767
|
const memoryRuntime = memoryOptions === undefined ? undefined : {
|
|
9637
9768
|
key: memoryOptions.key,
|
|
9638
|
-
service: yield*
|
|
9639
|
-
onNone: () =>
|
|
9640
|
-
message: "RunOptions.memory requires Memory in context",
|
|
9769
|
+
service: yield* Option16.match(memoryService, {
|
|
9770
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9771
|
+
message: options.memory === undefined ? "Agent.memory requires Memory in context" : "RunOptions.memory requires Memory in context",
|
|
9641
9772
|
turn: 0
|
|
9642
9773
|
})),
|
|
9643
|
-
onSome:
|
|
9774
|
+
onSome: Effect46.succeed
|
|
9644
9775
|
})
|
|
9645
9776
|
};
|
|
9646
|
-
const persisted = persistenceOptions === undefined ? undefined : yield*
|
|
9647
|
-
onNone: () =>
|
|
9777
|
+
const persisted = persistenceOptions === undefined ? undefined : yield* Option16.match(persistenceService, {
|
|
9778
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
9648
9779
|
message: "RunOptions.persistence requires Chat.Persistence in context",
|
|
9649
9780
|
turn: 0
|
|
9650
9781
|
})),
|
|
9651
|
-
onSome: (service) => service.getOrCreate(persistenceOptions.chatId, persistenceOptions.timeToLive === undefined ? undefined : { timeToLive: persistenceOptions.timeToLive }).pipe(
|
|
9782
|
+
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 })))
|
|
9652
9783
|
});
|
|
9653
|
-
const seedSystem = persisted !== undefined && system !== undefined && (yield*
|
|
9784
|
+
const seedSystem = persisted !== undefined && system !== undefined && (yield* Ref11.get(persisted.history)).content.length === 0 ? system : undefined;
|
|
9654
9785
|
const freshChat = options.history !== undefined ? Chat.fromPrompt(options.history) : system !== undefined ? Chat.fromPrompt([Prompt4.makeMessage("system", { content: system })]) : Chat.empty;
|
|
9655
9786
|
const chat = persisted ?? (yield* freshChat);
|
|
9656
|
-
const savePersisted = persisted === undefined ?
|
|
9657
|
-
const failSuspended = (call, token, reason) => Stream7.unwrap(savePersisted.pipe(
|
|
9787
|
+
const savePersisted = persisted === undefined ? Effect46.void : persisted.save.pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: 0, cause: error })));
|
|
9788
|
+
const failSuspended = (call, token, reason) => Stream7.unwrap(savePersisted.pipe(Effect46.as(Stream7.fail(suspended(call, token, reason)))));
|
|
9658
9789
|
const state = {
|
|
9659
9790
|
text: "",
|
|
9660
9791
|
turn: 0,
|
|
@@ -9667,20 +9798,20 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9667
9798
|
const activatedSkillTools = new Map;
|
|
9668
9799
|
let sessionSyncedMessages = 0;
|
|
9669
9800
|
let sessionInitialized = false;
|
|
9670
|
-
const activeSession =
|
|
9801
|
+
const activeSession = Option16.isSome(compactionService) ? sessionService : Option16.none();
|
|
9671
9802
|
const sessionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9672
9803
|
const compactionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9673
9804
|
const memoryError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9674
9805
|
const skillError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
9675
9806
|
const isSkillActivationCall = (call) => call.name === activateSkillToolName && skillRuntime !== undefined && hasActivatableSkills;
|
|
9676
|
-
const insertRecalledItems = (turn, prompt, items) =>
|
|
9807
|
+
const insertRecalledItems = (turn, prompt, items) => Effect46.gen(function* () {
|
|
9677
9808
|
const parts = items.flatMap((item) => item.parts);
|
|
9678
9809
|
if (parts.length === 0)
|
|
9679
9810
|
return prompt;
|
|
9680
9811
|
const userParts = [];
|
|
9681
9812
|
for (const part of parts) {
|
|
9682
9813
|
if (!isUserMessagePart(part)) {
|
|
9683
|
-
return yield*
|
|
9814
|
+
return yield* Effect46.fail(new AgentError({
|
|
9684
9815
|
message: `Memory recalled unsupported prompt part type: ${part.type}`,
|
|
9685
9816
|
turn
|
|
9686
9817
|
}));
|
|
@@ -9691,12 +9822,12 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9691
9822
|
const [first, ...rest] = prompt.content;
|
|
9692
9823
|
return first?.role === "system" ? Prompt4.fromMessages([first, memoryMessage2, ...rest]) : Prompt4.fromMessages([memoryMessage2, ...prompt.content]);
|
|
9693
9824
|
});
|
|
9694
|
-
const recallInitialPrompt = (prompt) => memoryRuntime === undefined ?
|
|
9695
|
-
const rememberTurn = (turn, transcript, terminal) => memoryRuntime === undefined ?
|
|
9696
|
-
const syncSession = (turn, transcript) =>
|
|
9697
|
-
onNone: () =>
|
|
9698
|
-
onSome: (session) =>
|
|
9699
|
-
const existingPath = yield* session.path().pipe(
|
|
9825
|
+
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)));
|
|
9826
|
+
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)));
|
|
9827
|
+
const syncSession = (turn, transcript) => Option16.match(activeSession, {
|
|
9828
|
+
onNone: () => Effect46.succeed([]),
|
|
9829
|
+
onSome: (session) => Effect46.gen(function* () {
|
|
9830
|
+
const existingPath = yield* session.path().pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9700
9831
|
if (!sessionInitialized) {
|
|
9701
9832
|
sessionInitialized = true;
|
|
9702
9833
|
if (existingPath.length > 0) {
|
|
@@ -9705,40 +9836,40 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9705
9836
|
}
|
|
9706
9837
|
}
|
|
9707
9838
|
for (const message of transcript.content.slice(sessionSyncedMessages)) {
|
|
9708
|
-
yield* session.append({ _tag: "Message", message }).pipe(
|
|
9839
|
+
yield* session.append({ _tag: "Message", message }).pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9709
9840
|
}
|
|
9710
9841
|
sessionSyncedMessages = transcript.content.length;
|
|
9711
|
-
return yield* session.path().pipe(
|
|
9842
|
+
return yield* session.path().pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9712
9843
|
})
|
|
9713
9844
|
});
|
|
9714
9845
|
const countTokens = (turn, prompt) => {
|
|
9715
9846
|
if (state.contextTokens !== undefined)
|
|
9716
|
-
return
|
|
9717
|
-
return
|
|
9718
|
-
onNone: () =>
|
|
9719
|
-
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(
|
|
9847
|
+
return Effect46.succeed(state.contextTokens);
|
|
9848
|
+
return Option16.match(tokenizerService, {
|
|
9849
|
+
onNone: () => Effect46.succeed(0),
|
|
9850
|
+
onSome: (tokenizer) => tokenizer.tokenize(prompt).pipe(Effect46.map((tokens) => tokens.length), Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn, cause: error })))
|
|
9720
9851
|
});
|
|
9721
9852
|
};
|
|
9722
|
-
const compactionUsage = (turn, history, prompt) => countTokens(turn, Prompt4.concat(history, prompt)).pipe(
|
|
9853
|
+
const compactionUsage = (turn, history, prompt) => countTokens(turn, Prompt4.concat(history, prompt)).pipe(Effect46.map((contextTokens) => ({
|
|
9723
9854
|
contextTokens,
|
|
9724
9855
|
contextWindow: options.compaction?.contextWindow ?? Number.POSITIVE_INFINITY,
|
|
9725
9856
|
reserveTokens: DEFAULT_RESERVE_TOKENS
|
|
9726
9857
|
})));
|
|
9727
|
-
const applyCompactionResult = (turn, result) =>
|
|
9728
|
-
yield*
|
|
9858
|
+
const applyCompactionResult = (turn, result) => Effect46.gen(function* () {
|
|
9859
|
+
yield* Ref11.set(chat.history, result.history);
|
|
9729
9860
|
sessionSyncedMessages = result.history.content.length;
|
|
9730
|
-
if (result._tag === "Summarize" &&
|
|
9861
|
+
if (result._tag === "Summarize" && Option16.isSome(activeSession)) {
|
|
9731
9862
|
yield* activeSession.value.append({
|
|
9732
9863
|
_tag: "Compaction",
|
|
9733
9864
|
summary: result.summary,
|
|
9734
9865
|
firstKeptEntryId: result.firstKeptEntryId
|
|
9735
|
-
}).pipe(
|
|
9866
|
+
}).pipe(Effect46.mapError((error) => sessionError(turn, error)));
|
|
9736
9867
|
}
|
|
9737
9868
|
});
|
|
9738
|
-
const preparePrompt = (turn, prompt, overflow) =>
|
|
9739
|
-
onNone: () =>
|
|
9740
|
-
onSome: (compaction) =>
|
|
9741
|
-
const history = yield*
|
|
9869
|
+
const preparePrompt = (turn, prompt, overflow) => Option16.match(compactionService, {
|
|
9870
|
+
onNone: () => Effect46.succeed(prompt),
|
|
9871
|
+
onSome: (compaction) => Effect46.gen(function* () {
|
|
9872
|
+
const history = yield* Ref11.get(chat.history);
|
|
9742
9873
|
const path2 = yield* syncSession(turn, history);
|
|
9743
9874
|
const usage = yield* compactionUsage(turn, history, prompt);
|
|
9744
9875
|
const compacted = yield* compaction.maybeCompact({
|
|
@@ -9751,28 +9882,28 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9751
9882
|
usage,
|
|
9752
9883
|
overflow,
|
|
9753
9884
|
...options.toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes: options.toolOutputMaxBytes }
|
|
9754
|
-
}).pipe(
|
|
9755
|
-
if (
|
|
9885
|
+
}).pipe(Effect46.mapError((error) => compactionError(turn, error)));
|
|
9886
|
+
if (Option16.isNone(compacted))
|
|
9756
9887
|
return prompt;
|
|
9757
9888
|
yield* applyCompactionResult(turn, compacted.value);
|
|
9758
9889
|
return compacted.value.prompt;
|
|
9759
9890
|
})
|
|
9760
9891
|
});
|
|
9761
|
-
const boundedSuccessResult = (turn, call, outcome) => (options.toolOutputMaxBytes === undefined ?
|
|
9892
|
+
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)));
|
|
9762
9893
|
const outcomeEvents = (turn, call, outcome) => {
|
|
9763
9894
|
switch (outcome._tag) {
|
|
9764
9895
|
case "Success":
|
|
9765
|
-
return (isSkillActivationCall(call) ?
|
|
9896
|
+
return (isSkillActivationCall(call) ? Effect46.succeed(successResult(call, outcome)) : boundedSuccessResult(turn, call, outcome)).pipe(Effect46.map((result) => {
|
|
9766
9897
|
state.pending.push(result);
|
|
9767
9898
|
return Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9768
9899
|
}));
|
|
9769
9900
|
case "Failure": {
|
|
9770
9901
|
const result = failedResult(call, outcome.message);
|
|
9771
9902
|
state.pending.push(result);
|
|
9772
|
-
return
|
|
9903
|
+
return Effect46.succeed(Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]));
|
|
9773
9904
|
}
|
|
9774
9905
|
case "Suspend":
|
|
9775
|
-
return
|
|
9906
|
+
return Effect46.succeed(failSuspended(call, outcome.token, "tool-wait"));
|
|
9776
9907
|
}
|
|
9777
9908
|
};
|
|
9778
9909
|
const defaultExecute = (request) => {
|
|
@@ -9780,11 +9911,11 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9780
9911
|
return executeToolkit(agent.toolkit, request);
|
|
9781
9912
|
}
|
|
9782
9913
|
const activated = activatedSkillTools.get(request.call.name);
|
|
9783
|
-
return activated === undefined ?
|
|
9914
|
+
return activated === undefined ? Effect46.succeed({ _tag: "Failure", message: `Tool ${request.call.name} is not registered` }) : executeToolkit(Toolkit3.make(activated), request);
|
|
9784
9915
|
};
|
|
9785
|
-
const executeApproved = (turn, call, request) => Stream7.concat(Stream7.fromIterable([{ _tag: "ToolExecutionStarted", turn, call }]), Stream7.unwrap(
|
|
9916
|
+
const executeApproved = (turn, call, request) => Stream7.concat(Stream7.fromIterable([{ _tag: "ToolExecutionStarted", turn, call }]), Stream7.unwrap(Effect46.gen(function* () {
|
|
9786
9917
|
const progressQueue = yield* Queue2.unbounded();
|
|
9787
|
-
const signal = yield*
|
|
9918
|
+
const signal = yield* Effect46.abortSignal;
|
|
9788
9919
|
const context = ToolContext.of({
|
|
9789
9920
|
signal,
|
|
9790
9921
|
sessionId,
|
|
@@ -9796,14 +9927,14 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9796
9927
|
...progress.message === undefined ? {} : { message: progress.message },
|
|
9797
9928
|
...progress.data === undefined ? {} : { data: progress.data }
|
|
9798
9929
|
};
|
|
9799
|
-
return Queue2.offer(progressQueue, event).pipe(
|
|
9930
|
+
return Queue2.offer(progressQueue, event).pipe(Effect46.asVoid);
|
|
9800
9931
|
}
|
|
9801
9932
|
});
|
|
9802
|
-
const execution = isSkillActivationCall(call) ? activateSkillOutcome(turn, call) :
|
|
9933
|
+
const execution = isSkillActivationCall(call) ? activateSkillOutcome(turn, call) : Option16.match(executor, {
|
|
9803
9934
|
onNone: () => defaultExecute(request),
|
|
9804
9935
|
onSome: (service) => service.execute(request)
|
|
9805
9936
|
});
|
|
9806
|
-
const fiber = yield* execution.pipe(
|
|
9937
|
+
const fiber = yield* execution.pipe(Effect46.provideService(ToolContext, context), Effect46.ensuring(Queue2.end(progressQueue).pipe(Effect46.asVoid)), Effect46.forkScoped({ startImmediately: true }));
|
|
9807
9938
|
return Stream7.concat(Stream7.fromQueue(progressQueue), Stream7.fromEffect(Fiber.join(fiber)).pipe(Stream7.flatMap((outcome) => Stream7.unwrap(outcomeEvents(turn, call, outcome)))));
|
|
9808
9939
|
})));
|
|
9809
9940
|
const permissionError = (turn, error) => new AgentError({ message: error.message, turn, cause: error });
|
|
@@ -9812,13 +9943,13 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9812
9943
|
state.pending.push(result);
|
|
9813
9944
|
return Stream7.fromIterable([{ _tag: "ToolExecutionCompleted", turn, call, result }]);
|
|
9814
9945
|
};
|
|
9815
|
-
const activateSkillOutcome = (turn, call) =>
|
|
9946
|
+
const activateSkillOutcome = (turn, call) => Effect46.gen(function* () {
|
|
9816
9947
|
if (skillRuntime === undefined)
|
|
9817
9948
|
return { _tag: "Failure", message: "SkillSource is not available" };
|
|
9818
|
-
const params =
|
|
9819
|
-
if (
|
|
9949
|
+
const params = Schema48.decodeUnknownOption(activateSkillParameters)(call.params);
|
|
9950
|
+
if (Option16.isNone(params))
|
|
9820
9951
|
return { _tag: "Failure", message: "Skill activation requires a name" };
|
|
9821
|
-
const skill = yield* skillRuntime.source.get(params.value.name).pipe(
|
|
9952
|
+
const skill = yield* skillRuntime.source.get(params.value.name).pipe(Effect46.mapError((error) => skillError(turn, error)));
|
|
9822
9953
|
if (skill === undefined)
|
|
9823
9954
|
return { _tag: "Failure", message: `Skill not found: ${params.value.name}` };
|
|
9824
9955
|
if (skill.frontmatter.disableModelInvocation === true) {
|
|
@@ -9826,7 +9957,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9826
9957
|
}
|
|
9827
9958
|
let body = activatedSkillBodies.get(skill.frontmatter.name);
|
|
9828
9959
|
if (body === undefined) {
|
|
9829
|
-
body = yield* skill.body.pipe(
|
|
9960
|
+
body = yield* skill.body.pipe(Effect46.mapError((error) => skillError(turn, error)));
|
|
9830
9961
|
activatedSkillBodies.set(skill.frontmatter.name, body);
|
|
9831
9962
|
for (const tool2 of skill.tools) {
|
|
9832
9963
|
activatedSkillTools.set(tool2.name, tool2);
|
|
@@ -9839,14 +9970,14 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9839
9970
|
};
|
|
9840
9971
|
return { _tag: "Success", result: output, encodedResult: output };
|
|
9841
9972
|
});
|
|
9842
|
-
const rememberAlways = (turn, call) =>
|
|
9843
|
-
onNone: () =>
|
|
9844
|
-
onSome: (store) => store.remember({ pattern: call.name, level: "allow" }).pipe(
|
|
9973
|
+
const rememberAlways = (turn, call) => Effect46.serviceOption(RuleStore).pipe(Effect46.flatMap(Option16.match({
|
|
9974
|
+
onNone: () => Effect46.void,
|
|
9975
|
+
onSome: (store) => store.remember({ pattern: call.name, level: "allow" }).pipe(Effect46.mapError((error) => permissionError(turn, error)))
|
|
9845
9976
|
})));
|
|
9846
|
-
const approvalEvents = (turn, call, messages, request, tool2) => Stream7.unwrap(approvalRequired(tool2, call, messages).pipe(
|
|
9977
|
+
const approvalEvents = (turn, call, messages, request, tool2) => Stream7.unwrap(approvalRequired(tool2, call, messages).pipe(Effect46.map((isRequired) => {
|
|
9847
9978
|
if (!isRequired)
|
|
9848
9979
|
return executeApproved(turn, call, request);
|
|
9849
|
-
if (
|
|
9980
|
+
if (Option16.isNone(approvals)) {
|
|
9850
9981
|
const result = failedResult(call, "Approvals service is required for approval-gated tools");
|
|
9851
9982
|
state.pending.push(result);
|
|
9852
9983
|
return Stream7.fromIterable([
|
|
@@ -9854,7 +9985,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9854
9985
|
{ _tag: "ToolExecutionCompleted", turn, call, result }
|
|
9855
9986
|
]);
|
|
9856
9987
|
}
|
|
9857
|
-
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(approvals.value.check(request).pipe(
|
|
9988
|
+
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(approvals.value.check(request).pipe(Effect46.map((decision2) => {
|
|
9858
9989
|
switch (decision2._tag) {
|
|
9859
9990
|
case "Approved":
|
|
9860
9991
|
return executeApproved(turn, call, request);
|
|
@@ -9875,7 +10006,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9875
10006
|
case "Denied":
|
|
9876
10007
|
return permissionDeniedEvents(turn, call, answer.reason);
|
|
9877
10008
|
case "Always":
|
|
9878
|
-
return Stream7.unwrap(rememberAlways(turn, call).pipe(
|
|
10009
|
+
return Stream7.unwrap(rememberAlways(turn, call).pipe(Effect46.as(executeApproved(turn, call, request))));
|
|
9879
10010
|
}
|
|
9880
10011
|
};
|
|
9881
10012
|
const permissionAskEvents = (turn, call, request, token) => {
|
|
@@ -9887,9 +10018,9 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9887
10018
|
turn,
|
|
9888
10019
|
toolCallId: call.id
|
|
9889
10020
|
};
|
|
9890
|
-
if (
|
|
10021
|
+
if (Option16.isNone(permissionsService))
|
|
9891
10022
|
return failSuspended(call, token, "approval");
|
|
9892
|
-
return Stream7.concat(Stream7.fromIterable([{ _tag: "ApprovalRequested", turn, call }]), Stream7.unwrap(permissionsService.value.await(pending).pipe(
|
|
10023
|
+
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({
|
|
9893
10024
|
onNone: () => failSuspended(call, token, "approval"),
|
|
9894
10025
|
onSome: (answer) => permissionAnsweredEvents(turn, call, request, answer)
|
|
9895
10026
|
})))));
|
|
@@ -9897,7 +10028,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9897
10028
|
const toolCallEvents = (turn, call, messages) => {
|
|
9898
10029
|
const request = { call, turn, agentName: agent.name, sessionId };
|
|
9899
10030
|
const tool2 = currentToolkit().tools[call.name];
|
|
9900
|
-
if (
|
|
10031
|
+
if (Option16.isNone(permissionsService))
|
|
9901
10032
|
return approvalEvents(turn, call, messages, request, tool2);
|
|
9902
10033
|
return Stream7.unwrap(permissionsService.value.evaluate({
|
|
9903
10034
|
tool: call.name,
|
|
@@ -9906,7 +10037,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9906
10037
|
turn,
|
|
9907
10038
|
toolCallId: call.id,
|
|
9908
10039
|
sessionId
|
|
9909
|
-
}).pipe(
|
|
10040
|
+
}).pipe(Effect46.mapError((error) => permissionError(turn, error)), Effect46.map((decision2) => {
|
|
9910
10041
|
switch (decision2._tag) {
|
|
9911
10042
|
case "Allow":
|
|
9912
10043
|
return approvalEvents(turn, call, messages, request, tool2);
|
|
@@ -9917,8 +10048,8 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9917
10048
|
}
|
|
9918
10049
|
})));
|
|
9919
10050
|
};
|
|
9920
|
-
const captureFinishPart = (part) =>
|
|
9921
|
-
const span = yield*
|
|
10051
|
+
const captureFinishPart = (part) => Effect46.gen(function* () {
|
|
10052
|
+
const span = yield* Effect46.currentSpan;
|
|
9922
10053
|
state.finish = {
|
|
9923
10054
|
usage: state.finish === undefined ? part.usage : addUsage(state.finish.usage, part.usage),
|
|
9924
10055
|
reason: part.reason
|
|
@@ -9933,18 +10064,20 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9933
10064
|
},
|
|
9934
10065
|
response: { finishReasons: [part.reason] }
|
|
9935
10066
|
});
|
|
9936
|
-
}).pipe(
|
|
9937
|
-
const captureStructuredUsage = (content) =>
|
|
10067
|
+
}).pipe(Effect46.orDie);
|
|
10068
|
+
const captureStructuredUsage = (content) => Effect46.sync(() => {
|
|
9938
10069
|
for (const part of content) {
|
|
9939
10070
|
if (part.type === "finish") {
|
|
9940
10071
|
state.usage = state.usage === undefined ? part.usage : addUsage(state.usage, part.usage);
|
|
9941
10072
|
}
|
|
9942
10073
|
}
|
|
9943
10074
|
});
|
|
9944
|
-
const withModelResilience = (effect) =>
|
|
10075
|
+
const withModelResilience = (effect) => Option16.match(resilienceService, {
|
|
9945
10076
|
onNone: () => effect,
|
|
9946
|
-
onSome: (resilience) =>
|
|
10077
|
+
onSome: (resilience) => Effect46.flatMap(LanguageModel4.LanguageModel, (model) => effect.pipe(Effect46.provideService(LanguageModel4.LanguageModel, apply(model, resilience))))
|
|
9947
10078
|
});
|
|
10079
|
+
const withAgentModel = (effect) => agentModelContext === undefined ? effect : effect.pipe(Effect46.provide(agentModelContext));
|
|
10080
|
+
const provideAgentModel = (stream2) => agentModelContext === undefined ? stream2 : stream2.pipe(Stream7.provideContext(agentModelContext));
|
|
9948
10081
|
const partEvents = (turn, part, messages) => {
|
|
9949
10082
|
if (part.type === "error") {
|
|
9950
10083
|
return Stream7.fail(new AgentError({ message: errorMessage(part.error), turn, cause: part.error }));
|
|
@@ -9962,7 +10095,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9962
10095
|
}
|
|
9963
10096
|
return modelPart;
|
|
9964
10097
|
};
|
|
9965
|
-
const applyPartToEvents = (turn, part, messages) => Stream7.unwrap(applyPartChain(chain, part, { agentName: agent.name, turn }).pipe(
|
|
10098
|
+
const applyPartToEvents = (turn, part, messages) => Stream7.unwrap(applyPartChain(chain, part, { agentName: agent.name, turn }).pipe(Effect46.map(Option16.match({
|
|
9966
10099
|
onSome: (transformed) => partEvents(turn, transformed, messages),
|
|
9967
10100
|
onNone: () => part.type === "tool-call" ? Stream7.fail(new MiddlewareViolation({
|
|
9968
10101
|
turn,
|
|
@@ -9973,18 +10106,18 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9973
10106
|
const activeToolkit = (activeTools) => Toolkit3.make(...Object.values(currentToolkit().tools).filter((tool2) => activeTools.includes(tool2.name)));
|
|
9974
10107
|
const modelTurn = (turn, prompt, overrides) => {
|
|
9975
10108
|
const toolkit = overrides?.activeTools === undefined ? currentToolkit() : activeToolkit(overrides.activeTools);
|
|
9976
|
-
const attempt = (activePrompt, retryOverflow) => Stream7.unwrap(
|
|
10109
|
+
const attempt = (activePrompt, retryOverflow) => Stream7.unwrap(Ref11.get(chat.history).pipe(Effect46.map((historyBeforeAttempt) => {
|
|
9977
10110
|
let emitted = false;
|
|
9978
10111
|
const messages = Prompt4.concat(historyBeforeAttempt, activePrompt).content;
|
|
9979
|
-
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(Stream7.map((part) => ({ part, messages })), Stream7.tap(() =>
|
|
10112
|
+
return chat.streamText({ prompt: activePrompt, toolkit, disableToolCallResolution: true }).pipe(Stream7.map((part) => ({ part, messages })), Stream7.tap(() => Effect46.sync(() => {
|
|
9980
10113
|
emitted = true;
|
|
9981
10114
|
})), Stream7.catchCause((cause) => {
|
|
9982
10115
|
if (Cause3.hasInterrupts(cause))
|
|
9983
|
-
return Stream7.fromEffect(
|
|
10116
|
+
return Stream7.fromEffect(Effect46.interrupt);
|
|
9984
10117
|
const error = Cause3.squash(cause);
|
|
9985
|
-
if (retryOverflow && !emitted && isContextOverflow(error) &&
|
|
9986
|
-
return Stream7.unwrap(
|
|
9987
|
-
yield*
|
|
10118
|
+
if (retryOverflow && !emitted && isContextOverflow(error) && Option16.isSome(compactionService)) {
|
|
10119
|
+
return Stream7.unwrap(Effect46.gen(function* () {
|
|
10120
|
+
yield* Ref11.set(chat.history, historyBeforeAttempt);
|
|
9988
10121
|
const compactedPrompt = yield* preparePrompt(turn, activePrompt, true);
|
|
9989
10122
|
return attempt(compactedPrompt, false);
|
|
9990
10123
|
}));
|
|
@@ -9992,12 +10125,12 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
9992
10125
|
return Stream7.make({ part: Response3.makePart("error", { error }), messages });
|
|
9993
10126
|
}));
|
|
9994
10127
|
})));
|
|
9995
|
-
const parts = Stream7.unwrap(applyPromptChain(chain, Prompt4.make(prompt), { agentName: agent.name, turn }).pipe(
|
|
9996
|
-
const resilientParts =
|
|
10128
|
+
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))))));
|
|
10129
|
+
const resilientParts = Option16.match(resilienceService, {
|
|
9997
10130
|
onNone: () => parts,
|
|
9998
|
-
onSome: (resilience) => Stream7.unwrap(
|
|
10131
|
+
onSome: (resilience) => Stream7.unwrap(LanguageModel4.LanguageModel.pipe(Effect46.map((model) => parts.pipe(Stream7.provideService(LanguageModel4.LanguageModel, apply(model, resilience))))))
|
|
9999
10132
|
});
|
|
10000
|
-
return overrides?.model === undefined ? resilientParts : resilientParts.pipe(Stream7.provide(overrides.model));
|
|
10133
|
+
return overrides?.model === undefined ? provideAgentModel(resilientParts) : resilientParts.pipe(Stream7.provide(overrides.model));
|
|
10001
10134
|
};
|
|
10002
10135
|
const turnCompletedEvent = (turn, transcript) => ({
|
|
10003
10136
|
_tag: "TurnCompleted",
|
|
@@ -10012,21 +10145,21 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10012
10145
|
transcript,
|
|
10013
10146
|
...state.usage === undefined ? {} : { usage: state.usage }
|
|
10014
10147
|
});
|
|
10015
|
-
const structuredFinalEvents = (turn, config) => Stream7.fromEffect(
|
|
10148
|
+
const structuredFinalEvents = (turn, config) => Stream7.fromEffect(Effect46.gen(function* () {
|
|
10016
10149
|
const structuredTurn = turn + 1;
|
|
10017
10150
|
const transformedPrompt = yield* applyPromptChain(chain, Prompt4.make(config.objectPrompt), {
|
|
10018
10151
|
agentName: agent.name,
|
|
10019
10152
|
turn: structuredTurn
|
|
10020
10153
|
});
|
|
10021
|
-
const response = yield* withModelResilience(chat.generateObject({
|
|
10154
|
+
const response = yield* withAgentModel(withModelResilience(chat.generateObject({
|
|
10022
10155
|
prompt: transformedPrompt,
|
|
10023
10156
|
schema: config.schema,
|
|
10024
10157
|
objectName: config.objectName,
|
|
10025
10158
|
toolChoice: "none"
|
|
10026
|
-
})).pipe(
|
|
10159
|
+
}))).pipe(Effect46.mapError((error) => new AgentError({ message: errorMessage(error), turn: structuredTurn, cause: error })));
|
|
10027
10160
|
yield* captureStructuredUsage(response.content);
|
|
10028
10161
|
yield* savePersisted;
|
|
10029
|
-
const transcript = yield*
|
|
10162
|
+
const transcript = yield* Ref11.get(chat.history);
|
|
10030
10163
|
const structuredOutput = {
|
|
10031
10164
|
_tag: "StructuredOutput",
|
|
10032
10165
|
turn: structuredTurn,
|
|
@@ -10036,16 +10169,16 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10036
10169
|
return [structuredOutput, terminalCompletedEvent(structuredTurn, transcript)];
|
|
10037
10170
|
})).pipe(Stream7.flatMap((events) => Stream7.fromIterable(events)));
|
|
10038
10171
|
const promptFromSteeringMessages = (messages) => messages.reduce((prompt, message) => Prompt4.concat(prompt, message.prompt), Prompt4.empty);
|
|
10039
|
-
const takeSteering = () =>
|
|
10040
|
-
onNone: () =>
|
|
10172
|
+
const takeSteering = () => Option16.match(steeringService, {
|
|
10173
|
+
onNone: () => Effect46.succeed([]),
|
|
10041
10174
|
onSome: (service) => service.takeSteering()
|
|
10042
10175
|
});
|
|
10043
|
-
const takeFollowUp = () =>
|
|
10044
|
-
onNone: () =>
|
|
10176
|
+
const takeFollowUp = () => Option16.match(steeringService, {
|
|
10177
|
+
onNone: () => Effect46.succeed([]),
|
|
10045
10178
|
onSome: (service) => service.takeFollowUp()
|
|
10046
10179
|
});
|
|
10047
|
-
const afterTurn = (turn) =>
|
|
10048
|
-
const transcript = yield*
|
|
10180
|
+
const afterTurn = (turn) => Effect46.gen(function* () {
|
|
10181
|
+
const transcript = yield* Ref11.get(chat.history);
|
|
10049
10182
|
yield* syncSession(turn, transcript);
|
|
10050
10183
|
const pending = state.pending;
|
|
10051
10184
|
yield* rememberTurn(turn, transcript, pending.length === 0);
|
|
@@ -10100,7 +10233,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10100
10233
|
}).pipe(Stream7.drain);
|
|
10101
10234
|
const runTurn = (turn, prompt, overrides) => {
|
|
10102
10235
|
let next;
|
|
10103
|
-
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(
|
|
10236
|
+
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) => {
|
|
10104
10237
|
next = result.next;
|
|
10105
10238
|
return result.events;
|
|
10106
10239
|
})))), Stream7.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": turn } }));
|
|
@@ -10114,7 +10247,7 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10114
10247
|
params: resume.call.params,
|
|
10115
10248
|
providerExecuted: false
|
|
10116
10249
|
});
|
|
10117
|
-
const currentTurn = resetTurnState(0).pipe(Stream7.concat(Stream7.unwrap(
|
|
10250
|
+
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) => {
|
|
10118
10251
|
next = result.next;
|
|
10119
10252
|
return result.events;
|
|
10120
10253
|
})))), Stream7.withSpan("Baton.Agent.turn", { attributes: { "baton.turn": 0 } }));
|
|
@@ -10125,10 +10258,10 @@ var streamInternal = (agent, options, structured) => Stream7.unwrap(Effect45.gen
|
|
|
10125
10258
|
const runStream = options.resume === undefined ? runTurn(0, initialPrompt) : resumeStream(options.resume);
|
|
10126
10259
|
return runStream.pipe(Stream7.catchCause((cause) => {
|
|
10127
10260
|
if (Cause3.hasInterrupts(cause))
|
|
10128
|
-
return Stream7.fromEffect(
|
|
10261
|
+
return Stream7.fromEffect(Effect46.interrupt);
|
|
10129
10262
|
const error = Cause3.squash(cause);
|
|
10130
10263
|
if (error instanceof AgentSuspended) {
|
|
10131
|
-
return Stream7.unwrap(
|
|
10264
|
+
return Stream7.unwrap(Ref11.get(chat.history).pipe(Effect46.map((transcript) => Stream7.concat(Stream7.fromIterable([turnCompletedEvent(state.turn, transcript)]), Stream7.failCause(cause)))));
|
|
10132
10265
|
}
|
|
10133
10266
|
return Stream7.failCause(cause);
|
|
10134
10267
|
}));
|
|
@@ -10139,29 +10272,29 @@ var streamObject = (agent, options) => streamInternal(agent, options, {
|
|
|
10139
10272
|
objectName: options.objectName ?? "output",
|
|
10140
10273
|
objectPrompt: options.objectPrompt ?? defaultObjectPrompt
|
|
10141
10274
|
});
|
|
10142
|
-
var generate = (agent, options) => Stream7.runLast(stream2(agent, options)).pipe(
|
|
10143
|
-
onNone: () =>
|
|
10144
|
-
onSome: (event) => event._tag === "Completed" ?
|
|
10275
|
+
var generate = (agent, options) => Stream7.runLast(stream2(agent, options)).pipe(Effect46.flatMap(Option16.match({
|
|
10276
|
+
onNone: () => Effect46.fail(new AgentError({ message: "Agent run ended without a Completed event", turn: 0 })),
|
|
10277
|
+
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 }))
|
|
10145
10278
|
})));
|
|
10146
10279
|
var generateObject = (agent, options) => Stream7.runFold(streamObject(agent, options), () => ({
|
|
10147
|
-
value:
|
|
10148
|
-
completed:
|
|
10280
|
+
value: Option16.none(),
|
|
10281
|
+
completed: Option16.none()
|
|
10149
10282
|
}), (acc, event) => {
|
|
10150
10283
|
if (event._tag === "StructuredOutput") {
|
|
10151
|
-
return { ...acc, value:
|
|
10284
|
+
return { ...acc, value: Option16.some(event.value) };
|
|
10152
10285
|
}
|
|
10153
10286
|
if (event._tag === "Completed") {
|
|
10154
|
-
return { ...acc, completed:
|
|
10287
|
+
return { ...acc, completed: Option16.some(event) };
|
|
10155
10288
|
}
|
|
10156
10289
|
return acc;
|
|
10157
|
-
}).pipe(
|
|
10158
|
-
onNone: () =>
|
|
10159
|
-
onSome: (event) =>
|
|
10160
|
-
onNone: () =>
|
|
10290
|
+
}).pipe(Effect46.flatMap(({ value, completed }) => Option16.match(completed, {
|
|
10291
|
+
onNone: () => Effect46.fail(new AgentError({ message: "Agent object run ended without a Completed event", turn: 0 })),
|
|
10292
|
+
onSome: (event) => Option16.match(value, {
|
|
10293
|
+
onNone: () => Effect46.fail(new AgentError({
|
|
10161
10294
|
message: "Agent object run ended without a StructuredOutput event",
|
|
10162
10295
|
turn: 0
|
|
10163
10296
|
})),
|
|
10164
|
-
onSome: (typedValue) =>
|
|
10297
|
+
onSome: (typedValue) => Effect46.succeed({
|
|
10165
10298
|
text: event.text,
|
|
10166
10299
|
turns: event.turns,
|
|
10167
10300
|
transcript: event.transcript,
|
|
@@ -10169,14 +10302,14 @@ var generateObject = (agent, options) => Stream7.runFold(streamObject(agent, opt
|
|
|
10169
10302
|
})
|
|
10170
10303
|
})
|
|
10171
10304
|
})));
|
|
10172
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10305
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/agent-tool.ts
|
|
10173
10306
|
var exports_agent_tool = {};
|
|
10174
10307
|
__export(exports_agent_tool, {
|
|
10175
10308
|
asTool: () => asTool
|
|
10176
10309
|
});
|
|
10177
|
-
import { Cause as Cause4, Effect as
|
|
10310
|
+
import { Cause as Cause4, Effect as Effect47, Schema as Schema49 } from "effect";
|
|
10178
10311
|
import { Tool as Tool5, Toolkit as Toolkit4 } from "effect/unstable/ai";
|
|
10179
|
-
var defaultParameters =
|
|
10312
|
+
var defaultParameters = Schema49.Struct({ prompt: Schema49.String });
|
|
10180
10313
|
var errorMessage2 = (error) => {
|
|
10181
10314
|
if (error instanceof AgentSuspended) {
|
|
10182
10315
|
return `suspended on ${error.tool_name}: ${error.reason}`;
|
|
@@ -10195,39 +10328,39 @@ var errorMessage2 = (error) => {
|
|
|
10195
10328
|
var causeMessage = (agentName, cause) => `sub-agent '${agentName}' could not complete: ${errorMessage2(Cause4.squash(cause))}`;
|
|
10196
10329
|
var lazyHandled = (toolkit, name, handler) => ({
|
|
10197
10330
|
tools: toolkit.tools,
|
|
10198
|
-
handle: (toolName, params) => toolkit.pipe(
|
|
10331
|
+
handle: (toolName, params) => toolkit.pipe(Effect47.provide(toolkit.toLayer({
|
|
10199
10332
|
[name]: handler
|
|
10200
|
-
})),
|
|
10333
|
+
})), Effect47.flatMap((handled) => handled.handle(toolName, params)))
|
|
10201
10334
|
});
|
|
10202
10335
|
var asTool = (agent, options = {}) => {
|
|
10203
10336
|
const name = options.name ?? agent.name;
|
|
10204
10337
|
const parameters = options.parameters ?? defaultParameters;
|
|
10205
|
-
const success2 = options.success ??
|
|
10338
|
+
const success2 = options.success ?? Schema49.String;
|
|
10206
10339
|
const toPrompt = options.toPrompt ?? ((params) => params.prompt);
|
|
10207
10340
|
const fromResult = options.fromResult ?? ((result) => result.text);
|
|
10208
10341
|
const tool2 = Tool5.make(name, {
|
|
10209
10342
|
...options.description === undefined ? {} : { description: options.description },
|
|
10210
10343
|
parameters,
|
|
10211
10344
|
success: success2,
|
|
10212
|
-
failure:
|
|
10345
|
+
failure: Schema49.String,
|
|
10213
10346
|
failureMode: "return"
|
|
10214
10347
|
});
|
|
10215
10348
|
const toolkit = Toolkit4.make(tool2);
|
|
10216
|
-
const handler = (params) =>
|
|
10217
|
-
const prompt = yield*
|
|
10218
|
-
const result = yield* generate(agent, { prompt }).pipe(
|
|
10349
|
+
const handler = (params) => Effect47.gen(function* () {
|
|
10350
|
+
const prompt = yield* Effect47.try({ try: () => toPrompt(params), catch: errorMessage2 });
|
|
10351
|
+
const result = yield* generate(agent, { prompt }).pipe(Effect47.catchCause((cause) => {
|
|
10219
10352
|
if (Cause4.hasInterrupts(cause))
|
|
10220
|
-
return
|
|
10353
|
+
return Effect47.interrupt;
|
|
10221
10354
|
const error = Cause4.squash(cause);
|
|
10222
10355
|
if (error instanceof AgentSuspended)
|
|
10223
|
-
return
|
|
10224
|
-
return
|
|
10356
|
+
return Effect47.die(error);
|
|
10357
|
+
return Effect47.fail(causeMessage(agent.name, cause));
|
|
10225
10358
|
}));
|
|
10226
|
-
return yield*
|
|
10359
|
+
return yield* Effect47.try({ try: () => fromResult(result), catch: errorMessage2 });
|
|
10227
10360
|
});
|
|
10228
10361
|
return lazyHandled(toolkit, name, handler);
|
|
10229
10362
|
};
|
|
10230
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10363
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/guardrail.ts
|
|
10231
10364
|
var exports_guardrail = {};
|
|
10232
10365
|
__export(exports_guardrail, {
|
|
10233
10366
|
validateInput: () => validateInput2,
|
|
@@ -10235,7 +10368,7 @@ __export(exports_guardrail, {
|
|
|
10235
10368
|
redactInput: () => redactInput,
|
|
10236
10369
|
filterOutput: () => filterOutput
|
|
10237
10370
|
});
|
|
10238
|
-
import { Effect as
|
|
10371
|
+
import { Effect as Effect48, Option as Option17 } from "effect";
|
|
10239
10372
|
import { Prompt as Prompt6, Response as Response4 } from "effect/unstable/ai";
|
|
10240
10373
|
var replacement = (options) => options.replacement ?? "[redacted]";
|
|
10241
10374
|
var redactText = (text3, options) => text3.replace(options.pattern, replacement(options));
|
|
@@ -10285,19 +10418,19 @@ var redactPromptText = (prompt, options) => Prompt6.fromMessages(prompt.content.
|
|
|
10285
10418
|
}
|
|
10286
10419
|
}));
|
|
10287
10420
|
var validateInput2 = (check2) => ({
|
|
10288
|
-
transformPrompt: (prompt, context) => check2(prompt, context).pipe(
|
|
10289
|
-
onNone: () =>
|
|
10290
|
-
onSome: (reason) =>
|
|
10421
|
+
transformPrompt: (prompt, context) => check2(prompt, context).pipe(Effect48.flatMap(Option17.match({
|
|
10422
|
+
onNone: () => Effect48.succeed(prompt),
|
|
10423
|
+
onSome: (reason) => Effect48.fail(new AgentError({ message: `Input guardrail blocked: ${reason}`, turn: context.turn }))
|
|
10291
10424
|
})))
|
|
10292
10425
|
});
|
|
10293
10426
|
var redactInput = (options) => ({
|
|
10294
|
-
transformPrompt: (prompt) =>
|
|
10427
|
+
transformPrompt: (prompt) => Effect48.succeed(redactPromptText(prompt, options))
|
|
10295
10428
|
});
|
|
10296
10429
|
var redactOutput = (options) => ({
|
|
10297
10430
|
transformPart: (part) => {
|
|
10298
10431
|
if (part.type !== "text-delta")
|
|
10299
|
-
return
|
|
10300
|
-
return
|
|
10432
|
+
return Effect48.succeed(Option17.some(part));
|
|
10433
|
+
return Effect48.succeed(Option17.some(Response4.makePart("text-delta", {
|
|
10301
10434
|
id: part.id,
|
|
10302
10435
|
delta: redactText(part.delta, options),
|
|
10303
10436
|
metadata: part.metadata
|
|
@@ -10305,22 +10438,22 @@ var redactOutput = (options) => ({
|
|
|
10305
10438
|
}
|
|
10306
10439
|
});
|
|
10307
10440
|
var filterOutput = (keep) => ({
|
|
10308
|
-
transformPart: (part, context) =>
|
|
10441
|
+
transformPart: (part, context) => Effect48.succeed(part.type === "tool-call" || keep(part, context) ? Option17.some(part) : Option17.none())
|
|
10309
10442
|
});
|
|
10310
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10443
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/handoff.ts
|
|
10311
10444
|
var exports_handoff = {};
|
|
10312
10445
|
__export(exports_handoff, {
|
|
10313
10446
|
transferTool: () => transferTool,
|
|
10314
10447
|
supervisor: () => supervisor,
|
|
10315
10448
|
fanOut: () => fanOut
|
|
10316
10449
|
});
|
|
10317
|
-
import { Effect as
|
|
10450
|
+
import { Effect as Effect49, Schema as Schema50 } from "effect";
|
|
10318
10451
|
import { AiError as AiError2, Toolkit as Toolkit5 } from "effect/unstable/ai";
|
|
10319
|
-
var defaultTransferParameters =
|
|
10452
|
+
var defaultTransferParameters = Schema50.Struct({ prompt: Schema50.String });
|
|
10320
10453
|
var transferName = (agentName) => `transfer_to_${agentName}`;
|
|
10321
10454
|
var positiveConcurrency = (value) => {
|
|
10322
10455
|
const concurrency = value ?? 4;
|
|
10323
|
-
return Number.isInteger(concurrency) && concurrency > 0 ?
|
|
10456
|
+
return Number.isInteger(concurrency) && concurrency > 0 ? Effect49.succeed(concurrency) : Effect49.fail(new AgentError({
|
|
10324
10457
|
message: "Handoff.fanOut concurrency must be a positive integer",
|
|
10325
10458
|
turn: 0
|
|
10326
10459
|
}));
|
|
@@ -10334,7 +10467,7 @@ var mergeHandled = (toolkits) => {
|
|
|
10334
10467
|
tools,
|
|
10335
10468
|
handle: (name, params) => {
|
|
10336
10469
|
const toolkit = toolkits.find((candidate) => candidate.tools[name] !== undefined);
|
|
10337
|
-
return toolkit === undefined ?
|
|
10470
|
+
return toolkit === undefined ? Effect49.fail(AiError2.make({
|
|
10338
10471
|
module: "Handoff",
|
|
10339
10472
|
method: `${String(name)}.handle`,
|
|
10340
10473
|
reason: new AiError2.ToolNotFoundError({
|
|
@@ -10354,7 +10487,7 @@ var transferTool = (target, options = {}) => asTool(target, {
|
|
|
10354
10487
|
...options.toPrompt === undefined ? {} : { toPrompt: options.toPrompt },
|
|
10355
10488
|
...options.fromResult === undefined ? {} : { fromResult: options.fromResult }
|
|
10356
10489
|
});
|
|
10357
|
-
var fanOut = (children, options = {}) => positiveConcurrency(options.concurrency).pipe(
|
|
10490
|
+
var fanOut = (children, options = {}) => positiveConcurrency(options.concurrency).pipe(Effect49.flatMap((concurrency) => Effect49.forEach(children, (child) => generate(child.agent, { ...child.options, prompt: child.prompt }), {
|
|
10358
10491
|
concurrency
|
|
10359
10492
|
})));
|
|
10360
10493
|
var supervisor = (options) => {
|
|
@@ -10370,96 +10503,8 @@ var supervisor = (options) => {
|
|
|
10370
10503
|
toolkit
|
|
10371
10504
|
};
|
|
10372
10505
|
};
|
|
10373
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.3/node_modules/@batonfx/core/src/model-registry.ts
|
|
10374
|
-
var exports_model_registry = {};
|
|
10375
|
-
__export(exports_model_registry, {
|
|
10376
|
-
testLayer: () => testLayer38,
|
|
10377
|
-
registrations: () => registrations,
|
|
10378
|
-
registrationFromLayer: () => registrationFromLayer,
|
|
10379
|
-
register: () => register4,
|
|
10380
|
-
provide: () => provide,
|
|
10381
|
-
memoryLayer: () => memoryLayer25,
|
|
10382
|
-
layerFromRegistrationEffects: () => layerFromRegistrationEffects,
|
|
10383
|
-
layer: () => layer31,
|
|
10384
|
-
combine: () => combine,
|
|
10385
|
-
Service: () => Service29,
|
|
10386
|
-
LanguageModelNotRegistered: () => LanguageModelNotRegistered
|
|
10387
|
-
});
|
|
10388
|
-
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";
|
|
10389
|
-
import { Model } from "effect/unstable/ai";
|
|
10390
|
-
|
|
10391
|
-
class LanguageModelNotRegistered extends Schema50.TaggedErrorClass()("LanguageModelNotRegistered", {
|
|
10392
|
-
provider: Schema50.String,
|
|
10393
|
-
model: Schema50.String,
|
|
10394
|
-
registration_key: Schema50.optionalKey(Schema50.String)
|
|
10395
|
-
}) {
|
|
10396
|
-
}
|
|
10397
|
-
|
|
10398
|
-
class Service29 extends Context42.Service()("@batonfx/core/ModelRegistry") {
|
|
10399
|
-
}
|
|
10400
|
-
var registrationVariantKey = (value) => value.registrationKey ?? null;
|
|
10401
|
-
var selectionVariantKey = (selection) => selection.registrationKey ?? null;
|
|
10402
|
-
var registryIdentity = (registration) => JSON.stringify([registration.provider, registration.model, registrationVariantKey(registration)]);
|
|
10403
|
-
var matchesSelection = (selection) => (registration) => registration.provider === selection.provider && registration.model === selection.model && registrationVariantKey(registration) === selectionVariantKey(selection);
|
|
10404
|
-
var upsertRegistration = (registry, registration) => {
|
|
10405
|
-
const key2 = registryIdentity(registration);
|
|
10406
|
-
const exists = Option17.isSome(Chunk2.findFirst(registry, (item) => registryIdentity(item) === key2));
|
|
10407
|
-
if (!exists)
|
|
10408
|
-
return Chunk2.append(registry, registration);
|
|
10409
|
-
return Chunk2.map(registry, (item) => registryIdentity(item) === key2 ? registration : item);
|
|
10410
|
-
};
|
|
10411
|
-
var findRegistration = (registry, selection) => Chunk2.findFirst(registry, matchesSelection(selection)).pipe(Option17.getOrUndefined);
|
|
10412
|
-
var registrationFromLayer = (input) => Model.make(input.provider, input.model, input.layer).captureRequirements.pipe(Effect49.map((layer31) => ({
|
|
10413
|
-
provider: input.provider,
|
|
10414
|
-
model: input.model,
|
|
10415
|
-
layer: layer31,
|
|
10416
|
-
...input.registrationKey === undefined ? {} : { registrationKey: input.registrationKey },
|
|
10417
|
-
...input.metadata === undefined ? {} : { metadata: input.metadata }
|
|
10418
|
-
})));
|
|
10419
|
-
var layer31 = (initialRegistrations = [], options) => Layer43.effect(Service29, Effect49.gen(function* () {
|
|
10420
|
-
const registry = yield* Ref11.make(initialRegistrations.reduce(upsertRegistration, Chunk2.empty()));
|
|
10421
|
-
const semaphore = options?.maxConcurrentModelCalls === undefined ? undefined : yield* Semaphore3.make(options.maxConcurrentModelCalls);
|
|
10422
|
-
const register4 = Effect49.fn("ModelRegistry.register")(function* (input) {
|
|
10423
|
-
yield* Ref11.update(registry, (items) => upsertRegistration(items, input.registration));
|
|
10424
|
-
});
|
|
10425
|
-
const registrations = Ref11.get(registry).pipe(Effect49.map(Chunk2.toReadonlyArray));
|
|
10426
|
-
const provide = Effect49.fn("ModelRegistry.provide")(function* (selection, effect) {
|
|
10427
|
-
const items = yield* Ref11.get(registry);
|
|
10428
|
-
const registration = findRegistration(items, selection);
|
|
10429
|
-
if (registration === undefined) {
|
|
10430
|
-
return yield* Effect49.fail(new LanguageModelNotRegistered({
|
|
10431
|
-
provider: selection.provider,
|
|
10432
|
-
model: selection.model,
|
|
10433
|
-
...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
|
|
10434
|
-
}));
|
|
10435
|
-
}
|
|
10436
|
-
const provided = effect.pipe(Effect49.provide(registration.layer));
|
|
10437
|
-
return yield* semaphore === undefined ? provided : semaphore.withPermits(1)(provided);
|
|
10438
|
-
});
|
|
10439
|
-
return Service29.of({
|
|
10440
|
-
register: register4,
|
|
10441
|
-
registrations,
|
|
10442
|
-
provide
|
|
10443
|
-
});
|
|
10444
|
-
}));
|
|
10445
|
-
var layerFromRegistrationEffects = (registrations, options) => Layer43.unwrap(Effect49.all(registrations).pipe(Effect49.map((items) => layer31(items, options))));
|
|
10446
|
-
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))));
|
|
10447
|
-
var memoryLayer25 = layer31;
|
|
10448
|
-
var testLayer38 = (implementation) => Layer43.succeed(Service29, Service29.of(implementation));
|
|
10449
|
-
var register4 = Effect49.fn("ModelRegistry.register.call")(function* (input) {
|
|
10450
|
-
const service = yield* Service29;
|
|
10451
|
-
return yield* service.register(input);
|
|
10452
|
-
});
|
|
10453
|
-
var registrations = Effect49.fn("ModelRegistry.registrations.call")(function* () {
|
|
10454
|
-
const service = yield* Service29;
|
|
10455
|
-
return yield* service.registrations;
|
|
10456
|
-
});
|
|
10457
|
-
var provide = (selection, effect) => Effect49.gen(function* () {
|
|
10458
|
-
const service = yield* Service29;
|
|
10459
|
-
return yield* service.provide(selection, effect);
|
|
10460
|
-
});
|
|
10461
10506
|
|
|
10462
|
-
// ../../node_modules/.bun/@batonfx+core@0.3.
|
|
10507
|
+
// ../../node_modules/.bun/@batonfx+core@0.3.6/node_modules/@batonfx/core/src/index.ts
|
|
10463
10508
|
import {
|
|
10464
10509
|
AiError as AiError3,
|
|
10465
10510
|
Chat as Chat2,
|
|
@@ -11255,7 +11300,15 @@ var make6 = (options = {}) => Effect54.gen(function* () {
|
|
|
11255
11300
|
createdAt
|
|
11256
11301
|
}).pipe(Effect54.mapError(memoryError));
|
|
11257
11302
|
});
|
|
11258
|
-
|
|
11303
|
+
const forget2 = Effect54.fn("MemoryService.forget")(function* (input) {
|
|
11304
|
+
const subject = yield* decodeSubject(input.key.subject);
|
|
11305
|
+
yield* repository.forget({
|
|
11306
|
+
agent: input.key.agent,
|
|
11307
|
+
subject,
|
|
11308
|
+
...input.id === undefined ? {} : { id: input.id }
|
|
11309
|
+
}).pipe(Effect54.mapError(memoryError));
|
|
11310
|
+
});
|
|
11311
|
+
return { recall, remember: remember2, forget: forget2 };
|
|
11259
11312
|
});
|
|
11260
11313
|
var serviceLayer = (options) => Layer47.effect(Service33, make6(options).pipe(Effect54.map(Service33.of)));
|
|
11261
11314
|
var batonLayer = Layer47.effect(exports_memory.Memory, Effect54.gen(function* () {
|
|
@@ -11271,6 +11324,10 @@ var remember2 = Effect54.fn("MemoryService.remember.call")(function* (input) {
|
|
|
11271
11324
|
const service = yield* Service33;
|
|
11272
11325
|
return yield* service.remember(input);
|
|
11273
11326
|
});
|
|
11327
|
+
var forget2 = Effect54.fn("MemoryService.forget.call")(function* (input) {
|
|
11328
|
+
const service = yield* Service33;
|
|
11329
|
+
return yield* service.forget(input);
|
|
11330
|
+
});
|
|
11274
11331
|
|
|
11275
11332
|
// ../runtime/src/model/language-model-service.ts
|
|
11276
11333
|
var exports_language_model_service = {};
|
|
@@ -12586,7 +12643,8 @@ var terminalMemoryTranscript = (prompt, text3) => {
|
|
|
12586
12643
|
};
|
|
12587
12644
|
var recallOnlyMemory = (memory) => exports_memory.Memory.of({
|
|
12588
12645
|
recall: memory.recall,
|
|
12589
|
-
remember: () => Effect67.void
|
|
12646
|
+
remember: () => Effect67.void,
|
|
12647
|
+
forget: () => Effect67.void
|
|
12590
12648
|
});
|
|
12591
12649
|
var metadataValue = (metadata11, key2) => metadata11?.[key2];
|
|
12592
12650
|
var decodeOptionalNumber = (value, key2, valid) => {
|
|
@@ -15583,7 +15641,7 @@ __export(exports_language_model_registration, {
|
|
|
15583
15641
|
anthropic: () => anthropic
|
|
15584
15642
|
});
|
|
15585
15643
|
|
|
15586
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15644
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/anthropic.ts
|
|
15587
15645
|
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic";
|
|
15588
15646
|
import { Layer as Layer70 } from "effect";
|
|
15589
15647
|
import { FetchHttpClient as FetchHttpClient2 } from "effect/unstable/http";
|
|
@@ -15599,13 +15657,13 @@ var anthropic = (input) => exports_model_registry.registrationFromLayer({
|
|
|
15599
15657
|
});
|
|
15600
15658
|
var anthropicClientLayerConfig = AnthropicClient.layerConfig;
|
|
15601
15659
|
var withAnthropic = (options) => exports_model_registry.layerFromRegistrationEffects([anthropic(options)]).pipe(Layer70.provide(AnthropicClient.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer70.provide(FetchHttpClient2.layer));
|
|
15602
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15660
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/deterministic.ts
|
|
15603
15661
|
import { OpenAiClient as OpenAiClient3 } from "@effect/ai-openai";
|
|
15604
15662
|
import { Effect as Effect79, Layer as Layer72, Option as Option28, Stream as Stream11 } from "effect";
|
|
15605
15663
|
import { LanguageModel as LanguageModel8, Response as Response7 } from "effect/unstable/ai";
|
|
15606
15664
|
import { FetchHttpClient as FetchHttpClient4 } from "effect/unstable/http";
|
|
15607
15665
|
|
|
15608
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15666
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openai.ts
|
|
15609
15667
|
import { OpenAiClient as OpenAiClient2, OpenAiLanguageModel } from "@effect/ai-openai";
|
|
15610
15668
|
import { Layer as Layer71 } from "effect";
|
|
15611
15669
|
import { FetchHttpClient as FetchHttpClient3 } from "effect/unstable/http";
|
|
@@ -15622,7 +15680,7 @@ var openAi = (input) => exports_model_registry.registrationFromLayer({
|
|
|
15622
15680
|
var openAiClientLayerConfig2 = OpenAiClient2.layerConfig;
|
|
15623
15681
|
var withOpenAi = (options) => exports_model_registry.layerFromRegistrationEffects([openAi(options)]).pipe(Layer71.provide(OpenAiClient2.layerConfig({ ...options.clientConfig, apiKey: options.apiKey })), Layer71.provide(FetchHttpClient3.layer));
|
|
15624
15682
|
|
|
15625
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15683
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/deterministic.ts
|
|
15626
15684
|
var deterministicModelLayer = Layer72.effect(LanguageModel8.LanguageModel, LanguageModel8.make({
|
|
15627
15685
|
generateText: () => Effect79.succeed([{ type: "text", text: "deterministic response" }]),
|
|
15628
15686
|
streamText: () => Stream11.make(Response7.makePart("text-delta", { id: "text", delta: "deterministic response" }))
|
|
@@ -15646,7 +15704,7 @@ var withOpenAiOrDeterministic = (options) => Layer72.unwrap(Effect79.gen(functio
|
|
|
15646
15704
|
...Option28.isSome(openAiRegistration) ? [openAiRegistration.value] : []
|
|
15647
15705
|
]);
|
|
15648
15706
|
}));
|
|
15649
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15707
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openai-compat.ts
|
|
15650
15708
|
import { OpenAiClient as OpenAiClient4, OpenAiLanguageModel as OpenAiLanguageModel2 } from "@effect/ai-openai-compat";
|
|
15651
15709
|
import { Config as Config8, Layer as Layer73 } from "effect";
|
|
15652
15710
|
import { FetchHttpClient as FetchHttpClient5 } from "effect/unstable/http";
|
|
@@ -15667,7 +15725,7 @@ var clientLayerConfig = (options) => OpenAiClient4.layerConfig({
|
|
|
15667
15725
|
...options.baseUrl === undefined ? {} : { apiUrl: Config8.succeed(options.baseUrl) }
|
|
15668
15726
|
});
|
|
15669
15727
|
var withOpenAiCompatible = (options) => exports_model_registry.layerFromRegistrationEffects([openAiCompatible(options)]).pipe(Layer73.provide(clientLayerConfig(options)), Layer73.provide(FetchHttpClient5.layer));
|
|
15670
|
-
// ../../node_modules/.bun/@batonfx+providers@0.3.
|
|
15728
|
+
// ../../node_modules/.bun/@batonfx+providers@0.3.6/node_modules/@batonfx/providers/src/openrouter.ts
|
|
15671
15729
|
import { OpenRouterClient, OpenRouterLanguageModel } from "@effect/ai-openrouter";
|
|
15672
15730
|
import { Layer as Layer74 } from "effect";
|
|
15673
15731
|
import { FetchHttpClient as FetchHttpClient6 } from "effect/unstable/http";
|