@honeybee-ai/incubator 1.0.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.
Potentially problematic release.
This version of @honeybee-ai/incubator might be problematic. Click here for more details.
- package/README.md +586 -0
- package/dashboard/dist/assets/index-CVqcfjV3.js +9 -0
- package/dashboard/dist/assets/index-CyFMIiFl.css +1 -0
- package/dashboard/dist/index.html +13 -0
- package/dist/agent/prompt.d.ts +70 -0
- package/dist/agent/prompt.js +165 -0
- package/dist/agent/prompt.js.map +1 -0
- package/dist/agent/providers.d.ts +6 -0
- package/dist/agent/providers.js +320 -0
- package/dist/agent/providers.js.map +1 -0
- package/dist/agent/runner.d.ts +22 -0
- package/dist/agent/runner.js +282 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/test-helpers.d.ts +11 -0
- package/dist/agent/test-helpers.js +63 -0
- package/dist/agent/test-helpers.js.map +1 -0
- package/dist/agent/tools.d.ts +4 -0
- package/dist/agent/tools.js +545 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/types.d.ts +54 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/bus.d.ts +24 -0
- package/dist/bus.js +79 -0
- package/dist/bus.js.map +1 -0
- package/dist/guard.d.ts +44 -0
- package/dist/guard.js +178 -0
- package/dist/guard.js.map +1 -0
- package/dist/heartbeat.d.ts +41 -0
- package/dist/heartbeat.js +104 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/honeycomb.d.ts +49 -0
- package/dist/honeycomb.js +176 -0
- package/dist/honeycomb.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +371 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/config.d.ts +14 -0
- package/dist/integrations/config.js +48 -0
- package/dist/integrations/config.js.map +1 -0
- package/dist/integrations/index.d.ts +4 -0
- package/dist/integrations/index.js +4 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/loader.d.ts +8 -0
- package/dist/integrations/loader.js +27 -0
- package/dist/integrations/loader.js.map +1 -0
- package/dist/integrations/manager.d.ts +29 -0
- package/dist/integrations/manager.js +108 -0
- package/dist/integrations/manager.js.map +1 -0
- package/dist/namespaces.d.ts +25 -0
- package/dist/namespaces.js +84 -0
- package/dist/namespaces.js.map +1 -0
- package/dist/persistence.d.ts +7 -0
- package/dist/persistence.js +62 -0
- package/dist/persistence.js.map +1 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +5 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/parser.d.ts +31 -0
- package/dist/protocol/parser.js +193 -0
- package/dist/protocol/parser.js.map +1 -0
- package/dist/protocol/renderer.d.ts +16 -0
- package/dist/protocol/renderer.js +193 -0
- package/dist/protocol/renderer.js.map +1 -0
- package/dist/protocol/schema.d.ts +341 -0
- package/dist/protocol/schema.js +285 -0
- package/dist/protocol/schema.js.map +1 -0
- package/dist/protocol/types.d.ts +144 -0
- package/dist/protocol/types.js +8 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/variables.d.ts +22 -0
- package/dist/protocol/variables.js +58 -0
- package/dist/protocol/variables.js.map +1 -0
- package/dist/rest.d.ts +3 -0
- package/dist/rest.js +794 -0
- package/dist/rest.js.map +1 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +410 -0
- package/dist/server.js.map +1 -0
- package/dist/stores/backend.d.ts +15 -0
- package/dist/stores/backend.js +28 -0
- package/dist/stores/backend.js.map +1 -0
- package/dist/stores/claims.d.ts +14 -0
- package/dist/stores/claims.js +77 -0
- package/dist/stores/claims.js.map +1 -0
- package/dist/stores/conflicts.d.ts +10 -0
- package/dist/stores/conflicts.js +39 -0
- package/dist/stores/conflicts.js.map +1 -0
- package/dist/stores/control.d.ts +37 -0
- package/dist/stores/control.js +105 -0
- package/dist/stores/control.js.map +1 -0
- package/dist/stores/discoveries.d.ts +11 -0
- package/dist/stores/discoveries.js +45 -0
- package/dist/stores/discoveries.js.map +1 -0
- package/dist/stores/events.d.ts +14 -0
- package/dist/stores/events.js +37 -0
- package/dist/stores/events.js.map +1 -0
- package/dist/stores/help.d.ts +11 -0
- package/dist/stores/help.js +46 -0
- package/dist/stores/help.js.map +1 -0
- package/dist/stores/interfaces.d.ts +87 -0
- package/dist/stores/interfaces.js +2 -0
- package/dist/stores/interfaces.js.map +1 -0
- package/dist/stores/messages.d.ts +8 -0
- package/dist/stores/messages.js +29 -0
- package/dist/stores/messages.js.map +1 -0
- package/dist/stores/progress.d.ts +8 -0
- package/dist/stores/progress.js +21 -0
- package/dist/stores/progress.js.map +1 -0
- package/dist/stores/proposals.d.ts +11 -0
- package/dist/stores/proposals.js +46 -0
- package/dist/stores/proposals.js.map +1 -0
- package/dist/stores/redis/claims.d.ts +15 -0
- package/dist/stores/redis/claims.js +96 -0
- package/dist/stores/redis/claims.js.map +1 -0
- package/dist/stores/redis/db.d.ts +39 -0
- package/dist/stores/redis/db.js +34 -0
- package/dist/stores/redis/db.js.map +1 -0
- package/dist/stores/redis/discoveries.d.ts +13 -0
- package/dist/stores/redis/discoveries.js +54 -0
- package/dist/stores/redis/discoveries.js.map +1 -0
- package/dist/stores/redis/events.d.ts +17 -0
- package/dist/stores/redis/events.js +57 -0
- package/dist/stores/redis/events.js.map +1 -0
- package/dist/stores/redis/index.d.ts +3 -0
- package/dist/stores/redis/index.js +29 -0
- package/dist/stores/redis/index.js.map +1 -0
- package/dist/stores/redis/state.d.ts +14 -0
- package/dist/stores/redis/state.js +83 -0
- package/dist/stores/redis/state.js.map +1 -0
- package/dist/stores/reinforcements.d.ts +11 -0
- package/dist/stores/reinforcements.js +42 -0
- package/dist/stores/reinforcements.js.map +1 -0
- package/dist/stores/roles.d.ts +9 -0
- package/dist/stores/roles.js +22 -0
- package/dist/stores/roles.js.map +1 -0
- package/dist/stores/sqlite/claims.d.ts +17 -0
- package/dist/stores/sqlite/claims.js +121 -0
- package/dist/stores/sqlite/claims.js.map +1 -0
- package/dist/stores/sqlite/db.d.ts +16 -0
- package/dist/stores/sqlite/db.js +77 -0
- package/dist/stores/sqlite/db.js.map +1 -0
- package/dist/stores/sqlite/discoveries.d.ts +14 -0
- package/dist/stores/sqlite/discoveries.js +66 -0
- package/dist/stores/sqlite/discoveries.js.map +1 -0
- package/dist/stores/sqlite/events.d.ts +16 -0
- package/dist/stores/sqlite/events.js +75 -0
- package/dist/stores/sqlite/events.js.map +1 -0
- package/dist/stores/sqlite/index.d.ts +2 -0
- package/dist/stores/sqlite/index.js +31 -0
- package/dist/stores/sqlite/index.js.map +1 -0
- package/dist/stores/sqlite/state.d.ts +15 -0
- package/dist/stores/sqlite/state.js +99 -0
- package/dist/stores/sqlite/state.js.map +1 -0
- package/dist/stores/state.d.ts +11 -0
- package/dist/stores/state.js +67 -0
- package/dist/stores/state.js.map +1 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +20 -0
- package/dist/utils.js.map +1 -0
- package/dist/ws.d.ts +25 -0
- package/dist/ws.js +117 -0
- package/dist/ws.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { matchGlob, isExpired } from '../utils.js';
|
|
2
|
+
export class ClaimStore {
|
|
3
|
+
claims = new Map();
|
|
4
|
+
eventStore;
|
|
5
|
+
constructor(eventStore) {
|
|
6
|
+
this.eventStore = eventStore;
|
|
7
|
+
}
|
|
8
|
+
async claim(resource, value, agentId, ttlMs) {
|
|
9
|
+
const existing = this.claims.get(resource);
|
|
10
|
+
// If there's an active, non-expired claim by someone else, reject
|
|
11
|
+
if (existing && existing.status === 'active' && !isExpired(existing.claimedAt, existing.ttlMs)) {
|
|
12
|
+
if (existing.owner !== agentId) {
|
|
13
|
+
return { status: 'rejected', claim: existing };
|
|
14
|
+
}
|
|
15
|
+
// Same owner re-claiming: update value/ttl
|
|
16
|
+
existing.value = value;
|
|
17
|
+
existing.ttlMs = ttlMs;
|
|
18
|
+
return { status: 'approved', claim: existing };
|
|
19
|
+
}
|
|
20
|
+
const claim = {
|
|
21
|
+
resource,
|
|
22
|
+
value,
|
|
23
|
+
owner: agentId,
|
|
24
|
+
status: 'active',
|
|
25
|
+
claimedAt: new Date().toISOString(),
|
|
26
|
+
ttlMs,
|
|
27
|
+
};
|
|
28
|
+
this.claims.set(resource, claim);
|
|
29
|
+
await this.eventStore.publish('claim.acquired', { resource, value, owner: agentId }, agentId);
|
|
30
|
+
return { status: 'approved', claim };
|
|
31
|
+
}
|
|
32
|
+
async release(resource, agentId) {
|
|
33
|
+
const claim = this.claims.get(resource);
|
|
34
|
+
if (!claim || claim.status !== 'active')
|
|
35
|
+
return null;
|
|
36
|
+
// Only the owner can release
|
|
37
|
+
if (claim.owner !== agentId)
|
|
38
|
+
return null;
|
|
39
|
+
claim.status = 'released';
|
|
40
|
+
await this.eventStore.publish('claim.released', { resource, owner: agentId }, agentId);
|
|
41
|
+
return claim;
|
|
42
|
+
}
|
|
43
|
+
async check(resource) {
|
|
44
|
+
const claim = this.claims.get(resource);
|
|
45
|
+
if (!claim)
|
|
46
|
+
return null;
|
|
47
|
+
if (claim.status === 'active' && isExpired(claim.claimedAt, claim.ttlMs)) {
|
|
48
|
+
claim.status = 'expired';
|
|
49
|
+
}
|
|
50
|
+
return claim;
|
|
51
|
+
}
|
|
52
|
+
async list(pattern) {
|
|
53
|
+
const results = [];
|
|
54
|
+
for (const claim of this.claims.values()) {
|
|
55
|
+
if (claim.status === 'active' && isExpired(claim.claimedAt, claim.ttlMs)) {
|
|
56
|
+
claim.status = 'expired';
|
|
57
|
+
}
|
|
58
|
+
if (claim.status !== 'active')
|
|
59
|
+
continue;
|
|
60
|
+
if (pattern && !matchGlob(pattern, claim.resource))
|
|
61
|
+
continue;
|
|
62
|
+
results.push(claim);
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
// For persistence
|
|
67
|
+
async getAll() {
|
|
68
|
+
return [...this.claims.values()];
|
|
69
|
+
}
|
|
70
|
+
async load(claims) {
|
|
71
|
+
this.claims.clear();
|
|
72
|
+
for (const claim of claims) {
|
|
73
|
+
this.claims.set(claim.resource, claim);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.js","sourceRoot":"","sources":["../../src/stores/claims.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAInD,MAAM,OAAO,UAAU;IACb,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IAClC,UAAU,CAAc;IAEhC,YAAY,UAAuB;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,KAAa,EAAE,OAAe,EAAE,KAAc;QAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE3C,kEAAkE;QAClE,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/F,IAAI,QAAQ,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC/B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;YACjD,CAAC;YACD,2CAA2C;YAC3C,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;YACvB,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;YACvB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACjD,CAAC;QAED,MAAM,KAAK,GAAU;YACnB,QAAQ;YACR,KAAK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AG,SAAS,CAAC;QAC3B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAgB;QACzB,MAAM,OAAO,GAAY,EAAE,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;YAC3B,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ;gBAAE,SAAS;YACxC,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC;gBAAE,SAAS;YAC7D,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,kBAAkB;IAClB,KAAK,CAAC,MAAM;QACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAe;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Conflict } from '../types.js';
|
|
2
|
+
import type { IConflictStore, IEventStore } from './interfaces.js';
|
|
3
|
+
export declare class ConflictStore implements IConflictStore {
|
|
4
|
+
private conflicts;
|
|
5
|
+
private eventStore;
|
|
6
|
+
constructor(eventStore: IEventStore);
|
|
7
|
+
flag(agentId: string, discovery_a: string, discovery_b: string, reason: string): Promise<Conflict>;
|
|
8
|
+
resolve(conflictId: string, agentId: string, resolution: string): Promise<Conflict | null>;
|
|
9
|
+
list(status?: string): Promise<Conflict[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
export class ConflictStore {
|
|
3
|
+
conflicts = new Map();
|
|
4
|
+
eventStore;
|
|
5
|
+
constructor(eventStore) {
|
|
6
|
+
this.eventStore = eventStore;
|
|
7
|
+
}
|
|
8
|
+
async flag(agentId, discovery_a, discovery_b, reason) {
|
|
9
|
+
const conflict = {
|
|
10
|
+
id: randomBytes(8).toString('hex'),
|
|
11
|
+
flaggedBy: agentId,
|
|
12
|
+
discovery_a,
|
|
13
|
+
discovery_b,
|
|
14
|
+
reason,
|
|
15
|
+
status: 'open',
|
|
16
|
+
createdAt: new Date().toISOString(),
|
|
17
|
+
};
|
|
18
|
+
this.conflicts.set(conflict.id, conflict);
|
|
19
|
+
await this.eventStore.publish('conflict.flagged', { conflict_id: conflict.id, flagged_by: agentId, discovery_a, discovery_b }, agentId);
|
|
20
|
+
return conflict;
|
|
21
|
+
}
|
|
22
|
+
async resolve(conflictId, agentId, resolution) {
|
|
23
|
+
const conflict = this.conflicts.get(conflictId);
|
|
24
|
+
if (!conflict || conflict.status !== 'open')
|
|
25
|
+
return null;
|
|
26
|
+
conflict.status = 'resolved';
|
|
27
|
+
conflict.resolvedBy = agentId;
|
|
28
|
+
conflict.resolution = resolution;
|
|
29
|
+
await this.eventStore.publish('conflict.resolved', { conflict_id: conflictId, resolved_by: agentId, resolution }, agentId);
|
|
30
|
+
return conflict;
|
|
31
|
+
}
|
|
32
|
+
async list(status) {
|
|
33
|
+
const all = [...this.conflicts.values()];
|
|
34
|
+
if (!status)
|
|
35
|
+
return all;
|
|
36
|
+
return all.filter(c => c.status === status);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingUR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,CAAC,UAAU,GAAG,OAAO,CAAC;QAC9B,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;QACjC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3H,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAe;QACxB,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM;YAAE,OAAO,GAAG,CAAC;QACxB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IEventStore } from './interfaces.js';
|
|
2
|
+
export interface HaltInfo {
|
|
3
|
+
halted: true;
|
|
4
|
+
reason: string;
|
|
5
|
+
status: 'completed' | 'failed';
|
|
6
|
+
haltedBy: string;
|
|
7
|
+
haltedAt: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PauseInfo {
|
|
10
|
+
paused: true;
|
|
11
|
+
reason: string;
|
|
12
|
+
pausedBy: string;
|
|
13
|
+
pausedAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ControlStatus {
|
|
16
|
+
halted: boolean;
|
|
17
|
+
paused: boolean;
|
|
18
|
+
haltReason?: string;
|
|
19
|
+
haltStatus?: string;
|
|
20
|
+
pauseReason?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class ControlStore {
|
|
23
|
+
private protocolHalt;
|
|
24
|
+
private agentHalts;
|
|
25
|
+
private protocolPause;
|
|
26
|
+
private agentPauses;
|
|
27
|
+
private events;
|
|
28
|
+
constructor(events: IEventStore);
|
|
29
|
+
/** Halt the entire protocol or a specific agent */
|
|
30
|
+
halt(reason: string, haltedBy: string, status?: 'completed' | 'failed', target?: string): Promise<HaltInfo>;
|
|
31
|
+
/** Pause the entire protocol or a specific agent */
|
|
32
|
+
pause(reason: string, pausedBy: string, target?: string): Promise<PauseInfo>;
|
|
33
|
+
/** Resume a specific agent or the entire protocol */
|
|
34
|
+
resume(resumedBy: string, reason: string, target?: string): Promise<boolean>;
|
|
35
|
+
/** Check if an agent should stop (halted) or wait (paused) */
|
|
36
|
+
getStatus(agentId?: string): ControlStatus;
|
|
37
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export class ControlStore {
|
|
2
|
+
protocolHalt = null;
|
|
3
|
+
agentHalts = new Map();
|
|
4
|
+
protocolPause = null;
|
|
5
|
+
agentPauses = new Map();
|
|
6
|
+
events;
|
|
7
|
+
constructor(events) {
|
|
8
|
+
this.events = events;
|
|
9
|
+
}
|
|
10
|
+
/** Halt the entire protocol or a specific agent */
|
|
11
|
+
async halt(reason, haltedBy, status = 'completed', target) {
|
|
12
|
+
const info = {
|
|
13
|
+
halted: true,
|
|
14
|
+
reason,
|
|
15
|
+
status,
|
|
16
|
+
haltedBy,
|
|
17
|
+
haltedAt: new Date().toISOString(),
|
|
18
|
+
};
|
|
19
|
+
if (target) {
|
|
20
|
+
this.agentHalts.set(target, info);
|
|
21
|
+
await this.events.publish('agent.halted', { agent: target, reason, status, halted_by: haltedBy }, haltedBy);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.protocolHalt = info;
|
|
25
|
+
await this.events.publish('protocol.halt', { reason, status, halted_by: haltedBy }, haltedBy);
|
|
26
|
+
}
|
|
27
|
+
return info;
|
|
28
|
+
}
|
|
29
|
+
/** Pause the entire protocol or a specific agent */
|
|
30
|
+
async pause(reason, pausedBy, target) {
|
|
31
|
+
const info = {
|
|
32
|
+
paused: true,
|
|
33
|
+
reason,
|
|
34
|
+
pausedBy,
|
|
35
|
+
pausedAt: new Date().toISOString(),
|
|
36
|
+
};
|
|
37
|
+
if (target) {
|
|
38
|
+
this.agentPauses.set(target, info);
|
|
39
|
+
await this.events.publish('agent.paused', { agent: target, reason, paused_by: pausedBy }, pausedBy);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.protocolPause = info;
|
|
43
|
+
await this.events.publish('protocol.paused', { reason, paused_by: pausedBy }, pausedBy);
|
|
44
|
+
}
|
|
45
|
+
return info;
|
|
46
|
+
}
|
|
47
|
+
/** Resume a specific agent or the entire protocol */
|
|
48
|
+
async resume(resumedBy, reason, target) {
|
|
49
|
+
if (target) {
|
|
50
|
+
if (!this.agentPauses.has(target))
|
|
51
|
+
return false;
|
|
52
|
+
this.agentPauses.delete(target);
|
|
53
|
+
await this.events.publish('agent.resumed', { agent: target, reason, resumed_by: resumedBy }, resumedBy);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
if (!this.protocolPause)
|
|
58
|
+
return false;
|
|
59
|
+
this.protocolPause = null;
|
|
60
|
+
await this.events.publish('protocol.resumed', { reason, resumed_by: resumedBy }, resumedBy);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Check if an agent should stop (halted) or wait (paused) */
|
|
65
|
+
getStatus(agentId) {
|
|
66
|
+
// Protocol-wide halt takes priority
|
|
67
|
+
if (this.protocolHalt) {
|
|
68
|
+
return {
|
|
69
|
+
halted: true,
|
|
70
|
+
paused: false,
|
|
71
|
+
haltReason: this.protocolHalt.reason,
|
|
72
|
+
haltStatus: this.protocolHalt.status,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Per-agent halt
|
|
76
|
+
if (agentId && this.agentHalts.has(agentId)) {
|
|
77
|
+
const h = this.agentHalts.get(agentId);
|
|
78
|
+
return {
|
|
79
|
+
halted: true,
|
|
80
|
+
paused: false,
|
|
81
|
+
haltReason: h.reason,
|
|
82
|
+
haltStatus: h.status,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Protocol-wide pause
|
|
86
|
+
if (this.protocolPause) {
|
|
87
|
+
return {
|
|
88
|
+
halted: false,
|
|
89
|
+
paused: true,
|
|
90
|
+
pauseReason: this.protocolPause.reason,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Per-agent pause
|
|
94
|
+
if (agentId && this.agentPauses.has(agentId)) {
|
|
95
|
+
const p = this.agentPauses.get(agentId);
|
|
96
|
+
return {
|
|
97
|
+
halted: false,
|
|
98
|
+
paused: true,
|
|
99
|
+
pauseReason: p.reason,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return { halted: false, paused: false };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/stores/control.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,YAAY;IACf,YAAY,GAAoB,IAAI,CAAC;IACrC,UAAU,GAAG,IAAI,GAAG,EAAoB,CAAC;IACzC,aAAa,GAAqB,IAAI,CAAC;IACvC,WAAW,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC3C,MAAM,CAAc;IAE5B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,mDAAmD;IACnD,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,QAAgB,EAAE,SAAiC,WAAW,EAAE,MAAe;QACxG,MAAM,IAAI,GAAa;YACrB,MAAM,EAAE,IAAI;YACZ,MAAM;YACN,MAAM;YACN,QAAQ;YACR,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACnC,CAAC;QAEF,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAClC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,EAA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AAE,CAAC;YACvB,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,IAAI;gBACZ,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;aACvC,CAAC;QACJ,CAAC;QAED,kBAAkB;QAClB,IAAI,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;YACzC,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,IAAI;gBACZ,WAAW,EAAE,CAAC,CAAC,MAAM;aACtB,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Discovery } from '../types.js';
|
|
2
|
+
import type { IDiscoveryStore, IEventStore } from './interfaces.js';
|
|
3
|
+
export declare class DiscoveryStore implements IDiscoveryStore {
|
|
4
|
+
private discoveries;
|
|
5
|
+
private eventStore;
|
|
6
|
+
constructor(eventStore: IEventStore);
|
|
7
|
+
publish(topic: string, content: string, agentId: string, category?: string): Promise<Discovery>;
|
|
8
|
+
search(query?: string, category?: string): Promise<Discovery[]>;
|
|
9
|
+
getAll(): Promise<Discovery[]>;
|
|
10
|
+
load(discoveries: Discovery[]): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { generateId } from '../utils.js';
|
|
2
|
+
export class DiscoveryStore {
|
|
3
|
+
discoveries = [];
|
|
4
|
+
eventStore;
|
|
5
|
+
constructor(eventStore) {
|
|
6
|
+
this.eventStore = eventStore;
|
|
7
|
+
}
|
|
8
|
+
async publish(topic, content, agentId, category) {
|
|
9
|
+
const discovery = {
|
|
10
|
+
id: generateId(),
|
|
11
|
+
topic,
|
|
12
|
+
content,
|
|
13
|
+
category,
|
|
14
|
+
publishedBy: agentId,
|
|
15
|
+
publishedAt: new Date().toISOString(),
|
|
16
|
+
};
|
|
17
|
+
this.discoveries.push(discovery);
|
|
18
|
+
await this.eventStore.publish('discovery.published', {
|
|
19
|
+
id: discovery.id,
|
|
20
|
+
topic,
|
|
21
|
+
category,
|
|
22
|
+
}, agentId);
|
|
23
|
+
return discovery;
|
|
24
|
+
}
|
|
25
|
+
async search(query, category) {
|
|
26
|
+
let results = this.discoveries;
|
|
27
|
+
if (category) {
|
|
28
|
+
results = results.filter(d => d.category === category);
|
|
29
|
+
}
|
|
30
|
+
if (query) {
|
|
31
|
+
const lower = query.toLowerCase();
|
|
32
|
+
results = results.filter(d => d.topic.toLowerCase().includes(lower) ||
|
|
33
|
+
d.content.toLowerCase().includes(lower));
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
// For persistence
|
|
38
|
+
async getAll() {
|
|
39
|
+
return [...this.discoveries];
|
|
40
|
+
}
|
|
41
|
+
async load(discoveries) {
|
|
42
|
+
this.discoveries = discoveries;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=discoveries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discoveries.js","sourceRoot":"","sources":["../../src/stores/discoveries.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,cAAc;IACjB,WAAW,GAAgB,EAAE,CAAC;IAC9B,UAAU,CAAc;IAEhC,YAAY,UAAuB;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,OAAe,EAAE,OAAe,EAAE,QAAiB;QAC9E,MAAM,SAAS,GAAc;YAC3B,EAAE,EAAE,UAAU,EAAE;YAChB,KAAK;YACL,OAAO;YACP,QAAQ;YACR,WAAW,EAAE,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
export declare class EventStore implements IEventStore {
|
|
4
|
+
private events;
|
|
5
|
+
private cursor;
|
|
6
|
+
publish(type: string, data: unknown, agentId: string): Promise<IncubatorEvent>;
|
|
7
|
+
getEvents(since?: number, type?: string): Promise<{
|
|
8
|
+
events: IncubatorEvent[];
|
|
9
|
+
cursor: number;
|
|
10
|
+
}>;
|
|
11
|
+
getCursor(): Promise<number>;
|
|
12
|
+
getAll(): Promise<IncubatorEvent[]>;
|
|
13
|
+
load(events: IncubatorEvent[], cursor: number): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class EventStore {
|
|
2
|
+
events = [];
|
|
3
|
+
cursor = 0;
|
|
4
|
+
async publish(type, data, agentId) {
|
|
5
|
+
const event = {
|
|
6
|
+
id: ++this.cursor,
|
|
7
|
+
type,
|
|
8
|
+
data,
|
|
9
|
+
publishedBy: agentId,
|
|
10
|
+
publishedAt: new Date().toISOString(),
|
|
11
|
+
};
|
|
12
|
+
this.events.push(event);
|
|
13
|
+
return event;
|
|
14
|
+
}
|
|
15
|
+
async getEvents(since, type) {
|
|
16
|
+
let filtered = this.events;
|
|
17
|
+
if (since !== undefined) {
|
|
18
|
+
filtered = filtered.filter(e => e.id > since);
|
|
19
|
+
}
|
|
20
|
+
if (type) {
|
|
21
|
+
filtered = filtered.filter(e => e.type === type);
|
|
22
|
+
}
|
|
23
|
+
return { events: filtered, cursor: this.cursor };
|
|
24
|
+
}
|
|
25
|
+
async getCursor() {
|
|
26
|
+
return this.cursor;
|
|
27
|
+
}
|
|
28
|
+
// For persistence
|
|
29
|
+
async getAll() {
|
|
30
|
+
return [...this.events];
|
|
31
|
+
}
|
|
32
|
+
async load(events, cursor) {
|
|
33
|
+
this.events = events;
|
|
34
|
+
this.cursor = cursor;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"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QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HelpRequest } from '../types.js';
|
|
2
|
+
import type { IHelpStore, IEventStore } from './interfaces.js';
|
|
3
|
+
export declare class HelpStore implements IHelpStore {
|
|
4
|
+
private requests;
|
|
5
|
+
private eventStore;
|
|
6
|
+
constructor(eventStore: IEventStore);
|
|
7
|
+
request(from: string, problem: string, needs_capability?: string, urgency?: 'low' | 'normal' | 'high'): Promise<HelpRequest>;
|
|
8
|
+
claim(requestId: string, agentId: string): Promise<HelpRequest | null>;
|
|
9
|
+
resolve(requestId: string, agentId: string): Promise<HelpRequest | null>;
|
|
10
|
+
list(status?: string): Promise<HelpRequest[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
export class HelpStore {
|
|
3
|
+
requests = new Map();
|
|
4
|
+
eventStore;
|
|
5
|
+
constructor(eventStore) {
|
|
6
|
+
this.eventStore = eventStore;
|
|
7
|
+
}
|
|
8
|
+
async request(from, problem, needs_capability, urgency) {
|
|
9
|
+
const req = {
|
|
10
|
+
id: randomBytes(8).toString('hex'),
|
|
11
|
+
from,
|
|
12
|
+
problem,
|
|
13
|
+
needs_capability,
|
|
14
|
+
urgency: urgency ?? 'normal',
|
|
15
|
+
status: 'open',
|
|
16
|
+
createdAt: new Date().toISOString(),
|
|
17
|
+
};
|
|
18
|
+
this.requests.set(req.id, req);
|
|
19
|
+
await this.eventStore.publish('help.requested', { request_id: req.id, from, problem, needs_capability, urgency: req.urgency }, from);
|
|
20
|
+
return req;
|
|
21
|
+
}
|
|
22
|
+
async claim(requestId, agentId) {
|
|
23
|
+
const req = this.requests.get(requestId);
|
|
24
|
+
if (!req || req.status !== 'open')
|
|
25
|
+
return null;
|
|
26
|
+
req.status = 'claimed';
|
|
27
|
+
req.claimedBy = agentId;
|
|
28
|
+
await this.eventStore.publish('help.claimed', { request_id: requestId, claimed_by: agentId }, agentId);
|
|
29
|
+
return req;
|
|
30
|
+
}
|
|
31
|
+
async resolve(requestId, agentId) {
|
|
32
|
+
const req = this.requests.get(requestId);
|
|
33
|
+
if (!req || req.status !== 'claimed')
|
|
34
|
+
return null;
|
|
35
|
+
req.status = 'resolved';
|
|
36
|
+
await this.eventStore.publish('help.resolved', { request_id: requestId, resolved_by: agentId }, agentId);
|
|
37
|
+
return req;
|
|
38
|
+
}
|
|
39
|
+
async list(status) {
|
|
40
|
+
const all = [...this.requests.values()];
|
|
41
|
+
if (!status)
|
|
42
|
+
return all;
|
|
43
|
+
return all.filter(r => r.status === status);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/stores/help.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,SAAS;IACZ,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC1C,UAAU,CAAc;IAEhC,YAAY,UAAuB;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,OAAe,EAAE,gBAAyB,EAAE,OAAmC;QACzG,MAAM,GAAG,GAAgB;YACvB,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;YAClC,IAAI;YACJ,OAAO;YACP,gBAAgB;YAChB,OAAO,EAAE,OAAO,IAAI,QAAQ;YAC5B,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAC/B,MAAM,I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,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM;YAAE,OAAO,GAAG,CAAC;QACxB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { StateEntry, Claim, IncubatorEvent, Discovery, ClaimResult, Message, HelpRequest, ProgressReport, Conflict, RoleAssignment, ReinforcementRequest, Proposal } from '../types.js';
|
|
2
|
+
import type { ControlStore } from './control.js';
|
|
3
|
+
export interface IStateStore {
|
|
4
|
+
get(key: string): Promise<StateEntry | null>;
|
|
5
|
+
set(key: string, value: unknown, agentId: string, category?: string, ttlMs?: number): Promise<StateEntry>;
|
|
6
|
+
delete(key: string): Promise<boolean>;
|
|
7
|
+
query(pattern?: string, category?: string): Promise<StateEntry[]>;
|
|
8
|
+
getAll(): Promise<StateEntry[]>;
|
|
9
|
+
load(entries: StateEntry[]): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface IEventStore {
|
|
12
|
+
publish(type: string, data: unknown, agentId: string): Promise<IncubatorEvent>;
|
|
13
|
+
getEvents(since?: number, type?: string): Promise<{
|
|
14
|
+
events: IncubatorEvent[];
|
|
15
|
+
cursor: number;
|
|
16
|
+
}>;
|
|
17
|
+
getCursor(): Promise<number>;
|
|
18
|
+
getAll(): Promise<IncubatorEvent[]>;
|
|
19
|
+
load(events: IncubatorEvent[], cursor: number): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface IClaimStore {
|
|
22
|
+
claim(resource: string, value: string, agentId: string, ttlMs?: number): Promise<ClaimResult>;
|
|
23
|
+
release(resource: string, agentId: string): Promise<Claim | null>;
|
|
24
|
+
check(resource: string): Promise<Claim | null>;
|
|
25
|
+
list(pattern?: string): Promise<Claim[]>;
|
|
26
|
+
getAll(): Promise<Claim[]>;
|
|
27
|
+
load(claims: Claim[]): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export interface IDiscoveryStore {
|
|
30
|
+
publish(topic: string, content: string, agentId: string, category?: string): Promise<Discovery>;
|
|
31
|
+
search(query?: string, category?: string): Promise<Discovery[]>;
|
|
32
|
+
getAll(): Promise<Discovery[]>;
|
|
33
|
+
load(discoveries: Discovery[]): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface IMessageStore {
|
|
36
|
+
send(from: string, to: string, content: string, replyTo?: string): Promise<Message>;
|
|
37
|
+
getFor(agentId: string, since?: string): Promise<Message[]>;
|
|
38
|
+
getAll(): Promise<Message[]>;
|
|
39
|
+
}
|
|
40
|
+
export interface IHelpStore {
|
|
41
|
+
request(from: string, problem: string, needs_capability?: string, urgency?: 'low' | 'normal' | 'high'): Promise<HelpRequest>;
|
|
42
|
+
claim(requestId: string, agentId: string): Promise<HelpRequest | null>;
|
|
43
|
+
resolve(requestId: string, agentId: string): Promise<HelpRequest | null>;
|
|
44
|
+
list(status?: string): Promise<HelpRequest[]>;
|
|
45
|
+
}
|
|
46
|
+
export interface IProgressStore {
|
|
47
|
+
report(claim: string, agentId: string, progress: number, note?: string): Promise<ProgressReport>;
|
|
48
|
+
get(claim: string): Promise<ProgressReport | null>;
|
|
49
|
+
list(): Promise<ProgressReport[]>;
|
|
50
|
+
}
|
|
51
|
+
export interface IConflictStore {
|
|
52
|
+
flag(agentId: string, discovery_a: string, discovery_b: string, reason: string): Promise<Conflict>;
|
|
53
|
+
resolve(conflictId: string, agentId: string, resolution: string): Promise<Conflict | null>;
|
|
54
|
+
list(status?: string): Promise<Conflict[]>;
|
|
55
|
+
}
|
|
56
|
+
export interface IRoleStore {
|
|
57
|
+
assign(agentId: string, role: string): Promise<RoleAssignment>;
|
|
58
|
+
getAssignments(): Promise<RoleAssignment[]>;
|
|
59
|
+
getByAgent(agentId: string): Promise<RoleAssignment | null>;
|
|
60
|
+
remove(agentId: string): Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
export interface IProposalStore {
|
|
63
|
+
propose(agentId: string, action: string, detail?: string, quorum?: number): Promise<Proposal>;
|
|
64
|
+
endorse(proposalId: string, agentId: string): Promise<Proposal | null>;
|
|
65
|
+
list(status?: string): Promise<Proposal[]>;
|
|
66
|
+
get(proposalId: string): Promise<Proposal | null>;
|
|
67
|
+
}
|
|
68
|
+
export interface IReinforcementStore {
|
|
69
|
+
request(agentId: string, role: string, count: number, reason?: string): Promise<ReinforcementRequest>;
|
|
70
|
+
approve(requestId: string): Promise<ReinforcementRequest | null>;
|
|
71
|
+
deny(requestId: string, reason: string): Promise<ReinforcementRequest | null>;
|
|
72
|
+
list(): Promise<ReinforcementRequest[]>;
|
|
73
|
+
}
|
|
74
|
+
export interface Stores {
|
|
75
|
+
state: IStateStore;
|
|
76
|
+
events: IEventStore;
|
|
77
|
+
claims: IClaimStore;
|
|
78
|
+
discoveries: IDiscoveryStore;
|
|
79
|
+
messages: IMessageStore;
|
|
80
|
+
help: IHelpStore;
|
|
81
|
+
progress: IProgressStore;
|
|
82
|
+
conflicts: IConflictStore;
|
|
83
|
+
roles: IRoleStore;
|
|
84
|
+
proposals: IProposalStore;
|
|
85
|
+
reinforcements: IReinforcementStore;
|
|
86
|
+
control: ControlStore;
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/stores/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Message } from '../types.js';
|
|
2
|
+
import type { IMessageStore } from './interfaces.js';
|
|
3
|
+
export declare class MessageStore implements IMessageStore {
|
|
4
|
+
private messages;
|
|
5
|
+
send(from: string, to: string, content: string, replyTo?: string): Promise<Message>;
|
|
6
|
+
getFor(agentId: string, since?: string): Promise<Message[]>;
|
|
7
|
+
getAll(): Promise<Message[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
export class MessageStore {
|
|
3
|
+
messages = [];
|
|
4
|
+
async send(from, to, content, replyTo) {
|
|
5
|
+
const msg = {
|
|
6
|
+
id: randomBytes(8).toString('hex'),
|
|
7
|
+
from,
|
|
8
|
+
to,
|
|
9
|
+
content,
|
|
10
|
+
replyTo,
|
|
11
|
+
sentAt: new Date().toISOString(),
|
|
12
|
+
};
|
|
13
|
+
this.messages.push(msg);
|
|
14
|
+
return msg;
|
|
15
|
+
}
|
|
16
|
+
async getFor(agentId, since) {
|
|
17
|
+
return this.messages.filter(m => {
|
|
18
|
+
if (m.to !== agentId)
|
|
19
|
+
return false;
|
|
20
|
+
if (since && m.sentAt <= since)
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async getAll() {
|
|
26
|
+
return [...this.messages];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/stores/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,YAAY;IACf,QAAQ,GAAc,EAAE,CAAC;IAEjC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,EAAU,EAAE,OAAe,EAAE,OAAgB;QACpE,MAAM,GAAG,GAAY;YACnB,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;YAClC,IAAI;YACJ,EAAE;YACF,OAAO;YACP,OAAO;YACP,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACjC,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,KAAc;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;YAC9B,IAAI,CAAC,CAAC,EAAE,KAAK,OAAO;gBAAE,OAAO,KAAK,CAAC;YACnC,IAAI,KAAK,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK;gBAAE,OAAO,KAAK,CAAC;YAC7C,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProgressReport } from '../types.js';
|
|
2
|
+
import type { IProgressStore } from './interfaces.js';
|
|
3
|
+
export declare class ProgressStore implements IProgressStore {
|
|
4
|
+
private reports;
|
|
5
|
+
report(claim: string, agentId: string, progress: number, note?: string): Promise<ProgressReport>;
|
|
6
|
+
get(claim: string): Promise<ProgressReport | null>;
|
|
7
|
+
list(): Promise<ProgressReport[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class ProgressStore {
|
|
2
|
+
reports = new Map();
|
|
3
|
+
async report(claim, agentId, progress, note) {
|
|
4
|
+
const report = {
|
|
5
|
+
claim,
|
|
6
|
+
agent: agentId,
|
|
7
|
+
progress: Math.max(0, Math.min(1, progress)),
|
|
8
|
+
note,
|
|
9
|
+
updatedAt: new Date().toISOString(),
|
|
10
|
+
};
|
|
11
|
+
this.reports.set(claim, report);
|
|
12
|
+
return report;
|
|
13
|
+
}
|
|
14
|
+
async get(claim) {
|
|
15
|
+
return this.reports.get(claim) ?? null;
|
|
16
|
+
}
|
|
17
|
+
async list() {
|
|
18
|
+
return [...this.reports.values()];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/stores/progress.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAChB,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEpD,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAe,EAAE,QAAgB,EAAE,IAAa;QAC1E,MAAM,MAAM,GAAmB;YAC7B,KAAK;YACL,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC5C,IAAI;YACJ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
|