@ottocode/sdk 0.1.260 → 0.1.261

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottocode/sdk",
3
- "version": "0.1.260",
3
+ "version": "0.1.261",
4
4
  "description": "AI agent SDK for building intelligent assistants - tree-shakable and comprehensive",
5
5
  "author": "nitishxyz",
6
6
  "license": "MIT",
@@ -20,9 +20,9 @@ import {
20
20
  joinPath,
21
21
  } from './paths.ts';
22
22
  import {
23
- providerIds,
24
23
  readEnvKey,
25
24
  setEnvKey,
25
+ isBuiltInProviderId,
26
26
  } from '../../providers/src/index.ts';
27
27
 
28
28
  export type Scope = 'global' | 'local';
@@ -45,7 +45,7 @@ export async function isAuthorized(
45
45
  provider: ProviderId,
46
46
  projectRoot?: string,
47
47
  ): Promise<boolean> {
48
- if (!providerIds.includes(provider)) return false;
48
+ if (!isBuiltInProviderId(provider)) return false;
49
49
  if (readEnvKey(provider)) return true;
50
50
  const { auth } = await read(projectRoot);
51
51
  const info = auth[provider];
@@ -59,7 +59,7 @@ export async function ensureEnv(
59
59
  provider: ProviderId,
60
60
  projectRoot?: string,
61
61
  ): Promise<void> {
62
- if (!providerIds.includes(provider)) return;
62
+ if (!isBuiltInProviderId(provider)) return;
63
63
  if (readEnvKey(provider)) return;
64
64
  const { auth } = await read(projectRoot);
65
65
  const stored = auth[provider];
@@ -32,6 +32,8 @@ export type { ProviderId, ModelInfo } from '../../types/src/index.ts';
32
32
  export { discoverProjectTools } from './tools/loader';
33
33
  export type { DiscoveredTool, DiscoverResult } from './tools/loader';
34
34
  export { setTerminalManager, getTerminalManager } from './tools/loader';
35
+ export { shellExecutorContext } from './tools/builtin/shell';
36
+ export type { ShellExecutor } from './tools/builtin/shell';
35
37
 
36
38
  // Tool error handling utilities
37
39
  export {
@@ -1,4 +1,5 @@
1
1
  import { tool, type Tool } from 'ai';
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
3
  import { spawn } from 'node:child_process';
3
4
  import { z } from 'zod/v3';
4
5
  import DESCRIPTION from './shell.txt' with { type: 'text' };
@@ -52,10 +53,23 @@ type ShellStreamChunk =
52
53
  channel: 'output';
53
54
  delta: string;
54
55
  }
56
+ | {
57
+ channel: 'terminal';
58
+ terminalId: string;
59
+ }
55
60
  | {
56
61
  result: ShellResult;
57
62
  };
58
63
 
64
+ export type ShellExecutorInput = ShellInput & { cwd: string };
65
+
66
+ export type ShellExecutor = (
67
+ input: ShellExecutorInput,
68
+ options?: { abortSignal?: AbortSignal },
69
+ ) => AsyncIterable<ShellStreamChunk> | ShellResult | Promise<ShellResult>;
70
+
71
+ export const shellExecutorContext = new AsyncLocalStorage<ShellExecutor>();
72
+
59
73
  const shellInputSchema = z
60
74
  .object({
61
75
  cmd: z
@@ -111,6 +125,13 @@ export function buildShellTool(projectRoot: string): {
111
125
 
112
126
  const absCwd = resolveSafePath(projectRoot, cwd || '.');
113
127
  const finalCmd = injectCoAuthorIntoGitCommit(cmd);
128
+ const shellExecutor = shellExecutorContext.getStore();
129
+ if (shellExecutor) {
130
+ return shellExecutor(
131
+ { cmd: finalCmd, cwd: absCwd, allowNonZeroExit, timeout },
132
+ options,
133
+ ) as AsyncIterable<ShellStreamChunk> | ShellResult;
134
+ }
114
135
 
115
136
  const proc = spawn(finalCmd, {
116
137
  cwd: absCwd,
package/src/index.ts CHANGED
@@ -277,6 +277,9 @@ export type { ProviderName, ModelConfig } from './core/src/index.ts';
277
277
  export { discoverProjectTools } from './core/src/index.ts';
278
278
  export type { DiscoveredTool, DiscoverResult } from './core/src/index.ts';
279
279
  export { setTerminalManager, getTerminalManager } from './core/src/index.ts';
280
+ export { shellExecutorContext } from './core/src/index.ts';
281
+ export type { ShellExecutor } from './core/src/index.ts';
282
+ export { createToolError } from './core/src/index.ts';
280
283
  export { buildFsTools } from './core/src/index.ts';
281
284
  export { buildGitTools } from './core/src/index.ts';
282
285
  export {
@@ -1,5 +1,9 @@
1
1
  import type { ModelInfo } from '../../types/src/index.ts';
2
2
 
3
+ type FetchHeaders = NonNullable<
4
+ Parameters<typeof globalThis.fetch>[1]
5
+ >['headers'];
6
+
3
7
  export type DiscoverOllamaOptions = {
4
8
  baseURL: string;
5
9
  apiKey?: string;
@@ -80,7 +84,7 @@ export async function discoverOllamaModels(
80
84
  async function discoverSingleOllamaModel(
81
85
  fetchImpl: typeof globalThis.fetch,
82
86
  baseURL: string,
83
- headers: HeadersInit | undefined,
87
+ headers: FetchHeaders | undefined,
84
88
  id: string,
85
89
  ): Promise<ModelInfo> {
86
90
  try {
@@ -143,7 +147,7 @@ function extractContextLength(
143
147
  return undefined;
144
148
  }
145
149
 
146
- function buildHeaders(apiKey?: string): HeadersInit | undefined {
150
+ function buildHeaders(apiKey?: string): FetchHeaders | undefined {
147
151
  if (!apiKey) return undefined;
148
152
  return { Authorization: `Bearer ${apiKey}` };
149
153
  }
@@ -7,6 +7,7 @@ import type {
7
7
  ModelOwner,
8
8
  } from '../../types/src/index.ts';
9
9
  import { filterModelsForAuthType } from './oauth-models.ts';
10
+ import { isBuiltInProviderId } from './registry.ts';
10
11
 
11
12
  export const providerIds = Object.keys(catalog) as BuiltInProviderId[];
12
13
 
@@ -106,12 +107,12 @@ export function getModelNpmBinding(
106
107
  provider: ProviderId,
107
108
  model: string,
108
109
  ): string | undefined {
109
- const entry = catalog[provider];
110
+ const entry = isBuiltInProviderId(provider) ? catalog[provider] : undefined;
110
111
  const modelInfo = getProviderModels(provider).find((m) => m.id === model);
111
112
  if (modelInfo?.provider?.npm) return modelInfo.provider.npm;
112
113
  if (entry?.npm) return entry.npm;
113
114
 
114
- for (const key of Object.keys(catalog) as ProviderId[]) {
115
+ for (const key of Object.keys(catalog) as BuiltInProviderId[]) {
115
116
  const e = catalog[key];
116
117
  const m = getProviderModels(key).find((x) => x.id === model);
117
118
  if (m?.provider?.npm) return m.provider.npm;
@@ -233,7 +234,7 @@ export function getModelInfo(
233
234
  provider: ProviderId,
234
235
  model: string,
235
236
  ): ModelInfo | undefined {
236
- const entry = catalog[provider];
237
+ const entry = isBuiltInProviderId(provider) ? catalog[provider] : undefined;
237
238
  if (!entry) return undefined;
238
239
  return getProviderModels(provider).find((m) => m.id === model);
239
240
  }
@@ -241,7 +242,7 @@ export function getModelInfo(
241
242
  function getProviderModels(provider: ProviderId): ModelInfo[] {
242
243
  return (
243
244
  getCachedProviderCatalogEntry(provider)?.models ??
244
- catalog[provider]?.models ??
245
+ (isBuiltInProviderId(provider) ? catalog[provider]?.models : undefined) ??
245
246
  []
246
247
  );
247
248
  }
@@ -4,6 +4,7 @@ import type { OttoConfig, ProviderId } from '../../types/src/index.ts';
4
4
  import {
5
5
  getProviderDefinition,
6
6
  hasConfiguredModel,
7
+ isBuiltInProviderId,
7
8
  providerAllowsAnyModel,
8
9
  } from './registry.ts';
9
10
 
@@ -64,12 +65,13 @@ export function validateProviderModel(
64
65
  }
65
66
 
66
67
  const p = providerId;
67
- if (!catalog[p] && !getCachedProviderCatalogEntry(p)) {
68
+ const builtInEntry = isBuiltInProviderId(p) ? catalog[p] : undefined;
69
+ if (!builtInEntry && !getCachedProviderCatalogEntry(p)) {
68
70
  throw new Error(`Provider not supported: ${providerId}`);
69
71
  }
70
72
  const models =
71
- getCachedProviderCatalogEntry(p)?.models ?? catalog[p]?.models ?? [];
72
- const entry = models.find((m) => m.id === modelId);
73
+ getCachedProviderCatalogEntry(p)?.models ?? builtInEntry?.models ?? [];
74
+ const entry = models.find((m: { id: string }) => m.id === modelId);
73
75
  if (!entry) {
74
76
  throwModelNotFound(providerId, modelId, models);
75
77
  }
@@ -21,6 +21,7 @@ export type {
21
21
  PathConfig,
22
22
  ProviderSettingsEntry,
23
23
  ProviderSettings,
24
+ SkillSettings,
24
25
  OttoConfig,
25
26
  ToolApprovalMode,
26
27
  ReasoningLevel,