@teith/openclaw-runware-provider 0.4.2 → 0.4.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/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +11 -71
- package/dist/catalog.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -44
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +0 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -69
- package/dist/models.js.map +1 -1
- package/dist/provider-discovery.d.ts.map +1 -1
- package/dist/provider-discovery.js +3 -42
- package/dist/provider-discovery.js.map +1 -1
- package/package.json +1 -1
package/dist/catalog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAcD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,EAAE,CAAC,CA2BzB;AAyFD,wBAAgB,UAAU,IAAI,IAAI,CAGjC"}
|
package/dist/catalog.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
console.log(`[runware-diag] catalog.ts module loaded at ${new Date().toISOString()}`);
|
|
2
1
|
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
3
|
-
const FETCH_TIMEOUT_MS =
|
|
2
|
+
const FETCH_TIMEOUT_MS = 5000;
|
|
4
3
|
const FIRST_FETCH_MAX_ATTEMPTS = 3;
|
|
5
4
|
const RETRY_BACKOFF_BASE_MS = 500;
|
|
6
5
|
let cache = null;
|
|
@@ -8,34 +7,23 @@ let inflight = null;
|
|
|
8
7
|
export async function fetchModels(baseUrl, apiKey) {
|
|
9
8
|
const now = Date.now();
|
|
10
9
|
if (cache && now - cache.fetchedAt < CACHE_TTL_MS) {
|
|
11
|
-
console.log(`[runware-diag] fetchModels: CACHE HIT, age=${((now - cache.fetchedAt) / 1000).toFixed(1)}s, count=${cache.models.length}`);
|
|
12
10
|
return cache.models;
|
|
13
11
|
}
|
|
14
|
-
if (inflight)
|
|
15
|
-
console.log(`[runware-diag] fetchModels: INFLIGHT, returning shared promise`);
|
|
12
|
+
if (inflight)
|
|
16
13
|
return inflight;
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// would just delay that fallback. The first call is the one that matters:
|
|
21
|
-
// it's on openclaw's startup critical path, and a single 5s timeout against
|
|
22
|
-
// a cold TLS handshake to Runware is the proximate cause of the "Runware
|
|
23
|
-
// models missing after gateway restart" bug.
|
|
14
|
+
// Retry only on the first fetch (no cache). Once we have any cache, the
|
|
15
|
+
// catch path returns stale data on failure, so retrying would just delay
|
|
16
|
+
// the fallback.
|
|
24
17
|
const maxAttempts = cache ? 1 : FIRST_FETCH_MAX_ATTEMPTS;
|
|
25
|
-
console.log(`[runware-diag] fetchModels: cache=${cache ? `stale (age ${((now - cache.fetchedAt) / 1000).toFixed(1)}s)` : "empty"}, starting fetch with maxAttempts=${maxAttempts}, baseUrl=${baseUrl}`);
|
|
26
18
|
inflight = (async () => {
|
|
27
19
|
try {
|
|
28
20
|
const models = await fetchWithRetries(baseUrl, apiKey, maxAttempts);
|
|
29
21
|
cache = { models, fetchedAt: Date.now() };
|
|
30
|
-
console.log(`[runware-diag] fetchModels: fetch SUCCESS, cached ${models.length} models`);
|
|
31
22
|
return models;
|
|
32
23
|
}
|
|
33
24
|
catch (err) {
|
|
34
|
-
if (cache)
|
|
35
|
-
console.warn(`[runware-diag] fetchModels: fetch FAILED, returning stale cache of ${cache.models.length} models: ${err instanceof Error ? err.message : err}`);
|
|
25
|
+
if (cache)
|
|
36
26
|
return cache.models;
|
|
37
|
-
}
|
|
38
|
-
console.error(`[runware-diag] fetchModels: fetch FAILED and NO CACHE — propagating error: ${err instanceof Error ? err.message : err}`);
|
|
39
27
|
throw err;
|
|
40
28
|
}
|
|
41
29
|
finally {
|
|
@@ -48,20 +36,12 @@ async function fetchWithRetries(baseUrl, apiKey, maxAttempts) {
|
|
|
48
36
|
let lastErr;
|
|
49
37
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
50
38
|
try {
|
|
51
|
-
|
|
52
|
-
if (attempt > 1) {
|
|
53
|
-
console.log(`[runware-catalog] /v1/models succeeded on attempt ${attempt}/${maxAttempts}`);
|
|
54
|
-
}
|
|
55
|
-
return models;
|
|
39
|
+
return await fetchFromUpstream(baseUrl, apiKey);
|
|
56
40
|
}
|
|
57
41
|
catch (err) {
|
|
58
42
|
lastErr = err;
|
|
59
|
-
|
|
60
|
-
if (attempt === maxAttempts) {
|
|
61
|
-
console.warn(`[runware-catalog] /v1/models failed on attempt ${attempt}/${maxAttempts} (giving up): ${msg}`);
|
|
43
|
+
if (attempt === maxAttempts)
|
|
62
44
|
break;
|
|
63
|
-
}
|
|
64
|
-
console.warn(`[runware-catalog] /v1/models failed on attempt ${attempt}/${maxAttempts}, retrying: ${msg}`);
|
|
65
45
|
// Exponential backoff: 500ms, 1500ms, 3500ms, ...
|
|
66
46
|
const delay = RETRY_BACKOFF_BASE_MS * (2 ** attempt - 1);
|
|
67
47
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
@@ -75,59 +55,19 @@ async function fetchFromUpstream(baseUrl, apiKey) {
|
|
|
75
55
|
const url = `${baseUrl.replace(/\/+$/, "")}/models`;
|
|
76
56
|
const controller = new AbortController();
|
|
77
57
|
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
78
|
-
const startedAt = Date.now();
|
|
79
|
-
console.log(`[runware-diag] fetchFromUpstream: GET ${url} (apiKey length=${apiKey.length}, timeout=${FETCH_TIMEOUT_MS}ms)`);
|
|
80
58
|
try {
|
|
81
59
|
const res = await fetch(url, {
|
|
82
60
|
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
|
|
83
61
|
signal: controller.signal,
|
|
84
62
|
});
|
|
85
|
-
const elapsed = Date.now() - startedAt;
|
|
86
|
-
console.log(`[runware-diag] fetchFromUpstream: response in ${elapsed}ms, status=${res.status} ${res.statusText}`);
|
|
87
63
|
if (!res.ok) {
|
|
88
|
-
// res.text() can throw synchronously (test mocks without a text()
|
|
89
|
-
// method, body already consumed elsewhere) — that TypeError isn't
|
|
90
|
-
// caught by .catch() because no promise was returned. Wrap in
|
|
91
|
-
// try/catch so we still throw the status-based error below
|
|
92
|
-
// instead of shadowing it with "res.text is not a function".
|
|
93
|
-
let errBody = "";
|
|
94
|
-
try {
|
|
95
|
-
errBody = await res.text();
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// body unreadable; status-based error below still surfaces
|
|
99
|
-
}
|
|
100
|
-
if (errBody) {
|
|
101
|
-
console.warn(`[runware-diag] fetchFromUpstream: non-OK body (first 200 chars): ${errBody.slice(0, 200)}`);
|
|
102
|
-
}
|
|
103
64
|
throw new Error(`Runware /models returned ${res.status} ${res.statusText}`);
|
|
104
65
|
}
|
|
105
66
|
const body = (await res.json());
|
|
106
|
-
const bodyKeys = Object.keys(body).join(",");
|
|
107
67
|
const data = Array.isArray(body.data) ? body.data : [];
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
console.log(`[runware-diag] fetchFromUpstream: body keys=[${bodyKeys}], data.length=${data.length}, first item keys=[${firstItemKeys}]`);
|
|
112
|
-
if (data.length === 0) {
|
|
113
|
-
// Surface what came back so we can see if Runware sent {data: null},
|
|
114
|
-
// {models: [...]} (wrong key), an error envelope, etc.
|
|
115
|
-
const bodyStr = JSON.stringify(body).slice(0, 500);
|
|
116
|
-
console.warn(`[runware-diag] fetchFromUpstream: data array is EMPTY. Body snippet: ${bodyStr}`);
|
|
117
|
-
}
|
|
118
|
-
const parsed = data.map(parseRunwareModel);
|
|
119
|
-
const valid = parsed.filter((m) => m !== null);
|
|
120
|
-
if (parsed.length !== valid.length) {
|
|
121
|
-
console.warn(`[runware-diag] fetchFromUpstream: dropped ${parsed.length - valid.length}/${parsed.length} models in parse (missing/invalid id)`);
|
|
122
|
-
}
|
|
123
|
-
if (valid.length > 0) {
|
|
124
|
-
const sample = valid
|
|
125
|
-
.slice(0, 5)
|
|
126
|
-
.map((m) => m.id)
|
|
127
|
-
.join(", ");
|
|
128
|
-
console.log(`[runware-diag] fetchFromUpstream: parsed ${valid.length} models, sample ids: ${sample}`);
|
|
129
|
-
}
|
|
130
|
-
return valid;
|
|
68
|
+
return data
|
|
69
|
+
.map(parseRunwareModel)
|
|
70
|
+
.filter((m) => m !== null);
|
|
131
71
|
}
|
|
132
72
|
finally {
|
|
133
73
|
clearTimeout(timeout);
|
package/dist/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAuBlC,IAAI,KAAK,GAA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AC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,KAAK,GAAG,IAAI,CAAC;IACb,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,KAAK,EAAE,WAkCZ,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
` Runware OpenClaw Provider v0.4.2 (debug build)\n` +
|
|
3
|
-
` index.ts loaded at: ${new Date().toISOString()}\n` +
|
|
4
|
-
"═══════════════════════════════════════════════════");
|
|
5
|
-
import { API_KEY_ENV_VAR, BASE_URL_ENV_VAR, PROVIDER_ID, PROVIDER_LABEL, buildCatalogRows, buildProvider, prewarmCatalog, resolveApiKey, resolveBaseUrl, } from "./models.js";
|
|
1
|
+
import { API_KEY_ENV_VAR, BASE_URL_ENV_VAR, PROVIDER_ID, PROVIDER_LABEL, buildCatalogRows, buildProvider, resolveApiKey, resolveBaseUrl, } from "./models.js";
|
|
6
2
|
import { startCostMetricPoller } from "./cost-metric.js";
|
|
7
3
|
// See cost-metric.ts. Idempotent across both entry files via
|
|
8
4
|
// globalThis-stored state — whichever module openclaw loads first wins.
|
|
9
5
|
startCostMetricPoller();
|
|
10
|
-
// Pre-fetch /v1/models in the background so the catalog cache is populated
|
|
11
|
-
// (or in flight) by the time openclaw calls catalog.run. Without this, the
|
|
12
|
-
// first model-list request sits on the gateway-startup critical path and
|
|
13
|
-
// frequently times out on a cold TLS handshake to Runware, leaving openclaw
|
|
14
|
-
// with an empty catalog. See models.ts → prewarmCatalog() for rationale.
|
|
15
|
-
prewarmCatalog();
|
|
16
6
|
const PLUGIN_ID = "runware-openclaw-provider";
|
|
17
7
|
/**
|
|
18
8
|
* Plugin entry that openclaw's plugin loader invokes after `npm install`-ing
|
|
@@ -40,7 +30,6 @@ const entry = {
|
|
|
40
30
|
name: PROVIDER_LABEL,
|
|
41
31
|
description: "Runware — unified OpenAI-compatible access to Claude, GPT, Gemini, Qwen, GLM, MiniMax, Kimi, and Gemma.",
|
|
42
32
|
register(api) {
|
|
43
|
-
console.log(`[runware-diag] index.ts register(api) CALLED by openclaw at ${new Date().toISOString()} — registering provider + catalog provider hooks`);
|
|
44
33
|
api.registerProvider({
|
|
45
34
|
id: PROVIDER_ID,
|
|
46
35
|
label: PROVIDER_LABEL,
|
|
@@ -50,25 +39,11 @@ const entry = {
|
|
|
50
39
|
catalog: {
|
|
51
40
|
order: "simple",
|
|
52
41
|
run: async (ctx) => {
|
|
53
|
-
const cid = Math.random().toString(36).slice(2, 8);
|
|
54
|
-
console.log(`[runware-diag] registerProvider.catalog.run[${cid}] called, ctx.env keys=[${Object.keys(ctx.env ?? {}).join(",") || "(none)"}], has resolveProviderApiKey=${typeof ctx.resolveProviderApiKey === "function"}`);
|
|
55
42
|
const apiKey = resolveApiKey(ctx);
|
|
56
|
-
if (!apiKey)
|
|
57
|
-
console.warn(`[runware-diag] registerProvider.catalog.run[${cid}]: no apiKey, returning null`);
|
|
43
|
+
if (!apiKey)
|
|
58
44
|
return null;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const provider = await buildProvider(apiKey, resolveBaseUrl(ctx.env));
|
|
62
|
-
console.log(`[runware-diag] registerProvider.catalog.run[${cid}]: SUCCESS, returning provider with ${provider.models.length} models`);
|
|
63
|
-
return { provider };
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
// fetchModels already retried with backoff. If we still failed
|
|
67
|
-
// every attempt, return null so openclaw treats the catalog as
|
|
68
|
-
// unpopulated rather than letting the throw bubble up.
|
|
69
|
-
console.error(`[runware-diag] registerProvider.catalog.run[${cid}]: FAILED after retries: ${err instanceof Error ? err.message : err}`);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
45
|
+
const provider = await buildProvider(apiKey, resolveBaseUrl(ctx.env));
|
|
46
|
+
return { provider };
|
|
72
47
|
},
|
|
73
48
|
},
|
|
74
49
|
});
|
|
@@ -76,25 +51,12 @@ const entry = {
|
|
|
76
51
|
provider: PROVIDER_ID,
|
|
77
52
|
kinds: ["text"],
|
|
78
53
|
liveCatalog: async (ctx) => {
|
|
79
|
-
const cid = Math.random().toString(36).slice(2, 8);
|
|
80
|
-
console.log(`[runware-diag] liveCatalog[${cid}] called, ctx.env keys=[${Object.keys(ctx.env ?? {}).join(",") || "(none)"}]`);
|
|
81
54
|
const apiKey = resolveApiKey(ctx);
|
|
82
|
-
if (!apiKey)
|
|
83
|
-
console.warn(`[runware-diag] liveCatalog[${cid}]: no apiKey, returning null`);
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const rows = await buildCatalogRows(apiKey, resolveBaseUrl(ctx.env));
|
|
88
|
-
console.log(`[runware-diag] liveCatalog[${cid}]: SUCCESS, returning ${rows.length} rows`);
|
|
89
|
-
return rows;
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
console.error(`[runware-diag] liveCatalog[${cid}]: FAILED after retries: ${err instanceof Error ? err.message : err}`);
|
|
55
|
+
if (!apiKey)
|
|
93
56
|
return null;
|
|
94
|
-
|
|
57
|
+
return buildCatalogRows(apiKey, resolveBaseUrl(ctx.env));
|
|
95
58
|
},
|
|
96
59
|
});
|
|
97
|
-
console.log(`[runware-diag] index.ts register(api): all hooks registered`);
|
|
98
60
|
},
|
|
99
61
|
};
|
|
100
62
|
export default entry;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,6DAA6D;AAC7D,wEAAwE;AACxE,qBAAqB,EAAE,CAAC;AAExB,MAAM,SAAS,GAAG,2BAA2B,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,KAAK,GAAgB;IACzB,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,cAAc;IACpB,WAAW,EACT,yGAAyG;IAE3G,QAAQ,CAAC,GAAG;QACV,GAAG,CAAC,gBAAgB,CAAC;YACnB,EAAE,EAAE,WAAW;YACf,KAAK,EAAE,cAAc;YACrB,QAAQ,EAAE,yBAAyB;YACnC,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;YAC5C,IAAI,EAAE,EAAE;YACR,OAAO,EAAE;gBACP,KAAK,EAAE,QAAQ;gBACf,GAAG,EAAE,KAAK,EAAE,GAAmB,EAAE,EAAE;oBACjC,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;oBAClC,IAAI,CAAC,MAAM;wBAAE,OAAO,IAAI,CAAC;oBACzB,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;oBACtE,OAAO,EAAE,QAAQ,EAAE,CAAC;gBACtB,CAAC;aACF;SACF,CAAC,CAAC;QAEH,GAAG,CAAC,4BAA4B,CAAC;YAC/B,QAAQ,EAAE,WAAW;YACrB,KAAK,EAAE,CAAC,MAAM,CAAC;YACf,WAAW,EAAE,KAAK,EAAE,GAAmB,EAAE,EAAE;gBACzC,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,CAAC,MAAM;oBAAE,OAAO,IAAI,CAAC;gBACzB,OAAO,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3D,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/models.d.ts
CHANGED
|
@@ -107,6 +107,5 @@ export declare function buildProvider(apiKey: string, baseUrl: string): Promise<
|
|
|
107
107
|
* response.
|
|
108
108
|
*/
|
|
109
109
|
export declare function buildCatalogRows(apiKey: string, baseUrl: string): Promise<ModelCatalogRow[]>;
|
|
110
|
-
export declare function prewarmCatalog(): void;
|
|
111
110
|
export {};
|
|
112
111
|
//# sourceMappingURL=models.d.ts.map
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEtD,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,cAAc,YAAY,CAAC;AACxC,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAC5D,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAGnD,eA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CAAC,GAAG,MAAM,CAI/E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE;IACjC,qBAAqB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC1C,GAAG,MAAM,GAAG,SAAS,CAKrB;AA2CD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,CAAC,CASxB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,EAAE,CAAC,CAG5B"}
|
package/dist/models.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* Runware hasn't published those limits fall back to conservative
|
|
10
10
|
* provider defaults so OpenClaw never sees a missing value.
|
|
11
11
|
*/
|
|
12
|
-
console.log(`[runware-diag] models.ts module loaded`);
|
|
13
12
|
import { fetchModels } from "./catalog.js";
|
|
14
13
|
export const PROVIDER_ID = "runware";
|
|
15
14
|
export const PROVIDER_LABEL = "Runware";
|
|
@@ -67,20 +66,11 @@ export function resolveBaseUrl(env) {
|
|
|
67
66
|
* managed deployment, where the user configured the key via the wizard).
|
|
68
67
|
*/
|
|
69
68
|
export function resolveApiKey(ctx) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const fromEnv = fromCtx ?? fromProc;
|
|
73
|
-
if (typeof fromEnv === "string" && fromEnv.length > 0) {
|
|
74
|
-
console.log(`[runware-diag] resolveApiKey: from ${fromCtx ? "ctx.env" : "process.env"} (length=${fromEnv.length})`);
|
|
69
|
+
const fromEnv = ctx.env?.[API_KEY_ENV_VAR] ?? process.env[API_KEY_ENV_VAR];
|
|
70
|
+
if (typeof fromEnv === "string" && fromEnv.length > 0)
|
|
75
71
|
return fromEnv;
|
|
76
|
-
}
|
|
77
72
|
const fromAuth = ctx.resolveProviderApiKey?.(PROVIDER_ID).apiKey;
|
|
78
|
-
|
|
79
|
-
console.log(`[runware-diag] resolveApiKey: from ctx.resolveProviderApiKey (length=${fromAuth.length})`);
|
|
80
|
-
return fromAuth;
|
|
81
|
-
}
|
|
82
|
-
console.warn(`[runware-diag] resolveApiKey: NOT FOUND. ctx.env has key=${ctx.env !== undefined && API_KEY_ENV_VAR in ctx.env}, process.env has key=${process.env[API_KEY_ENV_VAR] !== undefined}, ctx.resolveProviderApiKey=${typeof ctx.resolveProviderApiKey === "function"}`);
|
|
83
|
-
return undefined;
|
|
73
|
+
return typeof fromAuth === "string" && fromAuth.length > 0 ? fromAuth : undefined;
|
|
84
74
|
}
|
|
85
75
|
function buildModelInput(model) {
|
|
86
76
|
return model.inputModalities?.includes("image") ? ["text", "image"] : ["text"];
|
|
@@ -126,21 +116,13 @@ function buildCatalogRow(model) {
|
|
|
126
116
|
* `/v1/models` from Runware via the TTL cache in `catalog.ts`.
|
|
127
117
|
*/
|
|
128
118
|
export async function buildProvider(apiKey, baseUrl) {
|
|
129
|
-
console.log(`[runware-diag] buildProvider: invoked with baseUrl=${baseUrl}, apiKey length=${apiKey.length}`);
|
|
130
119
|
const models = await fetchModels(baseUrl, apiKey);
|
|
131
|
-
const entries = models.map(buildModelEntry);
|
|
132
|
-
console.log(`[runware-diag] buildProvider: returning ProviderShape with ${entries.length} models${entries.length > 0
|
|
133
|
-
? ` (sample: ${entries
|
|
134
|
-
.slice(0, 5)
|
|
135
|
-
.map((m) => m.id)
|
|
136
|
-
.join(", ")})`
|
|
137
|
-
: ""}`);
|
|
138
120
|
return {
|
|
139
121
|
baseUrl,
|
|
140
122
|
apiKey,
|
|
141
123
|
api: "openai-completions",
|
|
142
124
|
timeoutSeconds: REQUEST_TIMEOUT_SECONDS,
|
|
143
|
-
models:
|
|
125
|
+
models: models.map(buildModelEntry),
|
|
144
126
|
};
|
|
145
127
|
}
|
|
146
128
|
/**
|
|
@@ -150,53 +132,7 @@ export async function buildProvider(apiKey, baseUrl) {
|
|
|
150
132
|
* response.
|
|
151
133
|
*/
|
|
152
134
|
export async function buildCatalogRows(apiKey, baseUrl) {
|
|
153
|
-
console.log(`[runware-diag] buildCatalogRows: invoked with baseUrl=${baseUrl}`);
|
|
154
135
|
const models = await fetchModels(baseUrl, apiKey);
|
|
155
|
-
|
|
156
|
-
console.log(`[runware-diag] buildCatalogRows: returning ${rows.length} rows`);
|
|
157
|
-
return rows;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Kick off a background `/v1/models` fetch at module load so the catalog
|
|
161
|
-
* cache is populated (or in-flight) by the time openclaw calls
|
|
162
|
-
* `catalog.run`. Idempotent — `fetchModels` deduplicates concurrent calls
|
|
163
|
-
* via its inflight promise, and a populated cache short-circuits
|
|
164
|
-
* subsequent calls — so it's safe to invoke from multiple entry files
|
|
165
|
-
* (index.ts and provider-discovery.ts).
|
|
166
|
-
*
|
|
167
|
-
* This is the main mitigation for "openclaw starts up and Runware's
|
|
168
|
-
* model list is missing": the first /v1/models call is the slow one
|
|
169
|
-
* (cold DNS, TLS handshake) and is the one most likely to time out
|
|
170
|
-
* before openclaw's catalog resolution window closes. Pre-warming
|
|
171
|
-
* moves that latency off the critical path — by the time openclaw asks
|
|
172
|
-
* for the catalog the fetch is either complete (cache hit) or in flight
|
|
173
|
-
* (inflight dedup), so the worst case is now "wait for one in-flight
|
|
174
|
-
* request" instead of "start a new request from cold under whatever
|
|
175
|
-
* deadline openclaw has".
|
|
176
|
-
*
|
|
177
|
-
* If RUNWARE_API_KEY isn't in env yet (out-of-cluster dev, unusually
|
|
178
|
-
* early module load), the prewarm silently skips and the next
|
|
179
|
-
* `catalog.run` invocation resolves the key from its `ctx` argument
|
|
180
|
-
* — fetchWithRetries still gives us 3 attempts at that point.
|
|
181
|
-
*/
|
|
182
|
-
let prewarmStarted = false;
|
|
183
|
-
export function prewarmCatalog() {
|
|
184
|
-
if (prewarmStarted)
|
|
185
|
-
return;
|
|
186
|
-
const apiKey = resolveApiKey({ env: process.env });
|
|
187
|
-
if (!apiKey) {
|
|
188
|
-
console.log("[runware-catalog] prewarm skipped — RUNWARE_API_KEY not in env yet");
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
prewarmStarted = true;
|
|
192
|
-
const baseUrl = resolveBaseUrl(process.env);
|
|
193
|
-
fetchModels(baseUrl, apiKey).then((models) => console.log(`[runware-catalog] prewarm loaded ${models.length} models`), (err) => {
|
|
194
|
-
// Reset the flag so the next entry-point's prewarmCatalog() call
|
|
195
|
-
// (or the catalog.run hook) re-attempts the fetch. fetchModels'
|
|
196
|
-
// own retry loop already burned its attempts; on persistent failure
|
|
197
|
-
// we let catalog.run fall through to its empty-provider path.
|
|
198
|
-
prewarmStarted = false;
|
|
199
|
-
console.warn(`[runware-catalog] prewarm failed (will retry on catalog.run): ${err instanceof Error ? err.message : err}`);
|
|
200
|
-
});
|
|
136
|
+
return models.map(buildCatalogRow);
|
|
201
137
|
}
|
|
202
138
|
//# sourceMappingURL=models.js.map
|
package/dist/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAK3C,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC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AAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-discovery.d.ts","sourceRoot":"","sources":["../src/provider-discovery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider-discovery.d.ts","sourceRoot":"","sources":["../src/provider-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAMjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAUjD;;;;;;;;;;;;;;GAcG;AAEH,UAAU,YAAY;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,qBAAqB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE;AAYD,iBAAe,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,aAAa,CAAA;CAAE,CAAC,CAUxF;AAED,QAAA,MAAM,wBAAwB;;;;;;;;;;CAU7B,CAAC;AAEF,eAAe,wBAAwB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
` Runware OpenClaw Provider v0.4.2 (debug build)\n` +
|
|
3
|
-
` provider-discovery.ts loaded at: ${new Date().toISOString()}\n` +
|
|
4
|
-
"═══════════════════════════════════════════════════");
|
|
5
|
-
import { API_KEY_ENV_VAR, BASE_URL_ENV_VAR, DEFAULT_BASE_URL, PROVIDER_ID, PROVIDER_LABEL, buildProvider, prewarmCatalog, resolveApiKey, resolveBaseUrl, } from "./models.js";
|
|
1
|
+
import { API_KEY_ENV_VAR, BASE_URL_ENV_VAR, DEFAULT_BASE_URL, PROVIDER_ID, PROVIDER_LABEL, buildProvider, resolveApiKey, resolveBaseUrl, } from "./models.js";
|
|
6
2
|
import { startCostMetricPoller } from "./cost-metric.js";
|
|
7
3
|
// Emit `openclaw.cost.usd` OpenTelemetry counter from runware transcript
|
|
8
4
|
// entries. Compensates for openclaw's broken diagnostic-path pricing
|
|
@@ -10,14 +6,6 @@ import { startCostMetricPoller } from "./cost-metric.js";
|
|
|
10
6
|
// cost-metric.ts for the full rationale. Idempotent: also called from
|
|
11
7
|
// index.ts, second call is a no-op.
|
|
12
8
|
startCostMetricPoller();
|
|
13
|
-
// Pre-fetch /v1/models in the background so the catalog cache is populated
|
|
14
|
-
// (or in flight) by the time openclaw calls catalog.run. Without this the
|
|
15
|
-
// first /v1/models request sits on the gateway-startup critical path and
|
|
16
|
-
// frequently times out on a cold TLS handshake to Runware, leaving openclaw
|
|
17
|
-
// with an empty Runware catalog until a fresh restart succeeds. See
|
|
18
|
-
// models.ts → prewarmCatalog() for rationale. Idempotent: also called from
|
|
19
|
-
// index.ts, second call short-circuits on the prewarmStarted flag.
|
|
20
|
-
prewarmCatalog();
|
|
21
9
|
function emptyProvider(baseUrl) {
|
|
22
10
|
return {
|
|
23
11
|
baseUrl,
|
|
@@ -28,8 +16,6 @@ function emptyProvider(baseUrl) {
|
|
|
28
16
|
};
|
|
29
17
|
}
|
|
30
18
|
async function runwareCatalogRun(ctx) {
|
|
31
|
-
const cid = Math.random().toString(36).slice(2, 8);
|
|
32
|
-
console.log(`[runware-diag] runwareCatalogRun[${cid}] CALLED at ${new Date().toISOString()}, ctx.env keys=[${Object.keys(ctx.env ?? {}).join(",") || "(none)"}], has resolveProviderApiKey=${typeof ctx.resolveProviderApiKey === "function"}`);
|
|
33
19
|
const baseUrl = resolveBaseUrl(ctx.env);
|
|
34
20
|
const apiKey = resolveApiKey(ctx);
|
|
35
21
|
// No API key reachable yet (e.g. the gateway is starting up before the
|
|
@@ -37,33 +23,9 @@ async function runwareCatalogRun(ctx) {
|
|
|
37
23
|
// an empty provider shape so openclaw treats the catalog as "known but
|
|
38
24
|
// currently unpopulated" rather than crashing. The next invocation will
|
|
39
25
|
// re-resolve and fill in models once the key is present.
|
|
40
|
-
if (!apiKey)
|
|
41
|
-
console.warn(`[runware-diag] runwareCatalogRun[${cid}]: NO API KEY, returning EMPTY provider — openclaw will see 0 models`);
|
|
26
|
+
if (!apiKey)
|
|
42
27
|
return { provider: emptyProvider(baseUrl) };
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const provider = await buildProvider(apiKey, baseUrl);
|
|
46
|
-
console.log(`[runware-diag] runwareCatalogRun[${cid}]: RETURNING provider with ${provider.models.length} models${provider.models.length > 0
|
|
47
|
-
? `, sample: ${provider.models
|
|
48
|
-
.slice(0, 5)
|
|
49
|
-
.map((m) => m.id)
|
|
50
|
-
.join(", ")}`
|
|
51
|
-
: " — openclaw will see EMPTY DROPDOWN"}`);
|
|
52
|
-
return { provider };
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
// fetchModels already retried with exponential backoff (catalog.ts).
|
|
56
|
-
// If we still failed every attempt, return an empty provider so
|
|
57
|
-
// openclaw treats the catalog as "unpopulated, will retry" rather
|
|
58
|
-
// than letting the throw bubble up — historically that bubble was
|
|
59
|
-
// the proximate cause of "Runware models missing" after a gateway
|
|
60
|
-
// restart, because the first cold-start /v1/models call timed out
|
|
61
|
-
// and there was no recovery path. The next catalog.run invocation
|
|
62
|
-
// will retry; if a concurrent retry is already in flight the
|
|
63
|
-
// inflight dedup in fetchModels makes both share one upstream call.
|
|
64
|
-
console.error(`[runware-diag] runwareCatalogRun[${cid}]: FAILED after retries, returning EMPTY provider: ${err instanceof Error ? err.message : err}`);
|
|
65
|
-
return { provider: emptyProvider(baseUrl) };
|
|
66
|
-
}
|
|
28
|
+
return { provider: await buildProvider(apiKey, baseUrl) };
|
|
67
29
|
}
|
|
68
30
|
const runwareProviderDiscovery = {
|
|
69
31
|
id: PROVIDER_ID,
|
|
@@ -76,7 +38,6 @@ const runwareProviderDiscovery = {
|
|
|
76
38
|
run: runwareCatalogRun,
|
|
77
39
|
},
|
|
78
40
|
};
|
|
79
|
-
console.log(`[runware-diag] provider-discovery.ts default export READY: id=${runwareProviderDiscovery.id}, label=${runwareProviderDiscovery.label}, catalog.order=${runwareProviderDiscovery.catalog.order}, envVars=[${runwareProviderDiscovery.envVars.join(",")}]`);
|
|
80
41
|
export default runwareProviderDiscovery;
|
|
81
42
|
export { DEFAULT_BASE_URL };
|
|
82
43
|
//# sourceMappingURL=provider-discovery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-discovery.js","sourceRoot":"","sources":["../src/provider-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"provider-discovery.js","sourceRoot":"","sources":["../src/provider-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,yEAAyE;AACzE,qEAAqE;AACrE,+DAA+D;AAC/D,sEAAsE;AACtE,oCAAoC;AACpC,qBAAqB,EAAE,CAAC;AAuBxB,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO;QACL,OAAO;QACP,MAAM,EAAE,EAAE;QACV,GAAG,EAAE,oBAAoB;QACzB,cAAc,EAAE,GAAG;QACnB,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,GAAiB;IAChD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,uEAAuE;IACvE,0EAA0E;IAC1E,uEAAuE;IACvE,wEAAwE;IACxE,yDAAyD;IACzD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;IACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,wBAAwB,GAAG;IAC/B,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,yBAAyB;IACnC,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC5C,IAAI,EAAE,EAAE;IACR,OAAO,EAAE;QACP,KAAK,EAAE,MAAe;QACtB,GAAG,EAAE,iBAAiB;KACvB;CACF,CAAC;AAEF,eAAe,wBAAwB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teith/openclaw-runware-provider",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "OpenClaw provider plugin for Runware — unified OpenAI-compatible access to Claude, GPT, Gemini, Qwen, GLM, MiniMax, Kimi, and Gemma.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|