@gajae-code/ai 0.16.1 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/types/auth-gateway/server.d.ts +4 -2
  3. package/dist/types/bedrock-claude-cache-policy.d.ts +21 -0
  4. package/dist/types/openai-completions-compat.d.ts +22 -0
  5. package/dist/types/providers/amazon-bedrock.d.ts +17 -2
  6. package/dist/types/providers/anthropic.d.ts +1 -0
  7. package/dist/types/providers/openai-completions-compat.d.ts +1 -1
  8. package/dist/types/providers/opencode-go-session.d.ts +5 -0
  9. package/dist/types/types.d.ts +7 -0
  10. package/dist/types/utils/codex-entitlement.d.ts +22 -0
  11. package/package.json +3 -3
  12. package/src/auth-gateway/server.ts +5 -0
  13. package/src/auth-storage.ts +31 -8
  14. package/src/bedrock-claude-cache-policy.d.ts +21 -0
  15. package/src/bedrock-claude-cache-policy.ts +68 -0
  16. package/src/model-pricing.ts +11 -0
  17. package/src/model-thinking.ts +31 -7
  18. package/src/models.json +37 -0
  19. package/src/openai-completions-compat.d.ts +22 -0
  20. package/src/openai-completions-compat.ts +77 -3
  21. package/src/providers/amazon-bedrock.d.ts +17 -2
  22. package/src/providers/amazon-bedrock.ts +9 -9
  23. package/src/providers/anthropic.d.ts +1 -0
  24. package/src/providers/anthropic.ts +38 -21
  25. package/src/providers/cursor.ts +12 -6
  26. package/src/providers/openai-codex/response-handler.ts +1 -1
  27. package/src/providers/openai-codex-responses.ts +14 -5
  28. package/src/providers/openai-completions-compat.d.ts +1 -1
  29. package/src/providers/openai-completions-compat.ts +8 -1
  30. package/src/providers/openai-completions.ts +14 -1
  31. package/src/providers/openai-responses.ts +11 -1
  32. package/src/providers/opencode-go-session.d.ts +5 -0
  33. package/src/providers/opencode-go-session.ts +57 -0
  34. package/src/stream.ts +1 -0
  35. package/src/types.d.ts +7 -0
  36. package/src/types.ts +7 -0
  37. package/src/utils/codex-entitlement.d.ts +22 -0
  38. package/src/utils/codex-entitlement.ts +57 -0
  39. package/src/utils/discovery/antigravity.ts +2 -1
  40. package/src/utils/discovery/gemini.ts +2 -1
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Model entitlement facts shared by Codex credential selection and provider
3
+ * error presentation.
4
+ *
5
+ * GPT-5.6 Sol is a Pro-tier ChatGPT Codex model. The usage endpoint is the
6
+ * authority for the account tier; this module only names the model policy and
7
+ * keeps the provider's deterministic rejection wording in one place.
8
+ */
9
+ export type OpenAICodexProEntitlement = "entitled" | "denied" | "unknown";
10
+ /**
11
+ * Classify a ChatGPT `plan_type` for strict Pro-tier Codex models.
12
+ *
13
+ * The usage endpoint remains authoritative: only exact, documented tier names
14
+ * are classified. Known Free/Plus tiers can be rejected locally, while missing
15
+ * or unfamiliar values stay unknown and reach the provider instead of being
16
+ * guessed from a substring.
17
+ */
18
+ export declare function classifyOpenAICodexProEntitlement(planType: string | undefined): OpenAICodexProEntitlement;
19
+ export declare function requiresOpenAICodexProModel(provider: string, modelId: string | undefined): boolean;
20
+ export declare function requiresStrictOpenAICodexProModel(provider: string, modelId: string | undefined): boolean;
21
+ export declare function isOpenAICodexChatGPTEntitlementError(message: string | undefined, code?: string): boolean;
22
+ export declare function formatOpenAICodexChatGPTEntitlementError(modelId: string | undefined): string;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Model entitlement facts shared by Codex credential selection and provider
3
+ * error presentation.
4
+ *
5
+ * GPT-5.6 Sol is a Pro-tier ChatGPT Codex model. The usage endpoint is the
6
+ * authority for the account tier; this module only names the model policy and
7
+ * keeps the provider's deterministic rejection wording in one place.
8
+ */
9
+
10
+ const OPENAI_CODEX_PRO_ENTITLED_PLAN_TYPES = new Set(["pro", "business", "enterprise", "team"]);
11
+ const OPENAI_CODEX_PRO_DENIED_PLAN_TYPES = new Set(["free", "plus"]);
12
+
13
+ export type OpenAICodexProEntitlement = "entitled" | "denied" | "unknown";
14
+
15
+ /**
16
+ * Classify a ChatGPT `plan_type` for strict Pro-tier Codex models.
17
+ *
18
+ * The usage endpoint remains authoritative: only exact, documented tier names
19
+ * are classified. Known Free/Plus tiers can be rejected locally, while missing
20
+ * or unfamiliar values stay unknown and reach the provider instead of being
21
+ * guessed from a substring.
22
+ */
23
+ export function classifyOpenAICodexProEntitlement(planType: string | undefined): OpenAICodexProEntitlement {
24
+ const normalized = planType?.trim().toLowerCase();
25
+ if (!normalized) return "unknown";
26
+ if (OPENAI_CODEX_PRO_ENTITLED_PLAN_TYPES.has(normalized)) return "entitled";
27
+ if (OPENAI_CODEX_PRO_DENIED_PLAN_TYPES.has(normalized)) return "denied";
28
+ return "unknown";
29
+ }
30
+
31
+ export function requiresOpenAICodexProModel(provider: string, modelId: string | undefined): boolean {
32
+ return (
33
+ provider === "openai-codex" &&
34
+ typeof modelId === "string" &&
35
+ (modelId.toLowerCase().includes("-spark") || modelId.toLowerCase() === "gpt-5.6-sol")
36
+ );
37
+ }
38
+
39
+ export function requiresStrictOpenAICodexProModel(provider: string, modelId: string | undefined): boolean {
40
+ return provider === "openai-codex" && modelId?.toLowerCase() === "gpt-5.6-sol";
41
+ }
42
+
43
+ export function isOpenAICodexChatGPTEntitlementError(message: string | undefined, code?: string): boolean {
44
+ return (
45
+ /\bnot supported when using codex with a chatgpt account\b/i.test(message ?? "") &&
46
+ (code === undefined || code.toLowerCase() === "invalid_request_error")
47
+ );
48
+ }
49
+
50
+ export function formatOpenAICodexChatGPTEntitlementError(modelId: string | undefined): string {
51
+ const safeModelId = modelId
52
+ ?.replace(/[\x00-\x1f\x7f-\x9f]+/gu, " ")
53
+ .trim()
54
+ .slice(0, 128);
55
+ const model = safeModelId ? ` model "${safeModelId}"` : " model";
56
+ return `This ChatGPT Codex account cannot use${model}. Select a model available to this ChatGPT account, such as "gpt-5.5", or use an API-key credential that supports the model.`;
57
+ }
@@ -180,6 +180,7 @@ export async function fetchAntigravityDiscoveryModels(
180
180
  options: FetchAntigravityDiscoveryModelsOptions,
181
181
  ): Promise<Model<"google-gemini-cli">[] | null> {
182
182
  const fetcher = options.fetcher ?? fetch;
183
+ const signal = options.signal ?? AbortSignal.timeout(5_000);
183
184
  const targetProvider = options.targetProvider ?? "google-antigravity";
184
185
  const endpoints = options.endpoint
185
186
  ? [trimTrailingSlashes(options.endpoint)]
@@ -196,7 +197,7 @@ export async function fetchAntigravityDiscoveryModels(
196
197
  "User-Agent": options.userAgent ?? getAntigravityUserAgent(),
197
198
  },
198
199
  body: JSON.stringify({}),
199
- signal: options.signal,
200
+ signal,
200
201
  });
201
202
  } catch {
202
203
  continue;
@@ -72,6 +72,7 @@ export async function fetchGeminiModels(
72
72
  const baseUrl = normalizeBaseUrl(options.baseUrl);
73
73
  const pageSize = normalizePositiveInt(options.pageSize, DEFAULT_PAGE_SIZE);
74
74
  const maxPages = normalizePositiveInt(options.maxPages, DEFAULT_MAX_PAGES);
75
+ const signal = options.signal ?? AbortSignal.timeout(5_000);
75
76
 
76
77
  const bundledById = new Map(
77
78
  getBundledModels("google").map(model => [model.id, model as Model<"google-generative-ai">]),
@@ -86,7 +87,7 @@ export async function fetchGeminiModels(
86
87
  try {
87
88
  response = await fetchImpl(requestUrl, {
88
89
  method: "GET",
89
- signal: options.signal,
90
+ signal,
90
91
  });
91
92
  } catch {
92
93
  return null;