open-agents-ai 0.187.432 → 0.187.433
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +627 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -514275,9 +514275,634 @@ var init_embeddingAligner = __esm({
|
|
|
514275
514275
|
}
|
|
514276
514276
|
});
|
|
514277
514277
|
|
|
514278
|
+
// packages/memory/dist/crl/index.js
|
|
514279
|
+
var CRL_SYMBOLS, SYMBOL_MEANINGS, CRLParser, CRLEncoder, CRLDecoder, CRLTemplateResolver, CRL;
|
|
514280
|
+
var init_crl = __esm({
|
|
514281
|
+
"packages/memory/dist/crl/index.js"() {
|
|
514282
|
+
"use strict";
|
|
514283
|
+
CRL_SYMBOLS = {
|
|
514284
|
+
// Logical operators
|
|
514285
|
+
THEREFORE: "∴",
|
|
514286
|
+
BECAUSE: "∵",
|
|
514287
|
+
EQUIVALENT: "≡",
|
|
514288
|
+
IMPLIES: "→",
|
|
514289
|
+
BICONDITIONAL: "↔",
|
|
514290
|
+
NOT: "¬",
|
|
514291
|
+
AND: "∧",
|
|
514292
|
+
OR: "∨",
|
|
514293
|
+
XOR: "⊕",
|
|
514294
|
+
// Relational operators
|
|
514295
|
+
ELEMENT_OF: "∈",
|
|
514296
|
+
NOT_ELEMENT_OF: "∉",
|
|
514297
|
+
PROPER_SUBSET: "⊂",
|
|
514298
|
+
SUBSET_OR_EQUAL: "⊆",
|
|
514299
|
+
UNION: "∪",
|
|
514300
|
+
INTERSECTION: "∩",
|
|
514301
|
+
EMPTY: "∅",
|
|
514302
|
+
// Temporal/Sequential
|
|
514303
|
+
THEN: "⇒",
|
|
514304
|
+
FROM: "⇐",
|
|
514305
|
+
LOOP: "⟳",
|
|
514306
|
+
CYCLE: "↻",
|
|
514307
|
+
NEXT: "⏵",
|
|
514308
|
+
PREVIOUS: "⏴",
|
|
514309
|
+
// Modal/Evidential
|
|
514310
|
+
POSSIBLE: "◇",
|
|
514311
|
+
NECESSARY: "□",
|
|
514312
|
+
OBSERVED: "⊙",
|
|
514313
|
+
UNCERTAIN: "?",
|
|
514314
|
+
CRITICAL: "!",
|
|
514315
|
+
APPROXIMATE: "~",
|
|
514316
|
+
// Quantifiers
|
|
514317
|
+
FOR_ALL: "∀",
|
|
514318
|
+
EXISTS: "∃",
|
|
514319
|
+
NOT_EXISTS: "∄",
|
|
514320
|
+
AGGREGATE: "∑",
|
|
514321
|
+
PRODUCT: "∏"
|
|
514322
|
+
};
|
|
514323
|
+
SYMBOL_MEANINGS = {
|
|
514324
|
+
"∴": "therefore",
|
|
514325
|
+
"∵": "because",
|
|
514326
|
+
"≡": "equivalent",
|
|
514327
|
+
"→": "implies",
|
|
514328
|
+
"↔": "biconditional",
|
|
514329
|
+
"¬": "not",
|
|
514330
|
+
"∧": "and",
|
|
514331
|
+
"∨": "or",
|
|
514332
|
+
"⊕": "xor",
|
|
514333
|
+
"∈": "element_of",
|
|
514334
|
+
"∉": "not_element_of",
|
|
514335
|
+
"⊂": "proper_subset",
|
|
514336
|
+
"⊆": "subset_or_equal",
|
|
514337
|
+
"∪": "union",
|
|
514338
|
+
"∩": "intersection",
|
|
514339
|
+
"∅": "empty",
|
|
514340
|
+
"⇒": "then",
|
|
514341
|
+
"⇐": "from",
|
|
514342
|
+
"⟳": "loop",
|
|
514343
|
+
"↻": "cycle",
|
|
514344
|
+
"⏵": "next",
|
|
514345
|
+
"⏴": "previous",
|
|
514346
|
+
"◇": "possible",
|
|
514347
|
+
"□": "necessary",
|
|
514348
|
+
"⊙": "observed",
|
|
514349
|
+
"?": "uncertain",
|
|
514350
|
+
"!": "critical",
|
|
514351
|
+
"~": "approximate",
|
|
514352
|
+
"∀": "for_all",
|
|
514353
|
+
"∃": "exists",
|
|
514354
|
+
"∄": "not_exists",
|
|
514355
|
+
"∑": "aggregate",
|
|
514356
|
+
"∏": "product"
|
|
514357
|
+
};
|
|
514358
|
+
CRLParser = class {
|
|
514359
|
+
pos = 0;
|
|
514360
|
+
input = "";
|
|
514361
|
+
parse(input) {
|
|
514362
|
+
this.input = input;
|
|
514363
|
+
this.pos = 0;
|
|
514364
|
+
const nodes = [];
|
|
514365
|
+
const start2 = this.pos;
|
|
514366
|
+
while (this.pos < this.input.length) {
|
|
514367
|
+
this.skipWhitespace();
|
|
514368
|
+
if (this.pos >= this.input.length)
|
|
514369
|
+
break;
|
|
514370
|
+
const node = this.parseNode();
|
|
514371
|
+
if (node)
|
|
514372
|
+
nodes.push(node);
|
|
514373
|
+
}
|
|
514374
|
+
return {
|
|
514375
|
+
type: "statement",
|
|
514376
|
+
nodes,
|
|
514377
|
+
raw: input,
|
|
514378
|
+
position: { start: start2, end: this.pos }
|
|
514379
|
+
};
|
|
514380
|
+
}
|
|
514381
|
+
parseNode() {
|
|
514382
|
+
this.skipWhitespace();
|
|
514383
|
+
if (this.peek() === "[") {
|
|
514384
|
+
return this.parseConcept();
|
|
514385
|
+
}
|
|
514386
|
+
if (this.peek() === "$" && this.peek(1) === "{") {
|
|
514387
|
+
return this.parseTemplate();
|
|
514388
|
+
}
|
|
514389
|
+
if (this.isQuantifier(this.peek())) {
|
|
514390
|
+
return this.parseQuantifier();
|
|
514391
|
+
}
|
|
514392
|
+
if (this.isOperator(this.peek())) {
|
|
514393
|
+
return this.parseOperator();
|
|
514394
|
+
}
|
|
514395
|
+
this.pos++;
|
|
514396
|
+
return null;
|
|
514397
|
+
}
|
|
514398
|
+
parseConcept() {
|
|
514399
|
+
const start2 = this.pos;
|
|
514400
|
+
this.pos++;
|
|
514401
|
+
let name10 = "";
|
|
514402
|
+
while (this.pos < this.input.length && this.peek() !== "]") {
|
|
514403
|
+
name10 += this.peek();
|
|
514404
|
+
this.pos++;
|
|
514405
|
+
}
|
|
514406
|
+
this.pos++;
|
|
514407
|
+
let properties;
|
|
514408
|
+
if (this.peek() === "{") {
|
|
514409
|
+
properties = this.parseProperties();
|
|
514410
|
+
}
|
|
514411
|
+
let strength;
|
|
514412
|
+
if (this.peek() === "★") {
|
|
514413
|
+
strength = 0;
|
|
514414
|
+
while (this.peek() === "★") {
|
|
514415
|
+
strength++;
|
|
514416
|
+
this.pos++;
|
|
514417
|
+
}
|
|
514418
|
+
}
|
|
514419
|
+
return {
|
|
514420
|
+
type: "concept",
|
|
514421
|
+
name: name10.trim(),
|
|
514422
|
+
properties,
|
|
514423
|
+
strength,
|
|
514424
|
+
raw: this.input.substring(start2, this.pos),
|
|
514425
|
+
position: { start: start2, end: this.pos }
|
|
514426
|
+
};
|
|
514427
|
+
}
|
|
514428
|
+
parseProperties() {
|
|
514429
|
+
const props = {};
|
|
514430
|
+
this.pos++;
|
|
514431
|
+
while (this.pos < this.input.length && this.peek() !== "}") {
|
|
514432
|
+
const key = this.parseIdentifier();
|
|
514433
|
+
if (this.peek() === ":") {
|
|
514434
|
+
this.pos++;
|
|
514435
|
+
const value2 = this.parseIdentifier();
|
|
514436
|
+
props[key] = value2;
|
|
514437
|
+
}
|
|
514438
|
+
if (this.peek() === ",")
|
|
514439
|
+
this.pos++;
|
|
514440
|
+
}
|
|
514441
|
+
this.pos++;
|
|
514442
|
+
return props;
|
|
514443
|
+
}
|
|
514444
|
+
parseIdentifier() {
|
|
514445
|
+
let id = "";
|
|
514446
|
+
while (this.pos < this.input.length && /[a-zA-Z0-9_]/.test(this.peek())) {
|
|
514447
|
+
id += this.peek();
|
|
514448
|
+
this.pos++;
|
|
514449
|
+
}
|
|
514450
|
+
return id;
|
|
514451
|
+
}
|
|
514452
|
+
parseTemplate() {
|
|
514453
|
+
const start2 = this.pos;
|
|
514454
|
+
this.pos += 2;
|
|
514455
|
+
let variable = "";
|
|
514456
|
+
let defaultValue;
|
|
514457
|
+
let typeAnnotation;
|
|
514458
|
+
let transform;
|
|
514459
|
+
while (this.pos < this.input.length && this.peek() !== "}" && this.peek() !== ":" && this.peek() !== "|" && this.peek() !== "→") {
|
|
514460
|
+
variable += this.peek();
|
|
514461
|
+
this.pos++;
|
|
514462
|
+
}
|
|
514463
|
+
if (this.peek() === ":") {
|
|
514464
|
+
this.pos++;
|
|
514465
|
+
defaultValue = "";
|
|
514466
|
+
while (this.pos < this.input.length && this.peek() !== "}") {
|
|
514467
|
+
defaultValue += this.peek();
|
|
514468
|
+
this.pos++;
|
|
514469
|
+
}
|
|
514470
|
+
}
|
|
514471
|
+
if (this.peek() === "|") {
|
|
514472
|
+
this.pos++;
|
|
514473
|
+
typeAnnotation = "";
|
|
514474
|
+
while (this.pos < this.input.length && this.peek() !== "}" && this.peek() !== "→") {
|
|
514475
|
+
typeAnnotation += this.peek();
|
|
514476
|
+
this.pos++;
|
|
514477
|
+
}
|
|
514478
|
+
}
|
|
514479
|
+
if (this.peek() === "→") {
|
|
514480
|
+
this.pos++;
|
|
514481
|
+
transform = "";
|
|
514482
|
+
while (this.pos < this.input.length && this.peek() !== "}") {
|
|
514483
|
+
transform += this.peek();
|
|
514484
|
+
this.pos++;
|
|
514485
|
+
}
|
|
514486
|
+
}
|
|
514487
|
+
this.pos++;
|
|
514488
|
+
return {
|
|
514489
|
+
type: "template",
|
|
514490
|
+
variable: variable.trim(),
|
|
514491
|
+
defaultValue,
|
|
514492
|
+
typeAnnotation,
|
|
514493
|
+
transform,
|
|
514494
|
+
raw: this.input.substring(start2, this.pos),
|
|
514495
|
+
position: { start: start2, end: this.pos }
|
|
514496
|
+
};
|
|
514497
|
+
}
|
|
514498
|
+
parseQuantifier() {
|
|
514499
|
+
const start2 = this.pos;
|
|
514500
|
+
const quantifier = this.peek();
|
|
514501
|
+
this.pos++;
|
|
514502
|
+
let variable = "";
|
|
514503
|
+
while (this.pos < this.input.length && /[a-zA-Z_]/.test(this.peek())) {
|
|
514504
|
+
variable += this.peek();
|
|
514505
|
+
this.pos++;
|
|
514506
|
+
}
|
|
514507
|
+
let domain;
|
|
514508
|
+
if (this.peek() === "∈") {
|
|
514509
|
+
this.pos++;
|
|
514510
|
+
this.skipWhitespace();
|
|
514511
|
+
domain = this.parseConcept();
|
|
514512
|
+
}
|
|
514513
|
+
this.skipWhitespace();
|
|
514514
|
+
if (this.peek() === ":")
|
|
514515
|
+
this.pos++;
|
|
514516
|
+
this.skipWhitespace();
|
|
514517
|
+
const predicate = this.parseNode();
|
|
514518
|
+
return {
|
|
514519
|
+
type: "quantifier",
|
|
514520
|
+
quantifier,
|
|
514521
|
+
variable,
|
|
514522
|
+
domain,
|
|
514523
|
+
predicate,
|
|
514524
|
+
raw: this.input.substring(start2, this.pos),
|
|
514525
|
+
position: { start: start2, end: this.pos }
|
|
514526
|
+
};
|
|
514527
|
+
}
|
|
514528
|
+
parseOperator() {
|
|
514529
|
+
const start2 = this.pos;
|
|
514530
|
+
const op = this.peek();
|
|
514531
|
+
this.pos++;
|
|
514532
|
+
return {
|
|
514533
|
+
type: "relation",
|
|
514534
|
+
raw: op,
|
|
514535
|
+
position: { start: start2, end: this.pos }
|
|
514536
|
+
};
|
|
514537
|
+
}
|
|
514538
|
+
skipWhitespace() {
|
|
514539
|
+
while (this.pos < this.input.length && /\s/.test(this.peek())) {
|
|
514540
|
+
this.pos++;
|
|
514541
|
+
}
|
|
514542
|
+
}
|
|
514543
|
+
peek(offset = 0) {
|
|
514544
|
+
return this.input[this.pos + offset] || "";
|
|
514545
|
+
}
|
|
514546
|
+
isQuantifier(char) {
|
|
514547
|
+
return ["∀", "∃", "∄", "∑", "∏"].includes(char);
|
|
514548
|
+
}
|
|
514549
|
+
isOperator(char) {
|
|
514550
|
+
return [
|
|
514551
|
+
"∴",
|
|
514552
|
+
"∵",
|
|
514553
|
+
"≡",
|
|
514554
|
+
"→",
|
|
514555
|
+
"↔",
|
|
514556
|
+
"¬",
|
|
514557
|
+
"∧",
|
|
514558
|
+
"∨",
|
|
514559
|
+
"⊕",
|
|
514560
|
+
"∈",
|
|
514561
|
+
"∉",
|
|
514562
|
+
"⊂",
|
|
514563
|
+
"⊆",
|
|
514564
|
+
"∪",
|
|
514565
|
+
"∩",
|
|
514566
|
+
"⇒",
|
|
514567
|
+
"⇐"
|
|
514568
|
+
].includes(char);
|
|
514569
|
+
}
|
|
514570
|
+
};
|
|
514571
|
+
CRLEncoder = class {
|
|
514572
|
+
conceptPatterns = /* @__PURE__ */ new Map();
|
|
514573
|
+
/**
|
|
514574
|
+
* Encode natural language text to CRL
|
|
514575
|
+
*/
|
|
514576
|
+
encode(text) {
|
|
514577
|
+
const concepts = this.extractConcepts(text);
|
|
514578
|
+
const relations = this.extractRelations(text, concepts);
|
|
514579
|
+
return this.buildExpression(concepts, relations);
|
|
514580
|
+
}
|
|
514581
|
+
/**
|
|
514582
|
+
* Extract key concepts from text
|
|
514583
|
+
*/
|
|
514584
|
+
extractConcepts(text) {
|
|
514585
|
+
const concepts = [];
|
|
514586
|
+
const conceptPattern = /\[([^\]]+)\]/g;
|
|
514587
|
+
let match;
|
|
514588
|
+
while ((match = conceptPattern.exec(text)) !== null) {
|
|
514589
|
+
concepts.push({
|
|
514590
|
+
type: "concept",
|
|
514591
|
+
name: match[1],
|
|
514592
|
+
raw: match[0],
|
|
514593
|
+
position: { start: match.index, end: match.index + match[0].length }
|
|
514594
|
+
});
|
|
514595
|
+
}
|
|
514596
|
+
const implicitPattern = /\b([A-Z][a-z]+(?:_[A-Z][a-z]+)*)\b/g;
|
|
514597
|
+
while ((match = implicitPattern.exec(text)) !== null) {
|
|
514598
|
+
if (!concepts.find((c9) => c9.name === match[1])) {
|
|
514599
|
+
concepts.push({
|
|
514600
|
+
type: "concept",
|
|
514601
|
+
name: match[1],
|
|
514602
|
+
raw: match[0],
|
|
514603
|
+
position: { start: match.index, end: match.index + match[0].length }
|
|
514604
|
+
});
|
|
514605
|
+
}
|
|
514606
|
+
}
|
|
514607
|
+
return concepts;
|
|
514608
|
+
}
|
|
514609
|
+
/**
|
|
514610
|
+
* Extract relations between concepts
|
|
514611
|
+
*/
|
|
514612
|
+
extractRelations(text, concepts) {
|
|
514613
|
+
const relations = [];
|
|
514614
|
+
const relationPattern = /\[([^\]]+)\]\s*(→|↔|∴|∵|⇒|⇐)(?::(\w+))?\s*(?:→)?\s*\[([^\]]+)\]/g;
|
|
514615
|
+
let match;
|
|
514616
|
+
while ((match = relationPattern.exec(text)) !== null) {
|
|
514617
|
+
const from3 = concepts.find((c9) => c9.name === match[1]);
|
|
514618
|
+
const to = concepts.find((c9) => c9.name === match[4]);
|
|
514619
|
+
if (from3 && to) {
|
|
514620
|
+
relations.push({
|
|
514621
|
+
type: "relation",
|
|
514622
|
+
from: from3,
|
|
514623
|
+
to,
|
|
514624
|
+
operator: match[2],
|
|
514625
|
+
edgeType: match[3],
|
|
514626
|
+
raw: match[0],
|
|
514627
|
+
position: { start: match.index, end: match.index + match[0].length }
|
|
514628
|
+
});
|
|
514629
|
+
}
|
|
514630
|
+
}
|
|
514631
|
+
return relations;
|
|
514632
|
+
}
|
|
514633
|
+
/**
|
|
514634
|
+
* Build CRL expression from concepts and relations
|
|
514635
|
+
*/
|
|
514636
|
+
buildExpression(concepts, relations) {
|
|
514637
|
+
const lines = [];
|
|
514638
|
+
for (const rel of relations) {
|
|
514639
|
+
let line = `[${rel.from.name}] ${rel.operator}`;
|
|
514640
|
+
if (rel.edgeType)
|
|
514641
|
+
line += `:${rel.edgeType}`;
|
|
514642
|
+
line += ` [${rel.to.name}]`;
|
|
514643
|
+
lines.push(line);
|
|
514644
|
+
}
|
|
514645
|
+
const relatedConcepts = /* @__PURE__ */ new Set();
|
|
514646
|
+
for (const rel of relations) {
|
|
514647
|
+
relatedConcepts.add(rel.from.name);
|
|
514648
|
+
relatedConcepts.add(rel.to.name);
|
|
514649
|
+
}
|
|
514650
|
+
for (const concept of concepts) {
|
|
514651
|
+
if (!relatedConcepts.has(concept.name)) {
|
|
514652
|
+
lines.push(`[${concept.name}]`);
|
|
514653
|
+
}
|
|
514654
|
+
}
|
|
514655
|
+
return lines.join("\n");
|
|
514656
|
+
}
|
|
514657
|
+
/**
|
|
514658
|
+
* Compress text using CRL patterns
|
|
514659
|
+
*/
|
|
514660
|
+
compress(text) {
|
|
514661
|
+
const replacements = [
|
|
514662
|
+
[/therefore/gi, "∴"],
|
|
514663
|
+
[/because/gi, "∵"],
|
|
514664
|
+
[/implies that/gi, "→"],
|
|
514665
|
+
[/is equivalent to/gi, "≡"],
|
|
514666
|
+
[/is an? element of/gi, "∈"],
|
|
514667
|
+
[/is not an? element of/gi, "∉"],
|
|
514668
|
+
[/is a subset of/gi, "⊂"],
|
|
514669
|
+
[/for all/gi, "∀"],
|
|
514670
|
+
[/there exists/gi, "∃"],
|
|
514671
|
+
[/and then/gi, "⇒"],
|
|
514672
|
+
[/leads to/gi, "→"],
|
|
514673
|
+
[/causes/gi, "→:causes"],
|
|
514674
|
+
[/fixes/gi, "→:fixes"],
|
|
514675
|
+
[/relates to/gi, "∩"]
|
|
514676
|
+
];
|
|
514677
|
+
let result = text;
|
|
514678
|
+
for (const [pattern, replacement] of replacements) {
|
|
514679
|
+
result = result.replace(pattern, replacement);
|
|
514680
|
+
}
|
|
514681
|
+
return result;
|
|
514682
|
+
}
|
|
514683
|
+
};
|
|
514684
|
+
CRLDecoder = class {
|
|
514685
|
+
/**
|
|
514686
|
+
* Decode CRL expression to natural language
|
|
514687
|
+
*/
|
|
514688
|
+
decode(crl) {
|
|
514689
|
+
const parser2 = new CRLParser();
|
|
514690
|
+
const ast = parser2.parse(crl);
|
|
514691
|
+
return this.renderStatement(ast);
|
|
514692
|
+
}
|
|
514693
|
+
/**
|
|
514694
|
+
* Render a statement node
|
|
514695
|
+
*/
|
|
514696
|
+
renderStatement(node) {
|
|
514697
|
+
return node.nodes.map((n2) => this.renderNode(n2)).filter(Boolean).join(". ");
|
|
514698
|
+
}
|
|
514699
|
+
/**
|
|
514700
|
+
* Render any CRL node
|
|
514701
|
+
*/
|
|
514702
|
+
renderNode(node) {
|
|
514703
|
+
switch (node.type) {
|
|
514704
|
+
case "concept":
|
|
514705
|
+
return this.renderConcept(node);
|
|
514706
|
+
case "template":
|
|
514707
|
+
return this.renderTemplate(node);
|
|
514708
|
+
case "quantifier":
|
|
514709
|
+
return this.renderQuantifier(node);
|
|
514710
|
+
case "relation":
|
|
514711
|
+
return this.renderRelation(node);
|
|
514712
|
+
default:
|
|
514713
|
+
return "";
|
|
514714
|
+
}
|
|
514715
|
+
}
|
|
514716
|
+
/**
|
|
514717
|
+
* Render a concept
|
|
514718
|
+
*/
|
|
514719
|
+
renderConcept(node) {
|
|
514720
|
+
let result = node.name;
|
|
514721
|
+
if (node.properties) {
|
|
514722
|
+
const props = Object.entries(node.properties).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
514723
|
+
result += ` (${props})`;
|
|
514724
|
+
}
|
|
514725
|
+
if (node.strength) {
|
|
514726
|
+
result += ` [strength: ${node.strength}/5]`;
|
|
514727
|
+
}
|
|
514728
|
+
return result;
|
|
514729
|
+
}
|
|
514730
|
+
/**
|
|
514731
|
+
* Render a template
|
|
514732
|
+
*/
|
|
514733
|
+
renderTemplate(node) {
|
|
514734
|
+
let result = node.variable;
|
|
514735
|
+
if (node.typeAnnotation) {
|
|
514736
|
+
result += ` (${node.typeAnnotation})`;
|
|
514737
|
+
}
|
|
514738
|
+
if (node.defaultValue) {
|
|
514739
|
+
result += ` [default: ${node.defaultValue}]`;
|
|
514740
|
+
}
|
|
514741
|
+
return result;
|
|
514742
|
+
}
|
|
514743
|
+
/**
|
|
514744
|
+
* Render a quantifier
|
|
514745
|
+
*/
|
|
514746
|
+
renderQuantifier(node) {
|
|
514747
|
+
const quantifierMeanings = {
|
|
514748
|
+
"∀": "For all",
|
|
514749
|
+
"∃": "There exists",
|
|
514750
|
+
"∄": "There does not exist",
|
|
514751
|
+
"∑": "Sum of",
|
|
514752
|
+
"∏": "Product of"
|
|
514753
|
+
};
|
|
514754
|
+
let result = `${quantifierMeanings[node.quantifier]} ${node.variable}`;
|
|
514755
|
+
if (node.domain) {
|
|
514756
|
+
result += ` in ${this.renderNode(node.domain)}`;
|
|
514757
|
+
}
|
|
514758
|
+
if (node.predicate) {
|
|
514759
|
+
result += `, ${this.renderNode(node.predicate)}`;
|
|
514760
|
+
}
|
|
514761
|
+
return result;
|
|
514762
|
+
}
|
|
514763
|
+
/**
|
|
514764
|
+
* Render a relation
|
|
514765
|
+
*/
|
|
514766
|
+
renderRelation(node) {
|
|
514767
|
+
const operatorMeanings = {
|
|
514768
|
+
"→": "implies",
|
|
514769
|
+
"∴": "therefore",
|
|
514770
|
+
"∵": "because",
|
|
514771
|
+
"≡": "is equivalent to",
|
|
514772
|
+
"↔": "is mutually related to",
|
|
514773
|
+
"∈": "is an element of",
|
|
514774
|
+
"⊂": "is a subset of",
|
|
514775
|
+
"∪": "combined with",
|
|
514776
|
+
"∩": "intersects with",
|
|
514777
|
+
"⇒": "then",
|
|
514778
|
+
"⇐": "from"
|
|
514779
|
+
};
|
|
514780
|
+
const from3 = this.renderConcept(node.from);
|
|
514781
|
+
const to = this.renderConcept(node.to);
|
|
514782
|
+
const op = operatorMeanings[node.operator] || node.operator;
|
|
514783
|
+
if (node.edgeType) {
|
|
514784
|
+
return `${from3} ${node.edgeType} ${to}`;
|
|
514785
|
+
}
|
|
514786
|
+
return `${from3} ${op} ${to}`;
|
|
514787
|
+
}
|
|
514788
|
+
/**
|
|
514789
|
+
* Expand CRL symbols to natural language
|
|
514790
|
+
*/
|
|
514791
|
+
expand(text) {
|
|
514792
|
+
const expansions = {
|
|
514793
|
+
"∴": "therefore",
|
|
514794
|
+
"∵": "because",
|
|
514795
|
+
"≡": "is equivalent to",
|
|
514796
|
+
"→": "implies",
|
|
514797
|
+
"↔": "is mutually related to",
|
|
514798
|
+
"¬": "not",
|
|
514799
|
+
"∧": "and",
|
|
514800
|
+
"∨": "or",
|
|
514801
|
+
"∈": "is an element of",
|
|
514802
|
+
"∉": "is not an element of",
|
|
514803
|
+
"⊂": "is a subset of",
|
|
514804
|
+
"⊆": "is a subset of or equal to",
|
|
514805
|
+
"∪": "union with",
|
|
514806
|
+
"∩": "intersection with",
|
|
514807
|
+
"∅": "empty",
|
|
514808
|
+
"⇒": "then",
|
|
514809
|
+
"⇐": "from",
|
|
514810
|
+
"◇": "possibly",
|
|
514811
|
+
"□": "necessarily",
|
|
514812
|
+
"⊙": "observed",
|
|
514813
|
+
"∀": "for all",
|
|
514814
|
+
"∃": "there exists",
|
|
514815
|
+
"∄": "there does not exist"
|
|
514816
|
+
};
|
|
514817
|
+
let result = text;
|
|
514818
|
+
for (const [symbol3, expansion] of Object.entries(expansions)) {
|
|
514819
|
+
result = result.replace(new RegExp(symbol3, "g"), ` ${expansion} `);
|
|
514820
|
+
}
|
|
514821
|
+
return result.replace(/\s+/g, " ").trim();
|
|
514822
|
+
}
|
|
514823
|
+
};
|
|
514824
|
+
CRLTemplateResolver = class {
|
|
514825
|
+
/**
|
|
514826
|
+
* Resolve templates in CRL expression
|
|
514827
|
+
*/
|
|
514828
|
+
resolve(crl, context2) {
|
|
514829
|
+
const templatePattern = /\$\{([^}]+)\}/g;
|
|
514830
|
+
return crl.replace(templatePattern, (match, template) => {
|
|
514831
|
+
return this.resolveTemplate(template, context2);
|
|
514832
|
+
});
|
|
514833
|
+
}
|
|
514834
|
+
resolveTemplate(template, context2) {
|
|
514835
|
+
const parts = template.split(/[:|→]/);
|
|
514836
|
+
const variable = parts[0].trim();
|
|
514837
|
+
const defaultValue = parts[1]?.trim();
|
|
514838
|
+
const typeAnnotation = parts[2]?.trim();
|
|
514839
|
+
let value2;
|
|
514840
|
+
if (variable.startsWith("ctx:")) {
|
|
514841
|
+
const ctxVar = variable.substring(5);
|
|
514842
|
+
value2 = context2[ctxVar];
|
|
514843
|
+
} else if (variable.startsWith("mem:")) {
|
|
514844
|
+
const memVar = variable.substring(4);
|
|
514845
|
+
const memArray = context2.memories?.[memVar];
|
|
514846
|
+
value2 = memArray?.join(", ");
|
|
514847
|
+
} else if (variable.startsWith("state:")) {
|
|
514848
|
+
const stateVar = variable.substring(6);
|
|
514849
|
+
value2 = context2.state?.[stateVar];
|
|
514850
|
+
} else {
|
|
514851
|
+
value2 = context2.variables?.[variable];
|
|
514852
|
+
}
|
|
514853
|
+
return value2 || defaultValue || `[${variable}]`;
|
|
514854
|
+
}
|
|
514855
|
+
};
|
|
514856
|
+
CRL = {
|
|
514857
|
+
parser: new CRLParser(),
|
|
514858
|
+
encoder: new CRLEncoder(),
|
|
514859
|
+
decoder: new CRLDecoder(),
|
|
514860
|
+
resolver: new CRLTemplateResolver(),
|
|
514861
|
+
symbols: CRL_SYMBOLS,
|
|
514862
|
+
meanings: SYMBOL_MEANINGS,
|
|
514863
|
+
/**
|
|
514864
|
+
* Quick encode: natural language → CRL
|
|
514865
|
+
*/
|
|
514866
|
+
encode(text) {
|
|
514867
|
+
return this.encoder.encode(text);
|
|
514868
|
+
},
|
|
514869
|
+
/**
|
|
514870
|
+
* Quick decode: CRL → natural language
|
|
514871
|
+
*/
|
|
514872
|
+
decode(crl) {
|
|
514873
|
+
return this.decoder.decode(crl);
|
|
514874
|
+
},
|
|
514875
|
+
/**
|
|
514876
|
+
* Quick compress: replace common patterns with symbols
|
|
514877
|
+
*/
|
|
514878
|
+
compress(text) {
|
|
514879
|
+
return this.encoder.compress(text);
|
|
514880
|
+
},
|
|
514881
|
+
/**
|
|
514882
|
+
* Quick expand: replace symbols with natural language
|
|
514883
|
+
*/
|
|
514884
|
+
expand(text) {
|
|
514885
|
+
return this.decoder.expand(text);
|
|
514886
|
+
},
|
|
514887
|
+
/**
|
|
514888
|
+
* Resolve templates with context
|
|
514889
|
+
*/
|
|
514890
|
+
resolve(crl, context2) {
|
|
514891
|
+
return this.resolver.resolve(crl, context2);
|
|
514892
|
+
}
|
|
514893
|
+
};
|
|
514894
|
+
}
|
|
514895
|
+
});
|
|
514896
|
+
|
|
514278
514897
|
// packages/memory/dist/index.js
|
|
514279
514898
|
var dist_exports2 = {};
|
|
514280
514899
|
__export(dist_exports2, {
|
|
514900
|
+
CRL: () => CRL,
|
|
514901
|
+
CRLDecoder: () => CRLDecoder,
|
|
514902
|
+
CRLEncoder: () => CRLEncoder,
|
|
514903
|
+
CRLParser: () => CRLParser,
|
|
514904
|
+
CRLTemplateResolver: () => CRLTemplateResolver,
|
|
514905
|
+
CRL_SYMBOLS: () => CRL_SYMBOLS,
|
|
514281
514906
|
DECAY_TAU: () => DECAY_TAU,
|
|
514282
514907
|
EmbeddingAligner: () => EmbeddingAligner,
|
|
514283
514908
|
EpisodeStore: () => EpisodeStore,
|
|
@@ -514286,6 +514911,7 @@ __export(dist_exports2, {
|
|
|
514286
514911
|
PatchHistoryStore: () => PatchHistoryStore,
|
|
514287
514912
|
ProceduralMemoryStore: () => ProceduralMemoryStore,
|
|
514288
514913
|
RepoProfileStore: () => RepoProfileStore,
|
|
514914
|
+
SYMBOL_MEANINGS: () => SYMBOL_MEANINGS,
|
|
514289
514915
|
TaskMemoryStore: () => TaskMemoryStore,
|
|
514290
514916
|
TemporalGraph: () => TemporalGraph,
|
|
514291
514917
|
ToolPatternStore: () => ToolPatternStore,
|
|
@@ -514333,6 +514959,7 @@ var init_dist7 = __esm({
|
|
|
514333
514959
|
init_proceduralMemoryStore();
|
|
514334
514960
|
init_splanifold();
|
|
514335
514961
|
init_embeddingAligner();
|
|
514962
|
+
init_crl();
|
|
514336
514963
|
}
|
|
514337
514964
|
});
|
|
514338
514965
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-agents-ai",
|
|
3
|
-
"version": "0.187.
|
|
3
|
+
"version": "0.187.433",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "open-agents-ai",
|
|
9
|
-
"version": "0.187.
|
|
9
|
+
"version": "0.187.433",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "CC-BY-NC-4.0",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED