@yolk-sdk/agent 0.1.0-canary.60 → 0.1.0-canary.62

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 (42) hide show
  1. package/README.md +23 -13
  2. package/dist/compaction/checkpoint.d.mts +2 -2
  3. package/dist/compaction/checkpoint.d.mts.map +1 -1
  4. package/dist/providers/anthropic/usage.d.mts.map +1 -1
  5. package/dist/providers/anthropic/usage.mjs +3 -3
  6. package/dist/providers/anthropic/usage.mjs.map +1 -1
  7. package/dist/providers/openai/codex-usage.d.mts.map +1 -1
  8. package/dist/providers/openai/codex-usage.mjs +3 -3
  9. package/dist/providers/openai/codex-usage.mjs.map +1 -1
  10. package/dist/providers/openai-responses-provider-internal.d.mts.map +1 -1
  11. package/dist/providers/openai-responses-provider-internal.mjs +21 -2
  12. package/dist/providers/openai-responses-provider-internal.mjs.map +1 -1
  13. package/dist/providers/subscription-usage-internal.d.mts +7 -1
  14. package/dist/providers/subscription-usage-internal.d.mts.map +1 -1
  15. package/dist/providers/subscription-usage-internal.mjs +11 -1
  16. package/dist/providers/subscription-usage-internal.mjs.map +1 -1
  17. package/dist/providers/subscription-usage.d.mts +1 -1
  18. package/dist/providers/subscription-usage.d.mts.map +1 -1
  19. package/dist/providers/subscription-usage.mjs +2 -0
  20. package/dist/providers/subscription-usage.mjs.map +1 -1
  21. package/dist/providers/xai/grok-provider.d.mts +7 -1
  22. package/dist/providers/xai/grok-provider.d.mts.map +1 -1
  23. package/dist/providers/xai/grok-provider.mjs +4 -1
  24. package/dist/providers/xai/grok-provider.mjs.map +1 -1
  25. package/dist/providers/xai/usage.d.mts +17 -0
  26. package/dist/providers/xai/usage.d.mts.map +1 -0
  27. package/dist/providers/xai/usage.mjs +131 -0
  28. package/dist/providers/xai/usage.mjs.map +1 -0
  29. package/dist/react/chat-messages.d.mts +1 -1
  30. package/dist/react/chat-messages.d.mts.map +1 -1
  31. package/dist/react/use-agent-chat.d.mts +1 -1
  32. package/dist/skillset/merge.d.mts +1 -1
  33. package/dist/skillset/name.d.mts +2 -2
  34. package/dist/skillset/name.d.mts.map +1 -1
  35. package/package.json +6 -1
  36. package/src/providers/anthropic/usage.ts +2 -4
  37. package/src/providers/openai/codex-usage.ts +2 -4
  38. package/src/providers/openai-responses-provider-internal.ts +31 -3
  39. package/src/providers/subscription-usage-internal.ts +22 -0
  40. package/src/providers/subscription-usage.ts +7 -1
  41. package/src/providers/xai/grok-provider.ts +10 -1
  42. package/src/providers/xai/usage.ts +279 -0
package/README.md CHANGED
@@ -43,6 +43,7 @@ Published package metadata requires Node.js 22+.
43
43
  | `@yolk-sdk/agent/providers/xai` | Grok subscription OAuth and token broker helpers |
44
44
  | `@yolk-sdk/agent/providers/xai/grok` | Grok subscription request and auth helpers |
45
45
  | `@yolk-sdk/agent/providers/xai/grok-provider` | Grok subscription LLM provider factory |
46
+ | `@yolk-sdk/agent/providers/xai/usage` | Grok subscription-allowance snapshots |
46
47
  | `@yolk-sdk/agent/providers/subscription-usage` | Shared allowance snapshot and safe error schemas |
47
48
  | `@yolk-sdk/agent/skillset` | Portable skill and slash-command parsing/catalogs |
48
49
  | `@yolk-sdk/agent/voice` | Voice protocol, controller, tool handler, projection, speech |
@@ -176,7 +177,10 @@ Required authorization and JSON headers cannot be replaced through `extraHeaders
176
177
 
177
178
  Grok subscription access uses `https://cli-chat-proxy.grok.com/v1/responses`, not the xAI developer
178
179
  API-key endpoint. The adapter sends the required CLI-session and model-routing headers and rejects
179
- mismatched or expired access-token envelopes before HTTP. The package exports browser-PKCE and
180
+ mismatched or expired access-token envelopes before HTTP. `makeXAiGrokProviderLayer` also requires
181
+ a truthful host-owned `clientVersion`, sent as `x-grok-client-version`, because the xAI CLI proxy
182
+ version-gates requests and rejects missing or outdated versions with HTTP 426; required headers
183
+ stay non-overridable through `extraHeaders`. The package exports browser-PKCE and
180
184
  device-flow constants; hosts own the callback listener or device polling, token exchange/refresh,
181
185
  secure storage, and model discovery. Only set `responsesUrl` to a trusted proxy because it receives
182
186
  the OAuth bearer. xAI controls the public CLI OAuth client and private, unsupported proxy contract,
@@ -222,11 +226,12 @@ typed retry/error state.
222
226
 
223
227
  ## Subscription allowance snapshots
224
228
 
225
- The Claude and Codex usage adapters read best-effort consumer subscription allowance percentages and
226
- reset windows. Claude currently normalizes its aggregate five-hour and seven-day windows; Codex
227
- normalizes its primary and secondary rate-limit windows. Additional provider-specific buckets are
228
- ignored. These private provider endpoints may change without notice. Pass a fresh
229
- host-owned `OAuthAccessToken` and provide an Effect `HttpClient`:
229
+ The Claude, Codex, and Grok usage adapters read best-effort consumer subscription allowance
230
+ percentages and reset windows. Claude normalizes its aggregate five-hour and seven-day windows;
231
+ Codex normalizes primary and secondary rate-limit windows; Grok normalizes its aggregate shared
232
+ credit allowance. Additional provider-specific buckets are ignored. These private provider
233
+ endpoints may change without notice. Pass a fresh host-owned `OAuthAccessToken` and provide an
234
+ Effect `HttpClient`:
230
235
 
231
236
  ```ts
232
237
  import { Effect } from 'effect'
@@ -240,13 +245,18 @@ const snapshot = await fetchOpenAiCodexSubscriptionUsage(hostOAuthAccessToken).p
240
245
  ```
241
246
 
242
247
  Use `fetchAnthropicClaudeSubscriptionUsage` from
243
- `@yolk-sdk/agent/providers/anthropic/usage` for Claude. Provider adapters return an immutable Effect
244
- `Chunk` of semantic window ids, percentages, and optional reset/duration fields; hosts own labels,
245
- polling, persistence, stale-data
246
- policy, alert thresholds, billing interpretation, and UI. Configure `requestTimeoutMs` at the
247
- server integration boundary. Endpoint origins stay fixed, and `FetchHttpClient.layer` is configured
248
- for manual redirects. A custom `HttpClient` must not follow redirects for these credential-bearing
249
- requests.
248
+ `@yolk-sdk/agent/providers/anthropic/usage` for Claude. Use
249
+ `fetchXAiGrokSubscriptionUsage` from `@yolk-sdk/agent/providers/xai/usage` for Grok and pass the
250
+ actual authenticated xAI `user_id` as `xAiUserId`. The generic token `accountId` is not interpreted
251
+ as an xAI user id. Also pass your host integration's truthful version as `clientVersion`; the
252
+ adapter sends it with `x-grok-client-mode: headless` and never claims an official Grok client
253
+ version.
254
+
255
+ Provider adapters return an immutable Effect `Chunk` of semantic window ids, percentages, and
256
+ optional reset/duration fields; hosts own labels, polling, persistence, stale-data policy, alert
257
+ thresholds, billing interpretation, and UI. Configure `requestTimeoutMs` at the server integration
258
+ boundary. Endpoint origins stay fixed, and `FetchHttpClient.layer` is configured for manual
259
+ redirects. A custom `HttpClient` must not follow redirects for these credential-bearing requests.
250
260
 
251
261
  Subscription allowance snapshots are separate from protocol `AgentUsage`, which accounts for tokens
252
262
  used by model requests and nested model work.
@@ -18,8 +18,8 @@ declare const makeCompactionCheckpointText: (input: CompactionCheckpointInput) =
18
18
  declare const makeCompactionCheckpointMessage: (input: CompactionCheckpointInput) => UserMessage;
19
19
  declare const isCompactionCheckpointText: (value: string) => boolean;
20
20
  declare const isCompactionCheckpointMessage: (message: AgentMessage) => boolean;
21
- declare const dropLeadingCompactionCheckpointMessage: (messages: ReadonlyArray<AgentMessage>) => readonly (import("@yolk-sdk/agent/protocol").ToolResultMessage | UserMessage | import("@yolk-sdk/agent/protocol").AssistantAgentMessage)[];
22
- declare const compactionSummarySourceMessages: (input: CompactionSummarySourceMessageOptions) => readonly (import("@yolk-sdk/agent/protocol").ToolResultMessage | UserMessage | import("@yolk-sdk/agent/protocol").AssistantAgentMessage)[];
21
+ declare const dropLeadingCompactionCheckpointMessage: (messages: ReadonlyArray<AgentMessage>) => readonly (UserMessage | import("@yolk-sdk/agent/protocol").AssistantAgentMessage | import("@yolk-sdk/agent/protocol").ToolResultMessage)[];
22
+ declare const compactionSummarySourceMessages: (input: CompactionSummarySourceMessageOptions) => readonly (UserMessage | import("@yolk-sdk/agent/protocol").AssistantAgentMessage | import("@yolk-sdk/agent/protocol").ToolResultMessage)[];
23
23
  //#endregion
24
24
  export { CompactionCheckpointInput, CompactionSummarySourceMessageOptions, compactionCheckpointCloseTag, compactionCheckpointOpenTag, compactionSummarySourceMessages, defaultCompactionCheckpointHeader, dropLeadingCompactionCheckpointMessage, isCompactionCheckpointMessage, isCompactionCheckpointText, makeCompactionCheckpointMessage, makeCompactionCheckpointText };
