trellis 2.1.9 → 3.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/README.md +65 -796
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2948 -182
- package/dist/client/index.js +4 -4
- package/dist/context/heat-map-manager.d.ts +100 -0
- package/dist/context/heat-map-manager.d.ts.map +1 -0
- package/dist/context/manager.d.ts +16 -0
- package/dist/context/manager.d.ts.map +1 -0
- package/dist/context/types.d.ts +20 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/core/agents/harness.d.ts +10 -1
- package/dist/core/agents/harness.d.ts.map +1 -1
- package/dist/core/agents/types.d.ts +18 -2
- package/dist/core/agents/types.d.ts.map +1 -1
- package/dist/core/computation/expr-evaluator.d.ts +52 -0
- package/dist/core/computation/expr-evaluator.d.ts.map +1 -0
- package/dist/core/index.js +93 -5
- package/dist/core/kernel/logic-middleware.d.ts +19 -0
- package/dist/core/kernel/logic-middleware.d.ts.map +1 -0
- package/dist/core/kernel/schema-middleware.d.ts +15 -0
- package/dist/core/kernel/schema-middleware.d.ts.map +1 -0
- package/dist/core/kernel/security-middleware.d.ts +24 -0
- package/dist/core/kernel/security-middleware.d.ts.map +1 -0
- package/dist/core/kernel/sync-provider.d.ts +59 -0
- package/dist/core/kernel/sync-provider.d.ts.map +1 -0
- package/dist/core/kernel/trellis-kernel.d.ts +55 -0
- package/dist/core/kernel/trellis-kernel.d.ts.map +1 -1
- package/dist/core/ontology/builtins.d.ts.map +1 -1
- package/dist/core/ontology/core-ontology.d.ts +20 -0
- package/dist/core/ontology/core-ontology.d.ts.map +1 -0
- package/dist/core/ontology/index.d.ts +3 -1
- package/dist/core/ontology/index.d.ts.map +1 -1
- package/dist/core/ontology/types.d.ts +138 -34
- package/dist/core/ontology/types.d.ts.map +1 -1
- package/dist/core/persist/backend.d.ts +2 -0
- package/dist/core/persist/backend.d.ts.map +1 -1
- package/dist/core/persist/better-sqlite-backend.d.ts +33 -0
- package/dist/core/persist/better-sqlite-backend.d.ts.map +1 -0
- package/dist/core/persist/sqlite-backend.d.ts +2 -0
- package/dist/core/persist/sqlite-backend.d.ts.map +1 -1
- package/dist/core/store/eav-store.d.ts +4 -0
- package/dist/core/store/eav-store.d.ts.map +1 -1
- package/dist/db/index.js +10 -8
- package/dist/{deploy-99j5dc9c.js → deploy-999q207z.js} +2 -1
- package/dist/engine.d.ts +3 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/evals/types.d.ts +29 -0
- package/dist/evals/types.d.ts.map +1 -0
- package/dist/{import-fyg5sgq4.js → import-s2b8e0ft.js} +2 -2
- package/dist/{index-3ejh8k6v.js → index-0q7wbasy.js} +18 -4
- package/dist/{index-7t92ej34.js → index-0zk3fx2s.js} +467 -7
- package/dist/{index-xr7rx360.js → index-6n5dcebj.js} +33 -0
- package/dist/{index-4beszbgg.js → index-7e27kvvj.js} +1 -1
- package/dist/index-bmyt7k8n.js +90 -0
- package/dist/{index-k5kf7sd0.js → index-hmdbnd4n.js} +1 -1
- package/dist/{index-czecrvvn.js → index-q31hfjja.js} +858 -48
- package/dist/{index-8fjwnztt.js → index-skhn0agf.js} +1 -1
- package/dist/{index-04sq3h27.js → index-w7ng765c.js} +3 -1
- package/dist/{index-hgd30epa.js → index-wt8rz4gn.js} +4 -21
- package/dist/{index-5p6zgspx.js → index-y3d71wzd.js} +1 -1
- package/dist/index-y6a4kj0p.js +43 -0
- package/dist/{index-5bhe57y9.js → index-yhwjgfvj.js} +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/dist/llm/provider.d.ts +11 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/types.d.ts +74 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +7 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/orchestration/types.d.ts +22 -0
- package/dist/orchestration/types.d.ts.map +1 -0
- package/dist/plugins/agent-memory/graph-context-manager.d.ts +75 -0
- package/dist/plugins/agent-memory/graph-context-manager.d.ts.map +1 -0
- package/dist/plugins/agent-memory/index.d.ts +30 -0
- package/dist/plugins/agent-memory/index.d.ts.map +1 -0
- package/dist/plugins/agent-memory/ontology.d.ts +13 -0
- package/dist/plugins/agent-memory/ontology.d.ts.map +1 -0
- package/dist/plugins/agent-memory/plugin.d.ts +17 -0
- package/dist/plugins/agent-memory/plugin.d.ts.map +1 -0
- package/dist/plugins/brand/cache.d.ts +18 -0
- package/dist/plugins/brand/cache.d.ts.map +1 -0
- package/dist/plugins/brand/catalog-generator.d.ts +89 -0
- package/dist/plugins/brand/catalog-generator.d.ts.map +1 -0
- package/dist/plugins/brand/constraints.d.ts +55 -0
- package/dist/plugins/brand/constraints.d.ts.map +1 -0
- package/dist/plugins/brand/index.d.ts +44 -0
- package/dist/plugins/brand/index.d.ts.map +1 -0
- package/dist/plugins/brand/mcp-tools.d.ts +101 -0
- package/dist/plugins/brand/mcp-tools.d.ts.map +1 -0
- package/dist/plugins/brand/ontology.d.ts +13 -0
- package/dist/plugins/brand/ontology.d.ts.map +1 -0
- package/dist/plugins/brand/plugin.d.ts +21 -0
- package/dist/plugins/brand/plugin.d.ts.map +1 -0
- package/dist/plugins/brand/voice-tone.d.ts +24 -0
- package/dist/plugins/brand/voice-tone.d.ts.map +1 -0
- package/dist/plugins/idea-garden/api.d.ts +26 -0
- package/dist/plugins/idea-garden/api.d.ts.map +1 -0
- package/dist/plugins/idea-garden/index.d.ts +12 -0
- package/dist/plugins/idea-garden/index.d.ts.map +1 -0
- package/dist/plugins/idea-garden/plugin.d.ts +16 -0
- package/dist/plugins/idea-garden/plugin.d.ts.map +1 -0
- package/dist/plugins/idea-garden/types.d.ts +22 -0
- package/dist/plugins/idea-garden/types.d.ts.map +1 -0
- package/dist/plugins/plan-approval/index.d.ts +36 -0
- package/dist/plugins/plan-approval/index.d.ts.map +1 -0
- package/dist/plugins/plan-approval/ontology.d.ts +11 -0
- package/dist/plugins/plan-approval/ontology.d.ts.map +1 -0
- package/dist/plugins/plan-approval/plan-manager.d.ts +104 -0
- package/dist/plugins/plan-approval/plan-manager.d.ts.map +1 -0
- package/dist/plugins/plan-approval/plugin.d.ts +110 -0
- package/dist/plugins/plan-approval/plugin.d.ts.map +1 -0
- package/dist/plugins/proactive-watcher/index.d.ts +28 -0
- package/dist/plugins/proactive-watcher/index.d.ts.map +1 -0
- package/dist/plugins/proactive-watcher/ontology.d.ts +8 -0
- package/dist/plugins/proactive-watcher/ontology.d.ts.map +1 -0
- package/dist/plugins/proactive-watcher/plugin.d.ts +20 -0
- package/dist/plugins/proactive-watcher/plugin.d.ts.map +1 -0
- package/dist/plugins/proactive-watcher/watcher-manager.d.ts +36 -0
- package/dist/plugins/proactive-watcher/watcher-manager.d.ts.map +1 -0
- package/dist/plugins/sprite-tools/checkpoint-middleware.d.ts +43 -0
- package/dist/plugins/sprite-tools/checkpoint-middleware.d.ts.map +1 -0
- package/dist/plugins/sprite-tools/index.d.ts +40 -0
- package/dist/plugins/sprite-tools/index.d.ts.map +1 -0
- package/dist/plugins/sprite-tools/plugin.d.ts +69 -0
- package/dist/plugins/sprite-tools/plugin.d.ts.map +1 -0
- package/dist/react/index.js +4 -4
- package/dist/scaffold/index.d.ts +13 -0
- package/dist/scaffold/index.d.ts.map +1 -0
- package/dist/scaffold/infer.d.ts +42 -0
- package/dist/scaffold/infer.d.ts.map +1 -0
- package/dist/scaffold/profile.d.ts +51 -0
- package/dist/scaffold/profile.d.ts.map +1 -0
- package/dist/scaffold/seed.d.ts +27 -0
- package/dist/scaffold/seed.d.ts.map +1 -0
- package/dist/scaffold/write.d.ts +53 -0
- package/dist/scaffold/write.d.ts.map +1 -0
- package/dist/{sdk-sj8rp0m7.js → sdk-snn5gad3.js} +4 -4
- package/dist/server/deploy.d.ts.map +1 -1
- package/dist/server/index.d.ts +5 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +37 -7
- package/dist/server/sprites.d.ts +26 -0
- package/dist/server/sprites.d.ts.map +1 -0
- package/dist/server/vm-config.d.ts +60 -0
- package/dist/server/vm-config.d.ts.map +1 -0
- package/dist/{server-3vkpnpbz.js → server-mrctdwzr.js} +2 -2
- package/dist/sprites-vc4qbrp1.js +16 -0
- package/dist/streaming/types.d.ts +43 -0
- package/dist/streaming/types.d.ts.map +1 -0
- package/dist/{tenancy-tjr7kk2v.js → tenancy-7d1g4ayp.js} +3 -3
- package/dist/ui/client.html +460 -664
- package/dist/ui/server.d.ts +6 -2
- package/dist/ui/server.d.ts.map +1 -1
- package/dist/vcs/decompose.d.ts.map +1 -1
- package/dist/vcs/index.js +2 -2
- package/dist/vcs/issue.d.ts.map +1 -1
- package/dist/vcs/types.d.ts +1 -0
- package/dist/vcs/types.d.ts.map +1 -1
- package/dist/vm-config-6xhsj6b3.js +22 -0
- package/package.json +14 -4
- /package/dist/{index-kbnht9p8.js → index-c9h37r6h.js} +0 -0
package/dist/client/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import"../index-k5b0xskw.js";
|
|
|
3
3
|
import {
|
|
4
4
|
FetchError,
|
|
5
5
|
TrellisDb
|
|
6
|
-
} from "../index-
|
|
6
|
+
} from "../index-7e27kvvj.js";
|
|
7
7
|
import {
|
|
8
8
|
CONFIG_FILE,
|
|
9
9
|
configPath,
|
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
updateConfig,
|
|
14
14
|
writeConfig
|
|
15
15
|
} from "../index-xzym9w0m.js";
|
|
16
|
-
import"../index-
|
|
17
|
-
import"../index-
|
|
18
|
-
import"../index-
|
|
16
|
+
import"../index-y3d71wzd.js";
|
|
17
|
+
import"../index-0zk3fx2s.js";
|
|
18
|
+
import"../index-yhwjgfvj.js";
|
|
19
19
|
import"../index-yp88he8n.js";
|
|
20
20
|
import"../index-a76rekgs.js";
|
|
21
21
|
export {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heat-Map Context Manager — Relevance-weighted message retention.
|
|
3
|
+
*
|
|
4
|
+
* Replaces naive FIFO pruning with a heat-score system that considers:
|
|
5
|
+
* - Recency: newer messages score higher
|
|
6
|
+
* - Reference frequency: messages the LLM referenced score higher
|
|
7
|
+
* - Role priority: system messages are never pruned
|
|
8
|
+
*
|
|
9
|
+
* Heat scores decay each turn, and messages the model referenced get
|
|
10
|
+
* boosted. When pruning to a target token budget, lowest-heat messages
|
|
11
|
+
* are dropped first.
|
|
12
|
+
*
|
|
13
|
+
* @module trellis/context
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMMessage } from '../llm/types.js';
|
|
16
|
+
import type { ContextManager } from './types.js';
|
|
17
|
+
export interface HeatMapConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Decay multiplier applied to all heat scores each turn.
|
|
20
|
+
* Lower values = faster decay. Default: 0.85
|
|
21
|
+
*/
|
|
22
|
+
decayFactor?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Base heat score assigned to new messages.
|
|
25
|
+
* Default: 1.0
|
|
26
|
+
*/
|
|
27
|
+
baseHeat?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Heat boost applied when a message is referenced.
|
|
30
|
+
* Default: 0.5
|
|
31
|
+
*/
|
|
32
|
+
referenceBoost?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum heat score — messages below this during pruning are
|
|
35
|
+
* prioritized for removal. Default: 0.1
|
|
36
|
+
*/
|
|
37
|
+
pruneThreshold?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ScoredMessage {
|
|
40
|
+
message: LLMMessage;
|
|
41
|
+
heat: number;
|
|
42
|
+
addedAtTurn: number;
|
|
43
|
+
referenceCount: number;
|
|
44
|
+
}
|
|
45
|
+
export declare class HeatMapContextManager implements ContextManager {
|
|
46
|
+
private messages;
|
|
47
|
+
private turnCount;
|
|
48
|
+
private config;
|
|
49
|
+
constructor(config?: HeatMapConfig);
|
|
50
|
+
addMessage(message: LLMMessage): void;
|
|
51
|
+
getHistory(): LLMMessage[];
|
|
52
|
+
prune(targetTokenCount: number): Promise<void>;
|
|
53
|
+
summarize(): Promise<string>;
|
|
54
|
+
injectRagContext(_query: string, _limit?: number): Promise<void>;
|
|
55
|
+
calculateTokenCount(message: LLMMessage): number;
|
|
56
|
+
/**
|
|
57
|
+
* Advance the turn counter and decay all heat scores.
|
|
58
|
+
* Call this at the start of each LLM turn.
|
|
59
|
+
*/
|
|
60
|
+
advanceTurn(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Boost heat for messages that were referenced in the model's response.
|
|
63
|
+
*
|
|
64
|
+
* Detection is based on content overlap: if the response contains
|
|
65
|
+
* substrings from a previous message, that message gets boosted.
|
|
66
|
+
*
|
|
67
|
+
* @param response - The model's response content to check for references
|
|
68
|
+
* @param minOverlap - Minimum substring length to count as a reference (default: 20)
|
|
69
|
+
*/
|
|
70
|
+
boostReferencedMessages(response: string, minOverlap?: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Manually boost a specific message's heat score.
|
|
73
|
+
* Useful when the caller knows a particular message is relevant.
|
|
74
|
+
*/
|
|
75
|
+
boostMessage(index: number, boost?: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Get the heat scores for all messages.
|
|
78
|
+
*/
|
|
79
|
+
getHeatMap(): Array<{
|
|
80
|
+
role: string;
|
|
81
|
+
heat: number;
|
|
82
|
+
referenceCount: number;
|
|
83
|
+
preview: string;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Get the current turn count.
|
|
87
|
+
*/
|
|
88
|
+
getTurnCount(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Get scored messages (for inspection/testing).
|
|
91
|
+
*/
|
|
92
|
+
getScoredMessages(): ReadonlyArray<ScoredMessage>;
|
|
93
|
+
private _totalTokens;
|
|
94
|
+
/**
|
|
95
|
+
* Extract representative substrings from content for overlap detection.
|
|
96
|
+
* Takes samples from the beginning, middle, and end.
|
|
97
|
+
*/
|
|
98
|
+
private _extractSamples;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=heat-map-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heat-map-manager.d.ts","sourceRoot":"","sources":["../../src/context/heat-map-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAMD,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,CAAC,EAAE,aAAa;IAalC,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IASrC,UAAU,IAAI,UAAU,EAAE;IAIpB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ5B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItE,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM;IAQhD;;;OAGG;IACH,WAAW,IAAI,IAAI;IASnB;;;;;;;;OAQG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,IAAI;IA0BxE;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAOjD;;OAEG;IACH,UAAU,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAS5F;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,iBAAiB,IAAI,aAAa,CAAC,aAAa,CAAC;IAQjD,OAAO,CAAC,YAAY;IAOpB;;;OAGG;IACH,OAAO,CAAC,eAAe;CAoBxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Context Manager Implementation
|
|
3
|
+
*/
|
|
4
|
+
import { LLMMessage } from '../llm/types.js';
|
|
5
|
+
import { ContextManager } from './types.js';
|
|
6
|
+
export declare class BaseContextManager implements ContextManager {
|
|
7
|
+
private history;
|
|
8
|
+
constructor(initialHistory?: LLMMessage[]);
|
|
9
|
+
addMessage(message: LLMMessage): void;
|
|
10
|
+
getHistory(): LLMMessage[];
|
|
11
|
+
prune(targetTokenCount: number): Promise<void>;
|
|
12
|
+
summarize(): Promise<string>;
|
|
13
|
+
injectRagContext(query: string, limit?: number): Promise<void>;
|
|
14
|
+
calculateTokenCount(message: LLMMessage): number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/context/manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,OAAO,CAAoB;gBAEvB,cAAc,GAAE,UAAU,EAAO;IAI7C,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAIrC,UAAU,IAAI,UAAU,EAAE;IAIpB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM;CAGjD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Management Interface and Types
|
|
3
|
+
*/
|
|
4
|
+
import { LLMMessage } from '../llm/types.js';
|
|
5
|
+
export interface ContextWindow {
|
|
6
|
+
maxTokens: number;
|
|
7
|
+
currentTokens: number;
|
|
8
|
+
messages: LLMMessage[];
|
|
9
|
+
availableRagResults?: string[];
|
|
10
|
+
relatedEntityIds?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ContextManager {
|
|
13
|
+
addMessage(message: LLMMessage): void;
|
|
14
|
+
getHistory(): LLMMessage[];
|
|
15
|
+
prune(targetTokenCount: number): Promise<void>;
|
|
16
|
+
summarize(): Promise<string>;
|
|
17
|
+
injectRagContext(query: string, limit?: number): Promise<void>;
|
|
18
|
+
calculateTokenCount(message: LLMMessage): number;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,UAAU,EAAE,CAAC;IAGvB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAG/B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACtC,UAAU,IAAI,UAAU,EAAE,CAAC;IAG3B,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAG7B,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG/D,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC;CAClD"}
|
|
@@ -7,13 +7,22 @@
|
|
|
7
7
|
* @module trellis/core/agents
|
|
8
8
|
*/
|
|
9
9
|
import type { TrellisKernel } from '../kernel/trellis-kernel.js';
|
|
10
|
-
import type { AgentDef, ToolDef, ToolHandler, ToolResult, AgentRun, DecisionTrace, AgentHarnessConfig } from './types.js';
|
|
10
|
+
import type { AgentDef, ToolDef, ToolHandler, ToolResult, AgentRun, DecisionTrace, AgentHarnessConfig, RunTaskOptions } from './types.js';
|
|
11
11
|
export declare class AgentHarness {
|
|
12
12
|
private kernel;
|
|
13
13
|
private toolHandlers;
|
|
14
14
|
private config;
|
|
15
15
|
private runCounter;
|
|
16
16
|
constructor(kernel: TrellisKernel, config?: AgentHarnessConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Execute an autonomous task run using the configured LLM provider.
|
|
19
|
+
*
|
|
20
|
+
* When the configured contextManager is a GraphContextManager, conversations
|
|
21
|
+
* are automatically created (or resumed) and linked to the agent run. Pass
|
|
22
|
+
* `opts.conversationId` to resume an existing conversation.
|
|
23
|
+
*/
|
|
24
|
+
runAgentTask(agentId: string, input: string, opts?: RunTaskOptions): Promise<string>;
|
|
25
|
+
private _getAvailableTools;
|
|
17
26
|
createAgent(def: Omit<AgentDef, 'id' | 'capabilities' | 'tools'> & {
|
|
18
27
|
id?: string;
|
|
19
28
|
capabilities?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/core/agents/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EACV,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,EAEb,kBAAkB,
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/core/agents/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EACV,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,EAEb,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AAMpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,YAAY,CAAuC;IAC3D,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,UAAU,CAAa;gBAEnB,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAW9D;;;;;;OAMG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAkG1F,OAAO,CAAC,kBAAkB;IAiBpB,WAAW,CACf,GAAG,EAAE,IAAI,CAAC,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I,CAAC,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5B,GACA,OAAO,CAAC,MAAM,CAAC;IA8BlB;;OAEG;IACG,UAAU,CACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GACxD,OAAO,CAAC,UAAU,CAAC;IAyBtB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,EAAE;IAanD,OAAO,CAAC,mBAAmB;CA4C5B"}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module trellis/core/agents
|
|
8
8
|
*/
|
|
9
|
+
import type { LLMProvider } from '../../llm/types.js';
|
|
10
|
+
import type { ContextManager } from '../../context/types.js';
|
|
9
11
|
export interface AgentDef {
|
|
10
12
|
id: string;
|
|
11
13
|
name: string;
|
|
@@ -16,6 +18,8 @@ export interface AgentDef {
|
|
|
16
18
|
status: 'active' | 'inactive' | 'deprecated';
|
|
17
19
|
capabilities: string[];
|
|
18
20
|
tools: string[];
|
|
21
|
+
temperature?: number;
|
|
22
|
+
maxTokens?: number;
|
|
19
23
|
}
|
|
20
24
|
export interface ToolDef {
|
|
21
25
|
id: string;
|
|
@@ -30,7 +34,7 @@ export interface ToolResult {
|
|
|
30
34
|
output: unknown;
|
|
31
35
|
error?: string;
|
|
32
36
|
}
|
|
33
|
-
export type RunStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
37
|
+
export type RunStatus = 'running' | 'completed' | 'failed' | 'cancelled' | 'plan_pending';
|
|
34
38
|
export interface AgentRun {
|
|
35
39
|
id: string;
|
|
36
40
|
agentId: string;
|
|
@@ -39,7 +43,9 @@ export interface AgentRun {
|
|
|
39
43
|
status: RunStatus;
|
|
40
44
|
input?: string;
|
|
41
45
|
output?: string;
|
|
42
|
-
|
|
46
|
+
totalTokens?: number;
|
|
47
|
+
promptTokens?: number;
|
|
48
|
+
completionTokens?: number;
|
|
43
49
|
decisions: DecisionTrace[];
|
|
44
50
|
}
|
|
45
51
|
export interface DecisionTrace {
|
|
@@ -59,5 +65,15 @@ export interface AgentHarnessConfig {
|
|
|
59
65
|
recordDecisions?: boolean;
|
|
60
66
|
/** Maximum decisions per run before auto-stopping. */
|
|
61
67
|
maxDecisionsPerRun?: number;
|
|
68
|
+
/** Integration with an LLM provider for autonomous reasoning. */
|
|
69
|
+
llmProvider?: LLMProvider;
|
|
70
|
+
/** Context manager for handling agent memory. */
|
|
71
|
+
contextManager?: ContextManager;
|
|
72
|
+
}
|
|
73
|
+
export interface RunTaskOptions {
|
|
74
|
+
/** Resume an existing conversation instead of creating a new one. */
|
|
75
|
+
conversationId?: string;
|
|
76
|
+
/** Title for a new conversation (defaults to first 80 chars of input). */
|
|
77
|
+
conversationTitle?: string;
|
|
62
78
|
}
|
|
63
79
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/agents/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;IAC7C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,EAAE,CAA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4
|
+
* Evaluates @expr fields with built-in functions.
|
|
5
|
+
* Supports: $if, $round, $concat, $len, $lower, $upper, $trim, $now, $uuid
|
|
6
|
+
*/
|
|
7
|
+
import type { Atom } from '../store/eav-store.js';
|
|
8
|
+
export interface EvalContext {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare class ExprEvaluator {
|
|
12
|
+
private functions;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Evaluate an expression string against a context.
|
|
16
|
+
*/
|
|
17
|
+
eval(expr: string, context: EvalContext): unknown;
|
|
18
|
+
private evalFunction;
|
|
19
|
+
private parseArgs;
|
|
20
|
+
private if;
|
|
21
|
+
private round;
|
|
22
|
+
private concat;
|
|
23
|
+
private len;
|
|
24
|
+
private lower;
|
|
25
|
+
private upper;
|
|
26
|
+
private trim;
|
|
27
|
+
private now;
|
|
28
|
+
private uuid;
|
|
29
|
+
private add;
|
|
30
|
+
private sub;
|
|
31
|
+
private mul;
|
|
32
|
+
private div;
|
|
33
|
+
private mod;
|
|
34
|
+
private eq;
|
|
35
|
+
private ne;
|
|
36
|
+
private gt;
|
|
37
|
+
private gte;
|
|
38
|
+
private lt;
|
|
39
|
+
private lte;
|
|
40
|
+
private and;
|
|
41
|
+
private or;
|
|
42
|
+
private not;
|
|
43
|
+
private coalesce;
|
|
44
|
+
private contains;
|
|
45
|
+
private startsWith;
|
|
46
|
+
private endsWith;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Evaluate an expression and return a valid Atom.
|
|
50
|
+
*/
|
|
51
|
+
export declare function evalExpr(expr: string, context: EvalContext): Atom;
|
|
52
|
+
//# sourceMappingURL=expr-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr-evaluator.d.ts","sourceRoot":"","sources":["../../../src/core/computation/expr-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,E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|
import {
|
|
13
13
|
DatalogRuntime,
|
|
14
14
|
parseQuery,
|
|
@@ -18,13 +18,13 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
SqliteKernelBackend,
|
|
20
20
|
TrellisKernel
|
|
21
|
-
} from "../index-
|
|
21
|
+
} from "../index-0zk3fx2s.js";
|
|
22
22
|
import {
|
|
23
23
|
EAVStore,
|
|
24
24
|
flatten,
|
|
25
25
|
init_eav_store,
|
|
26
26
|
jsonEntityFacts
|
|
27
|
-
} from "../index-
|
|
27
|
+
} from "../index-yhwjgfvj.js";
|
|
28
28
|
import {
|
|
29
29
|
QueryEngine
|
|
30
30
|
} from "../index-yp88he8n.js";
|
|
@@ -47,6 +47,92 @@ class AgentHarness {
|
|
|
47
47
|
...config
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
async runAgentTask(agentId, input, opts) {
|
|
51
|
+
if (!this.config.llmProvider) {
|
|
52
|
+
throw new Error("AgentHarness: No llmProvider configured for autonomous tasks.");
|
|
53
|
+
}
|
|
54
|
+
const agent = this.getAgent(agentId);
|
|
55
|
+
if (!agent)
|
|
56
|
+
throw new Error(`Agent "${agentId}" not found.`);
|
|
57
|
+
const runId = await this.startRun(agentId, input);
|
|
58
|
+
const context = this.config.contextManager;
|
|
59
|
+
if (context && typeof context.createConversation === "function") {
|
|
60
|
+
const gcm = context;
|
|
61
|
+
if (opts?.conversationId) {
|
|
62
|
+
await gcm.resumeConversation(opts.conversationId);
|
|
63
|
+
} else {
|
|
64
|
+
const convId = await gcm.createConversation({
|
|
65
|
+
title: opts?.conversationTitle ?? input.slice(0, 80),
|
|
66
|
+
agentId,
|
|
67
|
+
model: agent.model
|
|
68
|
+
});
|
|
69
|
+
await this.kernel.addLink(runId, "hasConversation", convId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (context && agent.systemPrompt) {
|
|
73
|
+
context.addMessage({ role: "system", content: agent.systemPrompt });
|
|
74
|
+
}
|
|
75
|
+
if (context) {
|
|
76
|
+
context.addMessage({ role: "user", content: input });
|
|
77
|
+
}
|
|
78
|
+
let turnCount = 0;
|
|
79
|
+
const maxTurns = agent.maxTokens ?? 10;
|
|
80
|
+
try {
|
|
81
|
+
while (turnCount < maxTurns) {
|
|
82
|
+
turnCount++;
|
|
83
|
+
const messages = context ? context.getHistory() : [
|
|
84
|
+
...agent.systemPrompt ? [{ role: "system", content: agent.systemPrompt }] : [],
|
|
85
|
+
{ role: "user", content: input }
|
|
86
|
+
];
|
|
87
|
+
const response = await this.config.llmProvider.complete(messages, {
|
|
88
|
+
model: agent.model,
|
|
89
|
+
temperature: agent.temperature,
|
|
90
|
+
tools: this._getAvailableTools(agent.tools)
|
|
91
|
+
});
|
|
92
|
+
const message = response.choices[0].message;
|
|
93
|
+
if (context)
|
|
94
|
+
context.addMessage(message);
|
|
95
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
96
|
+
let planPending = false;
|
|
97
|
+
for (const call of message.tool_calls) {
|
|
98
|
+
const result = await this.invokeTool(runId, call.function.name, JSON.parse(call.function.arguments));
|
|
99
|
+
if (context) {
|
|
100
|
+
context.addMessage({
|
|
101
|
+
role: "tool",
|
|
102
|
+
tool_call_id: call.id,
|
|
103
|
+
name: call.function.name,
|
|
104
|
+
content: result.success ? JSON.stringify(result.output) : result.error ?? "Unknown error"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (result.success && result.output && typeof result.output === "object" && result.output._planPending) {
|
|
108
|
+
planPending = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (planPending) {
|
|
112
|
+
await this.kernel.updateEntity(runId, { status: "plan_pending" });
|
|
113
|
+
return runId;
|
|
114
|
+
}
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
await this.completeRun(runId, message.content ?? "", response.usage?.total_tokens);
|
|
118
|
+
return runId;
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`Agent run exceeded maximum turns (${maxTurns}).`);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
await this.failRun(runId, err.message);
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_getAvailableTools(toolIds) {
|
|
127
|
+
return this.listTools().filter((t) => toolIds.includes(t.id)).map((t) => ({
|
|
128
|
+
type: "function",
|
|
129
|
+
function: {
|
|
130
|
+
name: t.id,
|
|
131
|
+
description: t.description,
|
|
132
|
+
parameters: t.schema ? JSON.parse(t.schema) : { type: "object", properties: {} }
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
50
136
|
async createAgent(def) {
|
|
51
137
|
const id = def.id ?? `agent:${def.name.toLowerCase().replace(/\s+/g, "-")}`;
|
|
52
138
|
await this.kernel.createEntity(id, "Agent", {
|
|
@@ -138,7 +224,7 @@ class AgentHarness {
|
|
|
138
224
|
if (output)
|
|
139
225
|
updates.output = output;
|
|
140
226
|
if (tokenCount !== undefined)
|
|
141
|
-
updates.
|
|
227
|
+
updates.totalTokens = tokenCount;
|
|
142
228
|
await this.kernel.updateEntity(runId, updates);
|
|
143
229
|
}
|
|
144
230
|
async failRun(runId, error) {
|
|
@@ -167,7 +253,9 @@ class AgentHarness {
|
|
|
167
253
|
status: get("status") ?? "running",
|
|
168
254
|
input: get("input"),
|
|
169
255
|
output: get("output"),
|
|
170
|
-
|
|
256
|
+
totalTokens: get("totalTokens"),
|
|
257
|
+
promptTokens: get("promptTokens"),
|
|
258
|
+
completionTokens: get("completionTokens"),
|
|
171
259
|
decisions
|
|
172
260
|
};
|
|
173
261
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logic Middleware
|
|
3
|
+
*
|
|
4
|
+
* Evaluates computed fields (formula, rollup, ai_generated) after queries.
|
|
5
|
+
* Runs post-query to enrich results with computed values.
|
|
6
|
+
*/
|
|
7
|
+
import type { KernelMiddleware } from './middleware.js';
|
|
8
|
+
import type { SchemaDefinition } from '../ontology/types.js';
|
|
9
|
+
export interface LogicMiddlewareConfig {
|
|
10
|
+
ontologies: Map<string, SchemaDefinition>;
|
|
11
|
+
/** Optional AI function for ai_generated fields */
|
|
12
|
+
generateAiField?: (prompt: string, context: Record<string, unknown>) => Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a logic middleware that enriches query results with computed fields.
|
|
16
|
+
* This middleware hooks into queries, not mutations.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createLogicMiddleware(config: LogicMiddlewareConfig): KernelMiddleware;
|
|
19
|
+
//# sourceMappingURL=logic-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic-middleware.d.ts","sourceRoot":"","sources":["../../../src/core/kernel/logic-middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,mDAAmD;IACnD,eAAe,CAAC,EAAE,CAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,GAC5B,gBAAgB,CA0BlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Validation Middleware
|
|
3
|
+
*
|
|
4
|
+
* Validates mutations against ontology schemas. Blocks operations that
|
|
5
|
+
* violate schema constraints (required fields, type mismatches, etc.).
|
|
6
|
+
*/
|
|
7
|
+
import type { KernelMiddleware } from './middleware.js';
|
|
8
|
+
import type { SchemaDefinition } from '../ontology/types.js';
|
|
9
|
+
export interface SchemaMiddlewareConfig {
|
|
10
|
+
ontologies: Map<string, SchemaDefinition>;
|
|
11
|
+
/** Whether to block on validation errors (default: true) */
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createSchemaMiddleware(config: SchemaMiddlewareConfig): KernelMiddleware;
|
|
15
|
+
//# sourceMappingURL=schema-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-middleware.d.ts","sourceRoot":"","sources":["../../../src/core/kernel/schema-middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,4DAA4D;IAC5D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,sBAAsB,GAC7B,gBAAgB,CAmElB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Middleware
|
|
3
|
+
*
|
|
4
|
+
* Capability-based access control. Validates that the agent has permission
|
|
5
|
+
* to perform the requested operation on the target entity.
|
|
6
|
+
*/
|
|
7
|
+
import type { KernelMiddleware } from './middleware.js';
|
|
8
|
+
export type Permission = 'read' | 'create' | 'update' | 'delete' | 'link' | 'unlink' | 'admin';
|
|
9
|
+
export interface Capability {
|
|
10
|
+
/** What the capability applies to (entity ID, type, or '*' for all) */
|
|
11
|
+
resource: string;
|
|
12
|
+
/** Permissions granted */
|
|
13
|
+
permissions: Permission[];
|
|
14
|
+
}
|
|
15
|
+
export interface SecurityMiddlewareConfig {
|
|
16
|
+
/** Agent ID to capabilities map */
|
|
17
|
+
capabilities: Map<string, Capability[]>;
|
|
18
|
+
/** Default capabilities for agents not in the map */
|
|
19
|
+
defaultCapabilities?: Capability[];
|
|
20
|
+
/** If true, blocks operations without explicit grants. If false, allows by default. */
|
|
21
|
+
strict?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function createSecurityMiddleware(config: SecurityMiddlewareConfig): KernelMiddleware;
|
|
24
|
+
//# sourceMappingURL=security-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-middleware.d.ts","sourceRoot":"","sources":["../../../src/core/kernel/security-middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAwB;IACvC,mCAAmC;IACnC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACxC,qDAAqD;IACrD,mBAAmB,CAAC,EAAE,UAAU,EAAE,CAAC;IACnC,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,wBAAwB,GAC/B,gBAAgB,CAoElB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync Provider Interface
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract for real-time sync and federation.
|
|
5
|
+
* Implementations handle applying remote operations and broadcasting local changes.
|
|
6
|
+
*/
|
|
7
|
+
import type { KernelOp } from '../persist/backend.js';
|
|
8
|
+
/**
|
|
9
|
+
* Incoming remote operation from another peer.
|
|
10
|
+
*/
|
|
11
|
+
export interface RemoteOp {
|
|
12
|
+
op: KernelOp;
|
|
13
|
+
sourcePeerId: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sync provider interface.
|
|
18
|
+
* Implement this to enable real-time sync between peers.
|
|
19
|
+
*/
|
|
20
|
+
export interface SyncProvider {
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the sync provider.
|
|
23
|
+
*/
|
|
24
|
+
connect(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Disconnect from the sync network.
|
|
27
|
+
*/
|
|
28
|
+
disconnect(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Check if connected.
|
|
31
|
+
*/
|
|
32
|
+
isConnected(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Apply a remote operation from another peer.
|
|
35
|
+
* The kernel should apply this to its local store.
|
|
36
|
+
*/
|
|
37
|
+
applyRemoteOperation(op: RemoteOp): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Broadcast a local operation to other peers.
|
|
40
|
+
*/
|
|
41
|
+
broadcast(op: KernelOp): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the peer ID for this node.
|
|
44
|
+
*/
|
|
45
|
+
getPeerId(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get list of connected peers.
|
|
48
|
+
*/
|
|
49
|
+
getPeers(): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Handle incoming operations (register callback).
|
|
52
|
+
*/
|
|
53
|
+
onRemoteOp(callback: (op: RemoteOp) => void | Promise<void>): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a no-op sync provider for local-only mode.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createLocalSyncProvider(): SyncProvider;
|
|
59
|
+
//# sourceMappingURL=sync-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-provider.d.ts","sourceRoot":"","sources":["../../../src/core/kernel/sync-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,QAAQ,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC;IAEvB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,IAAI,MAAM,EAAE,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,YAAY,CAWtD"}
|