@yolk-sdk/agent 0.1.0-canary.59 → 0.1.0-canary.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -48
- package/dist/providers/anthropic/usage.d.mts.map +1 -1
- package/dist/providers/anthropic/usage.mjs +3 -3
- package/dist/providers/anthropic/usage.mjs.map +1 -1
- package/dist/providers/openai/codex-usage.d.mts.map +1 -1
- package/dist/providers/openai/codex-usage.mjs +3 -3
- package/dist/providers/openai/codex-usage.mjs.map +1 -1
- package/dist/providers/openai/provider.d.mts +18 -5
- package/dist/providers/openai/provider.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +79 -47
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/openai-responses-provider-internal.d.mts.map +1 -1
- package/dist/providers/openai-responses-provider-internal.mjs +21 -2
- package/dist/providers/openai-responses-provider-internal.mjs.map +1 -1
- package/dist/providers/subscription-usage-internal.d.mts +7 -1
- package/dist/providers/subscription-usage-internal.d.mts.map +1 -1
- package/dist/providers/subscription-usage-internal.mjs +11 -1
- package/dist/providers/subscription-usage-internal.mjs.map +1 -1
- package/dist/providers/subscription-usage.d.mts +1 -1
- package/dist/providers/subscription-usage.d.mts.map +1 -1
- package/dist/providers/subscription-usage.mjs +2 -0
- package/dist/providers/subscription-usage.mjs.map +1 -1
- package/dist/providers/vercel/ai-gateway-provider.d.mts +25 -0
- package/dist/providers/vercel/ai-gateway-provider.d.mts.map +1 -0
- package/dist/providers/vercel/ai-gateway-provider.mjs +39 -0
- package/dist/providers/vercel/ai-gateway-provider.mjs.map +1 -0
- package/dist/providers/xai/usage.d.mts +17 -0
- package/dist/providers/xai/usage.d.mts.map +1 -0
- package/dist/providers/xai/usage.mjs +131 -0
- package/dist/providers/xai/usage.mjs.map +1 -0
- package/dist/skillset/merge.d.mts +2 -2
- package/dist/skillset/name.d.mts +2 -2
- package/dist/skillset/name.d.mts.map +1 -1
- package/package.json +11 -1
- package/src/providers/anthropic/usage.ts +2 -4
- package/src/providers/openai/codex-usage.ts +2 -4
- package/src/providers/openai/provider.ts +157 -60
- package/src/providers/openai-responses-provider-internal.ts +31 -3
- package/src/providers/subscription-usage-internal.ts +22 -0
- package/src/providers/subscription-usage.ts +7 -1
- package/src/providers/vercel/ai-gateway-provider.ts +69 -0
- package/src/providers/xai/usage.ts +279 -0
package/README.md
CHANGED
|
@@ -17,36 +17,38 @@ Published package metadata requires Node.js 22+.
|
|
|
17
17
|
|
|
18
18
|
## Subpaths
|
|
19
19
|
|
|
20
|
-
| Subpath
|
|
21
|
-
|
|
|
22
|
-
| `@yolk-sdk/agent/protocol`
|
|
23
|
-
| `@yolk-sdk/agent/loop`
|
|
24
|
-
| `@yolk-sdk/agent/loop/testing`
|
|
25
|
-
| `@yolk-sdk/agent/runtime`
|
|
26
|
-
| `@yolk-sdk/agent/client`
|
|
27
|
-
| `@yolk-sdk/agent/compaction`
|
|
28
|
-
| `@yolk-sdk/agent/tools`
|
|
29
|
-
| `@yolk-sdk/agent/react`
|
|
30
|
-
| `@yolk-sdk/agent/oauth`
|
|
31
|
-
| `@yolk-sdk/agent/providers/openai`
|
|
32
|
-
| `@yolk-sdk/agent/providers/openai/codex`
|
|
33
|
-
| `@yolk-sdk/agent/providers/openai/codex-usage`
|
|
34
|
-
| `@yolk-sdk/agent/providers/openai/codex-provider`
|
|
35
|
-
| `@yolk-sdk/agent/providers/openai/provider`
|
|
36
|
-
| `@yolk-sdk/agent/providers/openai/realtime`
|
|
37
|
-
| `@yolk-sdk/agent/providers/openai/speech`
|
|
38
|
-
| `@yolk-sdk/agent/providers/
|
|
39
|
-
| `@yolk-sdk/agent/providers/anthropic
|
|
40
|
-
| `@yolk-sdk/agent/providers/anthropic/
|
|
41
|
-
| `@yolk-sdk/agent/providers/anthropic/
|
|
42
|
-
| `@yolk-sdk/agent/providers/
|
|
43
|
-
| `@yolk-sdk/agent/providers/xai
|
|
44
|
-
| `@yolk-sdk/agent/providers/xai/grok
|
|
45
|
-
| `@yolk-sdk/agent/providers/
|
|
46
|
-
| `@yolk-sdk/agent/
|
|
47
|
-
| `@yolk-sdk/agent/
|
|
48
|
-
| `@yolk-sdk/agent/
|
|
49
|
-
| `@yolk-sdk/agent/voice
|
|
20
|
+
| Subpath | Purpose |
|
|
21
|
+
| ------------------------------------------------------ | -------------------------------------------------------------- |
|
|
22
|
+
| `@yolk-sdk/agent/protocol` | Wire messages, events, content, usage, tool schemas |
|
|
23
|
+
| `@yolk-sdk/agent/loop` | Stateless LLM/tool loop |
|
|
24
|
+
| `@yolk-sdk/agent/loop/testing` | Faux provider and tool executor test helpers |
|
|
25
|
+
| `@yolk-sdk/agent/runtime` | Transcript or append-backed runtime orchestration |
|
|
26
|
+
| `@yolk-sdk/agent/client` | HTTP/NDJSON transport, HITL resume, retry/error state helpers |
|
|
27
|
+
| `@yolk-sdk/agent/compaction` | Host-owned compaction budgets, checkpoints, formatting, retry |
|
|
28
|
+
| `@yolk-sdk/agent/tools` | Tool registry, `makeTool`, subagent/question contracts |
|
|
29
|
+
| `@yolk-sdk/agent/react` | Headless React chat hook, reducer, selectors, and render model |
|
|
30
|
+
| `@yolk-sdk/agent/oauth` | Provider-neutral OAuth token and broker contracts |
|
|
31
|
+
| `@yolk-sdk/agent/providers/openai` | OpenAI/Codex OAuth and broker helpers |
|
|
32
|
+
| `@yolk-sdk/agent/providers/openai/codex` | OpenAI Codex request and auth helpers |
|
|
33
|
+
| `@yolk-sdk/agent/providers/openai/codex-usage` | Codex subscription-allowance snapshots |
|
|
34
|
+
| `@yolk-sdk/agent/providers/openai/codex-provider` | Codex LLM provider factory |
|
|
35
|
+
| `@yolk-sdk/agent/providers/openai/provider` | OpenAI-compatible LLM provider factory |
|
|
36
|
+
| `@yolk-sdk/agent/providers/openai/realtime` | OpenAI Realtime session config and event codecs |
|
|
37
|
+
| `@yolk-sdk/agent/providers/openai/speech` | OpenAI text-to-speech and transcription adapters |
|
|
38
|
+
| `@yolk-sdk/agent/providers/vercel/ai-gateway-provider` | Vercel AI Gateway Chat Completions provider factory |
|
|
39
|
+
| `@yolk-sdk/agent/providers/anthropic` | Anthropic/Claude OAuth and broker helpers |
|
|
40
|
+
| `@yolk-sdk/agent/providers/anthropic/claude` | Claude request and auth helpers |
|
|
41
|
+
| `@yolk-sdk/agent/providers/anthropic/usage` | Claude subscription-allowance snapshots |
|
|
42
|
+
| `@yolk-sdk/agent/providers/anthropic/claude-provider` | Claude LLM provider factory |
|
|
43
|
+
| `@yolk-sdk/agent/providers/xai` | Grok subscription OAuth and token broker helpers |
|
|
44
|
+
| `@yolk-sdk/agent/providers/xai/grok` | Grok subscription request and auth helpers |
|
|
45
|
+
| `@yolk-sdk/agent/providers/xai/grok-provider` | Grok subscription LLM provider factory |
|
|
46
|
+
| `@yolk-sdk/agent/providers/xai/usage` | Grok subscription-allowance snapshots |
|
|
47
|
+
| `@yolk-sdk/agent/providers/subscription-usage` | Shared allowance snapshot and safe error schemas |
|
|
48
|
+
| `@yolk-sdk/agent/skillset` | Portable skill and slash-command parsing/catalogs |
|
|
49
|
+
| `@yolk-sdk/agent/voice` | Voice protocol, controller, tool handler, projection, speech |
|
|
50
|
+
| `@yolk-sdk/agent/voice/browser` | Browser WebRTC voice transport |
|
|
51
|
+
| `@yolk-sdk/agent/voice/react` | Headless browser voice React hook |
|
|
50
52
|
|
|
51
53
|
## Imports
|
|
52
54
|
|
|
@@ -88,7 +90,7 @@ import {
|
|
|
88
90
|
makeAgentChatEventProjectionState,
|
|
89
91
|
useAgentChat
|
|
90
92
|
} from '@yolk-sdk/agent/react'
|
|
91
|
-
import {
|
|
93
|
+
import { makeVercelAiGatewayProviderLayer } from '@yolk-sdk/agent/providers/vercel/ai-gateway-provider'
|
|
92
94
|
```
|
|
93
95
|
|
|
94
96
|
Test helpers live behind their own subpath:
|
|
@@ -153,6 +155,7 @@ limits or apply hidden fallbacks.
|
|
|
153
155
|
| Provider factory | Output-limit field |
|
|
154
156
|
| ---------------------------------- | --------------------- |
|
|
155
157
|
| `makeOpenAiProviderLayer` | `maxCompletionTokens` |
|
|
158
|
+
| `makeVercelAiGatewayProviderLayer` | `maxCompletionTokens` |
|
|
156
159
|
| `makeOpenAiCodexProviderLayer` | none |
|
|
157
160
|
| `makeAnthropicClaudeProviderLayer` | `maxTokens` |
|
|
158
161
|
| `makeXAiGrokProviderLayer` | `maxOutputTokens` |
|
|
@@ -163,6 +166,15 @@ require the matching limit configuration. ChatGPT subscription Codex rejects ven
|
|
|
163
166
|
optional deprecated `maxOutputTokens` compatibility field. `OpenAiProviderLayer` reads both
|
|
164
167
|
`OPENAI_API_KEY` and integer `OPENAI_MAX_COMPLETION_TOKENS` through Effect Config.
|
|
165
168
|
|
|
169
|
+
Vercel AI Gateway uses its OpenAI-compatible JSON Chat Completions endpoint. Pass either an AI
|
|
170
|
+
Gateway API key or Vercel OIDC token as `apiKey`; `maxCompletionTokens` is sent as Gateway
|
|
171
|
+
`max_tokens`. The env-backed `VercelAiGatewayProviderLayer` tries `AI_GATEWAY_API_KEY` first, then
|
|
172
|
+
`VERCEL_OIDC_TOKEN`, and requires integer
|
|
173
|
+
`AI_GATEWAY_MAX_COMPLETION_TOKENS`. Model ids are opaque `provider/model` strings. Hosts may set
|
|
174
|
+
`fallbackModels`, provider `routing`, and optional `http-referer` / `x-title` attribution headers.
|
|
175
|
+
Required authorization and JSON headers cannot be replaced through `extraHeaders`. Only override
|
|
176
|
+
`chatCompletionsUrl` with a trusted proxy because it receives the bearer credential.
|
|
177
|
+
|
|
166
178
|
Grok subscription access uses `https://cli-chat-proxy.grok.com/v1/responses`, not the xAI developer
|
|
167
179
|
API-key endpoint. The adapter sends the required CLI-session and model-routing headers and rejects
|
|
168
180
|
mismatched or expired access-token envelopes before HTTP. The package exports browser-PKCE and
|
|
@@ -202,19 +214,21 @@ policy and emits protocol-visible retry/error state:
|
|
|
202
214
|
- `buildAgentChatItems` can project active retry state as an `AgentChatItem` with `_tag: 'Retry'`.
|
|
203
215
|
- Anthropic prompt-too-long responses become non-retryable `context_overflow`; the host-owned
|
|
204
216
|
compaction wrapper may compact and retry once.
|
|
205
|
-
- Anthropic `max_tokens`
|
|
206
|
-
|
|
217
|
+
- Anthropic `max_tokens` and OpenAI-compatible `finish_reason: "length"` / `"content_filter"`
|
|
218
|
+
completions fail as non-retryable `invalid_response` instead of reporting truncated or filtered
|
|
219
|
+
output as complete.
|
|
207
220
|
|
|
208
221
|
Raw provider response bodies stay out of protocol/UI. Hosts own durable persistence and display of
|
|
209
222
|
typed retry/error state.
|
|
210
223
|
|
|
211
224
|
## Subscription allowance snapshots
|
|
212
225
|
|
|
213
|
-
The Claude and
|
|
214
|
-
reset windows. Claude
|
|
215
|
-
normalizes
|
|
216
|
-
|
|
217
|
-
host-owned `OAuthAccessToken` and provide an
|
|
226
|
+
The Claude, Codex, and Grok usage adapters read best-effort consumer subscription allowance
|
|
227
|
+
percentages and reset windows. Claude normalizes its aggregate five-hour and seven-day windows;
|
|
228
|
+
Codex normalizes primary and secondary rate-limit windows; Grok normalizes its aggregate shared
|
|
229
|
+
credit allowance. Additional provider-specific buckets are ignored. These private provider
|
|
230
|
+
endpoints may change without notice. Pass a fresh host-owned `OAuthAccessToken` and provide an
|
|
231
|
+
Effect `HttpClient`:
|
|
218
232
|
|
|
219
233
|
```ts
|
|
220
234
|
import { Effect } from 'effect'
|
|
@@ -228,13 +242,18 @@ const snapshot = await fetchOpenAiCodexSubscriptionUsage(hostOAuthAccessToken).p
|
|
|
228
242
|
```
|
|
229
243
|
|
|
230
244
|
Use `fetchAnthropicClaudeSubscriptionUsage` from
|
|
231
|
-
`@yolk-sdk/agent/providers/anthropic/usage` for Claude.
|
|
232
|
-
`
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
245
|
+
`@yolk-sdk/agent/providers/anthropic/usage` for Claude. Use
|
|
246
|
+
`fetchXAiGrokSubscriptionUsage` from `@yolk-sdk/agent/providers/xai/usage` for Grok and pass the
|
|
247
|
+
actual authenticated xAI `user_id` as `xAiUserId`. The generic token `accountId` is not interpreted
|
|
248
|
+
as an xAI user id. Also pass your host integration's truthful version as `clientVersion`; the
|
|
249
|
+
adapter sends it with `x-grok-client-mode: headless` and never claims an official Grok client
|
|
250
|
+
version.
|
|
251
|
+
|
|
252
|
+
Provider adapters return an immutable Effect `Chunk` of semantic window ids, percentages, and
|
|
253
|
+
optional reset/duration fields; hosts own labels, polling, persistence, stale-data policy, alert
|
|
254
|
+
thresholds, billing interpretation, and UI. Configure `requestTimeoutMs` at the server integration
|
|
255
|
+
boundary. Endpoint origins stay fixed, and `FetchHttpClient.layer` is configured for manual
|
|
256
|
+
redirects. A custom `HttpClient` must not follow redirects for these credential-bearing requests.
|
|
238
257
|
|
|
239
258
|
Subscription allowance snapshots are separate from protocol `AgentUsage`, which accounts for tokens
|
|
240
259
|
used by model requests and nested model work.
|
|
@@ -300,8 +319,9 @@ inside one source fail validation. Hosts own file discovery, storage, enablement
|
|
|
300
319
|
- `AudioPart` with `InlineBase64`, `Url`, or host-owned `Ref` source
|
|
301
320
|
|
|
302
321
|
Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
|
|
303
|
-
`refAttachmentSource`. Providers can pass through supported media URLs: OpenAI Chat
|
|
304
|
-
URLs; OpenAI Codex supports image and document URLs; Anthropic supports image
|
|
322
|
+
`refAttachmentSource`. Providers can pass through supported media URLs: OpenAI Chat and Vercel AI
|
|
323
|
+
Gateway support image URLs; OpenAI Codex supports image and document URLs; Anthropic supports image
|
|
324
|
+
and PDF URLs. The Grok
|
|
305
325
|
Responses lowerer can encode image URLs/data URLs, but hosts should enable image capability only for
|
|
306
326
|
subscription models they have verified accept image input. Use
|
|
307
327
|
inline base64 for simple apps, durable URLs for app-owned uploads, or persist `Ref` values and call
|
|
@@ -391,7 +411,7 @@ replay.
|
|
|
391
411
|
|
|
392
412
|
## Parallel tool calls
|
|
393
413
|
|
|
394
|
-
OpenAI, OpenAI Codex, and Grok requests enable vendor parallel tool calls when tools are available. The
|
|
414
|
+
OpenAI, Vercel AI Gateway, OpenAI Codex, and Grok requests enable vendor parallel tool calls when tools are available. The
|
|
395
415
|
Codex stream adapter preserves every sibling function call and suppresses final-response replays
|
|
396
416
|
by call id. The loop executes calls emitted in the same model turn concurrently, bounded by the
|
|
397
417
|
host-configured `LoopConfig.toolConcurrency`; dependent work waits for the next model turn.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;cAoBa,mCAAA;AAAA,KAED,uCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cAoBd,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAuDvC,qCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,uCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
|
|
2
|
-
import { canonicalSubscriptionUsageInstant,
|
|
2
|
+
import { canonicalSubscriptionUsageInstant, executeAndReadProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
|
|
3
3
|
import { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from "./claude.mjs";
|
|
4
4
|
import { Chunk, Clock, Effect } from "effect";
|
|
5
5
|
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
@@ -56,7 +56,7 @@ const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.ge
|
|
|
56
56
|
provider: anthropicClaudeProviderId,
|
|
57
57
|
reason: "invalid_request_timeout"
|
|
58
58
|
}));
|
|
59
|
-
return yield* parseAnthropicClaudeSubscriptionUsage(yield*
|
|
59
|
+
return yield* parseAnthropicClaudeSubscriptionUsage(yield* executeAndReadProviderSubscriptionUsageJson({
|
|
60
60
|
provider: anthropicClaudeProviderId,
|
|
61
61
|
client: yield* HttpClient.HttpClient,
|
|
62
62
|
request: HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(HttpClientRequest.setHeaders({
|
|
@@ -65,7 +65,7 @@ const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.ge
|
|
|
65
65
|
"anthropic-beta": "oauth-2025-04-20"
|
|
66
66
|
})),
|
|
67
67
|
timeoutMs: requestTimeoutMs
|
|
68
|
-
})
|
|
68
|
+
}), new Date(yield* Clock.currentTimeMillis).toISOString());
|
|
69
69
|
}).pipe(Effect.withSpan("AnthropicClaudeSubscriptionUsage.fetch"));
|
|
70
70
|
//#endregion
|
|
71
71
|
export { anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.mjs","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from './claude.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n
|
|
1
|
+
{"version":3,"file":"usage.mjs","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from './claude.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeAndReadProviderSubscriptionUsageJson,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const anthropicClaudeSubscriptionUsageUrl = 'https://api.anthropic.com/api/oauth/usage'\n\nexport type AnthropicClaudeSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\nconst NullableString = Schema.NullOr(Schema.String)\n\nclass AnthropicClaudeSubscriptionUsageWindowWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWindowWire>(\n 'AnthropicClaudeSubscriptionUsageWindowWire'\n)({\n utilization: Schema.optional(NullableNumber),\n resets_at: Schema.optional(NullableString)\n}) {}\n\nclass AnthropicClaudeSubscriptionUsageWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWire>(\n 'AnthropicClaudeSubscriptionUsageWire'\n)({\n five_hour: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),\n seven_day: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))\n}) {}\n\nexport const parseAnthropicClaudeSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: AnthropicClaudeSubscriptionUsageWindowWire | null | undefined,\n id: 'five-hour' | 'seven-day'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.utilization)) {\n return\n }\n\n const resetValue = wire.resets_at === null ? undefined : wire.resets_at\n const resetsAt =\n resetValue === undefined ? undefined : canonicalSubscriptionUsageInstant(resetValue)\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.utilization,\n ...(resetsAt === undefined ? {} : { resetsAt })\n })\n )\n }\n\n append(decoded.five_hour, 'five-hour')\n append(decoded.seven_day, 'seven-day')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: anthropicClaudeProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('AnthropicClaudeSubscriptionUsage.parse')\n )\n}\n\nexport const fetchAnthropicClaudeSubscriptionUsage = (\n token: OAuthAccessToken,\n options: AnthropicClaudeSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== anthropicClaudeProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseAnthropicClaudeSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('AnthropicClaudeSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAoBA,MAAa,sCAAsC;AAMnD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAClD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,6CAAN,cAAyD,OAAO,MAC9D,4CACF,EAAE;CACA,aAAa,OAAO,SAAS,cAAc;CAC3C,WAAW,OAAO,SAAS,cAAc;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;CACpF,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;AACtF,CAAC,EAAE,CAAC;AAEJ,MAAa,yCACX,OACA,cAC6F;CAC7F,MAAM,qBAAqB,kCAAkC,SAAS;CAEtE,IAAI,uBAAuB,KAAA,GACzB,OAAO,OAAO,KACZ,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH;CAGF,OAAO,OAAO,oBAAoB,oCAAoC,EAAE,KAAK,EAAE,KAC7E,OAAO,KAAI,YAAW;EACpB,MAAM,UAAkD,CAAC;EACzD,MAAM,UACJ,MACA,OACG;GACH,IAAI,CAAC,8BAA8B,MAAM,WA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
1
|
-
{"version":3,"file":"codex-usage.d.mts","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"codex-usage.d.mts","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"mappings":";;;;;;cAqBa,+BAAA;AAAA,KAED,mCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cA2Bd,iCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAiEvC,iCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,mCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
|
|
2
|
-
import { canonicalSubscriptionUsageInstant,
|
|
2
|
+
import { canonicalSubscriptionUsageInstant, executeAndReadProviderSubscriptionUsageJson, positiveSubscriptionUsageNumber, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
|
|
3
3
|
import { openAiCodexProviderId } from "./codex.mjs";
|
|
4
4
|
import { Chunk, Clock, Effect } from "effect";
|
|
5
5
|
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
@@ -67,7 +67,7 @@ const fetchOpenAiCodexSubscriptionUsage = (token, options = {}) => Effect.gen(fu
|
|
|
67
67
|
provider: openAiCodexProviderId,
|
|
68
68
|
reason: "invalid_request_timeout"
|
|
69
69
|
}));
|
|
70
|
-
return yield* parseOpenAiCodexSubscriptionUsage(yield*
|
|
70
|
+
return yield* parseOpenAiCodexSubscriptionUsage(yield* executeAndReadProviderSubscriptionUsageJson({
|
|
71
71
|
provider: openAiCodexProviderId,
|
|
72
72
|
client: yield* HttpClient.HttpClient,
|
|
73
73
|
request: HttpClientRequest.get(openAiCodexSubscriptionUsageUrl).pipe(HttpClientRequest.setHeaders({
|
|
@@ -76,7 +76,7 @@ const fetchOpenAiCodexSubscriptionUsage = (token, options = {}) => Effect.gen(fu
|
|
|
76
76
|
"chatgpt-account-id": accountId
|
|
77
77
|
})),
|
|
78
78
|
timeoutMs: requestTimeoutMs
|
|
79
|
-
})
|
|
79
|
+
}), new Date(yield* Clock.currentTimeMillis).toISOString());
|
|
80
80
|
}).pipe(Effect.withSpan("OpenAiCodexSubscriptionUsage.fetch"));
|
|
81
81
|
//#endregion
|
|
82
82
|
export { fetchOpenAiCodexSubscriptionUsage, openAiCodexSubscriptionUsageUrl, parseOpenAiCodexSubscriptionUsage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-usage.mjs","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { openAiCodexProviderId } from './codex.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n
|
|
1
|
+
{"version":3,"file":"codex-usage.mjs","names":[],"sources":["../../../src/providers/openai/codex-usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { openAiCodexProviderId } from './codex.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeAndReadProviderSubscriptionUsageJson,\n positiveSubscriptionUsageNumber,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const openAiCodexSubscriptionUsageUrl = 'https://chatgpt.com/backend-api/wham/usage'\n\nexport type OpenAiCodexSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\n\nclass OpenAiCodexSubscriptionUsageWindowWire extends Schema.Class<OpenAiCodexSubscriptionUsageWindowWire>(\n 'OpenAiCodexSubscriptionUsageWindowWire'\n)({\n used_percent: Schema.optional(NullableNumber),\n limit_window_seconds: Schema.optional(NullableNumber),\n reset_after_seconds: Schema.optional(NullableNumber),\n reset_at: Schema.optional(NullableNumber)\n}) {}\n\nclass OpenAiCodexSubscriptionRateLimitWire extends Schema.Class<OpenAiCodexSubscriptionRateLimitWire>(\n 'OpenAiCodexSubscriptionRateLimitWire'\n)({\n primary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire)),\n secondary_window: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionUsageWindowWire))\n}) {}\n\nclass OpenAiCodexSubscriptionUsageWire extends Schema.Class<OpenAiCodexSubscriptionUsageWire>(\n 'OpenAiCodexSubscriptionUsageWire'\n)({\n rate_limit: Schema.optional(Schema.NullOr(OpenAiCodexSubscriptionRateLimitWire))\n}) {}\n\nexport const parseOpenAiCodexSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(OpenAiCodexSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: OpenAiCodexSubscriptionUsageWindowWire | null | undefined,\n id: 'primary' | 'secondary'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.used_percent)) {\n return\n }\n\n const resetAt = wire.reset_at\n const resetsAt =\n resetAt === null || resetAt === undefined\n ? undefined\n : canonicalSubscriptionUsageInstant(resetAt)\n const resetsAfterSeconds = positiveSubscriptionUsageNumber(wire.reset_after_seconds)\n ? wire.reset_after_seconds\n : undefined\n const windowDurationMinutes = positiveSubscriptionUsageNumber(wire.limit_window_seconds)\n ? wire.limit_window_seconds / 60\n : undefined\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.used_percent,\n ...(resetsAt === undefined ? {} : { resetsAt }),\n ...(resetsAfterSeconds === undefined ? {} : { resetsAfterSeconds }),\n ...(windowDurationMinutes === undefined ? {} : { windowDurationMinutes })\n })\n )\n }\n\n append(decoded.rate_limit?.primary_window, 'primary')\n append(decoded.rate_limit?.secondary_window, 'secondary')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: openAiCodexProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: openAiCodexProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('OpenAiCodexSubscriptionUsage.parse')\n )\n}\n\nexport const fetchOpenAiCodexSubscriptionUsage = (\n token: OAuthAccessToken,\n options: OpenAiCodexSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== openAiCodexProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const accountId = token.accountId?.trim()\n\n if (accountId === undefined || accountId.length === 0) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'missing_account_id'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: openAiCodexProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(openAiCodexSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n authorization: `Bearer ${token.accessToken}`,\n 'chatgpt-account-id': accountId\n })\n )\n const json = yield* executeAndReadProviderSubscriptionUsageJson({\n provider: openAiCodexProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseOpenAiCodexSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('OpenAiCodexSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAqBA,MAAa,kCAAkC;AAM/C,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,yCAAN,cAAqD,OAAO,MAC1D,wCACF,EAAE;CACA,cAAc,OAAO,SAAS,cAAc;CAC5C,sBAAsB,OAAO,SAAS,cAAc;CACpD,qBAAqB,OAAO,SAAS,cAAc;CACnD,UAAU,OAAO,SAAS,cAAc;AAC1C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,gBAAgB,OAAO,SAAS,OAAO,OAAO,sCAAsC,CAAC;CACrF,kBAAkB,OAAO,SAAS,OAAO,OAAO,sCAAsC,CAAC;AACzF,CAAC,EAAE,CAAC;AAEJ,IAAM,mCAAN,cAA+C,OAAO,MACpD,kCACF,EAAE,EACA,YAAY,OAAO,SAAS,OAAO,OA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aAAa;CACtB,IAAI,MAAM,aAAA,gBACR,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,YAAY,MAAM,WAAW,KAAK;CAExC,IAAI,cAAc,KAAA,KAAa,UAAU,WAAW,GAClD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAGF,MAAM,mBAAmB,QAAQ,oBAAA;CAEjC,IAAI,CAAC,sCAAsC,gBAAgB,GACzD,OAAO,OAAO,OAAO,KACnB,4CAA4C,KAAK;EAC/C,UAAU;EACV,QAAQ;CACV,CAAC,CACH;CAmBF,OAAO,OAAO,kCAAkC,OAR5B,4CAA4C;EAC9D,UAAU;EACV,QAAA,OAVoB,WAAW;EAW/B,SAVc,kBAAkB,IAAI,+BAA+B,EAAE,KACrE,kBAAkB,WAAW;GAC3B,QAAQ;GACR,eAAe,UAAU,MAAM;GAC/B,sBAAsB;EACxB,CAAC,CAKK;EACN,WAAW;CACb,CAAC,GACiB,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEG,CAAC;AACjE,CAAC,EAAE,KAAK,OAAO,SAAS,oCAAoC,CAAC"}
|
|
@@ -3,10 +3,17 @@ import { HttpClient } from "effect/unstable/http";
|
|
|
3
3
|
import { LLMError, LLMProvider, LLMRequest } from "@yolk-sdk/agent/loop";
|
|
4
4
|
|
|
5
5
|
//#region src/providers/openai/provider.d.ts
|
|
6
|
+
type OpenAiProviderIdentity = {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
};
|
|
6
10
|
type OpenAiProviderConfig = {
|
|
7
11
|
readonly chatCompletionsUrl?: string;
|
|
8
|
-
readonly maxCompletionTokens: number;
|
|
9
|
-
readonly
|
|
12
|
+
readonly maxCompletionTokens: number; /** Selects the compatible endpoint's output-limit parameter. Defaults to `max_completion_tokens`. */
|
|
13
|
+
readonly completionTokenField?: 'max_completion_tokens' | 'max_tokens';
|
|
14
|
+
readonly extraHeaders?: Readonly<Record<string, string>>; /** Adds compatible endpoint extensions; canonical model/messages/limit/stream fields win. */
|
|
15
|
+
readonly extraBody?: Readonly<Record<string, unknown>>; /** Customizes safe error metadata for a branded OpenAI-compatible endpoint. */
|
|
16
|
+
readonly providerIdentity?: OpenAiProviderIdentity;
|
|
10
17
|
readonly apiKey: Redacted.Redacted<string>;
|
|
11
18
|
};
|
|
12
19
|
type OpenAiTextContentPart = {
|
|
@@ -54,13 +61,19 @@ type OpenAiTool = {
|
|
|
54
61
|
type OpenAiRequestBody = {
|
|
55
62
|
readonly model: string;
|
|
56
63
|
readonly messages: ReadonlyArray<OpenAiMessage>;
|
|
57
|
-
readonly max_completion_tokens
|
|
64
|
+
readonly max_completion_tokens?: number;
|
|
65
|
+
readonly max_tokens?: number;
|
|
66
|
+
readonly stream: false;
|
|
58
67
|
readonly tools?: ReadonlyArray<OpenAiTool>;
|
|
59
68
|
readonly parallel_tool_calls?: true;
|
|
60
69
|
};
|
|
61
|
-
|
|
70
|
+
type OpenAiRequestBodyConfig = {
|
|
62
71
|
readonly maxCompletionTokens: number;
|
|
63
|
-
|
|
72
|
+
readonly completionTokenField?: 'max_completion_tokens' | 'max_tokens';
|
|
73
|
+
readonly extraBody?: Readonly<Record<string, unknown>>;
|
|
74
|
+
readonly providerName?: string;
|
|
75
|
+
};
|
|
76
|
+
declare const toOpenAiRequestBody: (request: LLMRequest, config: OpenAiRequestBodyConfig) => Effect.Effect<OpenAiRequestBody, LLMError>;
|
|
64
77
|
declare const makeOpenAiProviderLayer: (config: OpenAiProviderConfig) => Layer.Layer<LLMProvider, never, HttpClient.HttpClient>;
|
|
65
78
|
declare const OpenAiProviderLayer: Layer.Layer<LLMProvider, LLMError, never>;
|
|
66
79
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","names":[],"sources":["../../../src/providers/openai/provider.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"provider.d.mts","names":[],"sources":["../../../src/providers/openai/provider.ts"],"mappings":";;;;;KA6CK,sBAAA;EAAA,SACM,EAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGH,oBAAA;EAAA,SACD,kBAAA;EAAA,SACA,mBAAA,UAFC;EAAA,SAID,oBAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA,mBAAA;EAAA,SAExB,SAAA,GAAY,QAAA,CAAS,MAAA,oBAAA;EAAA,SAErB,gBAAA,GAAmB,sBAAA;EAAA,SACnB,MAAA,EAAQ,QAAA,CAAS,QAAA;AAAA;AAAA,KAGvB,qBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGV,sBAAA;EAAA,SACM,IAAA;EAAA,SACA,SAAA;IAAA,SACE,GAAA;EAAA;AAAA;AAAA,KAIR,iBAAA,YAA6B,aAAA,CAAc,qBAAA,GAAwB,sBAAA;AAAA,KAEnE,cAAA;EAAA,SACM,EAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA;IAAA,SACE,IAAA;IAAA,SACA,SAAA;EAAA;AAAA;AAAA,KAIR,aAAA;EAAA,SACU,IAAA;EAAA,SAAyB,OAAA;AAAA;EAAA,SACzB,IAAA;EAAA,SAAuB,OAAA,EAAS,iBAAA;AAAA;EAAA,SAEhC,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,aAAA,CAAc,cAAA;AAAA;EAAA,SAE3B,IAAA;EAAA,SAAuB,YAAA;EAAA,SAA+B,OAAA;AAAA;AAAA,KAEhE,UAAA;EAAA,SACM,IAAA;EAAA,SACA,QAAA;IAAA,SACE,IAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA;AAAA;AAAA,KAIR,iBAAA;EAAA,SACM,KAAA;EAAA,SACA,QAAA,EAAU,aAAA,CAAc,aAAA;EAAA,SACxB,qBAAA;EAAA,SACA,UAAA;EAAA,SACA,MAAA;EA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