@batonfx/memory 0.1.0 → 0.2.0
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/.turbo/turbo-build.log +1 -1
- package/dist/index.js +356 -67
- package/package.json +2 -2
- package/src/index.ts +9 -9
- package/src/semantic-recall.ts +17 -14
- package/src/working-memory.ts +11 -8
- package/test/index.test.ts +8 -8
- package/test/semantic-recall.test.ts +12 -12
- package/test/working-memory.test.ts +8 -8
package/.turbo/turbo-build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -10320,6 +10320,7 @@ function resolveAt(key) {
|
|
|
10320
10320
|
}
|
|
10321
10321
|
var resolveIdentifier = /* @__PURE__ */ resolveAt("identifier");
|
|
10322
10322
|
var resolveTitle = /* @__PURE__ */ resolveAt("title");
|
|
10323
|
+
var resolveDescription = /* @__PURE__ */ resolveAt("description");
|
|
10323
10324
|
var resolveBrands = /* @__PURE__ */ resolveAt("brands");
|
|
10324
10325
|
var getExpected = /* @__PURE__ */ memoize((ast) => {
|
|
10325
10326
|
const identifier2 = resolveIdentifier(ast);
|
|
@@ -12893,6 +12894,7 @@ function runChecks(checks, s) {
|
|
|
12893
12894
|
var ClassTypeId = "~effect/Schema/Class";
|
|
12894
12895
|
var STRUCTURAL_ANNOTATION_KEY = "~structural";
|
|
12895
12896
|
var resolveIdentifier2 = resolveIdentifier;
|
|
12897
|
+
var resolveDescription2 = resolveDescription;
|
|
12896
12898
|
function isJson(u) {
|
|
12897
12899
|
const onPath = new Set;
|
|
12898
12900
|
const validated = new Set;
|
|
@@ -30518,6 +30520,43 @@ class AiError extends (/* @__PURE__ */ ErrorClass("effect/ai/AiError/AiError")({
|
|
|
30518
30520
|
}
|
|
30519
30521
|
var isAiErrorReason = (u) => hasProperty(u, ReasonTypeId);
|
|
30520
30522
|
var make27 = (params) => new AiError(params);
|
|
30523
|
+
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/Random.js
|
|
30524
|
+
var Random5 = Random;
|
|
30525
|
+
var randomWith = (f) => withFiber2((fiber3) => succeed6(f(fiber3.getRef(Random5))));
|
|
30526
|
+
var next2 = /* @__PURE__ */ randomWith((r) => r.nextDoubleUnsafe());
|
|
30527
|
+
|
|
30528
|
+
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/IdGenerator.js
|
|
30529
|
+
class IdGenerator extends (/* @__PURE__ */ Service()("@effect/ai/IdGenerator")) {
|
|
30530
|
+
}
|
|
30531
|
+
var DEFAULT_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
30532
|
+
var DEFAULT_SEPARATOR = "_";
|
|
30533
|
+
var DEFAULT_SIZE = 16;
|
|
30534
|
+
var makeGenerator = ({
|
|
30535
|
+
alphabet = DEFAULT_ALPHABET,
|
|
30536
|
+
prefix,
|
|
30537
|
+
separator = DEFAULT_SEPARATOR,
|
|
30538
|
+
size: size6 = DEFAULT_SIZE
|
|
30539
|
+
}) => {
|
|
30540
|
+
const alphabetLength = alphabet.length;
|
|
30541
|
+
return fnUntraced2(function* () {
|
|
30542
|
+
const chars = new Array(size6);
|
|
30543
|
+
for (let i = 0;i < size6; i++) {
|
|
30544
|
+
const index2 = yield* next2;
|
|
30545
|
+
chars[i] = alphabet[index2 * alphabetLength | 0];
|
|
30546
|
+
}
|
|
30547
|
+
const identifier2 = chars.join("");
|
|
30548
|
+
if (isUndefined(prefix)) {
|
|
30549
|
+
return identifier2;
|
|
30550
|
+
}
|
|
30551
|
+
return `${prefix}${separator}${identifier2}`;
|
|
30552
|
+
});
|
|
30553
|
+
};
|
|
30554
|
+
var defaultIdGenerator = {
|
|
30555
|
+
generateId: /* @__PURE__ */ makeGenerator({
|
|
30556
|
+
prefix: "id"
|
|
30557
|
+
})
|
|
30558
|
+
};
|
|
30559
|
+
|
|
30521
30560
|
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/LanguageModel.js
|
|
30522
30561
|
var exports_LanguageModel = {};
|
|
30523
30562
|
__export(exports_LanguageModel, {
|
|
@@ -30622,43 +30661,6 @@ var awaitEmpty = (self) => whileLoop2({
|
|
|
30622
30661
|
step: constVoid
|
|
30623
30662
|
});
|
|
30624
30663
|
|
|
30625
|
-
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/Random.js
|
|
30626
|
-
var Random5 = Random;
|
|
30627
|
-
var randomWith = (f) => withFiber2((fiber3) => succeed6(f(fiber3.getRef(Random5))));
|
|
30628
|
-
var next2 = /* @__PURE__ */ randomWith((r) => r.nextDoubleUnsafe());
|
|
30629
|
-
|
|
30630
|
-
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/IdGenerator.js
|
|
30631
|
-
class IdGenerator extends (/* @__PURE__ */ Service()("@effect/ai/IdGenerator")) {
|
|
30632
|
-
}
|
|
30633
|
-
var DEFAULT_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
30634
|
-
var DEFAULT_SEPARATOR = "_";
|
|
30635
|
-
var DEFAULT_SIZE = 16;
|
|
30636
|
-
var makeGenerator = ({
|
|
30637
|
-
alphabet = DEFAULT_ALPHABET,
|
|
30638
|
-
prefix,
|
|
30639
|
-
separator = DEFAULT_SEPARATOR,
|
|
30640
|
-
size: size6 = DEFAULT_SIZE
|
|
30641
|
-
}) => {
|
|
30642
|
-
const alphabetLength = alphabet.length;
|
|
30643
|
-
return fnUntraced2(function* () {
|
|
30644
|
-
const chars = new Array(size6);
|
|
30645
|
-
for (let i = 0;i < size6; i++) {
|
|
30646
|
-
const index2 = yield* next2;
|
|
30647
|
-
chars[i] = alphabet[index2 * alphabetLength | 0];
|
|
30648
|
-
}
|
|
30649
|
-
const identifier2 = chars.join("");
|
|
30650
|
-
if (isUndefined(prefix)) {
|
|
30651
|
-
return identifier2;
|
|
30652
|
-
}
|
|
30653
|
-
return `${prefix}${separator}${identifier2}`;
|
|
30654
|
-
});
|
|
30655
|
-
};
|
|
30656
|
-
var defaultIdGenerator = {
|
|
30657
|
-
generateId: /* @__PURE__ */ makeGenerator({
|
|
30658
|
-
prefix: "id"
|
|
30659
|
-
})
|
|
30660
|
-
};
|
|
30661
|
-
|
|
30662
30664
|
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/internal/codec-transformer.js
|
|
30663
30665
|
var defaultCodecTransformer = (codec) => {
|
|
30664
30666
|
const document = resolveTopLevel$ref(toJsonSchemaDocument2(codec));
|
|
@@ -32200,6 +32202,275 @@ var mapProviderResults = (inputLength, results) => {
|
|
|
32200
32202
|
}
|
|
32201
32203
|
return succeed6(embeddings);
|
|
32202
32204
|
};
|
|
32205
|
+
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/Tool.js
|
|
32206
|
+
var exports_Tool = {};
|
|
32207
|
+
__export(exports_Tool, {
|
|
32208
|
+
unsafeSecureJsonParse: () => unsafeSecureJsonParse,
|
|
32209
|
+
providerDefined: () => providerDefined,
|
|
32210
|
+
make: () => make34,
|
|
32211
|
+
isUserDefined: () => isUserDefined,
|
|
32212
|
+
isProviderDefined: () => isProviderDefined,
|
|
32213
|
+
isEmptyParamsRecord: () => isEmptyParamsRecord,
|
|
32214
|
+
isDynamic: () => isDynamic,
|
|
32215
|
+
getStrictMode: () => getStrictMode,
|
|
32216
|
+
getJsonSchemaFromSchema: () => getJsonSchemaFromSchema,
|
|
32217
|
+
getJsonSchema: () => getJsonSchema,
|
|
32218
|
+
getDescription: () => getDescription,
|
|
32219
|
+
dynamic: () => dynamic,
|
|
32220
|
+
TypeId: () => TypeId35,
|
|
32221
|
+
Title: () => Title,
|
|
32222
|
+
Strict: () => Strict,
|
|
32223
|
+
Readonly: () => Readonly,
|
|
32224
|
+
ProviderDefinedTypeId: () => ProviderDefinedTypeId,
|
|
32225
|
+
OpenWorld: () => OpenWorld,
|
|
32226
|
+
NameMapper: () => NameMapper,
|
|
32227
|
+
Meta: () => Meta,
|
|
32228
|
+
Idempotent: () => Idempotent,
|
|
32229
|
+
EmptyParams: () => EmptyParams,
|
|
32230
|
+
DynamicTypeId: () => DynamicTypeId,
|
|
32231
|
+
Destructive: () => Destructive
|
|
32232
|
+
});
|
|
32233
|
+
var TypeId35 = "~effect/ai/Tool";
|
|
32234
|
+
var ProviderDefinedTypeId = "~effect/ai/Tool/ProviderDefined";
|
|
32235
|
+
var DynamicTypeId = "~effect/ai/Tool/Dynamic";
|
|
32236
|
+
var isUserDefined = (u) => hasProperty(u, TypeId35) && !isProviderDefined(u) && !isDynamic(u);
|
|
32237
|
+
var isProviderDefined = (u) => hasProperty(u, ProviderDefinedTypeId);
|
|
32238
|
+
var isDynamic = (u) => hasProperty(u, DynamicTypeId);
|
|
32239
|
+
var Proto8 = {
|
|
32240
|
+
[TypeId35]: {
|
|
32241
|
+
_Requirements: identity
|
|
32242
|
+
},
|
|
32243
|
+
pipe() {
|
|
32244
|
+
return pipeArguments(this, arguments);
|
|
32245
|
+
},
|
|
32246
|
+
addDependency() {
|
|
32247
|
+
return userDefinedProto({
|
|
32248
|
+
...this
|
|
32249
|
+
});
|
|
32250
|
+
},
|
|
32251
|
+
setParameters(parametersSchema) {
|
|
32252
|
+
return userDefinedProto({
|
|
32253
|
+
...this,
|
|
32254
|
+
parametersSchema
|
|
32255
|
+
});
|
|
32256
|
+
},
|
|
32257
|
+
setSuccess(successSchema) {
|
|
32258
|
+
return userDefinedProto({
|
|
32259
|
+
...this,
|
|
32260
|
+
successSchema
|
|
32261
|
+
});
|
|
32262
|
+
},
|
|
32263
|
+
setFailure(failureSchema) {
|
|
32264
|
+
return userDefinedProto({
|
|
32265
|
+
...this,
|
|
32266
|
+
failureSchema
|
|
32267
|
+
});
|
|
32268
|
+
},
|
|
32269
|
+
annotate(tag2, value3) {
|
|
32270
|
+
return userDefinedProto({
|
|
32271
|
+
...this,
|
|
32272
|
+
annotations: add(this.annotations, tag2, value3)
|
|
32273
|
+
});
|
|
32274
|
+
},
|
|
32275
|
+
annotateMerge(context4) {
|
|
32276
|
+
return userDefinedProto({
|
|
32277
|
+
...this,
|
|
32278
|
+
annotations: merge(this.annotations, context4)
|
|
32279
|
+
});
|
|
32280
|
+
}
|
|
32281
|
+
};
|
|
32282
|
+
var ProviderDefinedProto = {
|
|
32283
|
+
...Proto8,
|
|
32284
|
+
[ProviderDefinedTypeId]: ProviderDefinedTypeId
|
|
32285
|
+
};
|
|
32286
|
+
var DynamicProto = {
|
|
32287
|
+
...Proto8,
|
|
32288
|
+
[DynamicTypeId]: DynamicTypeId
|
|
32289
|
+
};
|
|
32290
|
+
var userDefinedProto = (options) => {
|
|
32291
|
+
const self = Object.assign(Object.create(Proto8), options);
|
|
32292
|
+
self.id = `effect/ai/Tool/${options.name}`;
|
|
32293
|
+
return self;
|
|
32294
|
+
};
|
|
32295
|
+
var providerDefinedProto = (options) => Object.assign(Object.create(ProviderDefinedProto), {
|
|
32296
|
+
...options
|
|
32297
|
+
});
|
|
32298
|
+
var dynamicProto = (options) => {
|
|
32299
|
+
const self = Object.assign(Object.create(DynamicProto), options);
|
|
32300
|
+
self.id = `effect/ai/Tool/${options.name}`;
|
|
32301
|
+
return self;
|
|
32302
|
+
};
|
|
32303
|
+
var make34 = (name, options) => {
|
|
32304
|
+
const successSchema = options?.success ?? Void2;
|
|
32305
|
+
const failureSchema = options?.failure ?? Never2;
|
|
32306
|
+
return userDefinedProto({
|
|
32307
|
+
name,
|
|
32308
|
+
description: options?.description,
|
|
32309
|
+
parametersSchema: options?.parameters ?? EmptyParams,
|
|
32310
|
+
successSchema,
|
|
32311
|
+
failureSchema,
|
|
32312
|
+
failureMode: options?.failureMode ?? "error",
|
|
32313
|
+
annotations: empty(),
|
|
32314
|
+
needsApproval: options?.needsApproval
|
|
32315
|
+
});
|
|
32316
|
+
};
|
|
32317
|
+
var dynamic = (name, options) => {
|
|
32318
|
+
const successSchema = options?.success ?? Unknown2;
|
|
32319
|
+
const failureSchema = options?.failure ?? Never2;
|
|
32320
|
+
const rawParameters = options?.parameters ?? Unknown2;
|
|
32321
|
+
const isEffectSchema = isSchema(rawParameters);
|
|
32322
|
+
const parametersSchema = isEffectSchema ? rawParameters : Unknown2;
|
|
32323
|
+
const jsonSchema = isEffectSchema ? undefined : rawParameters;
|
|
32324
|
+
return dynamicProto({
|
|
32325
|
+
name,
|
|
32326
|
+
description: options?.description,
|
|
32327
|
+
parametersSchema,
|
|
32328
|
+
successSchema,
|
|
32329
|
+
failureSchema,
|
|
32330
|
+
failureMode: options?.failureMode ?? "error",
|
|
32331
|
+
annotations: empty(),
|
|
32332
|
+
needsApproval: options?.needsApproval,
|
|
32333
|
+
jsonSchema
|
|
32334
|
+
});
|
|
32335
|
+
};
|
|
32336
|
+
var providerDefined = (options) => (args2) => {
|
|
32337
|
+
const failureMode = isNotUndefined(args2) && "failureMode" in args2 ? args2.failureMode : undefined;
|
|
32338
|
+
const successSchema = options?.success ?? Void2;
|
|
32339
|
+
const failureSchema = options?.failure ?? Never2;
|
|
32340
|
+
return providerDefinedProto({
|
|
32341
|
+
id: options.id,
|
|
32342
|
+
name: options.customName,
|
|
32343
|
+
providerName: options.providerName,
|
|
32344
|
+
args: args2,
|
|
32345
|
+
argsSchema: options?.args ?? Void2,
|
|
32346
|
+
requiresHandler: options.requiresHandler ?? false,
|
|
32347
|
+
parametersSchema: options?.parameters ?? Void2,
|
|
32348
|
+
successSchema,
|
|
32349
|
+
failureSchema,
|
|
32350
|
+
failureMode: failureMode ?? "error"
|
|
32351
|
+
});
|
|
32352
|
+
};
|
|
32353
|
+
|
|
32354
|
+
class NameMapper {
|
|
32355
|
+
#customToProvider = /* @__PURE__ */ new Map;
|
|
32356
|
+
#providerToCustom = /* @__PURE__ */ new Map;
|
|
32357
|
+
constructor(tools) {
|
|
32358
|
+
for (const tool of tools) {
|
|
32359
|
+
if (isProviderDefined(tool)) {
|
|
32360
|
+
this.#customToProvider.set(tool.name, tool.providerName);
|
|
32361
|
+
this.#providerToCustom.set(tool.providerName, tool.name);
|
|
32362
|
+
}
|
|
32363
|
+
}
|
|
32364
|
+
}
|
|
32365
|
+
get customNames() {
|
|
32366
|
+
return Array.from(this.#customToProvider.keys());
|
|
32367
|
+
}
|
|
32368
|
+
get providerNames() {
|
|
32369
|
+
return Array.from(this.#providerToCustom.keys());
|
|
32370
|
+
}
|
|
32371
|
+
getCustomName(providerName) {
|
|
32372
|
+
return this.#providerToCustom.get(providerName) ?? providerName;
|
|
32373
|
+
}
|
|
32374
|
+
getProviderName(customName) {
|
|
32375
|
+
return this.#customToProvider.get(customName) ?? customName;
|
|
32376
|
+
}
|
|
32377
|
+
}
|
|
32378
|
+
var getDescription = (tool) => {
|
|
32379
|
+
if (tool.description !== undefined) {
|
|
32380
|
+
return tool.description;
|
|
32381
|
+
}
|
|
32382
|
+
if (isSchema(tool.parametersSchema)) {
|
|
32383
|
+
return resolveDescription2(tool.parametersSchema.ast);
|
|
32384
|
+
}
|
|
32385
|
+
return;
|
|
32386
|
+
};
|
|
32387
|
+
var getJsonSchema = (tool, options) => {
|
|
32388
|
+
if (isDynamic(tool) && tool.jsonSchema !== undefined) {
|
|
32389
|
+
return tool.jsonSchema;
|
|
32390
|
+
}
|
|
32391
|
+
return getJsonSchemaFromSchema(tool.parametersSchema, options);
|
|
32392
|
+
};
|
|
32393
|
+
var getJsonSchemaFromSchema = (schema, options) => {
|
|
32394
|
+
if (isNotUndefined(options?.transformer)) {
|
|
32395
|
+
return options.transformer(schema).jsonSchema;
|
|
32396
|
+
}
|
|
32397
|
+
const document = toJsonSchemaDocument2(schema);
|
|
32398
|
+
if (Object.keys(document.definitions).length > 0) {
|
|
32399
|
+
document.schema.$defs = document.definitions;
|
|
32400
|
+
}
|
|
32401
|
+
return document.schema;
|
|
32402
|
+
};
|
|
32403
|
+
|
|
32404
|
+
class Title extends (/* @__PURE__ */ Service()("effect/ai/Tool/Title")) {
|
|
32405
|
+
}
|
|
32406
|
+
|
|
32407
|
+
class Meta extends (/* @__PURE__ */ Service()("effect/ai/Tool/Meta")) {
|
|
32408
|
+
}
|
|
32409
|
+
var Readonly = /* @__PURE__ */ Reference("effect/ai/Tool/Readonly", {
|
|
32410
|
+
defaultValue: constFalse
|
|
32411
|
+
});
|
|
32412
|
+
var Destructive = /* @__PURE__ */ Reference("effect/ai/Tool/Destructive", {
|
|
32413
|
+
defaultValue: constTrue
|
|
32414
|
+
});
|
|
32415
|
+
var Idempotent = /* @__PURE__ */ Reference("effect/ai/Tool/Idempotent", {
|
|
32416
|
+
defaultValue: constFalse
|
|
32417
|
+
});
|
|
32418
|
+
var OpenWorld = /* @__PURE__ */ Reference("effect/ai/Tool/OpenWorld", {
|
|
32419
|
+
defaultValue: constTrue
|
|
32420
|
+
});
|
|
32421
|
+
var Strict = /* @__PURE__ */ Reference("effect/ai/Tool/Strict", {
|
|
32422
|
+
defaultValue: () => {
|
|
32423
|
+
return;
|
|
32424
|
+
}
|
|
32425
|
+
});
|
|
32426
|
+
var getStrictMode = (tool) => get(tool.annotations, Strict);
|
|
32427
|
+
var suspectProtoRx = /"__proto__"\s*:/;
|
|
32428
|
+
var suspectConstructorRx = /"constructor"\s*:/;
|
|
32429
|
+
function _parse(text) {
|
|
32430
|
+
const obj = JSON.parse(text);
|
|
32431
|
+
if (obj === null || typeof obj !== "object") {
|
|
32432
|
+
return obj;
|
|
32433
|
+
}
|
|
32434
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
32435
|
+
return obj;
|
|
32436
|
+
}
|
|
32437
|
+
return filter12(obj);
|
|
32438
|
+
}
|
|
32439
|
+
function filter12(obj) {
|
|
32440
|
+
let next3 = [obj];
|
|
32441
|
+
while (next3.length) {
|
|
32442
|
+
const nodes = next3;
|
|
32443
|
+
next3 = [];
|
|
32444
|
+
for (const node of nodes) {
|
|
32445
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
32446
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
32447
|
+
}
|
|
32448
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
32449
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
32450
|
+
}
|
|
32451
|
+
for (const key in node) {
|
|
32452
|
+
const value3 = node[key];
|
|
32453
|
+
if (value3 && typeof value3 === "object") {
|
|
32454
|
+
next3.push(value3);
|
|
32455
|
+
}
|
|
32456
|
+
}
|
|
32457
|
+
}
|
|
32458
|
+
}
|
|
32459
|
+
return obj;
|
|
32460
|
+
}
|
|
32461
|
+
var unsafeSecureJsonParse = (text) => {
|
|
32462
|
+
const prevLimit = getStackTraceLimit();
|
|
32463
|
+
setStackTraceLimit(0);
|
|
32464
|
+
try {
|
|
32465
|
+
return _parse(text);
|
|
32466
|
+
} finally {
|
|
32467
|
+
setStackTraceLimit(prevLimit);
|
|
32468
|
+
}
|
|
32469
|
+
};
|
|
32470
|
+
var EmptyParams = /* @__PURE__ */ Record(String5, Never2);
|
|
32471
|
+
function isEmptyParamsRecord(indexSignature) {
|
|
32472
|
+
return indexSignature.parameter === string2 && isNever2(indexSignature.type);
|
|
32473
|
+
}
|
|
32203
32474
|
// ../core/src/agent-event.ts
|
|
32204
32475
|
class AgentError extends exports_Schema.TaggedErrorClass()("@batonfx/core/AgentError", {
|
|
32205
32476
|
message: exports_Schema.String,
|
|
@@ -32414,6 +32685,25 @@ var allowAll = exports_Layer.succeed(Permissions, Permissions.of({
|
|
|
32414
32685
|
await: () => exports_Effect.succeed(exports_Option.none())
|
|
32415
32686
|
}));
|
|
32416
32687
|
|
|
32688
|
+
// ../core/src/skill-source.ts
|
|
32689
|
+
class SkillSourceError extends exports_Schema.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
32690
|
+
source: exports_Schema.String,
|
|
32691
|
+
message: exports_Schema.String,
|
|
32692
|
+
cause: exports_Schema.optionalKey(exports_Schema.Defect())
|
|
32693
|
+
}) {
|
|
32694
|
+
}
|
|
32695
|
+
class SkillSource extends exports_Context.Service()("@batonfx/core/SkillSource") {
|
|
32696
|
+
}
|
|
32697
|
+
var fromSkills = (skills) => {
|
|
32698
|
+
const all5 = [...skills];
|
|
32699
|
+
const byName = new Map(all5.map((skill) => [skill.frontmatter.name, skill]));
|
|
32700
|
+
return exports_Layer.succeed(SkillSource, SkillSource.of({
|
|
32701
|
+
all: exports_Effect.succeed(all5),
|
|
32702
|
+
get: (name) => exports_Effect.succeed(byName.get(name))
|
|
32703
|
+
}));
|
|
32704
|
+
};
|
|
32705
|
+
var empty15 = fromSkills([]);
|
|
32706
|
+
|
|
32417
32707
|
// ../core/src/steering.ts
|
|
32418
32708
|
class Steering extends exports_Context.Service()("@batonfx/core/Steering") {
|
|
32419
32709
|
}
|
|
@@ -32439,9 +32729,22 @@ var decision = {
|
|
|
32439
32729
|
}),
|
|
32440
32730
|
stop: { _tag: "Stop" }
|
|
32441
32731
|
};
|
|
32442
|
-
var
|
|
32443
|
-
var recurs2 = (n) =>
|
|
32732
|
+
var make35 = (decide) => ({ decide });
|
|
32733
|
+
var recurs2 = (n) => make35((info) => exports_Effect.succeed(info.turn < n + 1 ? decision.continue() : decision.stop));
|
|
32444
32734
|
var defaultPolicy = recurs2(8);
|
|
32735
|
+
|
|
32736
|
+
// ../core/src/agent.ts
|
|
32737
|
+
var activateSkillToolName = "activate_skill";
|
|
32738
|
+
var activateSkillParameters = exports_Schema.Struct({ name: exports_Schema.String });
|
|
32739
|
+
var activateSkillTool = exports_Tool.make(activateSkillToolName, {
|
|
32740
|
+
description: "Load the full body for one listed Baton skill by name before applying that skill.",
|
|
32741
|
+
parameters: activateSkillParameters,
|
|
32742
|
+
success: exports_Schema.Struct({
|
|
32743
|
+
name: exports_Schema.String,
|
|
32744
|
+
body: exports_Schema.String,
|
|
32745
|
+
allowedTools: exports_Schema.Array(exports_Schema.String)
|
|
32746
|
+
})
|
|
32747
|
+
});
|
|
32445
32748
|
// ../core/src/agent-tool.ts
|
|
32446
32749
|
var defaultParameters = exports_Schema.Struct({ prompt: exports_Schema.String });
|
|
32447
32750
|
// ../core/src/handoff.ts
|
|
@@ -32464,28 +32767,11 @@ var registrations = exports_Effect.fn("ModelRegistry.registrations.call")(functi
|
|
|
32464
32767
|
const service3 = yield* Service2;
|
|
32465
32768
|
return yield* service3.registrations;
|
|
32466
32769
|
});
|
|
32467
|
-
// ../core/src/skill-source.ts
|
|
32468
|
-
class SkillSourceError extends exports_Schema.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
32469
|
-
source: exports_Schema.String,
|
|
32470
|
-
message: exports_Schema.String,
|
|
32471
|
-
cause: exports_Schema.optionalKey(exports_Schema.Defect())
|
|
32472
|
-
}) {
|
|
32473
|
-
}
|
|
32474
|
-
class SkillSource extends exports_Context.Service()("@batonfx/core/SkillSource") {
|
|
32475
|
-
}
|
|
32476
|
-
var fromSkills = (skills) => {
|
|
32477
|
-
const all5 = [...skills];
|
|
32478
|
-
const byName = new Map(all5.map((skill) => [skill.frontmatter.name, skill]));
|
|
32479
|
-
return exports_Layer.succeed(SkillSource, SkillSource.of({
|
|
32480
|
-
all: exports_Effect.succeed(all5),
|
|
32481
|
-
get: (name) => exports_Effect.succeed(byName.get(name))
|
|
32482
|
-
}));
|
|
32483
|
-
};
|
|
32484
|
-
var empty15 = fromSkills([]);
|
|
32485
32770
|
// src/semantic-recall.ts
|
|
32486
32771
|
var exports_semantic_recall = {};
|
|
32487
32772
|
__export(exports_semantic_recall, {
|
|
32488
|
-
|
|
32773
|
+
makeSemanticRecall: () => makeSemanticRecall,
|
|
32774
|
+
make: () => make38,
|
|
32489
32775
|
layer: () => layer
|
|
32490
32776
|
});
|
|
32491
32777
|
|
|
@@ -32525,7 +32811,7 @@ var cosine = (left, right) => {
|
|
|
32525
32811
|
return 0;
|
|
32526
32812
|
return dot / (Math.sqrt(leftMagnitude) * Math.sqrt(rightMagnitude));
|
|
32527
32813
|
};
|
|
32528
|
-
var
|
|
32814
|
+
var make37 = exports_Ref.make(exports_HashMap.empty()).pipe(exports_Effect.map((documents) => ({
|
|
32529
32815
|
upsert: (nextDocuments) => exports_Effect.gen(function* () {
|
|
32530
32816
|
for (const document of nextDocuments) {
|
|
32531
32817
|
yield* validateVector(`document ${document.id} embedding`, document.embedding);
|
|
@@ -32560,7 +32846,7 @@ var make36 = exports_Ref.make(exports_HashMap.empty()).pipe(exports_Effect.map((
|
|
|
32560
32846
|
return matches.toSorted((left, right) => right.score - left.score).slice(0, input.limit);
|
|
32561
32847
|
})
|
|
32562
32848
|
})));
|
|
32563
|
-
var memoryLayer2 = exports_Layer.effect(VectorStore,
|
|
32849
|
+
var memoryLayer2 = exports_Layer.effect(VectorStore, make37.pipe(exports_Effect.map(VectorStore.of)));
|
|
32564
32850
|
var testLayer2 = (implementation) => exports_Layer.succeed(VectorStore, VectorStore.of(implementation));
|
|
32565
32851
|
|
|
32566
32852
|
// src/semantic-recall.ts
|
|
@@ -32604,7 +32890,7 @@ var itemFromMatch = (match7) => ({
|
|
|
32604
32890
|
parts: [textPart2(match7.document.text)],
|
|
32605
32891
|
metadata: { ...match7.document.metadata, score: match7.score }
|
|
32606
32892
|
});
|
|
32607
|
-
var
|
|
32893
|
+
var make38 = (options = {}) => exports_Effect.gen(function* () {
|
|
32608
32894
|
const store = yield* VectorStore;
|
|
32609
32895
|
const embeddingModel = yield* exports_EmbeddingModel.EmbeddingModel;
|
|
32610
32896
|
const counter = yield* exports_Ref.make(0);
|
|
@@ -32638,12 +32924,14 @@ var make37 = (options = {}) => exports_Effect.gen(function* () {
|
|
|
32638
32924
|
}
|
|
32639
32925
|
};
|
|
32640
32926
|
});
|
|
32641
|
-
var
|
|
32927
|
+
var makeSemanticRecall = make38;
|
|
32928
|
+
var layer = (options = {}) => exports_Layer.effect(exports_memory.Memory, make38(options).pipe(exports_Effect.map(exports_memory.Memory.of)));
|
|
32642
32929
|
|
|
32643
32930
|
// src/working-memory.ts
|
|
32644
32931
|
var exports_working_memory = {};
|
|
32645
32932
|
__export(exports_working_memory, {
|
|
32646
|
-
|
|
32933
|
+
makeWorkingMemory: () => makeWorkingMemory,
|
|
32934
|
+
make: () => make39,
|
|
32647
32935
|
layer: () => layer2
|
|
32648
32936
|
});
|
|
32649
32937
|
var emptyState = {
|
|
@@ -32727,7 +33015,7 @@ ${state.summary}
|
|
|
32727
33015
|
],
|
|
32728
33016
|
...state.recent.map((item) => ({ id: item.id, parts: [textPart3(formatItem(item))] }))
|
|
32729
33017
|
];
|
|
32730
|
-
var
|
|
33018
|
+
var make39 = (options = {}) => exports_Ref.make(exports_HashMap.empty()).pipe(exports_Effect.map((states) => {
|
|
32731
33019
|
const maxMessages = Math.max(0, Math.floor(options.maxMessages ?? 20));
|
|
32732
33020
|
return {
|
|
32733
33021
|
recall: (input) => exports_Ref.get(states).pipe(exports_Effect.map((current) => exports_HashMap.get(current, keyId(input.key))), exports_Effect.map((state) => state._tag === "Some" ? recallItems(state.value) : [])),
|
|
@@ -32761,12 +33049,13 @@ var make38 = (options = {}) => exports_Ref.make(exports_HashMap.empty()).pipe(ex
|
|
|
32761
33049
|
}
|
|
32762
33050
|
};
|
|
32763
33051
|
}));
|
|
32764
|
-
var
|
|
33052
|
+
var makeWorkingMemory = make39;
|
|
33053
|
+
var layer2 = (options = {}) => exports_Layer.effect(exports_memory.Memory, make39(options).pipe(exports_Effect.map(exports_memory.Memory.of)));
|
|
32765
33054
|
|
|
32766
33055
|
// src/index.ts
|
|
32767
33056
|
var combinedLayer = (options = {}) => exports_Layer.effect(exports_memory.Memory, exports_Effect.gen(function* () {
|
|
32768
|
-
const working = yield*
|
|
32769
|
-
const semantic = yield*
|
|
33057
|
+
const working = yield* makeWorkingMemory(options.working);
|
|
33058
|
+
const semantic = yield* makeSemanticRecall(options.semantic);
|
|
32770
33059
|
return exports_memory.Memory.of(exports_memory.merge(working, semantic));
|
|
32771
33060
|
}));
|
|
32772
33061
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@batonfx/memory",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"typecheck": "bun tsc --noEmit"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@batonfx/core": "0.
|
|
17
|
+
"@batonfx/core": "0.2.0",
|
|
18
18
|
"effect": "4.0.0-beta.93"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Effect, Layer } from "effect"
|
|
2
|
-
import
|
|
2
|
+
import { EmbeddingModel } from "effect/unstable/ai"
|
|
3
3
|
import { Memory } from "@batonfx/core"
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import { makeSemanticRecall } from "./semantic-recall"
|
|
5
|
+
import { VectorStore } from "./vector-store"
|
|
6
|
+
import { makeWorkingMemory } from "./working-memory"
|
|
7
7
|
|
|
8
8
|
export * as SemanticRecall from "./semantic-recall"
|
|
9
9
|
export * as VectorStore from "./vector-store"
|
|
@@ -11,19 +11,19 @@ export * as WorkingMemory from "./working-memory"
|
|
|
11
11
|
|
|
12
12
|
/** @experimental */
|
|
13
13
|
export interface CombinedOptions {
|
|
14
|
-
readonly working?:
|
|
15
|
-
readonly semantic?:
|
|
14
|
+
readonly working?: import("./working-memory").Options
|
|
15
|
+
readonly semantic?: import("./semantic-recall").Options
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** @experimental */
|
|
19
19
|
export const combinedLayer = (
|
|
20
20
|
options: CombinedOptions = {},
|
|
21
|
-
): Layer.Layer<Memory.Memory, never, VectorStore
|
|
21
|
+
): Layer.Layer<Memory.Memory, never, VectorStore | EmbeddingModel.EmbeddingModel> =>
|
|
22
22
|
Layer.effect(
|
|
23
23
|
Memory.Memory,
|
|
24
24
|
Effect.gen(function* () {
|
|
25
|
-
const working = yield*
|
|
26
|
-
const semantic = yield*
|
|
25
|
+
const working = yield* makeWorkingMemory(options.working)
|
|
26
|
+
const semantic = yield* makeSemanticRecall(options.semantic)
|
|
27
27
|
return Memory.Memory.of(Memory.merge(working, semantic))
|
|
28
28
|
}),
|
|
29
29
|
)
|
package/src/semantic-recall.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect, Layer, Ref } from "effect"
|
|
2
|
-
import
|
|
2
|
+
import { EmbeddingModel, Prompt } from "effect/unstable/ai"
|
|
3
3
|
import { Memory } from "@batonfx/core"
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import { VectorStore } from "./vector-store"
|
|
5
|
+
import type { Match } from "./vector-store"
|
|
6
6
|
/** @experimental */
|
|
7
7
|
export interface Options {
|
|
8
8
|
readonly limit?: number
|
|
@@ -13,22 +13,22 @@ const errorMessage = (error: unknown) => (error instanceof Error ? `${error.name
|
|
|
13
13
|
|
|
14
14
|
const memoryError = (error: unknown): Memory.MemoryError => new Memory.MemoryError({ message: errorMessage(error) })
|
|
15
15
|
|
|
16
|
-
const textPart = (text: string) =>
|
|
16
|
+
const textPart = (text: string) => Prompt.makePart("text", { text })
|
|
17
17
|
|
|
18
|
-
const textFromParts = (parts: ReadonlyArray<
|
|
18
|
+
const textFromParts = (parts: ReadonlyArray<Prompt.Part>): string =>
|
|
19
19
|
parts
|
|
20
|
-
.filter((part): part is
|
|
20
|
+
.filter((part): part is Prompt.TextPart => part.type === "text")
|
|
21
21
|
.map((part) => part.text)
|
|
22
22
|
.join("")
|
|
23
23
|
|
|
24
|
-
const userText = (prompt:
|
|
24
|
+
const userText = (prompt: Prompt.Prompt): string =>
|
|
25
25
|
prompt.content
|
|
26
|
-
.filter((message): message is
|
|
26
|
+
.filter((message): message is Prompt.UserMessage => message.role === "user")
|
|
27
27
|
.map((message) => textFromParts(message.content))
|
|
28
28
|
.filter((text) => text.length > 0)
|
|
29
29
|
.join("\n\n")
|
|
30
30
|
|
|
31
|
-
const finalExchangeText = (prompt:
|
|
31
|
+
const finalExchangeText = (prompt: Prompt.Prompt): string | undefined => {
|
|
32
32
|
let assistant: string | undefined
|
|
33
33
|
let assistantIndex = -1
|
|
34
34
|
for (let index = prompt.content.length - 1; index >= 0; index -= 1) {
|
|
@@ -51,7 +51,7 @@ const finalExchangeText = (prompt: Ai.Prompt.Prompt): string | undefined => {
|
|
|
51
51
|
return undefined
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const itemFromMatch = (match:
|
|
54
|
+
const itemFromMatch = (match: Match): Memory.Item => ({
|
|
55
55
|
id: match.document.id,
|
|
56
56
|
parts: [textPart(match.document.text)],
|
|
57
57
|
metadata: { ...match.document.metadata, score: match.score },
|
|
@@ -60,10 +60,10 @@ const itemFromMatch = (match: VectorStore.Match): Memory.Item => ({
|
|
|
60
60
|
/** @experimental */
|
|
61
61
|
export const make = (
|
|
62
62
|
options: Options = {},
|
|
63
|
-
): Effect.Effect<Memory.Interface, never, VectorStore
|
|
63
|
+
): Effect.Effect<Memory.Interface, never, VectorStore | EmbeddingModel.EmbeddingModel> =>
|
|
64
64
|
Effect.gen(function* () {
|
|
65
|
-
const store = yield* VectorStore
|
|
66
|
-
const embeddingModel = yield*
|
|
65
|
+
const store = yield* VectorStore
|
|
66
|
+
const embeddingModel = yield* EmbeddingModel.EmbeddingModel
|
|
67
67
|
const counter = yield* Ref.make(0)
|
|
68
68
|
const limit = options.limit ?? 5
|
|
69
69
|
|
|
@@ -112,8 +112,11 @@ export const make = (
|
|
|
112
112
|
}
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
+
/** @experimental */
|
|
116
|
+
export const makeSemanticRecall = make
|
|
117
|
+
|
|
115
118
|
/** @experimental */
|
|
116
119
|
export const layer = (
|
|
117
120
|
options: Options = {},
|
|
118
|
-
): Layer.Layer<Memory.Memory, never, VectorStore
|
|
121
|
+
): Layer.Layer<Memory.Memory, never, VectorStore | EmbeddingModel.EmbeddingModel> =>
|
|
119
122
|
Layer.effect(Memory.Memory, make(options).pipe(Effect.map(Memory.Memory.of)))
|
package/src/working-memory.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Effect, HashMap, Layer, Ref } from "effect"
|
|
2
|
-
import
|
|
2
|
+
import { LanguageModel, Prompt, Toolkit } from "effect/unstable/ai"
|
|
3
3
|
import { Memory } from "@batonfx/core"
|
|
4
4
|
|
|
5
5
|
/** @experimental */
|
|
6
6
|
export interface SummarizeOptions {
|
|
7
|
-
readonly model: Layer.Layer<
|
|
7
|
+
readonly model: Layer.Layer<LanguageModel.LanguageModel>
|
|
8
8
|
readonly prompt?: string
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -44,11 +44,11 @@ const memoryError = (error: unknown): Memory.MemoryError => new Memory.MemoryErr
|
|
|
44
44
|
|
|
45
45
|
const keyId = (key: Memory.Key): string => JSON.stringify([key.agent, key.subject])
|
|
46
46
|
|
|
47
|
-
const textPart = (text: string) =>
|
|
47
|
+
const textPart = (text: string) => Prompt.makePart("text", { text })
|
|
48
48
|
|
|
49
|
-
const textFromParts = (parts: ReadonlyArray<
|
|
49
|
+
const textFromParts = (parts: ReadonlyArray<Prompt.Part>): string =>
|
|
50
50
|
parts
|
|
51
|
-
.filter((part): part is
|
|
51
|
+
.filter((part): part is Prompt.TextPart => part.type === "text")
|
|
52
52
|
.map((part) => part.text)
|
|
53
53
|
.join("")
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ const roleLabel = (role: StoredRole): string => (role === "user" ? "User" : "Ass
|
|
|
56
56
|
|
|
57
57
|
const formatItem = (item: IncomingItem): string => `${roleLabel(item.role)}: ${item.text}`
|
|
58
58
|
|
|
59
|
-
const normalize = (prompt:
|
|
59
|
+
const normalize = (prompt: Prompt.Prompt): ReadonlyArray<IncomingItem> =>
|
|
60
60
|
prompt.content.flatMap((message) => {
|
|
61
61
|
if (message.role !== "user" && message.role !== "assistant") return []
|
|
62
62
|
const text = textFromParts(message.content).trim()
|
|
@@ -114,10 +114,10 @@ const summarizeOverflow = (
|
|
|
114
114
|
overflow: ReadonlyArray<StoredItem>,
|
|
115
115
|
): Effect.Effect<string | undefined, Memory.MemoryError> =>
|
|
116
116
|
Effect.gen(function* () {
|
|
117
|
-
const model = yield*
|
|
117
|
+
const model = yield* LanguageModel.LanguageModel
|
|
118
118
|
const response = yield* model.generateText({
|
|
119
119
|
prompt: renderSummaryPrompt(options.prompt ?? defaultSummaryPrompt, summary, overflow),
|
|
120
|
-
toolkit:
|
|
120
|
+
toolkit: Toolkit.empty,
|
|
121
121
|
toolChoice: "none",
|
|
122
122
|
})
|
|
123
123
|
const text = response.text.trim()
|
|
@@ -184,6 +184,9 @@ export const make = (options: Options = {}): Effect.Effect<Memory.Interface> =>
|
|
|
184
184
|
}),
|
|
185
185
|
)
|
|
186
186
|
|
|
187
|
+
/** @experimental */
|
|
188
|
+
export const makeWorkingMemory = make
|
|
189
|
+
|
|
187
190
|
/** @experimental */
|
|
188
191
|
export const layer = (options: Options = {}): Layer.Layer<Memory.Memory> =>
|
|
189
192
|
Layer.effect(Memory.Memory, make(options).pipe(Effect.map(Memory.Memory.of)))
|
package/test/index.test.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { describe, expect, it } from "@effect/vitest"
|
|
2
2
|
import { Effect, Layer } from "effect"
|
|
3
|
-
import
|
|
3
|
+
import { EmbeddingModel, Prompt } from "effect/unstable/ai"
|
|
4
4
|
import { Memory } from "@batonfx/core"
|
|
5
5
|
import { combinedLayer, VectorStore } from "../src/index"
|
|
6
6
|
|
|
7
7
|
const key: Memory.Key = { agent: "memory-agent", subject: "subject-a" }
|
|
8
8
|
|
|
9
|
-
const textPart = (text: string) =>
|
|
10
|
-
const user = (text: string) =>
|
|
11
|
-
const assistant = (text: string) =>
|
|
12
|
-
const prompt = (...messages: ReadonlyArray<
|
|
9
|
+
const textPart = (text: string) => Prompt.makePart("text", { text })
|
|
10
|
+
const user = (text: string) => Prompt.makeMessage("user", { content: [textPart(text)] })
|
|
11
|
+
const assistant = (text: string) => Prompt.makeMessage("assistant", { content: [textPart(text)] })
|
|
12
|
+
const prompt = (...messages: ReadonlyArray<Prompt.Message>) => Prompt.fromMessages(messages)
|
|
13
13
|
|
|
14
14
|
const itemText = (item: Memory.Item): string =>
|
|
15
15
|
item.parts
|
|
16
|
-
.filter((part): part is
|
|
16
|
+
.filter((part): part is Prompt.TextPart => part.type === "text")
|
|
17
17
|
.map((part) => part.text)
|
|
18
18
|
.join("")
|
|
19
19
|
|
|
20
20
|
const embeddingLayer = Layer.effect(
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
EmbeddingModel.EmbeddingModel,
|
|
22
|
+
EmbeddingModel.make({
|
|
23
23
|
embedMany: ({ inputs }) =>
|
|
24
24
|
Effect.succeed({
|
|
25
25
|
results: inputs.map(() => [1, 0]),
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { describe, expect, it } from "@effect/vitest"
|
|
2
2
|
import { Effect, Layer } from "effect"
|
|
3
|
-
import
|
|
3
|
+
import { AiError, EmbeddingModel, Prompt } from "effect/unstable/ai"
|
|
4
4
|
import { Memory } from "@batonfx/core"
|
|
5
5
|
import { SemanticRecall, VectorStore } from "../src/index"
|
|
6
6
|
|
|
7
7
|
const key: Memory.Key = { agent: "memory-agent", subject: "subject-a" }
|
|
8
8
|
const otherKey: Memory.Key = { agent: "memory-agent", subject: "subject-b" }
|
|
9
9
|
|
|
10
|
-
const textPart = (text: string) =>
|
|
11
|
-
const user = (text: string) =>
|
|
12
|
-
const assistant = (text: string) =>
|
|
13
|
-
const prompt = (...messages: ReadonlyArray<
|
|
10
|
+
const textPart = (text: string) => Prompt.makePart("text", { text })
|
|
11
|
+
const user = (text: string) => Prompt.makeMessage("user", { content: [textPart(text)] })
|
|
12
|
+
const assistant = (text: string) => Prompt.makeMessage("assistant", { content: [textPart(text)] })
|
|
13
|
+
const prompt = (...messages: ReadonlyArray<Prompt.Message>) => Prompt.fromMessages(messages)
|
|
14
14
|
|
|
15
15
|
const itemText = (item: Memory.Item): string =>
|
|
16
16
|
item.parts
|
|
17
|
-
.filter((part): part is
|
|
17
|
+
.filter((part): part is Prompt.TextPart => part.type === "text")
|
|
18
18
|
.map((part) => part.text)
|
|
19
19
|
.join("")
|
|
20
20
|
|
|
@@ -22,8 +22,8 @@ const vectorForText = (text: string): Array<number> =>
|
|
|
22
22
|
text.toLowerCase().includes("color") || text.toLowerCase().includes("blue") ? [1, 0] : [0, 1]
|
|
23
23
|
|
|
24
24
|
const embeddingLayer = Layer.effect(
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
EmbeddingModel.EmbeddingModel,
|
|
26
|
+
EmbeddingModel.make({
|
|
27
27
|
embedMany: ({ inputs }) =>
|
|
28
28
|
Effect.succeed({
|
|
29
29
|
results: inputs.map(vectorForText),
|
|
@@ -92,14 +92,14 @@ describe("SemanticRecall", () => {
|
|
|
92
92
|
)
|
|
93
93
|
|
|
94
94
|
it.effect("maps embedding failures to MemoryError", () => {
|
|
95
|
-
const embeddingError =
|
|
95
|
+
const embeddingError = AiError.make({
|
|
96
96
|
module: "SemanticRecallTest",
|
|
97
97
|
method: "embedMany",
|
|
98
|
-
reason: new
|
|
98
|
+
reason: new AiError.UnknownError({ description: "embedding failed" }),
|
|
99
99
|
})
|
|
100
100
|
const failingEmbedding = Layer.effect(
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
EmbeddingModel.EmbeddingModel,
|
|
102
|
+
EmbeddingModel.make({ embedMany: () => Effect.fail(embeddingError) }),
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
return Effect.gen(function* () {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { describe, expect, it } from "@effect/vitest"
|
|
2
2
|
import { Effect, Layer, Stream } from "effect"
|
|
3
|
-
import
|
|
3
|
+
import { LanguageModel, Prompt } from "effect/unstable/ai"
|
|
4
4
|
import { Memory } from "@batonfx/core"
|
|
5
5
|
import { WorkingMemory } from "../src/index"
|
|
6
6
|
|
|
7
7
|
const key: Memory.Key = { agent: "memory-agent", subject: "subject-a" }
|
|
8
8
|
const otherKey: Memory.Key = { agent: "memory-agent", subject: "subject-b" }
|
|
9
9
|
|
|
10
|
-
const textPart = (text: string) =>
|
|
11
|
-
const user = (text: string) =>
|
|
12
|
-
const assistant = (text: string) =>
|
|
13
|
-
const prompt = (...messages: ReadonlyArray<
|
|
10
|
+
const textPart = (text: string) => Prompt.makePart("text", { text })
|
|
11
|
+
const user = (text: string) => Prompt.makeMessage("user", { content: [textPart(text)] })
|
|
12
|
+
const assistant = (text: string) => Prompt.makeMessage("assistant", { content: [textPart(text)] })
|
|
13
|
+
const prompt = (...messages: ReadonlyArray<Prompt.Message>) => Prompt.fromMessages(messages)
|
|
14
14
|
|
|
15
15
|
const itemText = (item: Memory.Item): string =>
|
|
16
16
|
item.parts
|
|
17
|
-
.filter((part): part is
|
|
17
|
+
.filter((part): part is Prompt.TextPart => part.type === "text")
|
|
18
18
|
.map((part) => part.text)
|
|
19
19
|
.join("")
|
|
20
20
|
|
|
@@ -40,8 +40,8 @@ describe("WorkingMemory", () => {
|
|
|
40
40
|
let summaryCalls = 0
|
|
41
41
|
let summaryPrompt = ""
|
|
42
42
|
const summaryModel = Layer.effect(
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
LanguageModel.LanguageModel,
|
|
44
|
+
LanguageModel.make({
|
|
45
45
|
generateText: (options) =>
|
|
46
46
|
Effect.sync(() => {
|
|
47
47
|
summaryCalls += 1
|