@almadar/agent 2.0.0 → 2.0.2
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/agent/event-budget.d.ts +28 -0
- package/dist/agent/experimental/hitl-v2.d.ts +161 -0
- package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/interrupt-config.d.ts +51 -0
- package/dist/agent/session-manager.d.ts +204 -0
- package/dist/agent/skill-agent.d.ts +182 -0
- package/dist/agent/workflow-middleware.d.ts +63 -0
- package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
- package/dist/api-types.d.ts +595 -0
- package/dist/context/compaction.d.ts +191 -0
- package/dist/context-compaction.d.ts +55 -0
- package/dist/evals/online-sampling.d.ts +114 -0
- package/dist/evals/utils/compact-orbital.d.ts +100 -0
- package/dist/event-transformer/event-transformer.d.ts +120 -0
- package/dist/event-transformer/index.d.ts +7 -0
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryManager.d.ts +243 -0
- package/dist/memory/PreferenceLearner.d.ts +59 -0
- package/dist/memory/agentic-search.d.ts +116 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/memory-orbital.d.ts +66 -0
- package/dist/memory/types.d.ts +143 -0
- package/dist/metrics.d.ts +77 -0
- package/dist/multi-user.d.ts +155 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/langsmith-integration.d.ts +203 -0
- package/dist/observability.d.ts +196 -0
- package/dist/orbitals/archive/sanitize.d.ts +24 -0
- package/dist/orbitals/batch/batch-generator.d.ts +41 -0
- package/dist/orbitals/batch/concurrency.d.ts +54 -0
- package/dist/orbitals/batch/index.d.ts +14 -0
- package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
- package/dist/orbitals/batch/types.d.ts +103 -0
- package/dist/orbitals/cache/index.d.ts +11 -0
- package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
- package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
- package/dist/orbitals/cache/structural-templates.d.ts +33 -0
- package/dist/orbitals/combiner/index.d.ts +102 -0
- package/dist/orbitals/domain-language/index.d.ts +9 -0
- package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
- package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
- package/dist/orbitals/generation/index.d.ts +10 -0
- package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
- package/dist/orbitals/shared/constants.d.ts +65 -0
- package/dist/orbitals/shared/index.d.ts +11 -0
- package/dist/orbitals/shared/types.d.ts +187 -0
- package/dist/orbitals/shared/utils.d.ts +97 -0
- package/dist/orchestration/complexity-classifier.d.ts +38 -0
- package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
- package/dist/orchestration/index.d.ts +31 -0
- package/dist/orchestration/provider-router.d.ts +45 -0
- package/dist/persistence/firestore-checkpointer.d.ts +139 -0
- package/dist/persistence/firestore-session-store.d.ts +75 -0
- package/dist/persistence/firestore-store.d.ts +86 -0
- package/dist/persistence/index.d.ts +10 -0
- package/dist/persistence/memory-backend.d.ts +33 -0
- package/dist/persistence/types.d.ts +40 -0
- package/dist/security/audit-log.d.ts +44 -0
- package/dist/state-sync.d.ts +171 -0
- package/dist/subagents.d.ts +38 -0
- package/dist/tools/combine-schemas.d.ts +154 -0
- package/dist/tools/composition.d.ts +119 -0
- package/dist/tools/domain-orbital.d.ts +997 -0
- package/dist/tools/execute.d.ts +38 -0
- package/dist/tools/finish-task.d.ts +56 -0
- package/dist/tools/generate-schema.d.ts +53 -0
- package/dist/tools/github.d.ts +297 -0
- package/dist/tools/index.d.ts +1318 -0
- package/dist/tools/orbital-batch-subagent.d.ts +85 -0
- package/dist/tools/orbital-subagent.d.ts +454 -0
- package/dist/tools/orchestrated-fixing.d.ts +74 -0
- package/dist/tools/orchestrated-generation.d.ts +75 -0
- package/dist/tools/sandbox-executor.d.ts +31 -0
- package/dist/tools/schema-chunking.d.ts +117 -0
- package/dist/tools/trait-subagent.d.ts +179 -0
- package/dist/tools/validate-schema.d.ts +17 -0
- package/dist/types.d.ts +167 -0
- package/dist/utils/safety/capability-token.d.ts +50 -0
- package/dist/utils/safety/circuit-breaker.d.ts +71 -0
- package/dist/utils/safety/index.d.ts +19 -0
- package/dist/utils/safety/rate-limiter.d.ts +39 -0
- package/dist/utils/safety/threshold-auth.d.ts +70 -0
- package/dist/workspace/git-client.d.ts +51 -0
- package/dist/workspace/index.d.ts +38 -0
- package/dist/workspace/memory-files.d.ts +31 -0
- package/dist/workspace/sink-manager.d.ts +26 -0
- package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
- package/dist/workspace/sinks/git-sink.d.ts +47 -0
- package/dist/workspace/sinks/index.d.ts +9 -0
- package/dist/workspace/templates.d.ts +32 -0
- package/dist/workspace/types.d.ts +86 -0
- package/dist/workspace/workspace-manager.d.ts +57 -0
- package/package.json +8 -7
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firestore Checkpointer for LangGraph
|
|
3
|
+
*
|
|
4
|
+
* Custom implementation of BaseCheckpointSaver using Firebase Firestore.
|
|
5
|
+
* This is required because LangGraph only provides Postgres/Redis savers.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: This module does NOT import firebase-admin directly.
|
|
8
|
+
* The Firestore `db` instance must be injected via constructor options.
|
|
9
|
+
* This keeps the @almadar/agent package free of firebase-admin as a direct dependency.
|
|
10
|
+
*/
|
|
11
|
+
import { BaseCheckpointSaver, type Checkpoint, type CheckpointTuple, type CheckpointMetadata, type CheckpointListOptions, type PendingWrite } from '@langchain/langgraph-checkpoint';
|
|
12
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
13
|
+
/**
|
|
14
|
+
* Minimal Firestore interface to avoid importing firebase-admin.
|
|
15
|
+
* Consumers pass their own Firestore instance.
|
|
16
|
+
*/
|
|
17
|
+
export interface FirestoreDb {
|
|
18
|
+
collection(path: string): FirestoreCollectionRef;
|
|
19
|
+
batch(): FirestoreBatch;
|
|
20
|
+
}
|
|
21
|
+
export interface FirestoreCollectionRef {
|
|
22
|
+
doc(id: string): FirestoreDocRef;
|
|
23
|
+
where(field: string, op: string, value: unknown): FirestoreQuery;
|
|
24
|
+
orderBy(field: string, direction?: string): FirestoreQuery;
|
|
25
|
+
limit(n: number): FirestoreQuery;
|
|
26
|
+
}
|
|
27
|
+
export interface FirestoreDocRef {
|
|
28
|
+
set(data: unknown): Promise<unknown>;
|
|
29
|
+
get(): Promise<FirestoreDocSnapshot>;
|
|
30
|
+
update(data: unknown): Promise<unknown>;
|
|
31
|
+
delete(): Promise<unknown>;
|
|
32
|
+
readonly ref: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface FirestoreDocSnapshot {
|
|
35
|
+
exists: boolean;
|
|
36
|
+
data(): Record<string, unknown> | undefined;
|
|
37
|
+
readonly ref: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface FirestoreQuery {
|
|
40
|
+
where(field: string, op: string, value: unknown): FirestoreQuery;
|
|
41
|
+
orderBy(field: string, direction?: string): FirestoreQuery;
|
|
42
|
+
limit(n: number): FirestoreQuery;
|
|
43
|
+
startAfter(doc: unknown): FirestoreQuery;
|
|
44
|
+
get(): Promise<FirestoreQuerySnapshot>;
|
|
45
|
+
}
|
|
46
|
+
export interface FirestoreQuerySnapshot {
|
|
47
|
+
empty: boolean;
|
|
48
|
+
docs: FirestoreQueryDocSnapshot[];
|
|
49
|
+
size: number;
|
|
50
|
+
}
|
|
51
|
+
export interface FirestoreQueryDocSnapshot {
|
|
52
|
+
data(): Record<string, unknown>;
|
|
53
|
+
readonly ref: unknown;
|
|
54
|
+
}
|
|
55
|
+
export interface FirestoreBatch {
|
|
56
|
+
set(ref: unknown, data: unknown): void;
|
|
57
|
+
delete(ref: unknown): void;
|
|
58
|
+
commit(): Promise<unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Firestore Timestamp-like interface.
|
|
62
|
+
*/
|
|
63
|
+
export interface FirestoreTimestamp {
|
|
64
|
+
toDate(): Date;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for FirestoreCheckpointer.
|
|
68
|
+
*/
|
|
69
|
+
export interface FirestoreCheckpointerOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Firestore instance. Required — injected by consumer.
|
|
72
|
+
*/
|
|
73
|
+
db: FirestoreDb;
|
|
74
|
+
/**
|
|
75
|
+
* Collection name for checkpoints.
|
|
76
|
+
* @default 'agent_checkpoints'
|
|
77
|
+
*/
|
|
78
|
+
checkpointsCollection?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Collection name for pending writes.
|
|
81
|
+
* @default 'agent_writes'
|
|
82
|
+
*/
|
|
83
|
+
writesCollection?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Firestore-backed checkpointer for LangGraph agents.
|
|
87
|
+
*
|
|
88
|
+
* Provides persistent checkpoint storage across server restarts.
|
|
89
|
+
* Thread checkpoints are stored as Firestore documents.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { getFirestore } from 'firebase-admin/firestore';
|
|
94
|
+
*
|
|
95
|
+
* const checkpointer = new FirestoreCheckpointer({
|
|
96
|
+
* db: getFirestore(),
|
|
97
|
+
* checkpointsCollection: 'agent_checkpoints',
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* const agent = createDeepAgent({
|
|
101
|
+
* // ...
|
|
102
|
+
* checkpointer,
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare class FirestoreCheckpointer extends BaseCheckpointSaver {
|
|
107
|
+
private db;
|
|
108
|
+
private checkpointsCollection;
|
|
109
|
+
private writesCollection;
|
|
110
|
+
constructor(options: FirestoreCheckpointerOptions);
|
|
111
|
+
/**
|
|
112
|
+
* Get thread ID from config.
|
|
113
|
+
*/
|
|
114
|
+
private getThreadId;
|
|
115
|
+
/**
|
|
116
|
+
* Get checkpoint ID from config, or undefined for latest.
|
|
117
|
+
*/
|
|
118
|
+
private getCheckpointId;
|
|
119
|
+
/**
|
|
120
|
+
* Get checkpoint by config.
|
|
121
|
+
*/
|
|
122
|
+
getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
|
|
123
|
+
/**
|
|
124
|
+
* List checkpoints for a thread.
|
|
125
|
+
*/
|
|
126
|
+
list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
|
|
127
|
+
/**
|
|
128
|
+
* Save a checkpoint.
|
|
129
|
+
*/
|
|
130
|
+
put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata, _newVersions: Record<string, number | string>): Promise<RunnableConfig>;
|
|
131
|
+
/**
|
|
132
|
+
* Store pending writes for a checkpoint.
|
|
133
|
+
*/
|
|
134
|
+
putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Delete all checkpoints and writes for a thread.
|
|
137
|
+
*/
|
|
138
|
+
deleteThread(threadId: string): Promise<void>;
|
|
139
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firestore Session Store for DeepAgent
|
|
3
|
+
*
|
|
4
|
+
* Provides persistent session storage for skill-based agents.
|
|
5
|
+
* Sessions are stored in Firestore and persist across server restarts.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: This module does NOT import firebase-admin directly.
|
|
8
|
+
* The Firestore `db` instance must be injected via constructor options.
|
|
9
|
+
*/
|
|
10
|
+
import type { Session } from './types.js';
|
|
11
|
+
import type { FirestoreDb } from './firestore-checkpointer.js';
|
|
12
|
+
/**
|
|
13
|
+
* Options for FirestoreSessionStore.
|
|
14
|
+
*/
|
|
15
|
+
export interface FirestoreSessionStoreOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Firestore instance. Required — injected by consumer.
|
|
18
|
+
*/
|
|
19
|
+
db: FirestoreDb;
|
|
20
|
+
/**
|
|
21
|
+
* Collection name for sessions.
|
|
22
|
+
* @default 'agent_sessions'
|
|
23
|
+
*/
|
|
24
|
+
collection?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Firestore-backed session store for skill agents.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const sessionStore = new FirestoreSessionStore({ db: getFirestore() });
|
|
32
|
+
*
|
|
33
|
+
* await sessionStore.save({
|
|
34
|
+
* threadId: 'abc-123',
|
|
35
|
+
* skill: 'kflow-generating-m',
|
|
36
|
+
* workDir: '/tmp/workspace',
|
|
37
|
+
* createdAt: new Date(),
|
|
38
|
+
* lastActivityAt: new Date(),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const session = await sessionStore.get('abc-123');
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class FirestoreSessionStore {
|
|
45
|
+
private db;
|
|
46
|
+
private collection;
|
|
47
|
+
constructor(options: FirestoreSessionStoreOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Save a session.
|
|
50
|
+
*/
|
|
51
|
+
save(session: Session): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get a session by thread ID.
|
|
54
|
+
*/
|
|
55
|
+
get(threadId: string): Promise<Session | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Update session's last activity timestamp.
|
|
58
|
+
*/
|
|
59
|
+
touch(threadId: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Delete a session.
|
|
62
|
+
*/
|
|
63
|
+
delete(threadId: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* List sessions, optionally filtered by user ID.
|
|
66
|
+
*/
|
|
67
|
+
list(options?: {
|
|
68
|
+
userId?: string;
|
|
69
|
+
limit?: number;
|
|
70
|
+
}): Promise<Session[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Delete expired sessions (older than specified hours).
|
|
73
|
+
*/
|
|
74
|
+
deleteExpired(maxAgeHours?: number): Promise<number>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firestore Store for LangGraph
|
|
3
|
+
*
|
|
4
|
+
* Custom implementation of BaseStore using Firebase Firestore.
|
|
5
|
+
* This provides persistent key-value storage for agent memories.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: This module does NOT import firebase-admin directly.
|
|
8
|
+
* The Firestore `db` instance must be injected via constructor options.
|
|
9
|
+
*/
|
|
10
|
+
import { BaseStore, type Operation, type OperationResults } from '@langchain/langgraph-checkpoint';
|
|
11
|
+
import type { FirestoreDb } from './firestore-checkpointer.js';
|
|
12
|
+
/**
|
|
13
|
+
* Options for FirestoreStore.
|
|
14
|
+
*/
|
|
15
|
+
export interface FirestoreStoreOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Firestore instance. Required — injected by consumer.
|
|
18
|
+
*/
|
|
19
|
+
db: FirestoreDb;
|
|
20
|
+
/**
|
|
21
|
+
* Collection name for store items.
|
|
22
|
+
* @default 'agent_memories'
|
|
23
|
+
*/
|
|
24
|
+
collection?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Firestore-backed store for LangGraph agent memories.
|
|
28
|
+
*
|
|
29
|
+
* Provides persistent key-value storage that can be shared across threads.
|
|
30
|
+
* Items are organized by hierarchical namespaces.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { getFirestore } from 'firebase-admin/firestore';
|
|
35
|
+
*
|
|
36
|
+
* const store = new FirestoreStore({
|
|
37
|
+
* db: getFirestore(),
|
|
38
|
+
* collection: 'agent_memories',
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Store a memory
|
|
42
|
+
* await store.put(['agent', 'patterns'], 'schema-best-practices', {
|
|
43
|
+
* content: 'Always validate schemas before saving',
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Retrieve a memory
|
|
47
|
+
* const item = await store.get(['agent', 'patterns'], 'schema-best-practices');
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare class FirestoreStore extends BaseStore {
|
|
51
|
+
private db;
|
|
52
|
+
private collection;
|
|
53
|
+
constructor(options: FirestoreStoreOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Create document ID from namespace and key.
|
|
56
|
+
*/
|
|
57
|
+
private makeDocId;
|
|
58
|
+
/**
|
|
59
|
+
* Create namespace key for querying.
|
|
60
|
+
*/
|
|
61
|
+
private makeNamespaceKey;
|
|
62
|
+
/**
|
|
63
|
+
* Execute multiple operations in a batch.
|
|
64
|
+
*/
|
|
65
|
+
batch<Op extends Operation[]>(operations: Op): Promise<OperationResults<Op>>;
|
|
66
|
+
/**
|
|
67
|
+
* Get an item by namespace and key.
|
|
68
|
+
*/
|
|
69
|
+
private getItem;
|
|
70
|
+
/**
|
|
71
|
+
* Put an item.
|
|
72
|
+
*/
|
|
73
|
+
private putItem;
|
|
74
|
+
/**
|
|
75
|
+
* Delete an item.
|
|
76
|
+
*/
|
|
77
|
+
private deleteItem;
|
|
78
|
+
/**
|
|
79
|
+
* Search for items.
|
|
80
|
+
*/
|
|
81
|
+
private searchItems;
|
|
82
|
+
/**
|
|
83
|
+
* List namespaces.
|
|
84
|
+
*/
|
|
85
|
+
private listNamespacesItems;
|
|
86
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence Module
|
|
3
|
+
*
|
|
4
|
+
* Pluggable persistence backends for agent sessions, checkpoints, and memory.
|
|
5
|
+
*/
|
|
6
|
+
export type { SessionMetadata, SessionRecord, PersistenceMode, Session, } from './types.js';
|
|
7
|
+
export { MemorySessionBackend } from './memory-backend.js';
|
|
8
|
+
export { FirestoreCheckpointer, type FirestoreCheckpointerOptions, type FirestoreDb, type FirestoreTimestamp, } from './firestore-checkpointer.js';
|
|
9
|
+
export { FirestoreSessionStore, type FirestoreSessionStoreOptions, } from './firestore-session-store.js';
|
|
10
|
+
export { FirestoreStore, type FirestoreStoreOptions, } from './firestore-store.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Persistence Backend
|
|
3
|
+
*
|
|
4
|
+
* Provides in-memory session metadata storage for development.
|
|
5
|
+
* Data is lost on process restart.
|
|
6
|
+
*/
|
|
7
|
+
import type { SessionMetadata, SessionRecord } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* In-memory session metadata store.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MemorySessionBackend {
|
|
12
|
+
private sessions;
|
|
13
|
+
/**
|
|
14
|
+
* Store session metadata.
|
|
15
|
+
*/
|
|
16
|
+
store(threadId: string, metadata: SessionMetadata): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get session metadata.
|
|
19
|
+
*/
|
|
20
|
+
get(threadId: string): SessionMetadata | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Delete session metadata.
|
|
23
|
+
*/
|
|
24
|
+
delete(threadId: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* List all sessions.
|
|
27
|
+
*/
|
|
28
|
+
list(): SessionRecord[];
|
|
29
|
+
/**
|
|
30
|
+
* Check if a session exists.
|
|
31
|
+
*/
|
|
32
|
+
has(threadId: string): boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence Types
|
|
3
|
+
*
|
|
4
|
+
* Interfaces for pluggable persistence backends.
|
|
5
|
+
* Consumers provide implementations (memory, Firestore, etc.)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Session metadata stored by any backend.
|
|
9
|
+
*/
|
|
10
|
+
export interface SessionMetadata {
|
|
11
|
+
skill: string;
|
|
12
|
+
workDir: string;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
lastActivityAt: number;
|
|
15
|
+
/** If true, auto-approve all future interrupts without user interaction */
|
|
16
|
+
approveAll?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Session record with thread ID (for listing).
|
|
20
|
+
*/
|
|
21
|
+
export interface SessionRecord extends SessionMetadata {
|
|
22
|
+
threadId: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Persistence mode for agent sessions.
|
|
26
|
+
* - 'memory': In-memory storage (default, lost on restart)
|
|
27
|
+
* - 'firestore': Firestore-backed storage (persistent)
|
|
28
|
+
*/
|
|
29
|
+
export type PersistenceMode = 'memory' | 'firestore';
|
|
30
|
+
/**
|
|
31
|
+
* Session data for Firestore storage.
|
|
32
|
+
*/
|
|
33
|
+
export interface Session {
|
|
34
|
+
threadId: string;
|
|
35
|
+
skill: string;
|
|
36
|
+
workDir: string;
|
|
37
|
+
userId?: string;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
lastActivityAt: Date;
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuditLog — Hash-chained append-only audit ledger.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript port of saezbaldo/ic-agi `ic_agi/audit_log.py`.
|
|
5
|
+
* See: https://github.com/saezbaldo/ic-agi
|
|
6
|
+
*
|
|
7
|
+
* Each entry is cryptographically linked to the previous one via
|
|
8
|
+
* SHA-256 chaining. Any tampering with historical entries will
|
|
9
|
+
* break chain verification.
|
|
10
|
+
*/
|
|
11
|
+
export interface AuditEntry {
|
|
12
|
+
/** Zero-based position in the chain. */
|
|
13
|
+
index: number;
|
|
14
|
+
/** Unix epoch seconds — set by append(), never caller-supplied. */
|
|
15
|
+
timestamp: number;
|
|
16
|
+
/** Arbitrary event data. */
|
|
17
|
+
data: Record<string, unknown>;
|
|
18
|
+
/** SHA-256 of the previous entry (or GENESIS_HASH for the first entry). */
|
|
19
|
+
prevHash: string;
|
|
20
|
+
/** SHA-256 of this entry's canonical form. */
|
|
21
|
+
entryHash: string;
|
|
22
|
+
}
|
|
23
|
+
export declare class AuditLog {
|
|
24
|
+
private entries;
|
|
25
|
+
/**
|
|
26
|
+
* Append a new entry to the chain.
|
|
27
|
+
* The timestamp is set here — callers cannot supply it.
|
|
28
|
+
*/
|
|
29
|
+
append(data: Record<string, unknown>): AuditEntry;
|
|
30
|
+
/**
|
|
31
|
+
* Verify the integrity of the entire chain.
|
|
32
|
+
* Recomputes every entry hash and checks chain linkage.
|
|
33
|
+
* Returns false immediately on the first mismatch.
|
|
34
|
+
*/
|
|
35
|
+
verify(): boolean;
|
|
36
|
+
/** Return entries, optionally filtered by source, event type, or count limit. */
|
|
37
|
+
getEntries(filter?: {
|
|
38
|
+
source?: string;
|
|
39
|
+
event?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}): AuditEntry[];
|
|
42
|
+
getEntry(index: number): AuditEntry | undefined;
|
|
43
|
+
get length(): number;
|
|
44
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Synchronization Support - GAP-010
|
|
3
|
+
*
|
|
4
|
+
* Provides agent-side support for real-time state synchronization.
|
|
5
|
+
* The actual transport (WebSocket/SSE) is handled by @almadar/server.
|
|
6
|
+
*
|
|
7
|
+
* This module provides:
|
|
8
|
+
* - State change notifications
|
|
9
|
+
* - Conflict resolution utilities
|
|
10
|
+
* - State serialization for sync
|
|
11
|
+
* - Event emitters for server integration
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { EventEmitter } from 'events';
|
|
16
|
+
import type { Checkpoint } from '@langchain/langgraph-checkpoint';
|
|
17
|
+
/**
|
|
18
|
+
* State change event types
|
|
19
|
+
*/
|
|
20
|
+
export type StateChangeType = 'checkpoint_created' | 'checkpoint_updated' | 'session_started' | 'session_ended' | 'tool_executed' | 'memory_updated' | 'interrupt_triggered' | 'interrupt_resolved';
|
|
21
|
+
/**
|
|
22
|
+
* State change event
|
|
23
|
+
*/
|
|
24
|
+
export interface StateChangeEvent {
|
|
25
|
+
/** Change type */
|
|
26
|
+
type: StateChangeType;
|
|
27
|
+
/** Thread/session ID */
|
|
28
|
+
threadId: string;
|
|
29
|
+
/** User ID */
|
|
30
|
+
userId?: string;
|
|
31
|
+
/** Timestamp */
|
|
32
|
+
timestamp: number;
|
|
33
|
+
/** Change payload */
|
|
34
|
+
payload: Record<string, unknown>;
|
|
35
|
+
/** Version vector for conflict resolution */
|
|
36
|
+
version: VersionVector;
|
|
37
|
+
/** Source client ID */
|
|
38
|
+
sourceClientId?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Version vector for conflict resolution
|
|
42
|
+
*/
|
|
43
|
+
export interface VersionVector {
|
|
44
|
+
/** Logical timestamp */
|
|
45
|
+
timestamp: number;
|
|
46
|
+
/** Sequence number */
|
|
47
|
+
sequence: number;
|
|
48
|
+
/** Node/client ID */
|
|
49
|
+
nodeId: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sync state snapshot
|
|
53
|
+
*/
|
|
54
|
+
export interface StateSyncSnapshot {
|
|
55
|
+
/** Thread ID */
|
|
56
|
+
threadId: string;
|
|
57
|
+
/** Current checkpoint */
|
|
58
|
+
checkpoint?: Checkpoint;
|
|
59
|
+
/** Session metadata */
|
|
60
|
+
sessionMetadata?: Record<string, unknown>;
|
|
61
|
+
/** Memory state */
|
|
62
|
+
memoryState?: Record<string, unknown>;
|
|
63
|
+
/** Version vector */
|
|
64
|
+
version: VersionVector;
|
|
65
|
+
/** Last updated */
|
|
66
|
+
lastUpdated: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Conflict resolution result
|
|
70
|
+
*/
|
|
71
|
+
export interface ConflictResolution {
|
|
72
|
+
/** Whether conflict was resolved */
|
|
73
|
+
resolved: boolean;
|
|
74
|
+
/** Winning state if resolved */
|
|
75
|
+
winningState?: StateSyncSnapshot;
|
|
76
|
+
/** Conflicting changes if not resolved */
|
|
77
|
+
conflicts?: Array<{
|
|
78
|
+
clientA: StateChangeEvent;
|
|
79
|
+
clientB: StateChangeEvent;
|
|
80
|
+
}>;
|
|
81
|
+
/** Resolution strategy used */
|
|
82
|
+
strategy: 'last_write_wins' | 'merge' | 'manual';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sync configuration
|
|
86
|
+
*/
|
|
87
|
+
export interface StateSyncConfig {
|
|
88
|
+
/** Enable sync */
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
/** Conflict resolution strategy */
|
|
91
|
+
conflictStrategy: 'last_write_wins' | 'merge' | 'manual';
|
|
92
|
+
/** Throttle interval (ms) */
|
|
93
|
+
throttleInterval: number;
|
|
94
|
+
/** Max retry attempts */
|
|
95
|
+
maxRetries: number;
|
|
96
|
+
/** Client ID */
|
|
97
|
+
clientId: string;
|
|
98
|
+
}
|
|
99
|
+
export declare class StateSyncManager extends EventEmitter {
|
|
100
|
+
private config;
|
|
101
|
+
private sequenceNumber;
|
|
102
|
+
private pendingChanges;
|
|
103
|
+
private throttleTimer;
|
|
104
|
+
constructor(config?: Partial<StateSyncConfig>);
|
|
105
|
+
/**
|
|
106
|
+
* Notify that state has changed (called by agent internals)
|
|
107
|
+
*/
|
|
108
|
+
notifyStateChange(type: StateChangeType, threadId: string, payload: Record<string, unknown>, userId?: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Receive state change from server (called by server transport)
|
|
111
|
+
*/
|
|
112
|
+
receiveRemoteChange(event: StateChangeEvent): void;
|
|
113
|
+
/**
|
|
114
|
+
* Create sync snapshot for current state
|
|
115
|
+
*/
|
|
116
|
+
createSnapshot(threadId: string, state: {
|
|
117
|
+
checkpoint?: Checkpoint;
|
|
118
|
+
sessionMetadata?: Record<string, unknown>;
|
|
119
|
+
memoryState?: Record<string, unknown>;
|
|
120
|
+
}): StateSyncSnapshot;
|
|
121
|
+
/**
|
|
122
|
+
* Compare two version vectors
|
|
123
|
+
* Returns: -1 if a < b, 0 if concurrent/equal, 1 if a > b
|
|
124
|
+
*/
|
|
125
|
+
compareVersions(a: VersionVector, b: VersionVector): number;
|
|
126
|
+
/**
|
|
127
|
+
* Check if there are pending changes to sync
|
|
128
|
+
*/
|
|
129
|
+
hasPendingChanges(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Get and clear pending changes
|
|
132
|
+
*/
|
|
133
|
+
flushPendingChanges(): StateChangeEvent[];
|
|
134
|
+
/**
|
|
135
|
+
* Get sync configuration
|
|
136
|
+
*/
|
|
137
|
+
getConfig(): StateSyncConfig;
|
|
138
|
+
/**
|
|
139
|
+
* Update sync configuration
|
|
140
|
+
*/
|
|
141
|
+
updateConfig(config: Partial<StateSyncConfig>): void;
|
|
142
|
+
/**
|
|
143
|
+
* Dispose resources
|
|
144
|
+
*/
|
|
145
|
+
dispose(): void;
|
|
146
|
+
private generateClientId;
|
|
147
|
+
private createVersionVector;
|
|
148
|
+
private scheduleSync;
|
|
149
|
+
private findConflicts;
|
|
150
|
+
private resolveConflicts;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get or create global state sync manager
|
|
154
|
+
*/
|
|
155
|
+
export declare function getStateSyncManager(config?: Partial<StateSyncConfig>): StateSyncManager;
|
|
156
|
+
/**
|
|
157
|
+
* Reset global state sync manager
|
|
158
|
+
*/
|
|
159
|
+
export declare function resetStateSyncManager(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Create a synchronized wrapper for session operations
|
|
162
|
+
*/
|
|
163
|
+
export declare function withSync<T extends (...args: unknown[]) => unknown>(fn: T, syncManager: StateSyncManager, options: {
|
|
164
|
+
threadId: string;
|
|
165
|
+
type: StateChangeType;
|
|
166
|
+
getPayload: (...args: unknown[]) => Record<string, unknown>;
|
|
167
|
+
}): T;
|
|
168
|
+
/**
|
|
169
|
+
* Debounce sync notifications
|
|
170
|
+
*/
|
|
171
|
+
export declare function debounceSync(syncManager: StateSyncManager, delay?: number): (type: StateChangeType, threadId: string, payload: Record<string, unknown>) => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KFlow DeepAgent Subagents
|
|
3
|
+
*
|
|
4
|
+
* Specialized subagents for complex schema generation tasks.
|
|
5
|
+
* These are spawned via the `task()` built-in tool.
|
|
6
|
+
*
|
|
7
|
+
* Uses @almadar/skills for schema reference documentation.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { SubAgent } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create the Schema Generator Subagent configuration.
|
|
14
|
+
*
|
|
15
|
+
* Focused agent for generating KFlow schemas from requirements.
|
|
16
|
+
* Writes schema to file and verifies it exists.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSchemaGeneratorSubagent(): SubAgent;
|
|
19
|
+
/**
|
|
20
|
+
* Create the Error Fixer Subagent configuration.
|
|
21
|
+
*
|
|
22
|
+
* Focused agent for fixing validation and compilation errors.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createErrorFixerSubagent(): SubAgent;
|
|
25
|
+
/**
|
|
26
|
+
* Create the Test Analyzer Subagent configuration.
|
|
27
|
+
*
|
|
28
|
+
* Focused agent for analyzing test failures and suggesting fixes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createTestAnalyzerSubagent(): SubAgent;
|
|
31
|
+
/**
|
|
32
|
+
* Create all subagent configurations.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSubagents(): SubAgent[];
|
|
35
|
+
/**
|
|
36
|
+
* Create subagent configs as a record for easy lookup.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createSubagentConfigs(): Record<string, SubAgent>;
|