@remnic/plugin-openclaw 9.54.4 → 9.54.6
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 +5 -1
- package/dist/chunk-HDTN2ZKK.js +40 -0
- package/dist/index.js +520 -102
- package/dist/support-passport-model-route.d.ts +7 -0
- package/dist/support-passport-model-route.js +7 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +9 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOpenClawSupportPassportModelRoute
|
|
3
|
+
} from "./chunk-HDTN2ZKK.js";
|
|
1
4
|
import {
|
|
2
5
|
__export,
|
|
3
6
|
__reExport
|
|
@@ -214,6 +217,49 @@ import {
|
|
|
214
217
|
|
|
215
218
|
// ../../src/tools.ts
|
|
216
219
|
import { runMemoryGovernance } from "@remnic/core/maintenance/memory-governance";
|
|
220
|
+
|
|
221
|
+
// ../../src/memory-action-target.ts
|
|
222
|
+
import { isSupportPassportPrivateMemory } from "@remnic/core";
|
|
223
|
+
function clampUnitInterval(value, fallback) {
|
|
224
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
225
|
+
if (value < 0) return 0;
|
|
226
|
+
if (value > 1) return 1;
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
function normalizeEligibilitySource(value) {
|
|
230
|
+
switch (value) {
|
|
231
|
+
case "extraction":
|
|
232
|
+
case "consolidation":
|
|
233
|
+
case "replay":
|
|
234
|
+
case "manual":
|
|
235
|
+
return value;
|
|
236
|
+
default:
|
|
237
|
+
return "unknown";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function deriveMemoryActionPolicyEligibility(memory) {
|
|
241
|
+
if (!memory) return void 0;
|
|
242
|
+
const frontmatter = memory.frontmatter;
|
|
243
|
+
return {
|
|
244
|
+
confidence: clampUnitInterval(frontmatter.confidence, 0),
|
|
245
|
+
lifecycleState: frontmatter.status === "archived" ? "archived" : frontmatter.lifecycleState ?? "candidate",
|
|
246
|
+
importance: clampUnitInterval(frontmatter.importance?.score, 0),
|
|
247
|
+
source: normalizeEligibilitySource(frontmatter.source)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async function readReferencedMemoryForPolicyEligibility(storage, memoryId) {
|
|
251
|
+
if (!memoryId) return void 0;
|
|
252
|
+
const direct = await storage.getMemoryById?.(memoryId);
|
|
253
|
+
if (direct) return direct;
|
|
254
|
+
const active = (await storage.readAllMemories?.())?.find((memory) => memory.frontmatter.id === memoryId);
|
|
255
|
+
if (active) return active;
|
|
256
|
+
return (await storage.readArchivedMemories?.())?.find((memory) => memory.frontmatter.id === memoryId);
|
|
257
|
+
}
|
|
258
|
+
function blocksSupportPassportMutation(action, memory) {
|
|
259
|
+
return (action === "update_note" || action === "discard" || action === "link_graph") && Boolean(memory && isSupportPassportPrivateMemory(memory));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ../../src/tools.ts
|
|
217
263
|
function toolResult(text) {
|
|
218
264
|
return { content: [{ type: "text", text }], details: void 0 };
|
|
219
265
|
}
|
|
@@ -232,12 +278,6 @@ function asNonEmptyString(value) {
|
|
|
232
278
|
function normalizeToolNamespace(value) {
|
|
233
279
|
return asNonEmptyString(value);
|
|
234
280
|
}
|
|
235
|
-
function clampUnitInterval(value, fallback) {
|
|
236
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
237
|
-
if (value < 0) return 0;
|
|
238
|
-
if (value > 1) return 1;
|
|
239
|
-
return value;
|
|
240
|
-
}
|
|
241
281
|
function normalizeProfilingReportLimit(value) {
|
|
242
282
|
if (value === void 0) return 5;
|
|
243
283
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
@@ -252,43 +292,7 @@ function normalizeMemorySearchResultLimit(value) {
|
|
|
252
292
|
}
|
|
253
293
|
return Math.min(Math.max(value, 1), 50);
|
|
254
294
|
}
|
|
255
|
-
|
|
256
|
-
switch (value) {
|
|
257
|
-
case "extraction":
|
|
258
|
-
case "consolidation":
|
|
259
|
-
case "replay":
|
|
260
|
-
case "manual":
|
|
261
|
-
return value;
|
|
262
|
-
default:
|
|
263
|
-
return "unknown";
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function deriveMemoryActionPolicyEligibility(memory) {
|
|
267
|
-
if (!memory) return void 0;
|
|
268
|
-
const frontmatter = memory.frontmatter;
|
|
269
|
-
return {
|
|
270
|
-
confidence: clampUnitInterval(frontmatter.confidence, 0),
|
|
271
|
-
lifecycleState: frontmatter.status === "archived" ? "archived" : frontmatter.lifecycleState ?? "candidate",
|
|
272
|
-
importance: clampUnitInterval(frontmatter.importance?.score, 0),
|
|
273
|
-
source: normalizeMemoryActionEligibilitySource(frontmatter.source)
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
async function readReferencedMemoryForPolicyEligibility(storage, memoryId) {
|
|
277
|
-
if (!memoryId) return void 0;
|
|
278
|
-
if (typeof storage.getMemoryById === "function") {
|
|
279
|
-
const direct = await storage.getMemoryById(memoryId);
|
|
280
|
-
if (direct) return direct;
|
|
281
|
-
}
|
|
282
|
-
if (typeof storage.readAllMemories === "function") {
|
|
283
|
-
const active = (await storage.readAllMemories()).find((memory) => memory.frontmatter.id === memoryId);
|
|
284
|
-
if (active) return active;
|
|
285
|
-
}
|
|
286
|
-
if (typeof storage.readArchivedMemories === "function") {
|
|
287
|
-
const archived = (await storage.readArchivedMemories()).find((memory) => memory.frontmatter.id === memoryId);
|
|
288
|
-
if (archived) return archived;
|
|
289
|
-
}
|
|
290
|
-
return void 0;
|
|
291
|
-
}
|
|
295
|
+
var MEMORY_SEARCH_CANDIDATE_CAP = 25e3;
|
|
292
296
|
var WORK_TASK_STATUSES = /* @__PURE__ */ new Set(["todo", "in_progress", "blocked", "done", "cancelled"]);
|
|
293
297
|
var WORK_TASK_PRIORITIES = /* @__PURE__ */ new Set(["low", "medium", "high"]);
|
|
294
298
|
var WORK_PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "on_hold", "completed", "archived"]);
|
|
@@ -568,12 +572,39 @@ Best for:
|
|
|
568
572
|
const { query, maxResults, collection, namespace } = params;
|
|
569
573
|
const namespaceFilter = namespace && namespace.length > 0 ? namespace : void 0;
|
|
570
574
|
const resultLimit = normalizeMemorySearchResultLimit(maxResults);
|
|
571
|
-
const
|
|
575
|
+
const searchCandidates = async (limit) => collection === "global" && !namespaceFilter ? await orchestrator.qmd.searchGlobal(query, limit) : await orchestrator.searchAcrossNamespaces({
|
|
572
576
|
query,
|
|
573
577
|
namespaces: namespaceFilter ? [namespaceFilter] : void 0,
|
|
574
|
-
maxResults:
|
|
578
|
+
maxResults: limit,
|
|
575
579
|
mode: "search"
|
|
576
580
|
});
|
|
581
|
+
let candidateLimit = resultLimit;
|
|
582
|
+
const privateVisibilityCache = /* @__PURE__ */ new Map();
|
|
583
|
+
let candidates = await searchCandidates(candidateLimit);
|
|
584
|
+
let filtered = await orchestrator.filterPrivateSearchResults(
|
|
585
|
+
candidates,
|
|
586
|
+
namespaceFilter ? [namespaceFilter] : [],
|
|
587
|
+
false,
|
|
588
|
+
privateVisibilityCache
|
|
589
|
+
);
|
|
590
|
+
while (filtered.length < resultLimit && candidates.length >= candidateLimit && candidateLimit < MEMORY_SEARCH_CANDIDATE_CAP) {
|
|
591
|
+
const nextCandidateLimit = Math.min(
|
|
592
|
+
MEMORY_SEARCH_CANDIDATE_CAP,
|
|
593
|
+
Math.max(candidateLimit + 16, candidateLimit * 2)
|
|
594
|
+
);
|
|
595
|
+
if (nextCandidateLimit === candidateLimit) break;
|
|
596
|
+
const nextCandidates = await searchCandidates(nextCandidateLimit);
|
|
597
|
+
if (nextCandidates.length <= candidates.length) break;
|
|
598
|
+
candidateLimit = nextCandidateLimit;
|
|
599
|
+
candidates = nextCandidates;
|
|
600
|
+
filtered = await orchestrator.filterPrivateSearchResults(
|
|
601
|
+
candidates,
|
|
602
|
+
namespaceFilter ? [namespaceFilter] : [],
|
|
603
|
+
false,
|
|
604
|
+
privateVisibilityCache
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
filtered = filtered.slice(0, resultLimit);
|
|
577
608
|
if (filtered.length === 0) {
|
|
578
609
|
return toolResult(`No memories found matching: "${query}"`);
|
|
579
610
|
}
|
|
@@ -1600,6 +1631,19 @@ NOTE: You did not provide sessionKey; under concurrency this may not match your
|
|
|
1600
1631
|
}
|
|
1601
1632
|
const storage = typeof orchestrator.getStorage === "function" ? await orchestrator.getStorage(ns) : orchestrator.storage;
|
|
1602
1633
|
const referencedMemory = await readReferencedMemoryForPolicyEligibility(storage, memoryIdValue);
|
|
1634
|
+
if (blocksSupportPassportMutation(action, referencedMemory)) {
|
|
1635
|
+
await orchestrator.appendMemoryActionEvent({
|
|
1636
|
+
...baseEvent,
|
|
1637
|
+
outcome: "failed",
|
|
1638
|
+
status: "rejected",
|
|
1639
|
+
dryRun: dryRun === true,
|
|
1640
|
+
outputMemoryIds: [],
|
|
1641
|
+
reason: "validation: support passport records require the owner surface"
|
|
1642
|
+
});
|
|
1643
|
+
return toolResult(
|
|
1644
|
+
"Validation failed: support passport records can only be changed through the support passport owner surface."
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1603
1647
|
const structuredEvent = {
|
|
1604
1648
|
...baseEvent,
|
|
1605
1649
|
outcome: outcome ?? "applied",
|
|
@@ -3062,8 +3106,8 @@ import { registerLcmTools } from "@remnic/core/lcm/index";
|
|
|
3062
3106
|
import { estimateTokens as estimateLcmTokens } from "@remnic/core/lcm/archive";
|
|
3063
3107
|
import { registerCli } from "@remnic/core/cli";
|
|
3064
3108
|
import {
|
|
3065
|
-
FallbackLlmClient,
|
|
3066
|
-
fallbackLlmRuntimeContextFromConfig
|
|
3109
|
+
FallbackLlmClient as FallbackLlmClient2,
|
|
3110
|
+
fallbackLlmRuntimeContextFromConfig as fallbackLlmRuntimeContextFromConfig2
|
|
3067
3111
|
} from "@remnic/core/fallback-llm";
|
|
3068
3112
|
|
|
3069
3113
|
// ../../src/objective-state.ts
|
|
@@ -3092,8 +3136,36 @@ async function probeQmdAvailability(host) {
|
|
|
3092
3136
|
|
|
3093
3137
|
// ../../src/access-service.ts
|
|
3094
3138
|
var access_service_exports = {};
|
|
3139
|
+
__export(access_service_exports, {
|
|
3140
|
+
EngramAccessService: () => EngramAccessService,
|
|
3141
|
+
createConfiguredSupportPassportGatewayRoute: () => createConfiguredSupportPassportGatewayRoute
|
|
3142
|
+
});
|
|
3095
3143
|
__reExport(access_service_exports, access_service_star);
|
|
3096
3144
|
import * as access_service_star from "@remnic/core/access-service";
|
|
3145
|
+
import { EngramAccessService as CoreEngramAccessService } from "@remnic/core/access-service";
|
|
3146
|
+
import { FallbackLlmClient, fallbackLlmRuntimeContextFromConfig } from "@remnic/core/fallback-llm";
|
|
3147
|
+
import { createOpenClawSupportPassportModelRoute as createOpenClawSupportPassportModelRoute2 } from "@remnic/plugin-openclaw/support-passport-model-route";
|
|
3148
|
+
function createConfiguredSupportPassportGatewayRoute(config, preferredClient) {
|
|
3149
|
+
const gatewayClient = preferredClient ?? (config.gatewayConfig ? new FallbackLlmClient(
|
|
3150
|
+
config.gatewayConfig,
|
|
3151
|
+
fallbackLlmRuntimeContextFromConfig(config)
|
|
3152
|
+
) : null);
|
|
3153
|
+
return gatewayClient ? createOpenClawSupportPassportModelRoute2(config, gatewayClient) : null;
|
|
3154
|
+
}
|
|
3155
|
+
var EngramAccessService = class extends CoreEngramAccessService {
|
|
3156
|
+
supportPassportGatewayRoute;
|
|
3157
|
+
constructor(orchestrator, options = {}) {
|
|
3158
|
+
super(orchestrator, options);
|
|
3159
|
+
const injectedRoute = super.supportPassportGatewayRouteRef;
|
|
3160
|
+
this.supportPassportGatewayRoute = injectedRoute ?? createConfiguredSupportPassportGatewayRoute(
|
|
3161
|
+
orchestrator.config,
|
|
3162
|
+
orchestrator.fastGatewayLlm
|
|
3163
|
+
);
|
|
3164
|
+
}
|
|
3165
|
+
get supportPassportGatewayRouteRef() {
|
|
3166
|
+
return this.supportPassportGatewayRoute;
|
|
3167
|
+
}
|
|
3168
|
+
};
|
|
3097
3169
|
|
|
3098
3170
|
// ../../src/access-http.ts
|
|
3099
3171
|
var access_http_exports = {};
|
|
@@ -5323,7 +5395,7 @@ import path8 from "path";
|
|
|
5323
5395
|
import {
|
|
5324
5396
|
renderMemoryContextPrompt
|
|
5325
5397
|
} from "@remnic/core";
|
|
5326
|
-
import { log as
|
|
5398
|
+
import { log as log7 } from "@remnic/core/logger";
|
|
5327
5399
|
|
|
5328
5400
|
// src/delegate-authorization.ts
|
|
5329
5401
|
import { log as log2 } from "@remnic/core/logger";
|
|
@@ -7639,8 +7711,301 @@ function registerDelegateMemoryCapability(api, options) {
|
|
|
7639
7711
|
return built;
|
|
7640
7712
|
}
|
|
7641
7713
|
|
|
7714
|
+
// src/delegate-support-passport-model.ts
|
|
7715
|
+
import {
|
|
7716
|
+
SUPPORT_PASSPORT_MODEL_ACK_PATH,
|
|
7717
|
+
SUPPORT_PASSPORT_MODEL_JOB_PATH,
|
|
7718
|
+
SUPPORT_PASSPORT_MODEL_RESULT_PATH,
|
|
7719
|
+
acceptsSupportPassportModelResponse,
|
|
7720
|
+
parseSupportPassportModelJob
|
|
7721
|
+
} from "@remnic/core";
|
|
7722
|
+
import { log as log6 } from "@remnic/core/logger";
|
|
7723
|
+
var MODEL_WORKER_COUNT = 4;
|
|
7724
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 25e3;
|
|
7725
|
+
var RESULT_REQUEST_TIMEOUT_MS = 5e3;
|
|
7726
|
+
var RESULT_RETRY_DELAY_MS = 1e3;
|
|
7727
|
+
var POLL_RETRY_MAX_DELAY_MS = 3e4;
|
|
7728
|
+
var SHUTDOWN_RESULT_REQUEST_TIMEOUT_MS = 250;
|
|
7729
|
+
function supportPassportModelPollRetryDelayMs(consecutiveFailures) {
|
|
7730
|
+
const exponent = Math.max(0, Math.min(30, Math.floor(consecutiveFailures) - 1));
|
|
7731
|
+
return Math.min(POLL_RETRY_MAX_DELAY_MS, RESULT_RETRY_DELAY_MS * 2 ** exponent);
|
|
7732
|
+
}
|
|
7733
|
+
async function post(target, serviceId, pathname, body, signal, timeoutMs) {
|
|
7734
|
+
const auth = target.resolveAuthToken();
|
|
7735
|
+
const requestSignal = AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]);
|
|
7736
|
+
const response = await fetch(daemonUrl(target, pathname), {
|
|
7737
|
+
method: "POST",
|
|
7738
|
+
headers: {
|
|
7739
|
+
"content-type": "application/json",
|
|
7740
|
+
...auth.token ? { Authorization: `Bearer ${auth.token}` } : {}
|
|
7741
|
+
},
|
|
7742
|
+
body: JSON.stringify(body),
|
|
7743
|
+
signal: requestSignal
|
|
7744
|
+
});
|
|
7745
|
+
if (response.status === 401 || response.status === 403) {
|
|
7746
|
+
reportDaemonAuthorizationFailure(serviceId, pathname, response.status, auth.source);
|
|
7747
|
+
}
|
|
7748
|
+
return response;
|
|
7749
|
+
}
|
|
7750
|
+
function abortableRetryDelay(signal, delayMs = RESULT_RETRY_DELAY_MS) {
|
|
7751
|
+
if (signal.aborted) return Promise.resolve();
|
|
7752
|
+
return new Promise((resolve) => {
|
|
7753
|
+
const done = () => {
|
|
7754
|
+
clearTimeout(timeout);
|
|
7755
|
+
signal.removeEventListener("abort", done);
|
|
7756
|
+
resolve();
|
|
7757
|
+
};
|
|
7758
|
+
const timeout = setTimeout(done, delayMs);
|
|
7759
|
+
signal.addEventListener("abort", done, { once: true });
|
|
7760
|
+
});
|
|
7761
|
+
}
|
|
7762
|
+
function createDelegateSupportPassportModelService(options) {
|
|
7763
|
+
let controller;
|
|
7764
|
+
let worker;
|
|
7765
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
7766
|
+
if (!Number.isInteger(requestTimeoutMs) || requestTimeoutMs < 1) {
|
|
7767
|
+
throw new Error("requestTimeoutMs must be a positive integer");
|
|
7768
|
+
}
|
|
7769
|
+
const invoke = async (job, signal) => {
|
|
7770
|
+
const timeoutSignal = AbortSignal.timeout(job.timeoutMs);
|
|
7771
|
+
const modelSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
7772
|
+
if (modelSignal.aborted) return null;
|
|
7773
|
+
let removeAbort = () => {
|
|
7774
|
+
};
|
|
7775
|
+
const aborted = new Promise((resolve) => {
|
|
7776
|
+
const onAbort = () => resolve(null);
|
|
7777
|
+
modelSignal.addEventListener("abort", onAbort, { once: true });
|
|
7778
|
+
removeAbort = () => modelSignal.removeEventListener("abort", onAbort);
|
|
7779
|
+
});
|
|
7780
|
+
try {
|
|
7781
|
+
return await Promise.race([
|
|
7782
|
+
options.route.invoke(job.messages, {
|
|
7783
|
+
temperature: job.temperature,
|
|
7784
|
+
maxTokens: job.maxTokens,
|
|
7785
|
+
timeoutMs: job.timeoutMs,
|
|
7786
|
+
signal: modelSignal,
|
|
7787
|
+
operation: job.operation,
|
|
7788
|
+
jsonSchema: job.jsonSchema,
|
|
7789
|
+
acceptResponse: (candidate) => acceptsSupportPassportModelResponse(job.operation, job.messages, candidate.content)
|
|
7790
|
+
}),
|
|
7791
|
+
aborted
|
|
7792
|
+
]);
|
|
7793
|
+
} catch (error) {
|
|
7794
|
+
if (!modelSignal.aborted) {
|
|
7795
|
+
log6.warn(`delegate support passport model call failed: ${String(error)}`);
|
|
7796
|
+
}
|
|
7797
|
+
return null;
|
|
7798
|
+
} finally {
|
|
7799
|
+
removeAbort();
|
|
7800
|
+
}
|
|
7801
|
+
};
|
|
7802
|
+
const completeDuringShutdown = async (job, deadline) => {
|
|
7803
|
+
const remainingMs = deadline - Date.now();
|
|
7804
|
+
if (remainingMs <= 0) return;
|
|
7805
|
+
const shutdownTimeoutMs = Math.min(SHUTDOWN_RESULT_REQUEST_TIMEOUT_MS, remainingMs);
|
|
7806
|
+
const completion = await post(
|
|
7807
|
+
options.target,
|
|
7808
|
+
options.serviceId,
|
|
7809
|
+
SUPPORT_PASSPORT_MODEL_RESULT_PATH,
|
|
7810
|
+
{ id: job.id, claimId: job.claimId, result: null },
|
|
7811
|
+
AbortSignal.timeout(shutdownTimeoutMs),
|
|
7812
|
+
shutdownTimeoutMs
|
|
7813
|
+
);
|
|
7814
|
+
await completion.body?.cancel();
|
|
7815
|
+
if (!completion.ok && completion.status !== 404) {
|
|
7816
|
+
throw new Error(`delegate support passport model completion was rejected with HTTP ${completion.status}`);
|
|
7817
|
+
}
|
|
7818
|
+
};
|
|
7819
|
+
const complete = async (job, result, signal, deadline, serviceSignal, onAccepted) => {
|
|
7820
|
+
if (signal.aborted) {
|
|
7821
|
+
if (serviceSignal.aborted) await completeDuringShutdown(job, deadline);
|
|
7822
|
+
return;
|
|
7823
|
+
}
|
|
7824
|
+
let lastFailure = "the job deadline elapsed";
|
|
7825
|
+
while (!signal.aborted && Date.now() < deadline) {
|
|
7826
|
+
const remainingMs = deadline - Date.now();
|
|
7827
|
+
let completion;
|
|
7828
|
+
try {
|
|
7829
|
+
completion = await post(
|
|
7830
|
+
options.target,
|
|
7831
|
+
options.serviceId,
|
|
7832
|
+
SUPPORT_PASSPORT_MODEL_RESULT_PATH,
|
|
7833
|
+
{ id: job.id, claimId: job.claimId, result },
|
|
7834
|
+
signal,
|
|
7835
|
+
Math.min(RESULT_REQUEST_TIMEOUT_MS, remainingMs)
|
|
7836
|
+
);
|
|
7837
|
+
} catch (error) {
|
|
7838
|
+
if (signal.aborted) {
|
|
7839
|
+
if (serviceSignal.aborted) await completeDuringShutdown(job, deadline);
|
|
7840
|
+
return;
|
|
7841
|
+
}
|
|
7842
|
+
lastFailure = String(error);
|
|
7843
|
+
const retryDelayMs2 = Math.min(RESULT_RETRY_DELAY_MS, deadline - Date.now());
|
|
7844
|
+
if (retryDelayMs2 > 0) await abortableRetryDelay(signal, retryDelayMs2);
|
|
7845
|
+
continue;
|
|
7846
|
+
}
|
|
7847
|
+
const status = completion.status;
|
|
7848
|
+
if (completion.ok) {
|
|
7849
|
+
onAccepted();
|
|
7850
|
+
await completion.body?.cancel().catch(() => void 0);
|
|
7851
|
+
return;
|
|
7852
|
+
}
|
|
7853
|
+
await completion.body?.cancel();
|
|
7854
|
+
if (status !== 408 && status !== 425 && status !== 429 && status < 500) {
|
|
7855
|
+
throw new Error(`delegate support passport model completion was rejected with HTTP ${status}`);
|
|
7856
|
+
}
|
|
7857
|
+
if (signal.aborted) {
|
|
7858
|
+
if (serviceSignal.aborted) await completeDuringShutdown(job, deadline);
|
|
7859
|
+
return;
|
|
7860
|
+
}
|
|
7861
|
+
lastFailure = `HTTP ${status}`;
|
|
7862
|
+
const retryDelayMs = Math.min(RESULT_RETRY_DELAY_MS, deadline - Date.now());
|
|
7863
|
+
if (retryDelayMs > 0) await abortableRetryDelay(signal, retryDelayMs);
|
|
7864
|
+
}
|
|
7865
|
+
if (signal.aborted) {
|
|
7866
|
+
if (serviceSignal.aborted) await completeDuringShutdown(job, deadline);
|
|
7867
|
+
return;
|
|
7868
|
+
}
|
|
7869
|
+
throw new Error(`delegate support passport model completion missed its deadline after ${lastFailure}`);
|
|
7870
|
+
};
|
|
7871
|
+
const acknowledge = async (job, signal, timeoutMs, settleOnShutdown = false) => {
|
|
7872
|
+
if (!job.claimId) return true;
|
|
7873
|
+
const deadline = Date.now() + Math.min(job.timeoutMs, timeoutMs);
|
|
7874
|
+
while (!signal.aborted && Date.now() < deadline) {
|
|
7875
|
+
const remainingMs = deadline - Date.now();
|
|
7876
|
+
try {
|
|
7877
|
+
const response = await post(
|
|
7878
|
+
options.target,
|
|
7879
|
+
options.serviceId,
|
|
7880
|
+
SUPPORT_PASSPORT_MODEL_ACK_PATH,
|
|
7881
|
+
{ id: job.id, claimId: job.claimId },
|
|
7882
|
+
signal,
|
|
7883
|
+
Math.min(RESULT_REQUEST_TIMEOUT_MS, remainingMs)
|
|
7884
|
+
);
|
|
7885
|
+
const status = response.status;
|
|
7886
|
+
await response.body?.cancel();
|
|
7887
|
+
if (response.ok) return true;
|
|
7888
|
+
if (status !== 408 && status !== 425 && status !== 429 && status < 500) return false;
|
|
7889
|
+
} catch {
|
|
7890
|
+
if (signal.aborted) {
|
|
7891
|
+
if (settleOnShutdown) await completeDuringShutdown(job, deadline);
|
|
7892
|
+
return false;
|
|
7893
|
+
}
|
|
7894
|
+
}
|
|
7895
|
+
const retryDelayMs = Math.min(RESULT_RETRY_DELAY_MS, deadline - Date.now());
|
|
7896
|
+
if (retryDelayMs > 0) await abortableRetryDelay(signal, retryDelayMs);
|
|
7897
|
+
}
|
|
7898
|
+
if (signal.aborted && settleOnShutdown) await completeDuringShutdown(job, deadline);
|
|
7899
|
+
return false;
|
|
7900
|
+
};
|
|
7901
|
+
const maintainClaim = async (job, signal, deadline) => {
|
|
7902
|
+
if (!job.claimId || !job.executionLeaseTimeoutMs) return;
|
|
7903
|
+
const renewalDelayMs = Math.max(1, Math.floor(job.executionLeaseTimeoutMs / 3));
|
|
7904
|
+
const renewalTimeoutMs = Math.max(1, job.executionLeaseTimeoutMs - renewalDelayMs);
|
|
7905
|
+
while (!signal.aborted && Date.now() < deadline) {
|
|
7906
|
+
await abortableRetryDelay(signal, Math.min(renewalDelayMs, deadline - Date.now()));
|
|
7907
|
+
if (signal.aborted || Date.now() >= deadline) return;
|
|
7908
|
+
if (!await acknowledge(job, signal, Math.min(renewalTimeoutMs, deadline - Date.now()))) {
|
|
7909
|
+
throw new Error("delegate support passport model claim lease renewal failed");
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
};
|
|
7913
|
+
const runPoller = async (signal) => {
|
|
7914
|
+
let consecutiveFailures = 0;
|
|
7915
|
+
const delayAfterFailure = async () => {
|
|
7916
|
+
consecutiveFailures += 1;
|
|
7917
|
+
await abortableRetryDelay(signal, supportPassportModelPollRetryDelayMs(consecutiveFailures));
|
|
7918
|
+
};
|
|
7919
|
+
while (!signal.aborted) {
|
|
7920
|
+
try {
|
|
7921
|
+
const response = await post(
|
|
7922
|
+
options.target,
|
|
7923
|
+
options.serviceId,
|
|
7924
|
+
SUPPORT_PASSPORT_MODEL_JOB_PATH,
|
|
7925
|
+
{ timeoutMs: 2e4, claimLease: true },
|
|
7926
|
+
signal,
|
|
7927
|
+
requestTimeoutMs
|
|
7928
|
+
);
|
|
7929
|
+
if (response.status === 204) {
|
|
7930
|
+
consecutiveFailures = 0;
|
|
7931
|
+
continue;
|
|
7932
|
+
}
|
|
7933
|
+
if (!response.ok) {
|
|
7934
|
+
await response.body?.cancel();
|
|
7935
|
+
await delayAfterFailure();
|
|
7936
|
+
continue;
|
|
7937
|
+
}
|
|
7938
|
+
const job = parseSupportPassportModelJob(await response.json());
|
|
7939
|
+
if (!job) {
|
|
7940
|
+
log6.warn("delegate support passport model bridge received an invalid job");
|
|
7941
|
+
await delayAfterFailure();
|
|
7942
|
+
continue;
|
|
7943
|
+
}
|
|
7944
|
+
consecutiveFailures = 0;
|
|
7945
|
+
const deadline = Date.now() + job.timeoutMs;
|
|
7946
|
+
if (!await acknowledge(job, signal, job.claimAckTimeoutMs ?? job.timeoutMs, true)) {
|
|
7947
|
+
log6.warn("delegate support passport model bridge could not acknowledge a claimed job");
|
|
7948
|
+
await delayAfterFailure();
|
|
7949
|
+
continue;
|
|
7950
|
+
}
|
|
7951
|
+
const remainingMs = deadline - Date.now();
|
|
7952
|
+
if (remainingMs <= 0) continue;
|
|
7953
|
+
const claimedJob = { ...job, timeoutMs: remainingMs };
|
|
7954
|
+
const heartbeatController = new AbortController();
|
|
7955
|
+
const workController = new AbortController();
|
|
7956
|
+
const heartbeatSignal = AbortSignal.any([signal, heartbeatController.signal]);
|
|
7957
|
+
const workSignal = AbortSignal.any([signal, workController.signal]);
|
|
7958
|
+
let heartbeatError;
|
|
7959
|
+
let completionAccepted = false;
|
|
7960
|
+
const heartbeat = maintainClaim(claimedJob, heartbeatSignal, deadline).catch((error) => {
|
|
7961
|
+
if (heartbeatSignal.aborted || completionAccepted) return;
|
|
7962
|
+
heartbeatError = error;
|
|
7963
|
+
workController.abort();
|
|
7964
|
+
});
|
|
7965
|
+
try {
|
|
7966
|
+
const result = await invoke(claimedJob, workSignal);
|
|
7967
|
+
if (heartbeatError) throw heartbeatError;
|
|
7968
|
+
await complete(claimedJob, result, workSignal, deadline, signal, () => {
|
|
7969
|
+
completionAccepted = true;
|
|
7970
|
+
});
|
|
7971
|
+
if (heartbeatError && !completionAccepted) throw heartbeatError;
|
|
7972
|
+
} catch (error) {
|
|
7973
|
+
log6.warn(`delegate support passport model completion failed: ${String(error)}`);
|
|
7974
|
+
} finally {
|
|
7975
|
+
heartbeatController.abort();
|
|
7976
|
+
workController.abort();
|
|
7977
|
+
await heartbeat;
|
|
7978
|
+
}
|
|
7979
|
+
} catch (error) {
|
|
7980
|
+
if (signal.aborted) break;
|
|
7981
|
+
log6.warn(`delegate support passport model bridge failed: ${String(error)}`);
|
|
7982
|
+
await delayAfterFailure();
|
|
7983
|
+
}
|
|
7984
|
+
}
|
|
7985
|
+
};
|
|
7986
|
+
const run = async (signal) => {
|
|
7987
|
+
await Promise.all(Array.from({ length: MODEL_WORKER_COUNT }, () => runPoller(signal)));
|
|
7988
|
+
};
|
|
7989
|
+
return {
|
|
7990
|
+
id: `${options.serviceId}:support-passport-model`,
|
|
7991
|
+
async start() {
|
|
7992
|
+
if (worker) return;
|
|
7993
|
+
controller = new AbortController();
|
|
7994
|
+
worker = run(controller.signal).finally(() => {
|
|
7995
|
+
worker = void 0;
|
|
7996
|
+
controller = void 0;
|
|
7997
|
+
});
|
|
7998
|
+
},
|
|
7999
|
+
async stop() {
|
|
8000
|
+
controller?.abort();
|
|
8001
|
+
await worker;
|
|
8002
|
+
}
|
|
8003
|
+
};
|
|
8004
|
+
}
|
|
8005
|
+
|
|
7642
8006
|
// src/delegate-runtime.ts
|
|
7643
8007
|
var DELEGATE_BATCH_FLUSH_CACHE_TTL_MS = 3e4;
|
|
8008
|
+
var delegatePassportServiceApiServices = /* @__PURE__ */ new WeakMap();
|
|
7644
8009
|
function sessionKeyFrom(event, ctx) {
|
|
7645
8010
|
const fromCtx = ctx?.sessionKey;
|
|
7646
8011
|
if (typeof fromCtx === "string" && fromCtx.length > 0) return fromCtx;
|
|
@@ -7691,9 +8056,34 @@ function readContextComposition(response, fallbackContext) {
|
|
|
7691
8056
|
function registerDelegateRuntime(api, options) {
|
|
7692
8057
|
const { target, namespace, namespaceBindings } = options;
|
|
7693
8058
|
const now = options.now ?? Date.now;
|
|
8059
|
+
if (options.supportPassportModelRoute) {
|
|
8060
|
+
const registeredServices = delegatePassportServiceApiServices.get(api);
|
|
8061
|
+
if (registeredServices?.has(options.serviceId)) {
|
|
8062
|
+
log7.debug(
|
|
8063
|
+
`delegate register: ${options.serviceId} already has its support passport model service on this api`
|
|
8064
|
+
);
|
|
8065
|
+
} else if (typeof api.registerService !== "function") {
|
|
8066
|
+
log7.error(
|
|
8067
|
+
`[${options.serviceId}] delegate support passport gateway routing is unavailable: host exposes no service registration surface`
|
|
8068
|
+
);
|
|
8069
|
+
} else {
|
|
8070
|
+
api.registerService(
|
|
8071
|
+
createDelegateSupportPassportModelService({
|
|
8072
|
+
serviceId: options.serviceId,
|
|
8073
|
+
target,
|
|
8074
|
+
route: options.supportPassportModelRoute
|
|
8075
|
+
})
|
|
8076
|
+
);
|
|
8077
|
+
const services = registeredServices ?? /* @__PURE__ */ new Set();
|
|
8078
|
+
services.add(options.serviceId);
|
|
8079
|
+
if (registeredServices === void 0) {
|
|
8080
|
+
delegatePassportServiceApiServices.set(api, services);
|
|
8081
|
+
}
|
|
8082
|
+
}
|
|
8083
|
+
}
|
|
7694
8084
|
if (options.passive) {
|
|
7695
|
-
|
|
7696
|
-
`[${options.serviceId}] bridge mode delegate: memory slot not owned \u2014 passive, no hooks registered`
|
|
8085
|
+
log7.info(
|
|
8086
|
+
`[${options.serviceId}] bridge mode delegate: memory slot not owned \u2014 passive, no memory hooks registered`
|
|
7697
8087
|
);
|
|
7698
8088
|
return;
|
|
7699
8089
|
}
|
|
@@ -7761,13 +8151,13 @@ function registerDelegateRuntime(api, options) {
|
|
|
7761
8151
|
const promptRemaining = () => promptDeadline - Date.now();
|
|
7762
8152
|
try {
|
|
7763
8153
|
if (options.shouldSkipRecall(sessionKey)) {
|
|
7764
|
-
|
|
8154
|
+
log7.debug(`delegate recall skipped: cron policy excludes ${sessionKey}`);
|
|
7765
8155
|
return void 0;
|
|
7766
8156
|
}
|
|
7767
8157
|
const runtimeAgent = ctx?.runtime?.agent;
|
|
7768
8158
|
const agentId = (typeof ctx?.agentId === "string" ? ctx.agentId : void 0) ?? (typeof runtimeAgent?.id === "string" ? runtimeAgent.id : void 0) ?? "main";
|
|
7769
8159
|
if (await options.resolveSessionDisabled(sessionKey, agentId)) {
|
|
7770
|
-
|
|
8160
|
+
log7.debug(`delegate recall skipped: session toggle disables memory for ${sessionKey}`);
|
|
7771
8161
|
return void 0;
|
|
7772
8162
|
}
|
|
7773
8163
|
const cwd = cwdFrom(event, ctx, options.cwd);
|
|
@@ -7814,7 +8204,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
7814
8204
|
}
|
|
7815
8205
|
return { prependSystemContext: prompt };
|
|
7816
8206
|
} catch (err) {
|
|
7817
|
-
|
|
8207
|
+
log7.warn(`delegate recall failed: ${String(err)}`);
|
|
7818
8208
|
return void 0;
|
|
7819
8209
|
}
|
|
7820
8210
|
};
|
|
@@ -7836,7 +8226,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
7836
8226
|
api.registerMemoryPromptSection(memoryBuildFn);
|
|
7837
8227
|
}
|
|
7838
8228
|
} else {
|
|
7839
|
-
|
|
8229
|
+
log7.info(
|
|
7840
8230
|
`[${options.serviceId}] bridge mode delegate: prompt injection disabled by hooks policy`
|
|
7841
8231
|
);
|
|
7842
8232
|
}
|
|
@@ -7882,7 +8272,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
7882
8272
|
Math.max(1, observeRemaining())
|
|
7883
8273
|
);
|
|
7884
8274
|
} catch (err) {
|
|
7885
|
-
|
|
8275
|
+
log7.warn(`delegate observe failed: ${String(err)}`);
|
|
7886
8276
|
}
|
|
7887
8277
|
});
|
|
7888
8278
|
let cachedBatchFlushSupport;
|
|
@@ -7936,7 +8326,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
7936
8326
|
const remainingBudget = () => deadline - Date.now();
|
|
7937
8327
|
const sessionKey = lifecycleSessionKeyFrom(event, ctx);
|
|
7938
8328
|
if (sessionKey === void 0) {
|
|
7939
|
-
|
|
8329
|
+
log7.warn("delegate flush skipped: lifecycle event has malformed session key");
|
|
7940
8330
|
return false;
|
|
7941
8331
|
}
|
|
7942
8332
|
const namespaces = await lifecycleSessionNamespacesFrom(
|
|
@@ -7961,7 +8351,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
7961
8351
|
remainingTimeoutMs: remainingBudget
|
|
7962
8352
|
});
|
|
7963
8353
|
} catch (err) {
|
|
7964
|
-
|
|
8354
|
+
log7.warn(`delegate flush-plan ingestion failed: ${String(err)}`);
|
|
7965
8355
|
}
|
|
7966
8356
|
const flushNamespace = async (sessionNamespace) => postJson(
|
|
7967
8357
|
target,
|
|
@@ -8031,7 +8421,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
8031
8421
|
}
|
|
8032
8422
|
return flushIndividually();
|
|
8033
8423
|
} catch (err) {
|
|
8034
|
-
|
|
8424
|
+
log7.warn(`delegate flush failed: ${String(err)}`);
|
|
8035
8425
|
return false;
|
|
8036
8426
|
}
|
|
8037
8427
|
};
|
|
@@ -8041,7 +8431,7 @@ function registerDelegateRuntime(api, options) {
|
|
|
8041
8431
|
api.on("before_reset", flushEndedSession);
|
|
8042
8432
|
api.on("session_end", flushEndedSession);
|
|
8043
8433
|
}
|
|
8044
|
-
|
|
8434
|
+
log7.info(
|
|
8045
8435
|
`[${options.serviceId}] bridge mode delegate: memory loop backed by daemon at ${target.host}:${target.port} (embedded orchestrator skipped; tools/CLI stay daemon-side)`
|
|
8046
8436
|
);
|
|
8047
8437
|
}
|
|
@@ -8098,7 +8488,7 @@ function createDelegateNamespaceBindingStore(memoryDir, serviceId, isLegacyAdapt
|
|
|
8098
8488
|
return previous;
|
|
8099
8489
|
} catch (err) {
|
|
8100
8490
|
if (current.length > 0) {
|
|
8101
|
-
|
|
8491
|
+
log7.warn(
|
|
8102
8492
|
`[${serviceId}] delegate legacy namespace read failed; using canonical bindings: ${String(err)}`
|
|
8103
8493
|
);
|
|
8104
8494
|
return [];
|
|
@@ -8129,7 +8519,7 @@ function createDelegateNamespaceBindingStore(memoryDir, serviceId, isLegacyAdapt
|
|
|
8129
8519
|
try {
|
|
8130
8520
|
await legacy.replace?.(sessionKey, []);
|
|
8131
8521
|
} catch (err) {
|
|
8132
|
-
|
|
8522
|
+
log7.warn(`[${serviceId}] delegate legacy namespace cleanup failed: ${String(err)}`);
|
|
8133
8523
|
}
|
|
8134
8524
|
}
|
|
8135
8525
|
rememberMigratedLegacySession(sessionKey);
|
|
@@ -8150,7 +8540,7 @@ function createDelegateNamespaceBindingStore(memoryDir, serviceId, isLegacyAdapt
|
|
|
8150
8540
|
await persistNamespaceHistory(primary, sessionKey, merged);
|
|
8151
8541
|
await completeLegacyMigration(sessionKey);
|
|
8152
8542
|
} catch (err) {
|
|
8153
|
-
|
|
8543
|
+
log7.warn(`[${serviceId}] delegate namespace migration failed: ${String(err)}`);
|
|
8154
8544
|
}
|
|
8155
8545
|
return merged;
|
|
8156
8546
|
});
|
|
@@ -8178,13 +8568,13 @@ var delegateAuthorizationPreflightServices = /* @__PURE__ */ new WeakMap();
|
|
|
8178
8568
|
function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkDaemonHealthSync }) {
|
|
8179
8569
|
const boundServices = delegateHookApiServices.get(api);
|
|
8180
8570
|
if (boundServices?.has(options.serviceId)) {
|
|
8181
|
-
|
|
8571
|
+
log7.debug(
|
|
8182
8572
|
`delegate register: ${options.serviceId} already has hooks bound on this api \u2014 skipping duplicate registration`
|
|
8183
8573
|
);
|
|
8184
8574
|
return true;
|
|
8185
8575
|
}
|
|
8186
8576
|
if (delegateEmbeddedFallbackApis.has(api)) {
|
|
8187
|
-
|
|
8577
|
+
log7.debug(
|
|
8188
8578
|
`delegate register: ${options.serviceId} previously fell back to embedded on this api \u2014 staying embedded to avoid stacking memory paths`
|
|
8189
8579
|
);
|
|
8190
8580
|
return false;
|
|
@@ -8198,11 +8588,11 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8198
8588
|
bridge = resolveBridgeMode(options.configBridgeMode, {
|
|
8199
8589
|
memoryDir: options.memoryDir,
|
|
8200
8590
|
timeoutMs: bridgeHealthTimeoutMs,
|
|
8201
|
-
onSkip: (reason) =>
|
|
8591
|
+
onSkip: (reason) => log7.info(`[${options.serviceId}] bridge mode auto: staying embedded \u2014 ${reason}`)
|
|
8202
8592
|
});
|
|
8203
8593
|
} catch (err) {
|
|
8204
8594
|
const wantedDelegate = requestedDelegate(options.configBridgeMode);
|
|
8205
|
-
|
|
8595
|
+
log7.error(
|
|
8206
8596
|
wantedDelegate ? `${String(err)} \u2014 falling back to the embedded runtime` : `${String(err)} \u2014 the deployment is embedded, so this only affects delegate mode`
|
|
8207
8597
|
);
|
|
8208
8598
|
if (!options.passive) delegateEmbeddedFallbackApis.add(api);
|
|
@@ -8210,7 +8600,7 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8210
8600
|
}
|
|
8211
8601
|
if (bridge.mode !== "delegate") {
|
|
8212
8602
|
if (delegateBoundApis.has(api)) {
|
|
8213
|
-
|
|
8603
|
+
log7.warn(
|
|
8214
8604
|
`[${options.serviceId}] bridge mode resolved embedded, but a sibling service already bound delegate hooks on this api \u2014 reusing them instead of stacking an embedded runtime`
|
|
8215
8605
|
);
|
|
8216
8606
|
return true;
|
|
@@ -8218,7 +8608,7 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8218
8608
|
if (!options.passive) {
|
|
8219
8609
|
delegateEmbeddedFallbackApis.add(api);
|
|
8220
8610
|
if (resolveRequestedBridgeMode(options.configBridgeMode) === "auto") {
|
|
8221
|
-
|
|
8611
|
+
log7.info(
|
|
8222
8612
|
`[${options.serviceId}] bridge mode auto: embedded hooks are bound on this api \u2014 a daemon that starts later is picked up on the next gateway restart`
|
|
8223
8613
|
);
|
|
8224
8614
|
}
|
|
@@ -8227,13 +8617,13 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8227
8617
|
}
|
|
8228
8618
|
if (!bridge.healthVerified && !deps.checkHealth(bridge.daemonHost, bridge.daemonPort, bridgeHealthTimeoutMs)) {
|
|
8229
8619
|
if (delegateBoundApis.has(api)) {
|
|
8230
|
-
|
|
8620
|
+
log7.warn(
|
|
8231
8621
|
`[${options.serviceId}] no healthy daemon at ${bridge.daemonHost}:${bridge.daemonPort}, but a sibling service already bound delegate hooks on this api \u2014 reusing them instead of stacking an embedded runtime`
|
|
8232
8622
|
);
|
|
8233
8623
|
return true;
|
|
8234
8624
|
}
|
|
8235
8625
|
delegateEmbeddedFallbackApis.add(api);
|
|
8236
|
-
|
|
8626
|
+
log7.error(
|
|
8237
8627
|
`bridge mode delegate requested but no healthy daemon at ${bridge.daemonHost}:${bridge.daemonPort} \u2014 falling back to the embedded runtime`
|
|
8238
8628
|
);
|
|
8239
8629
|
return false;
|
|
@@ -8275,7 +8665,8 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8275
8665
|
capability: options.capability,
|
|
8276
8666
|
recallTimeoutMs: 25e3,
|
|
8277
8667
|
observeTimeoutMs: 12e4,
|
|
8278
|
-
flushTimeoutMs: 55e3
|
|
8668
|
+
flushTimeoutMs: 55e3,
|
|
8669
|
+
supportPassportModelRoute: options.supportPassportModelRoute
|
|
8279
8670
|
});
|
|
8280
8671
|
let preflightServices = delegateAuthorizationPreflightServices.get(api);
|
|
8281
8672
|
if (!options.passive && !preflightServices?.has(options.serviceId)) {
|
|
@@ -8290,16 +8681,16 @@ function maybeRegisterDelegateRuntime(api, options, deps = { checkHealth: checkD
|
|
|
8290
8681
|
void probe(target, "", operations).then((result) => {
|
|
8291
8682
|
if (result.state === "authorized") return;
|
|
8292
8683
|
if (result.state === "unauthorized") {
|
|
8293
|
-
|
|
8684
|
+
log7.warn(
|
|
8294
8685
|
`delegate authorization preflight rejected ${operationLabel} (${result.status}; token source: ${result.tokenSource}) \u2014 runtime remains active`
|
|
8295
8686
|
);
|
|
8296
8687
|
return;
|
|
8297
8688
|
}
|
|
8298
|
-
|
|
8689
|
+
log7.warn(
|
|
8299
8690
|
`delegate authorization preflight could not verify ${operationLabel} (token source: ${result.tokenSource}) \u2014 runtime remains active`
|
|
8300
8691
|
);
|
|
8301
8692
|
}).catch(() => {
|
|
8302
|
-
|
|
8693
|
+
log7.warn("delegate authorization preflight could not complete \u2014 runtime remains active");
|
|
8303
8694
|
});
|
|
8304
8695
|
}
|
|
8305
8696
|
return true;
|
|
@@ -8403,9 +8794,11 @@ function buildTurnFingerprint(input) {
|
|
|
8403
8794
|
import { planRecallMode } from "@remnic/core/intent";
|
|
8404
8795
|
import {
|
|
8405
8796
|
expandTildePath as expandTildePath4,
|
|
8797
|
+
isSupportPassportPrivateMemory as isSupportPassportPrivateMemory2,
|
|
8406
8798
|
renderMemoryContextPrompt as renderSharedMemoryContextPrompt,
|
|
8407
8799
|
resolveAgentAccessAuthToken,
|
|
8408
|
-
resolvePrincipal
|
|
8800
|
+
resolvePrincipal,
|
|
8801
|
+
searchWithGenericExclusion
|
|
8409
8802
|
} from "@remnic/core";
|
|
8410
8803
|
import {
|
|
8411
8804
|
normalizeHostEmbeddingVector,
|
|
@@ -9306,6 +9699,7 @@ var pluginDefinition = {
|
|
|
9306
9699
|
}
|
|
9307
9700
|
);
|
|
9308
9701
|
const delegateApi = api;
|
|
9702
|
+
const delegateSupportPassportGatewayRoute = createConfiguredSupportPassportGatewayRoute(cfg);
|
|
9309
9703
|
const delegateHandled = maybeRegisterDelegateRuntime(delegateApi, {
|
|
9310
9704
|
serviceId,
|
|
9311
9705
|
configBridgeMode: cfg.bridgeMode,
|
|
@@ -9324,6 +9718,7 @@ var pluginDefinition = {
|
|
|
9324
9718
|
shouldSkipRecall: (sk) => shouldSkipRecallForSession(sk, cfg),
|
|
9325
9719
|
cwd: getOpenClawRuntimeWorkspaceDir(api),
|
|
9326
9720
|
flushOnResetEnabled: cfg.flushOnResetEnabled,
|
|
9721
|
+
supportPassportModelRoute: delegateSupportPassportGatewayRoute ?? void 0,
|
|
9327
9722
|
// Memory-slot capability inputs. Mirrors the embedded derivation: the
|
|
9328
9723
|
// registration-time runtime agent owns this memory, and QMD is the
|
|
9329
9724
|
// backend only when it is both selected and enabled.
|
|
@@ -9391,7 +9786,7 @@ var pluginDefinition = {
|
|
|
9391
9786
|
globalThis.__openclawEngramTrace = void 0;
|
|
9392
9787
|
}
|
|
9393
9788
|
const existingAccessService = globalThis[keys.ACCESS_SERVICE];
|
|
9394
|
-
const accessService = existingAccessService && existingAccessService ? existingAccessService : new
|
|
9789
|
+
const accessService = existingAccessService && existingAccessService ? existingAccessService : new EngramAccessService(orchestrator, {
|
|
9395
9790
|
resolveSecretRef: (ref, context) => loadOpenClawSecretRefResolver().then((resolver) => resolver ? resolver(ref, context) : void 0)
|
|
9396
9791
|
});
|
|
9397
9792
|
globalThis[keys.ACCESS_SERVICE] = accessService;
|
|
@@ -9637,9 +10032,9 @@ Keep the reflection grounded in the evidence below.
|
|
|
9637
10032
|
let rawNarrative = "";
|
|
9638
10033
|
try {
|
|
9639
10034
|
if (route.kind === "gateway") {
|
|
9640
|
-
const llm = new
|
|
10035
|
+
const llm = new FallbackLlmClient2(
|
|
9641
10036
|
cfg.gatewayConfig,
|
|
9642
|
-
|
|
10037
|
+
fallbackLlmRuntimeContextFromConfig2(cfg)
|
|
9643
10038
|
);
|
|
9644
10039
|
if (!route.hasExplicitModel && !llm.isAvailable(route.options)) {
|
|
9645
10040
|
logger_exports.log.debug(
|
|
@@ -10671,17 +11066,27 @@ Keep the reflection grounded in the evidence below.
|
|
|
10671
11066
|
async search(query, opts) {
|
|
10672
11067
|
const namespace = typeof orchestrator.resolveSelfNamespace === "function" ? orchestrator.resolveSelfNamespace(opts?.sessionKey) : void 0;
|
|
10673
11068
|
const resolvedMode = opts?.qmdSearchModeOverride === "vsearch" ? "vector" : opts?.qmdSearchModeOverride === "query" ? "search" : opts?.qmdSearchModeOverride ?? "search";
|
|
10674
|
-
const
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
10678
|
-
|
|
11069
|
+
const requestedMaxResults = typeof opts?.maxResults === "number" && Number.isFinite(opts.maxResults) ? Math.max(0, Math.floor(opts.maxResults)) : void 0;
|
|
11070
|
+
const minScore = typeof opts?.minScore === "number" && Number.isFinite(opts.minScore) ? opts.minScore : void 0;
|
|
11071
|
+
const visibleResults = await searchWithGenericExclusion({
|
|
11072
|
+
budget: requestedMaxResults ?? Number.MAX_SAFE_INTEGER,
|
|
11073
|
+
sendInitialLimit: requestedMaxResults !== void 0,
|
|
11074
|
+
search: (limit) => orchestrator.searchAcrossNamespaces({
|
|
11075
|
+
query,
|
|
11076
|
+
...limit !== void 0 ? { maxResults: limit } : {},
|
|
11077
|
+
namespaces: namespace ? [namespace] : void 0,
|
|
11078
|
+
mode: resolvedMode
|
|
11079
|
+
}),
|
|
11080
|
+
filterPrivate: async (results) => {
|
|
11081
|
+
const visible = await orchestrator.filterPrivateSearchResults(
|
|
11082
|
+
results,
|
|
11083
|
+
namespace ? [namespace] : []
|
|
11084
|
+
);
|
|
11085
|
+
return minScore === void 0 ? visible : visible.filter((result) => result.score >= minScore);
|
|
11086
|
+
},
|
|
11087
|
+
isExcluded: (resultPath) => isMemoryArtifactPath(resultPath)
|
|
10679
11088
|
});
|
|
10680
|
-
return
|
|
10681
|
-
const candidate = result;
|
|
10682
|
-
const p = typeof candidate.path === "string" ? candidate.path : typeof candidate.id === "string" ? candidate.id : "";
|
|
10683
|
-
return !isMemoryArtifactPath(p);
|
|
10684
|
-
}).map((result, index) => {
|
|
11089
|
+
return visibleResults.map((result, index) => {
|
|
10685
11090
|
const candidate = result;
|
|
10686
11091
|
const rawPath = typeof candidate.path === "string" ? candidate.path : typeof candidate.id === "string" ? candidate.id : `memory-${index + 1}`;
|
|
10687
11092
|
const absolutePath = readScope.absolutize(rawPath);
|
|
@@ -10697,13 +11102,20 @@ Keep the reflection grounded in the evidence below.
|
|
|
10697
11102
|
source: isSessionsMemoryPath(normalizedPath) ? "sessions" : "memory",
|
|
10698
11103
|
citation: normalizedPath
|
|
10699
11104
|
};
|
|
10700
|
-
})
|
|
10701
|
-
(result) => typeof opts?.minScore === "number" && Number.isFinite(opts.minScore) ? result.score >= opts.minScore : true
|
|
10702
|
-
);
|
|
11105
|
+
});
|
|
10703
11106
|
},
|
|
10704
11107
|
async readFile(params) {
|
|
10705
11108
|
const requestedPath = readScope.normalizeWorkspacePath(params.relPath);
|
|
10706
11109
|
const absolutePath = await readScope.resolveReadablePath(params.relPath);
|
|
11110
|
+
const visible = await orchestrator.filterPrivateSearchResults([{
|
|
11111
|
+
docid: absolutePath,
|
|
11112
|
+
path: absolutePath,
|
|
11113
|
+
snippet: "",
|
|
11114
|
+
score: 0
|
|
11115
|
+
}], [], true);
|
|
11116
|
+
if (visible.length === 0) {
|
|
11117
|
+
throw new Error(`memory read excluded (private record): ${params.relPath}`);
|
|
11118
|
+
}
|
|
10707
11119
|
const text = await readTextFileLater(absolutePath);
|
|
10708
11120
|
const allLines = text.split(/\r?\n/);
|
|
10709
11121
|
const from = typeof params.from === "number" ? Math.max(1, Math.floor(params.from)) : 1;
|
|
@@ -11594,17 +12006,22 @@ Keep the reflection grounded in the evidence below.
|
|
|
11594
12006
|
const agentSessionKey = typeof params === "object" ? params.agentSessionKey : void 0;
|
|
11595
12007
|
const namespace = typeof orchestrator.resolveSelfNamespace === "function" ? orchestrator.resolveSelfNamespace(agentSessionKey) : void 0;
|
|
11596
12008
|
try {
|
|
11597
|
-
const
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
12009
|
+
const visibleResults = await searchWithGenericExclusion({
|
|
12010
|
+
budget: maxResults,
|
|
12011
|
+
sendInitialLimit: true,
|
|
12012
|
+
search: (limit) => orchestrator.searchAcrossNamespaces({
|
|
12013
|
+
query,
|
|
12014
|
+
...limit !== void 0 ? { maxResults: limit } : {},
|
|
12015
|
+
namespaces: namespace ? [namespace] : void 0,
|
|
12016
|
+
mode: "search"
|
|
12017
|
+
}),
|
|
12018
|
+
filterPrivate: (results) => orchestrator.filterPrivateSearchResults(
|
|
12019
|
+
results,
|
|
12020
|
+
namespace ? [namespace] : []
|
|
12021
|
+
),
|
|
12022
|
+
isExcluded: (resultPath) => isMemoryArtifactPath(resultPath)
|
|
11602
12023
|
});
|
|
11603
|
-
return
|
|
11604
|
-
const candidate = result;
|
|
11605
|
-
const p = typeof candidate.path === "string" ? candidate.path : typeof candidate.id === "string" ? candidate.id : "";
|
|
11606
|
-
return !isMemoryArtifactPath(p);
|
|
11607
|
-
}).map((result, index) => {
|
|
12024
|
+
return visibleResults.map((result, index) => {
|
|
11608
12025
|
const candidate = result;
|
|
11609
12026
|
const lookupPath = typeof candidate.path === "string" ? candidate.path : typeof candidate.id === "string" ? candidate.id : `remnic-memory-${index + 1}`;
|
|
11610
12027
|
const startLine = typeof candidate.startLine === "number" && Number.isFinite(candidate.startLine) ? Math.max(1, Math.floor(candidate.startLine)) : 1;
|
|
@@ -11642,7 +12059,7 @@ Keep the reflection grounded in the evidence below.
|
|
|
11642
12059
|
const resolved = await readMemoryByLookup(lookup, agentSessionKey);
|
|
11643
12060
|
if (!resolved) return null;
|
|
11644
12061
|
const { memory, displayPath } = resolved;
|
|
11645
|
-
if (isMemoryArtifactPath(displayPath) || isMemoryArtifactPath(memory.path)) {
|
|
12062
|
+
if (isMemoryArtifactPath(displayPath) || isMemoryArtifactPath(memory.path) || isSupportPassportPrivateMemory2(memory)) {
|
|
11646
12063
|
return null;
|
|
11647
12064
|
}
|
|
11648
12065
|
const allLines = memory.content.split(/\r?\n/);
|
|
@@ -12080,6 +12497,7 @@ var export_loadDaySummaryPrompt = day_summary_exports.loadDaySummaryPrompt;
|
|
|
12080
12497
|
export {
|
|
12081
12498
|
buildHourlySummaryCronJob,
|
|
12082
12499
|
checkDaemonHealth,
|
|
12500
|
+
createOpenClawSupportPassportModelRoute,
|
|
12083
12501
|
src_default as default,
|
|
12084
12502
|
detectBridgeMode,
|
|
12085
12503
|
detectDaemonBridgeMode,
|