aisnitch 0.2.21 → 0.2.22

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/index.cjs CHANGED
@@ -818,6 +818,9 @@ var EventDataSchema = import_zod.z.strictObject({
818
818
  activeFile: import_zod.z.string().min(1).max(4096).optional(),
819
819
  model: import_zod.z.string().min(1).max(200).optional(),
820
820
  tokensUsed: import_zod.z.number().int().min(0).optional(),
821
+ inputTokens: import_zod.z.number().int().min(0).optional(),
822
+ outputTokens: import_zod.z.number().int().min(0).optional(),
823
+ cachedTokens: import_zod.z.number().int().min(0).optional(),
821
824
  errorMessage: import_zod.z.string().min(1).max(1e4).optional(),
822
825
  errorType: ErrorTypeSchema.optional(),
823
826
  raw: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
@@ -2215,7 +2218,7 @@ function extractClaudeTranscriptObservations(payload, transcriptPath) {
2215
2218
  });
2216
2219
  const contentParts = extractClaudeContentParts(payload);
2217
2220
  const model = getString(payload, "model") ?? getString(getRecord(payload.message), "model");
2218
- const tokensUsed = extractTokenUsage(payload);
2221
+ const tokens = extractTokenUsageDetailed(payload);
2219
2222
  const rawPayload = payload;
2220
2223
  const sharedContext = {
2221
2224
  // 📖 Pass process.env so terminal detection works from transcript path too
@@ -2228,7 +2231,10 @@ function extractClaudeTranscriptObservations(payload, transcriptPath) {
2228
2231
  const sharedData = {
2229
2232
  model,
2230
2233
  raw: rawPayload,
2231
- tokensUsed
2234
+ tokensUsed: tokens.total,
2235
+ inputTokens: tokens.input,
2236
+ outputTokens: tokens.output,
2237
+ cachedTokens: tokens.cached
2232
2238
  };
2233
2239
  const observations = [];
2234
2240
  if (contentParts.some((part) => part.type === "thinking")) {
@@ -2286,23 +2292,28 @@ function extractClaudeContentParts(payload) {
2286
2292
  }
2287
2293
  return content.filter(isRecord);
2288
2294
  }
2289
- function extractTokenUsage(payload) {
2295
+ function extractTokenUsageDetailed(payload) {
2290
2296
  const tokens = getNumber(payload, "tokens");
2291
2297
  if (tokens !== void 0) {
2292
- return tokens;
2298
+ return { total: tokens };
2293
2299
  }
2294
2300
  const usage = getRecord(payload.usage);
2295
2301
  if (!usage) {
2296
- return void 0;
2302
+ return {};
2297
2303
  }
2298
2304
  const totalTokens = getNumber(usage, "total_tokens");
2299
2305
  if (totalTokens !== void 0) {
2300
- return totalTokens;
2306
+ return {
2307
+ total: totalTokens,
2308
+ input: getNumber(usage, "input_tokens"),
2309
+ output: getNumber(usage, "output_tokens"),
2310
+ cached: getNumber(usage, "cached_tokens")
2311
+ };
2301
2312
  }
2302
2313
  const inputTokens = getNumber(usage, "input_tokens") ?? 0;
2303
2314
  const outputTokens = getNumber(usage, "output_tokens") ?? 0;
2304
2315
  const usageSum = inputTokens + outputTokens;
2305
- return usageSum > 0 ? usageSum : void 0;
2316
+ return usageSum > 0 ? { total: usageSum, input: inputTokens, output: outputTokens } : {};
2306
2317
  }
2307
2318
  function extractClaudeToolInput(payload) {
2308
2319
  const toolInput = getRecord(payload.tool_input) ?? getRecord(payload.toolInput);
@@ -7406,7 +7417,17 @@ var OpenCodeAdapter = class extends BaseAdapter {
7406
7417
  project: extractOpenCodeProject(payload),
7407
7418
  raw: payload,
7408
7419
  toolInput: extractOpenCodeToolInput(payload),
7409
- toolName: extractOpenCodeToolName(payload)
7420
+ toolName: extractOpenCodeToolName(payload),
7421
+ // 📖 Extract token usage from payload (with input/output/cached breakdown)
7422
+ ...(() => {
7423
+ const tokens = extractOpenCodeTokens(payload);
7424
+ return {
7425
+ tokensUsed: tokens.total,
7426
+ inputTokens: tokens.inputTokens,
7427
+ outputTokens: tokens.outputTokens,
7428
+ cachedTokens: tokens.cachedTokens
7429
+ };
7430
+ })()
7410
7431
  };
7411
7432
  switch (eventType) {
7412
7433
  case "session.created": {
@@ -7435,9 +7456,21 @@ var OpenCodeAdapter = class extends BaseAdapter {
7435
7456
  await this.emitStateChange("agent.compact", sharedData, context);
7436
7457
  return;
7437
7458
  }
7459
+ case "thinking": {
7460
+ const thinkingContent = extractOpenCodeThinkingContent(payload);
7461
+ await this.emitStateChange("agent.thinking", {
7462
+ ...sharedData,
7463
+ thinkingContent
7464
+ }, context);
7465
+ return;
7466
+ }
7438
7467
  case "message.updated":
7439
7468
  case "message.part.updated": {
7440
- await this.emitStateChange("agent.streaming", sharedData, context);
7469
+ const messageContent = extractOpenCodeMessageContent(payload);
7470
+ await this.emitStateChange("agent.streaming", {
7471
+ ...sharedData,
7472
+ messageContent
7473
+ }, context);
7441
7474
  return;
7442
7475
  }
7443
7476
  case "permission.asked": {
@@ -7656,6 +7689,67 @@ function extractOpenCodeToolResult(payload) {
7656
7689
  }
7657
7690
  return void 0;
7658
7691
  }
7692
+ function extractOpenCodeMessageContent(payload) {
7693
+ const directMessage = getString10(payload, "text") ?? getString10(payload, "message") ?? getString10(payload, "content") ?? getString10(payload, "output");
7694
+ if (directMessage) {
7695
+ return directMessage;
7696
+ }
7697
+ const part = getRecord9(payload.part) ?? getRecord9(getRecord9(payload.properties)?.part);
7698
+ if (part) {
7699
+ return getString10(part, "text") ?? getString10(part, "content");
7700
+ }
7701
+ const props = getRecord9(payload.properties);
7702
+ if (props) {
7703
+ const message = getRecord9(props.message) ?? getRecord9(props.info);
7704
+ if (message) {
7705
+ return getString10(message, "text") ?? getString10(message, "content");
7706
+ }
7707
+ return getString10(props, "text") ?? getString10(props, "message");
7708
+ }
7709
+ return void 0;
7710
+ }
7711
+ function extractOpenCodeThinkingContent(payload) {
7712
+ const directThinking = getString10(payload, "thinking") ?? getString10(payload, "thinkingContent") ?? getString10(payload, "reasoning") ?? getString10(payload, "thought");
7713
+ if (directThinking) {
7714
+ return directThinking;
7715
+ }
7716
+ const props = getRecord9(payload.properties);
7717
+ if (props) {
7718
+ return getString10(props, "thinking") ?? getString10(props, "reasoning") ?? getString10(props, "thought");
7719
+ }
7720
+ return void 0;
7721
+ }
7722
+ function extractOpenCodeTokens(payload) {
7723
+ const directTokens = getNumber8(payload, "tokensUsed") ?? getNumber8(payload, "tokens");
7724
+ if (directTokens !== void 0) {
7725
+ return { total: directTokens };
7726
+ }
7727
+ const props = getRecord9(payload.properties);
7728
+ if (props) {
7729
+ const info = getRecord9(props.info);
7730
+ if (info) {
7731
+ const tokens = getRecord9(info.tokens);
7732
+ if (tokens) {
7733
+ const inputTokens = getNumber8(tokens, "input") ?? 0;
7734
+ const outputTokens = getNumber8(tokens, "output") ?? 0;
7735
+ const reasoningTokens = getNumber8(tokens, "reasoning") ?? 0;
7736
+ const total = inputTokens + outputTokens + reasoningTokens;
7737
+ return total > 0 ? {
7738
+ total,
7739
+ inputTokens,
7740
+ outputTokens,
7741
+ // reasoning tokens are often billed as cached on some providers
7742
+ cachedTokens: reasoningTokens
7743
+ } : {};
7744
+ }
7745
+ }
7746
+ const fallbackTokens = getNumber8(props, "tokensUsed") ?? getNumber8(props, "tokens");
7747
+ if (fallbackTokens !== void 0) {
7748
+ return { total: fallbackTokens };
7749
+ }
7750
+ }
7751
+ return {};
7752
+ }
7659
7753
 
7660
7754
  // src/adapters/pi.ts
7661
7755
  var import_node_child_process12 = require("child_process");
@@ -9352,7 +9446,7 @@ var import_ws = require("ws");
9352
9446
 
9353
9447
  // src/package-info.ts
9354
9448
  var AISNITCH_PACKAGE_NAME = "aisnitch";
9355
- var AISNITCH_VERSION = "0.2.21";
9449
+ var AISNITCH_VERSION = "0.2.22";
9356
9450
  var AISNITCH_DESCRIPTION = "Universal bridge for AI coding tool activity \u2014 capture, normalize, stream.";
9357
9451
  function getPackageScaffoldInfo() {
9358
9452
  return {