@openclaw/venice-provider 2026.11.3 → 2026.11.5-beta.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.
@@ -1,5 +1,6 @@
1
1
  import { parseVeniceModelPricing } from "../pricing-api.js";
2
2
  import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ import { floorPositiveFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
3
4
  import { buildManifestModelProviderConfig, readManifestProviderDefaultModelRef } from "openclaw/plugin-sdk/provider-catalog-shared";
4
5
  //#region extensions/venice/openclaw.plugin.json
5
6
  var openclaw_plugin_default = {
@@ -389,17 +390,6 @@ const VENICE_MODEL_CATALOG = buildManifestModelProviderConfig({
389
390
  providerId: "venice",
390
391
  catalog: VENICE_MANIFEST_CATALOG
391
392
  }).models;
392
- function normalizePositiveInt(value) {
393
- if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return;
394
- return Math.floor(value);
395
- }
396
- function resolveApiMaxCompletionTokens(params) {
397
- const raw = normalizePositiveInt(params.apiModel.model_spec?.maxCompletionTokens);
398
- if (!raw) return;
399
- const contextWindow = normalizePositiveInt(params.apiModel.model_spec?.availableContextTokens);
400
- const knownMaxTokens = typeof params.knownMaxTokens === "number" && Number.isFinite(params.knownMaxTokens) ? Math.floor(params.knownMaxTokens) : void 0;
401
- return Math.min(raw, contextWindow ?? knownMaxTokens ?? VENICE_DEFAULT_CONTEXT_WINDOW, knownMaxTokens ?? VENICE_DISCOVERY_HARD_MAX_TOKENS);
402
- }
403
393
  function projectVeniceModels(rows, fallback) {
404
394
  const catalogById = new Map(fallback.models.map((model) => [model.id, model]));
405
395
  const models = [];
@@ -409,17 +399,19 @@ function projectVeniceModels(rows, fallback) {
409
399
  if (typeof apiModel.id !== "string" || !apiModel.id.trim()) continue;
410
400
  const catalogEntry = catalogById.get(apiModel.id);
411
401
  const liveCost = parseVeniceModelPricing(apiModel.model_spec?.pricing);
412
- const apiMaxTokens = resolveApiMaxCompletionTokens({
413
- apiModel,
414
- knownMaxTokens: catalogEntry?.maxTokens
415
- });
402
+ const knownMaxTokens = catalogEntry?.maxTokens;
403
+ const raw = floorPositiveFiniteNumber(apiModel.model_spec?.maxCompletionTokens);
404
+ let apiMaxTokens;
405
+ if (raw) {
406
+ const contextWindow = floorPositiveFiniteNumber(apiModel.model_spec?.availableContextTokens);
407
+ const knownCap = knownMaxTokens === void 0 ? void 0 : Math.floor(knownMaxTokens);
408
+ apiMaxTokens = Math.min(raw, contextWindow ?? knownCap ?? VENICE_DEFAULT_CONTEXT_WINDOW, knownCap ?? VENICE_DISCOVERY_HARD_MAX_TOKENS);
409
+ }
416
410
  const supportsTools = apiModel.model_spec?.capabilities?.supportsFunctionCalling;
417
411
  if (catalogEntry) {
418
412
  const definition = {
419
413
  ...catalogEntry,
420
- input: [...catalogEntry.input],
421
- cost: liveCost ?? { ...catalogEntry.cost },
422
- ...catalogEntry.compat ? { compat: { ...catalogEntry.compat } } : {}
414
+ cost: liveCost ?? catalogEntry.cost
423
415
  };
424
416
  if (apiMaxTokens !== void 0) definition.maxTokens = apiMaxTokens;
425
417
  if (supportsTools === false) definition.compat = {
@@ -438,7 +430,7 @@ function projectVeniceModels(rows, fallback) {
438
430
  reasoning: isReasoning,
439
431
  input: hasVision ? ["text", "image"] : ["text"],
440
432
  cost: liveCost ?? VENICE_DEFAULT_COST,
441
- contextWindow: normalizePositiveInt(apiSpec?.availableContextTokens) ?? VENICE_DEFAULT_CONTEXT_WINDOW,
433
+ contextWindow: floorPositiveFiniteNumber(apiSpec?.availableContextTokens) ?? VENICE_DEFAULT_CONTEXT_WINDOW,
442
434
  maxTokens: apiMaxTokens ?? VENICE_DEFAULT_MAX_TOKENS,
443
435
  compat: {
444
436
  supportsUsageInStreaming: false,
@@ -0,0 +1 @@
1
+ {"version":3,"entries":[{"output":"api.js","source":"extensions/venice/api.ts"},{"output":"index.js","source":"extensions/venice/index.ts"},{"output":"models.js","source":"extensions/venice/models.ts"},{"output":"onboard.js","source":"extensions/venice/onboard.ts"},{"output":"pricing-api.js","source":"extensions/venice/pricing-api.ts"},{"output":"provider-catalog.js","source":"extensions/venice/provider-catalog.ts"},{"output":"stream.js","source":"extensions/venice/stream.ts"}],"chunks":[{"output":".setup/models-VFsL4jET.mjs","sha256":"7400985279b1242c929419058fb21605c2624b2721bda9817a5007b02c44a005","facadeSource":null,"sources":["extensions/venice/models.ts","extensions/venice/openclaw.plugin.json"]},{"output":"api.js","sha256":"fc3a500377e408b4330fec62ce57ae0fc8becd4f05d00c8a9fe3875d92e4d5ab","facadeSource":"extensions/venice/api.ts","sources":[]},{"output":"index.js","sha256":"930debe23d9626f93b5075a068b393314fdcc134e0e2d8d654106374337ddf6f","facadeSource":"extensions/venice/index.ts","sources":["extensions/venice/index.ts"]},{"output":"models.js","sha256":"4c3545cba51a51ee13ad062945213afbf76ec43fd949489ac47480d9db007ae8","facadeSource":"extensions/venice/models.ts","sources":[]},{"output":"onboard.js","sha256":"0a144e0da3df8c50465b82afa849f4d383e77622ce65370302d71c9de9d39342","facadeSource":"extensions/venice/onboard.ts","sources":["extensions/venice/onboard.ts"]},{"output":"pricing-api.js","sha256":"19d663f3b05ced3c05908f78f4034fc13cad3403543ee695199137eda2a58748","facadeSource":"extensions/venice/pricing-api.ts","sources":["extensions/venice/pricing-api.ts"]},{"output":"provider-catalog.js","sha256":"3da7067c948adf7b24503f62982abd159a1976e5d64e67bc35ff0ef7062b0687","facadeSource":"extensions/venice/provider-catalog.ts","sources":["extensions/venice/provider-catalog.ts"]},{"output":"stream.js","sha256":"1f9fbf5c789ab44df868511905c343a9b3622eba9eb161a57ff66b7852e54e19","facadeSource":"extensions/venice/stream.ts","sources":["extensions/venice/stream.ts"]}],"unrenderedSources":["extensions/venice/api.ts"]}
package/dist/api.js CHANGED
@@ -1,2 +1 @@
1
- import { n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-D73jPrCr.mjs";
2
- export { VENICE_BASE_URL, VENICE_DEFAULT_MODEL_REF, VENICE_MODEL_CATALOG };
1
+ export { t as VENICE_BASE_URL, n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG } from "./.setup/models-VFsL4jET.mjs";
package/dist/index.js CHANGED
@@ -1,13 +1,16 @@
1
- import { a as openclaw_plugin_default, i as VENICE_MODEL_DISCOVERY_OPTIONS, t as VENICE_BASE_URL } from "./.setup/models-D73jPrCr.mjs";
1
+ import { a as openclaw_plugin_default, i as VENICE_MODEL_DISCOVERY_OPTIONS, t as VENICE_BASE_URL } from "./.setup/models-VFsL4jET.mjs";
2
2
  import { applyVeniceConfig } from "./onboard.js";
3
3
  import { buildStaticVeniceProvider } from "./provider-catalog.js";
4
4
  import { createVeniceStreamWrapper } from "./stream.js";
5
- import { fetchVeniceUsage } from "./usage.js";
6
5
  import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
6
+ import { readProviderJsonObjectResponse } from "openclaw/plugin-sdk/provider-http";
7
7
  import { applyModelCompatPatch } from "openclaw/plugin-sdk/provider-model-shared";
8
+ import { buildUsageErrorSnapshot, buildUsageHttpErrorSnapshot, parseProviderUsageNonNegativeNumber, resolveProviderUsageApiKeyAuth } from "openclaw/plugin-sdk/provider-usage";
8
9
  import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
9
10
  //#region extensions/venice/index.ts
10
11
  const PROVIDER_ID = "venice";
12
+ const VENICE_BALANCE_URL = "https://api.venice.ai/api/v1/billing/balance";
13
+ const VENICE_USAGE_RESPONSE_MAX_BYTES = 1048576;
11
14
  const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = [
12
15
  "minLength",
13
16
  "maxLength",
@@ -16,9 +19,6 @@ const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = [
16
19
  "minContains",
17
20
  "maxContains"
18
21
  ];
19
- function isXaiBackedVeniceModel(modelId) {
20
- return normalizeLowercaseStringOrEmpty(modelId).includes("grok");
21
- }
22
22
  var venice_default = defineSingleProviderPluginEntry({
23
23
  id: PROVIDER_ID,
24
24
  name: "Venice Provider",
@@ -42,7 +42,7 @@ var venice_default = defineSingleProviderPluginEntry({
42
42
  liveModelDiscovery: VENICE_MODEL_DISCOVERY_OPTIONS
43
43
  },
44
44
  normalizeResolvedModel: ({ modelId, model }) => {
45
- const normalized = isXaiBackedVeniceModel(modelId) ? applyModelCompatPatch(model, {
45
+ const normalized = normalizeLowercaseStringOrEmpty(modelId).includes("grok") ? applyModelCompatPatch(model, {
46
46
  toolSchemaProfile: "xai",
47
47
  unsupportedToolSchemaKeywords: [...XAI_UNSUPPORTED_SCHEMA_KEYWORDS],
48
48
  toolCallArgumentsEncoding: "html-entities"
@@ -53,15 +53,76 @@ var venice_default = defineSingleProviderPluginEntry({
53
53
  }) : normalized;
54
54
  },
55
55
  wrapStreamFn: (ctx) => createVeniceStreamWrapper(ctx.streamFn),
56
- resolveUsageAuth: async (ctx) => {
57
- const apiKey = (await ctx.resolveApiKeyCandidatesFromConfigAndStore?.({ envDirect: [ctx.env.VENICE_API_KEY] }))?.[0];
58
- return apiKey ? { token: apiKey } : null;
59
- },
60
- fetchUsageSnapshot: async (ctx) => await fetchVeniceUsage({
61
- token: ctx.token,
62
- timeoutMs: ctx.timeoutMs,
63
- fetchFn: ctx.fetchFn
64
- })
56
+ resolveUsageAuth: (ctx) => resolveProviderUsageApiKeyAuth(ctx, [ctx.env.VENICE_API_KEY]),
57
+ fetchUsageSnapshot: async (ctx) => {
58
+ let response;
59
+ try {
60
+ response = await ctx.fetchFn(VENICE_BALANCE_URL, {
61
+ headers: {
62
+ Accept: "application/json",
63
+ Authorization: `Bearer ${ctx.token}`
64
+ },
65
+ signal: AbortSignal.timeout(ctx.timeoutMs)
66
+ });
67
+ } catch {
68
+ return buildUsageErrorSnapshot("venice", "Usage unavailable");
69
+ }
70
+ if (!response.ok) {
71
+ await response.body?.cancel().catch(() => void 0);
72
+ return buildUsageHttpErrorSnapshot({
73
+ provider: "venice",
74
+ status: response.status
75
+ });
76
+ }
77
+ let data;
78
+ try {
79
+ data = await readProviderJsonObjectResponse(response, "Venice usage", {
80
+ maxBytes: VENICE_USAGE_RESPONSE_MAX_BYTES,
81
+ chunkTimeoutMs: ctx.timeoutMs,
82
+ onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Venice usage response stalled for ${chunkTimeoutMs}ms`)
83
+ });
84
+ } catch {
85
+ return buildUsageErrorSnapshot("venice", "Malformed usage response");
86
+ }
87
+ const diem = parseProviderUsageNonNegativeNumber(data.balances?.diem);
88
+ const usd = parseProviderUsageNonNegativeNumber(data.balances?.usd);
89
+ const allocation = parseProviderUsageNonNegativeNumber(data.diemEpochAllocation);
90
+ const windows = [];
91
+ if (diem !== void 0 && allocation !== void 0 && allocation > 0) windows.push({
92
+ label: "DIEM epoch",
93
+ usedPercent: Math.min(100, Math.max(0, (allocation - diem) / allocation * 100))
94
+ });
95
+ const billing = [];
96
+ if (diem !== void 0) billing.push({
97
+ type: "balance",
98
+ label: "DIEM balance",
99
+ amount: diem,
100
+ unit: "DIEM"
101
+ });
102
+ if (usd !== void 0) billing.push({
103
+ type: "balance",
104
+ label: "USD balance",
105
+ amount: usd,
106
+ unit: "USD"
107
+ });
108
+ if (diem !== void 0 && allocation !== void 0 && allocation > 0) billing.push({
109
+ type: "budget",
110
+ label: "DIEM epoch",
111
+ used: Math.max(0, allocation - diem),
112
+ limit: allocation,
113
+ unit: "DIEM",
114
+ period: "epoch"
115
+ });
116
+ const consumptionCurrency = typeof data.consumptionCurrency === "string" ? data.consumptionCurrency.trim().toUpperCase() : "";
117
+ return {
118
+ provider: "venice",
119
+ displayName: "Venice",
120
+ windows,
121
+ ...billing.length > 0 ? { billing } : {},
122
+ ...consumptionCurrency ? { plan: `${consumptionCurrency} billing` } : {},
123
+ ...data.canConsume === false ? { summary: "API consumption unavailable" } : {}
124
+ };
125
+ }
65
126
  }
66
127
  });
67
128
  //#endregion
package/dist/models.js CHANGED
@@ -1,2 +1 @@
1
- import { i as VENICE_MODEL_DISCOVERY_OPTIONS, n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-D73jPrCr.mjs";
2
- export { VENICE_BASE_URL, VENICE_DEFAULT_MODEL_REF, VENICE_MODEL_CATALOG, VENICE_MODEL_DISCOVERY_OPTIONS };
1
+ export { t as VENICE_BASE_URL, n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG, i as VENICE_MODEL_DISCOVERY_OPTIONS } from "./.setup/models-VFsL4jET.mjs";
package/dist/onboard.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-D73jPrCr.mjs";
1
+ import { n as VENICE_DEFAULT_MODEL_REF, r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-VFsL4jET.mjs";
2
2
  import { createProviderConnectionPresetAppliers } from "openclaw/plugin-sdk/provider-onboard";
3
3
  //#region extensions/venice/onboard.ts
4
4
  const { applyConfig: applyVeniceConfig } = createProviderConnectionPresetAppliers({
@@ -1,10 +1,10 @@
1
- import { r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-D73jPrCr.mjs";
1
+ import { r as VENICE_MODEL_CATALOG, t as VENICE_BASE_URL } from "./.setup/models-VFsL4jET.mjs";
2
2
  //#region extensions/venice/provider-catalog.ts
3
3
  function buildStaticVeniceProvider() {
4
4
  return {
5
5
  baseUrl: VENICE_BASE_URL,
6
6
  api: "openai-completions",
7
- models: structuredClone(VENICE_MODEL_CATALOG)
7
+ models: VENICE_MODEL_CATALOG
8
8
  };
9
9
  }
10
10
  //#endregion
package/dist/stream.js CHANGED
@@ -1,15 +1,6 @@
1
1
  import { asOptionalObjectRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
2
2
  import { createPayloadPatchStreamWrapper, normalizeOpenAICompatibleReasoningReplay } from "openclaw/plugin-sdk/provider-stream-shared";
3
3
  //#region extensions/venice/stream.ts
4
- function isVeniceDeepSeekV4ModelId(modelId) {
5
- return modelId === "deepseek-v4-flash" || modelId === "deepseek-v4-pro";
6
- }
7
- function isVeniceGeminiModelId(modelId) {
8
- return typeof modelId === "string" && modelId.trim().toLowerCase().startsWith("gemini-");
9
- }
10
- function isVeniceGemini3ModelId(modelId) {
11
- return typeof modelId === "string" && /^gemini-3(?:[.-]|$)/.test(modelId.trim().toLowerCase());
12
- }
13
4
  function stringifyHistoricalValue(value) {
14
5
  if (typeof value === "string") return value;
15
6
  if (value === null || value === void 0) return "";
@@ -19,91 +10,9 @@ function stringifyHistoricalValue(value) {
19
10
  return "[Unserializable historical value]";
20
11
  }
21
12
  }
22
- function describeHistoricalToolCall(toolCall) {
23
- const fn = asOptionalObjectRecord(toolCall.function);
24
- const name = typeof fn?.name === "string" && fn.name.length > 0 ? fn.name : "unknown_tool";
25
- const args = stringifyHistoricalValue(fn?.arguments) || "{}";
26
- return {
27
- ...typeof toolCall.id === "string" ? { id: toolCall.id } : {},
28
- name,
29
- text: `[Historical tool call: ${name}(${args})]`
30
- };
31
- }
32
- function applyVeniceGeminiToolHistoryCompatibility(payload, context, model) {
33
- if (model.provider !== "venice" || !isVeniceGeminiModelId(model.id)) return;
34
- const historicalToolCallBatches = [];
35
- let hasHistoricalSignature = false;
36
- const requiresUnsignedCallFallback = isVeniceGemini3ModelId(model.id);
37
- for (const message of context.messages ?? []) {
38
- if (message.role !== "assistant" || message.stopReason === "error" || message.stopReason === "aborted") continue;
39
- const isExactRoute = message.api === model.api && message.provider === model.provider && message.model === model.id;
40
- const batch = [];
41
- for (const block of message.content) {
42
- if (block.type !== "toolCall" || typeof block.id !== "string") continue;
43
- const thoughtSignature = isExactRoute && typeof block.thoughtSignature === "string" && block.thoughtSignature.length > 0 ? block.thoughtSignature : void 0;
44
- hasHistoricalSignature ||= thoughtSignature !== void 0;
45
- batch.push({
46
- id: block.id,
47
- name: block.name,
48
- ...thoughtSignature ? { thoughtSignature } : {}
49
- });
50
- }
51
- if (batch.length > 0) historicalToolCallBatches.push(batch);
52
- }
53
- if (!hasHistoricalSignature && !requiresUnsignedCallFallback || !Array.isArray(payload.messages)) return;
54
- let historicalBatchIndex = 0;
55
- let pendingDowngradedToolCalls;
56
- for (const message of payload.messages) {
57
- const record = asOptionalObjectRecord(message);
58
- if (!record) {
59
- pendingDowngradedToolCalls = void 0;
60
- continue;
61
- }
62
- if (record.role === "tool") {
63
- const toolCallId = typeof record.tool_call_id === "string" ? record.tool_call_id : void 0;
64
- if (!toolCallId) continue;
65
- const pendingCalls = pendingDowngradedToolCalls;
66
- if (!pendingCalls) continue;
67
- const toolNames = pendingCalls.get(toolCallId);
68
- if (!toolNames) continue;
69
- const toolName = toolNames.shift();
70
- if (!toolName) continue;
71
- if (toolNames.length === 0) pendingCalls.delete(toolCallId);
72
- const result = stringifyHistoricalValue(record.content);
73
- for (const key of Object.keys(record)) delete record[key];
74
- record.role = "user";
75
- record.content = `[Historical tool result for ${toolName}:\n${result}]`;
76
- continue;
77
- }
78
- pendingDowngradedToolCalls = void 0;
79
- if (record.role !== "assistant" || !Array.isArray(record.tool_calls)) continue;
80
- const historicalBatch = historicalToolCallBatches[historicalBatchIndex++];
81
- let shouldDowngradeBatch = false;
82
- const describedCalls = [];
83
- for (const [toolCallIndex, toolCall] of record.tool_calls.entries()) {
84
- const toolCallRecord = asOptionalObjectRecord(toolCall);
85
- if (!toolCallRecord) continue;
86
- const historicalCall = historicalBatch?.[toolCallIndex];
87
- const describedCall = describeHistoricalToolCall(toolCallRecord);
88
- const signature = historicalCall && historicalCall.id === toolCallRecord.id && historicalCall.name === describedCall.name ? historicalCall.thoughtSignature : void 0;
89
- if (signature) toolCallRecord.thought_signature = signature;
90
- else if (requiresUnsignedCallFallback) shouldDowngradeBatch = true;
91
- describedCalls.push(describedCall);
92
- }
93
- if (!shouldDowngradeBatch) continue;
94
- pendingDowngradedToolCalls = /* @__PURE__ */ new Map();
95
- for (const call of describedCalls) if (call.id) {
96
- const names = pendingDowngradedToolCalls.get(call.id) ?? [];
97
- names.push(call.name);
98
- pendingDowngradedToolCalls.set(call.id, names);
99
- }
100
- record.content = [stringifyHistoricalValue(record.content), ...describedCalls.map((call) => call.text)].filter((part) => part.length > 0).join("\n");
101
- delete record.tool_calls;
102
- }
103
- }
104
13
  function createVeniceStreamWrapper(baseStreamFn) {
105
14
  return createPayloadPatchStreamWrapper(baseStreamFn, ({ payload, context, model }) => {
106
- if (model.provider === "venice" && isVeniceDeepSeekV4ModelId(model.id)) {
15
+ if (model.provider === "venice" && (model.id === "deepseek-v4-flash" || model.id === "deepseek-v4-pro")) {
107
16
  delete payload.thinking;
108
17
  delete payload.reasoning;
109
18
  delete payload.reasoning_effort;
@@ -112,7 +21,83 @@ function createVeniceStreamWrapper(baseStreamFn) {
112
21
  replaceNullReasoningContent: true
113
22
  });
114
23
  }
115
- applyVeniceGeminiToolHistoryCompatibility(payload, context, model);
24
+ if (model.provider !== "venice" || !model.id.trim().toLowerCase().startsWith("gemini-")) return;
25
+ const historicalToolCallBatches = [];
26
+ let hasHistoricalSignature = false;
27
+ const requiresUnsignedCallFallback = /^gemini-3(?:[.-]|$)/.test(model.id.trim().toLowerCase());
28
+ for (const message of context.messages) {
29
+ if (message.role !== "assistant" || message.stopReason === "error" || message.stopReason === "aborted") continue;
30
+ const isExactRoute = message.api === model.api && message.provider === model.provider && message.model === model.id;
31
+ const batch = [];
32
+ for (const block of message.content) {
33
+ if (block.type !== "toolCall") continue;
34
+ const thoughtSignature = isExactRoute ? block.thoughtSignature || void 0 : void 0;
35
+ hasHistoricalSignature ||= thoughtSignature !== void 0;
36
+ batch.push({
37
+ id: block.id,
38
+ name: block.name,
39
+ ...thoughtSignature ? { thoughtSignature } : {}
40
+ });
41
+ }
42
+ if (batch.length > 0) historicalToolCallBatches.push(batch);
43
+ }
44
+ if (!hasHistoricalSignature && !requiresUnsignedCallFallback || !Array.isArray(payload.messages)) return;
45
+ let historicalBatchIndex = 0;
46
+ let pendingDowngradedToolCalls;
47
+ for (const message of payload.messages) {
48
+ const record = asOptionalObjectRecord(message);
49
+ if (!record) {
50
+ pendingDowngradedToolCalls = void 0;
51
+ continue;
52
+ }
53
+ if (record.role === "tool") {
54
+ const toolCallId = typeof record.tool_call_id === "string" ? record.tool_call_id : void 0;
55
+ if (!toolCallId) continue;
56
+ const pendingCalls = pendingDowngradedToolCalls;
57
+ if (!pendingCalls) continue;
58
+ const toolNames = pendingCalls.get(toolCallId);
59
+ if (!toolNames) continue;
60
+ const toolName = toolNames.shift();
61
+ if (!toolName) continue;
62
+ if (toolNames.length === 0) pendingCalls.delete(toolCallId);
63
+ const result = stringifyHistoricalValue(record.content);
64
+ for (const key of Object.keys(record)) delete record[key];
65
+ record.role = "user";
66
+ record.content = `[Historical tool result for ${toolName}:\n${result}]`;
67
+ continue;
68
+ }
69
+ pendingDowngradedToolCalls = void 0;
70
+ if (record.role !== "assistant" || !Array.isArray(record.tool_calls)) continue;
71
+ const historicalBatch = historicalToolCallBatches[historicalBatchIndex++];
72
+ let shouldDowngradeBatch = false;
73
+ const describedCalls = [];
74
+ for (const [toolCallIndex, toolCall] of record.tool_calls.entries()) {
75
+ const toolCallRecord = asOptionalObjectRecord(toolCall);
76
+ if (!toolCallRecord) continue;
77
+ const historicalCall = historicalBatch?.[toolCallIndex];
78
+ const fn = asOptionalObjectRecord(toolCallRecord.function);
79
+ const name = typeof fn?.name === "string" && fn.name.length > 0 ? fn.name : "unknown_tool";
80
+ const args = stringifyHistoricalValue(fn?.arguments) || "{}";
81
+ const describedCall = {
82
+ ...typeof toolCallRecord.id === "string" ? { id: toolCallRecord.id } : {},
83
+ name,
84
+ text: `[Historical tool call: ${name}(${args})]`
85
+ };
86
+ const signature = historicalCall && historicalCall.id === toolCallRecord.id && historicalCall.name === describedCall.name ? historicalCall.thoughtSignature : void 0;
87
+ if (signature) toolCallRecord.thought_signature = signature;
88
+ else if (requiresUnsignedCallFallback) shouldDowngradeBatch = true;
89
+ describedCalls.push(describedCall);
90
+ }
91
+ if (!shouldDowngradeBatch) continue;
92
+ pendingDowngradedToolCalls = /* @__PURE__ */ new Map();
93
+ for (const call of describedCalls) if (call.id) {
94
+ const names = pendingDowngradedToolCalls.get(call.id) ?? [];
95
+ names.push(call.name);
96
+ pendingDowngradedToolCalls.set(call.id, names);
97
+ }
98
+ record.content = [stringifyHistoricalValue(record.content), ...describedCalls.map((call) => call.text)].filter((part) => part.length > 0).join("\n");
99
+ delete record.tool_calls;
100
+ }
116
101
  });
117
102
  }
118
103
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/venice-provider",
3
- "version": "2026.11.3",
3
+ "version": "2026.11.5-beta.2",
4
4
  "description": "OpenClaw Venice provider plugin",
5
5
  "type": "module",
6
6
  "openclaw": {
@@ -14,10 +14,10 @@
14
14
  "minHostVersion": ">=2026.6.9"
15
15
  },
16
16
  "compat": {
17
- "pluginApi": ">=2026.11.3"
17
+ "pluginApi": ">=2026.11.5-beta.2"
18
18
  },
19
19
  "build": {
20
- "openclawVersion": "2026.11.3",
20
+ "openclawVersion": "2026.11.5-beta.2",
21
21
  "bundledDist": false
22
22
  },
23
23
  "release": {
@@ -40,7 +40,7 @@
40
40
  "assets/activity.svg"
41
41
  ],
42
42
  "peerDependencies": {
43
- "openclaw": ">=2026.11.3"
43
+ "openclaw": ">=2026.11.5-beta.2"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "openclaw": {
package/dist/usage.js DELETED
@@ -1,76 +0,0 @@
1
- import { readProviderJsonObjectResponse } from "openclaw/plugin-sdk/provider-http";
2
- import { buildUsageErrorSnapshot, buildUsageHttpErrorSnapshot, parseProviderUsageNonNegativeNumber } from "openclaw/plugin-sdk/provider-usage";
3
- //#region extensions/venice/usage.ts
4
- const VENICE_BALANCE_URL = "https://api.venice.ai/api/v1/billing/balance";
5
- const VENICE_USAGE_RESPONSE_MAX_BYTES = 1048576;
6
- async function fetchVeniceUsage(params) {
7
- let response;
8
- try {
9
- response = await params.fetchFn(VENICE_BALANCE_URL, {
10
- headers: {
11
- Accept: "application/json",
12
- Authorization: `Bearer ${params.token}`
13
- },
14
- signal: AbortSignal.timeout(params.timeoutMs)
15
- });
16
- } catch {
17
- return buildUsageErrorSnapshot("venice", "Usage unavailable");
18
- }
19
- if (!response.ok) {
20
- await response.body?.cancel().catch(() => void 0);
21
- return buildUsageHttpErrorSnapshot({
22
- provider: "venice",
23
- status: response.status
24
- });
25
- }
26
- let data;
27
- try {
28
- data = await readProviderJsonObjectResponse(response, "Venice usage", {
29
- maxBytes: VENICE_USAGE_RESPONSE_MAX_BYTES,
30
- chunkTimeoutMs: params.timeoutMs,
31
- onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Venice usage response stalled for ${chunkTimeoutMs}ms`)
32
- });
33
- } catch {
34
- return buildUsageErrorSnapshot("venice", "Malformed usage response");
35
- }
36
- const diem = parseProviderUsageNonNegativeNumber(data.balances?.diem);
37
- const usd = parseProviderUsageNonNegativeNumber(data.balances?.usd);
38
- const allocation = parseProviderUsageNonNegativeNumber(data.diemEpochAllocation);
39
- const windows = [];
40
- if (diem !== void 0 && allocation !== void 0 && allocation > 0) windows.push({
41
- label: "DIEM epoch",
42
- usedPercent: Math.min(100, Math.max(0, (allocation - diem) / allocation * 100))
43
- });
44
- const billing = [];
45
- if (diem !== void 0) billing.push({
46
- type: "balance",
47
- label: "DIEM balance",
48
- amount: diem,
49
- unit: "DIEM"
50
- });
51
- if (usd !== void 0) billing.push({
52
- type: "balance",
53
- label: "USD balance",
54
- amount: usd,
55
- unit: "USD"
56
- });
57
- if (diem !== void 0 && allocation !== void 0 && allocation > 0) billing.push({
58
- type: "budget",
59
- label: "DIEM epoch",
60
- used: Math.max(0, allocation - diem),
61
- limit: allocation,
62
- unit: "DIEM",
63
- period: "epoch"
64
- });
65
- const consumptionCurrency = typeof data.consumptionCurrency === "string" ? data.consumptionCurrency.trim().toUpperCase() : "";
66
- return {
67
- provider: "venice",
68
- displayName: "Venice",
69
- windows,
70
- ...billing.length > 0 ? { billing } : {},
71
- ...consumptionCurrency ? { plan: `${consumptionCurrency} billing` } : {},
72
- ...data.canConsume === false ? { summary: "API consumption unavailable" } : {}
73
- };
74
- }
75
- //#endregion
76
- export { fetchVeniceUsage };