@yolk-sdk/agent 0.1.0-canary.115 → 0.1.0-canary.116

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 (62) hide show
  1. package/README.md +10 -5
  2. package/dist/protocol/event.d.mts +6 -0
  3. package/dist/protocol/event.d.mts.map +1 -1
  4. package/dist/protocol/event.mjs +6 -0
  5. package/dist/protocol/event.mjs.map +1 -1
  6. package/dist/providers/anthropic/conformance/claude-usage-cases.d.mts.map +1 -1
  7. package/dist/providers/anthropic/conformance/claude-usage-cases.mjs +30 -5
  8. package/dist/providers/anthropic/conformance/claude-usage-cases.mjs.map +1 -1
  9. package/dist/providers/anthropic/conformance/claude-usage-snapshot.d.mts +2 -1
  10. package/dist/providers/anthropic/conformance/claude-usage-snapshot.d.mts.map +1 -1
  11. package/dist/providers/anthropic/conformance/claude-usage-snapshot.mjs +3 -2
  12. package/dist/providers/anthropic/conformance/claude-usage-snapshot.mjs.map +1 -1
  13. package/dist/providers/anthropic/usage.d.mts +3 -1
  14. package/dist/providers/anthropic/usage.d.mts.map +1 -1
  15. package/dist/providers/anthropic/usage.mjs +70 -16
  16. package/dist/providers/anthropic/usage.mjs.map +1 -1
  17. package/dist/providers/anthropic-provider-internal.d.mts.map +1 -1
  18. package/dist/providers/anthropic-provider-internal.mjs +8 -1
  19. package/dist/providers/anthropic-provider-internal.mjs.map +1 -1
  20. package/dist/providers/openai/conformance/subscription-usage-cases-internal.d.mts +7 -1
  21. package/dist/providers/openai/conformance/subscription-usage-cases-internal.d.mts.map +1 -1
  22. package/dist/providers/openai/conformance/subscription-usage-cases-internal.mjs +8 -5
  23. package/dist/providers/openai/conformance/subscription-usage-cases-internal.mjs.map +1 -1
  24. package/dist/providers/openai-responses-provider-internal.d.mts.map +1 -1
  25. package/dist/providers/openai-responses-provider-internal.mjs +15 -2
  26. package/dist/providers/openai-responses-provider-internal.mjs.map +1 -1
  27. package/dist/providers/opencode/usage.d.mts.map +1 -1
  28. package/dist/providers/opencode/usage.mjs +13 -4
  29. package/dist/providers/opencode/usage.mjs.map +1 -1
  30. package/dist/providers/provider-error.d.mts +3 -1
  31. package/dist/providers/provider-error.d.mts.map +1 -1
  32. package/dist/providers/provider-error.mjs +2 -0
  33. package/dist/providers/provider-error.mjs.map +1 -1
  34. package/dist/providers/quota-reset-internal.d.mts +29 -0
  35. package/dist/providers/quota-reset-internal.d.mts.map +1 -0
  36. package/dist/providers/quota-reset-internal.mjs +98 -0
  37. package/dist/providers/quota-reset-internal.mjs.map +1 -0
  38. package/dist/providers/subscription-usage.d.mts +5 -0
  39. package/dist/providers/subscription-usage.d.mts.map +1 -1
  40. package/dist/providers/subscription-usage.mjs +6 -1
  41. package/dist/providers/subscription-usage.mjs.map +1 -1
  42. package/dist/react/chat-actions.d.mts +35 -35
  43. package/dist/react/chat-actions.d.mts.map +1 -1
  44. package/dist/react/chat-items.d.mts +30 -30
  45. package/dist/react/chat-items.d.mts.map +1 -1
  46. package/dist/react/chat-messages.d.mts +76 -76
  47. package/dist/react/chat-messages.d.mts.map +1 -1
  48. package/dist/skillset/merge.d.mts +1 -1
  49. package/dist/skillset/name.d.mts +2 -2
  50. package/dist/skillset/name.d.mts.map +1 -1
  51. package/package.json +3 -3
  52. package/src/protocol/event.ts +6 -0
  53. package/src/providers/anthropic/conformance/claude-usage-cases.ts +60 -5
  54. package/src/providers/anthropic/conformance/claude-usage-snapshot.ts +3 -2
  55. package/src/providers/anthropic/usage.ts +122 -27
  56. package/src/providers/anthropic-provider-internal.ts +13 -1
  57. package/src/providers/openai/conformance/subscription-usage-cases-internal.ts +32 -6
  58. package/src/providers/openai-responses-provider-internal.ts +23 -4
  59. package/src/providers/opencode/usage.ts +19 -5
  60. package/src/providers/provider-error.ts +12 -0
  61. package/src/providers/quota-reset-internal.ts +227 -0
  62. package/src/providers/subscription-usage.ts +6 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@ Root export is intentionally empty. Import feature APIs from explicit subpaths.
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- pnpm add @yolk-sdk/agent@canary effect@4.0.0
10
+ pnpm add @yolk-sdk/agent@canary effect@4.0.5
11
11
  ```
12
12
 
13
13
  Add `react` if you use `@yolk-sdk/agent/react` or `@yolk-sdk/agent/voice/react`.
@@ -15,7 +15,7 @@ Add `react` if you use `@yolk-sdk/agent/react` or `@yolk-sdk/agent/voice/react`.
15
15
  Running the experimental `@yolk-sdk/agent/providers/*/conformance` cases? Also add `@yolk-sdk/conformance@canary` (usually as a dev dependency); the cases run through `@yolk-sdk/conformance/runner`.
16
16
 
17
17
  Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
18
- Use the SDK's matching Effect version (`4.0.0`) in host code.
18
+ Use the SDK's matching Effect version (`4.0.5`) in host code.
19
19
  Published package metadata requires Node.js 22+.
20
20
 
21
21
  ## Subpaths
@@ -443,7 +443,9 @@ Provider adapters classify safe failure metadata at the boundary. The loop owns
443
443
  policy and emits protocol-visible retry/error state:
444
444
 
445
445
  - `ProviderErrorInfo` carries safe provider id, failure kind, HTTP status, provider code, optional
446
- `retryAfterMs`, and optional `stream` diagnostics (`ProviderStreamDiagnostics`) on chat
446
+ `retryAfterMs`, optional `quotaResetsAtMs` (epoch milliseconds when a spent account-wide
447
+ subscription quota resets; on `rate_limit` only, when Claude or a Responses provider such as
448
+ ChatGPT Codex reports a trusted reset), and optional `stream` diagnostics (`ProviderStreamDiagnostics`) on chat
447
449
  `unexpected_content_type` / `incomplete_stream` failures. Diagnostics contain counters and
448
450
  milestones, never transcript content, raw headers, or body fragments. See the
449
451
  [stream diagnostics guide](https://github.com/magoz/yolk-sdk/blob/main/apps/docs/content/docs/troubleshooting.mdx#diagnose-chat-stream-failures-with-stream-diagnostics).
@@ -471,7 +473,8 @@ typed retry/error state.
471
473
  ## Subscription allowance snapshots
472
474
 
473
475
  The Claude, Codex, and Grok usage adapters read best-effort consumer subscription allowance
474
- percentages and reset windows. Claude normalizes its aggregate five-hour and seven-day windows;
476
+ percentages and reset windows. Claude normalizes its aggregate five-hour and seven-day windows plus model-scoped weekly limits
477
+ (`seven-day-<model>`);
475
478
  Codex normalizes primary and secondary rate-limit windows; Grok normalizes its aggregate shared
476
479
  credit allowance. Additional provider-specific buckets are ignored. These private provider
477
480
  endpoints may change without notice. Pass a fresh host-owned `OAuthAccessToken` and provide an
@@ -497,7 +500,9 @@ adapter sends it with `x-grok-client-mode: headless` and never claims an officia
497
500
  version.
498
501
 
499
502
  Provider adapters return an immutable Effect `Chunk` of semantic window ids, percentages, and
500
- optional reset/duration fields; hosts own labels, polling, persistence, stale-data policy, alert
503
+ optional reset/duration fields. A model-scoped window (Claude's `seven-day-<model>`) carries
504
+ `models`, the lowercase model id substrings it limits; absent means every model of the account.
505
+ Hosts own labels, polling, persistence, stale-data policy, alert
501
506
  thresholds, billing interpretation, and UI. Configure `requestTimeoutMs` at the server integration
502
507
  boundary. Each fetcher defaults to its exported URL constant; the optional `url` override is only
503
508
  for a trusted proxy or local emulator, because the credential is sent to it. `FetchHttpClient.layer` is configured for manual
@@ -34,6 +34,12 @@ declare const ProviderErrorInfo_base: Schema.Class<ProviderErrorInfo, Schema.Str
34
34
  readonly status: Schema.optional<Schema.Number>;
35
35
  readonly providerCode: Schema.optional<Schema.String>;
36
36
  readonly retryAfterMs: Schema.optional<Schema.Number>;
37
+ /**
38
+ * When an exhausted subscription quota resets (epoch milliseconds), read from the provider's
39
+ * quota signal (Claude unified rate-limit headers, Codex `usage_limit_reached`). Present only on
40
+ * quota exhaustion, never on transient rate limits; account pools cool the account down until it.
41
+ */
42
+ readonly quotaResetsAtMs: Schema.optional<Schema.Number>;
37
43
  readonly stream: Schema.optional<typeof ProviderStreamDiagnostics>;
38
44
  }>, {}>;
39
45
  declare class ProviderErrorInfo extends ProviderErrorInfo_base {}
@@ -1 +1 @@
1
- {"version":3,"file":"event.d.mts","names":[],"sources":["../../src/protocol/event.ts"],"mappings":";;;;;;cAgCa,cAAA,EAAc,MAAA,CA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sBAAA,SAAA,kBAAA,SAAA,kBAAA,SAAA,eAAA,SAAA,iBAAA;AAAA,KA0CX,UAAA,UAAoB,UAAA,CAAW,IAAI;AAAA,KAEnC,kBAAA,GAAqB,OAAO,CACtC,UAAA;EAAA,SACW,IAAA;AAAA;AAAA,cAGA,oBAAA,GAAwB,KAAA,EAAO,UAAA,KAAa,KAAA,IAAS,kBAGjB"}
@@ -78,6 +78,12 @@ var ProviderErrorInfo = class extends Schema$1.Class("ProviderErrorInfo")({
78
78
  status: Schema$1.optional(Schema$1.Number),
79
79
  providerCode: Schema$1.optional(Schema$1.String),
80
80
  retryAfterMs: Schema$1.optional(Schema$1.Number),
81
+ /**
82
+ * When an exhausted subscription quota resets (epoch milliseconds), read from the provider's
83
+ * quota signal (Claude unified rate-limit headers, Codex `usage_limit_reached`). Present only on
84
+ * quota exhaustion, never on transient rate limits; account pools cool the account down until it.
85
+ */
86
+ quotaResetsAtMs: Schema$1.optional(Schema$1.Number),
81
87
  stream: Schema$1.optional(ProviderStreamDiagnostics)
82
88
  }) {};
83
89
  var AgentStart = class extends Schema$1.TaggedClass()("AgentStart", { ...EventIdentity }) {};
