@sayknow-cli/ai 0.3.11 → 0.3.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 +24 -25
- package/src/model-cache.ts +1 -1
- package/src/model-manager.ts +14 -3
- package/src/model-retirements.ts +13 -0
- package/src/model-thinking.ts +34 -2
- package/src/models.ts +26 -5
- package/src/provider-models/google.ts +1 -0
- package/src/providers/amazon-bedrock.ts +37 -33
- package/src/providers/anthropic.ts +94 -65
- package/src/providers/aws-credential-config.ts +180 -0
- package/src/providers/aws-credentials.ts +20 -63
- package/src/providers/google-gemini-cli.ts +27 -3
- package/src/providers/google-gemini-headers.ts +6 -1
- package/src/providers/google-shared.ts +55 -3
- package/src/types.ts +2 -0
- package/src/utils/discovery/antigravity.ts +16 -2
- package/dist/types/api-registry.d.ts +0 -30
- package/dist/types/auth-broker/client.d.ts +0 -67
- package/dist/types/auth-broker/index.d.ts +0 -5
- package/dist/types/auth-broker/refresher.d.ts +0 -25
- package/dist/types/auth-broker/remote-store.d.ts +0 -99
- package/dist/types/auth-broker/server.d.ts +0 -32
- package/dist/types/auth-broker/types.d.ts +0 -110
- package/dist/types/auth-broker/wire-schemas.d.ts +0 -443
- package/dist/types/auth-gateway/http.d.ts +0 -40
- package/dist/types/auth-gateway/index.d.ts +0 -3
- package/dist/types/auth-gateway/server.d.ts +0 -17
- package/dist/types/auth-gateway/types.d.ts +0 -115
- package/dist/types/auth-storage.d.ts +0 -695
- package/dist/types/cli.d.ts +0 -2
- package/dist/types/index.d.ts +0 -51
- package/dist/types/model-cache.d.ts +0 -17
- package/dist/types/model-manager.d.ts +0 -62
- package/dist/types/model-thinking.d.ts +0 -74
- package/dist/types/models.d.ts +0 -12
- package/dist/types/provider-details.d.ts +0 -24
- package/dist/types/provider-models/bundled-references.d.ts +0 -4
- package/dist/types/provider-models/descriptors.d.ts +0 -48
- package/dist/types/provider-models/google.d.ts +0 -20
- package/dist/types/provider-models/index.d.ts +0 -5
- package/dist/types/provider-models/ollama.d.ts +0 -7
- package/dist/types/provider-models/openai-compat.d.ts +0 -256
- package/dist/types/provider-models/special.d.ts +0 -19
- package/dist/types/providers/amazon-bedrock.d.ts +0 -60
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +0 -450
- package/dist/types/providers/anthropic-messages-server.d.ts +0 -17
- package/dist/types/providers/anthropic.d.ts +0 -208
- package/dist/types/providers/aws-credentials.d.ts +0 -43
- package/dist/types/providers/aws-eventstream.d.ts +0 -38
- package/dist/types/providers/aws-sigv4.d.ts +0 -55
- package/dist/types/providers/azure-openai-responses.d.ts +0 -15
- package/dist/types/providers/composer-discipline.d.ts +0 -26
- package/dist/types/providers/cursor/client-version.d.ts +0 -10
- package/dist/types/providers/cursor/gen/agent_pb.d.ts +0 -13022
- package/dist/types/providers/cursor.d.ts +0 -45
- package/dist/types/providers/error-message.d.ts +0 -27
- package/dist/types/providers/github-copilot-headers.d.ts +0 -40
- package/dist/types/providers/gitlab-duo.d.ts +0 -27
- package/dist/types/providers/google-auth.d.ts +0 -24
- package/dist/types/providers/google-gemini-cli.d.ts +0 -75
- package/dist/types/providers/google-gemini-headers.d.ts +0 -40
- package/dist/types/providers/google-shared.d.ts +0 -173
- package/dist/types/providers/google-types.d.ts +0 -138
- package/dist/types/providers/google-vertex.d.ts +0 -7
- package/dist/types/providers/google.d.ts +0 -4
- package/dist/types/providers/grammar.d.ts +0 -1
- package/dist/types/providers/kimi.d.ts +0 -27
- package/dist/types/providers/mock.d.ts +0 -177
- package/dist/types/providers/ollama.d.ts +0 -41
- package/dist/types/providers/openai-anthropic-shim.d.ts +0 -31
- package/dist/types/providers/openai-bounded-rate-limits.d.ts +0 -3
- package/dist/types/providers/openai-chat-server-schema.d.ts +0 -815
- package/dist/types/providers/openai-chat-server.d.ts +0 -16
- package/dist/types/providers/openai-codex/constants.d.ts +0 -26
- package/dist/types/providers/openai-codex/request-transformer.d.ts +0 -50
- package/dist/types/providers/openai-codex/response-handler.d.ts +0 -17
- package/dist/types/providers/openai-codex-responses.d.ts +0 -67
- package/dist/types/providers/openai-completions-compat.d.ts +0 -27
- package/dist/types/providers/openai-completions.d.ts +0 -33
- package/dist/types/providers/openai-request-transform.d.ts +0 -4
- package/dist/types/providers/openai-responses-server-schema.d.ts +0 -392
- package/dist/types/providers/openai-responses-server.d.ts +0 -17
- package/dist/types/providers/openai-responses-shared.d.ts +0 -104
- package/dist/types/providers/openai-responses.d.ts +0 -32
- package/dist/types/providers/pi-native-client.d.ts +0 -13
- package/dist/types/providers/pi-native-server.d.ts +0 -68
- package/dist/types/providers/register-builtins.d.ts +0 -31
- package/dist/types/providers/synthetic.d.ts +0 -26
- package/dist/types/providers/transform-messages.d.ts +0 -14
- package/dist/types/providers/vision-guard.d.ts +0 -8
- package/dist/types/rate-limit-utils.d.ts +0 -19
- package/dist/types/stream.d.ts +0 -43
- package/dist/types/types.d.ts +0 -829
- package/dist/types/usage/claude.d.ts +0 -3
- package/dist/types/usage/gemini.d.ts +0 -2
- package/dist/types/usage/github-copilot.d.ts +0 -7
- package/dist/types/usage/google-antigravity.d.ts +0 -2
- package/dist/types/usage/grok-cli.d.ts +0 -10
- package/dist/types/usage/kimi.d.ts +0 -2
- package/dist/types/usage/minimax-code.d.ts +0 -2
- package/dist/types/usage/openai-codex.d.ts +0 -3
- package/dist/types/usage/shared.d.ts +0 -1
- package/dist/types/usage/zai.d.ts +0 -2
- package/dist/types/usage.d.ts +0 -258
- package/dist/types/utils/abort.d.ts +0 -19
- package/dist/types/utils/anthropic-auth.d.ts +0 -31
- package/dist/types/utils/discovery/antigravity.d.ts +0 -61
- package/dist/types/utils/discovery/codex.d.ts +0 -38
- package/dist/types/utils/discovery/cursor.d.ts +0 -23
- package/dist/types/utils/discovery/gemini.d.ts +0 -25
- package/dist/types/utils/discovery/index.d.ts +0 -4
- package/dist/types/utils/discovery/openai-compatible.d.ts +0 -74
- package/dist/types/utils/event-stream.d.ts +0 -33
- package/dist/types/utils/fireworks-model-id.d.ts +0 -10
- package/dist/types/utils/foundry.d.ts +0 -1
- package/dist/types/utils/h2-fetch.d.ts +0 -22
- package/dist/types/utils/http-inspector.d.ts +0 -35
- package/dist/types/utils/idle-iterator.d.ts +0 -67
- package/dist/types/utils/json-parse.d.ts +0 -18
- package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +0 -18
- package/dist/types/utils/oauth/anthropic.d.ts +0 -22
- package/dist/types/utils/oauth/api-key-login.d.ts +0 -35
- package/dist/types/utils/oauth/api-key-validation.d.ts +0 -27
- package/dist/types/utils/oauth/callback-server.d.ts +0 -60
- package/dist/types/utils/oauth/cerebras.d.ts +0 -1
- package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +0 -18
- package/dist/types/utils/oauth/cursor.d.ts +0 -15
- package/dist/types/utils/oauth/deepinfra.d.ts +0 -1
- package/dist/types/utils/oauth/deepseek.d.ts +0 -10
- package/dist/types/utils/oauth/firepass.d.ts +0 -1
- package/dist/types/utils/oauth/fireworks.d.ts +0 -1
- package/dist/types/utils/oauth/fugu.d.ts +0 -1
- package/dist/types/utils/oauth/github-copilot.d.ts +0 -38
- package/dist/types/utils/oauth/gitlab-duo.d.ts +0 -3
- package/dist/types/utils/oauth/glm-zcode.d.ts +0 -71
- package/dist/types/utils/oauth/google-antigravity.d.ts +0 -11
- package/dist/types/utils/oauth/google-gemini-cli.d.ts +0 -10
- package/dist/types/utils/oauth/google-oauth-shared.d.ts +0 -28
- package/dist/types/utils/oauth/huggingface.d.ts +0 -19
- package/dist/types/utils/oauth/index.d.ts +0 -39
- package/dist/types/utils/oauth/kagi.d.ts +0 -17
- package/dist/types/utils/oauth/kilo.d.ts +0 -5
- package/dist/types/utils/oauth/kimi.d.ts +0 -21
- package/dist/types/utils/oauth/litellm.d.ts +0 -18
- package/dist/types/utils/oauth/lm-studio.d.ts +0 -17
- package/dist/types/utils/oauth/minimax-code.d.ts +0 -28
- package/dist/types/utils/oauth/moonshot.d.ts +0 -1
- package/dist/types/utils/oauth/nanogpt.d.ts +0 -1
- package/dist/types/utils/oauth/nvidia.d.ts +0 -18
- package/dist/types/utils/oauth/ollama-cloud.d.ts +0 -2
- package/dist/types/utils/oauth/ollama.d.ts +0 -18
- package/dist/types/utils/oauth/openai-codex.d.ts +0 -21
- package/dist/types/utils/oauth/opencode.d.ts +0 -18
- package/dist/types/utils/oauth/parallel.d.ts +0 -17
- package/dist/types/utils/oauth/perplexity.d.ts +0 -9
- package/dist/types/utils/oauth/pkce.d.ts +0 -8
- package/dist/types/utils/oauth/qianfan.d.ts +0 -17
- package/dist/types/utils/oauth/qwen-portal.d.ts +0 -19
- package/dist/types/utils/oauth/synthetic.d.ts +0 -1
- package/dist/types/utils/oauth/tavily.d.ts +0 -17
- package/dist/types/utils/oauth/together.d.ts +0 -1
- package/dist/types/utils/oauth/types.d.ts +0 -45
- package/dist/types/utils/oauth/venice.d.ts +0 -18
- package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +0 -18
- package/dist/types/utils/oauth/vllm.d.ts +0 -16
- package/dist/types/utils/oauth/xai.d.ts +0 -30
- package/dist/types/utils/oauth/xiaomi.d.ts +0 -25
- package/dist/types/utils/oauth/zai.d.ts +0 -18
- package/dist/types/utils/oauth/zenmux.d.ts +0 -1
- package/dist/types/utils/overflow.d.ts +0 -64
- package/dist/types/utils/parse-bind.d.ts +0 -23
- package/dist/types/utils/provider-response.d.ts +0 -3
- package/dist/types/utils/retry-after.d.ts +0 -3
- package/dist/types/utils/retry-budget.d.ts +0 -1
- package/dist/types/utils/retry.d.ts +0 -26
- package/dist/types/utils/schema/adapt.d.ts +0 -24
- package/dist/types/utils/schema/compatibility.d.ts +0 -30
- package/dist/types/utils/schema/dereference.d.ts +0 -11
- package/dist/types/utils/schema/draft.d.ts +0 -10
- package/dist/types/utils/schema/equality.d.ts +0 -4
- package/dist/types/utils/schema/fields.d.ts +0 -49
- package/dist/types/utils/schema/index.d.ts +0 -14
- package/dist/types/utils/schema/json-schema-validator.d.ts +0 -12
- package/dist/types/utils/schema/meta-validator.d.ts +0 -2
- package/dist/types/utils/schema/normalize.d.ts +0 -93
- package/dist/types/utils/schema/root-combinator.d.ts +0 -12
- package/dist/types/utils/schema/spill.d.ts +0 -8
- package/dist/types/utils/schema/stamps.d.ts +0 -25
- package/dist/types/utils/schema/types.d.ts +0 -4
- package/dist/types/utils/schema/wire.d.ts +0 -54
- package/dist/types/utils/schema/zod-decontaminate.d.ts +0 -31
- package/dist/types/utils/sse-debug.d.ts +0 -10
- package/dist/types/utils/tool-call-healing.d.ts +0 -71
- package/dist/types/utils/tool-choice-capability.d.ts +0 -41
- package/dist/types/utils/tool-choice.d.ts +0 -50
- package/dist/types/utils/validation.d.ts +0 -17
- package/dist/types/utils.d.ts +0 -35
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sayknow-cli/ai",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.13",
|
|
5
5
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
6
|
"homepage": "https://sayknow-cli.com",
|
|
7
7
|
"author": "jaybeyond",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"api"
|
|
28
28
|
],
|
|
29
29
|
"main": "./src/index.ts",
|
|
30
|
-
"types": "./
|
|
30
|
+
"types": "./src/index.ts",
|
|
31
31
|
"bin": {
|
|
32
32
|
"pi-ai": "./src/cli.ts"
|
|
33
33
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "^0.94.0",
|
|
45
45
|
"@bufbuild/protobuf": "^2.12.0",
|
|
46
|
-
"@sayknow-cli/utils": "0.3.
|
|
46
|
+
"@sayknow-cli/utils": "0.3.13",
|
|
47
47
|
"openai": "^6.36.0",
|
|
48
48
|
"partial-json": "^0.1.7",
|
|
49
49
|
"zod": "4.4.3"
|
|
@@ -57,88 +57,87 @@
|
|
|
57
57
|
"files": [
|
|
58
58
|
"src",
|
|
59
59
|
"README.md",
|
|
60
|
-
"CHANGELOG.md"
|
|
61
|
-
"dist/types"
|
|
60
|
+
"CHANGELOG.md"
|
|
62
61
|
],
|
|
63
62
|
"exports": {
|
|
64
63
|
".": {
|
|
65
|
-
"types": "./
|
|
64
|
+
"types": "./src/index.ts",
|
|
66
65
|
"import": "./src/index.ts"
|
|
67
66
|
},
|
|
68
67
|
"./*": {
|
|
69
|
-
"types": "./
|
|
68
|
+
"types": "./src/*.ts",
|
|
70
69
|
"import": "./src/*.ts"
|
|
71
70
|
},
|
|
72
71
|
"./auth-broker": {
|
|
73
|
-
"types": "./
|
|
72
|
+
"types": "./src/auth-broker/index.ts",
|
|
74
73
|
"import": "./src/auth-broker/index.ts"
|
|
75
74
|
},
|
|
76
75
|
"./auth-broker/*": {
|
|
77
|
-
"types": "./
|
|
76
|
+
"types": "./src/auth-broker/*.ts",
|
|
78
77
|
"import": "./src/auth-broker/*.ts"
|
|
79
78
|
},
|
|
80
79
|
"./auth-gateway": {
|
|
81
|
-
"types": "./
|
|
80
|
+
"types": "./src/auth-gateway/index.ts",
|
|
82
81
|
"import": "./src/auth-gateway/index.ts"
|
|
83
82
|
},
|
|
84
83
|
"./auth-gateway/*": {
|
|
85
|
-
"types": "./
|
|
84
|
+
"types": "./src/auth-gateway/*.ts",
|
|
86
85
|
"import": "./src/auth-gateway/*.ts"
|
|
87
86
|
},
|
|
88
87
|
"./models.json": {
|
|
89
|
-
"types": "./
|
|
88
|
+
"types": "./src/models.json.d.ts",
|
|
90
89
|
"import": "./src/models.json"
|
|
91
90
|
},
|
|
92
91
|
"./provider-models": {
|
|
93
|
-
"types": "./
|
|
92
|
+
"types": "./src/provider-models/index.ts",
|
|
94
93
|
"import": "./src/provider-models/index.ts"
|
|
95
94
|
},
|
|
96
95
|
"./provider-models/*": {
|
|
97
|
-
"types": "./
|
|
96
|
+
"types": "./src/provider-models/*.ts",
|
|
98
97
|
"import": "./src/provider-models/*.ts"
|
|
99
98
|
},
|
|
100
99
|
"./providers/*": {
|
|
101
|
-
"types": "./
|
|
100
|
+
"types": "./src/providers/*.ts",
|
|
102
101
|
"import": "./src/providers/*.ts"
|
|
103
102
|
},
|
|
104
103
|
"./providers/cursor/gen/*": {
|
|
105
|
-
"types": "./
|
|
104
|
+
"types": "./src/providers/cursor/gen/*.ts",
|
|
106
105
|
"import": "./src/providers/cursor/gen/*.ts"
|
|
107
106
|
},
|
|
108
107
|
"./providers/openai-codex/*": {
|
|
109
|
-
"types": "./
|
|
108
|
+
"types": "./src/providers/openai-codex/*.ts",
|
|
110
109
|
"import": "./src/providers/openai-codex/*.ts"
|
|
111
110
|
},
|
|
112
111
|
"./usage/*": {
|
|
113
|
-
"types": "./
|
|
112
|
+
"types": "./src/usage/*.ts",
|
|
114
113
|
"import": "./src/usage/*.ts"
|
|
115
114
|
},
|
|
116
115
|
"./utils/*": {
|
|
117
|
-
"types": "./
|
|
116
|
+
"types": "./src/utils/*.ts",
|
|
118
117
|
"import": "./src/utils/*.ts"
|
|
119
118
|
},
|
|
120
119
|
"./utils/discovery": {
|
|
121
|
-
"types": "./
|
|
120
|
+
"types": "./src/utils/discovery/index.ts",
|
|
122
121
|
"import": "./src/utils/discovery/index.ts"
|
|
123
122
|
},
|
|
124
123
|
"./utils/discovery/*": {
|
|
125
|
-
"types": "./
|
|
124
|
+
"types": "./src/utils/discovery/*.ts",
|
|
126
125
|
"import": "./src/utils/discovery/*.ts"
|
|
127
126
|
},
|
|
128
127
|
"./utils/oauth": {
|
|
129
|
-
"types": "./
|
|
128
|
+
"types": "./src/utils/oauth/index.ts",
|
|
130
129
|
"import": "./src/utils/oauth/index.ts"
|
|
131
130
|
},
|
|
132
131
|
"./utils/oauth/*": {
|
|
133
|
-
"types": "./
|
|
132
|
+
"types": "./src/utils/oauth/*.ts",
|
|
134
133
|
"import": "./src/utils/oauth/*.ts"
|
|
135
134
|
},
|
|
136
135
|
"./utils/schema": {
|
|
137
|
-
"types": "./
|
|
136
|
+
"types": "./src/utils/schema/index.ts",
|
|
138
137
|
"import": "./src/utils/schema/index.ts"
|
|
139
138
|
},
|
|
140
139
|
"./utils/schema/*": {
|
|
141
|
-
"types": "./
|
|
140
|
+
"types": "./src/utils/schema/*.ts",
|
|
142
141
|
"import": "./src/utils/schema/*.ts"
|
|
143
142
|
},
|
|
144
143
|
"./*.js": "./src/*.ts"
|
package/src/model-cache.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Replaces per-provider JSON files with a single cache.db.
|
|
4
4
|
*/
|
|
5
5
|
import { Database } from "bun:sqlite";
|
|
6
|
-
import { getModelDbPath } from "@sayknow-cli/utils";
|
|
6
|
+
import { getModelDbPath } from "@sayknow-cli/utils/dirs";
|
|
7
7
|
import type { Api, Model } from "./types";
|
|
8
8
|
|
|
9
9
|
const CACHE_SCHEMA_VERSION = 3;
|
package/src/model-manager.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readModelCache, writeModelCache } from "./model-cache";
|
|
2
|
+
import { isRetiredModel, isRetiredModelKey } from "./model-retirements";
|
|
2
3
|
import { applyGeneratedModelPolicies, enrichModelThinking } from "./model-thinking";
|
|
3
4
|
import { type GeneratedProvider, getBundledModels } from "./models";
|
|
4
5
|
import type { Api, Model, Provider } from "./types";
|
|
5
|
-
import { isRecord } from "./utils";
|
|
6
6
|
|
|
7
7
|
const DEFAULT_CACHE_TTL_MS = 2 * 60 * 60 * 1000;
|
|
8
8
|
const NON_AUTHORITATIVE_RETRY_MS = 5 * 60 * 1000;
|
|
@@ -85,7 +85,14 @@ function passModelList<TApi extends Api>(value: unknown): Model<TApi>[] {
|
|
|
85
85
|
}
|
|
86
86
|
const out: Model<TApi>[] = [];
|
|
87
87
|
for (const item of value) {
|
|
88
|
-
if (item === null || typeof item !== "object"
|
|
88
|
+
if (item === null || typeof item !== "object") {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const candidate = item as { id?: unknown; provider?: unknown };
|
|
92
|
+
if (typeof candidate.id !== "string") {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (typeof candidate.provider === "string" && isRetiredModelKey(candidate.provider, candidate.id)) {
|
|
89
96
|
continue;
|
|
90
97
|
}
|
|
91
98
|
out.push(enrichModelThinking(item as Model<TApi>));
|
|
@@ -382,7 +389,7 @@ function normalizeModelList<TApi extends Api>(value: unknown): Model<TApi>[] {
|
|
|
382
389
|
}
|
|
383
390
|
const models: Model<TApi>[] = [];
|
|
384
391
|
for (const item of value) {
|
|
385
|
-
if (isModelLike(item)) {
|
|
392
|
+
if (isModelLike(item) && !isRetiredModel(item)) {
|
|
386
393
|
models.push(enrichModelThinking(item as Model<TApi>));
|
|
387
394
|
}
|
|
388
395
|
}
|
|
@@ -441,6 +448,10 @@ function isModelLike(value: unknown): value is Model<Api> {
|
|
|
441
448
|
return true;
|
|
442
449
|
}
|
|
443
450
|
|
|
451
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
452
|
+
return typeof value === "object" && value !== null;
|
|
453
|
+
}
|
|
454
|
+
|
|
444
455
|
function isModelInputArray(value: unknown): value is ("text" | "image")[] {
|
|
445
456
|
if (!Array.isArray(value) || value.length === 0) {
|
|
446
457
|
return false;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Retired from advertised catalogs because Cloud Code Assist rejects live calls
|
|
2
|
+
// with HTTP 400. The callable high-thinking path is gemini-3.1-pro-low:high.
|
|
3
|
+
export const RETIRED_MODEL_KEYS = ["google-antigravity/gemini-3.1-pro-high"] as const;
|
|
4
|
+
|
|
5
|
+
const RETIRED_MODEL_KEY_SET = new Set<string>(RETIRED_MODEL_KEYS);
|
|
6
|
+
|
|
7
|
+
export function isRetiredModelKey(provider: string, modelId: string): boolean {
|
|
8
|
+
return RETIRED_MODEL_KEY_SET.has(`${provider}/${modelId}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isRetiredModel(model: { provider: string; id: string }): boolean {
|
|
12
|
+
return isRetiredModelKey(model.provider, model.id);
|
|
13
|
+
}
|
package/src/model-thinking.ts
CHANGED
|
@@ -47,6 +47,7 @@ const DEFAULT_REASONING_EFFORTS_WITH_XHIGH_AND_MAX: readonly Effort[] = [
|
|
|
47
47
|
const GEMINI_3_PRO_EFFORTS: readonly Effort[] = [Effort.Low, Effort.High];
|
|
48
48
|
const GEMINI_3_FLASH_EFFORTS: readonly Effort[] = [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High];
|
|
49
49
|
const GPT_5_2_PLUS_EFFORTS: readonly Effort[] = [Effort.Low, Effort.Medium, Effort.High, Effort.XHigh];
|
|
50
|
+
const GPT_5_6_PLUS_EFFORTS: readonly Effort[] = [Effort.Low, Effort.Medium, Effort.High, Effort.XHigh, Effort.Max];
|
|
50
51
|
const GPT_5_5_DEFAULT_EFFORT = Effort.XHigh;
|
|
51
52
|
|
|
52
53
|
const GPT_5_1_CODEX_MINI_EFFORTS: readonly Effort[] = [Effort.Medium, Effort.High];
|
|
@@ -60,7 +61,18 @@ type SemVer = {
|
|
|
60
61
|
|
|
61
62
|
type GeminiKind = "pro" | "flash";
|
|
62
63
|
type AnthropicKind = "opus" | "sonnet";
|
|
63
|
-
type OpenAIVariant =
|
|
64
|
+
type OpenAIVariant =
|
|
65
|
+
| "base"
|
|
66
|
+
| "codex"
|
|
67
|
+
| "codex-max"
|
|
68
|
+
| "codex-mini"
|
|
69
|
+
| "codex-spark"
|
|
70
|
+
| "luna"
|
|
71
|
+
| "mini"
|
|
72
|
+
| "max"
|
|
73
|
+
| "nano"
|
|
74
|
+
| "sol"
|
|
75
|
+
| "terra";
|
|
64
76
|
|
|
65
77
|
const CODEX_GPT_5_4_PRIORITY_BY_VARIANT: Partial<Record<OpenAIVariant, number>> = {
|
|
66
78
|
base: 0,
|
|
@@ -465,11 +477,25 @@ function applyGpt55ContextWindow(model: ApiModel<Api>, parsedModel: OpenAIModel)
|
|
|
465
477
|
}
|
|
466
478
|
return false;
|
|
467
479
|
}
|
|
480
|
+
const GPT_5_6_TIER_VARIANTS: ReadonlySet<OpenAIVariant> = new Set(["base", "sol", "terra", "luna"]);
|
|
481
|
+
|
|
482
|
+
function applyGpt56ContextWindow(model: ApiModel<Api>, parsedModel: OpenAIModel): boolean {
|
|
483
|
+
if (!semverGte(parsedModel.version, "5.6") || !GPT_5_6_TIER_VARIANTS.has(parsedModel.variant)) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
// GPT-5.6 tiers enforce a ~373K usable prompt budget on both transports
|
|
487
|
+
// (matches the openai-codex live catalog), despite the 1M+ marketing window.
|
|
488
|
+
model.contextWindow = 373_000;
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
468
491
|
|
|
469
492
|
function applyOpenAICatalogPolicy(model: ApiModel<Api>, parsedModel: OpenAIModel): void {
|
|
470
493
|
if (applyGpt55ContextWindow(model, parsedModel)) {
|
|
471
494
|
return;
|
|
472
495
|
}
|
|
496
|
+
if (applyGpt56ContextWindow(model, parsedModel)) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
473
499
|
// OpenAI code backend models: 400K figure includes output budget; input window is 272K.
|
|
474
500
|
if (parsedModel.variant.startsWith("codex") && parsedModel.variant !== "codex-spark") {
|
|
475
501
|
model.contextWindow = 272000;
|
|
@@ -582,6 +608,9 @@ function inferOpenAISupportedEfforts(model: OpenAIModel): readonly Effort[] {
|
|
|
582
608
|
if (model.variant === "codex-mini" && semverEqual(model.version, "5.1")) {
|
|
583
609
|
return GPT_5_1_CODEX_MINI_EFFORTS;
|
|
584
610
|
}
|
|
611
|
+
if (semverGte(model.version, "5.6")) {
|
|
612
|
+
return GPT_5_6_PLUS_EFFORTS;
|
|
613
|
+
}
|
|
585
614
|
if (semverGte(model.version, "5.2")) {
|
|
586
615
|
return GPT_5_2_PLUS_EFFORTS;
|
|
587
616
|
}
|
|
@@ -714,7 +743,10 @@ function parseAnthropicModel(modelId: string): AnthropicModel | null {
|
|
|
714
743
|
}
|
|
715
744
|
|
|
716
745
|
function parseOpenAIModel(modelId: string): OpenAIModel | null {
|
|
717
|
-
const match =
|
|
746
|
+
const match =
|
|
747
|
+
/gpt-(\d+(?:\.\d+){0,2})(?:-(codex-spark|codex-mini|codex-max|codex|luna|mini|max|nano|sol|terra))?$/.exec(
|
|
748
|
+
modelId,
|
|
749
|
+
);
|
|
718
750
|
if (!match) {
|
|
719
751
|
return null;
|
|
720
752
|
}
|
package/src/models.ts
CHANGED
|
@@ -1,26 +1,46 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { isRetiredModelKey } from "./model-retirements";
|
|
1
3
|
import { applyGeneratedModelPolicies, enrichModelThinking } from "./model-thinking";
|
|
2
|
-
|
|
4
|
+
// `with { type: "file" }` is embedded by `bun build --compile` and resolves to
|
|
5
|
+
// the bunfs path inside standalone binaries (and to the on-disk path in dev).
|
|
6
|
+
// A plain `createRequire` of a `.json` listed as an extra compile entrypoint is
|
|
7
|
+
// NOT emitted into the bunfs, and its cwd-fallback masks the failure whenever
|
|
8
|
+
// the process runs inside a repo checkout — see PR body for the minimal repro.
|
|
9
|
+
import modelsJsonPath from "./models.json" with { type: "file" };
|
|
3
10
|
import type { Api, KnownProvider, Model, Usage } from "./types";
|
|
4
11
|
import { isClaudeForcedToolChoiceIncapableModelId } from "./utils/tool-choice-capability";
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
|
-
* Static bundled model registry loaded from `models.json`.
|
|
14
|
+
* Static bundled model registry loaded lazily from `models.json`.
|
|
8
15
|
*
|
|
9
16
|
* This module intentionally exposes compile-time defaults only.
|
|
10
17
|
* It does not include runtime discovery, models.dev overlays, or on-disk cache state.
|
|
11
18
|
*
|
|
12
19
|
* For runtime-aware resolution, use `createModelManager()` / `resolveProviderModels()`.
|
|
13
20
|
*/
|
|
14
|
-
|
|
21
|
+
type BundledCatalog = typeof import("./models.json");
|
|
22
|
+
|
|
23
|
+
let bundledCatalog: BundledCatalog | undefined;
|
|
24
|
+
let providerNames: KnownProvider[] | undefined;
|
|
15
25
|
const providerModelRegistry: Map<string, Map<string, Model<Api>>> = new Map();
|
|
16
26
|
|
|
27
|
+
function getBundledCatalog(): BundledCatalog {
|
|
28
|
+
// TS types a .json import as its contents; at runtime `with { type: "file" }`
|
|
29
|
+
// yields the file path (bunfs path in compiled binaries, disk path in dev).
|
|
30
|
+
bundledCatalog ??= JSON.parse(readFileSync(modelsJsonPath as unknown as string, "utf8")) as BundledCatalog;
|
|
31
|
+
return bundledCatalog;
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
function getProviderModels(provider: GeneratedProvider): Map<string, Model<Api>> | undefined {
|
|
18
35
|
const cached = providerModelRegistry.get(provider);
|
|
19
36
|
if (cached) return cached;
|
|
20
|
-
const models =
|
|
37
|
+
const models = getBundledCatalog()[provider];
|
|
21
38
|
if (!models) return undefined;
|
|
22
39
|
const providerModels = new Map<string, Model<Api>>();
|
|
23
40
|
for (const [id, model] of Object.entries(models)) {
|
|
41
|
+
if (isRetiredModelKey(provider, id)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
24
44
|
providerModels.set(id, applyBundledCompatDefaults(enrichModelThinking(model as Model<Api>)));
|
|
25
45
|
}
|
|
26
46
|
providerModelRegistry.set(provider, providerModels);
|
|
@@ -52,7 +72,7 @@ function applyBundledCompatDefaults(model: Model<Api>): Model<Api> {
|
|
|
52
72
|
return policyModels[0] ?? normalized;
|
|
53
73
|
}
|
|
54
74
|
|
|
55
|
-
export type GeneratedProvider = keyof
|
|
75
|
+
export type GeneratedProvider = keyof BundledCatalog;
|
|
56
76
|
|
|
57
77
|
export function getBundledModel<TApi extends Api = Api>(provider: GeneratedProvider, modelId: string): Model<TApi> {
|
|
58
78
|
const providerModels = getProviderModels(provider);
|
|
@@ -62,6 +82,7 @@ export function getBundledModel<TApi extends Api = Api>(provider: GeneratedProvi
|
|
|
62
82
|
export function getBundledProviders(): KnownProvider[] {
|
|
63
83
|
// Defensive copy: the old eager path returned a fresh Array.from(...), so
|
|
64
84
|
// callers may freely mutate their result without corrupting enumeration.
|
|
85
|
+
providerNames ??= Object.keys(getBundledCatalog()) as KnownProvider[];
|
|
65
86
|
return providerNames.slice();
|
|
66
87
|
}
|
|
67
88
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Bun's native `HTTPS_PROXY` support.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { $env, $flag, extractHttpStatusFromError, fetchWithRetry } from "@sayknow-cli/utils";
|
|
10
|
+
import { $credentialEnv, $env, $flag, extractHttpStatusFromError, fetchWithRetry } from "@sayknow-cli/utils";
|
|
11
11
|
import type { Effort } from "../model-thinking";
|
|
12
12
|
import { mapEffortToAnthropicAdaptiveEffort, requireSupportedEffort } from "../model-thinking";
|
|
13
13
|
import { calculateCost } from "../models";
|
|
@@ -39,8 +39,10 @@ import {
|
|
|
39
39
|
markToolChoiceIncapability,
|
|
40
40
|
resolveToolChoice,
|
|
41
41
|
} from "../utils/tool-choice-capability";
|
|
42
|
+
import { isValidBedrockBearerToken } from "./aws-credential-config";
|
|
42
43
|
import { resolveAwsCredentials } from "./aws-credentials";
|
|
43
44
|
import { decodeEventStream } from "./aws-eventstream";
|
|
45
|
+
import type { AwsCredentials } from "./aws-sigv4";
|
|
44
46
|
import { signRequest } from "./aws-sigv4";
|
|
45
47
|
import { transformMessages } from "./transform-messages";
|
|
46
48
|
|
|
@@ -162,6 +164,8 @@ interface MetadataEvent {
|
|
|
162
164
|
};
|
|
163
165
|
}
|
|
164
166
|
|
|
167
|
+
type BedrockAuthMode = { kind: "bearer"; token: string } | { kind: "sigv4"; credentials: AwsCredentials };
|
|
168
|
+
|
|
165
169
|
export const streamBedrock: StreamFunction<"bedrock-converse-stream"> = (
|
|
166
170
|
model: Model<"bedrock-converse-stream">,
|
|
167
171
|
context: Context,
|
|
@@ -233,34 +237,44 @@ export const streamBedrock: StreamFunction<"bedrock-converse-stream"> = (
|
|
|
233
237
|
body: commandInput,
|
|
234
238
|
};
|
|
235
239
|
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
} else {
|
|
240
|
-
credentials = await resolveAwsCredentials({
|
|
241
|
-
profile: options.profile,
|
|
242
|
-
region,
|
|
243
|
-
signal: options.signal,
|
|
244
|
-
});
|
|
240
|
+
const bearerToken = $credentialEnv("AWS_BEARER_TOKEN_BEDROCK");
|
|
241
|
+
if (bearerToken && !isValidBedrockBearerToken(bearerToken)) {
|
|
242
|
+
throw new Error("AWS_BEARER_TOKEN_BEDROCK contains unsafe control characters.");
|
|
245
243
|
}
|
|
246
|
-
|
|
244
|
+
const authMode: BedrockAuthMode = bearerToken
|
|
245
|
+
? { kind: "bearer", token: bearerToken }
|
|
246
|
+
: {
|
|
247
|
+
kind: "sigv4",
|
|
248
|
+
credentials: $flag("AWS_BEDROCK_SKIP_AUTH")
|
|
249
|
+
? { accessKeyId: "dummy-access-key", secretAccessKey: "dummy-secret-key" }
|
|
250
|
+
: await resolveAwsCredentials({ profile: options.profile, region, signal: options.signal }),
|
|
251
|
+
};
|
|
247
252
|
const bodyText = JSON.stringify(commandInput);
|
|
248
253
|
const body = new TextEncoder().encode(bodyText);
|
|
249
254
|
const baseHeaders: Record<string, string> = {
|
|
250
255
|
"content-type": "application/json",
|
|
251
256
|
accept: "application/vnd.amazon.eventstream",
|
|
252
257
|
};
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
const buildRequestHeaders = async (requestBody: Uint8Array): Promise<Record<string, string>> => {
|
|
259
|
+
const headers = new Headers(baseHeaders);
|
|
260
|
+
if (authMode.kind === "bearer") {
|
|
261
|
+
headers.set("authorization", `Bearer ${authMode.token}`);
|
|
262
|
+
return Object.fromEntries(headers);
|
|
263
|
+
}
|
|
264
|
+
const signed = await signRequest({
|
|
265
|
+
method: "POST",
|
|
266
|
+
host,
|
|
267
|
+
path: urlPath,
|
|
268
|
+
body: requestBody,
|
|
269
|
+
region,
|
|
270
|
+
service: "bedrock",
|
|
271
|
+
credentials: authMode.credentials,
|
|
272
|
+
headers: baseHeaders,
|
|
273
|
+
});
|
|
274
|
+
for (const [name, value] of Object.entries(signed)) headers.set(name, value);
|
|
275
|
+
return Object.fromEntries(headers);
|
|
276
|
+
};
|
|
277
|
+
const requestHeaders = await buildRequestHeaders(body);
|
|
264
278
|
const sentForcedToolChoice = Boolean(toolConfig?.toolChoice?.any || toolConfig?.toolChoice?.tool);
|
|
265
279
|
let fallbackRan = false;
|
|
266
280
|
const retryWithoutForcedToolChoice = async (reason: string) => {
|
|
@@ -279,20 +293,10 @@ export const streamBedrock: StreamFunction<"bedrock-converse-stream"> = (
|
|
|
279
293
|
stripBedrockForcedToolChoiceForRetry(commandInput);
|
|
280
294
|
const retryBodyText = JSON.stringify(commandInput);
|
|
281
295
|
const retryBody = new TextEncoder().encode(retryBodyText);
|
|
282
|
-
const retrySigned = await signRequest({
|
|
283
|
-
method: "POST",
|
|
284
|
-
host,
|
|
285
|
-
path: urlPath,
|
|
286
|
-
body: retryBody,
|
|
287
|
-
region,
|
|
288
|
-
service: "bedrock",
|
|
289
|
-
credentials,
|
|
290
|
-
headers: baseHeaders,
|
|
291
|
-
});
|
|
292
296
|
if (rawRequestDump) rawRequestDump.body = commandInput;
|
|
293
297
|
return fetchWithRetry(url, {
|
|
294
298
|
method: "POST",
|
|
295
|
-
headers:
|
|
299
|
+
headers: await buildRequestHeaders(retryBody),
|
|
296
300
|
body: retryBody,
|
|
297
301
|
signal: options.signal,
|
|
298
302
|
maxAttempts: 1,
|