25
25
  //# sourceMappingURL=checkpoint.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkpoint.d.mts","names":[],"sources":["../../src/compaction/checkpoint.ts"],"mappings":";;;cAEa,2BAAA;AAAA,cACA,4BAAA;AAAA,cACA,iCAAA;AAAA,KAGD,yBAAA;EAAA,SACD,OAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;AAAA;AAAA,KAGC,qCAAA;EAAA,SACD,kBAAA;EAAA,SACA,QAAA,EAAU,aAAa,CAAC,YAAA;AAAA;AAAA,cAGtB,4BAAA,GAAgC,KAAgC,EAAzB,yBAAyB;AAAA,cAahE,+BAAA,GAAmC,KAAA,EAAO,yBAAA,KAAyB,WAI5E;AAAA,cAES,0BAAA,GAA8B,KAAa;AAAA,cAG3C,6BAAA,GAAiC,OAAqB,EAAZ,YAAY;AAAA,cAGtD,sCAAA,GACX,QAAA,EAAU,aAAA,CAAc,YAAA,mDAAa,iBAAA,GAAA,WAAA,sCAAA,qBAAA;AAAA,cAO1B,+BAAA,GACX,KAAA,EAAO,qCAAA,kDAAqC,iBAAA,GAAA,WAAA,sCAAA,qBAAA"}
1
+ {"version":3,"file":"checkpoint.d.mts","names":[],"sources":["../../src/compaction/checkpoint.ts"],"mappings":";;;cAEa,2BAAA;AAAA,cACA,4BAAA;AAAA,cACA,iCAAA;AAAA,KAGD,yBAAA;EAAA,SACD,OAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;AAAA;AAAA,KAGC,qCAAA;EAAA,SACD,kBAAA;EAAA,SACA,QAAA,EAAU,aAAa,CAAC,YAAA;AAAA;AAAA,cAGtB,4BAAA,GAAgC,KAAgC,EAAzB,yBAAyB;AAAA,cAahE,+BAAA,GAAmC,KAAA,EAAO,yBAAA,KAAyB,WAI5E;AAAA,cAES,0BAAA,GAA8B,KAAa;AAAA,cAG3C,6BAAA,GAAiC,OAAqB,EAAZ,YAAY;AAAA,cAGtD,sCAAA,GACX,QAAA,EAAU,aAAA,CAAc,YAAA,gBAAa,WAAA,sCAAA,qBAAA,sCAAA,iBAAA;AAAA,cAO1B,+BAAA,GACX,KAAA,EAAO,qCAAA,eAAqC,WAAA,sCAAA,qBAAA,sCAAA,iBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;cAqBa,mCAAA;AAAA,KAED,uCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cAoBd,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAuDvC,qCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,uCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
1
+ {"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;cAoBa,mCAAA;AAAA,KAED,uCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cAoBd,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAuDvC,qCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,uCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
@@ -1,5 +1,5 @@
1
1
  import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
2
- import { canonicalSubscriptionUsageInstant, executeProviderSubscriptionUsageRequest, readProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
2
+ import { canonicalSubscriptionUsageInstant, executeAndReadProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
3
3
  import { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from "./claude.mjs";
4
4
  import { Chunk, Clock, Effect } from "effect";
5
5
  import { HttpClient, HttpClientRequest } from "effect/unstable/http";
@@ -56,7 +56,7 @@ const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.ge
56
56
  provider: anthropicClaudeProviderId,
57
57
  reason: "invalid_request_timeout"
58
58
  }));
59
- return yield* parseAnthropicClaudeSubscriptionUsage(yield* readProviderSubscriptionUsageJson(anthropicClaudeProviderId, yield* executeProviderSubscriptionUsageRequest({
59
+ return yield* parseAnthropicClaudeSubscriptionUsage(yield* executeAndReadProviderSubscriptionUsageJson({
60
60
  provider: anthropicClaudeProviderId,
61
61
  client: yield* HttpClient.HttpClient,
62
62
  request: HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(HttpClientRequest.setHeaders({
@@ -65,7 +65,7 @@ const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.ge
65
65
  "anthropic-beta": "oauth-2025-04-20"
66
66
  })),
67
67
  timeoutMs: requestTimeoutMs
68
- })), new Date(yield* Clock.currentTimeMillis).toISOString());
68
+ }), new Date(yield* Clock.currentTimeMillis).toISOString());
69
69
  }).pipe(Effect.withSpan("AnthropicClaudeSubscriptionUsage.fetch"));
70
70
  //#endregion
