@remnic/plugin-openclaw 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{calibration-KQXCC77L.js → calibration-WZXRJMVP.js} +1 -1
- package/dist/{causal-consolidation-WINYJQJ4.js → causal-consolidation-YZLBOC7J.js} +1 -1
- package/dist/{chunk-TJZ7KBCC.js → chunk-BIBYVWVY.js} +112 -20
- package/dist/{chunk-WLR4WL6B.js → chunk-L46G4NGI.js} +10 -10
- package/dist/{engine-QHRKR53Q.js → engine-GPDZXAXN.js} +1 -1
- package/dist/{fallback-llm-2VMRPBHR.js → fallback-llm-7UTWU27F.js} +1 -1
- package/dist/index.js +549 -3155
- package/package.json +3 -3
|
@@ -139,6 +139,7 @@ function mergeEnv(overrides) {
|
|
|
139
139
|
import path from "path";
|
|
140
140
|
import os2 from "os";
|
|
141
141
|
var _resolveApiKeyForProvider = null;
|
|
142
|
+
var _getRuntimeAuthForModel = null;
|
|
142
143
|
var _resolverLoaded = false;
|
|
143
144
|
var _resolverNextRetryAt = 0;
|
|
144
145
|
var RESOLVER_RETRY_BACKOFF_MS = 6e4;
|
|
@@ -162,6 +163,10 @@ async function getGatewayResolver() {
|
|
|
162
163
|
const mod = await import(importUrl);
|
|
163
164
|
if (typeof mod.resolveApiKeyForProvider === "function") {
|
|
164
165
|
_resolveApiKeyForProvider = mod.resolveApiKeyForProvider;
|
|
166
|
+
if (typeof mod.getRuntimeAuthForModel === "function") {
|
|
167
|
+
_getRuntimeAuthForModel = mod.getRuntimeAuthForModel;
|
|
168
|
+
log.debug("loaded gateway getRuntimeAuthForModel from runtime module");
|
|
169
|
+
}
|
|
165
170
|
_resolverLoaded = true;
|
|
166
171
|
log.debug("loaded gateway resolveApiKeyForProvider from runtime module");
|
|
167
172
|
return _resolveApiKeyForProvider;
|
|
@@ -268,6 +273,39 @@ function resolveFromEnv(providerId) {
|
|
|
268
273
|
}
|
|
269
274
|
return void 0;
|
|
270
275
|
}
|
|
276
|
+
async function getGatewayRuntimeAuthForModel() {
|
|
277
|
+
await getGatewayResolver();
|
|
278
|
+
return _getRuntimeAuthForModel;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ../remnic-core/src/models-json.ts
|
|
282
|
+
import { readFileSync } from "fs";
|
|
283
|
+
import { join } from "path";
|
|
284
|
+
import { homedir } from "os";
|
|
285
|
+
var _cachedProviders = null;
|
|
286
|
+
var _loadAttempted = false;
|
|
287
|
+
function loadModelsJsonProviders() {
|
|
288
|
+
if (_loadAttempted) {
|
|
289
|
+
return _cachedProviders ?? {};
|
|
290
|
+
}
|
|
291
|
+
_loadAttempted = true;
|
|
292
|
+
try {
|
|
293
|
+
const modelsPath = join(homedir(), ".openclaw", "agents", "main", "agent", "models.json");
|
|
294
|
+
const raw = readFileSync(modelsPath, "utf-8");
|
|
295
|
+
const parsed = JSON.parse(raw);
|
|
296
|
+
const providers = parsed?.providers;
|
|
297
|
+
if (providers && typeof providers === "object" && !Array.isArray(providers)) {
|
|
298
|
+
_cachedProviders = providers;
|
|
299
|
+
log.debug(`loaded ${Object.keys(_cachedProviders).length} providers from models.json`);
|
|
300
|
+
return _cachedProviders;
|
|
301
|
+
}
|
|
302
|
+
} catch (err) {
|
|
303
|
+
log.debug(
|
|
304
|
+
`could not load models.json: ${err instanceof Error ? err.message : String(err)}`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
return {};
|
|
308
|
+
}
|
|
271
309
|
|
|
272
310
|
// ../remnic-core/src/fallback-llm.ts
|
|
273
311
|
var FallbackLlmClient = class {
|
|
@@ -379,8 +417,7 @@ var FallbackLlmClient = class {
|
|
|
379
417
|
*/
|
|
380
418
|
getModelChain(agentId) {
|
|
381
419
|
const chain = [];
|
|
382
|
-
const providers = this.gatewayConfig?.models?.providers;
|
|
383
|
-
if (!providers) return chain;
|
|
420
|
+
const providers = this.gatewayConfig?.models?.providers ?? {};
|
|
384
421
|
let modelConfig;
|
|
385
422
|
if (agentId) {
|
|
386
423
|
const persona = this.gatewayConfig?.agents?.list?.find(
|
|
@@ -428,7 +465,7 @@ var FallbackLlmClient = class {
|
|
|
428
465
|
}
|
|
429
466
|
const providerId = parts[0];
|
|
430
467
|
const modelId = parts.slice(1).join("/");
|
|
431
|
-
const providerConfig = providers[providerId];
|
|
468
|
+
const providerConfig = providers[providerId] ?? this.resolveFromModelsJson(providerId);
|
|
432
469
|
if (!providerConfig) {
|
|
433
470
|
log.warn(`fallback LLM: provider not found: ${providerId}`);
|
|
434
471
|
return null;
|
|
@@ -436,36 +473,91 @@ var FallbackLlmClient = class {
|
|
|
436
473
|
return { providerId, modelId, providerConfig, modelString };
|
|
437
474
|
}
|
|
438
475
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
476
|
+
* Look up a provider from the gateway's materialized models.json, which
|
|
477
|
+
* contains all providers including built-in ones (openai-codex, google-vertex,
|
|
478
|
+
* etc.) that aren't in the user's openclaw.json but are registered by
|
|
479
|
+
* gateway plugins. Returns null if the provider isn't found there either.
|
|
441
480
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
481
|
+
resolveFromModelsJson(providerId) {
|
|
482
|
+
const allProviders = loadModelsJsonProviders();
|
|
483
|
+
const config = allProviders[providerId];
|
|
484
|
+
if (config) {
|
|
485
|
+
log.debug(`fallback LLM: resolved provider "${providerId}" from models.json (api: ${config.api ?? "default"})`);
|
|
486
|
+
return config;
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
444
489
|
}
|
|
445
490
|
/**
|
|
446
491
|
* Try to call a single model.
|
|
492
|
+
*
|
|
493
|
+
* Uses the gateway's native getRuntimeAuthForModel when available — this
|
|
494
|
+
* handles all provider-specific auth transforms (OAuth token exchange,
|
|
495
|
+
* base URL overrides for codex/copilot/etc.) through the same codepath
|
|
496
|
+
* the gateway itself uses. Falls back to resolveProviderApiKey for
|
|
497
|
+
* simpler providers or when the runtime module isn't loaded.
|
|
447
498
|
*/
|
|
448
499
|
async tryModel(model, messages, options) {
|
|
500
|
+
const runtimeAuth = await this.resolveRuntimeAuth(model);
|
|
501
|
+
const effectiveBaseUrl = runtimeAuth?.baseUrl ?? model.providerConfig.baseUrl;
|
|
502
|
+
const resolvedApiKey = runtimeAuth?.apiKey ?? await this.resolveFallbackApiKey(model);
|
|
449
503
|
const rawKey = model.providerConfig.apiKey;
|
|
450
504
|
const needsResolution = rawKey === "secretref-managed" || typeof rawKey === "object" && rawKey !== null;
|
|
451
|
-
const resolvedApiKey = await this.resolveApiKey(model.providerId, model.providerConfig);
|
|
452
505
|
if (needsResolution && !resolvedApiKey) {
|
|
453
506
|
throw new Error(`API key for provider "${model.providerId}" could not be resolved from secret ref`);
|
|
454
507
|
}
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
508
|
+
const effectiveConfig = {
|
|
509
|
+
...model.providerConfig,
|
|
510
|
+
baseUrl: effectiveBaseUrl,
|
|
511
|
+
...resolvedApiKey ? { apiKey: resolvedApiKey } : {}
|
|
512
|
+
};
|
|
513
|
+
if (model.providerConfig.api === "anthropic-messages") {
|
|
514
|
+
return await this.callAnthropic(effectiveConfig, model.modelId, messages, options);
|
|
515
|
+
}
|
|
516
|
+
return await this.callOpenAI(
|
|
517
|
+
effectiveConfig,
|
|
518
|
+
model.modelId,
|
|
519
|
+
messages,
|
|
520
|
+
options,
|
|
521
|
+
shouldAssumeOpenAiChatCompletions(effectiveConfig.baseUrl)
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Resolve request-ready auth through the gateway's native runtime, which
|
|
526
|
+
* handles provider-specific transforms (OAuth token exchange for codex/copilot,
|
|
527
|
+
* base URL rewrite, etc.). Returns null if the runtime isn't available.
|
|
528
|
+
*/
|
|
529
|
+
async resolveRuntimeAuth(model) {
|
|
530
|
+
try {
|
|
531
|
+
const getRuntimeAuth = await getGatewayRuntimeAuthForModel();
|
|
532
|
+
if (!getRuntimeAuth) return null;
|
|
533
|
+
const result = await getRuntimeAuth({
|
|
534
|
+
model: {
|
|
535
|
+
provider: model.providerId,
|
|
536
|
+
id: model.modelId,
|
|
537
|
+
api: model.providerConfig.api,
|
|
538
|
+
baseUrl: model.providerConfig.baseUrl
|
|
539
|
+
},
|
|
540
|
+
cfg: this.gatewayConfig
|
|
541
|
+
});
|
|
542
|
+
if (result?.apiKey || result?.baseUrl) {
|
|
543
|
+
log.debug(
|
|
544
|
+
`fallback LLM: resolved runtime auth for "${model.modelString}" (source: ${result.source ?? "unknown"}, mode: ${result.mode ?? "unknown"})`
|
|
467
545
|
);
|
|
546
|
+
return { apiKey: result.apiKey, baseUrl: result.baseUrl };
|
|
547
|
+
}
|
|
548
|
+
} catch (err) {
|
|
549
|
+
log.debug(
|
|
550
|
+
`fallback LLM: gateway runtime auth failed for "${model.modelString}": ${err instanceof Error ? err.message : String(err)}`
|
|
551
|
+
);
|
|
468
552
|
}
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Resolve API key through the existing provider-level resolution (env vars,
|
|
557
|
+
* secret refs, etc.). Used as fallback when gateway runtime auth isn't available.
|
|
558
|
+
*/
|
|
559
|
+
async resolveFallbackApiKey(model) {
|
|
560
|
+
return resolveProviderApiKey(model.providerId, model.providerConfig.apiKey, this.gatewayConfig);
|
|
469
561
|
}
|
|
470
562
|
/**
|
|
471
563
|
* Call OpenAI-compatible API.
|
|
@@ -22,7 +22,7 @@ import { mkdir, readFile, readdir, appendFile, writeFile, stat } from "fs/promis
|
|
|
22
22
|
import path from "path";
|
|
23
23
|
import os from "os";
|
|
24
24
|
|
|
25
|
-
// ../../node_modules
|
|
25
|
+
// ../../node_modules/zod/v3/external.js
|
|
26
26
|
var external_exports = {};
|
|
27
27
|
__export(external_exports, {
|
|
28
28
|
BRAND: () => BRAND,
|
|
@@ -134,7 +134,7 @@ __export(external_exports, {
|
|
|
134
134
|
void: () => voidType
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
// ../../node_modules
|
|
137
|
+
// ../../node_modules/zod/v3/helpers/util.js
|
|
138
138
|
var util;
|
|
139
139
|
(function(util2) {
|
|
140
140
|
util2.assertEqual = (_) => {
|
|
@@ -268,7 +268,7 @@ var getParsedType = (data) => {
|
|
|
268
268
|
}
|
|
269
269
|
};
|
|
270
270
|
|
|
271
|
-
// ../../node_modules
|
|
271
|
+
// ../../node_modules/zod/v3/ZodError.js
|
|
272
272
|
var ZodIssueCode = util.arrayToEnum([
|
|
273
273
|
"invalid_type",
|
|
274
274
|
"invalid_literal",
|
|
@@ -386,7 +386,7 @@ ZodError.create = (issues) => {
|
|
|
386
386
|
return error;
|
|
387
387
|
};
|
|
388
388
|
|
|
389
|
-
// ../../node_modules
|
|
389
|
+
// ../../node_modules/zod/v3/locales/en.js
|
|
390
390
|
var errorMap = (issue, _ctx) => {
|
|
391
391
|
let message;
|
|
392
392
|
switch (issue.code) {
|
|
@@ -489,7 +489,7 @@ var errorMap = (issue, _ctx) => {
|
|
|
489
489
|
};
|
|
490
490
|
var en_default = errorMap;
|
|
491
491
|
|
|
492
|
-
// ../../node_modules
|
|
492
|
+
// ../../node_modules/zod/v3/errors.js
|
|
493
493
|
var overrideErrorMap = en_default;
|
|
494
494
|
function setErrorMap(map) {
|
|
495
495
|
overrideErrorMap = map;
|
|
@@ -498,7 +498,7 @@ function getErrorMap() {
|
|
|
498
498
|
return overrideErrorMap;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
// ../../node_modules
|
|
501
|
+
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
502
502
|
var makeIssue = (params) => {
|
|
503
503
|
const { data, path: path3, errorMaps, issueData } = params;
|
|
504
504
|
const fullPath = [...path3, ...issueData.path || []];
|
|
@@ -608,14 +608,14 @@ var isDirty = (x) => x.status === "dirty";
|
|
|
608
608
|
var isValid = (x) => x.status === "valid";
|
|
609
609
|
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
610
610
|
|
|
611
|
-
// ../../node_modules
|
|
611
|
+
// ../../node_modules/zod/v3/helpers/errorUtil.js
|
|
612
612
|
var errorUtil;
|
|
613
613
|
(function(errorUtil2) {
|
|
614
614
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
615
615
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
616
616
|
})(errorUtil || (errorUtil = {}));
|
|
617
617
|
|
|
618
|
-
// ../../node_modules
|
|
618
|
+
// ../../node_modules/zod/v3/types.js
|
|
619
619
|
var ParseInputLazyPath = class {
|
|
620
620
|
constructor(parent, value, path3, key) {
|
|
621
621
|
this._cachedPath = [];
|
|
@@ -4881,7 +4881,7 @@ var CompoundingEngine = class {
|
|
|
4881
4881
|
let promotionCandidates = this.config.compoundingSemanticEnabled ? this.derivePromotionCandidates(outcomeSummary, mistakes.registry, rubrics) : [];
|
|
4882
4882
|
if (this.config.cmcConsolidationEnabled) {
|
|
4883
4883
|
try {
|
|
4884
|
-
const { deriveCausalPromotionCandidates } = await import("./causal-consolidation-
|
|
4884
|
+
const { deriveCausalPromotionCandidates } = await import("./causal-consolidation-YZLBOC7J.js");
|
|
4885
4885
|
const causalCandidates = await deriveCausalPromotionCandidates({
|
|
4886
4886
|
memoryDir: this.config.memoryDir,
|
|
4887
4887
|
causalTrajectoryStoreDir: this.config.causalTrajectoryStoreDir,
|
|
@@ -4902,7 +4902,7 @@ var CompoundingEngine = class {
|
|
|
4902
4902
|
}
|
|
4903
4903
|
if (this.config.calibrationEnabled) {
|
|
4904
4904
|
try {
|
|
4905
|
-
const { runCalibrationConsolidation } = await import("./calibration-
|
|
4905
|
+
const { runCalibrationConsolidation } = await import("./calibration-WZXRJMVP.js");
|
|
4906
4906
|
const calRules = await runCalibrationConsolidation({
|
|
4907
4907
|
memoryDir: this.config.memoryDir,
|
|
4908
4908
|
gatewayConfig: this.config.gatewayConfig,
|