@oh-my-pi/pi-catalog 15.10.11

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 (90) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/types/build.d.ts +3 -0
  3. package/dist/types/compat/anthropic.d.ts +11 -0
  4. package/dist/types/compat/apply.d.ts +7 -0
  5. package/dist/types/compat/openai.d.ts +21 -0
  6. package/dist/types/discovery/antigravity.d.ts +61 -0
  7. package/dist/types/discovery/codex.d.ts +38 -0
  8. package/dist/types/discovery/cursor-gen/agent_pb.d.ts +13022 -0
  9. package/dist/types/discovery/cursor.d.ts +23 -0
  10. package/dist/types/discovery/gemini.d.ts +25 -0
  11. package/dist/types/discovery/index.d.ts +4 -0
  12. package/dist/types/discovery/openai-compatible.d.ts +72 -0
  13. package/dist/types/effort.d.ts +9 -0
  14. package/dist/types/fireworks-model-id.d.ts +10 -0
  15. package/dist/types/hosts.d.ts +128 -0
  16. package/dist/types/identity/bundled.d.ts +6 -0
  17. package/dist/types/identity/classify.d.ts +45 -0
  18. package/dist/types/identity/equivalence.d.ts +46 -0
  19. package/dist/types/identity/family.d.ts +45 -0
  20. package/dist/types/identity/id.d.ts +12 -0
  21. package/dist/types/identity/index.d.ts +9 -0
  22. package/dist/types/identity/markers.d.ts +4 -0
  23. package/dist/types/identity/priority.d.ts +1 -0
  24. package/dist/types/identity/reference.d.ts +22 -0
  25. package/dist/types/identity/selection.d.ts +20 -0
  26. package/dist/types/index.d.ts +15 -0
  27. package/dist/types/model-cache.d.ts +17 -0
  28. package/dist/types/model-manager.d.ts +64 -0
  29. package/dist/types/model-thinking.d.ts +67 -0
  30. package/dist/types/models.d.ts +12 -0
  31. package/dist/types/provider-models/bundled-references.d.ts +11 -0
  32. package/dist/types/provider-models/descriptor-types.d.ts +74 -0
  33. package/dist/types/provider-models/descriptors.d.ts +384 -0
  34. package/dist/types/provider-models/discovery-constants.d.ts +11 -0
  35. package/dist/types/provider-models/google.d.ts +27 -0
  36. package/dist/types/provider-models/index.d.ts +6 -0
  37. package/dist/types/provider-models/ollama.d.ts +9 -0
  38. package/dist/types/provider-models/openai-compat.d.ts +385 -0
  39. package/dist/types/provider-models/special.d.ts +16 -0
  40. package/dist/types/types.d.ts +405 -0
  41. package/dist/types/utils.d.ts +5 -0
  42. package/dist/types/wire/codex.d.ts +26 -0
  43. package/dist/types/wire/gemini-headers.d.ts +18 -0
  44. package/dist/types/wire/github-copilot.d.ts +18 -0
  45. package/package.json +100 -0
  46. package/src/build.ts +40 -0
  47. package/src/compat/anthropic.ts +67 -0
  48. package/src/compat/apply.ts +15 -0
  49. package/src/compat/openai.ts +365 -0
  50. package/src/discovery/antigravity.ts +261 -0
  51. package/src/discovery/codex.ts +371 -0
  52. package/src/discovery/cursor-gen/agent_pb.ts +15274 -0
  53. package/src/discovery/cursor.ts +307 -0
  54. package/src/discovery/gemini.ts +249 -0
  55. package/src/discovery/index.ts +4 -0
  56. package/src/discovery/openai-compatible.ts +224 -0
  57. package/src/effort.ts +16 -0
  58. package/src/fireworks-model-id.ts +30 -0
  59. package/src/hosts.ts +114 -0
  60. package/src/identity/bundled.ts +38 -0
  61. package/src/identity/classify.ts +141 -0
  62. package/src/identity/equivalence.ts +870 -0
  63. package/src/identity/family.ts +88 -0
  64. package/src/identity/id.ts +81 -0
  65. package/src/identity/index.ts +9 -0
  66. package/src/identity/markers.ts +49 -0
  67. package/src/identity/priority.ts +56 -0
  68. package/src/identity/reference.ts +134 -0
  69. package/src/identity/selection.ts +65 -0
  70. package/src/index.ts +15 -0
  71. package/src/model-cache.ts +132 -0
  72. package/src/model-manager.ts +472 -0
  73. package/src/model-thinking.ts +407 -0
  74. package/src/models.json +75308 -0
  75. package/src/models.json.d.ts +9 -0
  76. package/src/models.ts +64 -0
  77. package/src/provider-models/bundled-references.ts +54 -0
  78. package/src/provider-models/descriptor-types.ts +79 -0
  79. package/src/provider-models/descriptors.ts +456 -0
  80. package/src/provider-models/discovery-constants.ts +11 -0
  81. package/src/provider-models/google.ts +105 -0
  82. package/src/provider-models/index.ts +6 -0
  83. package/src/provider-models/ollama.ts +154 -0
  84. package/src/provider-models/openai-compat.ts +3106 -0
  85. package/src/provider-models/special.ts +67 -0
  86. package/src/types.ts +470 -0
  87. package/src/utils.ts +27 -0
  88. package/src/wire/codex.ts +43 -0
  89. package/src/wire/gemini-headers.ts +41 -0
  90. package/src/wire/github-copilot.ts +72 -0
