aisnitch 0.2.21 → 0.2.23

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.d.cts CHANGED
@@ -266,6 +266,9 @@ declare const EventDataSchema: z.ZodObject<{
266
266
  activeFile: z.ZodOptional<z.ZodString>;
267
267
  model: z.ZodOptional<z.ZodString>;
268
268
  tokensUsed: z.ZodOptional<z.ZodNumber>;
269
+ inputTokens: z.ZodOptional<z.ZodNumber>;
270
+ outputTokens: z.ZodOptional<z.ZodNumber>;
271
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
269
272
  errorMessage: z.ZodOptional<z.ZodString>;
270
273
  errorType: z.ZodOptional<z.ZodEnum<{
271
274
  rate_limit: "rate_limit";
@@ -361,6 +364,9 @@ declare const AISnitchEventSchema: z.ZodObject<{
361
364
  activeFile: z.ZodOptional<z.ZodString>;
362
365
  model: z.ZodOptional<z.ZodString>;
363
366
  tokensUsed: z.ZodOptional<z.ZodNumber>;
367
+ inputTokens: z.ZodOptional<z.ZodNumber>;
368
+ outputTokens: z.ZodOptional<z.ZodNumber>;
369
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
364
370
  errorMessage: z.ZodOptional<z.ZodString>;
365
371
  errorType: z.ZodOptional<z.ZodEnum<{
366
372
  rate_limit: "rate_limit";
@@ -470,6 +476,9 @@ declare const NormalizedAdapterHookPayloadSchema: z.ZodObject<{
470
476
  activeFile: z.ZodOptional<z.ZodOptional<z.ZodString>>;
471
477
  model: z.ZodOptional<z.ZodOptional<z.ZodString>>;
472
478
  tokensUsed: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
479
+ inputTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
480
+ outputTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
481
+ cachedTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
473
482
  errorMessage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
474
483
  errorType: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
475
484
  rate_limit: "rate_limit";
package/dist/index.d.ts CHANGED
@@ -266,6 +266,9 @@ declare const EventDataSchema: z.ZodObject<{
266
266
  activeFile: z.ZodOptional<z.ZodString>;
267
267
  model: z.ZodOptional<z.ZodString>;
268
268
  tokensUsed: z.ZodOptional<z.ZodNumber>;
269
+ inputTokens: z.ZodOptional<z.ZodNumber>;
270
+ outputTokens: z.ZodOptional<z.ZodNumber>;
271
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
269
272
  errorMessage: z.ZodOptional<z.ZodString>;
270
273
  errorType: z.ZodOptional<z.ZodEnum<{
271
274
  rate_limit: "rate_limit";
@@ -361,6 +364,9 @@ declare const AISnitchEventSchema: z.ZodObject<{
361
364
  activeFile: z.ZodOptional<z.ZodString>;
362
365
  model: z.ZodOptional<z.ZodString>;
363
366
  tokensUsed: z.ZodOptional<z.ZodNumber>;
367
+ inputTokens: z.ZodOptional<z.ZodNumber>;
368
+ outputTokens: z.ZodOptional<z.ZodNumber>;
369
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
364
370
  errorMessage: z.ZodOptional<z.ZodString>;
365
371
  errorType: z.ZodOptional<z.ZodEnum<{
366
372
  rate_limit: "rate_limit";
@@ -470,6 +476,9 @@ declare const NormalizedAdapterHookPayloadSchema: z.ZodObject<{
470
476
  activeFile: z.ZodOptional<z.ZodOptional<z.ZodString>>;
471
477
  model: z.ZodOptional<z.ZodOptional<z.ZodString>>;
472
478
  tokensUsed: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
479
+ inputTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
480
+ outputTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
481
+ cachedTokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
473
482
  errorMessage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
474
483
  errorType: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
475
484
  rate_limit: "rate_limit";
package/dist/index.js CHANGED
@@ -618,6 +618,9 @@ var EventDataSchema = z.strictObject({
618
618
  activeFile: z.string().min(1).max(4096).optional(),
619
619
  model: z.string().min(1).max(200).optional(),
620
620
  tokensUsed: z.number().int().min(0).optional(),
621
+ inputTokens: z.number().int().min(0).optional(),
622
+ outputTokens: z.number().int().min(0).optional(),
623
+ cachedTokens: z.number().int().min(0).optional(),
621
624
  errorMessage: z.string().min(1).max(1e4).optional(),
622
625
  errorType: ErrorTypeSchema.optional(),
623
626
  raw: z.record(z.string(), z.unknown()).optional(),
@@ -2015,7 +2018,7 @@ function extractClaudeTranscriptObservations(payload, transcriptPath) {
2015
2018
  });
2016
2019
  const contentParts = extractClaudeContentParts(payload);
2017
2020
  const model = getString(payload, "model") ?? getString(getRecord(payload.message), "model");
2018
- const tokensUsed = extractTokenUsage(payload);
2021
+ const tokens = extractTokenUsageDetailed(payload);
2019
2022
  const rawPayload = payload;
2020
2023
  const sharedContext = {
2021
2024
  // 📖 Pass process.env so terminal detection works from transcript path too
@@ -2028,7 +2031,10 @@ function extractClaudeTranscriptObservations(payload, transcriptPath) {
2028
2031
  const sharedData = {
2029
2032
  model,
2030
2033
  raw: rawPayload,
2031
- tokensUsed
2034
+ tokensUsed: tokens.total,
2035
+ inputTokens: tokens.input,
2036
+ outputTokens: tokens.output,
2037
+ cachedTokens: tokens.cached
2032
2038
  };
2033
2039
  const observations = [];
2034
2040
  if (contentParts.some((part) => part.type === "thinking")) {
@@ -2086,23 +2092,28 @@ function extractClaudeContentParts(payload) {
2086
2092
  }
2087
2093
  return content.filter(isRecord);
2088
2094
  }
2089
- function extractTokenUsage(payload) {
2095
+ function extractTokenUsageDetailed(payload) {
2090
2096
  const tokens = getNumber(payload, "tokens");
2091
2097
  if (tokens !== void 0) {
2092
- return tokens;
2098
+ return { total: tokens };
2093
2099
  }
2094
2100
  const usage = getRecord(payload.usage);
2095
2101
  if (!usage) {
2096
- return void 0;
2102
+ return {};
2097
2103
  }
2098
2104
  const totalTokens = getNumber(usage, "total_tokens");
2099
2105
  if (totalTokens !== void 0) {
2100
- return totalTokens;
2106
+ return {
2107
+ total: totalTokens,
2108
+ input: getNumber(usage, "input_tokens"),
2109
+ output: getNumber(usage, "output_tokens"),
2110
+ cached: getNumber(usage, "cached_tokens")
2111
+ };
2101
2112
  }
2102
2113
  const inputTokens = getNumber(usage, "input_tokens") ?? 0;
2103
2114
  const outputTokens = getNumber(usage, "output_tokens") ?? 0;
2104
2115
  const usageSum = inputTokens + outputTokens;
2105
- return usageSum > 0 ? usageSum : void 0;
2116
+ return usageSum > 0 ? { total: usageSum, input: inputTokens, output: outputTokens } : {};
2106
2117
  }
2107
2118
  function extractClaudeToolInput(payload) {
2108
2119
  const toolInput = getRecord(payload.tool_input) ?? getRecord(payload.toolInput);
@@ -7206,7 +7217,17 @@ var OpenCodeAdapter = class extends BaseAdapter {
7206
7217
  project: extractOpenCodeProject(payload),
7207
7218
  raw: payload,
7208
7219
  toolInput: extractOpenCodeToolInput(payload),
7209
- toolName: extractOpenCodeToolName(payload)
7220
+ toolName: extractOpenCodeToolName(payload),
7221
+ // 📖 Extract token usage from payload (with input/output/cached breakdown)
7222
+ ...(() => {
7223
+ const tokens = extractOpenCodeTokens(payload);
7224
+ return {
7225
+ tokensUsed: tokens.total,
7226
+ inputTokens: tokens.inputTokens,
7227
+ outputTokens: tokens.outputTokens,
7228
+ cachedTokens: tokens.cachedTokens
7229
+ };
7230
+ })()
7210
7231
  };
7211
7232
  switch (eventType) {
7212
7233
  case "session.created": {
@@ -7235,9 +7256,21 @@ var OpenCodeAdapter = class extends BaseAdapter {
7235
7256
  await this.emitStateChange("agent.compact", sharedData, context);
7236
7257
  return;
7237
7258
  }
7259
+ case "thinking": {
7260
+ const thinkingContent = extractOpenCodeThinkingContent(payload);
7261
+ await this.emitStateChange("agent.thinking", {
7262
+ ...sharedData,
7263
+ thinkingContent
7264
+ }, context);
7265
+ return;
7266
+ }
7238
7267
  case "message.updated":
7239
7268
  case "message.part.updated": {
7240
- await this.emitStateChange("agent.streaming", sharedData, context);
7269
+ const messageContent = extractOpenCodeMessageContent(payload);
7270
+ await this.emitStateChange("agent.streaming", {
7271
+ ...sharedData,
7272
+ messageContent
7273
+ }, context);
7241
7274
  return;
7242
7275
  }
7243
7276
  case "permission.asked": {
@@ -7456,6 +7489,67 @@ function extractOpenCodeToolResult(payload) {
7456
7489
  }
7457
7490
  return void 0;
7458
7491
  }
7492
+ function extractOpenCodeMessageContent(payload) {
7493
+ const directMessage = getString10(payload, "text") ?? getString10(payload, "message") ?? getString10(payload, "content") ?? getString10(payload, "output");
7494
+ if (directMessage) {
7495
+ return directMessage;
7496
+ }
7497
+ const part = getRecord9(payload.part) ?? getRecord9(getRecord9(payload.properties)?.part);
7498
+ if (part) {
7499
+ return getString10(part, "text") ?? getString10(part, "content");
7500
+ }
7501
+ const props = getRecord9(payload.properties);
7502
+ if (props) {
7503
+ const message = getRecord9(props.message) ?? getRecord9(props.info);
7504
+ if (message) {
7505
+ return getString10(message, "text") ?? getString10(message, "content");
7506
+ }
7507
+ return getString10(props, "text") ?? getString10(props, "message");
7508
+ }
7509
+ return void 0;
7510
+ }
7511
+ function extractOpenCodeThinkingContent(payload) {
7512
+ const directThinking = getString10(payload, "thinking") ?? getString10(payload, "thinkingContent") ?? getString10(payload, "reasoning") ?? getString10(payload, "thought");
7513
+ if (directThinking) {
7514
+ return directThinking;
7515
+ }
7516
+ const props = getRecord9(payload.properties);
7517
+ if (props) {
7518
+ return getString10(props, "thinking") ?? getString10(props, "reasoning") ?? getString10(props, "thought");
7519
+ }
7520
+ return void 0;
7521
+ }
7522
+ function extractOpenCodeTokens(payload) {
7523
+ const directTokens = getNumber8(payload, "tokensUsed") ?? getNumber8(payload, "tokens");
7524
+ if (directTokens !== void 0) {
7525
+ return { total: directTokens };
7526
+ }
7527
+ const props = getRecord9(payload.properties);
7528
+ if (props) {
7529
+ const info = getRecord9(props.info);
7530
+ if (info) {
7531
+ const tokens = getRecord9(info.tokens);
7532
+ if (tokens) {
7533
+ const inputTokens = getNumber8(tokens, "input") ?? 0;
7534
+ const outputTokens = getNumber8(tokens, "output") ?? 0;
7535
+ const reasoningTokens = getNumber8(tokens, "reasoning") ?? 0;
7536
+ const total = inputTokens + outputTokens + reasoningTokens;
7537
+ return total > 0 ? {
7538
+ total,
7539
+ inputTokens,
7540
+ outputTokens,
7541
+ // reasoning tokens are often billed as cached on some providers
7542
+ cachedTokens: reasoningTokens
7543
+ } : {};
7544
+ }
7545
+ }
7546
+ const fallbackTokens = getNumber8(props, "tokensUsed") ?? getNumber8(props, "tokens");
7547
+ if (fallbackTokens !== void 0) {
7548
+ return { total: fallbackTokens };
7549
+ }
7550
+ }
7551
+ return {};
7552
+ }
7459
7553
 
7460
7554
  // src/adapters/pi.ts
7461
7555
  import { execFile as execFile12 } from "child_process";
@@ -9152,7 +9246,7 @@ import { WebSocket, WebSocketServer } from "ws";
9152
9246
 
9153
9247
  // src/package-info.ts
9154
9248
  var AISNITCH_PACKAGE_NAME = "aisnitch";
9155
- var AISNITCH_VERSION = "0.2.21";
9249
+ var AISNITCH_VERSION = "0.2.23";
9156
9250
  var AISNITCH_DESCRIPTION = "Universal bridge for AI coding tool activity \u2014 capture, normalize, stream.";
9157
9251
  function getPackageScaffoldInfo() {
9158
9252
  return {