@demicodes/provider-claude-code 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.mjs +16 -1
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -691,7 +691,7 @@ function mapClaudeStdoutMessage(message, options = {}) {
691
691
  }
692
692
  events.push({
693
693
  type: "response",
694
- usage: mapUsage(message.usage)
694
+ usage: mapResultUsage(message.usage)
695
695
  });
696
696
  return {
697
697
  events,
@@ -820,6 +820,21 @@ function parseControlRequest(message) {
820
820
  params: message.params
821
821
  };
822
822
  }
823
+ /**
824
+ * Usage for the response event from a `result` message. The top-level
825
+ * `result.usage` sums every API call the CLI made within the turn (initial call
826
+ * plus one per tool result), so its input/cache counts can exceed the context
827
+ * window itself and must not be reported as request usage. `usage.iterations`
828
+ * lists the per-call usage; the last entry is the final request — the one the
829
+ * response contract requires.
830
+ */
831
+ function mapResultUsage(usage) {
832
+ if (isRecord(usage) && Array.isArray(usage.iterations)) {
833
+ const last = usage.iterations[usage.iterations.length - 1];
834
+ if (isRecord(last)) return mapUsage(last);
835
+ }
836
+ return mapUsage(usage);
837
+ }
823
838
  function mapUsage(usage) {
824
839
  if (!isRecord(usage)) return {
825
840
  inputTokens: 0,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/provider-claude-code",
3
3
  "description": "Claude Code provider adapter for Demi.",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {
@@ -12,13 +12,13 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@demicodes/core": "^0.2.1",
16
- "@demicodes/provider": "^0.2.1",
17
- "@demicodes/utils": "^0.2.1"
15
+ "@demicodes/core": "workspace:^",
16
+ "@demicodes/provider": "workspace:^",
17
+ "@demicodes/utils": "workspace:^"
18
18
  },
19
19
  "devDependencies": {
20
- "@demicodes/agent": "^0.2.1",
21
- "@demicodes/shell": "^0.2.1"
20
+ "@demicodes/agent": "workspace:^",
21
+ "@demicodes/shell": "workspace:^"
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "main": "./dist/index.mjs",