@@ -0,0 +1,105 @@
1
+ import { fetchAntigravityDiscoveryModels } from "../discovery/antigravity";
2
+ import { fetchGeminiModels } from "../discovery/gemini";
3
+ import type { ModelManagerOptions } from "../model-manager";
4
+ import type { FetchImpl } from "../types";
5
+
6
+ export interface GoogleModelManagerConfig {
7
+ apiKey?: string;
8
+ fetch?: FetchImpl;
9
+ }
10
+
11
+ export interface GoogleVertexModelManagerConfig {
12
+ apiKey?: string;
13
+ project?: string;
14
+ location?: string;
15
+ signal?: AbortSignal;
16
+ fetch?: FetchImpl;
17
+ }
18
+
19
+ export interface GoogleAntigravityModelManagerConfig {
20
+ oauthToken?: string;
21
+ endpoint?: string;
22
+ fetch?: FetchImpl;
23
+ }
24
+
25
+ export interface GoogleGeminiCliModelManagerConfig {
26
+ oauthToken?: string;
27
+ endpoint?: string;
28
+ fetch?: FetchImpl;
29
+ }
30
+
31
+ const CLOUD_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
32
+
33
+ function toDiscoveryFetch(fetchImpl: FetchImpl | undefined): typeof fetch | undefined {
34
+ if (!fetchImpl) {
35
+ return undefined;
36
+ }
37
+ return Object.assign(
38
+ (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => fetchImpl(input, init),
39
+ { preconnect: fetchImpl.preconnect ?? fetch.preconnect },
40
+ );
41
+ }
42
+
43
+ export function googleModelManagerOptions(
44
+ config?: GoogleModelManagerConfig,
45
+ ): ModelManagerOptions<"google-generative-ai"> {
46
+ const apiKey = config?.apiKey;
47
+ return {
48
+ providerId: "google",
49
+ ...(apiKey
50
+ ? { fetchDynamicModels: () => fetchGeminiModels({ apiKey, fetch: toDiscoveryFetch(config?.fetch) }) }
51
+ : undefined),
52
+ };
53
+ }
54
+
55
+ export function googleVertexModelManagerOptions(_config?: GoogleVertexModelManagerConfig): ModelManagerOptions {
56
+ return { providerId: "google-vertex" };
57
+ }
58
+
59
+ export function googleAntigravityModelManagerOptions(
60
+ config?: GoogleAntigravityModelManagerConfig,
61
+ ): ModelManagerOptions<"google-gemini-cli"> {
62
+ const token = config?.oauthToken;
63
+ return {
64
+ providerId: "google-antigravity",
65
+ ...(token
66
+ ? {
67
+ fetchDynamicModels: () =>
68
+ fetchAntigravityDiscoveryModels({
69
+ token,
70
+ endpoint: config?.endpoint,
71
+ fetcher: toDiscoveryFetch(config?.fetch),
72
+ }),
73
+ }
74
+ : undefined),
75
+ };
76
+ }
77
+
78
+ export function googleGeminiCliModelManagerOptions(
79
+ config?: GoogleGeminiCliModelManagerConfig,
80
+ ): ModelManagerOptions<"google-gemini-cli"> {
81
+ const token = config?.oauthToken;
82
+ const endpoint = config?.endpoint ?? CLOUD_CODE_ASSIST_ENDPOINT;
83
+ return {
84
+ providerId: "google-gemini-cli",
85
+ ...(token
86
+ ? {
87
+ fetchDynamicModels: async () => {
88
+ const models = await fetchAntigravityDiscoveryModels({
89
+ token,
90
+ endpoint,
91
+ fetcher: toDiscoveryFetch(config?.fetch),
92
+ });
93
+ if (models === null) {
94
+ return null;
95
+ }
96
+ return models.map(m => ({
97
+ ...m,
98
+ provider: "google-gemini-cli" as const,
99
+ baseUrl: endpoint,
100
+ }));
101
+ },
102
+ }
103
+ : undefined),
104
+ };
105
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./descriptor-types";
2
+ export * from "./descriptors";
3
+ export * from "./google";
4
+ export * from "./ollama";
5
+ export * from "./openai-compat";
6
+ export * from "./special";
@@ -0,0 +1,154 @@
1
+ import { fetchWithRetry } from "@oh-my-pi/pi-utils";
2
+ import { Effort } from "../effort";
3
+ import type { ModelManagerOptions } from "../model-manager";
4
+ import type { FetchImpl, ThinkingConfig } from "../types";
5
+ import { createBundledReferenceMap, createReferenceResolver } from "./bundled-references";
6
+
7
+ export interface OllamaCloudModelManagerConfig {
8
+ apiKey?: string;
9
+ baseUrl?: string;
10
+ fetch?: FetchImpl;
11
+ }
12
+
13
+ type OllamaTagEntry = {
14
+ name?: string;
15
+ model?: string;
16
+ };
17
+
18
+ type OllamaShowResponse = {
19
+ capabilities?: string[];
20
+ model_info?: Record<string, unknown>;
21
+ };
22
+
23
+ const OLLAMA_RETRY_DELAYS_MS = [2_000, 5_000, 10_000];
24
+
25
+ function trimTrailingSlash(value: string): string {
26
+ return value.endsWith("/") ? value.slice(0, -1) : value;
27
+ }
28
+
29
+ export function normalizeOllamaCloudBaseUrl(baseUrl?: string): string {
30
+ const value = baseUrl?.trim();
31
+ if (!value) {
32
+ return "https://ollama.com";
33
+ }
34
+ const trimmed = trimTrailingSlash(value);
35
+ return trimmed.endsWith("/api") ? trimmed.slice(0, -4) : trimmed;
36
+ }
37
+
38
+ function createCloudHeaders(apiKey: string): Record<string, string> {
39
+ return {
40
+ Accept: "application/json",
41
+ Authorization: `Bearer ${apiKey}`,
42
+ };
43
+ }
44
+
45
+ function getContextWindow(modelInfo: Record<string, unknown> | undefined): number | undefined {
46
+ if (!modelInfo) {
47
+ return undefined;
48
+ }
49
+ for (const [key, value] of Object.entries(modelInfo)) {
50
+ if (typeof value !== "number") {
51
+ continue;
52
+ }
53
+ if (key.endsWith(".context_length") || key.endsWith(".num_ctx") || key.endsWith(".context_window")) {
54
+ return value;
55
+ }
56
+ }
57
+ }
58
+
59
+ function getThinkingConfig(capabilities: string[] | undefined): ThinkingConfig | undefined {
60
+ if (!capabilities?.includes("thinking")) {
61
+ return undefined;
62
+ }
63
+ return { mode: "effort", efforts: [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High] };
64
+ }
65
+ async function fetchShowMetadata(
66
+ baseUrl: string,
67
+ apiKey: string,
68
+ model: string,
69
+ fetchImpl: FetchImpl = fetch,
70
+ ): Promise<OllamaShowResponse | undefined> {
71
+ const response = await fetchImpl(`${baseUrl}/api/show`, {
72
+ method: "POST",
73
+ headers: {
74
+ ...createCloudHeaders(apiKey),
75
+ "Content-Type": "application/json",
76
+ },
77
+ body: JSON.stringify({ model }),
78
+ });
79
+ if (!response.ok) {
80
+ return undefined;
81
+ }
82
+ return (await response.json()) as OllamaShowResponse;
83
+ }
84
+
85
+ export function ollamaCloudModelManagerOptions(
86
+ config?: OllamaCloudModelManagerConfig,
87
+ ): ModelManagerOptions<"ollama-chat"> {
88
+ const apiKey = config?.apiKey;
89
+ const baseUrl = normalizeOllamaCloudBaseUrl(config?.baseUrl);
90
+ const providerReferences = createBundledReferenceMap<"ollama-chat">("ollama-cloud");
91
+ const resolveReference = createReferenceResolver(providerReferences);
92
+ return {
93
+ providerId: "ollama-cloud",
94
+ fetchDynamicModels: async () => {
95
+ if (!apiKey) {
96
+ return [];
97
+ }
98
+ const response = await fetchWithRetry(`${baseUrl}/api/tags`, {
99
+ method: "GET",
100
+ headers: createCloudHeaders(apiKey),
101
+ fetch: config?.fetch,
102
+ defaultDelayMs: OLLAMA_RETRY_DELAYS_MS,
103
+ });
104
+ if (!response.ok) {
105
+ throw new Error(`HTTP ${response.status} from ${baseUrl}/api/tags`);
106
+ }
107
+ const payload = (await response.json()) as { models?: OllamaTagEntry[] };
108
+ const entries = payload.models ?? [];
109
+ const models = await Promise.all(
110
+ entries.map(async entry => {
111
+ const id = entry.model ?? entry.name;
112
+ if (!id) {
113
+ return undefined;
114
+ }
115
+ const providerReference = providerReferences.get(id);
116
+ const reference = resolveReference(id);
117
+ let metadata: OllamaShowResponse | undefined;
118
+ try {
119
+ metadata = await fetchShowMetadata(baseUrl, apiKey, id, config?.fetch);
120
+ } catch {
121
+ metadata = undefined;
122
+ }
123
+ const capabilities = metadata?.capabilities;
124
+ const contextWindow =
125
+ getContextWindow(metadata?.model_info) ?? providerReference?.contextWindow ?? 128000;
126
+ const reasoning = capabilities ? capabilities.includes("thinking") : (reference?.reasoning ?? false);
127
+ const thinking = capabilities ? getThinkingConfig(capabilities) : reference?.thinking;
128
+ const input = capabilities
129
+ ? capabilities.includes("vision")
130
+ ? (["text", "image"] as Array<"text" | "image">)
131
+ : (["text"] as Array<"text">)
132
+ : ((reference?.input as Array<"text" | "image"> | undefined) ?? (["text"] as Array<"text">));
133
+ const resolvedName = entry.name && entry.name !== id ? entry.name : (reference?.name ?? id);
134
+ return {
135
+ id,
136
+ name: resolvedName,
137
+ api: "ollama-chat" as const,
138
+ provider: "ollama-cloud" as const,
139
+ baseUrl,
140
+ reasoning,
141
+ thinking,
142
+ input,
143
+ cost: reference?.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
144
+ contextWindow,
145
+ maxTokens: providerReference?.maxTokens ?? Math.min(contextWindow, 8192),
146
+ };
147
+ }),
148
+ );
149
+ return models
150
+ .filter((model): model is NonNullable<(typeof models)[number]> => model !== undefined)
151
+ .sort((left, right) => left.id.localeCompare(right.id));
152
+ },
153
+ };
154
+ }