71
71
  export { anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
@@ -1 +1 @@
1
- {"version":3,"file":"usage.mjs","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from './claude.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeProviderSubscriptionUsageRequest,\n readProviderSubscriptionUsageJson,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const anthropicClaudeSubscriptionUsageUrl = 'https://api.anthropic.com/api/oauth/usage'\n\nexport type AnthropicClaudeSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\nconst NullableString = Schema.NullOr(Schema.String)\n\nclass AnthropicClaudeSubscriptionUsageWindowWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWindowWire>(\n 'AnthropicClaudeSubscriptionUsageWindowWire'\n)({\n utilization: Schema.optional(NullableNumber),\n resets_at: Schema.optional(NullableString)\n}) {}\n\nclass AnthropicClaudeSubscriptionUsageWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWire>(\n 'AnthropicClaudeSubscriptionUsageWire'\n)({\n five_hour: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),\n seven_day: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))\n}) {}\n\nexport const parseAnthropicClaudeSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: AnthropicClaudeSubscriptionUsageWindowWire | null | undefined,\n id: 'five-hour' | 'seven-day'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.utilization)) {\n return\n }\n\n const resetValue = wire.resets_at === null ? undefined : wire.resets_at\n const resetsAt =\n resetValue === undefined ? undefined : canonicalSubscriptionUsageInstant(resetValue)\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.utilization,\n ...(resetsAt === undefined ? {} : { resetsAt })\n })\n )\n }\n\n append(decoded.five_hour, 'five-hour')\n append(decoded.seven_day, 'seven-day')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: anthropicClaudeProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('AnthropicClaudeSubscriptionUsage.parse')\n )\n}\n\nexport const fetchAnthropicClaudeSubscriptionUsage = (\n token: OAuthAccessToken,\n options: AnthropicClaudeSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== anthropicClaudeProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n const response = yield* executeProviderSubscriptionUsageRequest({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const json = yield* readProviderSubscriptionUsageJson(anthropicClaudeProviderId, response)\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseAnthropicClaudeSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('AnthropicClaudeSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAqBA,MAAa,sCAAsC;AAMnD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAClD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,6CAAN,cAAyD,OAAO,MAC9D,4CACF,EAAE;CACA,aAAa,OAAO,SAAS,cAAc;CAC3C,WAAW,OAAO,SAAS,cAAc;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;CACpF,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;AACtF,CAAC,EAAE,CAAC;AAEJ,MAAa,yCACX,OACA,cAC6F;CAC7F,MAAM,qBAAqB,kCAAkC,SAAS;CAEtE,IAAI,uBAAuB,KAAA,GACzB,OAAO,OAAO,KACZ,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH;CAGF,OAAO,OAAO,oBAAoB,oCAAoC,EAAE,KAAK,EAAE,KAC7E,OAAO,KAAI,YAAW;EACpB,MAAM,UAAkD,CAAC;EACzD,MAAM,UACJ,MACA,OACG;GACH,IAA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,OAAO,SAAS,wCAAwC,CAAC"}
1
+ {"version":3,"file":"usage.mjs","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from './claude.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeAndReadProviderSubscriptionUsageJson,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const anthropicClaudeSubscriptionUsageUrl = 'https://api.anthropic.com/api/oauth/usage'\n\nexport type AnthropicClaudeSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\nconst NullableString = Schema.NullOr(Schema.String)\n\nclass AnthropicClaudeSubscriptionUsageWindowWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWindowWire>(\n 'AnthropicClaudeSubscriptionUsageWindowWire'\n)({\n utilization: Schema.optional(NullableNumber),\n resets_at: Schema.optional(NullableString)\n}) {}\n\nclass AnthropicClaudeSubscriptionUsageWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWire>(\n 'AnthropicClaudeSubscriptionUsageWire'\n)({\n five_hour: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),\n seven_day: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))\n}) {}\n\nexport const parseAnthropicClaudeSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: AnthropicClaudeSubscriptionUsageWindowWire | null | undefined,\n id: 'five-hour' | 'seven-day'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.utilization)) {\n return\n }\n\n const resetValue = wire.resets_at === null ? undefined : wire.resets_at\n const resetsAt =\n resetValue === undefined ? undefined : canonicalSubscriptionUsageInstant(resetValue)\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.utilization,\n ...(resetsAt === undefined ? {} : { resetsAt })\n })\n )\n }\n\n append(decoded.five_hour, 'five-hour')\n append(decoded.seven_day, 'seven-day')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: anthropicClaudeProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('AnthropicClaudeSubscriptionUsage.parse')\n )\n}\n\nexport const fetchAnthropicClaudeSubscriptionUsage = (\n token: OAuthAccessToken,\n options: AnthropicClaudeSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== anthropicClaudeProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseAnthropicClaudeSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('AnthropicClaudeSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAoBA,MAAa,sCAAsC;AAMnD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAClD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,6CAAN,cAAyD,OAAO,MAC9D,4CACF,EAAE;CACA,aAAa,OAAO,SAAS,cAAc;CAC3C,WAAW,OAAO,SAAS,cAAc;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;CACpF,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;AACtF,CAAC,EAAE,CAAC;AAEJ,MAAa,yCACX,OACA,cAC6F;CAC7F,MAAM,qBAAqB,kCAAkC,SAAS;CAEtE,IAAI,uBAAuB,KAAA,GACzB,OAAO,OAAO,KACZ,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH;CAGF,OAAO,OAA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AW;CACb,CAAC,GACiB,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEO,CAAC;AACrE,CAAC,EAAE,KAAK,OAAO,SAAS,wCAAwC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"codex-usage.d.mts","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"mappings":";;;;;;cAsBa,+BAAA;AAAA,KAED,mCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cA2Bd,iCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAiEvC,iCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,mCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
1
+ {"version":3,"file":"codex-usage.d.mts","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"mappings":";;;;;;cAqBa,+BAAA;AAAA,KAED,mCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cA2Bd,iCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAiEvC,iCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,mCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
@@ -1,5 +1,5 @@
1
1
  import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
2
- import { canonicalSubscriptionUsageInstant, executeProviderSubscriptionUsageRequest, positiveSubscriptionUsageNumber, readProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
2
+ import { canonicalSubscriptionUsageInstant, executeAndReadProviderSubscriptionUsageJson, positiveSubscriptionUsageNumber, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
3
3
  import { openAiCodexProviderId } from "./codex.mjs";
4
4
  import { Chunk, Clock, Effect } from "effect";
5
5
  import { HttpClient, HttpClientRequest } from "effect/unstable/http";
@@ -67,7 +67,7 @@ const fetchOpenAiCodexSubscriptionUsage = (token, options = {}) => Effect.gen(fu
67
67
  provider: openAiCodexProviderId,
68
68
  reason: "invalid_request_timeout"
69
69
  }));
70
- return yield* parseOpenAiCodexSubscriptionUsage(yield* readProviderSubscriptionUsageJson(openAiCodexProviderId, yield* executeProviderSubscriptionUsageRequest({
70
+ return yield* parseOpenAiCodexSubscriptionUsage(yield* executeAndReadProviderSubscriptionUsageJson({
71
71
  provider: openAiCodexProviderId,
72
72
  client: yield* HttpClient.HttpClient,
73
73
  request: HttpClientRequest.get(openAiCodexSubscriptionUsageUrl).pipe(HttpClientRequest.setHeaders({
@@ -76,7 +76,7 @@ const fetchOpenAiCodexSubscriptionUsage = (token, options = {}) => Effect.gen(fu
76
76
  "chatgpt-account-id": accountId
77
77
  })),
78
78
  timeoutMs: requestTimeoutMs
79
- })), new Date(yield* Clock.currentTimeMillis).toISOString());
79
+ }), new Date(yield* Clock.currentTimeMillis).toISOString());
80
80
  }).pipe(Effect.withSpan("OpenAiCodexSubscriptionUsage.fetch"));
81
81
  //#endregion
82
82
  export { fetchOpenAiCodexSubscriptionUsage, openAiCodexSubscriptionUsageUrl, parseOpenAiCodexSubscriptionUsage };
@@ -1 +1 @@
1
- {"version":3,"file":"codex-usage.mjs","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { openAiCodexProviderId } from './codex.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeProviderSubscriptionUsageRequest,\n positiveSubscriptionUsageNumber,\n readProviderSubscriptionUsageJson,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const openAiCodexSubscriptionUsageUrl = 'https://chatgpt.com/backend-api/wham/usage'\n\nexport type OpenAiCodexSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\n\nclass OpenAiCodexSubscriptionUsageWindowWire extends Schema.Class<OpenAiCodexSubscriptionUsageWindowWire>(\n 'OpenAiCodexSubscriptionUsageWindowWire'\n)({\n used_percent: Schema.optional(NullableNumber),\n limit_window_seconds: Schema.optional(NullableNumber),\n reset_after_seconds: Schema.optional(NullableNumber),\n reset_at: Schema.optional(NullableNumber)\n}) {}\n\nclass OpenAiCodexSubscriptionRateLimitWire extends Schema.Class<OpenAiCodexSubscriptionRateLimitWire>(\n 'OpenAiCodexSubscriptionRateLimitWire'\n)({\n primary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire)),\n secondary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire))\n}) {}\n\nclass OpenAiCodexSubscriptionUsageWire extends Schema.Class<OpenAiCodexSubscriptionUsageWire>(\n 'OpenAiCodexSubscriptionUsageWire'\n)({\n rate_limit: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionRateLimitWire))\n}) {}\n\nexport const parseOpenAiCodexSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(OpenAiCodexSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: OpenAiCodexSubscriptionUsageWindowWire | null | undefined,\n id: 'primary' | 'secondary'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.used_percent)) {\n return\n }\n\n const resetAt = wire.reset_at\n const resetsAt =\n resetAt === null || resetAt === undefined\n ? undefined\n : canonicalSubscriptionUsageInstant(resetAt)\n const resetsAfterSeconds = positiveSubscriptionUsageNumber(wire.reset_after_seconds)\n ? wire.reset_after_seconds\n : undefined\n const windowDurationMinutes = positiveSubscriptionUsageNumber(wire.limit_window_seconds)\n ? wire.limit_window_seconds / 60\n : undefined\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.used_percent,\n ...(resetsAt === undefined ? {} : { resetsAt }),\n ...(resetsAfterSeconds === undefined ? {} : { resetsAfterSeconds }),\n ...(windowDurationMinutes === undefined ? {} : { windowDurationMinutes })\n })\n )\n }\n\n append(decoded.rate_limit?.primary_window, 'primary')\n append(decoded.rate_limit?.secondary_window, 'secondary')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: openAiCodexProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('OpenAiCodexSubscriptionUsage.parse')\n )\n}\n\nexport const fetchOpenAiCodexSubscriptionUsage = (\n token: OAuthAccessToken,\n options: OpenAiCodexSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== openAiCodexProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const accountId = token.accountId?.trim()\n\n if (accountId === undefined || accountId.length === 0) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'missing_account_id'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(openAiCodexSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n authorization: `Bearer ${token.accessToken}`,\n 'chatgpt-account-id': accountId\n })\n )\n const response = yield* executeProviderSubscriptionUsageRequest({\n provider: openAiCodexProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const json = yield* readProviderSubscriptionUsageJson(openAiCodexProviderId, response)\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseOpenAiCodexSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('OpenAiCodexSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAsBA,MAAa,kCAAkC;AAM/C,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,yCAAN,cAAqD,OAAO,MAC1D,wCACF,EAAE;CACA,cAAc,OAAO,SAAS,cAAc;CAC5C,sBAAsB,OAAO,SAAS,cAAc;CACpD,qBAAqB,OAAO,SAAS,cAAc;CACnD,UAAU,OAAO,SAAS,cAAc;AAC1C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,gBA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MAAM,aAAa,OAAO;EACrC,CAAC;CACH,CAAC,GACD,OAAO,eACL,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH,GACA,OAAO,SAAS,oCAAoC,CACtD;AACF;AAEA,MAAa,qCACX,OACA,UAA+C,CAAC,MAMhD,OAAO,IAAI,aAAa;CACtB,IAAI,MAAM,aAAA,gBACR,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,YAAY,MAAM,WAAW,KAAK;CAExC,IAAI,cAAc,KAAA,KAAa,UAAU,WAAW,GAClD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,mBAAmB,QAAQ,oBAAA;CAEjC,IAAI,CAAC,sCAAsC,gBAAgB,GACzD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAoBF,OAAO,OAAO,kCAAkC,OAH5B,kCAAkC,uBAAuB,OANrD,wCAAwC;EAC9D,UAAU;EACV,QAAA,OAVoB,WAAW;EAW/B,SAVc,kBAAkB,IAAI,+BAA+B,EAAE,KACrE,kBAAkB,WAAW;GAC3B,QAAQ;GACR,eAAe,UAAU,MAAM;GAC/B,sBAAsB;EACxB,CAAC,CAKK;EACN,WAAW;CACb,CAAC,CACoF,GACnE,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEG,CAAC;AACjE,CAAC,EAAE,KAAK,OAAO,SAAS,oCAAoC,CAAC"}
1
+ {"version":3,"file":"codex-usage.mjs","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { openAiCodexProviderId } from './codex.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeAndReadProviderSubscriptionUsageJson,\n positiveSubscriptionUsageNumber,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const openAiCodexSubscriptionUsageUrl = 'https://chatgpt.com/backend-api/wham/usage'\n\nexport type OpenAiCodexSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\n\nclass OpenAiCodexSubscriptionUsageWindowWire extends Schema.Class<OpenAiCodexSubscriptionUsageWindowWire>(\n 'OpenAiCodexSubscriptionUsageWindowWire'\n)({\n used_percent: Schema.optional(NullableNumber),\n limit_window_seconds: Schema.optional(NullableNumber),\n reset_after_seconds: Schema.optional(NullableNumber),\n reset_at: Schema.optional(NullableNumber)\n}) {}\n\nclass OpenAiCodexSubscriptionRateLimitWire extends Schema.Class<OpenAiCodexSubscriptionRateLimitWire>(\n 'OpenAiCodexSubscriptionRateLimitWire'\n)({\n primary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire)),\n secondary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire))\n}) {}\n\nclass OpenAiCodexSubscriptionUsageWire extends Schema.Class<OpenAiCodexSubscriptionUsageWire>(\n 'OpenAiCodexSubscriptionUsageWire'\n)({\n rate_limit: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionRateLimitWire))\n}) {}\n\nexport const parseOpenAiCodexSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(OpenAiCodexSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: OpenAiCodexSubscriptionUsageWindowWire | null | undefined,\n id: 'primary' | 'secondary'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.used_percent)) {\n return\n }\n\n const resetAt = wire.reset_at\n const resetsAt =\n resetAt === null || resetAt === undefined\n ? undefined\n : canonicalSubscriptionUsageInstant(resetAt)\n const resetsAfterSeconds = positiveSubscriptionUsageNumber(wire.reset_after_seconds)\n ? wire.reset_after_seconds\n : undefined\n const windowDurationMinutes = positiveSubscriptionUsageNumber(wire.limit_window_seconds)\n ? wire.limit_window_seconds / 60\n : undefined\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.used_percent,\n ...(resetsAt === undefined ? {} : { resetsAt }),\n ...(resetsAfterSeconds === undefined ? {} : { resetsAfterSeconds }),\n ...(windowDurationMinutes === undefined ? {} : { windowDurationMinutes })\n })\n )\n }\n\n append(decoded.rate_limit?.primary_window, 'primary')\n append(decoded.rate_limit?.secondary_window, 'secondary')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: openAiCodexProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('OpenAiCodexSubscriptionUsage.parse')\n )\n}\n\nexport const fetchOpenAiCodexSubscriptionUsage = (\n token: OAuthAccessToken,\n options: OpenAiCodexSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== openAiCodexProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const accountId = token.accountId?.trim()\n\n if (accountId === undefined || accountId.length === 0) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'missing_account_id'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(openAiCodexSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n authorization: `Bearer ${token.accessToken}`,\n 'chatgpt-account-id': accountId\n })\n )\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: openAiCodexProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseOpenAiCodexSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('OpenAiCodexSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAqBA,MAAa,kCAAkC;AAM/C,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,yCAAN,cAAqD,OAAO,MAC1D,wCACF,EAAE;CACA,cAAc,OAAO,SAAS,cAAc;CAC5C,sBAAsB,OAAO,SAAS,cAAc;CACpD,qBAAqB,OAAO,SAAS,cAAc;CACnD,UAAU,OAAO,SAAS,cAAc;AAC1C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAA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GACX,SAAS,MAAM,aAAa,OAAO;EACrC,CAAC;CACH,CAAC,GACD,OAAO,eACL,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH,GACA,OAAO,SAAS,oCAAoC,CACtD;AACF;AAEA,MAAa,qCACX,OACA,UAA+C,CAAC,MAMhD,OAAO,IAAI,aAAa;CACtB,IAAI,MAAM,aAAA,gBACR,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,YAAY,MAAM,WAAW,KAAK;CAExC,IAAI,cAAc,KAAA,KAAa,UAAU,WAAW,GAClD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,mBAAmB,QAAQ,oBAAA;CAEjC,IAAI,CAAC,sCAAsC,gBAAgB,GACzD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAmBF,OAAO,OAAO,kCAAkC,OAR5B,4CAA4C;EAC9D,UAAU;EACV,QAAA,OAVoB,WAAW;EAW/B,SAVc,kBAAkB,IAAI,+BAA+B,EAAE,KACrE,kBAAkB,WAAW;GAC3B,QAAQ;GACR,eAAe,UAAU,MAAM;GAC/B,sBAAsB;EACxB,CAAC,CAKK;EACN,WAAW;CACb,CAAC,GACiB,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEG,CAAC;AACjE,CAAC,EAAE,KAAK,OAAO,SAAS,oCAAoC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses-provider-internal.d.mts","names":[],"sources":["../../src/providers/openai-responses-provider-internal.ts"],"mappings":";;;;;;;KAgDK,+BAAA;AAAA,KAEO,6BAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,UAAA;EAAA,SACA,YAAA;EAAA,SACA,YAAA;EAAA,SACA,oBAAA,G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EAAS,+BAAA;EAAA;EAAA,SAEX,KAAA,GAAQ,aAAA,CAAc,mBAAA;EAAA,SACtB,mBAAA;AAAA;AAAA,KAGN,uCAAA,GAA0C,0BAAA;EAAA,SACpC,SAAA,EAAW,WAAA,CAAY,0BAAA;AAAA;AAAA,cAgTrB,4BAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,YAAA;EAAA,SACA,8BAAA;EAAA,SACA,sBAAA;EAAA,SACA,eAAA;EAAA,SACA,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,+BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,0BAAA,EAA4B,QAAA;AAAA,cAwDhC,yCAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,YAAA;EAAA,SACA,8BAAA;EAAA,SACA,eAAA;EAAA,SACA,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,+BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,uCAAA,EAAyC,QAAA;AAAA,KAyCrD,iCAAA;EAAA,SACM,UAAA;EAAA,SACA,YAAA;EAAA,SACA,kBAAA;AAAA;AAAA,cAGE,+BAAA,GAAmC,YAAA,UAAsB,KAAA,EAAO,QAAA,KAAQ,QAMjF;AAAA,cA8mBS,6BAAA,GACX,UAAA,EAAY,iCAAA,EACZ,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cA2Hd,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
1
+ {"version":3,"file":"openai-responses-provider-internal.d.mts","names":[],"sources":["../../src/providers/openai-responses-provider-internal.ts"],"mappings":";;;;;;;KAgDK,+BAAA;AAAA,KAEO,6BAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,UAAA;EAAA,SACA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,SACE,MAAA,EAAQ,oBAAA;IAAA,SACR,OAAA,EAAS,+BAAA;EAAA;EAAA,SAEX,KAAA,GAAQ,aAAA,CAAc,mBAAA;EAAA,SACtB,mBAAA;AAAA;AAAA,KAGN,uCAAA,GAA0C,0BAAA;EAAA,SACpC,SAAA,EAAW,WAAA,CAAY,0BAAA;AAAA;AAAA,cAgTrB,4BAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,YAAA;EAAA,SACA,8BAAA;EAAA,SACA,sBAAA;EAAA,SACA,eAAA;EAAA,SACA,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,+BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,0BAAA,EAA4B,QAAA;AAAA,cAwDhC,yCAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,YAAA;EAAA,SACA,8BAAA;EAAA,SACA,eAAA;EAAA,SACA,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,+BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,uCAAA,EAAyC,QAAA;AAAA,KAyCrD,iCAAA;EAAA,SACM,UAAA;EAAA,SACA,YAAA;EAAA,SACA,kBAAA;AAAA;AAAA,cAGE,+BAAA,GAAmC,YAAA,UAAsB,KAAA,EAAO,QAAA,KAAQ,QAMjF;AAAA,cA0oBS,6BAAA,GACX,UAAA,EAAY,iCAAA,EACZ,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cA2Hd,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
@@ -250,7 +250,7 @@ const reasoningFromOutputItem = (item) => {
250
250
  }
251
251
  };
252
252
  const reasoningFromOutputItems = (items) => {
253
- return Array.flatten(Array.map(items, reasoningFromOutputItem)).join("");
253
+ return Array.flatten(Array.map(items, reasoningFromOutputItem)).join("\n\n");
254
254
  };
255
255
  const isValidTokenCount = (value) => Number.isSafeInteger(value) && value >= 0;
256
256
  const toAgentUsage = (usage) => {
@@ -323,6 +323,7 @@ const initialBodyState = {
323
323
  sse: {
324
324
  hasTextDelta: false,
325
325
  hasReasoningDelta: false,
326
+ reasoningSummaryPartKey: void 0,
326
327
  toolCallIds: /* @__PURE__ */ new Set(),
327
328
  hasDone: false
328
329
  }
@@ -408,6 +409,10 @@ const finalResponseToEvents = (response, state) => Effect.gen(function* () {
408
409
  if (!hasToolCalls) return dedupedEvents;
409
410
  return dedupedEvents.map((event) => event._tag === "Done" ? LLMDone.make({ stopReason: "tool_use" }) : event);
410
411
  });
412
+ const reasoningSummaryPartKey = (event) => {
413
+ if (typeof event.item_id !== "string" || typeof event.summary_index !== "number") return;
414
+ return `${event.item_id}:${event.summary_index}`;
415
+ };
411
416
  const processSseData = (descriptor, state, data) => Effect.gen(function* () {
412
417
  if (state.hasDone) return {
413
418
  state,
@@ -425,7 +430,19 @@ const processSseData = (descriptor, state, data) => Effect.gen(function* () {
425
430
  },
426
431
  events: [LLMTextDelta$1.make({ text: parsed.delta })]
427
432
  };
428
- if ((parsed.type === "response.reasoning_summary_text.delta" || parsed.type === "response.reasoning_text.delta") && typeof parsed.delta === "string") return {
433
+ if (parsed.type === "response.reasoning_summary_text.delta" && typeof parsed.delta === "string") {
434
+ const partKey = reasoningSummaryPartKey(parsed);
435
+ const startsNewPart = partKey !== void 0 && state.reasoningSummaryPartKey !== void 0 && partKey !== state.reasoningSummaryPartKey;
436
+ return {
437
+ state: {
438
+ ...state,
439
+ hasReasoningDelta: true,
440
+ reasoningSummaryPartKey: partKey ?? state.reasoningSummaryPartKey
441
+ },
442
+ events: [LLMReasoningDelta$1.make({ text: `${startsNewPart ? "\n\n" : ""}${parsed.delta}` })]
443
+ };
444
+ }
445
+ if (parsed.type === "response.reasoning_text.delta" && typeof parsed.delta === "string") return {
429
446
  state: {
430
447
  ...state,
431
448
  hasReasoningDelta: true
@@ -440,6 +457,7 @@ const processSseData = (descriptor, state, data) => Effect.gen(function* () {
440
457
  state: {
441
458
  hasTextDelta: state.hasTextDelta || events.some((event) => event._tag === "TextDelta"),
442
459
  hasReasoningDelta: state.hasReasoningDelta || events.some((event) => event._tag === "ReasoningDelta"),
460
+ reasoningSummaryPartKey: state.reasoningSummaryPartKey,
443
461
  toolCallIds: new Set([...state.toolCallIds, ...emittedToolCallIds]),
444
462
  hasDone: state.hasDone
445
463
  },
@@ -459,6 +477,7 @@ const processSseData = (descriptor, state, data) => Effect.gen(function* () {
459
477
  state: {
460
478
  hasTextDelta: state.hasTextDelta || emittedText,
461
479
  hasReasoningDelta: state.hasReasoningDelta || emittedReasoning,
480
+ reasoningSummaryPartKey: state.reasoningSummaryPartKey,
462
481
  toolCallIds: new Set([...state.toolCallIds, ...emittedToolCallIds]),
463
482
  hasDone: true
464
483
  },