@yolk-sdk/agent 0.1.0-canary.57 → 0.1.0-canary.59
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 +74 -13
- package/dist/providers/anthropic/usage.d.mts +15 -0
- package/dist/providers/anthropic/usage.d.mts.map +1 -0
- package/dist/providers/anthropic/usage.mjs +73 -0
- package/dist/providers/anthropic/usage.mjs.map +1 -0
- package/dist/providers/openai/codex-provider.d.mts +10 -11
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +27 -549
- package/dist/providers/openai/codex-provider.mjs.map +1 -1
- package/dist/providers/openai/codex-usage.d.mts +15 -0
- package/dist/providers/openai/codex-usage.d.mts.map +1 -0
- package/dist/providers/openai/codex-usage.mjs +84 -0
- package/dist/providers/openai/codex-usage.mjs.map +1 -0
- package/dist/providers/openai-responses-provider-internal.d.mts +106 -0
- package/dist/providers/openai-responses-provider-internal.d.mts.map +1 -0
- package/dist/providers/openai-responses-provider-internal.mjs +640 -0
- package/dist/providers/openai-responses-provider-internal.mjs.map +1 -0
- package/dist/providers/subscription-usage-internal.d.mts +20 -0
- package/dist/providers/subscription-usage-internal.d.mts.map +1 -0
- package/dist/providers/subscription-usage-internal.mjs +52 -0
- package/dist/providers/subscription-usage-internal.mjs.map +1 -0
- package/dist/providers/subscription-usage.d.mts +49 -0
- package/dist/providers/subscription-usage.d.mts.map +1 -0
- package/dist/providers/subscription-usage.mjs +55 -0
- package/dist/providers/subscription-usage.mjs.map +1 -0
- package/dist/providers/xai/grok-provider.d.mts +79 -0
- package/dist/providers/xai/grok-provider.d.mts.map +1 -0
- package/dist/providers/xai/grok-provider.mjs +32 -0
- package/dist/providers/xai/grok-provider.mjs.map +1 -0
- package/dist/providers/xai/grok.d.mts +60 -0
- package/dist/providers/xai/grok.d.mts.map +1 -0
- package/dist/providers/xai/grok.mjs +104 -0
- package/dist/providers/xai/grok.mjs.map +1 -0
- package/dist/providers/xai/index.d.mts +2 -0
- package/dist/providers/xai/index.mjs +2 -0
- package/package.json +31 -1
- package/src/providers/anthropic/usage.ts +150 -0
- package/src/providers/openai/codex-provider.ts +44 -1032
- package/src/providers/openai/codex-usage.ts +179 -0
- package/src/providers/openai-responses-provider-internal.ts +1342 -0
- package/src/providers/subscription-usage-internal.ts +105 -0
- package/src/providers/subscription-usage.ts +88 -0
- package/src/providers/xai/grok-provider.ts +129 -0
- package/src/providers/xai/grok.ts +161 -0
- package/src/providers/xai/index.ts +22 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Root export is intentionally tiny. Import feature APIs from explicit subpaths.
|
|
|
10
10
|
pnpm add @yolk-sdk/agent@canary effect
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Add `react` if you use `@yolk-sdk/agent/react`.
|
|
13
|
+
Add `react` if you use `@yolk-sdk/agent/react` or `@yolk-sdk/agent/voice/react`.
|
|
14
14
|
|
|
15
15
|
Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
|
|
16
16
|
Published package metadata requires Node.js 22+.
|
|
@@ -30,13 +30,19 @@ Published package metadata requires Node.js 22+.
|
|
|
30
30
|
| `@yolk-sdk/agent/oauth` | Provider-neutral OAuth token and broker contracts |
|
|
31
31
|
| `@yolk-sdk/agent/providers/openai` | OpenAI/Codex OAuth and broker helpers |
|
|
32
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 |
|
|
33
34
|
| `@yolk-sdk/agent/providers/openai/codex-provider` | Codex LLM provider factory |
|
|
34
35
|
| `@yolk-sdk/agent/providers/openai/provider` | OpenAI-compatible LLM provider factory |
|
|
35
36
|
| `@yolk-sdk/agent/providers/openai/realtime` | OpenAI Realtime session config and event codecs |
|
|
36
37
|
| `@yolk-sdk/agent/providers/openai/speech` | OpenAI text-to-speech and transcription adapters |
|
|
37
38
|
| `@yolk-sdk/agent/providers/anthropic` | Anthropic/Claude OAuth and broker helpers |
|
|
38
39
|
| `@yolk-sdk/agent/providers/anthropic/claude` | Claude request and auth helpers |
|
|
40
|
+
| `@yolk-sdk/agent/providers/anthropic/usage` | Claude subscription-allowance snapshots |
|
|
39
41
|
| `@yolk-sdk/agent/providers/anthropic/claude-provider` | Claude LLM provider factory |
|
|
42
|
+
| `@yolk-sdk/agent/providers/xai` | Grok subscription OAuth and token broker helpers |
|
|
43
|
+
| `@yolk-sdk/agent/providers/xai/grok` | Grok subscription request and auth helpers |
|
|
44
|
+
| `@yolk-sdk/agent/providers/xai/grok-provider` | Grok subscription LLM provider factory |
|
|
45
|
+
| `@yolk-sdk/agent/providers/subscription-usage` | Shared allowance snapshot and safe error schemas |
|
|
40
46
|
| `@yolk-sdk/agent/skillset` | Portable skill and slash-command parsing/catalogs |
|
|
41
47
|
| `@yolk-sdk/agent/voice` | Voice protocol, controller, tool handler, projection, speech |
|
|
42
48
|
| `@yolk-sdk/agent/voice/browser` | Browser WebRTC voice transport |
|
|
@@ -91,6 +97,18 @@ Test helpers live behind their own subpath:
|
|
|
91
97
|
import { FauxProvider, Reply, TestToolExecutor } from '@yolk-sdk/agent/loop/testing'
|
|
92
98
|
```
|
|
93
99
|
|
|
100
|
+
## Headless React chat
|
|
101
|
+
|
|
102
|
+
`useAgentChat` exposes protocol messages, render-oriented chat messages, run/error/waiting state,
|
|
103
|
+
and actions for submit, stop, edit, regenerate, delete, tool approval, and question responses. The
|
|
104
|
+
package supplies no components, styling, auth, or route ownership, and React remains an optional
|
|
105
|
+
peer used only by React subpaths.
|
|
106
|
+
|
|
107
|
+
By default the hook streams HTTP/NDJSON through `@yolk-sdk/agent/client`. Pass an
|
|
108
|
+
`AgentChatTransport` through the `transport` option to use another runtime. A custom transport
|
|
109
|
+
receives the transcript, session/model options, HITL responses, and an `AbortSignal`, and returns an
|
|
110
|
+
`AsyncIterable<AgentEvent>`; the host still owns endpoint auth and persistence.
|
|
111
|
+
|
|
94
112
|
## Quick start
|
|
95
113
|
|
|
96
114
|
```ts
|
|
@@ -137,12 +155,22 @@ limits or apply hidden fallbacks.
|
|
|
137
155
|
| `makeOpenAiProviderLayer` | `maxCompletionTokens` |
|
|
138
156
|
| `makeOpenAiCodexProviderLayer` | none |
|
|
139
157
|
| `makeAnthropicClaudeProviderLayer` | `maxTokens` |
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`
|
|
145
|
-
`
|
|
158
|
+
| `makeXAiGrokProviderLayer` | `maxOutputTokens` |
|
|
159
|
+
|
|
160
|
+
The public `toOpenAiRequestBody`, `toAnthropicClaudeRequestBody`, and `toXAiGrokRequestBody` helpers
|
|
161
|
+
require the matching limit configuration. ChatGPT subscription Codex rejects vendor
|
|
162
|
+
`max_output_tokens`, so `makeOpenAiCodexProviderLayer` and `toOpenAiCodexRequestBody` ignore the
|
|
163
|
+
optional deprecated `maxOutputTokens` compatibility field. `OpenAiProviderLayer` reads both
|
|
164
|
+
`OPENAI_API_KEY` and integer `OPENAI_MAX_COMPLETION_TOKENS` through Effect Config.
|
|
165
|
+
|
|
166
|
+
Grok subscription access uses `https://cli-chat-proxy.grok.com/v1/responses`, not the xAI developer
|
|
167
|
+
API-key endpoint. The adapter sends the required CLI-session and model-routing headers and rejects
|
|
168
|
+
mismatched or expired access-token envelopes before HTTP. The package exports browser-PKCE and
|
|
169
|
+
device-flow constants; hosts own the callback listener or device polling, token exchange/refresh,
|
|
170
|
+
secure storage, and model discovery. Only set `responsesUrl` to a trusted proxy because it receives
|
|
171
|
+
the OAuth bearer. xAI controls the public CLI OAuth client and private, unsupported proxy contract,
|
|
172
|
+
so hosts should treat those surfaces as changeable and confirm that their use complies with xAI
|
|
173
|
+
terms.
|
|
146
174
|
|
|
147
175
|
Set optional `reasoningEffort` on `run` or `runRuntime`; provider adapters lower it to vendor
|
|
148
176
|
configuration. Anthropic Claude forwards `low`, `medium`, `high`, and `xhigh` through
|
|
@@ -180,6 +208,37 @@ policy and emits protocol-visible retry/error state:
|
|
|
180
208
|
Raw provider response bodies stay out of protocol/UI. Hosts own durable persistence and display of
|
|
181
209
|
typed retry/error state.
|
|
182
210
|
|
|
211
|
+
## Subscription allowance snapshots
|
|
212
|
+
|
|
213
|
+
The Claude and Codex usage adapters read best-effort consumer subscription allowance percentages and
|
|
214
|
+
reset windows. Claude currently normalizes its aggregate five-hour and seven-day windows; Codex
|
|
215
|
+
normalizes its primary and secondary rate-limit windows. Additional provider-specific buckets are
|
|
216
|
+
ignored. These private provider endpoints may change without notice. Pass a fresh
|
|
217
|
+
host-owned `OAuthAccessToken` and provide an Effect `HttpClient`:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { Effect } from 'effect'
|
|
221
|
+
import { FetchHttpClient } from 'effect/unstable/http'
|
|
222
|
+
import { fetchOpenAiCodexSubscriptionUsage } from '@yolk-sdk/agent/providers/openai/codex-usage'
|
|
223
|
+
|
|
224
|
+
const snapshot = await fetchOpenAiCodexSubscriptionUsage(hostOAuthAccessToken).pipe(
|
|
225
|
+
Effect.provide(FetchHttpClient.layer),
|
|
226
|
+
Effect.runPromise
|
|
227
|
+
)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Use `fetchAnthropicClaudeSubscriptionUsage` from
|
|
231
|
+
`@yolk-sdk/agent/providers/anthropic/usage` for Claude. Provider adapters return an immutable Effect
|
|
232
|
+
`Chunk` of semantic window ids, percentages, and optional reset/duration fields; hosts own labels,
|
|
233
|
+
polling, persistence, stale-data
|
|
234
|
+
policy, alert thresholds, billing interpretation, and UI. Configure `requestTimeoutMs` at the
|
|
235
|
+
server integration boundary. Endpoint origins stay fixed, and `FetchHttpClient.layer` is configured
|
|
236
|
+
for manual redirects. A custom `HttpClient` must not follow redirects for these credential-bearing
|
|
237
|
+
requests.
|
|
238
|
+
|
|
239
|
+
Subscription allowance snapshots are separate from protocol `AgentUsage`, which accounts for tokens
|
|
240
|
+
used by model requests and nested model work.
|
|
241
|
+
|
|
183
242
|
## Usage accounting
|
|
184
243
|
|
|
185
244
|
Provider `LLMUsage` events are additive deltas. Adapters normalize vendor counters before emitting;
|
|
@@ -242,7 +301,9 @@ inside one source fail validation. Hosts own file discovery, storage, enablement
|
|
|
242
301
|
|
|
243
302
|
Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
|
|
244
303
|
`refAttachmentSource`. Providers can pass through supported media URLs: OpenAI Chat supports image
|
|
245
|
-
URLs; OpenAI Codex supports image and document URLs; Anthropic supports image and PDF URLs.
|
|
304
|
+
URLs; OpenAI Codex supports image and document URLs; Anthropic supports image and PDF URLs. The Grok
|
|
305
|
+
Responses lowerer can encode image URLs/data URLs, but hosts should enable image capability only for
|
|
306
|
+
subscription models they have verified accept image input. Use
|
|
246
307
|
inline base64 for simple apps, durable URLs for app-owned uploads, or persist `Ref` values and call
|
|
247
308
|
`resolveContentAttachmentSources` at your storage boundary before provider execution. Host apps own
|
|
248
309
|
upload, auth, retention, URL durability, and ref hydration policy.
|
|
@@ -330,7 +391,7 @@ replay.
|
|
|
330
391
|
|
|
331
392
|
## Parallel tool calls
|
|
332
393
|
|
|
333
|
-
OpenAI
|
|
394
|
+
OpenAI, OpenAI Codex, and Grok requests enable vendor parallel tool calls when tools are available. The
|
|
334
395
|
Codex stream adapter preserves every sibling function call and suppresses final-response replays
|
|
335
396
|
by call id. The loop executes calls emitted in the same model turn concurrently, bounded by the
|
|
336
397
|
host-configured `LoopConfig.toolConcurrency`; dependent work waits for the next model turn.
|
|
@@ -405,10 +466,10 @@ handler, approval HITL, transcript projection, and one-shot TTS/STT contracts.
|
|
|
405
466
|
|
|
406
467
|
- `useYolkVoice` (`@yolk-sdk/agent/voice/react`) owns browser session lifecycle, user drafts,
|
|
407
468
|
and pending approvals; provider codecs come from `@yolk-sdk/agent/providers/openai/realtime`.
|
|
408
|
-
- Tools execute server-side only: the controller forwards
|
|
409
|
-
`VoiceSessionToolCallRequest` to your endpoint; `handleVoiceToolCall`
|
|
410
|
-
`ToolDef.approval` policy and never runs
|
|
411
|
-
response.
|
|
469
|
+
- Tools execute server-side only: the controller forwards the normalized
|
|
470
|
+
`VoiceSessionToolCallRequest` JSON envelope to your endpoint; `handleVoiceToolCall` returns a
|
|
471
|
+
JSON-compatible `VoiceToolCallOutcome` envelope, applies `ToolDef.approval` policy, and never runs
|
|
472
|
+
approval-gated tools without a matching approved response.
|
|
412
473
|
- Approval-gated calls pause with `AwaitingInput`; approvals/denials resume through
|
|
413
474
|
`submitHitlResponse`. Voice `question` is deferred in v1.
|
|
414
475
|
- `projectVoiceEvent` turns voice events into protocol messages with no dangling host tool
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProviderSubscriptionUsageError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot } from "../subscription-usage.mjs";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { HttpClient } from "effect/unstable/http";
|
|
4
|
+
import { OAuthAccessToken } from "@yolk-sdk/agent/oauth";
|
|
5
|
+
|
|
6
|
+
//#region src/providers/anthropic/usage.d.ts
|
|
7
|
+
declare const anthropicClaudeSubscriptionUsageUrl = "https://api.anthropic.com/api/oauth/usage";
|
|
8
|
+
type AnthropicClaudeSubscriptionUsageOptions = {
|
|
9
|
+
readonly requestTimeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
declare const parseAnthropicClaudeSubscriptionUsage: (value: unknown, fetchedAt: string) => Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError>;
|
|
12
|
+
declare const fetchAnthropicClaudeSubscriptionUsage: (token: OAuthAccessToken, options?: AnthropicClaudeSubscriptionUsageOptions) => Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageError, HttpClient.HttpClient>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AnthropicClaudeSubscriptionUsageOptions, anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
|
|
15
|
+
//# sourceMappingURL=usage.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"mappings":";;;;;;cAqBa,mCAAA;AAAA,KAED,uCAAA;EAAA,SACD,gBAAgB;AAAA;AAAA,cAoBd,qCAAA,GACX,KAAA,WACA,SAAA,aACC,MAAA,CAAO,MAAA,CAAO,iCAAA,EAAmC,sCAAA;AAAA,cAuDvC,qCAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,GAAS,uCAAA,KACR,MAAA,CAAO,MAAA,CACR,iCAAA,EACA,8BAAA,EACA,UAAA,CAAW,UAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ProviderSubscriptionUsageConfigurationError, ProviderSubscriptionUsageResponseError, ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageWindow } from "../subscription-usage.mjs";
|
|
2
|
+
import { canonicalSubscriptionUsageInstant, executeProviderSubscriptionUsageRequest, readProviderSubscriptionUsageJson, validProviderSubscriptionUsageTimeout, validSubscriptionUsagePercent } from "../subscription-usage-internal.mjs";
|
|
3
|
+
import { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from "./claude.mjs";
|
|
4
|
+
import { Chunk, Clock, Effect } from "effect";
|
|
5
|
+
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
//#region src/providers/anthropic/usage.ts
|
|
8
|
+
const anthropicClaudeSubscriptionUsageUrl = "https://api.anthropic.com/api/oauth/usage";
|
|
9
|
+
const NullableNumber = Schema.NullOr(Schema.Number);
|
|
10
|
+
const NullableString = Schema.NullOr(Schema.String);
|
|
11
|
+
var AnthropicClaudeSubscriptionUsageWindowWire = class extends Schema.Class("AnthropicClaudeSubscriptionUsageWindowWire")({
|
|
12
|
+
utilization: Schema.optional(NullableNumber),
|
|
13
|
+
resets_at: Schema.optional(NullableString)
|
|
14
|
+
}) {};
|
|
15
|
+
var AnthropicClaudeSubscriptionUsageWire = class extends Schema.Class("AnthropicClaudeSubscriptionUsageWire")({
|
|
16
|
+
five_hour: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),
|
|
17
|
+
seven_day: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))
|
|
18
|
+
}) {};
|
|
19
|
+
const parseAnthropicClaudeSubscriptionUsage = (value, fetchedAt) => {
|
|
20
|
+
const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt);
|
|
21
|
+
if (canonicalFetchedAt === void 0) return Effect.fail(ProviderSubscriptionUsageResponseError.make({
|
|
22
|
+
provider: anthropicClaudeProviderId,
|
|
23
|
+
category: "invalid_response"
|
|
24
|
+
}));
|
|
25
|
+
return Schema.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(Effect.map((decoded) => {
|
|
26
|
+
const windows = [];
|
|
27
|
+
const append = (wire, id) => {
|
|
28
|
+
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
|
+
id,
|
|
33
|
+
usedPercent: wire.utilization,
|
|
34
|
+
...resetsAt === void 0 ? {} : { resetsAt }
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
append(decoded.five_hour, "five-hour");
|
|
38
|
+
append(decoded.seven_day, "seven-day");
|
|
39
|
+
return ProviderSubscriptionUsageSnapshot.make({
|
|
40
|
+
provider: anthropicClaudeProviderId,
|
|
41
|
+
fetchedAt: canonicalFetchedAt,
|
|
42
|
+
windows: Chunk.fromIterable(windows)
|
|
43
|
+
});
|
|
44
|
+
}), Effect.mapError(() => ProviderSubscriptionUsageResponseError.make({
|
|
45
|
+
provider: anthropicClaudeProviderId,
|
|
46
|
+
category: "invalid_response"
|
|
47
|
+
})), Effect.withSpan("AnthropicClaudeSubscriptionUsage.parse"));
|
|
48
|
+
};
|
|
49
|
+
const fetchAnthropicClaudeSubscriptionUsage = (token, options = {}) => Effect.gen(function* () {
|
|
50
|
+
if (token.provider !== "anthropic-claude") return yield* Effect.fail(ProviderSubscriptionUsageConfigurationError.make({
|
|
51
|
+
provider: anthropicClaudeProviderId,
|
|
52
|
+
reason: "provider_mismatch"
|
|
53
|
+
}));
|
|
54
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? 1e4;
|
|
55
|
+
if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) return yield* Effect.fail(ProviderSubscriptionUsageConfigurationError.make({
|
|
56
|
+
provider: anthropicClaudeProviderId,
|
|
57
|
+
reason: "invalid_request_timeout"
|
|
58
|
+
}));
|
|
59
|
+
return yield* parseAnthropicClaudeSubscriptionUsage(yield* readProviderSubscriptionUsageJson(anthropicClaudeProviderId, yield* executeProviderSubscriptionUsageRequest({
|
|
60
|
+
provider: anthropicClaudeProviderId,
|
|
61
|
+
client: yield* HttpClient.HttpClient,
|
|
62
|
+
request: HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(HttpClientRequest.setHeaders({
|
|
63
|
+
accept: "application/json",
|
|
64
|
+
...anthropicClaudeAuthorizationHeaders(token),
|
|
65
|
+
"anthropic-beta": "oauth-2025-04-20"
|
|
66
|
+
})),
|
|
67
|
+
timeoutMs: requestTimeoutMs
|
|
68
|
+
})), new Date(yield* Clock.currentTimeMillis).toISOString());
|
|
69
|
+
}).pipe(Effect.withSpan("AnthropicClaudeSubscriptionUsage.fetch"));
|
|
70
|
+
//#endregion
|
|
71
|
+
export { anthropicClaudeSubscriptionUsageUrl, fetchAnthropicClaudeSubscriptionUsage, parseAnthropicClaudeSubscriptionUsage };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=usage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.mjs","names":[],"sources":["../../../src/providers/anthropic/usage.ts"],"sourcesContent":["import { Chunk, Clock, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { HttpClient, HttpClientRequest } from 'effect/unstable/http'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport { anthropicClaudeAuthorizationHeaders, anthropicClaudeProviderId } from './claude.ts'\nimport {\n canonicalSubscriptionUsageInstant,\n defaultProviderSubscriptionUsageTimeoutMs,\n executeProviderSubscriptionUsageRequest,\n readProviderSubscriptionUsageJson,\n validProviderSubscriptionUsageTimeout,\n validSubscriptionUsagePercent\n} from '../subscription-usage-internal.ts'\nimport {\n ProviderSubscriptionUsageConfigurationError,\n type ProviderSubscriptionUsageError,\n ProviderSubscriptionUsageResponseError,\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageWindow\n} from '../subscription-usage.ts'\n\nexport const anthropicClaudeSubscriptionUsageUrl = 'https://api.anthropic.com/api/oauth/usage'\n\nexport type AnthropicClaudeSubscriptionUsageOptions = {\n readonly requestTimeoutMs?: number\n}\n\nconst NullableNumber = Schema.NullOr(Schema.Number)\nconst NullableString = Schema.NullOr(Schema.String)\n\nclass AnthropicClaudeSubscriptionUsageWindowWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWindowWire>(\n 'AnthropicClaudeSubscriptionUsageWindowWire'\n)({\n utilization: Schema.optional(NullableNumber),\n resets_at: Schema.optional(NullableString)\n}) {}\n\nclass AnthropicClaudeSubscriptionUsageWire extends Schema.Class<AnthropicClaudeSubscriptionUsageWire>(\n 'AnthropicClaudeSubscriptionUsageWire'\n)({\n five_hour: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire)),\n seven_day: Schema.optional(Schema.NullOr(AnthropicClaudeSubscriptionUsageWindowWire))\n}) {}\n\nexport const parseAnthropicClaudeSubscriptionUsage = (\n value: unknown,\n fetchedAt: string\n): Effect.Effect<ProviderSubscriptionUsageSnapshot, ProviderSubscriptionUsageResponseError> => {\n const canonicalFetchedAt = canonicalSubscriptionUsageInstant(fetchedAt)\n\n if (canonicalFetchedAt === undefined) {\n return Effect.fail(\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n )\n }\n\n return Schema.decodeUnknownEffect(AnthropicClaudeSubscriptionUsageWire)(value).pipe(\n Effect.map(decoded => {\n const windows: Array<ProviderSubscriptionUsageWindow> = []\n const append = (\n wire: AnthropicClaudeSubscriptionUsageWindowWire | null | undefined,\n id: 'five-hour' | 'seven-day'\n ) => {\n if (!validSubscriptionUsagePercent(wire?.utilization)) {\n return\n }\n\n const resetValue = wire.resets_at === null ? undefined : wire.resets_at\n const resetsAt =\n resetValue === undefined ? undefined : canonicalSubscriptionUsageInstant(resetValue)\n\n windows.push(\n ProviderSubscriptionUsageWindow.make({\n id,\n usedPercent: wire.utilization,\n ...(resetsAt === undefined ? {} : { resetsAt })\n })\n )\n }\n\n append(decoded.five_hour, 'five-hour')\n append(decoded.seven_day, 'seven-day')\n\n return ProviderSubscriptionUsageSnapshot.make({\n provider: anthropicClaudeProviderId,\n fetchedAt: canonicalFetchedAt,\n windows: Chunk.fromIterable(windows)\n })\n }),\n Effect.mapError(() =>\n ProviderSubscriptionUsageResponseError.make({\n provider: anthropicClaudeProviderId,\n category: 'invalid_response'\n })\n ),\n Effect.withSpan('AnthropicClaudeSubscriptionUsage.parse')\n )\n}\n\nexport const fetchAnthropicClaudeSubscriptionUsage = (\n token: OAuthAccessToken,\n options: AnthropicClaudeSubscriptionUsageOptions = {}\n): Effect.Effect<\n ProviderSubscriptionUsageSnapshot,\n ProviderSubscriptionUsageError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n if (token.provider !== anthropicClaudeProviderId) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'provider_mismatch'\n })\n )\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? defaultProviderSubscriptionUsageTimeoutMs\n\n if (!validProviderSubscriptionUsageTimeout(requestTimeoutMs)) {\n return yield* Effect.fail(\n ProviderSubscriptionUsageConfigurationError.make({\n provider: anthropicClaudeProviderId,\n reason: 'invalid_request_timeout'\n })\n )\n }\n\n const client = yield* HttpClient.HttpClient\n const request = HttpClientRequest.get(anthropicClaudeSubscriptionUsageUrl).pipe(\n HttpClientRequest.setHeaders({\n accept: 'application/json',\n ...anthropicClaudeAuthorizationHeaders(token),\n 'anthropic-beta': 'oauth-2025-04-20'\n })\n )\n const response = yield* executeProviderSubscriptionUsageRequest({\n provider: anthropicClaudeProviderId,\n client,\n request,\n timeoutMs: requestTimeoutMs\n })\n const json = yield* readProviderSubscriptionUsageJson(anthropicClaudeProviderId, response)\n const fetchedAt = new Date(yield* Clock.currentTimeMillis).toISOString()\n\n return yield* parseAnthropicClaudeSubscriptionUsage(json, fetchedAt)\n }).pipe(Effect.withSpan('AnthropicClaudeSubscriptionUsage.fetch'))\n"],"mappings":";;;;;;;AAqBA,MAAa,sCAAsC;AAMnD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAClD,MAAM,iBAAiB,OAAO,OAAO,OAAO,MAAM;AAElD,IAAM,6CAAN,cAAyD,OAAO,MAC9D,4CACF,EAAE;CACA,aAAa,OAAO,SAAS,cAAc;CAC3C,WAAW,OAAO,SAAS,cAAc;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAM,uCAAN,cAAmD,OAAO,MACxD,sCACF,EAAE;CACA,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;CACpF,WAAW,OAAO,SAAS,OAAO,OAAO,0CAA0C,CAAC;AACtF,CAAC,EAAE,CAAC;AAEJ,MAAa,yCACX,OACA,cAC6F;CAC7F,MAAM,qBAAqB,kCAAkC,SAAS;CAEtE,IAAI,uBAAuB,KAAA,GACzB,OAAO,OAAO,KACZ,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH;CAGF,OAAO,OAAO,oBAAoB,oCAAoC,EAAE,KAAK,EAAE,KAC7E,OAAO,KAAI,YAAW;EACpB,MAAM,UAAkD,CAAC;EACzD,MAAM,UACJ,MACA,OACG;GACH,IAAI,CAAC,8BAA8B,MAAM,WAAW,GAClD;GAGF,MAAM,aAAa,KAAK,cAAc,OAAO,KAAA,IAAY,KAAK;GAC9D,MAAM,WACJ,eAAe,KAAA,IAAY,KAAA,IAAY,kCAAkC,UAAU;GAErF,QAAQ,KACN,gCAAgC,KAAK;IACnC;IACA,aAAa,KAAK;IAClB,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC/C,CAAC,CACH;EACF;EAEA,OAAO,QAAQ,WAAW,WAAW;EACrC,OAAO,QAAQ,WAAW,WAAW;EAErC,OAAO,kCAAkC,KAAK;GAC5C,UAAU;GACV,WAAW;GACX,SAAS,MAAM,aAAa,OAAO;EACrC,CAAC;CACH,CAAC,GACD,OAAO,eACL,uCAAuC,KAAK;EAC1C,UAAU;EACV,UAAU;CACZ,CAAC,CACH,GACA,OAAO,SAAS,wCAAwC,CAC1D;AACF;AAEA,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;CAoBF,OAAO,OAAO,sCAAsC,OAHhC,kCAAkC,2BAA2B,OANzD,wCAAwC;EAC9D,UAAU;EACV,QAAA,OAVoB,WAAW;EAW/B,SAVc,kBAAkB,IAAI,mCAAmC,EAAE,KACzE,kBAAkB,WAAW;GAC3B,QAAQ;GACR,GAAG,oCAAoC,KAAK;GAC5C,kBAAkB;EACpB,CAAC,CAKK;EACN,WAAW;CACb,CAAC,CACwF,GACvE,IAAI,KAAK,OAAO,MAAM,iBAAiB,EAAE,YAEO,CAAC;AACrE,CAAC,EAAE,KAAK,OAAO,SAAS,wCAAwC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Effect
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import { AgentReasoningEffort } from "@yolk-sdk/agent/protocol";
|
|
3
|
-
import {
|
|
4
|
-
import { LLMError,
|
|
3
|
+
import { HttpClientResponse } from "effect/unstable/http";
|
|
4
|
+
import { LLMError, LLMRequest } from "@yolk-sdk/agent/loop";
|
|
5
5
|
import { OAuthAccessToken } from "@yolk-sdk/agent/oauth";
|
|
6
6
|
|
|
7
7
|
//#region src/providers/openai/codex-provider.d.ts
|
|
@@ -18,10 +18,6 @@ type OpenAiCodexProviderConfig = {
|
|
|
18
18
|
readonly defaultReasoningEffort?: AgentReasoningEffort;
|
|
19
19
|
readonly reasoningSummary?: OpenAiCodexReasoningSummary;
|
|
20
20
|
};
|
|
21
|
-
type OpenAiCodexMessageInput = {
|
|
22
|
-
readonly role: 'user' | 'assistant';
|
|
23
|
-
readonly content: string | ReadonlyArray<OpenAiCodexInputContentPart>;
|
|
24
|
-
};
|
|
25
21
|
type OpenAiCodexInputTextPart = {
|
|
26
22
|
readonly type: 'input_text';
|
|
27
23
|
readonly text: string;
|
|
@@ -39,7 +35,10 @@ type OpenAiCodexInputFilePart = {
|
|
|
39
35
|
readonly file_url: string;
|
|
40
36
|
};
|
|
41
37
|
type OpenAiCodexInputContentPart = OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart;
|
|
42
|
-
type
|
|
38
|
+
type OpenAiCodexMessageInput = {
|
|
39
|
+
readonly role: 'user' | 'assistant';
|
|
40
|
+
readonly content: string | ReadonlyArray<OpenAiCodexInputContentPart>;
|
|
41
|
+
};
|
|
43
42
|
type OpenAiCodexFunctionCallInput = {
|
|
44
43
|
readonly type: 'function_call';
|
|
45
44
|
readonly call_id: string;
|
|
@@ -49,7 +48,7 @@ type OpenAiCodexFunctionCallInput = {
|
|
|
49
48
|
type OpenAiCodexFunctionOutputInput = {
|
|
50
49
|
readonly type: 'function_call_output';
|
|
51
50
|
readonly call_id: string;
|
|
52
|
-
readonly output:
|
|
51
|
+
readonly output: string | ReadonlyArray<OpenAiCodexInputContentPart>;
|
|
53
52
|
};
|
|
54
53
|
type OpenAiCodexInputItem = OpenAiCodexMessageInput | OpenAiCodexFunctionCallInput | OpenAiCodexFunctionOutputInput;
|
|
55
54
|
type OpenAiCodexTool = {
|
|
@@ -76,8 +75,8 @@ declare const toOpenAiCodexRequestBody: (request: LLMRequest, config?: {
|
|
|
76
75
|
readonly defaultReasoningEffort?: AgentReasoningEffort;
|
|
77
76
|
readonly reasoningSummary?: OpenAiCodexReasoningSummary;
|
|
78
77
|
}) => Effect.Effect<OpenAiCodexRequestBody, LLMError>;
|
|
79
|
-
declare const streamOpenAiCodexResponse: (response: HttpClientResponse.HttpClientResponse) => Stream.Stream<
|
|
80
|
-
declare const makeOpenAiCodexProviderLayer: (config: OpenAiCodexProviderConfig) => Layer.Layer<LLMProvider, never, HttpClient.HttpClient>;
|
|
78
|
+
declare const streamOpenAiCodexResponse: (response: HttpClientResponse.HttpClientResponse) => import("effect/Stream").Stream<import("@yolk-sdk/agent/loop").LLMTextDelta | import("@yolk-sdk/agent/loop").LLMReasoningDelta | import("@yolk-sdk/agent/loop").LLMDone | import("@yolk-sdk/agent/loop").LLMToolCall | import("@yolk-sdk/agent/loop").LLMToolInputStart | import("@yolk-sdk/agent/loop").LLMToolInputDelta | import("@yolk-sdk/agent/loop").LLMProviderToolResult | import("@yolk-sdk/agent/loop").LLMUsage, LLMError, never>;
|
|
79
|
+
declare const makeOpenAiCodexProviderLayer: (config: OpenAiCodexProviderConfig) => import("effect/Layer").Layer<import("@yolk-sdk/agent/loop").LLMProvider, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
81
80
|
//#endregion
|
|
82
81
|
export { OpenAiCodexProviderConfig, OpenAiCodexReasoningSummary, makeOpenAiCodexProviderLayer, streamOpenAiCodexResponse, toOpenAiCodexRequestBody };
|
|
83
82
|
//# sourceMappingURL=codex-provider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-provider.d.mts","names":[],"sources":["../../../src/providers/openai/codex-provider.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"codex-provider.d.mts","names":[],"sources":["../../../src/providers/openai/codex-provider.ts"],"mappings":";;;;;;;KAaY,2BAAA;AAAA,KAEA,yBAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAHqB;;;AAAA;EAAA,SAQ5B,eAAA;EAAA,SACA,YAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA;EAAA,SACxB,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,2BAAA;AAAA;AAAA,KAGzB,wBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGV,yBAAA;EAAA,SACM,IAAA;EAAA,SACA,SAAS;AAAA;AAAA,KAGf,wBAAA;EAAA,SAEU,IAAA;EAAA,SACA,QAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGV,2BAAA,GACD,wBAAA,GACA,yBAAA,GACA,wBAAA;AAAA,KAEC,uBAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA,WAAkB,aAAa,CAAC,2BAAA;AAAA;AAAA,KAGtC,4BAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,SAAA;AAAA;AAAA,KAGN,8BAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA,WAAiB,aAAa,CAAC,2BAAA;AAAA;AAAA,KAGrC,oBAAA,GACD,uBAAA,GACA,4BAAA,GACA,8BAAA;AAAA,KAEC,eAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;AAAA;AAAA,KAGN,sBAAA;EAAA,SACM,KAAA;EAAA,SACA,YAAA;EAAA,SACA,KAAA,EAAO,aAAA,CAAc,oBAAA;EAAA,SACrB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;IAAA,SACE,MAAA,EAAQ,oBAAA;IAAA,SACR,OAAA,EAAS,2BAAA;EAAA;EAAA,SAEX,KAAA,GAAQ,aAAA,CAAc,eAAA;EAAA,SACtB,mBAAA;AAAA;AAAA,cASE,wBAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;oEAEW,eAAA;EAAA,SACA,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,2BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,sBAAA,EAAwB,QAAA;AAAA,cAc5B,yBAAA,GAA6B,QAAA,EAAU,kBAAA,CAAmB,kBAAA,6BAAkB,MAAA,gCAAA,YAAA,kCAAA,iBAAA,kCAAA,OAAA,kCAAA,WAAA,kCAAA,iBAAA,kCAAA,iBAAA,kCAAA,qBAAA,kCAAA,QAAA,EAAA,QAAA;AAAA,cAG5E,4BAAA,GAAgC,MAAA,EAAQ,yBAAyB,4BAAA,KAAA,gCAAA,WAAA,mDAAA,UAAA"}
|