@feltdb/core 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/README.md +184 -0
- package/dist/agent-decision.d.ts +81 -0
- package/dist/agent-decision.d.ts.map +1 -0
- package/dist/agent-decision.js +18 -0
- package/dist/agent-memory.d.ts +91 -0
- package/dist/agent-memory.d.ts.map +1 -0
- package/dist/agent-memory.js +21 -0
- package/dist/agent-observation.d.ts +61 -0
- package/dist/agent-observation.d.ts.map +1 -0
- package/dist/agent-observation.js +12 -0
- package/dist/agent-registry.d.ts +92 -0
- package/dist/agent-registry.d.ts.map +1 -0
- package/dist/agent-registry.js +134 -0
- package/dist/agent-runtime.d.ts +147 -0
- package/dist/agent-runtime.d.ts.map +1 -0
- package/dist/agent-runtime.js +240 -0
- package/dist/agent.d.ts +132 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +58 -0
- package/dist/capability.d.ts +21 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +23 -0
- package/dist/collection.d.ts +95 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +289 -0
- package/dist/db.d.ts +504 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +700 -0
- package/dist/execution.d.ts +148 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +18 -0
- package/dist/feltdb.d.ts +82 -0
- package/dist/feltdb.d.ts.map +1 -0
- package/dist/feltdb.js +6 -0
- package/dist/flowspec.d.ts +64 -0
- package/dist/flowspec.d.ts.map +1 -0
- package/dist/flowspec.js +272 -0
- package/dist/http-db.d.ts +50 -0
- package/dist/http-db.d.ts.map +1 -0
- package/dist/http-db.js +205 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/indexeddb-db.d.ts +54 -0
- package/dist/indexeddb-db.d.ts.map +1 -0
- package/dist/indexeddb-db.js +175 -0
- package/dist/memory-db.d.ts +49 -0
- package/dist/memory-db.d.ts.map +1 -0
- package/dist/memory-db.js +97 -0
- package/dist/operation.d.ts +25 -0
- package/dist/operation.d.ts.map +1 -0
- package/dist/operation.js +16 -0
- package/dist/reactive-graph.d.ts +67 -0
- package/dist/reactive-graph.d.ts.map +1 -0
- package/dist/reactive-graph.js +118 -0
- package/dist/recovery.d.ts +68 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +104 -0
- package/dist/storage.d.ts +48 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +6 -0
- package/dist/workflow.d.ts +20 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +12 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @feltdb/core
|
|
2
|
+
|
|
3
|
+
The main FeltDB API. This package provides a simple, state-first interface for working with FeltDB.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @feltdb/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createFeltDB } from '@feltdb/core';
|
|
15
|
+
|
|
16
|
+
const db = createFeltDB({
|
|
17
|
+
namespace: 'my-app',
|
|
18
|
+
server: {
|
|
19
|
+
url: 'https://db.example.com',
|
|
20
|
+
token: process.env.FELTDB_API_KEY!,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const todos = db.collection('todos');
|
|
25
|
+
|
|
26
|
+
// Insert
|
|
27
|
+
await todos.insert({
|
|
28
|
+
id: '1',
|
|
29
|
+
title: 'Learn FeltDB',
|
|
30
|
+
completed: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Query
|
|
34
|
+
const items = await todos.find({ completed: false });
|
|
35
|
+
|
|
36
|
+
// Update
|
|
37
|
+
await todos.update('1', { completed: true });
|
|
38
|
+
|
|
39
|
+
// Subscribe to changes
|
|
40
|
+
todos.subscribe((change) => {
|
|
41
|
+
console.log('Collection changed:', change);
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For a durable offline browser database using the same API:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const db = createFeltDB({ namespace: 'my-app', browser: true });
|
|
49
|
+
const todos = db.collection<Todo>('todos');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Browser mutations resolve after their IndexedDB transaction commits. The
|
|
53
|
+
durable change journal replays after reload and coordinates live collections
|
|
54
|
+
across tabs through `BroadcastChannel` when available.
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
### createFeltDB(options)
|
|
59
|
+
|
|
60
|
+
Initialize a new FeltDB instance.
|
|
61
|
+
|
|
62
|
+
**Options:**
|
|
63
|
+
- `namespace` (string) - Application namespace for data isolation
|
|
64
|
+
- `server` - Durable authenticated FeltDB server (`url` and `token`)
|
|
65
|
+
- `memory: true` - Explicit ephemeral development/test runtime; never use for customer data
|
|
66
|
+
- `browser: true` - Durable IndexedDB runtime with restart-safe change replay
|
|
67
|
+
|
|
68
|
+
**Returns:** Database instance
|
|
69
|
+
|
|
70
|
+
### db.collection(name)
|
|
71
|
+
|
|
72
|
+
Get or create a collection.
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
- `name` (string) - Collection name
|
|
76
|
+
|
|
77
|
+
**Returns:** Collection instance
|
|
78
|
+
|
|
79
|
+
### collection.insert(item)
|
|
80
|
+
|
|
81
|
+
Insert a new item into the collection.
|
|
82
|
+
|
|
83
|
+
**Parameters:**
|
|
84
|
+
- `item` (object) - Item to insert
|
|
85
|
+
|
|
86
|
+
**Returns:** Promise<string> - Item ID
|
|
87
|
+
|
|
88
|
+
### collection.find(query)
|
|
89
|
+
|
|
90
|
+
Query items from the collection.
|
|
91
|
+
|
|
92
|
+
**Parameters:**
|
|
93
|
+
- `query` (object) - Query filter
|
|
94
|
+
|
|
95
|
+
**Returns:** Promise<Array> - Matching items
|
|
96
|
+
|
|
97
|
+
### collection.update(id, updates)
|
|
98
|
+
|
|
99
|
+
Update an item in the collection.
|
|
100
|
+
|
|
101
|
+
**Parameters:**
|
|
102
|
+
- `id` (string) - Item ID
|
|
103
|
+
- `updates` (object) - Fields to update
|
|
104
|
+
|
|
105
|
+
**Returns:** Promise<void>
|
|
106
|
+
|
|
107
|
+
### collection.delete(id)
|
|
108
|
+
|
|
109
|
+
Remove an item from the collection.
|
|
110
|
+
|
|
111
|
+
**Parameters:**
|
|
112
|
+
- `id` (string) - Item ID
|
|
113
|
+
|
|
114
|
+
**Returns:** Promise<void>
|
|
115
|
+
|
|
116
|
+
### collection.subscribe(callback)
|
|
117
|
+
|
|
118
|
+
Subscribe to collection changes.
|
|
119
|
+
|
|
120
|
+
**Parameters:**
|
|
121
|
+
- `callback` (function) - Called when collection changes
|
|
122
|
+
|
|
123
|
+
**Returns:** Function - Unsubscribe function
|
|
124
|
+
|
|
125
|
+
### Network acquisition and state-first execution
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const task = await db.acquire<Task>('tasks', 'task-42');
|
|
129
|
+
const matches = await db.search<Task>('tasks', 'shipping blocker');
|
|
130
|
+
const artifact = await db.storeContent(new TextEncoder().encode('release artifact'));
|
|
131
|
+
const verifiedBytes = await db.acquireContent(artifact.hash);
|
|
132
|
+
|
|
133
|
+
await db.defineCapability('open-tasks', [
|
|
134
|
+
{ op: 'search', collection: 'tasks', query: '' },
|
|
135
|
+
{ op: 'filter_eq', field: 'done', value: false },
|
|
136
|
+
{ op: 'limit', count: 100 },
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
await db.defineWorkflow('release', ['verify', 'publish']);
|
|
140
|
+
const run = await db.startWorkflow('release', { version: '1.0.0' });
|
|
141
|
+
const claimed = await db.claimWorkflowStep(run.value.id, 'verify', 'worker-1');
|
|
142
|
+
await db.completeWorkflowStep(
|
|
143
|
+
run.value.id, 'verify', claimed.value.steps[0].claim_id, { ok: true },
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
await db.defineStateAgent('triage', ['search']);
|
|
147
|
+
const agentRun = await db.startStateAgent('triage', 'resolve customer blocker');
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Acquisition synchronizes canonical causal operations from configured peers.
|
|
151
|
+
Workflow and agent lifecycle records are canonical collections, so durability,
|
|
152
|
+
live events, replication, authorization, and audit apply automatically.
|
|
153
|
+
Execution claims use durable majority leases when peers are configured; stale
|
|
154
|
+
or minority-partition workers cannot publish completion.
|
|
155
|
+
|
|
156
|
+
### Embedded replica convergence and capability failover
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const command = createFeltDB({ namespace: 'command', browser: true });
|
|
160
|
+
const field = createFeltDB({ namespace: 'field', browser: true });
|
|
161
|
+
|
|
162
|
+
// Both replicas continue accepting durable state while disconnected.
|
|
163
|
+
await command.collection('resources').insert(resource, 'water-team');
|
|
164
|
+
await field.collection('incidents').insert(incident, 'clinic');
|
|
165
|
+
|
|
166
|
+
// Transport-independent, bidirectional operation exchange. Replays deduplicate.
|
|
167
|
+
await command.synchronizeWith(field);
|
|
168
|
+
|
|
169
|
+
field.registerCapabilityWorker('AssessIncident', assessIncident);
|
|
170
|
+
const routed = await command.executeCapabilityWithFailover(
|
|
171
|
+
'AssessIncident', { incident }, [field],
|
|
172
|
+
);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`exportOperations()` and `applyOperations()` are also available when the
|
|
176
|
+
application supplies its own transport. Merges use stable operation identity
|
|
177
|
+
and deterministic last-writer ordering, notify live collections, and retain
|
|
178
|
+
the imported operations in the local audit journal. Capability routing records
|
|
179
|
+
every provider attempt in `_flow_capability_routes`; each successful worker
|
|
180
|
+
execution is materialized in `_flow_executions`.
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Decision
|
|
3
|
+
*
|
|
4
|
+
* A first-class decision made by an agent with full provenance.
|
|
5
|
+
* Decisions are audit/provenance explanations, not hidden chain-of-thought.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* An action the agent could take
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentAction {
|
|
11
|
+
/** Unique action ID */
|
|
12
|
+
actionId: string;
|
|
13
|
+
/** Reference to the capability to invoke */
|
|
14
|
+
capabilityRef: string;
|
|
15
|
+
/** Input parameters for the capability */
|
|
16
|
+
inputs?: Record<string, any>;
|
|
17
|
+
/** Expected outcomes */
|
|
18
|
+
expectedOutcome?: string;
|
|
19
|
+
/** Confidence level (0-100) */
|
|
20
|
+
confidence?: number;
|
|
21
|
+
/** Why this action was selected */
|
|
22
|
+
reasoning?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A decision made by an agent
|
|
26
|
+
*/
|
|
27
|
+
export interface AgentDecision {
|
|
28
|
+
/** Unique decision ID */
|
|
29
|
+
decisionId: string;
|
|
30
|
+
/** Reference to the observing agent */
|
|
31
|
+
agentRef: {
|
|
32
|
+
name: string;
|
|
33
|
+
version: number;
|
|
34
|
+
};
|
|
35
|
+
/** Execution ID that made this decision */
|
|
36
|
+
executionId: string;
|
|
37
|
+
/** Observation that prompted this decision */
|
|
38
|
+
observationId: string;
|
|
39
|
+
/** The agent's intent */
|
|
40
|
+
intent: string;
|
|
41
|
+
/** The action the agent decided to take */
|
|
42
|
+
selectedAction: AgentAction;
|
|
43
|
+
/** Alternative actions considered */
|
|
44
|
+
alternatives?: AgentAction[];
|
|
45
|
+
/** Structured reasoning for the decision */
|
|
46
|
+
reason: {
|
|
47
|
+
/** Why this action was selected */
|
|
48
|
+
primary: string;
|
|
49
|
+
/** Constraints that were considered */
|
|
50
|
+
constraints?: string[];
|
|
51
|
+
/** State that influenced the decision */
|
|
52
|
+
stateFactors?: string[];
|
|
53
|
+
/** Capabilities that were available */
|
|
54
|
+
availableCapabilities?: string[];
|
|
55
|
+
/** Policy considerations */
|
|
56
|
+
policyFactors?: string[];
|
|
57
|
+
};
|
|
58
|
+
/** Confidence in this decision (0-100) */
|
|
59
|
+
confidence: number;
|
|
60
|
+
/** Whether this decision required human approval */
|
|
61
|
+
requiresApproval?: boolean;
|
|
62
|
+
/** Approval status if required */
|
|
63
|
+
approvalStatus?: 'pending' | 'approved' | 'rejected' | 'cancelled';
|
|
64
|
+
/** Approval timestamp if applicable */
|
|
65
|
+
approvedAt?: number;
|
|
66
|
+
/** Approver identity if applicable */
|
|
67
|
+
approvedBy?: string;
|
|
68
|
+
/** Timestamp when decision was made */
|
|
69
|
+
decidedAt: number;
|
|
70
|
+
/** Metadata */
|
|
71
|
+
metadata?: Record<string, any>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Generate a unique decision ID
|
|
75
|
+
*/
|
|
76
|
+
export declare function generateDecisionId(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Generate a unique action ID
|
|
79
|
+
*/
|
|
80
|
+
export declare function generateActionId(): string;
|
|
81
|
+
//# sourceMappingURL=agent-decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-decision.d.ts","sourceRoot":"","sources":["../src/agent-decision.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IAEjB,4CAA4C;IAC5C,aAAa,EAAE,MAAM,CAAC;IAEtB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B,wBAAwB;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH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gB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Decision
|
|
3
|
+
*
|
|
4
|
+
* A first-class decision made by an agent with full provenance.
|
|
5
|
+
* Decisions are audit/provenance explanations, not hidden chain-of-thought.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique decision ID
|
|
9
|
+
*/
|
|
10
|
+
export function generateDecisionId() {
|
|
11
|
+
return `dec-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique action ID
|
|
15
|
+
*/
|
|
16
|
+
export function generateActionId() {
|
|
17
|
+
return `act-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Memory
|
|
3
|
+
*
|
|
4
|
+
* Agent memory is just FeltDB state. Memory is stored as collections
|
|
5
|
+
* under flow://agent/{name}/memory/*
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Agent memory configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentMemoryConfig {
|
|
11
|
+
/** Agent name */
|
|
12
|
+
agentName: string;
|
|
13
|
+
/** Maximum memory size in KB */
|
|
14
|
+
maxSizeKb?: number;
|
|
15
|
+
/** Memory retention period in milliseconds */
|
|
16
|
+
retentionMs?: number;
|
|
17
|
+
/** Memory scope */
|
|
18
|
+
scope: 'local' | 'distributed' | 'shared';
|
|
19
|
+
/** Whether to enable memory persistence */
|
|
20
|
+
persistent: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Memory entry stored in an agent's memory collection
|
|
24
|
+
*/
|
|
25
|
+
export interface AgentMemoryEntry {
|
|
26
|
+
/** Unique entry ID */
|
|
27
|
+
entryId: string;
|
|
28
|
+
/** Entry key for lookup */
|
|
29
|
+
key: string;
|
|
30
|
+
/** Entry value */
|
|
31
|
+
value: any;
|
|
32
|
+
/** Entry type */
|
|
33
|
+
type: 'fact' | 'observation' | 'decision' | 'outcome' | 'goal' | 'plan';
|
|
34
|
+
/** When this entry was created */
|
|
35
|
+
createdAt: number;
|
|
36
|
+
/** When this entry expires (optional) */
|
|
37
|
+
expiresAt?: number;
|
|
38
|
+
/** Whether this entry is still valid */
|
|
39
|
+
valid: boolean;
|
|
40
|
+
/** Metadata about the entry */
|
|
41
|
+
metadata?: Record<string, any>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Agent memory query result
|
|
45
|
+
*/
|
|
46
|
+
export interface AgentMemoryResult {
|
|
47
|
+
/** Retrieved memory entries */
|
|
48
|
+
entries: AgentMemoryEntry[];
|
|
49
|
+
/** Total count of matching entries */
|
|
50
|
+
total: number;
|
|
51
|
+
/** Query execution time in milliseconds */
|
|
52
|
+
durationMs: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Memory collection reference for an agent
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAgentMemoryPath(agentName: string, memoryType?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Generate a unique memory entry ID
|
|
60
|
+
*/
|
|
61
|
+
export declare function generateMemoryEntryId(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Agent memory store interface
|
|
64
|
+
*/
|
|
65
|
+
export interface AgentMemoryStore {
|
|
66
|
+
/**
|
|
67
|
+
* Store a memory entry
|
|
68
|
+
*/
|
|
69
|
+
store(agentName: string, entry: AgentMemoryEntry): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieve a memory entry by key
|
|
72
|
+
*/
|
|
73
|
+
retrieve(agentName: string, key: string): Promise<AgentMemoryEntry | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieve all memory entries of a type
|
|
76
|
+
*/
|
|
77
|
+
retrieveByType(agentName: string, type: AgentMemoryEntry['type']): Promise<AgentMemoryEntry[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Query memory entries
|
|
80
|
+
*/
|
|
81
|
+
query(agentName: string, filter: Record<string, any>): Promise<AgentMemoryResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Delete a memory entry
|
|
84
|
+
*/
|
|
85
|
+
delete(agentName: string, key: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Clear all memory for an agent
|
|
88
|
+
*/
|
|
89
|
+
clear(agentName: string): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=agent-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-memory.d.ts","sourceRoot":"","sources":["../src/agent-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,mBAAmB;IACnB,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,QAAQ,CAAC;IAE1C,2CAA2C;IAC3C,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAEhB,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IAEZ,kBAAkB;IAClB,KAAK,EAAE,GAAG,CAAC;IAEX,iBAAiB;IACjB,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAExE,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAElB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wCAAwC;IACxC,KAAK,EAAE,OAAO,CAAC;IAEf,+BAA+B;IAC/B,QAAQ,CAAC,EAA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
4
|
+
* Agent memory is just FeltDB state. Memory is stored as collections
|
|
5
|
+
* under flow://agent/{name}/memory/*
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Memory collection reference for an agent
|
|
9
|
+
*/
|
|
10
|
+
export function getAgentMemoryPath(agentName, memoryType = '') {
|
|
11
|
+
if (memoryType) {
|
|
12
|
+
return `flow://agent/${agentName}/memory/${memoryType}`;
|
|
13
|
+
}
|
|
14
|
+
return `flow://agent/${agentName}/memory`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate a unique memory entry ID
|
|
18
|
+
*/
|
|
19
|
+
export function generateMemoryEntryId() {
|
|
20
|
+
return `mem-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Observation
|
|
3
|
+
*
|
|
4
|
+
* A first-class observation of state changes that can trigger agent reactions.
|
|
5
|
+
* Agents observe references to data, not arbitrary blobs.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* An observation made by or about an agent
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentObservation {
|
|
11
|
+
/** Unique observation ID */
|
|
12
|
+
observationId: string;
|
|
13
|
+
/** Reference to the observing agent */
|
|
14
|
+
agentRef: {
|
|
15
|
+
name: string;
|
|
16
|
+
version: number;
|
|
17
|
+
};
|
|
18
|
+
/** Execution that produced this observation */
|
|
19
|
+
executionId: string;
|
|
20
|
+
/** State version at time of observation */
|
|
21
|
+
stateVersion: number;
|
|
22
|
+
/** Input references that were observed */
|
|
23
|
+
sourceRefs: string[];
|
|
24
|
+
/** Observations about the state */
|
|
25
|
+
observations: {
|
|
26
|
+
/** Reference to observed data */
|
|
27
|
+
ref: string;
|
|
28
|
+
/** What changed */
|
|
29
|
+
change: 'created' | 'updated' | 'deleted';
|
|
30
|
+
/** Previous value (if available) */
|
|
31
|
+
previous?: any;
|
|
32
|
+
/** Current value */
|
|
33
|
+
current?: any;
|
|
34
|
+
/** Timestamp of the change */
|
|
35
|
+
changedAt: number;
|
|
36
|
+
}[];
|
|
37
|
+
/** Timestamp when observation was recorded */
|
|
38
|
+
recordedAt: number;
|
|
39
|
+
/** Metadata */
|
|
40
|
+
metadata?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reactive observation trigger
|
|
44
|
+
*
|
|
45
|
+
* Specifies conditions that should wake an agent
|
|
46
|
+
*/
|
|
47
|
+
export interface ObservationTrigger {
|
|
48
|
+
/** Which state patterns to watch */
|
|
49
|
+
patterns: string[];
|
|
50
|
+
/** Trigger on these change types */
|
|
51
|
+
changeTypes: ('created' | 'updated' | 'deleted')[];
|
|
52
|
+
/** Optional debounce time in milliseconds */
|
|
53
|
+
debounceMs?: number;
|
|
54
|
+
/** Optional timeout - max wait time in milliseconds */
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate a unique observation ID
|
|
59
|
+
*/
|
|
60
|
+
export declare function generateObservationId(): string;
|
|
61
|
+
//# sourceMappingURL=agent-observation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observation.d.ts","sourceRoot":"","sources":["../src/agent-observation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,aAAa,EAAE,MAAM,CAAC;IAEtB,uCAAuC;IACvC,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IAEpB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IAErB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB,mCAAmC;IACnC,YAAY,EAAE;QACZ,iCAAiC;QACjC,GAAG,EAAE,MAAM,CAAC;QAEZ,mBAAmB;QACnB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;QAE1C,oCAAoC;QACpC,QAAQ,CAAC,EAAE,GAAG,CAAC;QAEf,oBAAoB;QACpB,OAAO,CAAC,EAAE,GAAG,CAAC;QAEd,8BAA8B;QAC9B,SAAS,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;IAEJ,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IAEnB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,oCAAoC;IACpC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB,oCAAoC;IACpC,WAAW,EAAE,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,EAAE,CAAC;IAEnD,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Observation
|
|
3
|
+
*
|
|
4
|
+
* A first-class observation of state changes that can trigger agent reactions.
|
|
5
|
+
* Agents observe references to data, not arbitrary blobs.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique observation ID
|
|
9
|
+
*/
|
|
10
|
+
export function generateObservationId() {
|
|
11
|
+
return `obs-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry
|
|
3
|
+
*
|
|
4
|
+
* Similar to PeerRegistry and CapabilityLocationRegistry.
|
|
5
|
+
* Maps AgentRef to Agent definition, available providers, and compatible state.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentDefinition, AgentRef } from './agent.js';
|
|
8
|
+
/**
|
|
9
|
+
* Information about an agent provider
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentProvider {
|
|
12
|
+
/** Peer ID that provides this agent */
|
|
13
|
+
peerId: string;
|
|
14
|
+
/** Whether this peer is currently available */
|
|
15
|
+
available: boolean;
|
|
16
|
+
/** State version this peer has */
|
|
17
|
+
stateVersion: number;
|
|
18
|
+
/** Timestamp of last heartbeat */
|
|
19
|
+
lastHeartbeat: number;
|
|
20
|
+
/** Capabilities this provider supports */
|
|
21
|
+
capabilities: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Agent registration entry in the registry
|
|
25
|
+
*/
|
|
26
|
+
export interface AgentRegistryEntry {
|
|
27
|
+
/** The agent reference */
|
|
28
|
+
agentRef: AgentRef;
|
|
29
|
+
/** Agent definition */
|
|
30
|
+
definition: AgentDefinition;
|
|
31
|
+
/** Available providers for this agent */
|
|
32
|
+
providers: AgentProvider[];
|
|
33
|
+
/** Compatible state versions */
|
|
34
|
+
compatibleStateVersions: number[];
|
|
35
|
+
/** When this entry was registered */
|
|
36
|
+
registeredAt: number;
|
|
37
|
+
/** Last update timestamp */
|
|
38
|
+
updatedAt: number;
|
|
39
|
+
/** Is this agent currently active */
|
|
40
|
+
active: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Registry for agent definitions and discovery
|
|
44
|
+
*/
|
|
45
|
+
export declare class AgentRegistry {
|
|
46
|
+
private agents;
|
|
47
|
+
/**
|
|
48
|
+
* Register an agent definition
|
|
49
|
+
*/
|
|
50
|
+
register(agentRef: AgentRef, definition: AgentDefinition): void;
|
|
51
|
+
/**
|
|
52
|
+
* Unregister an agent
|
|
53
|
+
*/
|
|
54
|
+
unregister(agentRef: AgentRef): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get an agent registration entry
|
|
57
|
+
*/
|
|
58
|
+
get(agentRef: AgentRef): AgentRegistryEntry | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Get agent by name (returns latest version)
|
|
61
|
+
*/
|
|
62
|
+
getByName(name: string): AgentRegistryEntry | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Get all registered agents
|
|
65
|
+
*/
|
|
66
|
+
getAll(): AgentRegistryEntry[];
|
|
67
|
+
/**
|
|
68
|
+
* Add a provider for an agent
|
|
69
|
+
*/
|
|
70
|
+
addProvider(agentRef: AgentRef, provider: AgentProvider): void;
|
|
71
|
+
/**
|
|
72
|
+
* Remove a provider
|
|
73
|
+
*/
|
|
74
|
+
removeProvider(agentRef: AgentRef, peerId: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get available providers for an agent
|
|
77
|
+
*/
|
|
78
|
+
getAvailableProviders(agentRef: AgentRef): AgentProvider[];
|
|
79
|
+
/**
|
|
80
|
+
* Find agents by capability
|
|
81
|
+
*/
|
|
82
|
+
findByCapability(capability: string): AgentRegistryEntry[];
|
|
83
|
+
/**
|
|
84
|
+
* Update agent availability
|
|
85
|
+
*/
|
|
86
|
+
updateAvailability(agentRef: AgentRef, peerId: string, available: boolean): void;
|
|
87
|
+
/**
|
|
88
|
+
* Clear all registrations
|
|
89
|
+
*/
|
|
90
|
+
clear(): void;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=agent-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-registry.d.ts","sourceRoot":"","sources":["../src/agent-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IAEf,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IAEnB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IAErB,kCAAkC;IAClC,aAAa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