@workser/engine 0.1.16 → 0.1.17

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.
@@ -29,6 +29,8 @@ export interface ChatTool {
29
29
  export interface ChatResult {
30
30
  message: ChatMessage;
31
31
  finishReason: string | null;
32
+ /** Who served the call, when the route says (OpenRouter names it on every response). Cost audit 2026-11-13. */
33
+ provider?: string;
32
34
  usage?: {
33
35
  prompt_tokens?: number;
34
36
  completion_tokens?: number;
package/dist/src/model.js CHANGED
@@ -105,6 +105,7 @@ export async function chat(input) {
105
105
  : {}),
106
106
  },
107
107
  finishReason: choice.finish_reason ?? null,
108
+ ...(typeof body.provider === 'string' && body.provider ? { provider: body.provider } : {}),
108
109
  ...(body.usage ? { usage: body.usage } : {}),
109
110
  };
110
111
  }
@@ -126,6 +127,7 @@ async function readStream(body, onDelta, status, onReasoning) {
126
127
  let content = '';
127
128
  let finishReason = null;
128
129
  let usage;
130
+ let provider = '';
129
131
  const calls = [];
130
132
  let sawChoice = false;
131
133
  const handle = (data) => {
@@ -142,6 +144,8 @@ async function readStream(body, onDelta, status, onReasoning) {
142
144
  throw new ModelError(chunk.error.message ?? 'The model stream failed.', status);
143
145
  if (chunk?.usage)
144
146
  usage = chunk.usage;
147
+ if (typeof chunk?.provider === 'string' && chunk.provider)
148
+ provider = chunk.provider;
145
149
  const choice = chunk?.choices?.[0];
146
150
  if (!choice)
147
151
  return;
@@ -193,6 +197,7 @@ async function readStream(body, onDelta, status, onReasoning) {
193
197
  return {
194
198
  message: { role: 'assistant', content: content || null, ...(toolCalls.length ? { tool_calls: toolCalls } : {}) },
195
199
  finishReason,
200
+ ...(provider ? { provider } : {}),
196
201
  ...(usage ? { usage } : {}),
197
202
  };
198
203
  }
@@ -135,4 +135,4 @@ export declare const READ_ONLY_NUDGE: string;
135
135
  * tokens read from its cache and the hidden reasoning tokens. Owner 12 Nov: a trace showed no cache reads on
136
136
  * 40–50k-token calls only because these counts were dropped here, so nobody could tell whether caching worked.
137
137
  */
138
- export declare function usageEvent(model: string, usage: NonNullable<ChatResult['usage']>): Record<string, unknown>;
138
+ export declare function usageEvent(model: string, usage: NonNullable<ChatResult['usage']>, provider?: string): Record<string, unknown>;
@@ -316,7 +316,7 @@ export class CoreSession {
316
316
  this.messages.push(result.message);
317
317
  this.lastPromptTokens = Number(result.usage?.prompt_tokens ?? 0);
318
318
  if (result.usage) {
319
- this.options.emit('usage', usageEvent(this.model, result.usage));
319
+ this.options.emit('usage', usageEvent(this.model, result.usage, result.provider));
320
320
  }
321
321
  if (result.message.content) {
322
322
  this.options.emit('message', {
@@ -415,7 +415,7 @@ export class CoreSession {
415
415
  return;
416
416
  }
417
417
  if (result.usage) {
418
- this.options.emit('usage', usageEvent(this.model, result.usage));
418
+ this.options.emit('usage', usageEvent(this.model, result.usage, result.provider));
419
419
  }
420
420
  const next = withSummary(this.messages, cut, summary);
421
421
  this.messages.splice(0, this.messages.length, ...next);
@@ -591,11 +591,14 @@ export const READ_ONLY_NUDGE = `(Workser: ${READ_ONLY_TURNS} turns in a row with
591
591
  * tokens read from its cache and the hidden reasoning tokens. Owner 12 Nov: a trace showed no cache reads on
592
592
  * 40–50k-token calls only because these counts were dropped here, so nobody could tell whether caching worked.
593
593
  */
594
- export function usageEvent(model, usage) {
594
+ export function usageEvent(model, usage, provider) {
595
595
  const cached = usage.prompt_tokens_details?.cached_tokens;
596
596
  const reasoning = usage.completion_tokens_details?.reasoning_tokens;
597
597
  return {
598
598
  model,
599
+ // Who served this call: a cache lives on one provider's machines, so a call that moved provider reads none of it
600
+ // (cost audit 2026-11-13: 10-18% of cache misses came with no change to the history).
601
+ ...(provider ? { provider } : {}),
599
602
  tokens_in: Number(usage.prompt_tokens ?? 0),
600
603
  tokens_out: Number(usage.completion_tokens ?? 0),
601
604
  ...(typeof usage.cost === 'number' ? { cost_usd: usage.cost } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workser/engine",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Workser's coding engine for the 'loop in our service' mode: OpenCode's agent contract (its prompts, tool schemas and edit semantics, vendored from v1.19.5) running on Node, with every file and shell action going through a Place — so the machine can be a remote sandbox and no model key is ever on it.",
5
5
  "license": "MIT",
6
6
  "type": "module",