mu-core 0.12.0 → 0.15.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mu-core",
3
- "version": "0.12.0",
3
+ "version": "0.15.0",
4
4
  "description": "Agent loop orchestration core: types, plugin SDK, channels, sessions",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/agent.ts CHANGED
@@ -87,6 +87,7 @@ async function* streamTurn(
87
87
  let reasoning = '';
88
88
  let usage = 0;
89
89
  let cachedPromptTokens = 0;
90
+ let promptTokens = 0;
90
91
  const toolCalls: ToolCall[] = [];
91
92
 
92
93
  const hooks = registry.getHooks();
@@ -104,6 +105,7 @@ async function* streamTurn(
104
105
  tools: toolDefinitions,
105
106
  onUsage: (u) => {
106
107
  usage = u.totalTokens;
108
+ promptTokens = u.promptTokens;
107
109
  cachedPromptTokens = u.cachedPromptTokens ?? 0;
108
110
  },
109
111
  })) {
@@ -121,7 +123,7 @@ async function* streamTurn(
121
123
  }
122
124
  }
123
125
 
124
- const result: TurnResult = { content, reasoning, toolCalls, usage, cachedPromptTokens };
126
+ const result: TurnResult = { content, reasoning, toolCalls, usage, promptTokens, cachedPromptTokens };
125
127
  return await runAfterLlmHooks(hooks, result);
126
128
  }
127
129
 
@@ -210,7 +212,7 @@ export async function* runAgent(
210
212
  while (!signal.aborted) {
211
213
  // Re-evaluate every turn so per-turn agent switches are honoured.
212
214
  const tools = await registry.getFilteredTools();
213
- const { content, reasoning, toolCalls, usage, cachedPromptTokens } = yield* streamTurn(
215
+ const { content, reasoning, toolCalls, usage, promptTokens, cachedPromptTokens } = yield* streamTurn(
214
216
  current,
215
217
  mergedConfig,
216
218
  model,
@@ -220,7 +222,7 @@ export async function* runAgent(
220
222
  );
221
223
 
222
224
  if (usage > 0) {
223
- yield { type: 'usage', totalTokens: usage, cachedTokens: cachedPromptTokens };
225
+ yield { type: 'usage', totalTokens: usage, promptTokens, cachedTokens: cachedPromptTokens };
224
226
  }
225
227
  if (signal.aborted) {
226
228
  break;
package/src/plugin.ts CHANGED
@@ -232,6 +232,8 @@ export interface TurnResult {
232
232
  reasoning: string;
233
233
  toolCalls: ToolCall[];
234
234
  usage: number;
235
+ /** Input tokens sent to the model for this turn (prompt size). */
236
+ promptTokens: number;
235
237
  /** Subset of prompt tokens served from the server's prompt cache, when
236
238
  * reported. 0 when unsupported or no cache hit. */
237
239
  cachedPromptTokens?: number;
@@ -330,7 +332,7 @@ export interface SlashCommand {
330
332
  export type AgentEvent =
331
333
  | { type: 'content'; text: string }
332
334
  | { type: 'reasoning'; text: string }
333
- | { type: 'usage'; totalTokens: number; cachedTokens?: number }
335
+ | { type: 'usage'; totalTokens: number; promptTokens: number; cachedTokens?: number }
334
336
  | { type: 'messages'; messages: ChatMessage[] }
335
337
  | { type: 'turn_end' };
336
338
 
package/src/session.ts CHANGED
@@ -18,7 +18,7 @@ export type SessionEvent =
18
18
  | { type: 'stream_partial'; text: string; reasoning?: string }
19
19
  | { type: 'stream_started' }
20
20
  | { type: 'stream_ended' }
21
- | { type: 'usage'; totalTokens: number; cachedTokens: number }
21
+ | { type: 'usage'; totalTokens: number; promptTokens: number; cachedTokens: number }
22
22
  | { type: 'error'; message: string };
23
23
 
24
24
  export interface RunTurnOptions {
@@ -164,7 +164,12 @@ class SessionImpl implements Session {
164
164
  final = this.messages.slice();
165
165
  this.emit({ type: 'messages_changed', messages: this.messages.slice() });
166
166
  } else if (e.type === 'usage') {
167
- this.emit({ type: 'usage', totalTokens: e.totalTokens, cachedTokens: e.cachedTokens ?? 0 });
167
+ this.emit({
168
+ type: 'usage',
169
+ totalTokens: e.totalTokens,
170
+ promptTokens: e.promptTokens,
171
+ cachedTokens: e.cachedTokens ?? 0,
172
+ });
168
173
  } else if (e.type === 'turn_end') {
169
174
  // Clear the locally-tracked partial buffers AND notify subscribers,
170
175
  // otherwise the host's `stream` state still holds the previous step's