@ottocode/sdk 0.1.264 → 0.1.266

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 (36) hide show
  1. package/package.json +3 -2
  2. package/src/config/src/index.ts +1 -0
  3. package/src/core/src/providers/resolver.ts +33 -64
  4. package/src/core/src/tools/bin-manager/cache.ts +13 -0
  5. package/src/core/src/tools/bin-manager/filesystem.ts +32 -0
  6. package/src/core/src/tools/bin-manager/paths.ts +36 -0
  7. package/src/core/src/tools/bin-manager/vendor.ts +80 -0
  8. package/src/core/src/tools/bin-manager.ts +14 -140
  9. package/src/core/src/tools/builtin/patch/apply-hunk.ts +308 -0
  10. package/src/core/src/tools/builtin/patch/apply-report.ts +99 -0
  11. package/src/core/src/tools/builtin/patch/apply.ts +6 -663
  12. package/src/core/src/tools/builtin/patch/hunk-header.ts +17 -0
  13. package/src/core/src/tools/builtin/patch/indentation.ts +160 -0
  14. package/src/core/src/tools/builtin/patch/matching.ts +58 -0
  15. package/src/core/src/tools/builtin/patch/parse-enveloped.ts +10 -72
  16. package/src/core/src/tools/builtin/patch/parse-unified.ts +15 -105
  17. package/src/core/src/tools/builtin/patch/replace-builder.ts +64 -0
  18. package/src/core/src/tools/builtin/patch/unified-state.ts +86 -0
  19. package/src/core/src/tools/builtin/websearch-strategies.ts +197 -0
  20. package/src/core/src/tools/builtin/websearch.ts +9 -187
  21. package/src/core/src/tools/loader.ts +6 -49
  22. package/src/core/src/tools/plugin-discovery.ts +86 -0
  23. package/src/core/src/utils/logger/format.ts +50 -0
  24. package/src/core/src/utils/logger/sinks.ts +61 -0
  25. package/src/core/src/utils/logger.ts +2 -119
  26. package/src/index.ts +4 -0
  27. package/src/providers/src/catalog.ts +1126 -220
  28. package/src/providers/src/env.ts +1 -0
  29. package/src/providers/src/index.ts +6 -0
  30. package/src/providers/src/model-resolution.ts +21 -0
  31. package/src/providers/src/pricing.ts +3 -0
  32. package/src/providers/src/registry.ts +2 -0
  33. package/src/providers/src/utils.ts +3 -0
  34. package/src/providers/src/xai-client.ts +15 -0
  35. package/src/providers/src/zai-client.ts +5 -2
  36. package/src/types/src/provider.ts +1 -0
