@learningnodes/elen 0.1.1

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.
@@ -0,0 +1,17 @@
1
+ 
2
+  RUN  v2.1.9 C:/Users/ln_ni/OneDrive/Desktop/Desktop/ventures/learningnodes/git/marketplace-repos/Elen/packages/sdk-ts
3
+
4
+ Γ£ô tests/client.test.ts > ElenClient > logDecision creates a valid DecisionRecord
5
+ Γ£ô tests/client.test.ts > ElenClient > logDecision throws if no constraints provided
6
+ Γ£ô tests/client.test.ts > ElenClient > logDecision throws if no evidence provided
7
+ Γ£ô tests/client.test.ts > ElenClient > logDecision auto-classifies epistemic types
8
+ Γ£ô tests/client.test.ts > ElenClient > searchRecords filters by domain, minConfidence and parentPrompt
9
+ Γ£ô tests/client.test.ts > ElenClient > competency profile is computed from records
10
+ Γ£ô tests/client.test.ts > ElenClient > stores linked precedents in evidence
11
+ Γ£ô tests/client.test.ts > ElenClient > ID generation produces unique IDs
12
+
13
+  Test Files  1 passed (1)
14
+  Tests  8 passed (8)
15
+  Start at  12:18:15
16
+  Duration  2.30s (transform 471ms, setup 0ms, collect 666ms, tests 51ms, environment 1ms, prepare 546ms)
17
+
@@ -0,0 +1,16 @@
1
+ import { type DecisionRecord, type ConstraintSet } from '@learningnodes/elen-core';
2
+ import type { StorageAdapter } from './storage';
3
+ import type { CompetencyProfileResult, CommitDecisionInput, SearchOptions } from './types';
4
+ export declare class ElenClient {
5
+ private readonly agentId;
6
+ private readonly storage;
7
+ constructor(agentId: string, storage: StorageAdapter);
8
+ commitDecision(input: CommitDecisionInput): Promise<DecisionRecord>;
9
+ supersedeDecision(oldDecisionId: string, input: CommitDecisionInput): Promise<DecisionRecord>;
10
+ suggest(opts: SearchOptions): Promise<Partial<DecisionRecord>[]>;
11
+ expand(decisionId: string): Promise<{
12
+ record: DecisionRecord;
13
+ constraints: ConstraintSet;
14
+ } | null>;
15
+ getCompetencyProfile(): Promise<CompetencyProfileResult>;
16
+ }
package/dist/client.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElenClient = void 0;
4
+ const elen_core_1 = require("@learningnodes/elen-core");
5
+ const id_1 = require("./id");
6
+ class ElenClient {
7
+ constructor(agentId, storage) {
8
+ this.agentId = agentId;
9
+ this.storage = storage;
10
+ }
11
+ async commitDecision(input) {
12
+ const now = new Date().toISOString();
13
+ // 1. Resolve Constraints (Deterministic Hashing server-side)
14
+ const constraintSetId = (0, id_1.createConstraintSetId)(input.constraints);
15
+ const existingConstraints = await this.storage.getConstraintSet(constraintSetId);
16
+ if (!existingConstraints) {
17
+ const newSet = {
18
+ constraint_set_id: constraintSetId,
19
+ atoms: input.constraints,
20
+ summary: `Auto-generated summary for ${input.constraints.length} constraints`
21
+ };
22
+ elen_core_1.constraintSetSchema.parse(newSet);
23
+ await this.storage.saveConstraintSet(newSet);
24
+ }
25
+ // 2. Build the Minimal Decision Atom
26
+ const record = {
27
+ decision_id: (0, id_1.createDecisionId)(input.domain),
28
+ q_id: (0, id_1.createId)('q'),
29
+ decision_text: input.decisionText,
30
+ constraint_set_id: constraintSetId,
31
+ refs: input.refs ?? [],
32
+ status: input.status ?? 'active',
33
+ supersedes_id: input.supersedesId,
34
+ timestamp: now,
35
+ agent_id: this.agentId,
36
+ domain: input.domain
37
+ };
38
+ elen_core_1.decisionRecordSchema.parse(record);
39
+ await this.storage.saveRecord(record);
40
+ return record;
41
+ }
42
+ async supersedeDecision(oldDecisionId, input) {
43
+ // 1. Mark old as superseded
44
+ const oldRecord = await this.storage.getRecord(oldDecisionId);
45
+ if (oldRecord) {
46
+ oldRecord.status = 'superseded';
47
+ await this.storage.saveRecord(oldRecord);
48
+ }
49
+ // 2. Commit new
50
+ return this.commitDecision({
51
+ ...input,
52
+ supersedesId: oldDecisionId
53
+ });
54
+ }
55
+ async suggest(opts) {
56
+ const fullRecords = await this.storage.searchRecords(opts);
57
+ // Pointer-first retrieval (minimal payload)
58
+ return fullRecords.map(r => ({
59
+ decision_id: r.decision_id,
60
+ status: r.status,
61
+ decision_text: r.decision_text,
62
+ constraint_set_id: r.constraint_set_id,
63
+ refs: r.refs,
64
+ supersedes_id: r.supersedes_id
65
+ }));
66
+ }
67
+ async expand(decisionId) {
68
+ const record = await this.storage.getRecord(decisionId);
69
+ if (!record)
70
+ return null;
71
+ const constraints = await this.storage.getConstraintSet(record.constraint_set_id);
72
+ if (!constraints)
73
+ return null;
74
+ return { record, constraints };
75
+ }
76
+ async getCompetencyProfile() {
77
+ return this.storage.getCompetencyProfile(this.agentId);
78
+ }
79
+ }
80
+ exports.ElenClient = ElenClient;
package/dist/id.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function createId(prefix: string): string;
2
+ export declare function createDecisionId(domain: string): string;
3
+ export declare function createConstraintSetId(atoms: string[]): string;
package/dist/id.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createId = createId;
4
+ exports.createDecisionId = createDecisionId;
5
+ exports.createConstraintSetId = createConstraintSetId;
6
+ const node_crypto_1 = require("node:crypto");
7
+ function createId(prefix) {
8
+ return `${prefix}-${(0, node_crypto_1.randomBytes)(8).toString('base64url').slice(0, 10)}`;
9
+ }
10
+ function createDecisionId(domain) {
11
+ // Analytical Prefix: 3 chars domain + 'A' (Agent) + 'T3' (Routine Tier)
12
+ const d = domain.toUpperCase().replace(/[^A-Z]/g, '').padEnd(3, 'X').substring(0, 3);
13
+ const prefix = `${d}AT3`;
14
+ return `dec:${prefix}-${(0, node_crypto_1.randomBytes)(4).toString('base64url').slice(0, 6)}`;
15
+ }
16
+ function createConstraintSetId(atoms) {
17
+ const sorted = [...atoms].sort().join('|');
18
+ const hash = (0, node_crypto_1.createHash)('sha256').update(sorted).digest('hex').substring(0, 8);
19
+ return `cs:${hash}`;
20
+ }
@@ -0,0 +1,18 @@
1
+ import type { ElenConfig, CommitDecisionInput, SearchOptions } from './types';
2
+ export declare class Elen {
3
+ private readonly client;
4
+ constructor(config: ElenConfig);
5
+ private createStorage;
6
+ commitDecision(input: CommitDecisionInput): Promise<import("@learningnodes/elen-core").DecisionRecord>;
7
+ supersedeDecision(oldDecisionId: string, input: CommitDecisionInput): Promise<import("@learningnodes/elen-core").DecisionRecord>;
8
+ suggest(opts: SearchOptions): Promise<Partial<import("@learningnodes/elen-core").DecisionRecord>[]>;
9
+ expand(decisionId: string): Promise<{
10
+ record: import("@learningnodes/elen-core").DecisionRecord;
11
+ constraints: import("@learningnodes/elen-core").ConstraintSet;
12
+ } | null>;
13
+ getCompetencyProfile(): Promise<import("@learningnodes/elen-core").CompetencyProfile>;
14
+ }
15
+ export * from './client';
16
+ export * from './id';
17
+ export * from './storage';
18
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Elen = void 0;
18
+ const client_1 = require("./client");
19
+ const storage_1 = require("./storage");
20
+ class Elen {
21
+ constructor(config) {
22
+ const storage = this.createStorage(config);
23
+ this.client = new client_1.ElenClient(config.agentId, storage);
24
+ }
25
+ createStorage(config) {
26
+ if (config.storage === 'sqlite') {
27
+ return new storage_1.SQLiteStorage(config.sqlitePath ?? 'elen.db', config.projectId);
28
+ }
29
+ return new storage_1.InMemoryStorage();
30
+ }
31
+ async commitDecision(input) {
32
+ return this.client.commitDecision(input);
33
+ }
34
+ async supersedeDecision(oldDecisionId, input) {
35
+ return this.client.supersedeDecision(oldDecisionId, input);
36
+ }
37
+ async suggest(opts) {
38
+ return this.client.suggest(opts);
39
+ }
40
+ async expand(decisionId) {
41
+ return this.client.expand(decisionId);
42
+ }
43
+ async getCompetencyProfile() {
44
+ return this.client.getCompetencyProfile();
45
+ }
46
+ }
47
+ exports.Elen = Elen;
48
+ __exportStar(require("./client"), exports);
49
+ __exportStar(require("./id"), exports);
50
+ __exportStar(require("./storage"), exports);
51
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './interface';
2
+ export * from './memory';
3
+ export * from './sqlite';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interface"), exports);
18
+ __exportStar(require("./memory"), exports);
19
+ __exportStar(require("./sqlite"), exports);
@@ -0,0 +1,11 @@
1
+ import type { CompetencyProfile, DecisionRecord, ConstraintSet } from '@learningnodes/elen-core';
2
+ import type { SearchOptions } from '../types';
3
+ export interface StorageAdapter {
4
+ saveConstraintSet(constraintSet: ConstraintSet): Promise<void>;
5
+ getConstraintSet(id: string): Promise<ConstraintSet | null>;
6
+ saveRecord(record: DecisionRecord): Promise<void>;
7
+ getRecord(recordId: string): Promise<DecisionRecord | null>;
8
+ searchRecords(opts: SearchOptions): Promise<DecisionRecord[]>;
9
+ getAgentDecisions(agentId: string, domain?: string): Promise<DecisionRecord[]>;
10
+ getCompetencyProfile(agentId: string): Promise<CompetencyProfile>;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import type { CompetencyProfile, ConstraintSet, DecisionRecord } from '@learningnodes/elen-core';
2
+ import type { SearchOptions } from '../types';
3
+ import type { StorageAdapter } from './interface';
4
+ export declare class InMemoryStorage implements StorageAdapter {
5
+ private readonly constraintSets;
6
+ private readonly records;
7
+ saveConstraintSet(constraintSet: ConstraintSet): Promise<void>;
8
+ getConstraintSet(id: string): Promise<ConstraintSet | null>;
9
+ saveRecord(record: DecisionRecord): Promise<void>;
10
+ getRecord(recordId: string): Promise<DecisionRecord | null>;
11
+ searchRecords(opts: SearchOptions): Promise<DecisionRecord[]>;
12
+ getAgentDecisions(agentId: string, domain?: string): Promise<DecisionRecord[]>;
13
+ getCompetencyProfile(agentId: string): Promise<CompetencyProfile>;
14
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryStorage = void 0;
4
+ class InMemoryStorage {
5
+ constructor() {
6
+ this.constraintSets = new Map();
7
+ this.records = new Map();
8
+ }
9
+ async saveConstraintSet(constraintSet) {
10
+ if (!this.constraintSets.has(constraintSet.constraint_set_id)) {
11
+ this.constraintSets.set(constraintSet.constraint_set_id, constraintSet);
12
+ }
13
+ }
14
+ async getConstraintSet(id) {
15
+ return this.constraintSets.get(id) ?? null;
16
+ }
17
+ async saveRecord(record) {
18
+ this.records.set(record.decision_id, record);
19
+ }
20
+ async getRecord(recordId) {
21
+ return this.records.get(recordId) ?? null;
22
+ }
23
+ async searchRecords(opts) {
24
+ let results = Array.from(this.records.values());
25
+ if (opts.domain) {
26
+ results = results.filter((record) => record.domain === opts.domain);
27
+ }
28
+ if (opts.query) {
29
+ const needle = opts.query.toLowerCase();
30
+ results = results.filter((record) => {
31
+ const haystack = [
32
+ record.decision_text,
33
+ record.domain,
34
+ record.q_id
35
+ ].join(' ').toLowerCase();
36
+ return haystack.includes(needle);
37
+ });
38
+ }
39
+ const limit = opts.limit ?? results.length;
40
+ return results.sort((a, b) => b.timestamp.localeCompare(a.timestamp)).slice(0, limit);
41
+ }
42
+ async getAgentDecisions(agentId, domain) {
43
+ return Array.from(this.records.values()).filter((record) => record.agent_id === agentId && (domain ? record.domain === domain : true));
44
+ }
45
+ async getCompetencyProfile(agentId) {
46
+ const records = await this.getAgentDecisions(agentId);
47
+ const domainCounts = new Map();
48
+ for (const record of records) {
49
+ const count = domainCounts.get(record.domain) ?? 0;
50
+ domainCounts.set(record.domain, count + 1);
51
+ }
52
+ const domains = Array.from(domainCounts.keys());
53
+ const strengths = [];
54
+ const weaknesses = [];
55
+ for (const [domain, count] of domainCounts.entries()) {
56
+ if (count >= 5) {
57
+ strengths.push(domain);
58
+ }
59
+ }
60
+ return {
61
+ agent_id: agentId,
62
+ domains,
63
+ strengths,
64
+ weaknesses,
65
+ updated_at: new Date().toISOString()
66
+ };
67
+ }
68
+ }
69
+ exports.InMemoryStorage = InMemoryStorage;
@@ -0,0 +1,34 @@
1
+ import type { CompetencyProfile, DecisionRecord, ConstraintSet } from '@learningnodes/elen-core';
2
+ import type { SearchOptions } from '../types';
3
+ import type { StorageAdapter } from './interface';
4
+ export interface ProjectRecord {
5
+ project_id: string;
6
+ display_name: string;
7
+ source_hint: string | null;
8
+ created_at: string;
9
+ }
10
+ export interface ProjectSharingRecord {
11
+ source_project_id: string;
12
+ target_project_id: string;
13
+ direction: 'one-way' | 'bi-directional';
14
+ enabled: number;
15
+ }
16
+ export declare class SQLiteStorage implements StorageAdapter {
17
+ private readonly db;
18
+ private readonly projectId;
19
+ constructor(path: string, projectId?: string);
20
+ private init;
21
+ private ensureProject;
22
+ getProjects(): ProjectRecord[];
23
+ getSharing(): ProjectSharingRecord[];
24
+ upsertSharing(source: string, target: string, direction: 'one-way' | 'bi-directional', enabled: boolean): void;
25
+ deleteSharing(source: string, target: string): void;
26
+ private getAccessibleProjects;
27
+ saveConstraintSet(constraintSet: ConstraintSet): Promise<void>;
28
+ getConstraintSet(id: string): Promise<ConstraintSet | null>;
29
+ saveRecord(record: DecisionRecord): Promise<void>;
30
+ getRecord(recordId: string): Promise<DecisionRecord | null>;
31
+ searchRecords(opts: SearchOptions): Promise<DecisionRecord[]>;
32
+ getAgentDecisions(agentId: string, domain?: string): Promise<DecisionRecord[]>;
33
+ getCompetencyProfile(agentId: string): Promise<CompetencyProfile>;
34
+ }