@@ -1 +1 @@
1
- {"version":3,"file":"event.mjs","names":["Schema"],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { Match, Predicate } from 'effect'\nimport {\n AssistantAgentMessage,\n AgentMessage,\n AssistantReasoningReplay,\n UserMessage\n} from './message.ts'\nimport {\n HitlRequest,\n InputRequest,\n InputResponse,\n InteractionRequest,\n InteractionResponse,\n QuestionAnswer,\n QuestionRequest,\n QuestionResponse,\n ToolApprovalRequest,\n ToolApprovalResponse,\n ToolCall,\n ToolResult,\n type HitlResponse\n} from './tool.ts'\nimport { AgentUsage } from './usage.ts'\n\nconst NonEmptyTrimmedString = Schema.Trimmed.pipe(Schema.check(Schema.isNonEmpty()))\n\nconst EventIdentity = {\n eventId: Schema.optional(NonEmptyTrimmedString),\n createdAtMs: Schema.optional(Schema.Number)\n}\n\nexport const SubagentStatus = Schema.Literals(['running', 'completed', 'error'])\n\nexport type SubagentStatus = typeof SubagentStatus.Type\n\nexport const AgentErrorCode = Schema.Literals([\n 'validation_error',\n 'provider_error',\n 'rate_limit',\n 'overloaded',\n 'context_overflow',\n 'invalid_response',\n 'tool_error',\n 'tool_denied',\n 'tool_timeout',\n 'store_error',\n 'aborted',\n 'session_not_found',\n 'conflict',\n 'unknown'\n])\n\nexport type AgentErrorCode = typeof AgentErrorCode.Type\n\n/** Why an `aborted` run stopped: `user` cancelled it, the `system` stopped it, or it hit `max_turns`. */\nexport const AgentAbortReason = Schema.Literals(['user', 'system', 'max_turns'])\n\nexport type AgentAbortReason = typeof AgentAbortReason.Type\n\nexport const ProviderFailureKind = Schema.Literals([\n 'rate_limit',\n 'overloaded',\n 'server_error',\n 'network',\n 'stream',\n 'auth',\n 'context_overflow',\n 'invalid_response',\n 'unknown'\n])\n\nexport type ProviderFailureKind = typeof ProviderFailureKind.Type\n\nexport const ProviderStreamProtocol = Schema.Literals(['chat-completions', 'messages', 'responses'])\n\nexport type ProviderStreamProtocol = typeof ProviderStreamProtocol.Type\n\n/** `unknown` means no Content-Type header was present. */\nexport const ProviderStreamResponseFormat = Schema.Literals(['sse', 'json', 'other', 'unknown'])\n\nexport type ProviderStreamResponseFormat = typeof ProviderStreamResponseFormat.Type\n\n/** Stream failure metadata; never retain transcript content, raw headers, or body fragments. */\nexport class ProviderStreamDiagnostics extends Schema.Class<ProviderStreamDiagnostics>(\n 'ProviderStreamDiagnostics'\n)({\n protocol: ProviderStreamProtocol,\n responseFormat: ProviderStreamResponseFormat,\n /** Bytes received from HTTP body chunks before text decoding. */\n receivedBytes: Schema.Natural,\n /** Undelivered tail characters pending in the SSE buffer, in UTF-16 code units. */\n bufferedChars: Schema.Natural,\n /** Whether text or reasoning output was actually emitted to the consumer. */\n outputStarted: Schema.Boolean,\n /** Whether a terminal SSE frame ([DONE] or a processed finish reason) was seen. */\n terminalSeen: Schema.Boolean\n}) {}\n\nexport class ProviderErrorInfo extends Schema.Class<ProviderErrorInfo>('ProviderErrorInfo')({\n provider: NonEmptyTrimmedString,\n kind: ProviderFailureKind,\n status: Schema.optional(Schema.Number),\n providerCode: Schema.optional(Schema.String),\n retryAfterMs: Schema.optional(Schema.Number),\n stream: Schema.optional(ProviderStreamDiagnostics)\n}) {}\n\nexport class AgentStart extends Schema.TaggedClass<AgentStart>()('AgentStart', {\n ...EventIdentity\n}) {}\n\nexport class AgentError extends Schema.TaggedClass<AgentError>()('AgentError', {\n ...EventIdentity,\n code: AgentErrorCode,\n message: Schema.String,\n retryable: Schema.Boolean,\n provider: Schema.optional(ProviderErrorInfo),\n /** Set with code `aborted`; absent on events recorded before it existed. */\n abortReason: Schema.optional(AgentAbortReason)\n}) {}\n\nexport class AgentEnd extends Schema.TaggedClass<AgentEnd>()('AgentEnd', {\n ...EventIdentity,\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n}) {}\n\nexport class AgentAwaitingInput extends Schema.TaggedClass<AgentAwaitingInput>()(\n 'AgentAwaitingInput',\n {\n ...EventIdentity,\n requests: Schema.NonEmptyArray(HitlRequest),\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n }\n) {}\n\nexport class UsageUpdate extends Schema.TaggedClass<UsageUpdate>()('UsageUpdate', {\n ...EventIdentity,\n usage: AgentUsage\n}) {}\n\nexport class AgentRetry extends Schema.TaggedClass<AgentRetry>()('AgentRetry', {\n ...EventIdentity,\n attempt: Schema.Number,\n reason: AgentErrorCode,\n delayMs: Schema.Number,\n message: Schema.String,\n provider: Schema.optional(ProviderErrorInfo)\n}) {}\n\nexport class CompactionStart extends Schema.TaggedClass<CompactionStart>()('CompactionStart', {\n ...EventIdentity,\n strategy: Schema.String\n}) {}\n\nexport class CompactionEnd extends Schema.TaggedClass<CompactionEnd>()('CompactionEnd', {\n ...EventIdentity,\n strategy: Schema.String,\n beforeTokens: Schema.optional(Schema.Number),\n afterTokens: Schema.optional(Schema.Number)\n}) {}\n\nexport class TurnStart extends Schema.TaggedClass<TurnStart>()('TurnStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class TurnEnd extends Schema.TaggedClass<TurnEnd>()('TurnEnd', {\n ...EventIdentity,\n turn: Schema.Number,\n reason: Schema.Literals(['stop', 'tool_use'])\n}) {}\n\nexport class LLMStreamStart extends Schema.TaggedClass<LLMStreamStart>()('LLMStreamStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class LLMTextDelta extends Schema.TaggedClass<LLMTextDelta>()('LLMTextDelta', {\n ...EventIdentity,\n text: Schema.String,\n textSoFar: Schema.optional(Schema.String)\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String,\n reasoningSoFar: Schema.optional(Schema.String)\n }\n) {}\n\n/**\n * Closes the reasoning block streamed so far with the provider state that replays it (see\n * `AssistantReasoningReplay`), so a fold of the event stream rebuilds the same assistant message.\n * Opaque: UIs show nothing for it beyond ending the current reasoning block.\n */\nexport class LLMReasoningReplay extends Schema.TaggedClass<LLMReasoningReplay>()(\n 'LLMReasoningReplay',\n {\n ...EventIdentity,\n replay: AssistantReasoningReplay\n }\n) {}\n\nexport class ToolInputStart extends Schema.TaggedClass<ToolInputStart>()('ToolInputStart', {\n ...EventIdentity,\n id: Schema.String,\n name: Schema.optional(Schema.String)\n}) {}\n\nexport class ToolInputDelta extends Schema.TaggedClass<ToolInputDelta>()('ToolInputDelta', {\n ...EventIdentity,\n id: Schema.String,\n delta: Schema.String\n}) {}\n\nexport class ToolInputEnd extends Schema.TaggedClass<ToolInputEnd>()('ToolInputEnd', {\n ...EventIdentity,\n call: ToolCall\n}) {}\n\nexport class ToolApprovalRequested extends Schema.TaggedClass<ToolApprovalRequested>()(\n 'ToolApprovalRequested',\n {\n ...EventIdentity,\n call: ToolCall,\n request: Schema.optional(ToolApprovalRequest)\n }\n) {}\n\nexport class ToolApprovalGranted extends Schema.TaggedClass<ToolApprovalGranted>()(\n 'ToolApprovalGranted',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class ToolApprovalDenied extends Schema.TaggedClass<ToolApprovalDenied>()(\n 'ToolApprovalDenied',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n reason: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class QuestionRequested extends Schema.TaggedClass<QuestionRequested>()(\n 'QuestionRequested',\n {\n ...EventIdentity,\n request: QuestionRequest\n }\n) {}\n\nexport class QuestionAnswered extends Schema.TaggedClass<QuestionAnswered>()('QuestionAnswered', {\n ...EventIdentity,\n response: QuestionResponse\n}) {}\n\nexport class QuestionCancelled extends Schema.TaggedClass<QuestionCancelled>()(\n 'QuestionCancelled',\n {\n ...EventIdentity,\n response: QuestionResponse\n }\n) {}\n\nexport class InputRequested extends Schema.TaggedClass<InputRequested>()('InputRequested', {\n ...EventIdentity,\n request: InputRequest\n}) {}\n\nexport class InputSubmitted extends Schema.TaggedClass<InputSubmitted>()('InputSubmitted', {\n ...EventIdentity,\n response: InputResponse\n}) {}\n\nexport class InputCancelled extends Schema.TaggedClass<InputCancelled>()('InputCancelled', {\n ...EventIdentity,\n response: InputResponse\n}) {}\n\nexport class InteractionRequested extends Schema.TaggedClass<InteractionRequested>()(\n 'InteractionRequested',\n {\n ...EventIdentity,\n request: InteractionRequest\n }\n) {}\n\n/** Admission marker: the person submitted an action with final values. Not terminal\n * success and never a synthetic tool result; only a server execution result\n * settles the tool call.\n */\nexport class InteractionSubmitted extends Schema.TaggedClass<InteractionSubmitted>()(\n 'InteractionSubmitted',\n {\n ...EventIdentity,\n response: InteractionResponse\n }\n) {}\n\nexport class InteractionCancelled extends Schema.TaggedClass<InteractionCancelled>()(\n 'InteractionCancelled',\n {\n ...EventIdentity,\n response: InteractionResponse\n }\n) {}\n\nexport class LLMStreamEnd extends Schema.TaggedClass<LLMStreamEnd>()('LLMStreamEnd', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class UserMessageEvent extends Schema.TaggedClass<UserMessageEvent>()('UserMessage', {\n ...EventIdentity,\n message: UserMessage\n}) {}\n\nexport class AssistantMessageEvent extends Schema.TaggedClass<AssistantMessageEvent>()(\n 'AssistantMessage',\n {\n ...EventIdentity,\n message: AssistantAgentMessage\n }\n) {}\n\nexport class ToolExecutionStarted extends Schema.TaggedClass<ToolExecutionStarted>()(\n 'ToolExecutionStarted',\n {\n ...EventIdentity,\n call: ToolCall\n }\n) {}\n\n/** The host owns outstanding execution; this event only settles admission. */\nexport class ToolExecutionAccepted extends Schema.TaggedClass<ToolExecutionAccepted>()(\n 'ToolExecutionAccepted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionCompleted extends Schema.TaggedClass<ToolExecutionCompleted>()(\n 'ToolExecutionCompleted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionError extends Schema.TaggedClass<ToolExecutionError>()(\n 'ToolExecutionError',\n {\n ...EventIdentity,\n call: ToolCall,\n message: Schema.String,\n code: AgentErrorCode\n }\n) {}\n\nexport class ProviderToolResult extends Schema.TaggedClass<ProviderToolResult>()(\n 'ProviderToolResult',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class SubagentStarted extends Schema.TaggedClass<SubagentStarted>()('SubagentStarted', {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String\n}) {}\n\nexport class SubagentCompleted extends Schema.TaggedClass<SubagentCompleted>()(\n 'SubagentCompleted',\n {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String,\n status: SubagentStatus,\n durationMs: Schema.Number,\n summary: Schema.optional(Schema.String)\n }\n) {}\n\nexport const makeSubagentRunId = (parentToolCallId: string) => `subagent:${parentToolCallId}`\n\nconst ownStringField = (input: unknown, key: string): string | undefined => {\n if (!Predicate.isObjectOrArray(input)) {\n return undefined\n }\n\n const value: unknown = Object.getOwnPropertyDescriptor(input, key)?.value\n\n return Predicate.isString(value) ? value : undefined\n}\n\nconst isSubagentResultOfType = (callId: string, result: ToolResult, type: string) =>\n ownStringField(result.structuredContent, 'type') === type &&\n ownStringField(result.structuredContent, 'subagent_run_id') === makeSubagentRunId(callId)\n\n/**\n * The `subagent` call's result acknowledges background work (`makeSubagentAcceptedToolResult`):\n * the call completed, the child did not.\n */\nexport const isSubagentAcceptedToolResult = (callId: string, result: ToolResult) =>\n isSubagentResultOfType(callId, result, 'subagent_accepted') &&\n ownStringField(result.structuredContent, 'status') === 'accepted'\n\n/** A host observation of the subagent started by `callId`; never a child completion. */\nexport const isSubagentObservationToolResult = (callId: string, result: ToolResult) =>\n isSubagentResultOfType(callId, result, 'subagent_observation')\n\ntype QuestionAnswerCopyFields = {\n questionId: QuestionAnswer['questionId']\n optionIds?: QuestionAnswer['optionIds']\n customAnswer?: QuestionAnswer['customAnswer']\n}\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make(\n (() => {\n const fields: QuestionAnswerCopyFields = {\n questionId: answer.questionId\n }\n\n if (answer.optionIds !== undefined) {\n fields.optionIds = [...answer.optionIds]\n }\n\n if (answer.customAnswer !== undefined) {\n fields.customAnswer = answer.customAnswer\n }\n\n return fields\n })()\n )\n\ntype InputResponseCopyFields = {\n requestId: InputResponse['requestId']\n toolCallId: InputResponse['toolCallId']\n outcome: InputResponse['outcome']\n source: InputResponse['source']\n data?: InputResponse['data']\n reason?: InputResponse['reason']\n}\n\nconst inputResponseValue = (response: InputResponse) =>\n InputResponse.make(\n (() => {\n const fields: InputResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.data !== undefined) {\n fields.data = response.data\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype QuestionResponseCopyFields = {\n requestId: QuestionResponse['requestId']\n toolCallId: QuestionResponse['toolCallId']\n outcome: QuestionResponse['outcome']\n source: QuestionResponse['source']\n answers?: QuestionResponse['answers']\n reason?: QuestionResponse['reason']\n}\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make(\n (() => {\n const fields: QuestionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.answers !== undefined) {\n fields.answers = response.answers.map(answer => questionAnswerValue(answer))\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype ToolApprovalResponseCopyFields = {\n requestId: ToolApprovalResponse['requestId']\n toolCallId: ToolApprovalResponse['toolCallId']\n decision: ToolApprovalResponse['decision']\n source: ToolApprovalResponse['source']\n reason?: ToolApprovalResponse['reason']\n}\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make(\n (() => {\n const fields: ToolApprovalResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype InteractionResponseCopyFields = {\n requestId: InteractionResponse['requestId']\n toolCallId: InteractionResponse['toolCallId']\n outcome: InteractionResponse['outcome']\n source: InteractionResponse['source']\n actionId?: InteractionResponse['actionId']\n data?: InteractionResponse['data']\n reason?: InteractionResponse['reason']\n}\n\nconst interactionResponseValue = (response: InteractionResponse) =>\n InteractionResponse.make(\n (() => {\n const fields: InteractionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.actionId !== undefined) {\n fields.actionId = response.actionId\n }\n\n if (response.data !== undefined) {\n fields.data = response.data\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent =>\n Match.value(response).pipe(\n Match.tag('QuestionResponse', current => {\n const responseValue = questionResponseValue(current)\n\n return current.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }),\n Match.tag('ToolApprovalResponse', current => {\n const responseValue = toolApprovalResponseValue(current)\n\n return current.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: current.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: current.toolCallId,\n reason: current.reason ?? 'Denied by user',\n response: responseValue\n })\n }),\n Match.tag('InputResponse', current => {\n const responseValue = inputResponseValue(current)\n\n return current.outcome === 'submitted'\n ? InputSubmitted.make({ response: responseValue })\n : InputCancelled.make({ response: responseValue })\n }),\n Match.tag('InteractionResponse', current => {\n const responseValue = interactionResponseValue(current)\n\n return current.outcome === 'submitted'\n ? InteractionSubmitted.make({ response: responseValue })\n : InteractionCancelled.make({ response: responseValue })\n }),\n Match.exhaustive\n )\n\nexport const AgentEvent = Schema.Union([\n AgentStart,\n AgentError,\n AgentEnd,\n AgentAwaitingInput,\n UsageUpdate,\n AgentRetry,\n CompactionStart,\n CompactionEnd,\n TurnStart,\n TurnEnd,\n LLMStreamStart,\n LLMTextDelta,\n LLMReasoningDelta,\n LLMReasoningReplay,\n ToolInputStart,\n ToolInputDelta,\n ToolInputEnd,\n LLMStreamEnd,\n UserMessageEvent,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n InputRequested,\n InputSubmitted,\n InputCancelled,\n InteractionRequested,\n InteractionSubmitted,\n InteractionCancelled,\n ToolExecutionStarted,\n ToolExecutionAccepted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\n\nexport type AgentEvent = typeof AgentEvent.Type\n\nexport type TerminalAgentEvent = Extract<\n AgentEvent,\n { readonly _tag: 'AgentEnd' | 'AgentError' | 'AgentAwaitingInput' }\n>\n\nexport const isTerminalAgentEvent = (event: AgentEvent): event is TerminalAgentEvent =>\n Predicate.isTagged(event, 'AgentEnd') ||\n Predicate.isTagged(event, 'AgentError') ||\n Predicate.isTagged(event, 'AgentAwaitingInput')\n"],"mappings":";;;;;;AAyBA,MAAM,wBAAwBA,SAAO,QAAQ,KAAKA,SAAO,MAAMA,SAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAASA,SAAO,SAAS,qBAAqB;CAC9C,aAAaA,SAAO,SAASA,SAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiBA,SAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAI/E,MAAa,iBAAiBA,SAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAKD,MAAa,mBAAmBA,SAAO,SAAS;CAAC;CAAQ;CAAU;AAAW,CAAC;AAI/E,MAAa,sBAAsBA,SAAO,SAAS;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAa,yBAAyBA,SAAO,SAAS;CAAC;CAAoB;CAAY;AAAW,CAAC;;AAKnG,MAAa,+BAA+BA,SAAO,SAAS;CAAC;CAAO;CAAQ;CAAS;AAAS,CAAC;;AAK/F,IAAa,4BAAb,cAA+CA,SAAO,MACpD,2BACF,EAAE;CACA,UAAU;CACV,gBAAgB;;CAEhB,eAAeA,SAAO;;CAEtB,eAAeA,SAAO;;CAEtB,eAAeA,SAAO;;CAEtB,cAAcA,SAAO;AACvB,CAAC,EAAE,C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AAwB,YAAW;CAC3C,MAAM,gBAAgB,0BAA0B,OAAO;CAEvD,OAAO,QAAQ,aAAa,aACxB,oBAAoB,KAAK;EAAE,YAAY,QAAQ;EAAY,UAAU;CAAc,CAAC,IACpF,mBAAmB,KAAK;EACtB,YAAY,QAAQ;EACpB,QAAQ,QAAQ,UAAU;EAC1B,UAAU;CACZ,CAAC;AACP,CAAC,GACD,MAAM,IAAI,kBAAiB,YAAW;CACpC,MAAM,gBAAgB,mBAAmB,OAAO;CAEhD,OAAO,QAAQ,YAAY,cACvB,eAAe,KAAK,EAAE,UAAU,cAAc,CAAC,IAC/C,eAAe,KAAK,EAAE,UAAU,cAAc,CAAC;AACrD,CAAC,GACD,MAAM,IAAI,wBAAuB,YAAW;CAC1C,MAAM,gBAAgB,yBAAyB,OAAO;CAEtD,OAAO,QAAQ,YAAY,cACvB,qBAAqB,KAAK,EAAE,UAAU,cAAc,CAAC,IACrD,qBAAqB,KAAK,EAAE,UAAU,cAAc,CAAC;AAC3D,CAAC,GACD,MAAM,UACR;AAEF,MAAa,aAAaA,SAAO,MAAM;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AASD,MAAa,wBAAwB,UACnC,UAAU,SAAS,OAAO,UAAU,KACpC,UAAU,SAAS,OAAO,YAAY,KACtC,UAAU,SAAS,OAAO,oBAAoB"}
1
+ {"version":3,"file":"event.mjs","names":["Schema"],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { Match, Predicate } from 'effect'\nimport {\n AssistantAgentMessage,\n AgentMessage,\n AssistantReasoningReplay,\n UserMessage\n} from './message.ts'\nimport {\n HitlRequest,\n InputRequest,\n InputResponse,\n InteractionRequest,\n InteractionResponse,\n QuestionAnswer,\n QuestionRequest,\n QuestionResponse,\n ToolApprovalRequest,\n ToolApprovalResponse,\n ToolCall,\n ToolResult,\n type HitlResponse\n} from './tool.ts'\nimport { AgentUsage } from './usage.ts'\n\nconst NonEmptyTrimmedString = Schema.Trimmed.pipe(Schema.check(Schema.isNonEmpty()))\n\nconst EventIdentity = {\n eventId: Schema.optional(NonEmptyTrimmedString),\n createdAtMs: Schema.optional(Schema.Number)\n}\n\nexport const SubagentStatus = Schema.Literals(['running', 'completed', 'error'])\n\nexport type SubagentStatus = typeof SubagentStatus.Type\n\nexport const AgentErrorCode = Schema.Literals([\n 'validation_error',\n 'provider_error',\n 'rate_limit',\n 'overloaded',\n 'context_overflow',\n 'invalid_response',\n 'tool_error',\n 'tool_denied',\n 'tool_timeout',\n 'store_error',\n 'aborted',\n 'session_not_found',\n 'conflict',\n 'unknown'\n])\n\nexport type AgentErrorCode = typeof AgentErrorCode.Type\n\n/** Why an `aborted` run stopped: `user` cancelled it, the `system` stopped it, or it hit `max_turns`. */\nexport const AgentAbortReason = Schema.Literals(['user', 'system', 'max_turns'])\n\nexport type AgentAbortReason = typeof AgentAbortReason.Type\n\nexport const ProviderFailureKind = Schema.Literals([\n 'rate_limit',\n 'overloaded',\n 'server_error',\n 'network',\n 'stream',\n 'auth',\n 'context_overflow',\n 'invalid_response',\n 'unknown'\n])\n\nexport type ProviderFailureKind = typeof ProviderFailureKind.Type\n\nexport const ProviderStreamProtocol = Schema.Literals(['chat-completions', 'messages', 'responses'])\n\nexport type ProviderStreamProtocol = typeof ProviderStreamProtocol.Type\n\n/** `unknown` means no Content-Type header was present. */\nexport const ProviderStreamResponseFormat = Schema.Literals(['sse', 'json', 'other', 'unknown'])\n\nexport type ProviderStreamResponseFormat = typeof ProviderStreamResponseFormat.Type\n\n/** Stream failure metadata; never retain transcript content, raw headers, or body fragments. */\nexport class ProviderStreamDiagnostics extends Schema.Class<ProviderStreamDiagnostics>(\n 'ProviderStreamDiagnostics'\n)({\n protocol: ProviderStreamProtocol,\n responseFormat: ProviderStreamResponseFormat,\n /** Bytes received from HTTP body chunks before text decoding. */\n receivedBytes: Schema.Natural,\n /** Undelivered tail characters pending in the SSE buffer, in UTF-16 code units. */\n bufferedChars: Schema.Natural,\n /** Whether text or reasoning output was actually emitted to the consumer. */\n outputStarted: Schema.Boolean,\n /** Whether a terminal SSE frame ([DONE] or a processed finish reason) was seen. */\n terminalSeen: Schema.Boolean\n}) {}\n\nexport class ProviderErrorInfo extends Schema.Class<ProviderErrorInfo>('ProviderErrorInfo')({\n provider: NonEmptyTrimmedString,\n kind: ProviderFailureKind,\n status: Schema.optional(Schema.Number),\n providerCode: Schema.optional(Schema.String),\n retryAfterMs: Schema.optional(Schema.Number),\n /**\n * When an exhausted subscription quota resets (epoch milliseconds), read from the provider's\n * quota signal (Claude unified rate-limit headers, Codex `usage_limit_reached`). Present only on\n * quota exhaustion, never on transient rate limits; account pools cool the account down until it.\n */\n quotaResetsAtMs: Schema.optional(Schema.Number),\n stream: Schema.optional(ProviderStreamDiagnostics)\n}) {}\n\nexport class AgentStart extends Schema.TaggedClass<AgentStart>()('AgentStart', {\n ...EventIdentity\n}) {}\n\nexport class AgentError extends Schema.TaggedClass<AgentError>()('AgentError', {\n ...EventIdentity,\n code: AgentErrorCode,\n message: Schema.String,\n retryable: Schema.Boolean,\n provider: Schema.optional(ProviderErrorInfo),\n /** Set with code `aborted`; absent on events recorded before it existed. */\n abortReason: Schema.optional(AgentAbortReason)\n}) {}\n\nexport class AgentEnd extends Schema.TaggedClass<AgentEnd>()('AgentEnd', {\n ...EventIdentity,\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n}) {}\n\nexport class AgentAwaitingInput extends Schema.TaggedClass<AgentAwaitingInput>()(\n 'AgentAwaitingInput',\n {\n ...EventIdentity,\n requests: Schema.NonEmptyArray(HitlRequest),\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n }\n) {}\n\nexport class UsageUpdate extends Schema.TaggedClass<UsageUpdate>()('UsageUpdate', {\n ...EventIdentity,\n usage: AgentUsage\n}) {}\n\nexport class AgentRetry extends Schema.TaggedClass<AgentRetry>()('AgentRetry', {\n ...EventIdentity,\n attempt: Schema.Number,\n reason: AgentErrorCode,\n delayMs: Schema.Number,\n message: Schema.String,\n provider: Schema.optional(ProviderErrorInfo)\n}) {}\n\nexport class CompactionStart extends Schema.TaggedClass<CompactionStart>()('CompactionStart', {\n ...EventIdentity,\n strategy: Schema.String\n}) {}\n\nexport class CompactionEnd extends Schema.TaggedClass<CompactionEnd>()('CompactionEnd', {\n ...EventIdentity,\n strategy: Schema.String,\n beforeTokens: Schema.optional(Schema.Number),\n afterTokens: Schema.optional(Schema.Number)\n}) {}\n\nexport class TurnStart extends Schema.TaggedClass<TurnStart>()('TurnStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class TurnEnd extends Schema.TaggedClass<TurnEnd>()('TurnEnd', {\n ...EventIdentity,\n turn: Schema.Number,\n reason: Schema.Literals(['stop', 'tool_use'])\n}) {}\n\nexport class LLMStreamStart extends Schema.TaggedClass<LLMStreamStart>()('LLMStreamStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class LLMTextDelta extends Schema.TaggedClass<LLMTextDelta>()('LLMTextDelta', {\n ...EventIdentity,\n text: Schema.String,\n textSoFar: Schema.optional(Schema.String)\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String,\n reasoningSoFar: Schema.optional(Schema.String)\n }\n) {}\n\n/**\n * Closes the reasoning block streamed so far with the provider state that replays it (see\n * `AssistantReasoningReplay`), so a fold of the event stream rebuilds the same assistant message.\n * Opaque: UIs show nothing for it beyond ending the current reasoning block.\n */\nexport class LLMReasoningReplay extends Schema.TaggedClass<LLMReasoningReplay>()(\n 'LLMReasoningReplay',\n {\n ...EventIdentity,\n replay: AssistantReasoningReplay\n }\n) {}\n\nexport class ToolInputStart extends Schema.TaggedClass<ToolInputStart>()('ToolInputStart', {\n ...EventIdentity,\n id: Schema.String,\n name: Schema.optional(Schema.String)\n}) {}\n\nexport class ToolInputDelta extends Schema.TaggedClass<ToolInputDelta>()('ToolInputDelta', {\n ...EventIdentity,\n id: Schema.String,\n delta: Schema.String\n}) {}\n\nexport class ToolInputEnd extends Schema.TaggedClass<ToolInputEnd>()('ToolInputEnd', {\n ...EventIdentity,\n call: ToolCall\n}) {}\n\nexport class ToolApprovalRequested extends Schema.TaggedClass<ToolApprovalRequested>()(\n 'ToolApprovalRequested',\n {\n ...EventIdentity,\n call: ToolCall,\n request: Schema.optional(ToolApprovalRequest)\n }\n) {}\n\nexport class ToolApprovalGranted extends Schema.TaggedClass<ToolApprovalGranted>()(\n 'ToolApprovalGranted',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class ToolApprovalDenied extends Schema.TaggedClass<ToolApprovalDenied>()(\n 'ToolApprovalDenied',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n reason: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class QuestionRequested extends Schema.TaggedClass<QuestionRequested>()(\n 'QuestionRequested',\n {\n ...EventIdentity,\n request: QuestionRequest\n }\n) {}\n\nexport class QuestionAnswered extends Schema.TaggedClass<QuestionAnswered>()('QuestionAnswered', {\n ...EventIdentity,\n response: QuestionResponse\n}) {}\n\nexport class QuestionCancelled extends Schema.TaggedClass<QuestionCancelled>()(\n 'QuestionCancelled',\n {\n ...EventIdentity,\n response: QuestionResponse\n }\n) {}\n\nexport class InputRequested extends Schema.TaggedClass<InputRequested>()('InputRequested', {\n ...EventIdentity,\n request: InputRequest\n}) {}\n\nexport class InputSubmitted extends Schema.TaggedClass<InputSubmitted>()('InputSubmitted', {\n ...EventIdentity,\n response: InputResponse\n}) {}\n\nexport class InputCancelled extends Schema.TaggedClass<InputCancelled>()('InputCancelled', {\n ...EventIdentity,\n response: InputResponse\n}) {}\n\nexport class InteractionRequested extends Schema.TaggedClass<InteractionRequested>()(\n 'InteractionRequested',\n {\n ...EventIdentity,\n request: InteractionRequest\n }\n) {}\n\n/** Admission marker: the person submitted an action with final values. Not terminal\n * success and never a synthetic tool result; only a server execution result\n * settles the tool call.\n */\nexport class InteractionSubmitted extends Schema.TaggedClass<InteractionSubmitted>()(\n 'InteractionSubmitted',\n {\n ...EventIdentity,\n response: InteractionResponse\n }\n) {}\n\nexport class InteractionCancelled extends Schema.TaggedClass<InteractionCancelled>()(\n 'InteractionCancelled',\n {\n ...EventIdentity,\n response: InteractionResponse\n }\n) {}\n\nexport class LLMStreamEnd extends Schema.TaggedClass<LLMStreamEnd>()('LLMStreamEnd', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class UserMessageEvent extends Schema.TaggedClass<UserMessageEvent>()('UserMessage', {\n ...EventIdentity,\n message: UserMessage\n}) {}\n\nexport class AssistantMessageEvent extends Schema.TaggedClass<AssistantMessageEvent>()(\n 'AssistantMessage',\n {\n ...EventIdentity,\n message: AssistantAgentMessage\n }\n) {}\n\nexport class ToolExecutionStarted extends Schema.TaggedClass<ToolExecutionStarted>()(\n 'ToolExecutionStarted',\n {\n ...EventIdentity,\n call: ToolCall\n }\n) {}\n\n/** The host owns outstanding execution; this event only settles admission. */\nexport class ToolExecutionAccepted extends Schema.TaggedClass<ToolExecutionAccepted>()(\n 'ToolExecutionAccepted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionCompleted extends Schema.TaggedClass<ToolExecutionCompleted>()(\n 'ToolExecutionCompleted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionError extends Schema.TaggedClass<ToolExecutionError>()(\n 'ToolExecutionError',\n {\n ...EventIdentity,\n call: ToolCall,\n message: Schema.String,\n code: AgentErrorCode\n }\n) {}\n\nexport class ProviderToolResult extends Schema.TaggedClass<ProviderToolResult>()(\n 'ProviderToolResult',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class SubagentStarted extends Schema.TaggedClass<SubagentStarted>()('SubagentStarted', {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String\n}) {}\n\nexport class SubagentCompleted extends Schema.TaggedClass<SubagentCompleted>()(\n 'SubagentCompleted',\n {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String,\n status: SubagentStatus,\n durationMs: Schema.Number,\n summary: Schema.optional(Schema.String)\n }\n) {}\n\nexport const makeSubagentRunId = (parentToolCallId: string) => `subagent:${parentToolCallId}`\n\nconst ownStringField = (input: unknown, key: string): string | undefined => {\n if (!Predicate.isObjectOrArray(input)) {\n return undefined\n }\n\n const value: unknown = Object.getOwnPropertyDescriptor(input, key)?.value\n\n return Predicate.isString(value) ? value : undefined\n}\n\nconst isSubagentResultOfType = (callId: string, result: ToolResult, type: string) =>\n ownStringField(result.structuredContent, 'type') === type &&\n ownStringField(result.structuredContent, 'subagent_run_id') === makeSubagentRunId(callId)\n\n/**\n * The `subagent` call's result acknowledges background work (`makeSubagentAcceptedToolResult`):\n * the call completed, the child did not.\n */\nexport const isSubagentAcceptedToolResult = (callId: string, result: ToolResult) =>\n isSubagentResultOfType(callId, result, 'subagent_accepted') &&\n ownStringField(result.structuredContent, 'status') === 'accepted'\n\n/** A host observation of the subagent started by `callId`; never a child completion. */\nexport const isSubagentObservationToolResult = (callId: string, result: ToolResult) =>\n isSubagentResultOfType(callId, result, 'subagent_observation')\n\ntype QuestionAnswerCopyFields = {\n questionId: QuestionAnswer['questionId']\n optionIds?: QuestionAnswer['optionIds']\n customAnswer?: QuestionAnswer['customAnswer']\n}\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make(\n (() => {\n const fields: QuestionAnswerCopyFields = {\n questionId: answer.questionId\n }\n\n if (answer.optionIds !== undefined) {\n fields.optionIds = [...answer.optionIds]\n }\n\n if (answer.customAnswer !== undefined) {\n fields.customAnswer = answer.customAnswer\n }\n\n return fields\n })()\n )\n\ntype InputResponseCopyFields = {\n requestId: InputResponse['requestId']\n toolCallId: InputResponse['toolCallId']\n outcome: InputResponse['outcome']\n source: InputResponse['source']\n data?: InputResponse['data']\n reason?: InputResponse['reason']\n}\n\nconst inputResponseValue = (response: InputResponse) =>\n InputResponse.make(\n (() => {\n const fields: InputResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.data !== undefined) {\n fields.data = response.data\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype QuestionResponseCopyFields = {\n requestId: QuestionResponse['requestId']\n toolCallId: QuestionResponse['toolCallId']\n outcome: QuestionResponse['outcome']\n source: QuestionResponse['source']\n answers?: QuestionResponse['answers']\n reason?: QuestionResponse['reason']\n}\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make(\n (() => {\n const fields: QuestionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.answers !== undefined) {\n fields.answers = response.answers.map(answer => questionAnswerValue(answer))\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype ToolApprovalResponseCopyFields = {\n requestId: ToolApprovalResponse['requestId']\n toolCallId: ToolApprovalResponse['toolCallId']\n decision: ToolApprovalResponse['decision']\n source: ToolApprovalResponse['source']\n reason?: ToolApprovalResponse['reason']\n}\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make(\n (() => {\n const fields: ToolApprovalResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype InteractionResponseCopyFields = {\n requestId: InteractionResponse['requestId']\n toolCallId: InteractionResponse['toolCallId']\n outcome: InteractionResponse['outcome']\n source: InteractionResponse['source']\n actionId?: InteractionResponse['actionId']\n data?: InteractionResponse['data']\n reason?: InteractionResponse['reason']\n}\n\nconst interactionResponseValue = (response: InteractionResponse) =>\n InteractionResponse.make(\n (() => {\n const fields: InteractionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.actionId !== undefined) {\n fields.actionId = response.actionId\n }\n\n if (response.data !== undefined) {\n fields.data = response.data\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent =>\n Match.value(response).pipe(\n Match.tag('QuestionResponse', current => {\n const responseValue = questionResponseValue(current)\n\n return current.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }),\n Match.tag('ToolApprovalResponse', current => {\n const responseValue = toolApprovalResponseValue(current)\n\n return current.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: current.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: current.toolCallId,\n reason: current.reason ?? 'Denied by user',\n response: responseValue\n })\n }),\n Match.tag('InputResponse', current => {\n const responseValue = inputResponseValue(current)\n\n return current.outcome === 'submitted'\n ? InputSubmitted.make({ response: responseValue })\n : InputCancelled.make({ response: responseValue })\n }),\n Match.tag('InteractionResponse', current => {\n const responseValue = interactionResponseValue(current)\n\n return current.outcome === 'submitted'\n ? InteractionSubmitted.make({ response: responseValue })\n : InteractionCancelled.make({ response: responseValue })\n }),\n Match.exhaustive\n )\n\nexport const AgentEvent = Schema.Union([\n AgentStart,\n AgentError,\n AgentEnd,\n AgentAwaitingInput,\n UsageUpdate,\n AgentRetry,\n CompactionStart,\n CompactionEnd,\n TurnStart,\n TurnEnd,\n LLMStreamStart,\n LLMTextDelta,\n LLMReasoningDelta,\n LLMReasoningReplay,\n ToolInputStart,\n ToolInputDelta,\n ToolInputEnd,\n LLMStreamEnd,\n UserMessageEvent,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n InputRequested,\n InputSubmitted,\n InputCancelled,\n InteractionRequested,\n InteractionSubmitted,\n InteractionCancelled,\n ToolExecutionStarted,\n ToolExecutionAccepted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\n\nexport type AgentEvent = typeof AgentEvent.Type\n\nexport type TerminalAgentEvent = Extract<\n AgentEvent,\n { readonly _tag: 'AgentEnd' | 'AgentError' | 'AgentAwaitingInput' }\n>\n\nexport const isTerminalAgentEvent = (event: AgentEvent): event is TerminalAgentEvent =>\n Predicate.isTagged(event, 'AgentEnd') ||\n Predicate.isTagged(event, 'AgentError') ||\n Predicate.isTagged(event, 'AgentAwaitingInput')\n"],"mappings":";;;;;;AAyBA,MAAM,wBAAwBA,SAAO,QAAQ,KAAKA,SAAO,MAAMA,SAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAASA,SAAO,SAAS,qBAAqB;CAC9C,aAAaA,SAAO,SAASA,SAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiBA,SAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAI/E,MAAa,iBAAiBA,SAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAKD,MAAa,mBAAmBA,SAAO,SAAS;CAAC;CAAQ;CAA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A;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AASD,MAAa,wBAAwB,UACnC,UAAU,SAAS,OAAO,UAAU,KACpC,UAAU,SAAS,OAAO,YAAY,KACtC,UAAU,SAAS,OAAO,oBAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"claude-usage-cases.d.mts","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-cases.ts"],"mappings":";;;;;;AAuCC;AAAA,cARY,kCAAA;AAAA,KAED,uCAAA;;;;;WAKD,KAAA,EAAO,gBAAgB;AAAA;AAAA,cACjC,0CAAA;;cAGY,qCAAA,SAA8C,0CAGiC;;KAGhF,2CAAA,GACR,UAAA,CAAW,UAAA,GACX,qCAAqC;AAAA,KAE7B,mCAAA,GACV,gCAAgC,CAAC,qCAAA;AAAA,cAOtB,gCAAA,EAAkC,mCAoB3C;;cAGS,oCAAA,EAAsC,aAAa,CAAC,mCAAA"}
1
+ {"version":3,"file":"claude-usage-cases.d.mts","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-cases.ts"],"mappings":";;;;;;AAwCC;AAAA,cARY,kCAAA;AAAA,KAED,uCAAA;;;;;WAKD,KAAA,EAAO,gBAAgB;AAAA;AAAA,cACjC,0CAAA;;cAGY,qCAAA,SAA8C,0CAGiC;;KAGhF,2CAAA,GACR,UAAA,CAAW,UAAA,GACX,qCAAqC;AAAA,KAE7B,mCAAA,GACV,gCAAgC,CAAC,qCAAA;AAAA,cA0DtB,gCAAA,EAAkC,mCAuB3C;;cAGS,oCAAA,EAAsC,aAAa,CAAC,mCAAA"}
@@ -2,7 +2,7 @@ import { anthropicClaudeProviderId } from "../claude.mjs";
2
2
  import { anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage } from "../usage.mjs";
3
3
  import { makeSubscriptionUsageConformanceCase, wireField, wireInstant, wirePercent } from "../../openai/conformance/subscription-usage-cases-internal.mjs";
4
4
  import { anthropicClaudeUsageSnapshotFixture } from "./claude-usage-snapshot.mjs";
5
- import { Context, Effect } from "effect";
5
+ import { Context, Effect, Predicate } from "effect";
6
6
  //#region src/providers/anthropic/conformance/claude-usage-cases.ts
7
7
  /**
8
8
  * Claude subscription-usage conformance case for `@yolk-sdk/conformance/runner`.
@@ -27,16 +27,41 @@ const claudeWindows = [{
27
27
  key: "seven_day",
28
28
  id: "seven-day"
29
29
  }];
30
+ /**
31
+ * Model-scoped weekly limits (`limits[]` entries with `kind: "weekly_scoped"` and a numeric
32
+ * `percent`), keyed by the lowercase model id or else the display name slugged; the first entry per
33
+ * model wins.
34
+ */
35
+ const scopedWireWindows = (body) => {
36
+ const limits = wireField(body, "limits");
37
+ const seen = /* @__PURE__ */ new Set();
38
+ return (Array.isArray(limits) ? limits : []).flatMap((limit) => {
39
+ const usedPercent = wirePercent(wireField(limit, "percent"));
40
+ const model = wireField(wireField(limit, "scope"), "model");
41
+ const id = wireField(model, "id");
42
+ const name = wireField(model, "display_name");
43
+ const key = Predicate.isString(id) && id.trim() !== "" ? id.trim().toLowerCase() : Predicate.isString(name) ? name.trim().toLowerCase().split(/[^a-z0-9]+/).filter((part) => part !== "").join("-") : "";
44
+ if (wireField(limit, "kind") !== "weekly_scoped" || usedPercent === void 0 || key === "" || seen.has(key)) return [];
45
+ seen.add(key);
46
+ return [{
47
+ id: `seven-day-${key}`,
48
+ usedPercent,
49
+ resetsAt: wireInstant(wireField(limit, "resets_at")),
50
+ models: [key]
51
+ }];
52
+ });
53
+ };
30
54
  const anthropicClaudeUsageSnapshotCase = makeSubscriptionUsageConformanceCase({
31
55
  id: "anthropic.claude.usage.snapshot",
32
56
  title: "Claude subscription usage normalizes the reported windows only",
33
- docs: "The Claude OAuth usage endpoint (`GET /api/oauth/usage`, bearer OAuth token and `anthropic-beta: oauth-2025-04-20`) answers JSON with `five_hour` and `seven_day` windows as `{ utilization, resets_at }` (either may be `null`); the fetcher maps them to `five-hour` and `seven-day`.",
34
- wire: "A wire window is reported when its `utilization` is a number from 0 to 100; its reset instant is `resets_at` when readable.",
57
+ docs: "The Claude OAuth usage endpoint (`GET /api/oauth/usage`, bearer OAuth token and `anthropic-beta: oauth-2025-04-20`) answers JSON with `five_hour` and `seven_day` windows as `{ utilization, resets_at }` (either may be `null`) and model-scoped weekly limits in `limits[]` (`{ kind: \"weekly_scoped\", percent, resets_at, scope: { model: { id, display_name } } }`); the fetcher maps them to `five-hour`, `seven-day`, and `seven-day-<model>`.",
58
+ wire: "A wire window is reported when its `utilization` (scoped limits: `percent`) is a number from 0 to 100; its reset instant is `resets_at` when readable. A scoped limit is keyed by its lowercase model id, else its display name slugged, and lists that key as its only model; the first limit per key wins.",
35
59
  providerId: anthropicClaudeProviderId,
36
60
  windowIds: claudeWindows.map((window) => window.id),
37
61
  settings: Effect.service(AnthropicClaudeUsageConformanceConfig),
38
62
  fetch: (settings) => fetchAnthropicClaudeSubscriptionUsage(settings.token),
39
- expectedWindows: (body) => claudeWindows.flatMap((window) => {
63
+ scopedWindowIdPrefix: "seven-day-",
64
+ expectedWindows: (body) => [...claudeWindows.flatMap((window) => {
40
65
  const wire = wireField(body, window.key);
41
66
  const usedPercent = wirePercent(wireField(wire, "utilization"));
42
67
  return usedPercent === void 0 ? [] : [{
@@ -44,7 +69,7 @@ const anthropicClaudeUsageSnapshotCase = makeSubscriptionUsageConformanceCase({
44
69
  usedPercent,
45
70
  resetsAt: wireInstant(wireField(wire, "resets_at"))
46
71
  }];
47
- }),
72
+ }), ...scopedWireWindows(body)],
48
73
  fixture: anthropicClaudeUsageSnapshotFixture.id
49
74
  });
50
75
  /** Every Claude subscription-usage conformance case. */
@@ -1 +1 @@
1
- {"version":3,"file":"claude-usage-cases.mjs","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-cases.ts"],"sourcesContent":["/**\n * Claude subscription-usage conformance case for `@yolk-sdk/conformance/runner`.\n *\n * The case calls the public `fetchAnthropicClaudeSubscriptionUsage` (default\n * `https://api.anthropic.com/api/oauth/usage`, Claude OAuth bearer plus `anthropic-beta:\n * oauth-2025-04-20`) from `AnthropicClaudeUsageConformanceConfig` and asserts the normalized\n * `ProviderSubscriptionUsageSnapshot` against the raw body it reads at its own `HttpClient`\n * boundary (shared shape: `openai/conformance/subscription-usage-cases-internal.ts`). It needs only\n * `HttpClient.HttpClient` and the config service, so it runs against the replayed fixture\n * (`ReplayHttpClient`), the `@yolk-sdk/emulators/anthropic` usage route, or a host's live\n * `HttpClient`. It is a `read` case, not observed live yet (`observed` absent = unverified).\n */\nimport { Context, Effect } from 'effect'\nimport type { HttpClient } from 'effect/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport {\n makeSubscriptionUsageConformanceCase,\n wireField,\n wireInstant,\n wirePercent,\n type SubscriptionUsageConformanceCase,\n type SubscriptionUsageExpectedWindow\n} from '../../openai/conformance/subscription-usage-cases-internal.ts'\nimport { anthropicClaudeProviderId } from '../claude.ts'\nimport {\n anthropicClaudeSubscriptionUsageUrl,\n fetchAnthropicClaudeSubscriptionUsage\n} from '../usage.ts'\nimport { anthropicClaudeUsageSnapshotFixture } from './claude-usage-snapshot.ts'\n\n/** The Claude subscription-usage endpoint the case (and the fetcher's default) calls. */\nexport const anthropicClaudeUsageConformanceUrl = anthropicClaudeSubscriptionUsageUrl\n\nexport type AnthropicClaudeUsageConformanceSettings = {\n /**\n * Claude subscription OAuth access token (provider `anthropic-claude`), sent as `Authorization:\n * Bearer`. Any value works under replay or an emulator.\n */\n readonly token: OAuthAccessToken\n}\n\n/** Host-supplied settings for the Claude subscription-usage conformance case. */\nexport class AnthropicClaudeUsageConformanceConfig extends Context.Service<\n AnthropicClaudeUsageConformanceConfig,\n AnthropicClaudeUsageConformanceSettings\n>()('@yolk-sdk/agent/providers/anthropic/conformance/AnthropicClaudeUsageConformanceConfig') {}\n\n/** What the Claude usage conformance case requires from the host. */\nexport type AnthropicClaudeUsageConformanceRequirements =\n | HttpClient.HttpClient\n | AnthropicClaudeUsageConformanceConfig\n\nexport type AnthropicClaudeUsageConformanceCase =\n SubscriptionUsageConformanceCase<AnthropicClaudeUsageConformanceConfig>\n\nconst claudeWindows = [\n { key: 'five_hour', id: 'five-hour' },\n { key: 'seven_day', id: 'seven-day' }\n] as const\n\nexport const anthropicClaudeUsageSnapshotCase: AnthropicClaudeUsageConformanceCase =\n makeSubscriptionUsageConformanceCase({\n id: 'anthropic.claude.usage.snapshot',\n title: 'Claude subscription usage normalizes the reported windows only',\n docs: 'The Claude OAuth usage endpoint (`GET /api/oauth/usage`, bearer OAuth token and `anthropic-beta: oauth-2025-04-20`) answers JSON with `five_hour` and `seven_day` windows as `{ utilization, resets_at }` (either may be `null`); the fetcher maps them to `five-hour` and `seven-day`.',\n wire: 'A wire window is reported when its `utilization` is a number from 0 to 100; its reset instant is `resets_at` when readable.',\n providerId: anthropicClaudeProviderId,\n windowIds: claudeWindows.map(window => window.id),\n settings: Effect.service(AnthropicClaudeUsageConformanceConfig),\n fetch: settings => fetchAnthropicClaudeSubscriptionUsage(settings.token),\n expectedWindows: body =>\n claudeWindows.flatMap((window): Array<SubscriptionUsageExpectedWindow> => {\n const wire = wireField(body, window.key)\n const usedPercent = wirePercent(wireField(wire, 'utilization'))\n\n return usedPercent === undefined\n ? []\n : [{ id: window.id, usedPercent, resetsAt: wireInstant(wireField(wire, 'resets_at')) }]\n }),\n fixture: anthropicClaudeUsageSnapshotFixture.id\n })\n\n/** Every Claude subscription-usage conformance case. */\nexport const anthropicClaudeUsageConformanceCases: ReadonlyArray<AnthropicClaudeUsageConformanceCase> =\n [anthropicClaudeUsageSnapshotCase]\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,MAAa,qCAAqC;;AAWlD,IAAa,wCAAb,cAA2D,QAAQ,QAGjE,EAAE,uFAAuF,EAAE,CAAC;AAU9F,MAAM,gBAAgB,CACpB;CAAE,KAAK;CAAa,IAAI;AAAY,GACpC;CAAE,KAAK;CAAa,IAAI;AAAY,CACtC;AAEA,MAAa,mCACX,qCAAqC;CACnC,IAAI;CACJ,OAAO;CACP,MAAM;CACN,MAAM;CACN,YAAY;CACZ,WAAW,cAAc,KAAI,WAAU,OAAO,EAAE;CAChD,UAAU,OAAO,QAAQ,qCAAqC;CAC9D,QAAO,aAAY,sCAAsC,SAAS,KAAK;CACvE,kBAAiB,SACf,cAAc,SAAS,WAAmD;EACxE,MAAM,OAAO,UAAU,MAAM,OAAO,GAAG;EACvC,MAAM,cAAc,YAAY,UAAU,MAAM,aAAa,CAAC;EAE9D,OAAO,gBAAgB,KAAA,IACnB,CAAC,IACD,CAAC;GAAE,IAAI,OAAO;GAAI;GAAa,UAAU,YAAY,UAAU,MAAM,WAAW,CAAC;EAAE,CAAC;CAC1F,CAAC;CACH,SAAS,oCAAoC;AAC/C,CAAC;;AAGH,MAAa,uCACX,CAAC,gCAAgC"}
1
+ {"version":3,"file":"claude-usage-cases.mjs","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-cases.ts"],"sourcesContent":["/**\n * Claude subscription-usage conformance case for `@yolk-sdk/conformance/runner`.\n *\n * The case calls the public `fetchAnthropicClaudeSubscriptionUsage` (default\n * `https://api.anthropic.com/api/oauth/usage`, Claude OAuth bearer plus `anthropic-beta:\n * oauth-2025-04-20`) from `AnthropicClaudeUsageConformanceConfig` and asserts the normalized\n * `ProviderSubscriptionUsageSnapshot` against the raw body it reads at its own `HttpClient`\n * boundary (shared shape: `openai/conformance/subscription-usage-cases-internal.ts`). It needs only\n * `HttpClient.HttpClient` and the config service, so it runs against the replayed fixture\n * (`ReplayHttpClient`), the `@yolk-sdk/emulators/anthropic` usage route, or a host's live\n * `HttpClient`. It is a `read` case, not observed live yet (`observed` absent = unverified).\n */\nimport { Context, Effect, Predicate } from 'effect'\nimport type * as Schema from 'effect/Schema'\nimport type { HttpClient } from 'effect/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport {\n makeSubscriptionUsageConformanceCase,\n wireField,\n wireInstant,\n wirePercent,\n type SubscriptionUsageConformanceCase,\n type SubscriptionUsageExpectedWindow\n} from '../../openai/conformance/subscription-usage-cases-internal.ts'\nimport { anthropicClaudeProviderId } from '../claude.ts'\nimport {\n anthropicClaudeSubscriptionUsageUrl,\n fetchAnthropicClaudeSubscriptionUsage\n} from '../usage.ts'\nimport { anthropicClaudeUsageSnapshotFixture } from './claude-usage-snapshot.ts'\n\n/** The Claude subscription-usage endpoint the case (and the fetcher's default) calls. */\nexport const anthropicClaudeUsageConformanceUrl = anthropicClaudeSubscriptionUsageUrl\n\nexport type AnthropicClaudeUsageConformanceSettings = {\n /**\n * Claude subscription OAuth access token (provider `anthropic-claude`), sent as `Authorization:\n * Bearer`. Any value works under replay or an emulator.\n */\n readonly token: OAuthAccessToken\n}\n\n/** Host-supplied settings for the Claude subscription-usage conformance case. */\nexport class AnthropicClaudeUsageConformanceConfig extends Context.Service<\n AnthropicClaudeUsageConformanceConfig,\n AnthropicClaudeUsageConformanceSettings\n>()('@yolk-sdk/agent/providers/anthropic/conformance/AnthropicClaudeUsageConformanceConfig') {}\n\n/** What the Claude usage conformance case requires from the host. */\nexport type AnthropicClaudeUsageConformanceRequirements =\n | HttpClient.HttpClient\n | AnthropicClaudeUsageConformanceConfig\n\nexport type AnthropicClaudeUsageConformanceCase =\n SubscriptionUsageConformanceCase<AnthropicClaudeUsageConformanceConfig>\n\nconst claudeWindows = [\n { key: 'five_hour', id: 'five-hour' },\n { key: 'seven_day', id: 'seven-day' }\n] as const\n\n/**\n * Model-scoped weekly limits (`limits[]` entries with `kind: \"weekly_scoped\"` and a numeric\n * `percent`), keyed by the lowercase model id or else the display name slugged; the first entry per\n * model wins.\n */\nconst scopedWireWindows = (body: Schema.Json): Array<SubscriptionUsageExpectedWindow> => {\n const limits = wireField(body, 'limits')\n const seen = new Set<string>()\n\n return (Array.isArray(limits) ? limits : []).flatMap(\n (limit): Array<SubscriptionUsageExpectedWindow> => {\n const usedPercent = wirePercent(wireField(limit, 'percent'))\n const model = wireField(wireField(limit, 'scope'), 'model')\n const id = wireField(model, 'id')\n const name = wireField(model, 'display_name')\n\n const key =\n Predicate.isString(id) && id.trim() !== ''\n ? id.trim().toLowerCase()\n : Predicate.isString(name)\n ? name\n .trim()\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter(part => part !== '')\n .join('-')\n : ''\n\n if (\n wireField(limit, 'kind') !== 'weekly_scoped' ||\n usedPercent === undefined ||\n key === '' ||\n seen.has(key)\n ) {\n return []\n }\n\n seen.add(key)\n\n return [\n {\n id: `seven-day-${key}`,\n usedPercent,\n resetsAt: wireInstant(wireField(limit, 'resets_at')),\n models: [key]\n }\n ]\n }\n )\n}\n\nexport const anthropicClaudeUsageSnapshotCase: AnthropicClaudeUsageConformanceCase =\n makeSubscriptionUsageConformanceCase({\n id: 'anthropic.claude.usage.snapshot',\n title: 'Claude subscription usage normalizes the reported windows only',\n docs: 'The Claude OAuth usage endpoint (`GET /api/oauth/usage`, bearer OAuth token and `anthropic-beta: oauth-2025-04-20`) answers JSON with `five_hour` and `seven_day` windows as `{ utilization, resets_at }` (either may be `null`) and model-scoped weekly limits in `limits[]` (`{ kind: \"weekly_scoped\", percent, resets_at, scope: { model: { id, display_name } } }`); the fetcher maps them to `five-hour`, `seven-day`, and `seven-day-<model>`.',\n wire: 'A wire window is reported when its `utilization` (scoped limits: `percent`) is a number from 0 to 100; its reset instant is `resets_at` when readable. A scoped limit is keyed by its lowercase model id, else its display name slugged, and lists that key as its only model; the first limit per key wins.',\n providerId: anthropicClaudeProviderId,\n windowIds: claudeWindows.map(window => window.id),\n settings: Effect.service(AnthropicClaudeUsageConformanceConfig),\n fetch: settings => fetchAnthropicClaudeSubscriptionUsage(settings.token),\n scopedWindowIdPrefix: 'seven-day-',\n expectedWindows: body => [\n ...claudeWindows.flatMap((window): Array<SubscriptionUsageExpectedWindow> => {\n const wire = wireField(body, window.key)\n const usedPercent = wirePercent(wireField(wire, 'utilization'))\n\n return usedPercent === undefined\n ? []\n : [{ id: window.id, usedPercent, resetsAt: wireInstant(wireField(wire, 'resets_at')) }]\n }),\n ...scopedWireWindows(body)\n ],\n fixture: anthropicClaudeUsageSnapshotFixture.id\n })\n\n/** Every Claude subscription-usage conformance case. */\nexport const anthropicClaudeUsageConformanceCases: ReadonlyArray<AnthropicClaudeUsageConformanceCase> =\n [anthropicClaudeUsageSnapshotCase]\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAa,qCAAqC;;AAWlD,IAAa,wCAAb,cAA2D,QAAQ,QAGjE,EAAE,uFAAuF,EAAE,CAAC;AAU9F,MAAM,gBAAgB,CACpB;CAAE,KAAK;CAAa,IAAI;AAAY,GACpC;CAAE,KAAK;CAAa,IAAI;AAAY,CACtC;;;;;;AAOA,MAAM,qBAAqB,SAA8D;CACvF,MAAM,SAAS,UAAU,MAAM,QAAQ;CACvC,MAAM,uBAAO,IAAI,IAAY;CAE7B,QAAQ,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,GAAG,SAC1C,UAAkD;EACjD,MAAM,cAAc,YAAY,UAAU,OAAO,SAAS,CAAC;EAC3D,MAAM,QAAQ,UAAU,UAAU,OAAO,OAAO,GAAG,OAAO;EAC1D,MAAM,KAAK,UAAU,OAAO,IAAI;EAChC,MAAM,OAAO,UAAU,OAAO,cAAc;EAE5C,MAAM,MACJ,UAAU,SAAS,EAAE,KAAK,GAAG,KAAK,MAAM,KACpC,GAAG,KAAK,EAAE,YAAY,IACtB,UAAU,SAAS,IAAI,IACrB,KACG,KAAK,EACL,YAAY,EACZ,MAAM,YAAY,EAClB,QAAO,SAAQ,SAAS,EAAE,EAC1B,KAAK,GAAG,IACX;EAER,IACE,UAAU,OAAO,MAAM,MAAM,mBAC7B,gBAAgB,KAAA,KAChB,QAAQ,MACR,KAAK,IAAI,GAAG,GAEZ,OAAO,CAAC;EAGV,KAAK,IAAI,GAAG;EAEZ,OAAO,CACL;GACE,IAAI,aAAa;GACjB;GACA,UAAU,YAAY,UAAU,OAAO,WAAW,CAAC;GACnD,QAAQ,CAAC,GAAG;EACd,CACF;CACF,CACF;AACF;AAEA,MAAa,mCACX,qCAAqC;CACnC,IAAI;CACJ,OAAO;CACP,MAAM;CACN,MAAM;CACN,YAAY;CACZ,WAAW,cAAc,KAAI,WAAU,OAAO,EAAE;CAChD,UAAU,OAAO,QAAQ,qCAAqC;CAC9D,QAAO,aAAY,sCAAsC,SAAS,KAAK;CACvE,sBAAsB;CACtB,kBAAiB,SAAQ,CACvB,GAAG,cAAc,SAAS,WAAmD;EAC3E,MAAM,OAAO,UAAU,MAAM,OAAO,GAAG;EACvC,MAAM,cAAc,YAAY,UAAU,MAAM,aAAa,CAAC;EAE9D,OAAO,gBAAgB,KAAA,IACnB,CAAC,IACD,CAAC;GAAE,IAAI,OAAO;GAAI;GAAa,UAAU,YAAY,UAAU,MAAM,WAAW,CAAC;EAAE,CAAC;CAC1F,CAAC,GACD,GAAG,kBAAkB,IAAI,CAC3B;CACA,SAAS,oCAAoC;AAC/C,CAAC;;AAGH,MAAa,uCACX,CAAC,gCAAgC"}
@@ -3,7 +3,8 @@ import { WireFixture } from "@yolk-sdk/conformance/fixture";
3
3
  //#region src/providers/anthropic/conformance/claude-usage-snapshot.d.ts
4
4
  /**
5
5
  * Claude subscription-usage snapshot: `GET /api/oauth/usage` answering `five_hour` and
6
- * `seven_day` windows as `{ utilization, resets_at }`.
6
+ * `seven_day` windows as `{ utilization, resets_at }` and one model-scoped weekly limit in
7
+ * `limits[]`.
7
8
  *
8
9
  * Synthetic placeholder (`evidence: 'unverified'`) until a live recording replaces it. Regenerate
9
10
  * with `pnpm conformance:usage --family claude --live --owner-approved --account <label>`.
@@ -1 +1 @@
1
- {"version":3,"file":"claude-usage-snapshot.d.mts","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-snapshot.ts"],"mappings":";;;;;AASA;;;;AA0BC;cA1BY,mCAAA,EAAqC,WA0BjD"}
1
+ {"version":3,"file":"claude-usage-snapshot.d.mts","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-snapshot.ts"],"mappings":";;;;;AAUA;;;;AA0BC;;cA1BY,mCAAA,EAAqC,WA0BjD"}
@@ -1,7 +1,8 @@
1
1
  //#region src/providers/anthropic/conformance/claude-usage-snapshot.ts
2
2
  /**
3
3
  * Claude subscription-usage snapshot: `GET /api/oauth/usage` answering `five_hour` and
4
- * `seven_day` windows as `{ utilization, resets_at }`.
4
+ * `seven_day` windows as `{ utilization, resets_at }` and one model-scoped weekly limit in
5
+ * `limits[]`.
5
6
  *
6
7
  * Synthetic placeholder (`evidence: 'unverified'`) until a live recording replaces it. Regenerate
7
8
  * with `pnpm conformance:usage --family claude --live --owner-approved --account <label>`.
@@ -23,7 +24,7 @@ const anthropicClaudeUsageSnapshotFixture = {
23
24
  response: {
24
25
  status: 200,
25
26
  headers: { "content-type": "application/json" },
26
- body: "{\"five_hour\":{\"utilization\":18,\"resets_at\":\"2026-10-01T05:00:00.000Z\"},\"seven_day\":{\"utilization\":42,\"resets_at\":\"2026-10-06T00:00:00.000Z\"}}"
27
+ body: "{\"five_hour\":{\"utilization\":18,\"resets_at\":\"2026-10-01T05:00:00.000Z\"},\"seven_day\":{\"utilization\":42,\"resets_at\":\"2026-10-06T00:00:00.000Z\"},\"limits\":[{\"kind\":\"weekly_scoped\",\"percent\":64,\"resets_at\":\"2026-10-06T00:00:00.000Z\",\"scope\":{\"model\":{\"id\":null,\"display_name\":\"Opus\"}}}]}"
27
28
  }
28
29
  }]
29
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"claude-usage-snapshot.mjs","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-snapshot.ts"],"sourcesContent":["import type { WireFixture } from '@yolk-sdk/conformance/fixture'\n\n/**\n * Claude subscription-usage snapshot: `GET /api/oauth/usage` answering `five_hour` and\n * `seven_day` windows as `{ utilization, resets_at }`.\n *\n * Synthetic placeholder (`evidence: 'unverified'`) until a live recording replaces it. Regenerate\n * with `pnpm conformance:usage --family claude --live --owner-approved --account <label>`.\n */\nexport const anthropicClaudeUsageSnapshotFixture: WireFixture = {\n id: 'anthropic.claude.usage.snapshot.synthetic',\n caseId: 'anthropic.claude.usage.snapshot',\n evidence: 'unverified',\n recordedAt: '2026-09-30',\n account: 'synthetic',\n endpoint: 'https://api.anthropic.com/api/oauth/usage',\n note: 'Synthetic placeholder shaped like the Claude OAuth usage JSON the SDK parser reads. Not recorded from a live service; replace with a verified recording from pnpm conformance:usage --family claude --live --owner-approved --account <label>.',\n exchanges: [\n {\n request: {\n method: 'GET',\n url: 'https://api.anthropic.com/api/oauth/usage',\n headers: {\n accept: 'application/json'\n }\n },\n response: {\n status: 200,\n headers: {\n 'content-type': 'application/json'\n },\n body: '{\"five_hour\":{\"utilization\":18,\"resets_at\":\"2026-10-01T05:00:00.000Z\"},\"seven_day\":{\"utilization\":42,\"resets_at\":\"2026-10-06T00:00:00.000Z\"}}'\n }\n }\n ]\n}\n"],"mappings":";;;;;;;;AASA,MAAa,sCAAmD;CAC9D,IAAI;CACJ,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;CACT,UAAU;CACV,MAAM;CACN,WAAW,CACT;EACE,SAAS;GACP,QAAQ;GACR,KAAK;GACL,SAAS,EACP,QAAQ,mBACV;EACF;EACA,UAAU;GACR,QAAQ;GACR,SAAS,EACP,gBAAgB,mBAClB;GACA,MAAM;EACR;CACF,CACF;AACF"}
1
+ {"version":3,"file":"claude-usage-snapshot.mjs","names":[],"sources":["../../../../src/providers/anthropic/conformance/claude-usage-snapshot.ts"],"sourcesContent":["import type { WireFixture } from '@yolk-sdk/conformance/fixture'\n\n/**\n * Claude subscription-usage snapshot: `GET /api/oauth/usage` answering `five_hour` and\n * `seven_day` windows as `{ utilization, resets_at }` and one model-scoped weekly limit in\n * `limits[]`.\n *\n * Synthetic placeholder (`evidence: 'unverified'`) until a live recording replaces it. Regenerate\n * with `pnpm conformance:usage --family claude --live --owner-approved --account <label>`.\n */\nexport const anthropicClaudeUsageSnapshotFixture: WireFixture = {\n id: 'anthropic.claude.usage.snapshot.synthetic',\n caseId: 'anthropic.claude.usage.snapshot',\n evidence: 'unverified',\n recordedAt: '2026-09-30',\n account: 'synthetic',\n endpoint: 'https://api.anthropic.com/api/oauth/usage',\n note: 'Synthetic placeholder shaped like the Claude OAuth usage JSON the SDK parser reads. Not recorded from a live service; replace with a verified recording from pnpm conformance:usage --family claude --live --owner-approved --account <label>.',\n exchanges: [\n {\n request: {\n method: 'GET',\n url: 'https://api.anthropic.com/api/oauth/usage',\n headers: {\n accept: 'application/json'\n }\n },\n response: {\n status: 200,\n headers: {\n 'content-type': 'application/json'\n },\n body: '{\"five_hour\":{\"utilization\":18,\"resets_at\":\"2026-10-01T05:00:00.000Z\"},\"seven_day\":{\"utilization\":42,\"resets_at\":\"2026-10-06T00:00:00.000Z\"},\"limits\":[{\"kind\":\"weekly_scoped\",\"percent\":64,\"resets_at\":\"2026-10-06T00:00:00.000Z\",\"scope\":{\"model\":{\"id\":null,\"display_name\":\"Opus\"}}}]}'\n }\n }\n ]\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,sCAAmD;CAC9D,IAAI;CACJ,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;CACT,UAAU;CACV,MAAM;CACN,WAAW,CACT;EACE,SAAS;GACP,QAAQ;GACR,KAAK;GACL,SAAS,EACP,QAAQ,mBACV;EACF;EACA,UAAU;GACR,QAAQ;GACR,SAAS,EACP,gBAAgB,mBAClB;GACA,MAAM;EACR;CACF,CACF;AACF"}
@@ -14,8 +14,10 @@ type AnthropicClaudeSubscriptionUsageOptions = {
14
14
  */
15
15
  readonly url?: string;
16
16
  };
17
+ /** Window id prefix of model-scoped weekly limits: `seven-day-<model>`. */
18
+ declare const anthropicClaudeScopedWindowIdPrefix = "seven-day-";
17
19
  declare const parseAnthropicClaudeSubscriptionUsage: (value: unknown, fetchedAt: string) => Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError>;
18
20
  declare const fetchAnthropicClaudeSubscriptionUsage: (token: OAuthAccessToken, options?: AnthropicClaudeSubscriptionUsageOptions) => Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageError, HttpClient.HttpClient>;
19
21
  //#endregion
20
- export { AnthropicClaudeSubscriptionUsageOptions, anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
22
+ export { AnthropicClaudeSubscriptionUsageOptions, anthropicClaudeScopedWindowIdPrefix, anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
21
23
  //# sourceMappingURL=usage.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;cAoBa,mCAAA;AAAA,KAED,uCAAA;EAAA,SACD,gBAAA;EAHqC;;;AAAA;AAEhD;EAFgD,SASrC,GAAG;AAAA;AAAA,cAqBD,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAwEvC,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,gBAAA;EAHqC;;;AAAA;AAEhD;EAFgD,SASrC,GAAG;AAAA;;cA0CD,mCAAA;AAAA,cAsBA,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cA4HvC,qCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,uCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
@@ -1,7 +1,7 @@
1
1
  import { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from "./claude.mjs";
2
2
  import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
3
3
  import { canonicalSubscriptionUsageInstant, executeAndReadProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
4
- import { Chunk, Clock, Effect } from "effect";
4
+ import { Chunk, Clock, Effect, Option, Predicate } from "effect";
5
5
  import * as Schema$1 from "effect/Schema";
6
6
  import { HttpClient, HttpClientRequest } from "effect/http";
7
7
  //#region src/providers/anthropic/usage.ts
@@ -14,8 +14,34 @@ var AnthropicClaudeSubscriptionUsageWindowWire = class extends Schema$1.Class("A
14
14
  }) {};
15
15
  var AnthropicClaudeSubscriptionUsageWire = class extends Schema$1.Class("AnthropicClaudeSubscriptionUsageWire")({
16
16
  five_hour: Schema$1.optional(Schema$1.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),
17
- seven_day: Schema$1.optional(Schema$1.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))
17
+ seven_day: Schema$1.optional(Schema$1.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),
18
+ limits: Schema$1.optional(Schema$1.NullOr(Schema$1.Array(Schema$1.Unknown)))
18
19
  }) {};
20
+ /** A model-scoped weekly limit from `limits[]` (`kind: "weekly_scoped"`). */
21
+ const AnthropicClaudeScopedLimitWire = Schema$1.Struct({
22
+ kind: Schema$1.Literal("weekly_scoped"),
23
+ percent: Schema$1.Number,
24
+ resets_at: Schema$1.optional(Schema$1.Unknown),
25
+ scope: Schema$1.Struct({ model: Schema$1.Struct({
26
+ id: Schema$1.optional(Schema$1.Unknown),
27
+ display_name: Schema$1.optional(Schema$1.Unknown)
28
+ }) })
29
+ });
30
+ const decodeScopedLimit = Schema$1.decodeUnknownOption(AnthropicClaudeScopedLimitWire);
31
+ const fiveHourMinutes = 300;
32
+ const sevenDayMinutes = 10080;
33
+ /** Window id prefix of model-scoped weekly limits: `seven-day-<model>`. */
34
+ const anthropicClaudeScopedWindowIdPrefix = "seven-day-";
35
+ /**
36
+ * The lowercase model substring a scoped limit applies to: the model id when present, else the
37
+ * display name slugged (`Opus` → `opus`).
38
+ */
39
+ const scopedLimitModel = (model) => {
40
+ const id = Predicate.isString(model.id) ? model.id.trim().toLowerCase() : "";
41
+ if (id !== "") return id;
42
+ const slug = (Predicate.isString(model.display_name) ? model.display_name : "").trim().toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-+|-+$/g, "");
43
+ return slug === "" ? void 0 : slug;
44
+ };
19
45
  const parseAnthropicClaudeSubscriptionUsage = (value, fetchedAt) => {
20
46
  const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt);
21
47
  if (canonicalFetchedAt === void 0) return Effect.fail(ProviderSubscriptionUsageResponseError.make({
@@ -24,21 +50,49 @@ const parseAnthropicClaudeSubscriptionUsage = (value, fetchedAt) => {
24
50
  }));
25
51
  return Schema$1.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(Effect.map((decoded) => {
26
52
  const windows = [];
27
- const append = (wire, id) => {
53
+ const pushWindow = (input) => {
54
+ const resetsAt = Predicate.isString(input.resetsAt) || Predicate.isNumber(input.resetsAt) ? canonicalSubscriptionUsageInstant(input.resetsAt) : void 0;
55
+ const fields = resetsAt === void 0 ? {
56
+ id: input.id,
57
+ usedPercent: input.usedPercent,
58
+ windowDurationMinutes: input.windowDurationMinutes
59
+ } : {
60
+ id: input.id,
61
+ usedPercent: input.usedPercent,
62
+ resetsAt,
63
+ windowDurationMinutes: input.windowDurationMinutes
64
+ };
65
+ if (input.models !== void 0) fields.models = input.models;
66
+ windows.push(ProviderSubscriptionUsageWindow.make(fields));
67
+ };
68
+ const append = (wire, id, windowDurationMinutes) => {
28
69
  if (!validSubscriptionUsagePercent(wire?.utilization)) return;
29
- const resetValue = wire.resets_at === null ? void 0 : wire.resets_at;
30
- const resetsAt = resetValue === void 0 ? void 0 : canonicalSubscriptionUsageInstant(resetValue);
31
- windows.push(ProviderSubscriptionUsageWindow.make((() => {
32
- const fields = {
33
- id,
34
- usedPercent: wire.utilization
35
- };
36
- if (resetsAt !== void 0) fields.resetsAt = resetsAt;
37
- return fields;
38
- })()));
70
+ pushWindow({
71
+ id,
72
+ usedPercent: wire.utilization,
73
+ resetsAt: wire.resets_at,
74
+ windowDurationMinutes
75
+ });
39
76
  };
40
- append(decoded.five_hour, "five-hour");
41
- append(decoded.seven_day, "seven-day");
77
+ append(decoded.five_hour, "five-hour", fiveHourMinutes);
78
+ append(decoded.seven_day, "seven-day", sevenDayMinutes);
79
+ const scopedIds = /* @__PURE__ */ new Set();
80
+ for (const raw of decoded.limits ?? []) {
81
+ const limit = decodeScopedLimit(raw);
82
+ if (Option.isNone(limit) || !validSubscriptionUsagePercent(limit.value.percent)) continue;
83
+ const model = scopedLimitModel(limit.value.scope.model);
84
+ if (model === void 0) continue;
85
+ const id = `${anthropicClaudeScopedWindowIdPrefix}${model}`;
86
+ if (scopedIds.has(id)) continue;
87
+ scopedIds.add(id);
88
+ pushWindow({
89
+ id,
90
+ usedPercent: limit.value.percent,
91
+ resetsAt: limit.value.resets_at,
92
+ windowDurationMinutes: sevenDayMinutes,
93
+ models: [model]
94
+ });
95
+ }
42
96
  return ProviderSubscriptionUsageSnapshot.make({
43
97
  provider: anthropicClaudeProviderId,
44
98
  fetchedAt: canonicalFetchedAt,
@@ -71,6 +125,6 @@ const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.ge
71
125
  }), new Date(yield* Clock.currentTimeMillis).toISOString());
72
126
  }).pipe(Effect.withSpan("AnthropicClaudeSubscriptionUsage.fetch"));
73
127
  //#endregion
74
- export { anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
128
+ export { anthropicClaudeScopedWindowIdPrefix, anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
75
129
 
76
130
  //# sourceMappingURL=usage.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"usage.mjs","names":["Schema"],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/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 * Endpoint override. Defaults to `anthropicClaudeSubscriptionUsageUrl`. Override only with a trusted\n * proxy or a local emulator: the credential is sent to this URL. Redirects stay\n * manual and non-2xx redirects are still rejected.\n */\n readonly url?: string\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\n\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\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\n const resetsAt =\n resetValue === undefined ? undefined : canonicalSubscriptionUsageInstant(resetValue)\n\n type AnthropicUsageWindowFields = {\n id: typeof id\n usedPercent: number\n resetsAt?: string\n }\n\n windows.push(\n ProviderSubscriptionUsageWindow.make(\n (() => {\n const fields: AnthropicUsageWindowFields = {\n id,\n usedPercent: wire.utilization\n }\n\n if (resetsAt !== undefined) {\n fields.resetsAt = resetsAt\n }\n\n return fields\n })()\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\n const request = HttpClientRequest.get(options.url ?? anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\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;AAYnD,MAAM,iBAAiBA,SAAO,OAAOA,SAAO,MAAM;AAElD,MAAM,iBAAiBA,SAAO,OAAOA,SAAO,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A,MAAa,yCACX,OACA,UAAmD,CAAC,MAMpD,OAAO,IAAI,aAAa;CACtB,IAAI,MAAM,aAAA,oBACR,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;CAsBF,OAAO,OAAO,sCAAsC,OAThC,4CAA4C;EAC9D,UAAU;EACV,QAAA,OAZoB,WAAW;EAa/B,SAXc,kBAAkB,IAAI,QAAQ,OAAA,2CAA0C,EAAE,KACxF,kBAAkB,WAAW;GAC3B,QAAQ;GACR,GAAG,oCAAoC,KAAK;GAC5C,kBAAkB;EACpB,CAAC,CAMK;EACN,WAAW;CACb,CAAC,GAEiB,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEO,CAAC;AACrE,CAAC,EAAE,KAAK,OAAO,SAAS,wCAAwC,CAAC"}
1
+ {"version":3,"file":"usage.mjs","names":["Schema"],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect, Option, Predicate } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/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 * Endpoint override. Defaults to `anthropicClaudeSubscriptionUsageUrl`. Override only with a trusted\n * proxy or a local emulator: the credential is sent to this URL. Redirects stay\n * manual and non-2xx redirects are still rejected.\n */\n readonly url?: string\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\n\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 limits: Schema.optional(Schema.NullOr(Schema.Array(Schema.Unknown)))\n}) {}\n\n/** A model-scoped weekly limit from `limits[]` (`kind: \"weekly_scoped\"`). */\nconst AnthropicClaudeScopedLimitWire = Schema.Struct({\n kind: Schema.Literal('weekly_scoped'),\n percent: Schema.Number,\n resets_at: Schema.optional(Schema.Unknown),\n scope: Schema.Struct({\n model: Schema.Struct({\n id: Schema.optional(Schema.Unknown),\n display_name: Schema.optional(Schema.Unknown)\n })\n })\n})\n\nconst decodeScopedLimit = Schema.decodeUnknownOption(AnthropicClaudeScopedLimitWire)\n\nconst fiveHourMinutes = 300\n\nconst sevenDayMinutes = 10_080\n\n/** Window id prefix of model-scoped weekly limits: `seven-day-<model>`. */\nexport const anthropicClaudeScopedWindowIdPrefix = 'seven-day-'\n\n/**\n * The lowercase model substring a scoped limit applies to: the model id when present, else the\n * display name slugged (`Opus` → `opus`).\n */\nconst scopedLimitModel = (model: { readonly id?: unknown; readonly display_name?: unknown }) => {\n const id = Predicate.isString(model.id) ? model.id.trim().toLowerCase() : ''\n\n if (id !== '') {\n return id\n }\n\n const slug = (Predicate.isString(model.display_name) ? model.display_name : '')\n .trim()\n .toLowerCase()\n .replaceAll(/[^a-z0-9]+/g, '-')\n .replaceAll(/^-+|-+$/g, '')\n\n return slug === '' ? undefined : slug\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\n type AnthropicUsageWindowFields = {\n id: string\n usedPercent: number\n resetsAt?: string\n windowDurationMinutes: number\n models?: ReadonlyArray<string>\n }\n\n const pushWindow = (input: {\n readonly id: string\n readonly usedPercent: number\n readonly resetsAt: unknown\n readonly windowDurationMinutes: number\n readonly models?: ReadonlyArray<string>\n }) => {\n const resetsAt =\n Predicate.isString(input.resetsAt) || Predicate.isNumber(input.resetsAt)\n ? canonicalSubscriptionUsageInstant(input.resetsAt)\n : undefined\n\n const fields: AnthropicUsageWindowFields =\n resetsAt === undefined\n ? {\n id: input.id,\n usedPercent: input.usedPercent,\n windowDurationMinutes: input.windowDurationMinutes\n }\n : {\n id: input.id,\n usedPercent: input.usedPercent,\n resetsAt,\n windowDurationMinutes: input.windowDurationMinutes\n }\n\n if (input.models !== undefined) {\n fields.models = input.models\n }\n\n windows.push(ProviderSubscriptionUsageWindow.make(fields))\n }\n\n const append = (\n wire: AnthropicClaudeSubscriptionUsageWindowWire | null | undefined,\n id: 'five-hour' | 'seven-day',\n windowDurationMinutes: number\n ) => {\n if (!validSubscriptionUsagePercent(wire?.utilization)) {\n return\n }\n\n pushWindow({\n id,\n usedPercent: wire.utilization,\n resetsAt: wire.resets_at,\n windowDurationMinutes\n })\n }\n\n append(decoded.five_hour, 'five-hour', fiveHourMinutes)\n append(decoded.seven_day, 'seven-day', sevenDayMinutes)\n\n const scopedIds = new Set<string>()\n\n for (const raw of decoded.limits ?? []) {\n const limit = decodeScopedLimit(raw)\n\n if (Option.isNone(limit) || !validSubscriptionUsagePercent(limit.value.percent)) {\n continue\n }\n\n const model = scopedLimitModel(limit.value.scope.model)\n\n if (model === undefined) {\n continue\n }\n\n const id = `${anthropicClaudeScopedWindowIdPrefix}${model}`\n\n if (scopedIds.has(id)) {\n continue\n }\n\n scopedIds.add(id)\n pushWindow({\n id,\n usedPercent: limit.value.percent,\n resetsAt: limit.value.resets_at,\n windowDurationMinutes: sevenDayMinutes,\n models: [model]\n })\n }\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\n const request = HttpClientRequest.get(options.url ?? anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\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;AAYnD,MAAM,iBAAiBA,SAAO,OAAOA,SAAO,MAAM;AAElD,MAAM,iBAAiBA,SAAO,OAAOA,SAAO,MAAM;AAElD,IAAM,6CAAN,cAAyDA,SAAO,MAC9D,4CACF,EAAE;CACA,aAAaA,SAAO,SAAS,cAAc;CAC3C,WAAWA,SAAO,SAAS,cAAc;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmDA,SAAO,MACxD,sCACF,EAAE;CACA,WAAWA,SAAO,SAASA,SAAO,OAAO,0CAA0C,CAAC;CACpF,WAAWA,SAAO,SAASA,SAAO,OAAO,0CAA0C,CAAC;CACpF,QAAQA,SAAO,SAASA,SAAO,OAAOA,SAAO,MAAMA,SAAO,OAAO,CAAC,CAAC;AACrE,CAAC,EAAE,CAAC;;AAGJ,MAAM,iCAAiCA,SAAO,OAAO;CACnD,MAAMA,SAAO,QAAQ,eAAe;CACpC,SAASA,SAAO;CAChB,WA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,sCAAsC,gBAAgB,GACzD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAsBF,OAAO,OAAO,sCAAsC,OAThC,4CAA4C;EAC9D,UAAU;EACV,QAAA,OAZoB,WAAW;EAa/B,SAXc,kBAAkB,IAAI,QAAQ,OAAA,2CAA0C,EAAE,KACxF,kBAAkB,WAAW;GAC3B,QAAQ;GACR,GAAG,oCAAoC,KAAK;GAC5C,kBAAkB;EACpB,CAAC,CAMK;EACN,WAAW;CACb,CAAC,GAEiB,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEO,CAAC;AACrE,CAAC,EAAE,KAAK,OAAO,SAAS,wCAAwC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-provider-internal.d.mts","names":[],"sources":["../../src/providers/anthropic-provider-internal.ts"],"mappings":";;;;;;;;;AA8DA;;KAAY,uBAAA;;AAAuB;AAUnC;;;;AAEiC;AAGjC;KALY,uBAAA;EAAA,SACD,OAAA;EAAA,SACA,sBAAsB;AAAA;AAAA,KAGrB,6BAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,WAAA;EAAA,SACA,SAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA,mBAHxB;EAAA,SAKA,cAAA,GAAiB,uBAAA,EAJjB;EAAA,SAMA,QAAA,GAAW,uBAAA;AAAA;AAAA,KAGjB,qBAAA;EAAA,SACM,IAAA;EAAA,SACA,GAAG;AAAA;AAAA,KAGT,kBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAA;EAAA,SACA,aAAA,GAAgB,qBAAqB;AAAA;AAAA,KAG3C,oBAAA,GAAuB,kBAAkB;AAAA,KAEzC,mBAAA;EAAA,SACM,IAAA;EAAA,SACA,MAAA;IAAA,SAEM,IAAA;IAAA,SACA,UAAA;IAAA,SACA,IAAA;EAAA;IAAA,SAGA,IAAA;IAAA,SACA,GAAA;EAAA;EAA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EAAA,SACT,aAAA;IAAA,SACE,wBAAA,EAA0B,WAAA,CACjC,uBAAA;EAAA;AAAA;AAAA,KAKD,oBAAA;EAAA,SACM,KAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,oBAAA;EAAA,SACtB,QAAA,EAAU,aAAA,CAAc,gBAAA;EAAA,SACxB,UAAA;EAAA,SACA,aAAA;IAAA,SACE,MAAA;EAAA;EAAA,SAEF,QAAA,GAAW,wBAAA;EAAA,SACX,MAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;EAAA,SACtB,WAAA;IAAA,SAAyB,IAAA;EAAA;AAAA;;cA2EvB,sCAAA;;;;;;AA5ImC;cAu1CnC,sBAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,SAAA;EAAA,SACA,MAAA;EAAA,SACA,mBAAA;EAAA,SACA,cAAA,GAAiB,uBAAA;EAAA,SACjB,QAAA,GAAW,uBAAA;AAAA,MAErB,MAAA,CAAO,MAAA,CAAO,oBAAA,EAAsB,QAAA;;;;;KA+VlC,wBAAA;EAAA,SACM,cAAA,GAAiB,IAAA;EAAA,SACjB,kBAAA;EAAA,SACA,uBAAA;AAAA;AAAA,cAyhBE,uBAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,EAC7B,OAAA,GAAS,wBAAA,KACR,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cAqId,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
1
+ {"version":3,"file":"anthropic-provider-internal.d.mts","names":[],"sources":["../../src/providers/anthropic-provider-internal.ts"],"mappings":";;;;;;;;;AA+DA;;KAAY,uBAAA;;AAAuB;AAUnC;;;;AAEiC;AAGjC;KALY,uBAAA;EAAA,SACD,OAAA;EAAA,SACA,sBAAsB;AAAA;AAAA,KAGrB,6BAAA;EAAA,SACD,KAAA,EAAO,gBAA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