@ottocode/sdk 0.1.173
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/README.md +338 -0
- package/package.json +128 -0
- package/src/agent/types.ts +19 -0
- package/src/auth/src/copilot-oauth.ts +190 -0
- package/src/auth/src/index.ts +100 -0
- package/src/auth/src/oauth.ts +234 -0
- package/src/auth/src/openai-oauth.ts +394 -0
- package/src/auth/src/wallet.ts +51 -0
- package/src/browser.ts +32 -0
- package/src/config/src/index.ts +110 -0
- package/src/config/src/manager.ts +181 -0
- package/src/config/src/paths.ts +98 -0
- package/src/core/src/errors.ts +102 -0
- package/src/core/src/index.ts +108 -0
- package/src/core/src/providers/resolver.ts +244 -0
- package/src/core/src/streaming/artifacts.ts +41 -0
- package/src/core/src/terminals/bun-pty.ts +13 -0
- package/src/core/src/terminals/circular-buffer.ts +30 -0
- package/src/core/src/terminals/ensure-bun-pty.ts +70 -0
- package/src/core/src/terminals/index.ts +8 -0
- package/src/core/src/terminals/manager.ts +158 -0
- package/src/core/src/terminals/rust-libs.ts +30 -0
- package/src/core/src/terminals/terminal.ts +132 -0
- package/src/core/src/tools/bin-manager.ts +250 -0
- package/src/core/src/tools/builtin/bash.ts +155 -0
- package/src/core/src/tools/builtin/bash.txt +7 -0
- package/src/core/src/tools/builtin/file-cache.ts +39 -0
- package/src/core/src/tools/builtin/finish.ts +12 -0
- package/src/core/src/tools/builtin/finish.txt +10 -0
- package/src/core/src/tools/builtin/fs/cd.ts +19 -0
- package/src/core/src/tools/builtin/fs/cd.txt +5 -0
- package/src/core/src/tools/builtin/fs/index.ts +20 -0
- package/src/core/src/tools/builtin/fs/ls.ts +72 -0
- package/src/core/src/tools/builtin/fs/ls.txt +8 -0
- package/src/core/src/tools/builtin/fs/pwd.ts +17 -0
- package/src/core/src/tools/builtin/fs/pwd.txt +5 -0
- package/src/core/src/tools/builtin/fs/read.ts +119 -0
- package/src/core/src/tools/builtin/fs/read.txt +8 -0
- package/src/core/src/tools/builtin/fs/tree.ts +149 -0
- package/src/core/src/tools/builtin/fs/tree.txt +11 -0
- package/src/core/src/tools/builtin/fs/util.ts +95 -0
- package/src/core/src/tools/builtin/fs/write.ts +106 -0
- package/src/core/src/tools/builtin/fs/write.txt +11 -0
- package/src/core/src/tools/builtin/git.commit.txt +6 -0
- package/src/core/src/tools/builtin/git.diff.txt +5 -0
- package/src/core/src/tools/builtin/git.status.txt +5 -0
- package/src/core/src/tools/builtin/git.ts +151 -0
- package/src/core/src/tools/builtin/glob.ts +128 -0
- package/src/core/src/tools/builtin/glob.txt +10 -0
- package/src/core/src/tools/builtin/grep.ts +136 -0
- package/src/core/src/tools/builtin/grep.txt +9 -0
- package/src/core/src/tools/builtin/ignore.ts +45 -0
- package/src/core/src/tools/builtin/patch/apply.ts +546 -0
- package/src/core/src/tools/builtin/patch/constants.ts +5 -0
- package/src/core/src/tools/builtin/patch/normalize.ts +31 -0
- package/src/core/src/tools/builtin/patch/parse-enveloped.ts +209 -0
- package/src/core/src/tools/builtin/patch/parse-unified.ts +231 -0
- package/src/core/src/tools/builtin/patch/parse.ts +28 -0
- package/src/core/src/tools/builtin/patch/text.ts +23 -0
- package/src/core/src/tools/builtin/patch/types.ts +82 -0
- package/src/core/src/tools/builtin/patch.ts +167 -0
- package/src/core/src/tools/builtin/patch.txt +207 -0
- package/src/core/src/tools/builtin/progress.ts +55 -0
- package/src/core/src/tools/builtin/progress.txt +7 -0
- package/src/core/src/tools/builtin/ripgrep.ts +125 -0
- package/src/core/src/tools/builtin/ripgrep.txt +7 -0
- package/src/core/src/tools/builtin/terminal.ts +300 -0
- package/src/core/src/tools/builtin/terminal.txt +93 -0
- package/src/core/src/tools/builtin/todos.ts +66 -0
- package/src/core/src/tools/builtin/todos.txt +7 -0
- package/src/core/src/tools/builtin/websearch.ts +250 -0
- package/src/core/src/tools/builtin/websearch.txt +12 -0
- package/src/core/src/tools/error.ts +67 -0
- package/src/core/src/tools/loader.ts +421 -0
- package/src/core/src/types/index.ts +11 -0
- package/src/core/src/types/types.ts +4 -0
- package/src/core/src/utils/ansi.ts +27 -0
- package/src/core/src/utils/debug.ts +40 -0
- package/src/core/src/utils/logger.ts +150 -0
- package/src/index.ts +313 -0
- package/src/prompts/src/agents/build.txt +89 -0
- package/src/prompts/src/agents/general.txt +15 -0
- package/src/prompts/src/agents/plan.txt +10 -0
- package/src/prompts/src/agents/research.txt +50 -0
- package/src/prompts/src/base.txt +24 -0
- package/src/prompts/src/debug.ts +104 -0
- package/src/prompts/src/index.ts +1 -0
- package/src/prompts/src/modes/oneshot.txt +9 -0
- package/src/prompts/src/providers/anthropic.txt +247 -0
- package/src/prompts/src/providers/anthropicSpoof.txt +1 -0
- package/src/prompts/src/providers/default.txt +466 -0
- package/src/prompts/src/providers/google.txt +230 -0
- package/src/prompts/src/providers/moonshot.txt +24 -0
- package/src/prompts/src/providers/openai.txt +414 -0
- package/src/prompts/src/providers.ts +143 -0
- package/src/providers/src/anthropic-caching.ts +202 -0
- package/src/providers/src/anthropic-oauth-client.ts +157 -0
- package/src/providers/src/authorization.ts +17 -0
- package/src/providers/src/catalog-manual.ts +135 -0
- package/src/providers/src/catalog-merged.ts +9 -0
- package/src/providers/src/catalog.ts +8329 -0
- package/src/providers/src/copilot-client.ts +39 -0
- package/src/providers/src/env.ts +31 -0
- package/src/providers/src/google-client.ts +16 -0
- package/src/providers/src/index.ts +75 -0
- package/src/providers/src/moonshot-client.ts +25 -0
- package/src/providers/src/oauth-models.ts +39 -0
- package/src/providers/src/openai-oauth-client.ts +108 -0
- package/src/providers/src/opencode-client.ts +64 -0
- package/src/providers/src/openrouter-client.ts +31 -0
- package/src/providers/src/pricing.ts +178 -0
- package/src/providers/src/setu-client.ts +643 -0
- package/src/providers/src/utils.ts +210 -0
- package/src/providers/src/validate.ts +39 -0
- package/src/providers/src/zai-client.ts +47 -0
- package/src/skills/index.ts +34 -0
- package/src/skills/loader.ts +152 -0
- package/src/skills/parser.ts +108 -0
- package/src/skills/tool.ts +87 -0
- package/src/skills/types.ts +41 -0
- package/src/skills/validator.ts +110 -0
- package/src/types/src/auth.ts +33 -0
- package/src/types/src/config.ts +36 -0
- package/src/types/src/index.ts +20 -0
- package/src/types/src/provider.ts +71 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { loadConfig } from './index.ts';
|
|
2
|
+
import {
|
|
3
|
+
getAllAuth,
|
|
4
|
+
setAuth as setAuthFile,
|
|
5
|
+
removeAuth as removeAuthFile,
|
|
6
|
+
type ProviderId,
|
|
7
|
+
type AuthInfo,
|
|
8
|
+
} from '../../auth/src/index.ts';
|
|
9
|
+
import {
|
|
10
|
+
getGlobalConfigDir,
|
|
11
|
+
getGlobalConfigPath,
|
|
12
|
+
getLocalDataDir,
|
|
13
|
+
joinPath,
|
|
14
|
+
} from './paths.ts';
|
|
15
|
+
import {
|
|
16
|
+
providerIds,
|
|
17
|
+
readEnvKey,
|
|
18
|
+
setEnvKey,
|
|
19
|
+
} from '../../providers/src/index.ts';
|
|
20
|
+
|
|
21
|
+
export type Scope = 'global' | 'local';
|
|
22
|
+
|
|
23
|
+
export async function read(projectRoot?: string) {
|
|
24
|
+
const cfg = await loadConfig(projectRoot);
|
|
25
|
+
const auth = await getAllAuth(projectRoot);
|
|
26
|
+
return { cfg, auth };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function isAuthorized(
|
|
30
|
+
provider: ProviderId,
|
|
31
|
+
projectRoot?: string,
|
|
32
|
+
): Promise<boolean> {
|
|
33
|
+
if (!providerIds.includes(provider)) return false;
|
|
34
|
+
if (readEnvKey(provider)) return true;
|
|
35
|
+
const { auth } = await read(projectRoot);
|
|
36
|
+
const info = auth[provider];
|
|
37
|
+
if (info?.type === 'api' && info.key) return true;
|
|
38
|
+
if (info?.type === 'oauth' && info.refresh && info.access) return true;
|
|
39
|
+
if (info?.type === 'wallet' && info.secret) return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function ensureEnv(
|
|
44
|
+
provider: ProviderId,
|
|
45
|
+
projectRoot?: string,
|
|
46
|
+
): Promise<void> {
|
|
47
|
+
if (!providerIds.includes(provider)) return;
|
|
48
|
+
if (readEnvKey(provider)) return;
|
|
49
|
+
const { auth } = await read(projectRoot);
|
|
50
|
+
const stored = auth[provider];
|
|
51
|
+
const value =
|
|
52
|
+
stored?.type === 'api'
|
|
53
|
+
? stored.key
|
|
54
|
+
: stored?.type === 'wallet'
|
|
55
|
+
? stored.secret
|
|
56
|
+
: undefined;
|
|
57
|
+
if (value) setEnvKey(provider, value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function writeDefaults(
|
|
61
|
+
scope: Scope,
|
|
62
|
+
updates: Partial<{
|
|
63
|
+
agent: string;
|
|
64
|
+
provider: ProviderId;
|
|
65
|
+
model: string;
|
|
66
|
+
toolApproval: 'auto' | 'dangerous' | 'all';
|
|
67
|
+
}>,
|
|
68
|
+
projectRoot?: string,
|
|
69
|
+
) {
|
|
70
|
+
const root = projectRoot ? String(projectRoot) : process.cwd();
|
|
71
|
+
|
|
72
|
+
if (scope === 'local') {
|
|
73
|
+
const localDir = getLocalDataDir(root);
|
|
74
|
+
const localPath = joinPath(localDir, 'config.json');
|
|
75
|
+
const existing = await readJsonFile(localPath);
|
|
76
|
+
const prevDefaults =
|
|
77
|
+
existing && typeof existing.defaults === 'object'
|
|
78
|
+
? (existing.defaults as Record<string, unknown>)
|
|
79
|
+
: {};
|
|
80
|
+
const next = {
|
|
81
|
+
...existing,
|
|
82
|
+
defaults: { ...prevDefaults, ...updates },
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const { promises: fs } = await import('node:fs');
|
|
86
|
+
await fs.mkdir(localDir, { recursive: true }).catch(() => {});
|
|
87
|
+
} catch {}
|
|
88
|
+
await Bun.write(localPath, JSON.stringify(next, null, 2));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const globalPath = getGlobalConfigPath();
|
|
93
|
+
const existing = await readJsonFile(globalPath);
|
|
94
|
+
const prevDefaults =
|
|
95
|
+
existing && typeof existing.defaults === 'object'
|
|
96
|
+
? (existing.defaults as Record<string, unknown>)
|
|
97
|
+
: {};
|
|
98
|
+
const next = {
|
|
99
|
+
...existing,
|
|
100
|
+
defaults: { ...prevDefaults, ...updates },
|
|
101
|
+
};
|
|
102
|
+
const base = getGlobalConfigDir();
|
|
103
|
+
try {
|
|
104
|
+
const { promises: fs } = await import('node:fs');
|
|
105
|
+
await fs.mkdir(base, { recursive: true }).catch(() => {});
|
|
106
|
+
} catch {}
|
|
107
|
+
await Bun.write(globalPath, JSON.stringify(next, null, 2));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function readJsonFile(
|
|
111
|
+
filePath: string,
|
|
112
|
+
): Promise<Record<string, unknown> | undefined> {
|
|
113
|
+
const f = Bun.file(filePath);
|
|
114
|
+
if (!(await f.exists())) return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const parsed = await f.json();
|
|
117
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
118
|
+
return parsed as Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function writeAuth(
|
|
127
|
+
provider: ProviderId,
|
|
128
|
+
info: AuthInfo,
|
|
129
|
+
scope: Scope = 'global',
|
|
130
|
+
projectRoot?: string,
|
|
131
|
+
) {
|
|
132
|
+
await setAuthFile(provider, info, projectRoot, scope);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function removeAuth(
|
|
136
|
+
provider: ProviderId,
|
|
137
|
+
scope: Scope = 'global',
|
|
138
|
+
projectRoot?: string,
|
|
139
|
+
) {
|
|
140
|
+
await removeAuthFile(provider, projectRoot, scope);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function getOnboardingComplete(
|
|
144
|
+
_projectRoot?: string,
|
|
145
|
+
): Promise<boolean> {
|
|
146
|
+
const globalPath = getGlobalConfigPath();
|
|
147
|
+
const f = Bun.file(globalPath);
|
|
148
|
+
if (await f.exists()) {
|
|
149
|
+
try {
|
|
150
|
+
const data = await f.json();
|
|
151
|
+
return data?.onboardingComplete === true;
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function setOnboardingComplete(
|
|
160
|
+
_projectRoot?: string,
|
|
161
|
+
): Promise<void> {
|
|
162
|
+
const globalPath = getGlobalConfigPath();
|
|
163
|
+
const base = getGlobalConfigDir();
|
|
164
|
+
|
|
165
|
+
let existing: Record<string, unknown> = {};
|
|
166
|
+
const f = Bun.file(globalPath);
|
|
167
|
+
if (await f.exists()) {
|
|
168
|
+
try {
|
|
169
|
+
existing = (await f.json()) as Record<string, unknown>;
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const next = { ...existing, onboardingComplete: true };
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const { promises: fs } = await import('node:fs');
|
|
177
|
+
await fs.mkdir(base, { recursive: true }).catch(() => {});
|
|
178
|
+
} catch {}
|
|
179
|
+
|
|
180
|
+
await Bun.write(globalPath, JSON.stringify(next, null, 2));
|
|
181
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Utilities for resolving otto config/data paths consistently
|
|
2
|
+
// Uses XDG base directory spec for global config: ~/.config/otto by default
|
|
3
|
+
|
|
4
|
+
// Minimal path join to avoid node:path; ensures forward slashes
|
|
5
|
+
function joinPath(...parts: string[]) {
|
|
6
|
+
return parts
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.map((p) => p.replace(/\\/g, '/'))
|
|
9
|
+
.join('/')
|
|
10
|
+
.replace(/\/+\/+/g, '/');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getHomeDir(): string {
|
|
14
|
+
return (process.env.HOME || process.env.USERPROFILE || '').replace(
|
|
15
|
+
/\\/g,
|
|
16
|
+
'/',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getConfigHomeDir(): string {
|
|
21
|
+
const cfgHome = process.env.XDG_CONFIG_HOME;
|
|
22
|
+
if (cfgHome?.trim()) return cfgHome.replace(/\\/g, '/');
|
|
23
|
+
return joinPath(getHomeDir(), '.config');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getGlobalConfigDir(): string {
|
|
27
|
+
return joinPath(getConfigHomeDir(), 'otto');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getGlobalConfigPath(): string {
|
|
31
|
+
return joinPath(getGlobalConfigDir(), 'config.json');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getGlobalAuthPath(): string {
|
|
35
|
+
return joinPath(getGlobalConfigDir(), 'auth.json');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Secure location for auth secrets (not in config dir or project)
|
|
39
|
+
// - Linux: $XDG_STATE_HOME/otto/auth.json or ~/.local/state/otto/auth.json
|
|
40
|
+
// - macOS: ~/Library/Application Support/otto/auth.json
|
|
41
|
+
// - Windows: %APPDATA%\otto\auth.json
|
|
42
|
+
export function getSecureAuthPath(): string {
|
|
43
|
+
const platform = process.platform;
|
|
44
|
+
if (platform === 'darwin') {
|
|
45
|
+
return joinPath(
|
|
46
|
+
getHomeDir(),
|
|
47
|
+
'Library',
|
|
48
|
+
'Application Support',
|
|
49
|
+
'otto',
|
|
50
|
+
'auth.json',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (platform === 'win32') {
|
|
54
|
+
const appData = (process.env.APPDATA || '').replace(/\\/g, '/');
|
|
55
|
+
const base = appData || joinPath(getHomeDir(), 'AppData', 'Roaming');
|
|
56
|
+
return joinPath(base, 'otto', 'auth.json');
|
|
57
|
+
}
|
|
58
|
+
const stateHome = (process.env.XDG_STATE_HOME || '').replace(/\\/g, '/');
|
|
59
|
+
const base = stateHome || joinPath(getHomeDir(), '.local', 'state');
|
|
60
|
+
return joinPath(base, 'otto', 'auth.json');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Global content under config dir
|
|
64
|
+
export function getGlobalAgentsJsonPath(): string {
|
|
65
|
+
return joinPath(getGlobalConfigDir(), 'agents.json');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getGlobalAgentsDir(): string {
|
|
69
|
+
return joinPath(getGlobalConfigDir(), 'agents');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getGlobalToolsDir(): string {
|
|
73
|
+
return joinPath(getGlobalConfigDir(), 'tools');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getGlobalCommandsDir(): string {
|
|
77
|
+
return joinPath(getGlobalConfigDir(), 'commands');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function getLocalDataDir(projectRoot: string): string {
|
|
81
|
+
return joinPath(projectRoot, '.otto');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function ensureDir(dir: string) {
|
|
85
|
+
try {
|
|
86
|
+
// Attempt to create a marker file to ensure directory exists
|
|
87
|
+
await Bun.write(joinPath(dir, '.keep'), '');
|
|
88
|
+
} catch {
|
|
89
|
+
const { promises: fs } = await import('node:fs');
|
|
90
|
+
await fs.mkdir(dir, { recursive: true }).catch(() => {});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function fileExists(p: string) {
|
|
95
|
+
return await Bun.file(p).exists();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { joinPath };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all otto errors
|
|
3
|
+
*/
|
|
4
|
+
export class OttoError extends Error {
|
|
5
|
+
constructor(
|
|
6
|
+
message: string,
|
|
7
|
+
public readonly code: string,
|
|
8
|
+
public readonly status: number = 500,
|
|
9
|
+
public readonly details?: Record<string, unknown>,
|
|
10
|
+
) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toJSON() {
|
|
17
|
+
return {
|
|
18
|
+
name: this.name,
|
|
19
|
+
message: this.message,
|
|
20
|
+
code: this.code,
|
|
21
|
+
status: this.status,
|
|
22
|
+
details: this.details,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Authentication and authorization errors
|
|
29
|
+
*/
|
|
30
|
+
export class AuthError extends OttoError {
|
|
31
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
32
|
+
super(message, 'AUTH_ERROR', 401, details);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configuration errors
|
|
38
|
+
*/
|
|
39
|
+
export class ConfigError extends OttoError {
|
|
40
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
41
|
+
super(message, 'CONFIG_ERROR', 500, details);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Tool execution errors
|
|
47
|
+
*/
|
|
48
|
+
export class ToolError extends OttoError {
|
|
49
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
50
|
+
super(message, 'TOOL_ERROR', 500, details);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Provider errors (API, model not found, etc.)
|
|
56
|
+
*/
|
|
57
|
+
export class ProviderError extends OttoError {
|
|
58
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
59
|
+
super(message, 'PROVIDER_ERROR', 500, details);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Database errors
|
|
65
|
+
*/
|
|
66
|
+
export class DatabaseError extends OttoError {
|
|
67
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
68
|
+
super(message, 'DATABASE_ERROR', 500, details);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Validation errors (bad input, schema mismatch, etc.)
|
|
74
|
+
*/
|
|
75
|
+
export class ValidationError extends OttoError {
|
|
76
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
77
|
+
super(message, 'VALIDATION_ERROR', 400, details);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Not found errors (session, agent, tool, etc.)
|
|
83
|
+
*/
|
|
84
|
+
export class NotFoundError extends OttoError {
|
|
85
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
86
|
+
super(message, 'NOT_FOUND', 404, details);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Service errors from ask-service, session-manager, etc.
|
|
92
|
+
*/
|
|
93
|
+
export class ServiceError extends OttoError {
|
|
94
|
+
constructor(
|
|
95
|
+
message: string,
|
|
96
|
+
code = 'SERVICE_ERROR',
|
|
97
|
+
status = 500,
|
|
98
|
+
details?: Record<string, unknown>,
|
|
99
|
+
) {
|
|
100
|
+
super(message, code, status, details);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// =======================
|
|
2
|
+
// Core AI Functions (from AI SDK)
|
|
3
|
+
// =======================
|
|
4
|
+
export {
|
|
5
|
+
generateText,
|
|
6
|
+
streamText,
|
|
7
|
+
generateObject,
|
|
8
|
+
streamObject,
|
|
9
|
+
tool,
|
|
10
|
+
} from 'ai';
|
|
11
|
+
export type { ModelMessage, Tool } from 'ai';
|
|
12
|
+
|
|
13
|
+
// =======================
|
|
14
|
+
// Provider & Model Resolution
|
|
15
|
+
// =======================
|
|
16
|
+
export { resolveModel } from './providers/resolver';
|
|
17
|
+
export type { ProviderName, ModelConfig } from './providers/resolver';
|
|
18
|
+
|
|
19
|
+
// Re-export provider catalog and utilities for easy access
|
|
20
|
+
export {
|
|
21
|
+
catalog,
|
|
22
|
+
providerIds,
|
|
23
|
+
isProviderId,
|
|
24
|
+
isProviderAuthorized,
|
|
25
|
+
validateProviderModel,
|
|
26
|
+
} from '../../providers/src/index.ts';
|
|
27
|
+
export type { ProviderId, ModelInfo } from '../../types/src/index.ts';
|
|
28
|
+
|
|
29
|
+
// =======================
|
|
30
|
+
// Tools
|
|
31
|
+
// =======================
|
|
32
|
+
export { discoverProjectTools } from './tools/loader';
|
|
33
|
+
export type { DiscoveredTool } from './tools/loader';
|
|
34
|
+
export { setTerminalManager, getTerminalManager } from './tools/loader';
|
|
35
|
+
|
|
36
|
+
// Tool error handling utilities
|
|
37
|
+
export {
|
|
38
|
+
isToolError,
|
|
39
|
+
extractToolError,
|
|
40
|
+
createToolError,
|
|
41
|
+
} from './tools/error';
|
|
42
|
+
export type {
|
|
43
|
+
ToolErrorType,
|
|
44
|
+
ToolErrorResponse,
|
|
45
|
+
ToolSuccessResponse,
|
|
46
|
+
ToolResponse,
|
|
47
|
+
} from './tools/error';
|
|
48
|
+
|
|
49
|
+
// Re-export builtin tools for direct access
|
|
50
|
+
export { buildFsTools } from './tools/builtin/fs/index';
|
|
51
|
+
export { buildGitTools } from './tools/builtin/git';
|
|
52
|
+
export { buildTerminalTool } from './tools/builtin/terminal';
|
|
53
|
+
|
|
54
|
+
// =======================
|
|
55
|
+
// Terminals
|
|
56
|
+
// =======================
|
|
57
|
+
export { TerminalManager } from './terminals/index';
|
|
58
|
+
export type {
|
|
59
|
+
Terminal,
|
|
60
|
+
TerminalOptions,
|
|
61
|
+
TerminalStatus,
|
|
62
|
+
TerminalCreator,
|
|
63
|
+
CreateTerminalOptions,
|
|
64
|
+
} from './terminals/index';
|
|
65
|
+
|
|
66
|
+
// =======================
|
|
67
|
+
// Streaming & Artifacts
|
|
68
|
+
// =======================
|
|
69
|
+
export {
|
|
70
|
+
createFileDiffArtifact,
|
|
71
|
+
createToolResultPayload,
|
|
72
|
+
} from './streaming/artifacts';
|
|
73
|
+
export type {
|
|
74
|
+
Artifact,
|
|
75
|
+
FileDiffArtifact,
|
|
76
|
+
FileArtifact,
|
|
77
|
+
} from './streaming/artifacts';
|
|
78
|
+
|
|
79
|
+
// =======================
|
|
80
|
+
// Types
|
|
81
|
+
// =======================
|
|
82
|
+
export type { ExecutionContext, ToolResult } from './types/index';
|
|
83
|
+
|
|
84
|
+
// =======================
|
|
85
|
+
// Schema Validation
|
|
86
|
+
// =======================
|
|
87
|
+
export { z } from 'zod';
|
|
88
|
+
|
|
89
|
+
// =======================
|
|
90
|
+
// Error Handling
|
|
91
|
+
// =======================
|
|
92
|
+
export {
|
|
93
|
+
OttoError,
|
|
94
|
+
AuthError,
|
|
95
|
+
ConfigError,
|
|
96
|
+
ToolError,
|
|
97
|
+
ProviderError,
|
|
98
|
+
DatabaseError,
|
|
99
|
+
ValidationError,
|
|
100
|
+
NotFoundError,
|
|
101
|
+
ServiceError,
|
|
102
|
+
} from './errors';
|
|
103
|
+
|
|
104
|
+
// =======================
|
|
105
|
+
// Logging & Debug
|
|
106
|
+
// =======================
|
|
107
|
+
export { logger, debug, info, warn, error, time } from './utils/logger.ts';
|
|
108
|
+
export { isDebugEnabled, isTraceEnabled } from './utils/debug.ts';
|