@aliyunrds/ctxdb 1.0.8-beta.1 → 1.0.8-beta.3
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 +14 -10
- package/dist/{chunk-NFAPLK4C.js → chunk-3NJ37TEY.js} +1 -1
- package/dist/{chunk-NF5KFV2P.js → chunk-7OX6UVPB.js} +15 -8
- package/dist/{chunk-LTAO6USK.js → chunk-AUBVVYQL.js} +1 -1
- package/dist/{chunk-KYW76CL7.js → chunk-BUK4SZC2.js} +980 -958
- package/dist/{chunk-3B7J5VUT.js → chunk-EI63DQX3.js} +1 -1
- package/dist/{chunk-TYW6ABNS.js → chunk-LZ2LOWZL.js} +2 -2
- package/dist/{chunk-SGRMPSZU.js → chunk-ZFS6OMWE.js} +4 -3
- package/dist/cli/main.js +29 -17
- package/dist/hooks/hermes-post-llm-call.js +10 -8
- package/dist/hooks/hermes-pre-llm-call.js +13 -12
- package/dist/hooks/session-start.js +12 -11
- package/dist/hooks/stop.js +10 -8
- package/dist/hooks/user-prompt-submit.js +12 -11
- package/dist/opencode/index.js +21 -7
- package/package.json +1 -1
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
fetchKbCatalogBlock,
|
|
4
4
|
recallTurn
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-7OX6UVPB.js";
|
|
6
6
|
import {
|
|
7
7
|
debug
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BUK4SZC2.js";
|
|
9
9
|
|
|
10
10
|
// src/lib/warmup-recall.ts
|
|
11
11
|
import { execSync } from "child_process";
|
|
@@ -4,12 +4,13 @@ import {
|
|
|
4
4
|
isConnectionError,
|
|
5
5
|
resetCircuit,
|
|
6
6
|
tripCircuit
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-EI63DQX3.js";
|
|
8
8
|
import {
|
|
9
9
|
CtxdbError,
|
|
10
10
|
debug,
|
|
11
|
+
isDataApiReady,
|
|
11
12
|
isDebug
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BUK4SZC2.js";
|
|
13
14
|
|
|
14
15
|
// src/lib/capture-orchestrator.ts
|
|
15
16
|
import {
|
|
@@ -398,7 +399,7 @@ async function captureParsedMessages(parsed, cfg, client, agent = "default", ses
|
|
|
398
399
|
};
|
|
399
400
|
}
|
|
400
401
|
function capturePreflight(cfg, agent) {
|
|
401
|
-
if (!cfg
|
|
402
|
+
if (!isDataApiReady(cfg)) {
|
|
402
403
|
return { captured: false, reason: "config_incomplete", messageCount: 0 };
|
|
403
404
|
}
|
|
404
405
|
if (!cfg.autoCapture) {
|
package/dist/cli/main.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
uploadFile,
|
|
17
17
|
uploadText,
|
|
18
18
|
validateLocalFile
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-3NJ37TEY.js";
|
|
20
20
|
import {
|
|
21
21
|
AGENT_CHOICES,
|
|
22
22
|
CtxdbError,
|
|
@@ -31,19 +31,20 @@ import {
|
|
|
31
31
|
agentHomeDir,
|
|
32
32
|
agentHomeDirs,
|
|
33
33
|
agentPlatformSupport,
|
|
34
|
+
apiKeyCredential,
|
|
34
35
|
configuredAgents,
|
|
35
36
|
detectInstalledAgents,
|
|
36
37
|
hasConfiguredAgent,
|
|
37
38
|
inspectAgentHomes,
|
|
38
39
|
isAgentSlug,
|
|
39
40
|
isBuiltinAgent,
|
|
40
|
-
isComplete,
|
|
41
41
|
load,
|
|
42
42
|
removeAgent,
|
|
43
|
+
resolveDataApiCredential,
|
|
43
44
|
save,
|
|
44
45
|
updateConfiguredDebug,
|
|
45
46
|
writeInstalledPkgVersion
|
|
46
|
-
} from "../chunk-
|
|
47
|
+
} from "../chunk-BUK4SZC2.js";
|
|
47
48
|
import {
|
|
48
49
|
beginUpdateNotification,
|
|
49
50
|
completeUpdateNotification,
|
|
@@ -275,6 +276,8 @@ function formatStatusResult(r) {
|
|
|
275
276
|
["base_url", r.base_url],
|
|
276
277
|
["user_id", r.user_id],
|
|
277
278
|
["api_key", r.api_key_set ? "set" : "not set"],
|
|
279
|
+
["access_token", r.access_token_set ? "set" : "not set"],
|
|
280
|
+
["credential_type", r.credential_type ?? "none"],
|
|
278
281
|
["auto_capture", r.auto_capture],
|
|
279
282
|
["auto_recall", r.auto_recall],
|
|
280
283
|
["top_k", r.top_k],
|
|
@@ -323,15 +326,16 @@ function agentFromFlags(flags) {
|
|
|
323
326
|
function buildContext(args) {
|
|
324
327
|
const agent = agentFromFlags(args?.flags ?? {});
|
|
325
328
|
const cfg = load({ agent });
|
|
326
|
-
|
|
327
|
-
|
|
329
|
+
const credential = resolveDataApiCredential(cfg);
|
|
330
|
+
if (!cfg.baseUrl || !credential) {
|
|
331
|
+
const hint = agent === "default" ? "run `ctxdb setup --api-key=<key> --base-url=<url>` or set CTXDB_ACCESS_TOKEN / CTXDB_API_KEY / CTXDB_BASE_URL env vars" : `run \`ctxdb setup --agent ${agent}\` or set CTXDB_ACCESS_TOKEN / CTXDB_API_KEY / CTXDB_BASE_URL / CTXDB_USER_ID env vars`;
|
|
328
332
|
process.stderr.write(`config incomplete for agent ${agent}: ${hint}
|
|
329
333
|
`);
|
|
330
334
|
process.exit(2);
|
|
331
335
|
}
|
|
332
336
|
const client = new HttpClient({
|
|
333
337
|
baseUrl: cfg.baseUrl,
|
|
334
|
-
|
|
338
|
+
credential
|
|
335
339
|
});
|
|
336
340
|
return { cfg, client, agent };
|
|
337
341
|
}
|
|
@@ -389,7 +393,7 @@ function skillInstallRoot(agent) {
|
|
|
389
393
|
case "hermes":
|
|
390
394
|
return join(homedir(), ".hermes", "skills");
|
|
391
395
|
case "workbuddy":
|
|
392
|
-
return join(homedir(), ".workbuddy", "skills");
|
|
396
|
+
return join(homedir(), ".workbuddy-ai", "skills");
|
|
393
397
|
}
|
|
394
398
|
}
|
|
395
399
|
var SKILL_DIRS = ["contextdb-memory", "contextdb-knowledge"];
|
|
@@ -411,7 +415,7 @@ function hookConfigPath(agent) {
|
|
|
411
415
|
case "claude":
|
|
412
416
|
return join(homedir(), ".claude", "settings.json");
|
|
413
417
|
case "workbuddy":
|
|
414
|
-
return join(homedir(), ".workbuddy", "settings.json");
|
|
418
|
+
return join(homedir(), ".workbuddy-ai", "settings.json");
|
|
415
419
|
case "opencode":
|
|
416
420
|
case "hermes":
|
|
417
421
|
return null;
|
|
@@ -724,7 +728,10 @@ async function runSetup(options) {
|
|
|
724
728
|
});
|
|
725
729
|
} else {
|
|
726
730
|
try {
|
|
727
|
-
const client = new HttpClient({
|
|
731
|
+
const client = new HttpClient({
|
|
732
|
+
baseUrl: cfg.baseUrl,
|
|
733
|
+
credential: apiKeyCredential(cfg.apiKey)
|
|
734
|
+
});
|
|
728
735
|
await client.get("/v1/ping/");
|
|
729
736
|
steps.push({ step: "validate-ping", ok: true });
|
|
730
737
|
} catch (err) {
|
|
@@ -1473,7 +1480,7 @@ var SKILL_INSTALL_TARGETS = {
|
|
|
1473
1480
|
opencode: join(homedir(), ".config", "opencode", "skills"),
|
|
1474
1481
|
openclaw: join(homedir(), ".openclaw", "skills"),
|
|
1475
1482
|
hermes: join(homedir(), ".hermes", "skills"),
|
|
1476
|
-
workbuddy: join(homedir(), ".workbuddy", "skills")
|
|
1483
|
+
workbuddy: join(homedir(), ".workbuddy-ai", "skills")
|
|
1477
1484
|
};
|
|
1478
1485
|
function skillInstallTargetPath(target) {
|
|
1479
1486
|
return SKILL_INSTALL_TARGETS[target] ?? null;
|
|
@@ -2090,12 +2097,13 @@ FLAGS
|
|
|
2090
2097
|
`;
|
|
2091
2098
|
async function inspectStatus(agent) {
|
|
2092
2099
|
const cfg = load({ agent });
|
|
2093
|
-
const
|
|
2100
|
+
const credential = resolveDataApiCredential(cfg);
|
|
2101
|
+
const complete = Boolean(cfg.baseUrl && credential);
|
|
2094
2102
|
let connected = false;
|
|
2095
2103
|
let pingError = null;
|
|
2096
|
-
if (complete) {
|
|
2104
|
+
if (complete && credential) {
|
|
2097
2105
|
try {
|
|
2098
|
-
const client = new HttpClient({ baseUrl: cfg.baseUrl,
|
|
2106
|
+
const client = new HttpClient({ baseUrl: cfg.baseUrl, credential });
|
|
2099
2107
|
await client.get("/v1/ping/");
|
|
2100
2108
|
connected = true;
|
|
2101
2109
|
} catch (err) {
|
|
@@ -2110,6 +2118,8 @@ async function inspectStatus(agent) {
|
|
|
2110
2118
|
base_url: cfg.baseUrl,
|
|
2111
2119
|
user_id: cfg.userId,
|
|
2112
2120
|
api_key_set: Boolean(cfg.apiKey),
|
|
2121
|
+
access_token_set: Boolean(process.env.CTXDB_ACCESS_TOKEN?.trim()),
|
|
2122
|
+
credential_type: credential?.type ?? null,
|
|
2113
2123
|
auto_capture: cfg.autoCapture,
|
|
2114
2124
|
auto_recall: cfg.autoRecall,
|
|
2115
2125
|
top_k: cfg.topK,
|
|
@@ -2192,12 +2202,13 @@ ${hint}
|
|
|
2192
2202
|
async function ping(args) {
|
|
2193
2203
|
const agent = agentFromFlags(args.flags);
|
|
2194
2204
|
const cfg = load({ agent });
|
|
2195
|
-
|
|
2205
|
+
const credential = resolveDataApiCredential(cfg);
|
|
2206
|
+
if (!cfg.baseUrl || !credential) {
|
|
2196
2207
|
fail(
|
|
2197
|
-
`config incomplete for agent ${agent} \u2014 run \`ctxdb setup --agent ${agent}\` or set CTXDB_API_KEY / CTXDB_BASE_URL / CTXDB_USER_ID`
|
|
2208
|
+
`config incomplete for agent ${agent} \u2014 run \`ctxdb setup --agent ${agent}\` or set CTXDB_ACCESS_TOKEN / CTXDB_API_KEY / CTXDB_BASE_URL / CTXDB_USER_ID`
|
|
2198
2209
|
);
|
|
2199
2210
|
}
|
|
2200
|
-
const client = new HttpClient({ baseUrl: cfg.baseUrl,
|
|
2211
|
+
const client = new HttpClient({ baseUrl: cfg.baseUrl, credential });
|
|
2201
2212
|
const resp = await client.get("/v1/ping/");
|
|
2202
2213
|
printResult(resp, !!args.flags.json);
|
|
2203
2214
|
return 0;
|
|
@@ -4312,7 +4323,7 @@ COMMANDS
|
|
|
4312
4323
|
Hermes \u2192 writes agents.hermes config + ~/.hermes/config.yaml pre/post_llm_call hooks + skill
|
|
4313
4324
|
Approve pre_llm_call + post_llm_call with \`hermes --accept-hooks chat\`
|
|
4314
4325
|
(exit chat, rerun setup, then restart any running Hermes CLI/gateway)
|
|
4315
|
-
WorkBuddy \u2192 writes agents.workbuddy config + ~/.workbuddy/settings.json hooks + skill
|
|
4326
|
+
WorkBuddy \u2192 writes agents.workbuddy config + ~/.workbuddy-ai/settings.json hooks + skill
|
|
4316
4327
|
--all \u2192 detects and configures every setup-compatible built-in Agent
|
|
4317
4328
|
status [--agent <name> | --all] [--json]
|
|
4318
4329
|
Inspect configuration, connectivity, and integration health.
|
|
@@ -4474,6 +4485,7 @@ AGENT RESOLUTION (when --agent is omitted):
|
|
|
4474
4485
|
ENV VARS (override selected ~/.ctxdb/ctxdb.json agent config):
|
|
4475
4486
|
CTXDB_AGENT CTXDB_API_KEY CTXDB_BASE_URL CTXDB_USER_ID
|
|
4476
4487
|
CTXDB_AGENT_ID CTXDB_APP_ID
|
|
4488
|
+
CTXDB_ACCESS_TOKEN Runtime-only Data API Bearer credential; takes precedence over API key
|
|
4477
4489
|
|
|
4478
4490
|
UPDATE CHECK ENV VARS:
|
|
4479
4491
|
CTXDB_DISABLE_UPDATE_CHECK=1
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
captureParsedMessages
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import {
|
|
7
|
-
shouldSkipHooks
|
|
8
|
-
} from "../chunk-5ML4VSXN.js";
|
|
4
|
+
} from "../chunk-ZFS6OMWE.js";
|
|
5
|
+
import "../chunk-EI63DQX3.js";
|
|
9
6
|
import {
|
|
10
7
|
HttpClient,
|
|
11
8
|
agentFromArgvWithFallback,
|
|
12
9
|
debug,
|
|
13
10
|
load,
|
|
11
|
+
resolveDataApiCredential,
|
|
14
12
|
setDebug
|
|
15
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-BUK4SZC2.js";
|
|
14
|
+
import {
|
|
15
|
+
shouldSkipHooks
|
|
16
|
+
} from "../chunk-5ML4VSXN.js";
|
|
16
17
|
import "../chunk-R67JELM7.js";
|
|
17
18
|
import "../chunk-VIG4SYLU.js";
|
|
18
19
|
|
|
@@ -170,19 +171,20 @@ async function main() {
|
|
|
170
171
|
}
|
|
171
172
|
const input = extractHermesPostLlmCall(event);
|
|
172
173
|
const cfg = load({ agent });
|
|
174
|
+
const credential = resolveDataApiCredential(cfg);
|
|
173
175
|
setDebug(cfg.debug);
|
|
174
176
|
debug("hermes.post_llm_call", "start", {
|
|
175
177
|
sessionId: input.sessionId,
|
|
176
178
|
messageCount: input.messages.length,
|
|
177
179
|
userId: cfg.userId
|
|
178
180
|
});
|
|
179
|
-
if (!cfg.
|
|
181
|
+
if (!cfg.baseUrl || !credential) {
|
|
180
182
|
debug("hermes.post_llm_call", "skip (config incomplete)");
|
|
181
183
|
return 0;
|
|
182
184
|
}
|
|
183
185
|
const client = new HttpClient({
|
|
184
186
|
baseUrl: cfg.baseUrl,
|
|
185
|
-
|
|
187
|
+
credential,
|
|
186
188
|
timeoutMs: 5e3
|
|
187
189
|
});
|
|
188
190
|
const result = await captureParsedMessages(
|
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
import {
|
|
3
3
|
HOOK_TIMEOUT_MS,
|
|
4
4
|
composeSessionStart
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-LZ2LOWZL.js";
|
|
6
6
|
import {
|
|
7
7
|
composeUserPromptSubmit
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-AUBVVYQL.js";
|
|
9
9
|
import {
|
|
10
10
|
fetchKbCatalogBlock
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-7OX6UVPB.js";
|
|
12
|
+
import "../chunk-3NJ37TEY.js";
|
|
12
13
|
import {
|
|
13
14
|
isCircuitOpen
|
|
14
|
-
} from "../chunk-
|
|
15
|
-
import {
|
|
16
|
-
shouldSkipHooks
|
|
17
|
-
} from "../chunk-5ML4VSXN.js";
|
|
18
|
-
import "../chunk-NFAPLK4C.js";
|
|
15
|
+
} from "../chunk-EI63DQX3.js";
|
|
19
16
|
import {
|
|
20
17
|
HttpClient,
|
|
21
18
|
agentFromArgvWithFallback,
|
|
22
19
|
debug,
|
|
23
|
-
isComplete,
|
|
24
20
|
load,
|
|
21
|
+
resolveDataApiCredential,
|
|
25
22
|
setDebug
|
|
26
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-BUK4SZC2.js";
|
|
24
|
+
import {
|
|
25
|
+
shouldSkipHooks
|
|
26
|
+
} from "../chunk-5ML4VSXN.js";
|
|
27
27
|
import "../chunk-R67JELM7.js";
|
|
28
28
|
import "../chunk-VIG4SYLU.js";
|
|
29
29
|
|
|
@@ -109,6 +109,7 @@ async function main() {
|
|
|
109
109
|
}
|
|
110
110
|
const input = extractHermesPreLlmCall(event);
|
|
111
111
|
const cfg = load({ agent });
|
|
112
|
+
const credential = resolveDataApiCredential(cfg);
|
|
112
113
|
setDebug(cfg.debug);
|
|
113
114
|
debug("hermes.pre_llm_call", "start", {
|
|
114
115
|
prompt: input.prompt.slice(0, 200),
|
|
@@ -120,7 +121,7 @@ async function main() {
|
|
|
120
121
|
const wantsRecall = cfg.autoRecall && Boolean(input.prompt.trim());
|
|
121
122
|
const wantsSessionStart = input.isFirstTurn && Boolean(input.cwd) && (cfg.warmupRecall || cfg.kbCatalogInjection === "session_start");
|
|
122
123
|
const wantsRepeatedSessionCatalog = cfg.kbCatalogInjection === "session_start";
|
|
123
|
-
if (!
|
|
124
|
+
if (!cfg.baseUrl || !credential || !wantsRecall && !wantsSessionStart && !wantsRepeatedSessionCatalog) {
|
|
124
125
|
debug("hermes.pre_llm_call", "skip (config incomplete or no enabled injection)");
|
|
125
126
|
return 0;
|
|
126
127
|
}
|
|
@@ -132,7 +133,7 @@ async function main() {
|
|
|
132
133
|
}
|
|
133
134
|
const client = new HttpClient({
|
|
134
135
|
baseUrl: cfg.baseUrl,
|
|
135
|
-
|
|
136
|
+
credential,
|
|
136
137
|
timeoutMs: HOOK_TIMEOUT_MS
|
|
137
138
|
});
|
|
138
139
|
const composed = await composeHermesPreLlmCall(cfg, agent, client, input);
|
|
@@ -3,23 +3,23 @@ import {
|
|
|
3
3
|
HOOK_TIMEOUT_MS,
|
|
4
4
|
composeSessionStart,
|
|
5
5
|
formatSessionStartStdout
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-LZ2LOWZL.js";
|
|
7
|
+
import "../chunk-7OX6UVPB.js";
|
|
8
|
+
import "../chunk-3NJ37TEY.js";
|
|
8
9
|
import {
|
|
9
10
|
isCircuitOpen
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import {
|
|
12
|
-
shouldSkipHooks
|
|
13
|
-
} from "../chunk-5ML4VSXN.js";
|
|
14
|
-
import "../chunk-NFAPLK4C.js";
|
|
11
|
+
} from "../chunk-EI63DQX3.js";
|
|
15
12
|
import {
|
|
16
13
|
HttpClient,
|
|
17
14
|
agentFromArgvWithFallback,
|
|
18
15
|
debug,
|
|
19
|
-
isComplete,
|
|
20
16
|
load,
|
|
17
|
+
resolveDataApiCredential,
|
|
21
18
|
setDebug
|
|
22
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-BUK4SZC2.js";
|
|
20
|
+
import {
|
|
21
|
+
shouldSkipHooks
|
|
22
|
+
} from "../chunk-5ML4VSXN.js";
|
|
23
23
|
import "../chunk-R67JELM7.js";
|
|
24
24
|
import "../chunk-VIG4SYLU.js";
|
|
25
25
|
|
|
@@ -51,10 +51,11 @@ async function main() {
|
|
|
51
51
|
const sessionId = typeof event.session_id === "string" ? event.session_id : typeof event.sessionId === "string" ? event.sessionId : null;
|
|
52
52
|
if (!cwd) return 0;
|
|
53
53
|
const cfg = load({ agent });
|
|
54
|
+
const credential = resolveDataApiCredential(cfg);
|
|
54
55
|
setDebug(cfg.debug);
|
|
55
56
|
debug("warmup", "start", { cwd, userId: cfg.userId });
|
|
56
57
|
const kbInjectHere = cfg.kbCatalogInjection === "session_start";
|
|
57
|
-
if (!
|
|
58
|
+
if (!cfg.baseUrl || !credential || !cfg.warmupRecall && !kbInjectHere) {
|
|
58
59
|
debug("warmup", "skip (config incomplete or both warmup+kb off)");
|
|
59
60
|
return 0;
|
|
60
61
|
}
|
|
@@ -64,7 +65,7 @@ async function main() {
|
|
|
64
65
|
}
|
|
65
66
|
const client = new HttpClient({
|
|
66
67
|
baseUrl: cfg.baseUrl,
|
|
67
|
-
|
|
68
|
+
credential,
|
|
68
69
|
timeoutMs: HOOK_TIMEOUT_MS
|
|
69
70
|
});
|
|
70
71
|
const composed = await composeSessionStart(
|
package/dist/hooks/stop.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
captureTurn
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import {
|
|
7
|
-
shouldSkipHooks
|
|
8
|
-
} from "../chunk-5ML4VSXN.js";
|
|
4
|
+
} from "../chunk-ZFS6OMWE.js";
|
|
5
|
+
import "../chunk-EI63DQX3.js";
|
|
9
6
|
import {
|
|
10
7
|
HttpClient,
|
|
11
8
|
agentFromArgvWithFallback,
|
|
12
9
|
debug,
|
|
13
10
|
load,
|
|
11
|
+
resolveDataApiCredential,
|
|
14
12
|
setDebug
|
|
15
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-BUK4SZC2.js";
|
|
14
|
+
import {
|
|
15
|
+
shouldSkipHooks
|
|
16
|
+
} from "../chunk-5ML4VSXN.js";
|
|
16
17
|
import "../chunk-R67JELM7.js";
|
|
17
18
|
import "../chunk-VIG4SYLU.js";
|
|
18
19
|
|
|
@@ -47,13 +48,14 @@ async function main() {
|
|
|
47
48
|
if (typeof transcriptPath !== "string" || !transcriptPath) return 0;
|
|
48
49
|
const sessionId = extractHookSessionId(event);
|
|
49
50
|
const cfg = load({ agent });
|
|
51
|
+
const credential = resolveDataApiCredential(cfg);
|
|
50
52
|
setDebug(cfg.debug);
|
|
51
53
|
debug("capture", "start", { transcriptPath, userId: cfg.userId });
|
|
52
|
-
if (!cfg.
|
|
54
|
+
if (!cfg.baseUrl || !credential) {
|
|
53
55
|
debug("capture", "skip (config incomplete)");
|
|
54
56
|
return 0;
|
|
55
57
|
}
|
|
56
|
-
const client = new HttpClient({ baseUrl: cfg.baseUrl,
|
|
58
|
+
const client = new HttpClient({ baseUrl: cfg.baseUrl, credential, timeoutMs: 5e3 });
|
|
57
59
|
const result = await captureTurn(transcriptPath, cfg, client, agent, sessionId);
|
|
58
60
|
if (result.captured) {
|
|
59
61
|
debug("capture", `ok (${result.messageCount} msgs)`, result);
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
import {
|
|
3
3
|
composeUserPromptSubmit,
|
|
4
4
|
formatUserPromptSubmitStdout
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-AUBVVYQL.js";
|
|
6
|
+
import "../chunk-7OX6UVPB.js";
|
|
7
|
+
import "../chunk-3NJ37TEY.js";
|
|
7
8
|
import {
|
|
8
9
|
isCircuitOpen
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import {
|
|
11
|
-
shouldSkipHooks
|
|
12
|
-
} from "../chunk-5ML4VSXN.js";
|
|
13
|
-
import "../chunk-NFAPLK4C.js";
|
|
10
|
+
} from "../chunk-EI63DQX3.js";
|
|
14
11
|
import {
|
|
15
12
|
HttpClient,
|
|
16
13
|
agentFromArgvWithFallback,
|
|
17
14
|
debug,
|
|
18
|
-
isComplete,
|
|
19
15
|
load,
|
|
16
|
+
resolveDataApiCredential,
|
|
20
17
|
setDebug
|
|
21
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-BUK4SZC2.js";
|
|
19
|
+
import {
|
|
20
|
+
shouldSkipHooks
|
|
21
|
+
} from "../chunk-5ML4VSXN.js";
|
|
22
22
|
import "../chunk-R67JELM7.js";
|
|
23
23
|
import "../chunk-VIG4SYLU.js";
|
|
24
24
|
|
|
@@ -50,9 +50,10 @@ async function main() {
|
|
|
50
50
|
const sessionId = typeof event.session_id === "string" ? event.session_id : typeof event.sessionId === "string" ? event.sessionId : null;
|
|
51
51
|
if (!prompt.trim()) return 0;
|
|
52
52
|
const cfg = load({ agent });
|
|
53
|
+
const credential = resolveDataApiCredential(cfg);
|
|
53
54
|
setDebug(cfg.debug);
|
|
54
55
|
debug("recall", "start", { prompt: prompt.slice(0, 200), userId: cfg.userId });
|
|
55
|
-
if (!
|
|
56
|
+
if (!cfg.baseUrl || !credential || !cfg.autoRecall) {
|
|
56
57
|
debug("recall", "skip (config incomplete or autoRecall=false)");
|
|
57
58
|
return 0;
|
|
58
59
|
}
|
|
@@ -62,7 +63,7 @@ async function main() {
|
|
|
62
63
|
`);
|
|
63
64
|
return 0;
|
|
64
65
|
}
|
|
65
|
-
const client = new HttpClient({ baseUrl: cfg.baseUrl,
|
|
66
|
+
const client = new HttpClient({ baseUrl: cfg.baseUrl, credential, timeoutMs: 5e3 });
|
|
66
67
|
const { ctx, recall, kbBlock } = await composeUserPromptSubmit(
|
|
67
68
|
cfg,
|
|
68
69
|
agent,
|
package/dist/opencode/index.js
CHANGED
|
@@ -892,6 +892,9 @@ function agentRaw(raw) {
|
|
|
892
892
|
if (!section || typeof section !== "object" || Array.isArray(section)) return {};
|
|
893
893
|
return section;
|
|
894
894
|
}
|
|
895
|
+
function accessTokenFromEnv(env = process.env) {
|
|
896
|
+
return env.CTXDB_ACCESS_TOKEN?.trim() || null;
|
|
897
|
+
}
|
|
895
898
|
function applyEnv(cfg, env) {
|
|
896
899
|
if (env.CTXDB_API_KEY) cfg.apiKey = env.CTXDB_API_KEY;
|
|
897
900
|
if (env.CTXDB_BASE_URL) cfg.baseUrl = env.CTXDB_BASE_URL.replace(/\/+$/, "");
|
|
@@ -976,8 +979,8 @@ function loadOpencodeConfig(options = {}) {
|
|
|
976
979
|
}
|
|
977
980
|
return applyEnv(cfg, env);
|
|
978
981
|
}
|
|
979
|
-
function isConfigured(cfg) {
|
|
980
|
-
return Boolean(cfg.apiKey && cfg.baseUrl);
|
|
982
|
+
function isConfigured(cfg, env = process.env) {
|
|
983
|
+
return Boolean((accessTokenFromEnv(env) || cfg.apiKey) && cfg.baseUrl);
|
|
981
984
|
}
|
|
982
985
|
|
|
983
986
|
// src/http-client.ts
|
|
@@ -995,11 +998,13 @@ var CtxdbHttpError = class extends Error {
|
|
|
995
998
|
var HttpClient = class {
|
|
996
999
|
baseUrl;
|
|
997
1000
|
apiKey;
|
|
1001
|
+
accessToken;
|
|
998
1002
|
userAgent;
|
|
999
1003
|
fetchImpl;
|
|
1000
1004
|
constructor(opts) {
|
|
1001
1005
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
1002
1006
|
this.apiKey = opts.apiKey;
|
|
1007
|
+
this.accessToken = opts.accessToken ?? null;
|
|
1003
1008
|
this.userAgent = opts.userAgent ?? "ctxdb-opencode-plugin/0.0.0";
|
|
1004
1009
|
this.fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
1005
1010
|
}
|
|
@@ -1008,7 +1013,8 @@ var HttpClient = class {
|
|
|
1008
1013
|
"User-Agent": this.userAgent,
|
|
1009
1014
|
Connection: "close"
|
|
1010
1015
|
};
|
|
1011
|
-
if (this.
|
|
1016
|
+
if (this.accessToken) h.Authorization = `Bearer ${this.accessToken}`;
|
|
1017
|
+
else if (this.apiKey) h.Authorization = `Token ${this.apiKey}`;
|
|
1012
1018
|
if (contentType) h["Content-Type"] = contentType;
|
|
1013
1019
|
return h;
|
|
1014
1020
|
}
|
|
@@ -1125,7 +1131,11 @@ async function searchAndFormatRecall(prompt, cfg, client, timeoutMs, traceOption
|
|
|
1125
1131
|
},
|
|
1126
1132
|
store: {
|
|
1127
1133
|
...traceOptions.traceStore,
|
|
1128
|
-
secrets: [
|
|
1134
|
+
secrets: [
|
|
1135
|
+
...traceOptions.traceStore?.secrets ?? [],
|
|
1136
|
+
cfg.apiKey,
|
|
1137
|
+
client.accessToken
|
|
1138
|
+
]
|
|
1129
1139
|
}
|
|
1130
1140
|
} : null;
|
|
1131
1141
|
if (trace) {
|
|
@@ -1454,10 +1464,14 @@ var SESSION_TTL_MS = 15 * 60 * 1e3;
|
|
|
1454
1464
|
var SESSION_MAX = 100;
|
|
1455
1465
|
var RECALL_TIMEOUT_MS = 5e3;
|
|
1456
1466
|
var CAPTURE_TIMEOUT_MS = 8e3;
|
|
1457
|
-
function buildRuntime(config, cwd) {
|
|
1467
|
+
function buildRuntime(config, cwd, env = process.env) {
|
|
1458
1468
|
return {
|
|
1459
1469
|
config,
|
|
1460
|
-
http: new HttpClient({
|
|
1470
|
+
http: new HttpClient({
|
|
1471
|
+
baseUrl: config.baseUrl,
|
|
1472
|
+
apiKey: config.apiKey,
|
|
1473
|
+
accessToken: accessTokenFromEnv(env)
|
|
1474
|
+
}),
|
|
1461
1475
|
sessionState: /* @__PURE__ */ new Map(),
|
|
1462
1476
|
cwd
|
|
1463
1477
|
};
|
|
@@ -1500,7 +1514,7 @@ async function buildHooks(input) {
|
|
|
1500
1514
|
logDebug(
|
|
1501
1515
|
config,
|
|
1502
1516
|
"config",
|
|
1503
|
-
"opencode integration disabled: missing agents.opencode.api_key
|
|
1517
|
+
"opencode integration disabled: missing CTXDB_ACCESS_TOKEN or API key in agents.opencode.api_key / CTXDB_API_KEY"
|
|
1504
1518
|
);
|
|
1505
1519
|
return {};
|
|
1506
1520
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliyunrds/ctxdb",
|
|
3
|
-
"version": "1.0.8-beta.
|
|
3
|
+
"version": "1.0.8-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified access layer for RDS ContextDatabase: `ctxdb` CLI (memory + KB ops), one-shot multi-agent installer, per-agent config, hooks/plugins, and SKILL.md.",
|
|
6
6
|
"license": "Apache-2.0",
|