typeclaw 0.48.12 → 0.48.13
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/package.json +6 -3
- package/src/agent/attention-escalation.ts +8 -5
- package/src/agent/auth-reloadable.ts +2 -3
- package/src/agent/auth.ts +59 -79
- package/src/agent/compaction.ts +2 -2
- package/src/agent/index.ts +31 -15
- package/src/agent/llm-replay-sanitizer.ts +1 -1
- package/src/agent/model-overrides.ts +1 -1
- package/src/agent/multimodal/look-at.ts +3 -3
- package/src/agent/multimodal/read-redirect.ts +1 -1
- package/src/agent/plugin-tools.ts +26 -31
- package/src/agent/reload-tool.ts +1 -1
- package/src/agent/subagents.ts +1 -1
- package/src/agent/tool-error-remediation.ts +1 -1
- package/src/agent/tool-result-budget.ts +2 -2
- package/src/agent/tools/channel-disengage.ts +2 -2
- package/src/agent/tools/channel-edit.ts +2 -2
- package/src/agent/tools/channel-fetch-attachment.ts +2 -2
- package/src/agent/tools/channel-history.ts +2 -2
- package/src/agent/tools/channel-react.ts +2 -2
- package/src/agent/tools/channel-read.ts +2 -2
- package/src/agent/tools/channel-reply.ts +2 -2
- package/src/agent/tools/channel-send.ts +2 -2
- package/src/agent/tools/grant-role.ts +2 -2
- package/src/agent/tools/post-github-review.ts +2 -2
- package/src/agent/tools/restart.ts +2 -2
- package/src/agent/tools/skip-response.ts +2 -2
- package/src/agent/tools/spawn-subagent.ts +2 -2
- package/src/agent/tools/stream-snapshot.ts +2 -2
- package/src/agent/tools/subagent-cancel.ts +2 -2
- package/src/agent/tools/subagent-output.ts +2 -2
- package/src/agent/tools/todo/index.ts +2 -2
- package/src/agent/tools/webfetch/tool.ts +2 -2
- package/src/agent/tools/websearch.ts +2 -2
- package/src/channels/github-review-verdict-coordinator.ts +26 -3
- package/src/channels/router.ts +50 -25
- package/src/cli/model.ts +7 -5
- package/src/cli/oauth-callbacks.ts +38 -23
- package/src/config/config.ts +62 -25
- package/src/config/providers.ts +272 -47
- package/src/init/index.ts +4 -4
- package/src/init/oauth-login.ts +57 -17
- package/src/inspect/transcript-view.ts +6 -3
- package/src/run/channel-session-factory.ts +5 -4
- package/src/run/index.ts +11 -11
- package/src/secrets/refresh-provider-oauth.ts +30 -76
- package/src/secrets/schema.ts +3 -4
- package/src/secrets/storage.ts +133 -234
- package/src/server/index.ts +1 -1
- package/src/sessions/index.ts +1 -1
- package/src/skills/typeclaw-config/SKILL.md +4 -4
- package/src/skills/typeclaw-plugins/SKILL.md +5 -5
- package/src/tui/index.ts +5 -3
- package/src/tui/theme.ts +1 -1
- package/typeclaw.schema.json +32 -1
- package/src/agent/adaptive-thinking-compat.ts +0 -79
- package/src/secrets/oauth-xai.ts +0 -348
package/src/config/providers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ThinkingLevel } from '@
|
|
2
|
-
import type { KnownApi, Model } from '@
|
|
1
|
+
import type { ThinkingLevel } from '@earendil-works/pi-agent-core'
|
|
2
|
+
import type { KnownApi, Model } from '@earendil-works/pi-ai'
|
|
3
3
|
|
|
4
4
|
// Authentication mechanism a provider supports. `api-key` reads a static key
|
|
5
5
|
// from .env (the original path); `oauth` runs a browser flow at init time and
|
|
@@ -29,16 +29,16 @@ type KnownProvider = {
|
|
|
29
29
|
//
|
|
30
30
|
// Adding a new model: append it to the matching provider's `models` map. Each
|
|
31
31
|
// model object is the literal `Model<...>` that pi-ai consumes — keep it
|
|
32
|
-
// faithful to
|
|
33
|
-
//
|
|
34
|
-
//
|
|
32
|
+
// faithful to pi-ai's "Custom Providers" README section
|
|
33
|
+
// (https://github.com/earendil-works/pi/tree/main/packages/ai#custom-providers).
|
|
34
|
+
// `setRuntimeApiKey(provider, key)` keys off the `provider` field, so it MUST
|
|
35
|
+
// match the outer provider id.
|
|
35
36
|
//
|
|
36
37
|
// Adding a new provider: add a top-level entry. Set `auth` to the supported
|
|
37
38
|
// methods. For `api-key` providers, `apiKeyEnv` is the .env var typeclaw
|
|
38
39
|
// writes at init and reads at boot (match the upstream provider's standard,
|
|
39
40
|
// e.g. `OPENAI_API_KEY`). For `oauth` providers, `oauthProviderId` MUST match
|
|
40
|
-
// a pi-ai OAuth provider id exactly, otherwise
|
|
41
|
-
// throw "Unknown OAuth provider".
|
|
41
|
+
// a pi-ai OAuth provider id exactly, otherwise the provider login lookup fails.
|
|
42
42
|
//
|
|
43
43
|
// Granularity rule (split vs merge): a provider id is the runtime API surface,
|
|
44
44
|
// not the brand. Different API call => different provider id; same API call =>
|
|
@@ -61,9 +61,14 @@ export const KNOWN_PROVIDERS = {
|
|
|
61
61
|
auth: ['api-key'],
|
|
62
62
|
apiKeyEnv: 'OPENAI_API_KEY',
|
|
63
63
|
oauthProviderId: null,
|
|
64
|
-
// Costs and context windows mirror models.dev as of 2026-05-10
|
|
65
|
-
//
|
|
66
|
-
//
|
|
64
|
+
// Costs and context windows mirror models.dev as of 2026-05-10; the GPT-6
|
|
65
|
+
// Sol/Luna records mirror OpenAI's model docs as of 2026-09-22.
|
|
66
|
+
// GPT-6 bills cache writes at 1.25x input; pi 0.87's Responses transport
|
|
67
|
+
// reads cache_write_tokens (openai-responses-shared.js), so that rate is
|
|
68
|
+
// applied. The >272K-input 2x/1.5x tier is not expressible in TypeClaw's
|
|
69
|
+
// flat cost shape, so these records use the standard rate. When
|
|
70
|
+
// refreshing, also rerun `scripts/generate-schema.ts` so
|
|
71
|
+
// typeclaw.schema.json picks up new enum values.
|
|
67
72
|
models: {
|
|
68
73
|
// Default. Cheapest tool-calling reasoning model in the family;
|
|
69
74
|
// available on every paid OpenAI account tier.
|
|
@@ -115,6 +120,67 @@ export const KNOWN_PROVIDERS = {
|
|
|
115
120
|
contextWindow: 1050000,
|
|
116
121
|
maxTokens: 128000,
|
|
117
122
|
},
|
|
123
|
+
// GPT-6 Sol and Luna use Responses because Chat Completions accepts tools
|
|
124
|
+
// only at effort `none`. The full map and compat are pi-ai 0.87.1's
|
|
125
|
+
// catalog values, preserving every documented effort through `max`.
|
|
126
|
+
'gpt-6-sol': {
|
|
127
|
+
id: 'gpt-6-sol',
|
|
128
|
+
name: 'GPT-6 Sol',
|
|
129
|
+
api: 'openai-responses',
|
|
130
|
+
provider: 'openai',
|
|
131
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
132
|
+
reasoning: true,
|
|
133
|
+
input: ['text', 'image'],
|
|
134
|
+
cost: { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 },
|
|
135
|
+
contextWindow: 1050000,
|
|
136
|
+
maxTokens: 128000,
|
|
137
|
+
thinkingLevelMap: {
|
|
138
|
+
off: 'none',
|
|
139
|
+
minimal: null,
|
|
140
|
+
low: 'low',
|
|
141
|
+
medium: 'medium',
|
|
142
|
+
high: 'high',
|
|
143
|
+
xhigh: 'xhigh',
|
|
144
|
+
max: 'max',
|
|
145
|
+
},
|
|
146
|
+
compat: {
|
|
147
|
+
supportsStrictMode: true,
|
|
148
|
+
supportsOpenAIGrammarTools: true,
|
|
149
|
+
supportsAdditionalTools: true,
|
|
150
|
+
supportsToolSearch: true,
|
|
151
|
+
supportsMidConvoSystemMessages: true,
|
|
152
|
+
supportsExplicitPromptCacheMode: true,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
'gpt-6-luna': {
|
|
156
|
+
id: 'gpt-6-luna',
|
|
157
|
+
name: 'GPT-6 Luna',
|
|
158
|
+
api: 'openai-responses',
|
|
159
|
+
provider: 'openai',
|
|
160
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
161
|
+
reasoning: true,
|
|
162
|
+
input: ['text', 'image'],
|
|
163
|
+
cost: { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 },
|
|
164
|
+
contextWindow: 1050000,
|
|
165
|
+
maxTokens: 128000,
|
|
166
|
+
thinkingLevelMap: {
|
|
167
|
+
off: 'none',
|
|
168
|
+
minimal: null,
|
|
169
|
+
low: 'low',
|
|
170
|
+
medium: 'medium',
|
|
171
|
+
high: 'high',
|
|
172
|
+
xhigh: 'xhigh',
|
|
173
|
+
max: 'max',
|
|
174
|
+
},
|
|
175
|
+
compat: {
|
|
176
|
+
supportsStrictMode: true,
|
|
177
|
+
supportsOpenAIGrammarTools: true,
|
|
178
|
+
supportsAdditionalTools: true,
|
|
179
|
+
supportsToolSearch: true,
|
|
180
|
+
supportsMidConvoSystemMessages: true,
|
|
181
|
+
supportsExplicitPromptCacheMode: true,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
118
184
|
},
|
|
119
185
|
},
|
|
120
186
|
// ChatGPT Plus/Pro subscription via the OAuth Codex backend. No API key
|
|
@@ -177,6 +243,63 @@ export const KNOWN_PROVIDERS = {
|
|
|
177
243
|
contextWindow: 272000,
|
|
178
244
|
maxTokens: 128000,
|
|
179
245
|
},
|
|
246
|
+
// GPT-6 Sol and Luna use the documented Codex backend limits. Their
|
|
247
|
+
// 0.87.1 maps preserve all valid efforts through `max`; Codex floors
|
|
248
|
+
// unsupported `minimal` at `low`.
|
|
249
|
+
'gpt-6-sol': {
|
|
250
|
+
id: 'gpt-6-sol',
|
|
251
|
+
name: 'GPT-6 Sol',
|
|
252
|
+
api: 'openai-codex-responses',
|
|
253
|
+
provider: 'openai-codex',
|
|
254
|
+
baseUrl: 'https://chatgpt.com/backend-api',
|
|
255
|
+
reasoning: true,
|
|
256
|
+
input: ['text', 'image'],
|
|
257
|
+
cost: { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 },
|
|
258
|
+
contextWindow: 272000,
|
|
259
|
+
maxTokens: 128000,
|
|
260
|
+
thinkingLevelMap: {
|
|
261
|
+
off: 'none',
|
|
262
|
+
minimal: 'low',
|
|
263
|
+
low: 'low',
|
|
264
|
+
medium: 'medium',
|
|
265
|
+
high: 'high',
|
|
266
|
+
xhigh: 'xhigh',
|
|
267
|
+
max: 'max',
|
|
268
|
+
},
|
|
269
|
+
compat: {
|
|
270
|
+
supportsOpenAIGrammarTools: true,
|
|
271
|
+
supportsAdditionalTools: true,
|
|
272
|
+
supportsToolSearch: true,
|
|
273
|
+
supportsMidConvoSystemMessages: true,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
'gpt-6-luna': {
|
|
277
|
+
id: 'gpt-6-luna',
|
|
278
|
+
name: 'GPT-6 Luna',
|
|
279
|
+
api: 'openai-codex-responses',
|
|
280
|
+
provider: 'openai-codex',
|
|
281
|
+
baseUrl: 'https://chatgpt.com/backend-api',
|
|
282
|
+
reasoning: true,
|
|
283
|
+
input: ['text', 'image'],
|
|
284
|
+
cost: { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 },
|
|
285
|
+
contextWindow: 272000,
|
|
286
|
+
maxTokens: 128000,
|
|
287
|
+
thinkingLevelMap: {
|
|
288
|
+
off: 'none',
|
|
289
|
+
minimal: 'low',
|
|
290
|
+
low: 'low',
|
|
291
|
+
medium: 'medium',
|
|
292
|
+
high: 'high',
|
|
293
|
+
xhigh: 'xhigh',
|
|
294
|
+
max: 'max',
|
|
295
|
+
},
|
|
296
|
+
compat: {
|
|
297
|
+
supportsOpenAIGrammarTools: true,
|
|
298
|
+
supportsAdditionalTools: true,
|
|
299
|
+
supportsToolSearch: true,
|
|
300
|
+
supportsMidConvoSystemMessages: true,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
180
303
|
},
|
|
181
304
|
},
|
|
182
305
|
// Anthropic Claude — both the Anthropic Console API (ANTHROPIC_API_KEY)
|
|
@@ -215,7 +338,8 @@ export const KNOWN_PROVIDERS = {
|
|
|
215
338
|
// not the recommended path. Claude Mythos 5 (Fable 5's classifier-free
|
|
216
339
|
// sibling, limited availability via Project Glasswing) is intentionally
|
|
217
340
|
// NOT listed — access is gated per-org and a registry entry would fail for
|
|
218
|
-
// everyone else.
|
|
341
|
+
// everyone else. Opus 5.5 (Sep 22 2026) was added on its own; Claude Opus 5
|
|
342
|
+
// and Fable 5.1 are not registered yet.
|
|
219
343
|
//
|
|
220
344
|
// ID semantics differ across the lineup and matter for forward-compat:
|
|
221
345
|
// - `claude-haiku-4-5` is a 4.5-generation CONVENIENCE ALIAS that
|
|
@@ -238,8 +362,8 @@ export const KNOWN_PROVIDERS = {
|
|
|
238
362
|
// vs Opus 4.6, but total cost on identical workloads can rise meaningfully.
|
|
239
363
|
// - 1M token context window (vs 200k on Haiku) and 128k max output (vs
|
|
240
364
|
// 64k on Sonnet/Haiku). 1M context is at standard pricing — no surcharge.
|
|
241
|
-
// -
|
|
242
|
-
//
|
|
365
|
+
// - `xhigh` effort level between `high` and `max`; each record's
|
|
366
|
+
// `thinkingLevelMap` declares whether the model exposes it.
|
|
243
367
|
//
|
|
244
368
|
// Pricing mirrors Anthropic's official table as of 2026-05; cacheWrite is
|
|
245
369
|
// the 5m-TTL rate (1.25x input). 1h TTL is ~2x input (not modeled here —
|
|
@@ -264,6 +388,11 @@ export const KNOWN_PROVIDERS = {
|
|
|
264
388
|
contextWindow: 200000,
|
|
265
389
|
maxTokens: 64000,
|
|
266
390
|
},
|
|
391
|
+
// pi-ai 0.73 inferred adaptive thinking from the 4.6/4.7 ids; 0.87 reads
|
|
392
|
+
// only `compat.forceAdaptiveThinking` (anthropic-messages.js). Without
|
|
393
|
+
// these catalog fields Sonnet 4.6 and Opus 4.7 fall back to budget
|
|
394
|
+
// thinking, which Anthropic deprecates on 4.6 and rejects with a 400 on
|
|
395
|
+
// 4.7+ (platform.claude.com/docs/en/build-with-claude/extended-thinking).
|
|
267
396
|
'claude-sonnet-4-6': {
|
|
268
397
|
id: 'claude-sonnet-4-6',
|
|
269
398
|
name: 'Claude Sonnet 4.6',
|
|
@@ -275,6 +404,8 @@ export const KNOWN_PROVIDERS = {
|
|
|
275
404
|
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
276
405
|
contextWindow: 1000000,
|
|
277
406
|
maxTokens: 64000,
|
|
407
|
+
thinkingLevelMap: { max: 'max' },
|
|
408
|
+
compat: { forceAdaptiveThinking: true, supportsStrictTools: true },
|
|
278
409
|
},
|
|
279
410
|
// Sonnet 5 (Jul 1 2026) is the drop-in successor to Sonnet 4.6 with a
|
|
280
411
|
// caveat set that affects consumers of this record:
|
|
@@ -282,17 +413,12 @@ export const KNOWN_PROVIDERS = {
|
|
|
282
413
|
// Per-token price is unchanged, so equivalent requests cost more.
|
|
283
414
|
// - Adaptive thinking only: manual extended thinking
|
|
284
415
|
// (`thinking: {type: "enabled"}` with `budget_tokens`) returns a
|
|
285
|
-
// 400.
|
|
286
|
-
//
|
|
287
|
-
// and thinking defaults to "medium"), so registering this record
|
|
288
|
-
// with `reasoning: true` depends on the rewrite shim in
|
|
289
|
-
// src/agent/adaptive-thinking-compat.ts. Don't wire a
|
|
290
|
-
// thinking-budget knob to this id.
|
|
416
|
+
// 400. `compat.forceAdaptiveThinking` makes pi-ai's Anthropic
|
|
417
|
+
// transport send adaptive thinking on every path, compaction included.
|
|
291
418
|
// - Cost encodes the STANDARD rate (in effect Sep 1 2026+).
|
|
292
|
-
// Introductory pricing ($2/$10, cacheRead 0.2, cacheWrite 2.5)
|
|
293
|
-
// through Aug 31 2026
|
|
294
|
-
//
|
|
295
|
-
// two months after landing.
|
|
419
|
+
// Introductory pricing ($2/$10, cacheRead 0.2, cacheWrite 2.5) ran
|
|
420
|
+
// through Aug 31 2026. It was chosen so the record doesn't silently
|
|
421
|
+
// go stale two months after landing.
|
|
296
422
|
'claude-sonnet-5': {
|
|
297
423
|
id: 'claude-sonnet-5',
|
|
298
424
|
name: 'Claude Sonnet 5',
|
|
@@ -304,6 +430,8 @@ export const KNOWN_PROVIDERS = {
|
|
|
304
430
|
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
305
431
|
contextWindow: 1000000,
|
|
306
432
|
maxTokens: 128000,
|
|
433
|
+
thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
|
|
434
|
+
compat: { forceAdaptiveThinking: true, supportsStrictTools: true },
|
|
307
435
|
},
|
|
308
436
|
'claude-opus-4-7': {
|
|
309
437
|
id: 'claude-opus-4-7',
|
|
@@ -316,7 +444,12 @@ export const KNOWN_PROVIDERS = {
|
|
|
316
444
|
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
317
445
|
contextWindow: 1000000,
|
|
318
446
|
maxTokens: 128000,
|
|
447
|
+
thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
|
|
448
|
+
compat: { forceAdaptiveThinking: true, supportsTemperature: false, supportsStrictTools: true },
|
|
319
449
|
},
|
|
450
|
+
// Opus 4.8 was never in pi 0.73's adaptive id list, so it already got
|
|
451
|
+
// budget thinking (a 400 on 4.7+) before this migration. The catalog
|
|
452
|
+
// compat fixes it the same way.
|
|
320
453
|
'claude-opus-4-8': {
|
|
321
454
|
id: 'claude-opus-4-8',
|
|
322
455
|
name: 'Claude Opus 4.8',
|
|
@@ -328,15 +461,62 @@ export const KNOWN_PROVIDERS = {
|
|
|
328
461
|
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
329
462
|
contextWindow: 1000000,
|
|
330
463
|
maxTokens: 128000,
|
|
464
|
+
thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
|
|
465
|
+
compat: {
|
|
466
|
+
supportsMidConvoSystemMessages: true,
|
|
467
|
+
supportsMidConvoToolChanges: true,
|
|
468
|
+
forceAdaptiveThinking: true,
|
|
469
|
+
supportsTemperature: false,
|
|
470
|
+
supportsStrictTools: true,
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
// Opus 5.5 (Sep 22 2026) keeps adaptive thinking permanently on: both
|
|
474
|
+
// manual and disabled thinking return 400, which `forceAdaptiveThinking`
|
|
475
|
+
// plus `off`/`minimal: null` rule out. `supportsMidConvoEffort` routes the
|
|
476
|
+
// thinking level through the mid-conversation output-config control and
|
|
477
|
+
// sends `thinking-binding-controls-2026-08-01` with `drop_block`. Without
|
|
478
|
+
// that, a replayed thinking block whose prefix changed (for example after
|
|
479
|
+
// compaction) returns 400 on accounts created on or after 2026-08-31.
|
|
480
|
+
// Forced tool use is unsupported; typeclaw never sets toolChoice.
|
|
481
|
+
'claude-opus-5-5': {
|
|
482
|
+
id: 'claude-opus-5-5',
|
|
483
|
+
name: 'Claude Opus 5.5',
|
|
484
|
+
api: 'anthropic-messages',
|
|
485
|
+
provider: 'anthropic',
|
|
486
|
+
baseUrl: 'https://api.anthropic.com',
|
|
487
|
+
reasoning: true,
|
|
488
|
+
input: ['text', 'image'],
|
|
489
|
+
cost: { input: 4, output: 20, cacheRead: 0.2, cacheWrite: 5 },
|
|
490
|
+
contextWindow: 1000000,
|
|
491
|
+
maxTokens: 128000,
|
|
492
|
+
thinkingLevelMap: {
|
|
493
|
+
off: null,
|
|
494
|
+
minimal: null,
|
|
495
|
+
low: 'low',
|
|
496
|
+
medium: 'medium',
|
|
497
|
+
high: 'high',
|
|
498
|
+
xhigh: 'xhigh',
|
|
499
|
+
max: 'max',
|
|
500
|
+
},
|
|
501
|
+
compat: {
|
|
502
|
+
supportsMidConvoEffort: true,
|
|
503
|
+
supportsMidConvoSystemMessages: true,
|
|
504
|
+
supportsMidConvoToolChanges: true,
|
|
505
|
+
forceAdaptiveThinking: true,
|
|
506
|
+
supportsTemperature: false,
|
|
507
|
+
supportsStrictTools: true,
|
|
508
|
+
},
|
|
331
509
|
},
|
|
332
510
|
// Fable 5 (Jun 2026) is a NEW TIER above Opus — Anthropic's most
|
|
333
511
|
// capable widely released model, aimed at long-horizon agentic work.
|
|
334
512
|
// Ships the 5-generation tokenizer: ~1.3x token counts for the same
|
|
335
513
|
// text vs pre-5 models, so equivalent requests cost more than the
|
|
336
514
|
// per-token rates alone suggest. Adaptive thinking only, same as
|
|
337
|
-
// Sonnet 5 above
|
|
338
|
-
//
|
|
339
|
-
//
|
|
515
|
+
// Sonnet 5 above, via `compat.forceAdaptiveThinking`. Upstream's catalog
|
|
516
|
+
// also sets `allowedFallbackModels` (Anthropic server-side fallback to
|
|
517
|
+
// Opus 4.8 / Opus 5). That is deliberately NOT adopted: pi would send
|
|
518
|
+
// `fallbacks`, and a refused request would silently be served, and
|
|
519
|
+
// billed, by a different model than the one the operator configured.
|
|
340
520
|
'claude-fable-5': {
|
|
341
521
|
id: 'claude-fable-5',
|
|
342
522
|
name: 'Claude Fable 5',
|
|
@@ -348,6 +528,13 @@ export const KNOWN_PROVIDERS = {
|
|
|
348
528
|
cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.5 },
|
|
349
529
|
contextWindow: 1000000,
|
|
350
530
|
maxTokens: 128000,
|
|
531
|
+
thinkingLevelMap: { off: null, xhigh: 'xhigh', max: 'max' },
|
|
532
|
+
compat: {
|
|
533
|
+
supportsMidConvoSystemMessages: true,
|
|
534
|
+
supportsMidConvoToolChanges: true,
|
|
535
|
+
forceAdaptiveThinking: true,
|
|
536
|
+
supportsStrictTools: true,
|
|
537
|
+
},
|
|
351
538
|
},
|
|
352
539
|
},
|
|
353
540
|
},
|
|
@@ -521,24 +708,23 @@ export const KNOWN_PROVIDERS = {
|
|
|
521
708
|
},
|
|
522
709
|
},
|
|
523
710
|
},
|
|
524
|
-
// xAI (Grok)
|
|
525
|
-
//
|
|
526
|
-
// `openai-
|
|
527
|
-
//
|
|
528
|
-
//
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
//
|
|
534
|
-
// rule in src/agent/auth.ts applies: an OAuth credential on disk wins over
|
|
535
|
-
// XAI_API_KEY in .env — remove it (`typeclaw provider remove xai`) to fall
|
|
536
|
-
// back to the key.
|
|
711
|
+
// xAI (Grok) is a dual-auth provider: api-key requests use XAI_API_KEY and
|
|
712
|
+
// OAuth requests use the xAI OIDC credential. Grok 4.7 and 4.3 use
|
|
713
|
+
// `openai-responses` with pi-ai 0.87.1's catalog metadata, as upstream's
|
|
714
|
+
// built-in xAI provider does: Responses carries encrypted reasoning and the
|
|
715
|
+
// documented effort values. The grok-4.20 snapshots and grok-build-0.1 are
|
|
716
|
+
// not in that catalog, so they stay on `openai-completions`, where pi-ai
|
|
717
|
+
// sends no xAI reasoning_effort. That is their 0.73 wire behavior, unchanged.
|
|
718
|
+
// The built-in pi-ai xAI provider owns its device-code OAuth flow, including
|
|
719
|
+
// refresh. An OAuth credential on disk takes precedence over XAI_API_KEY in
|
|
720
|
+
// .env; remove it (`typeclaw provider remove xai`) to use the key instead.
|
|
537
721
|
//
|
|
538
722
|
// Costs and context windows mirror docs.x.ai/developers/models and the raw
|
|
539
723
|
// /v1/models price fields as of 2026-06-08 (xAI quotes prices in cents per
|
|
540
|
-
// 100M tokens; e.g. grok-4.3 prompt 12500 = $1.25/1M)
|
|
541
|
-
//
|
|
724
|
+
// 100M tokens; e.g. grok-4.3 prompt 12500 = $1.25/1M); grok-4.7 mirrors
|
|
725
|
+
// docs.x.ai/developers/grok-4-7 and /pricing as of 2026-09-21. grok-4.7 is
|
|
726
|
+
// the flagship; grok-4.3 stays first as the template record for uncurated
|
|
727
|
+
// refs; grok-build-0.1 is the coding-tuned model. The
|
|
542
728
|
// grok-4.20-0309 snapshots are pinned weights for reproducible runs.
|
|
543
729
|
//
|
|
544
730
|
// The earlier grok-4 / grok-4-fast / grok-code-fast-1 ids were RETIRED on
|
|
@@ -546,10 +732,10 @@ export const KNOWN_PROVIDERS = {
|
|
|
546
732
|
// grok-4.3 / grok-build-0.1 rates, so they are intentionally NOT listed.
|
|
547
733
|
//
|
|
548
734
|
// cacheWrite is 0: xAI publishes no cache-write price (caching is implicit,
|
|
549
|
-
// billed only at the cacheRead rate).
|
|
550
|
-
// tier (2x rates above a 200k-token request);
|
|
551
|
-
// express tiered pricing, so the standard rate is used and the
|
|
552
|
-
// noted here. When refreshing, rerun `scripts/generate-schema.ts`.
|
|
735
|
+
// billed only at the cacheRead rate). Every model here also carries a
|
|
736
|
+
// long-context tier (2x rates above a 200k-token request); the flat cost
|
|
737
|
+
// shape can't express tiered pricing, so the standard rate is used and the
|
|
738
|
+
// breakpoint is noted here. When refreshing, rerun `scripts/generate-schema.ts`.
|
|
553
739
|
xai: {
|
|
554
740
|
id: 'xai',
|
|
555
741
|
name: 'xAI (Grok)',
|
|
@@ -558,17 +744,56 @@ export const KNOWN_PROVIDERS = {
|
|
|
558
744
|
apiKeyEnv: 'XAI_API_KEY',
|
|
559
745
|
oauthProviderId: 'xai',
|
|
560
746
|
models: {
|
|
747
|
+
// pi-ai 0.87.1's xAI catalog caps Grok 4.3 at 30K and maps its efforts;
|
|
748
|
+
// `minimal` is not an xAI effort, so it clamps to `low`. The current
|
|
749
|
+
// transport sends model.maxTokens by default, so keep that vendor-safe cap.
|
|
561
750
|
'grok-4.3': {
|
|
562
751
|
id: 'grok-4.3',
|
|
563
752
|
name: 'Grok 4.3',
|
|
564
|
-
api: 'openai-
|
|
753
|
+
api: 'openai-responses',
|
|
565
754
|
provider: 'xai',
|
|
566
755
|
baseUrl: 'https://api.x.ai/v1',
|
|
567
756
|
reasoning: true,
|
|
568
757
|
input: ['text', 'image'],
|
|
569
758
|
cost: { input: 1.25, output: 2.5, cacheRead: 0.2, cacheWrite: 0 },
|
|
570
759
|
contextWindow: 1000000,
|
|
571
|
-
maxTokens:
|
|
760
|
+
maxTokens: 30000,
|
|
761
|
+
thinkingLevelMap: {
|
|
762
|
+
off: 'none',
|
|
763
|
+
minimal: null,
|
|
764
|
+
low: 'low',
|
|
765
|
+
medium: 'medium',
|
|
766
|
+
high: 'high',
|
|
767
|
+
xhigh: null,
|
|
768
|
+
max: null,
|
|
769
|
+
},
|
|
770
|
+
compat: { supportsLongCacheRetention: false },
|
|
771
|
+
},
|
|
772
|
+
// Responses is required for Grok 4.7's encrypted reasoning and maps
|
|
773
|
+
// the documented low/medium/high/xhigh effort values on pi-ai 0.87.1.
|
|
774
|
+
'grok-4.7': {
|
|
775
|
+
id: 'grok-4.7',
|
|
776
|
+
name: 'Grok 4.7',
|
|
777
|
+
api: 'openai-responses',
|
|
778
|
+
provider: 'xai',
|
|
779
|
+
baseUrl: 'https://api.x.ai/v1',
|
|
780
|
+
reasoning: true,
|
|
781
|
+
input: ['text', 'image'],
|
|
782
|
+
cost: { input: 2, output: 6, cacheRead: 0.5, cacheWrite: 0 },
|
|
783
|
+
// xAI documents no text-output ceiling. Use the 500K context window;
|
|
784
|
+
// pi-ai clamps it to remaining context before the Responses request.
|
|
785
|
+
contextWindow: 500000,
|
|
786
|
+
maxTokens: 500000,
|
|
787
|
+
thinkingLevelMap: {
|
|
788
|
+
off: null,
|
|
789
|
+
minimal: null,
|
|
790
|
+
low: 'low',
|
|
791
|
+
medium: 'medium',
|
|
792
|
+
high: 'high',
|
|
793
|
+
xhigh: 'xhigh',
|
|
794
|
+
max: null,
|
|
795
|
+
},
|
|
796
|
+
compat: { supportsLongCacheRetention: false },
|
|
572
797
|
},
|
|
573
798
|
'grok-4.20-0309-reasoning': {
|
|
574
799
|
id: 'grok-4.20-0309-reasoning',
|
package/src/init/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
} from '@/container'
|
|
30
30
|
import { hooklessGitArgs } from '@/git/hookless'
|
|
31
31
|
import { commitSystemFile } from '@/git/system-commit'
|
|
32
|
-
import {
|
|
32
|
+
import { type Channels, type Secret, SecretsBackend } from '@/secrets'
|
|
33
33
|
import { hostLocaleIsCjk } from '@/shared/host-locale'
|
|
34
34
|
import { isWindows } from '@/shared/platform'
|
|
35
35
|
import { createTui } from '@/tui'
|
|
@@ -949,10 +949,10 @@ export async function writeSecrets(
|
|
|
949
949
|
visionProviderId !== null &&
|
|
950
950
|
KNOWN_PROVIDERS[visionProviderId].apiKeyEnv !== null
|
|
951
951
|
if (wantsDefaultKey || wantsVisionKey) {
|
|
952
|
-
const
|
|
953
|
-
if (wantsDefaultKey)
|
|
952
|
+
const backend = new SecretsBackend(join(root, 'secrets.json'))
|
|
953
|
+
if (wantsDefaultKey) backend.writeProviderCredentialSync(providerId, { type: 'api_key', key: { value: apiKey! } })
|
|
954
954
|
if (wantsVisionKey) {
|
|
955
|
-
|
|
955
|
+
backend.writeProviderCredentialSync(visionProviderId, { type: 'api_key', key: { value: visionApiKey! } })
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
|
package/src/init/oauth-login.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
+
import type { AuthInteraction, AuthPrompt } from '@earendil-works/pi-ai'
|
|
4
|
+
import { ModelRuntime } from '@earendil-works/pi-coding-agent'
|
|
5
|
+
|
|
3
6
|
import {
|
|
4
7
|
KNOWN_PROVIDERS,
|
|
5
8
|
providerForModelRef,
|
|
@@ -14,13 +17,14 @@ export type OAuthLoginResult = { ok: true } | { ok: false; reason: string }
|
|
|
14
17
|
export type OAuthLoginRunner = (options: { cwd: string; model: ModelRef | string }) => Promise<OAuthLoginResult>
|
|
15
18
|
|
|
16
19
|
// Wrap pi-ai's OAuth callbacks so the CLI doesn't have to know about the
|
|
17
|
-
// upstream callback shape. The CLI sees
|
|
20
|
+
// upstream callback shape. The CLI sees five lifecycle events:
|
|
18
21
|
// (1) onAuth(url) — print the URL the user must visit
|
|
19
22
|
// (2) onProgress(message) — show waiting/finalizing status
|
|
20
|
-
// (3)
|
|
23
|
+
// (3) onSelect(message, options) — choose a provider-defined option by ID
|
|
24
|
+
// (4) onPrompt(prompt) — ask the user for a manual code if the browser flow
|
|
21
25
|
// can't reach the local callback server. Fires only after the local
|
|
22
26
|
// server gave up (bind error -> waitForCode resolves null).
|
|
23
|
-
// (
|
|
27
|
+
// (5) onManualCodeInput() — concurrent paste input that RACES the local
|
|
24
28
|
// callback server. Required for cross-device flows: pi-ai's openai-codex
|
|
25
29
|
// OAuth hardcodes redirect_uri=http://localhost:1455/auth/callback, which
|
|
26
30
|
// resolves to the *browser's* machine. When the user runs `typeclaw init`
|
|
@@ -32,11 +36,19 @@ export type OAuthLoginRunner = (options: { cwd: string; model: ModelRef | string
|
|
|
32
36
|
// code first wins. parseAuthorizationInput on the upstream side accepts
|
|
33
37
|
// the full redirect URL, the bare `code=...&state=...` query string, or
|
|
34
38
|
// just the code value.
|
|
39
|
+
export type OAuthSelectOption = Extract<AuthPrompt, { type: 'select' }>['options'][number]
|
|
40
|
+
|
|
35
41
|
export type OAuthCallbacks = {
|
|
36
42
|
onAuth: (url: string, instructions?: string) => void
|
|
37
43
|
onProgress?: (message: string) => void
|
|
38
|
-
onPrompt: (message: string, placeholder?: string) => Promise<string | null>
|
|
39
|
-
|
|
44
|
+
onPrompt: (message: string, placeholder?: string, signal?: AbortSignal) => Promise<string | null>
|
|
45
|
+
onSecret: (message: string, placeholder?: string, signal?: AbortSignal) => Promise<string | null>
|
|
46
|
+
onSelect: (
|
|
47
|
+
message: string,
|
|
48
|
+
options: readonly OAuthSelectOption[],
|
|
49
|
+
signal?: AbortSignal,
|
|
50
|
+
) => Promise<OAuthSelectOption['id'] | null>
|
|
51
|
+
onManualCodeInput?: (signal?: AbortSignal) => Promise<string>
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
// Default runner: real OAuth flow against pi-ai. Tests inject a stub to skip
|
|
@@ -52,19 +64,12 @@ export function makeOAuthLoginRunner(callbacks: OAuthCallbacks): OAuthLoginRunne
|
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
onPrompt: async (prompt) => {
|
|
60
|
-
const value = await callbacks.onPrompt(prompt.message, prompt.placeholder)
|
|
61
|
-
if (value === null) {
|
|
62
|
-
throw new Error('Login cancelled by user')
|
|
63
|
-
}
|
|
64
|
-
return value
|
|
65
|
-
},
|
|
66
|
-
onManualCodeInput: callbacks.onManualCodeInput,
|
|
67
|
+
const modelRuntime = await ModelRuntime.create({
|
|
68
|
+
credentials: createSecretsStoreForAgent(join(cwd, 'secrets.json')),
|
|
69
|
+
modelsPath: null,
|
|
70
|
+
refreshOnCreate: false,
|
|
67
71
|
})
|
|
72
|
+
await modelRuntime.login(provider.oauthProviderId, 'oauth', createOAuthInteraction(callbacks))
|
|
68
73
|
return { ok: true }
|
|
69
74
|
} catch (error) {
|
|
70
75
|
return { ok: false, reason: error instanceof Error ? error.message : String(error) }
|
|
@@ -72,6 +77,41 @@ export function makeOAuthLoginRunner(callbacks: OAuthCallbacks): OAuthLoginRunne
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
// Isolate the pi 0.87 AuthInteraction adaptation so manual-code prompt
|
|
81
|
+
// cancellation and callback forwarding remain behavior-testable without a
|
|
82
|
+
// live provider login.
|
|
83
|
+
export function createOAuthInteraction(callbacks: OAuthCallbacks): AuthInteraction {
|
|
84
|
+
return {
|
|
85
|
+
notify: (event) => {
|
|
86
|
+
if (event.type === 'auth_url') callbacks.onAuth(event.url, event.instructions)
|
|
87
|
+
else if (event.type === 'progress') callbacks.onProgress?.(event.message)
|
|
88
|
+
else if (event.type === 'device_code') callbacks.onAuth(event.verificationUri, `Enter code ${event.userCode}`)
|
|
89
|
+
},
|
|
90
|
+
prompt: async (prompt) => {
|
|
91
|
+
if (prompt.type === 'select') {
|
|
92
|
+
const value = await callbacks.onSelect(prompt.message, prompt.options, prompt.signal)
|
|
93
|
+
// pi-ai 0.87 requires select prompts to resolve with an option ID
|
|
94
|
+
// (dist/auth/types.d.ts:153-155); reject stale/corrupt UI values as cancellation.
|
|
95
|
+
if (value === null || !prompt.options.some((option) => option.id === value)) {
|
|
96
|
+
throw new Error('Login cancelled by user')
|
|
97
|
+
}
|
|
98
|
+
return value
|
|
99
|
+
}
|
|
100
|
+
if (prompt.type === 'manual_code' && callbacks.onManualCodeInput) {
|
|
101
|
+
return await callbacks.onManualCodeInput(prompt.signal)
|
|
102
|
+
}
|
|
103
|
+
const callback = prompt.type === 'secret' ? callbacks.onSecret : callbacks.onPrompt
|
|
104
|
+
if (prompt.type === 'text' || prompt.type === 'secret' || prompt.type === 'manual_code') {
|
|
105
|
+
const value = await callback(prompt.message, prompt.placeholder, prompt.signal)
|
|
106
|
+
if (value === null) throw new Error('Login cancelled by user')
|
|
107
|
+
return value
|
|
108
|
+
}
|
|
109
|
+
const unknownPrompt: never = prompt
|
|
110
|
+
throw new Error(`Unsupported OAuth prompt type: ${unknownPrompt}`)
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
// Test seam: lets unit tests assert "OAuth login was invoked with these
|
|
76
116
|
// params" without spinning up a real secrets store / browser callback server.
|
|
77
117
|
export type FakeOAuthLoginRunnerOptions = {
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
type Component,
|
|
7
7
|
type Terminal,
|
|
8
8
|
Text,
|
|
9
|
-
|
|
10
|
-
} from '@
|
|
9
|
+
TuiMainScreen,
|
|
10
|
+
} from '@earendil-works/pi-tui'
|
|
11
11
|
|
|
12
12
|
import { formatToolEnd, formatToolStart, formatUserPromptHistory } from '@/tui/format'
|
|
13
13
|
import { armTerminalGuard } from '@/tui/terminal-guard'
|
|
@@ -41,7 +41,10 @@ export const MAX_LIVE_HISTORY_ENTRIES = 250
|
|
|
41
41
|
export function createTranscriptView(opts: TranscriptViewOptions) {
|
|
42
42
|
async function run(): Promise<TranscriptViewOutcome> {
|
|
43
43
|
const terminal = (opts.createTerminal ?? (() => new ProcessTerminal()))()
|
|
44
|
-
|
|
44
|
+
// pi-tui 0.87 exports TUI only as an interface; use its concrete
|
|
45
|
+
// main-screen renderer to preserve this viewer's scrollback behavior
|
|
46
|
+
// (dist/tui.d.ts:213-244, tui-main-screen.d.ts:11-12).
|
|
47
|
+
const tui = new TuiMainScreen(terminal)
|
|
45
48
|
|
|
46
49
|
const status = new Text(statusLine('replay'), 0, 0)
|
|
47
50
|
tui.addChild(new Text(header(opts.summary), 0, 0))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { SessionManager } from '@
|
|
3
|
+
import { SessionManager } from '@earendil-works/pi-coding-agent'
|
|
4
4
|
|
|
5
5
|
import { createSession as defaultCreateSession } from '@/agent'
|
|
6
6
|
import type { LiveSessionRegistry } from '@/agent/live-sessions'
|
|
@@ -185,8 +185,9 @@ export function buildChannelSessionFactory(deps: BuildChannelSessionFactoryDeps)
|
|
|
185
185
|
// because pi-coding-agent prefixes filenames with an ISO timestamp at write
|
|
186
186
|
// time that is not derivable from sessionId alone. Failure to reopen
|
|
187
187
|
// (corruption, missing file, schema drift, or v2 mapping with no sessionFile)
|
|
188
|
-
// falls back to a fresh session
|
|
189
|
-
//
|
|
188
|
+
// falls back to a fresh session. pi 0.87 preserves a non-empty invalid file
|
|
189
|
+
// rather than silently rewriting it, so the warning below explicitly says its
|
|
190
|
+
// history is unavailable while retaining the file for operator recovery.
|
|
190
191
|
function tryReopenOrCreate(
|
|
191
192
|
cwd: string,
|
|
192
193
|
sessionDir: string,
|
|
@@ -234,7 +235,7 @@ function tryReopenOrCreate(
|
|
|
234
235
|
return sessionManager
|
|
235
236
|
} catch (err) {
|
|
236
237
|
if (!errorChainHasCode(err, 'ENOENT')) {
|
|
237
|
-
logger.warn('[channels] persisted session
|
|
238
|
+
logger.warn('[channels] persisted session history unavailable; creating new')
|
|
238
239
|
}
|
|
239
240
|
return SessionManager.create(cwd, sessionDir)
|
|
240
241
|
}
|