@@ -9,6 +9,7 @@ const ENV_VARS: Record<BuiltInProviderId, string> = {
9
9
  opencode: 'OPENCODE_API_KEY',
10
10
  copilot: 'GITHUB_TOKEN',
11
11
  ottorouter: 'OTTOROUTER_PRIVATE_KEY',
12
+ xai: 'XAI_API_KEY',
12
13
  zai: 'ZAI_API_KEY',
13
14
  'zai-coding': 'ZAI_CODING_API_KEY',
14
15
  moonshot: 'MOONSHOT_API_KEY',
@@ -42,6 +42,10 @@ export {
42
42
  discoverOllamaModels,
43
43
  normalizeOllamaBaseURL,
44
44
  } from './ollama-discovery.ts';
45
+ export {
46
+ resolveOpenAIResponsesModel,
47
+ shouldUseOpenAIResponsesApi,
48
+ } from './model-resolution.ts';
45
49
  export type {
46
50
  DiscoverOllamaOptions,
47
51
  DiscoverOllamaResult,
@@ -103,6 +107,8 @@ export {
103
107
  export type { AnthropicOAuthConfig } from './anthropic-oauth-client.ts';
104
108
  export { createGoogleModel } from './google-client.ts';
105
109
  export type { GoogleProviderConfig } from './google-client.ts';
110
+ export { createXaiModel } from './xai-client.ts';
111
+ export type { XaiProviderConfig } from './xai-client.ts';
106
112
  export { createZaiModel, createZaiCodingModel } from './zai-client.ts';
107
113
  export type { ZaiProviderConfig } from './zai-client.ts';
108
114
  export {
@@ -0,0 +1,21 @@
1
+ import type { createOpenAI } from '@ai-sdk/openai';
2
+
3
+ export function shouldUseOpenAIResponsesApi(model: string): boolean {
4
+ const lower = model.toLowerCase();
5
+ return (
6
+ lower.includes('gpt-5') ||
7
+ lower.startsWith('o1') ||
8
+ lower.startsWith('o3') ||
9
+ lower.startsWith('o4') ||
10
+ lower.includes('codex-mini')
11
+ );
12
+ }
13
+
14
+ export function resolveOpenAIResponsesModel(
15
+ instance: ReturnType<typeof createOpenAI>,
16
+ model: string,
17
+ ) {
18
+ return shouldUseOpenAIResponsesApi(model)
19
+ ? instance.responses(model)
20
+ : instance(model);
21
+ }
@@ -82,6 +82,9 @@ const pricingTable: Record<ProviderName, PricingEntry[]> = {
82
82
  ottorouter: [
83
83
  // Pricing from catalog entries; leave empty here
84
84
  ],
85
+ xai: [
86
+ // Pricing from catalog entries; leave empty here
87
+ ],
85
88
  zai: [
86
89
  // Pricing from catalog entries; leave empty here
87
90
  ],
@@ -35,6 +35,7 @@ const BUILTIN_COMPATIBILITY: Record<BuiltInProviderId, ProviderCompatibility> =
35
35
  opencode: 'openai-compatible',
36
36
  copilot: 'openai',
37
37
  ottorouter: 'openrouter',
38
+ xai: 'openai',
38
39
  zai: 'openai-compatible',
39
40
  'zai-coding': 'openai-compatible',
40
41
  moonshot: 'openai-compatible',
@@ -50,6 +51,7 @@ const BUILTIN_FAMILY: Record<BuiltInProviderId, ProviderPromptFamily> = {
50
51
  opencode: 'openai-compatible',
51
52
  copilot: 'openai',
52
53
  ottorouter: 'openai-compatible',
54
+ xai: 'openai',
53
55
  zai: 'glm',
54
56
  'zai-coding': 'glm',
55
57
  moonshot: 'moonshot',
@@ -41,6 +41,7 @@ const PREFERRED_FAST_MODELS: Partial<Record<ProviderId, string[]>> = {
41
41
  openrouter: ['anthropic/claude-3.5-haiku'],
42
42
  opencode: ['claude-3-5-haiku'],
43
43
  ottorouter: ['kimi-k2.5'],
44
+ xai: ['grok-code-fast-1', 'grok-4-fast'],
44
45
  zai: ['glm-4.5-flash'],
45
46
  copilot: ['gpt-4.1-mini'],
46
47
  };
@@ -152,6 +153,7 @@ const DIRECT_PROVIDER_FAMILY: Partial<
152
153
  moonshot: 'moonshot',
153
154
  minimax: 'minimax',
154
155
  copilot: 'openai',
156
+ xai: 'openai',
155
157
  zai: 'glm',
156
158
  'zai-coding': 'glm',
157
159
  };
@@ -177,6 +179,7 @@ function inferFromModelId(model: string): UnderlyingProviderKey {
177
179
  )
178
180
  return 'openai';
179
181
  if (lower.includes('gemini') || lower.startsWith('google/')) return 'google';
182
+ if (lower.includes('grok') || lower.startsWith('xai/')) return 'openai';
180
183
  if (lower.includes('kimi') || lower.startsWith('moonshotai/'))
181
184
  return 'moonshot';
182
185
  if (
@@ -0,0 +1,15 @@
1
+ import { createXai } from '@ai-sdk/xai';
2
+ import { catalog } from './catalog-merged.ts';
3
+
4
+ export type XaiProviderConfig = {
5
+ apiKey?: string;
6
+ baseURL?: string;
7
+ };
8
+
9
+ export function createXaiModel(model: string, config?: XaiProviderConfig) {
10
+ const entry = catalog.xai;
11
+ const apiKey = config?.apiKey || process.env.XAI_API_KEY || '';
12
+ const baseURL = config?.baseURL || entry?.api;
13
+ const instance = createXai({ apiKey, baseURL });
14
+ return instance(model);
15
+ }
@@ -3,11 +3,13 @@ import { catalog } from './catalog-merged.ts';
3
3
 
4
4
  export type ZaiProviderConfig = {
5
5
  apiKey?: string;
6
+ baseURL?: string;
6
7
  };
7
8
 
8
9
  export function createZaiModel(model: string, config?: ZaiProviderConfig) {
9
10
  const entry = catalog.zai;
10
- const baseURL = entry?.api || 'https://api.z.ai/api/paas/v4';
11
+ const baseURL =
12
+ config?.baseURL || entry?.api || 'https://api.z.ai/api/paas/v4';
11
13
  const apiKey =
12
14
  config?.apiKey ||
13
15
  process.env.ZAI_API_KEY ||
@@ -29,7 +31,8 @@ export function createZaiCodingModel(
29
31
  config?: ZaiProviderConfig,
30
32
  ) {
31
33
  const entry = catalog['zai-coding'];
32
- const baseURL = entry?.api || 'https://api.z.ai/api/coding/paas/v4';
34
+ const baseURL =
35
+ config?.baseURL || entry?.api || 'https://api.z.ai/api/coding/paas/v4';
33
36
  const apiKey =
34
37
  config?.apiKey ||
35
38
  process.env.ZAI_CODING_API_KEY ||
@@ -10,6 +10,7 @@ export type BuiltInProviderId =
10
10
  | 'opencode'
11
11
  | 'copilot'
12
12
  | 'ottorouter'
13
+ | 'xai'
13
14
  | 'zai'
14
15
  | 'zai-coding'
15
16
  | 'moonshot'