@nookplot/runtime 0.5.141 → 0.5.143
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/__tests__/apiMarketplace.test.js +189 -2
- package/dist/__tests__/apiMarketplace.test.js.map +1 -1
- package/dist/__tests__/autonomous.dedup.test.js +11 -0
- package/dist/__tests__/autonomous.dedup.test.js.map +1 -1
- package/dist/__tests__/autonomous.getAvailableActions.test.js +13 -1
- package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
- package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +2 -0
- package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.goalBootstrap.test.js +148 -0
- package/dist/__tests__/autonomous.goalBootstrap.test.js.map +1 -0
- package/dist/__tests__/autonomous.miningTrack.test.d.ts +2 -0
- package/dist/__tests__/autonomous.miningTrack.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.miningTrack.test.js +38 -0
- package/dist/__tests__/autonomous.miningTrack.test.js.map +1 -0
- package/dist/__tests__/autonomous.payApi.test.d.ts +2 -0
- package/dist/__tests__/autonomous.payApi.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.payApi.test.js +73 -0
- package/dist/__tests__/autonomous.payApi.test.js.map +1 -0
- package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts +2 -0
- package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.workspaceOpportunity.test.js +200 -0
- package/dist/__tests__/autonomous.workspaceOpportunity.test.js.map +1 -0
- package/dist/__tests__/codegen-drift.test.js +3 -1
- package/dist/__tests__/codegen-drift.test.js.map +1 -1
- package/dist/__tests__/conversation/modelThresholdsParity.test.js +19 -14
- package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
- package/dist/__tests__/economy.surplusBranch.test.js +64 -0
- package/dist/__tests__/economy.surplusBranch.test.js.map +1 -1
- package/dist/__tests__/goalLoop.test.d.ts +2 -0
- package/dist/__tests__/goalLoop.test.d.ts.map +1 -0
- package/dist/__tests__/goalLoop.test.js +358 -0
- package/dist/__tests__/goalLoop.test.js.map +1 -0
- package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
- package/dist/__tests__/helpers/mockRuntime.js +7 -0
- package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
- package/dist/__tests__/loadProfile.test.d.ts +8 -0
- package/dist/__tests__/loadProfile.test.d.ts.map +1 -0
- package/dist/__tests__/loadProfile.test.js +134 -0
- package/dist/__tests__/loadProfile.test.js.map +1 -0
- package/dist/__tests__/mining.test.d.ts +2 -0
- package/dist/__tests__/mining.test.d.ts.map +1 -0
- package/dist/__tests__/mining.test.js +306 -0
- package/dist/__tests__/mining.test.js.map +1 -0
- package/dist/__tests__/presetLoader.test.d.ts +2 -0
- package/dist/__tests__/presetLoader.test.d.ts.map +1 -0
- package/dist/__tests__/presetLoader.test.js +749 -0
- package/dist/__tests__/presetLoader.test.js.map +1 -0
- package/dist/__tests__/signalActionMap.test.d.ts +17 -0
- package/dist/__tests__/signalActionMap.test.d.ts.map +1 -0
- package/dist/__tests__/signalActionMap.test.js +165 -0
- package/dist/__tests__/signalActionMap.test.js.map +1 -0
- package/dist/__tests__/usdcBudget.test.d.ts +2 -0
- package/dist/__tests__/usdcBudget.test.d.ts.map +1 -0
- package/dist/__tests__/usdcBudget.test.js +128 -0
- package/dist/__tests__/usdcBudget.test.js.map +1 -0
- package/dist/__tests__/x402.test.d.ts +2 -0
- package/dist/__tests__/x402.test.d.ts.map +1 -0
- package/dist/__tests__/x402.test.js +117 -0
- package/dist/__tests__/x402.test.js.map +1 -0
- package/dist/actionCatalog.d.ts.map +1 -1
- package/dist/actionCatalog.generated.d.ts +1 -1
- package/dist/actionCatalog.generated.d.ts.map +1 -1
- package/dist/actionCatalog.generated.js +179 -24
- package/dist/actionCatalog.generated.js.map +1 -1
- package/dist/actionCatalog.js +0 -10
- package/dist/actionCatalog.js.map +1 -1
- package/dist/api-marketplace.d.ts +146 -0
- package/dist/api-marketplace.d.ts.map +1 -1
- package/dist/api-marketplace.js +218 -0
- package/dist/api-marketplace.js.map +1 -1
- package/dist/autonomous.d.ts +16 -9
- package/dist/autonomous.d.ts.map +1 -1
- package/dist/autonomous.js +268 -59
- package/dist/autonomous.js.map +1 -1
- package/dist/contentSafety.d.ts +1 -1
- package/dist/contentSafety.d.ts.map +1 -1
- package/dist/contentSafety.js +6 -2
- package/dist/contentSafety.js.map +1 -1
- package/dist/discovery.js +1 -1
- package/dist/discovery.js.map +1 -1
- package/dist/economy.d.ts +10 -15
- package/dist/economy.d.ts.map +1 -1
- package/dist/economy.js +16 -29
- package/dist/economy.js.map +1 -1
- package/dist/goal/goalLoop.d.ts +78 -0
- package/dist/goal/goalLoop.d.ts.map +1 -0
- package/dist/goal/goalLoop.js +388 -0
- package/dist/goal/goalLoop.js.map +1 -0
- package/dist/goal/goalPrompts.d.ts +20 -0
- package/dist/goal/goalPrompts.d.ts.map +1 -0
- package/dist/goal/goalPrompts.js +54 -0
- package/dist/goal/goalPrompts.js.map +1 -0
- package/dist/goal/types.d.ts +102 -0
- package/dist/goal/types.d.ts.map +1 -0
- package/dist/goal/types.js +7 -0
- package/dist/goal/types.js.map +1 -0
- package/dist/identity.d.ts +51 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +50 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/loadProfile.d.ts +100 -0
- package/dist/loadProfile.d.ts.map +1 -0
- package/dist/loadProfile.js +221 -0
- package/dist/loadProfile.js.map +1 -0
- package/dist/presetLoader.d.ts +130 -0
- package/dist/presetLoader.d.ts.map +1 -0
- package/dist/presetLoader.js +734 -0
- package/dist/presetLoader.js.map +1 -0
- package/dist/signalActionMap.d.ts.map +1 -1
- package/dist/signalActionMap.js +15 -5
- package/dist/signalActionMap.js.map +1 -1
- package/dist/swarms.d.ts +13 -0
- package/dist/swarms.d.ts.map +1 -1
- package/dist/swarms.js +4 -0
- package/dist/swarms.js.map +1 -1
- package/dist/tools.js +1 -1
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usdcBudget.d.ts +90 -0
- package/dist/usdcBudget.d.ts.map +1 -0
- package/dist/usdcBudget.js +155 -0
- package/dist/usdcBudget.js.map +1 -0
- package/dist/x402.d.ts +69 -0
- package/dist/x402.d.ts.map +1 -0
- package/dist/x402.js +139 -0
- package/dist/x402.js.map +1 -0
- package/package.json +2 -2
- package/dist/__tests__/economy.frontierInference.test.d.ts +0 -2
- package/dist/__tests__/economy.frontierInference.test.d.ts.map +0 -1
- package/dist/__tests__/economy.frontierInference.test.js +0 -61
- package/dist/__tests__/economy.frontierInference.test.js.map +0 -1
- package/dist/frontierPass.d.ts +0 -30
- package/dist/frontierPass.d.ts.map +0 -1
- package/dist/frontierPass.js +0 -42
- package/dist/frontierPass.js.map +0 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile-aware credential loading for @nookplot/runtime.
|
|
3
|
+
*
|
|
4
|
+
* The SDK normally takes `{ apiKey, gatewayUrl }` at instantiation —
|
|
5
|
+
* developers pass keys directly. This helper is for developers who want
|
|
6
|
+
* the SDK to read from `~/.nookplot/` like @nookplot/cli and @nookplot/mcp
|
|
7
|
+
* do, so a user running multiple forged agents can point the SDK at
|
|
8
|
+
* whichever scope is active in their shell.
|
|
9
|
+
*
|
|
10
|
+
* Reads from the same files the rest of the Nookplot stack uses:
|
|
11
|
+
* ~/.nookplot/credentials.json ← creator API key (shared)
|
|
12
|
+
* ~/.nookplot/profiles/<name>/profile.json ← per-agent scope
|
|
13
|
+
* ~/.nookplot/active-profile ← sticky default (CLI-written)
|
|
14
|
+
*
|
|
15
|
+
* Resolution order:
|
|
16
|
+
* 1. Explicit `name` argument to loadProfile()
|
|
17
|
+
* 2. NOOKPLOT_PROFILE env var
|
|
18
|
+
* 3. Sticky default from ~/.nookplot/active-profile
|
|
19
|
+
* 4. null (load default creds only, no scope)
|
|
20
|
+
*
|
|
21
|
+
* @module loadProfile
|
|
22
|
+
*
|
|
23
|
+
* @example Basic usage — pick up whatever profile is active
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { NookplotRuntime } from "@nookplot/runtime";
|
|
26
|
+
* import { loadProfile } from "@nookplot/runtime/loadProfile";
|
|
27
|
+
*
|
|
28
|
+
* const creds = loadProfile(); // respects NOOKPLOT_PROFILE env + sticky default
|
|
29
|
+
* if (!creds) throw new Error("No credentials — run `nookplot register` first");
|
|
30
|
+
*
|
|
31
|
+
* const runtime = new NookplotRuntime({
|
|
32
|
+
* apiKey: creds.apiKey,
|
|
33
|
+
* gatewayUrl: creds.gatewayUrl,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Explicit profile override
|
|
38
|
+
* ```ts
|
|
39
|
+
* const creds = loadProfile("jeffs-researcher");
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Multi-agent — run two SDK instances in parallel
|
|
43
|
+
* ```ts
|
|
44
|
+
* const researcherCreds = loadProfile("jeffs-researcher");
|
|
45
|
+
* const writerCreds = loadProfile("jeffs-writer");
|
|
46
|
+
*
|
|
47
|
+
* const researcher = new NookplotRuntime({ apiKey: researcherCreds!.apiKey, ... });
|
|
48
|
+
* const writer = new NookplotRuntime({ apiKey: writerCreds!.apiKey, ... });
|
|
49
|
+
* // Both clients share the creator's API key but scope to different forged agents.
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
53
|
+
import { homedir } from "node:os";
|
|
54
|
+
import { join } from "node:path";
|
|
55
|
+
function nookplotDir() {
|
|
56
|
+
return join(homedir(), ".nookplot");
|
|
57
|
+
}
|
|
58
|
+
function credentialsPath() {
|
|
59
|
+
return join(nookplotDir(), "credentials.json");
|
|
60
|
+
}
|
|
61
|
+
function profilePath(name) {
|
|
62
|
+
return join(nookplotDir(), "profiles", name, "profile.json");
|
|
63
|
+
}
|
|
64
|
+
function activeProfilePath() {
|
|
65
|
+
return join(nookplotDir(), "active-profile");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the active profile name in priority order.
|
|
69
|
+
* Exported for testing + for developers who want to see which profile
|
|
70
|
+
* WOULD be used without actually loading credentials.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveActiveProfileName(explicitName) {
|
|
73
|
+
if (explicitName)
|
|
74
|
+
return explicitName;
|
|
75
|
+
const env = process.env.NOOKPLOT_PROFILE;
|
|
76
|
+
if (env)
|
|
77
|
+
return env;
|
|
78
|
+
try {
|
|
79
|
+
if (existsSync(activeProfilePath())) {
|
|
80
|
+
const content = readFileSync(activeProfilePath(), "utf-8").trim();
|
|
81
|
+
if (content)
|
|
82
|
+
return content;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Permissions error or disk issue — fall through
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Load credentials, optionally merging a named profile's scope on top.
|
|
92
|
+
*
|
|
93
|
+
* Returns null if no `credentials.json` exists — the developer should
|
|
94
|
+
* surface a clear "run `nookplot register` first" message in that case.
|
|
95
|
+
*
|
|
96
|
+
* Does not throw on invalid profiles — if the named profile doesn't
|
|
97
|
+
* exist or is malformed, falls back to plain creator-direct credentials
|
|
98
|
+
* (matches @nookplot/mcp's fail-open behavior so stale env vars don't
|
|
99
|
+
* break unrelated commands).
|
|
100
|
+
*/
|
|
101
|
+
export function loadProfile(name) {
|
|
102
|
+
// 1. Load base credentials — the shared creator API key.
|
|
103
|
+
if (!existsSync(credentialsPath()))
|
|
104
|
+
return null;
|
|
105
|
+
let creds;
|
|
106
|
+
try {
|
|
107
|
+
creds = JSON.parse(readFileSync(credentialsPath(), "utf-8"));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (!creds.apiKey || !creds.address || !creds.privateKey || !creds.gatewayUrl) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
// 2. Honor NOOKPLOT_GATEWAY_URL env if set (matches SDK + MCP convention).
|
|
116
|
+
const gatewayUrl = process.env.NOOKPLOT_GATEWAY_URL ?? creds.gatewayUrl;
|
|
117
|
+
// 3. Resolve profile (if any) and read its scope.
|
|
118
|
+
const profileName = resolveActiveProfileName(name);
|
|
119
|
+
if (!profileName) {
|
|
120
|
+
return {
|
|
121
|
+
apiKey: creds.apiKey,
|
|
122
|
+
address: creds.address,
|
|
123
|
+
privateKey: creds.privateKey,
|
|
124
|
+
gatewayUrl,
|
|
125
|
+
displayName: creds.displayName,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const pPath = profilePath(profileName);
|
|
129
|
+
if (!existsSync(pPath)) {
|
|
130
|
+
// Stale profile reference — fall back to creator-direct. Matches
|
|
131
|
+
// @nookplot/mcp's fail-open pattern.
|
|
132
|
+
return {
|
|
133
|
+
apiKey: creds.apiKey,
|
|
134
|
+
address: creds.address,
|
|
135
|
+
privateKey: creds.privateKey,
|
|
136
|
+
gatewayUrl,
|
|
137
|
+
displayName: creds.displayName,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const p = JSON.parse(readFileSync(pPath, "utf-8"));
|
|
142
|
+
if (typeof p.scopedAgentAddress !== "string" || p.scopedAgentAddress.length === 0) {
|
|
143
|
+
// Malformed profile — fall back.
|
|
144
|
+
return {
|
|
145
|
+
apiKey: creds.apiKey,
|
|
146
|
+
address: creds.address,
|
|
147
|
+
privateKey: creds.privateKey,
|
|
148
|
+
gatewayUrl,
|
|
149
|
+
displayName: creds.displayName,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
apiKey: creds.apiKey,
|
|
154
|
+
address: creds.address,
|
|
155
|
+
privateKey: creds.privateKey,
|
|
156
|
+
gatewayUrl,
|
|
157
|
+
scopedAgentAddress: p.scopedAgentAddress,
|
|
158
|
+
profileName,
|
|
159
|
+
displayName: creds.displayName,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// JSON parse error on profile — fall back to creator-direct.
|
|
164
|
+
return {
|
|
165
|
+
apiKey: creds.apiKey,
|
|
166
|
+
address: creds.address,
|
|
167
|
+
privateKey: creds.privateKey,
|
|
168
|
+
gatewayUrl,
|
|
169
|
+
displayName: creds.displayName,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* List all profiles registered on the local machine. Each entry includes
|
|
175
|
+
* the profile name + its metadata. Useful for SDK consumers who want to
|
|
176
|
+
* enumerate the user's forged agents programmatically.
|
|
177
|
+
*
|
|
178
|
+
* Returns an empty array if ~/.nookplot/profiles doesn't exist. Never
|
|
179
|
+
* throws — invalid profiles are silently skipped.
|
|
180
|
+
*/
|
|
181
|
+
export function listProfiles() {
|
|
182
|
+
const dir = join(nookplotDir(), "profiles");
|
|
183
|
+
if (!existsSync(dir))
|
|
184
|
+
return [];
|
|
185
|
+
const out = [];
|
|
186
|
+
try {
|
|
187
|
+
const { readdirSync, statSync } = require("node:fs");
|
|
188
|
+
for (const name of readdirSync(dir).sort()) {
|
|
189
|
+
const full = join(dir, name);
|
|
190
|
+
try {
|
|
191
|
+
if (!statSync(full).isDirectory())
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const pPath = join(full, "profile.json");
|
|
198
|
+
if (!existsSync(pPath))
|
|
199
|
+
continue;
|
|
200
|
+
try {
|
|
201
|
+
const p = JSON.parse(readFileSync(pPath, "utf-8"));
|
|
202
|
+
if (typeof p.scopedAgentAddress !== "string")
|
|
203
|
+
continue;
|
|
204
|
+
out.push({
|
|
205
|
+
name,
|
|
206
|
+
scopedAgentAddress: p.scopedAgentAddress,
|
|
207
|
+
displayName: p.displayName,
|
|
208
|
+
hermesProfile: p.hermesProfile,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Skip invalid profiles
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// Missing dir or perms — return empty
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=loadProfile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadProfile.js","sourceRoot":"","sources":["../src/loadProfile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAmBjC,SAAS,WAAW;IAClB,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;AACtC,CAAC;AACD,SAAS,eAAe;IACtB,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,kBAAkB,CAAC,CAAC;AACjD,CAAC;AACD,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AAC/D,CAAC;AACD,SAAS,iBAAiB;IACxB,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAC/C,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,YAAqB;IAC5D,IAAI,YAAY;QAAE,OAA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AAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sCAAsC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PresetLoader — loads forge preset data into agent memory at boot.
|
|
3
|
+
*
|
|
4
|
+
* Reads the preset section of nookplot.yaml, fetches data per source via
|
|
5
|
+
* the gateway's forge data endpoint, runs content scanning, and ingests
|
|
6
|
+
* items as preset-tagged memories. Supports layered ingestion: RAG when
|
|
7
|
+
* available, memory.import() fallback.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Content scanning (sanitizeForPrompt) on every item
|
|
11
|
+
* - Idempotent loading via .preset-loaded.json manifest
|
|
12
|
+
* - Configurable failure policy (abort / continue / retry)
|
|
13
|
+
* - Boot progress events via EventEmitter
|
|
14
|
+
* - Self-awareness memory generation
|
|
15
|
+
*
|
|
16
|
+
* @module presetLoader
|
|
17
|
+
*/
|
|
18
|
+
import { EventEmitter } from "node:events";
|
|
19
|
+
import type { NookplotRuntime } from "./index.js";
|
|
20
|
+
export interface PresetConfig {
|
|
21
|
+
id: string;
|
|
22
|
+
version?: number;
|
|
23
|
+
trustLevel?: "verified" | "scanned" | "raw";
|
|
24
|
+
failurePolicy?: "abort" | "continue";
|
|
25
|
+
maxCostNook?: number;
|
|
26
|
+
sources?: Array<{
|
|
27
|
+
type: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
config: Record<string, unknown>;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export interface PresetLoadResult {
|
|
33
|
+
sources: Array<{
|
|
34
|
+
type: string;
|
|
35
|
+
label: string;
|
|
36
|
+
itemsLoaded: number;
|
|
37
|
+
itemsBlocked: number;
|
|
38
|
+
itemsSkipped: number;
|
|
39
|
+
method: "memory" | "rag" | "prompt";
|
|
40
|
+
status: "loaded" | "partial" | "failed";
|
|
41
|
+
error?: string;
|
|
42
|
+
costNook: number;
|
|
43
|
+
}>;
|
|
44
|
+
totalItems: number;
|
|
45
|
+
totalBlocked: number;
|
|
46
|
+
totalCostNook: number;
|
|
47
|
+
ragAvailable: boolean;
|
|
48
|
+
presetVersion: number;
|
|
49
|
+
loadedAt: string;
|
|
50
|
+
}
|
|
51
|
+
export type PresetLoadEvent = {
|
|
52
|
+
phase: "estimating";
|
|
53
|
+
message: string;
|
|
54
|
+
} | {
|
|
55
|
+
phase: "fetching";
|
|
56
|
+
source: string;
|
|
57
|
+
progress: string;
|
|
58
|
+
} | {
|
|
59
|
+
phase: "scanning";
|
|
60
|
+
source: string;
|
|
61
|
+
blocked: number;
|
|
62
|
+
} | {
|
|
63
|
+
phase: "ingesting";
|
|
64
|
+
source: string;
|
|
65
|
+
method: "memory" | "rag";
|
|
66
|
+
} | {
|
|
67
|
+
phase: "complete";
|
|
68
|
+
result: PresetLoadResult;
|
|
69
|
+
} | {
|
|
70
|
+
phase: "error";
|
|
71
|
+
source: string;
|
|
72
|
+
error: string;
|
|
73
|
+
};
|
|
74
|
+
export declare class PresetLoader extends EventEmitter {
|
|
75
|
+
private runtime;
|
|
76
|
+
private configPath;
|
|
77
|
+
private loading;
|
|
78
|
+
constructor(runtime: NookplotRuntime, configPath?: string);
|
|
79
|
+
/**
|
|
80
|
+
* Build x-preset-hmac header so the gateway trusts isPreset/presetId fields.
|
|
81
|
+
* HMAC = SHA-256(apiKey, "preset-ingest:" + agent_address).
|
|
82
|
+
*/
|
|
83
|
+
private presetIngestHeaders;
|
|
84
|
+
/**
|
|
85
|
+
* Load all preset data sources. Called once at agent boot.
|
|
86
|
+
* Concurrent calls are coalesced — only the first triggers a fetch,
|
|
87
|
+
* subsequent callers await the same promise (prevents double-pay).
|
|
88
|
+
*/
|
|
89
|
+
load(): Promise<PresetLoadResult>;
|
|
90
|
+
private _doLoad;
|
|
91
|
+
/**
|
|
92
|
+
* Check if preset data was already loaded (idempotent reboot check).
|
|
93
|
+
*/
|
|
94
|
+
isLoaded(): Promise<boolean>;
|
|
95
|
+
/**
|
|
96
|
+
* Map preset source type to knowledge graph knowledge_type.
|
|
97
|
+
*/
|
|
98
|
+
private mapSourceToKnowledgeType;
|
|
99
|
+
/**
|
|
100
|
+
* Map preset source type to knowledge graph source_type.
|
|
101
|
+
*/
|
|
102
|
+
private mapSourceToKGSourceType;
|
|
103
|
+
/**
|
|
104
|
+
* Ingest a KnowledgeAggregateV1 into the knowledge graph as structured items.
|
|
105
|
+
* Same decomposition as ingestAggregate but targets the KG endpoint.
|
|
106
|
+
*/
|
|
107
|
+
private ingestAggregateToKG;
|
|
108
|
+
/**
|
|
109
|
+
* Ingest a KnowledgeAggregateV1 as structured memories.
|
|
110
|
+
* Uses 5-7x fewer memory slots than equivalent raw traces:
|
|
111
|
+
* - Synthesis → semantic memory (importance 0.9)
|
|
112
|
+
* - Each keyInsight → procedural memory (confidence-weighted)
|
|
113
|
+
* - Each reasoning pattern → procedural memory
|
|
114
|
+
* - Contradictions → self_model memory
|
|
115
|
+
*
|
|
116
|
+
* Returns the number of memories stored.
|
|
117
|
+
*/
|
|
118
|
+
private ingestAggregate;
|
|
119
|
+
private readConfig;
|
|
120
|
+
private readManifest;
|
|
121
|
+
private writeManifest;
|
|
122
|
+
/**
|
|
123
|
+
* Lightweight client-side severity assessment.
|
|
124
|
+
* Full ContentScanner runs server-side; this is a first pass.
|
|
125
|
+
*/
|
|
126
|
+
private assessSeverity;
|
|
127
|
+
private emptyResult;
|
|
128
|
+
private manifestToResult;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=presetLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presetLoader.d.ts","sourceRoot":"","sources":["../src/presetLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C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