@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,150 @@
|
|
|
1
|
+
import { isDebugEnabled, isTraceEnabled } from './debug.ts';
|
|
2
|
+
|
|
3
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
4
|
+
|
|
5
|
+
function safeHasMeta(
|
|
6
|
+
meta?: Record<string, unknown>,
|
|
7
|
+
): meta is Record<string, unknown> {
|
|
8
|
+
return Boolean(meta && Object.keys(meta).length);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function debug(message: string, meta?: Record<string, unknown>): void {
|
|
12
|
+
if (!isDebugEnabled()) return;
|
|
13
|
+
try {
|
|
14
|
+
if (safeHasMeta(meta)) {
|
|
15
|
+
console.log(`[debug] ${message}`, meta);
|
|
16
|
+
} else {
|
|
17
|
+
console.log(`[debug] ${message}`);
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
// ignore logging errors
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function info(message: string, meta?: Record<string, unknown>): void {
|
|
25
|
+
if (!isDebugEnabled() && !isTraceEnabled()) return;
|
|
26
|
+
try {
|
|
27
|
+
if (safeHasMeta(meta)) {
|
|
28
|
+
console.log(`[info] ${message}`, meta);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(`[info] ${message}`);
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
// ignore logging errors
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function warn(message: string, meta?: Record<string, unknown>): void {
|
|
38
|
+
try {
|
|
39
|
+
if (safeHasMeta(meta)) {
|
|
40
|
+
console.warn(`[warn] ${message}`, meta);
|
|
41
|
+
} else {
|
|
42
|
+
console.warn(`[warn] ${message}`);
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
// ignore logging errors
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function error(
|
|
50
|
+
message: string,
|
|
51
|
+
err?: unknown,
|
|
52
|
+
meta?: Record<string, unknown>,
|
|
53
|
+
): void {
|
|
54
|
+
if (!isDebugEnabled()) return;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const logMeta: Record<string, unknown> = meta ? { ...meta } : {};
|
|
58
|
+
|
|
59
|
+
if (err) {
|
|
60
|
+
if (err instanceof Error) {
|
|
61
|
+
logMeta.error = {
|
|
62
|
+
name: err.name,
|
|
63
|
+
message: err.message,
|
|
64
|
+
};
|
|
65
|
+
if (isTraceEnabled() && err.stack) {
|
|
66
|
+
(logMeta.error as { stack?: string }).stack = err.stack;
|
|
67
|
+
}
|
|
68
|
+
} else if (typeof err === 'string') {
|
|
69
|
+
logMeta.error = err;
|
|
70
|
+
} else if (typeof err === 'object') {
|
|
71
|
+
const errObj = err as Record<string, unknown>;
|
|
72
|
+
const details: Record<string, unknown> = {};
|
|
73
|
+
if (typeof errObj.name === 'string') details.name = errObj.name;
|
|
74
|
+
if (typeof errObj.message === 'string')
|
|
75
|
+
details.message = errObj.message;
|
|
76
|
+
if (typeof errObj.code === 'string') details.code = errObj.code;
|
|
77
|
+
if (typeof errObj.status === 'number') details.status = errObj.status;
|
|
78
|
+
if (typeof errObj.statusCode === 'number')
|
|
79
|
+
details.statusCode = errObj.statusCode;
|
|
80
|
+
if (
|
|
81
|
+
isTraceEnabled() &&
|
|
82
|
+
typeof errObj.stack === 'string' &&
|
|
83
|
+
!details.stack
|
|
84
|
+
) {
|
|
85
|
+
details.stack = errObj.stack;
|
|
86
|
+
}
|
|
87
|
+
logMeta.error = Object.keys(details).length ? details : errObj;
|
|
88
|
+
} else {
|
|
89
|
+
logMeta.error = String(err);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (safeHasMeta(logMeta)) {
|
|
94
|
+
console.error(`[error] ${message}`, logMeta);
|
|
95
|
+
} else {
|
|
96
|
+
console.error(`[error] ${message}`);
|
|
97
|
+
}
|
|
98
|
+
} catch (logErr) {
|
|
99
|
+
try {
|
|
100
|
+
console.error(`[error] ${message} (logging failed)`, logErr);
|
|
101
|
+
} catch {
|
|
102
|
+
// ignore
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const logger = {
|
|
108
|
+
debug,
|
|
109
|
+
info,
|
|
110
|
+
warn,
|
|
111
|
+
error,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
function nowMs(): number {
|
|
115
|
+
const perf = (globalThis as { performance?: { now?: () => number } })
|
|
116
|
+
.performance;
|
|
117
|
+
if (perf && typeof perf.now === 'function') return perf.now();
|
|
118
|
+
return Date.now();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type Timer = {
|
|
122
|
+
end(meta?: Record<string, unknown>): void;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function time(label: string): Timer {
|
|
126
|
+
if (!isDebugEnabled()) {
|
|
127
|
+
return { end() {} };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const start = nowMs();
|
|
131
|
+
let finished = false;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
end(meta?: Record<string, unknown>) {
|
|
135
|
+
if (finished) return;
|
|
136
|
+
finished = true;
|
|
137
|
+
const duration = nowMs() - start;
|
|
138
|
+
try {
|
|
139
|
+
const base = `[timing] ${label} ${duration.toFixed(1)}ms`;
|
|
140
|
+
if (safeHasMeta(meta)) {
|
|
141
|
+
console.log(base, meta);
|
|
142
|
+
} else {
|
|
143
|
+
console.log(base);
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// ignore timing log errors
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @ottocode/sdk - Tree-shakable AI Agent SDK
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// This is the SINGLE source of truth for all ottocode functionality.
|
|
5
|
+
// All exports are tree-shakable - bundlers will only include what you use.
|
|
6
|
+
//
|
|
7
|
+
// Usage:
|
|
8
|
+
// import { generateText, resolveModel } from '@ottocode/sdk';
|
|
9
|
+
// import type { ProviderId, OttoConfig } from '@ottocode/sdk';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
// =======================
|
|
13
|
+
// Types (from internal types module)
|
|
14
|
+
// =======================
|
|
15
|
+
// Provider types
|
|
16
|
+
export type {
|
|
17
|
+
ProviderId,
|
|
18
|
+
ModelInfo,
|
|
19
|
+
ModelProviderBinding,
|
|
20
|
+
ProviderCatalogEntry,
|
|
21
|
+
} from './types/src/index.ts';
|
|
22
|
+
|
|
23
|
+
// Auth types
|
|
24
|
+
export type { ApiAuth, OAuth, AuthInfo, AuthFile } from './types/src/index.ts';
|
|
25
|
+
|
|
26
|
+
// Config types
|
|
27
|
+
export type {
|
|
28
|
+
DefaultConfig,
|
|
29
|
+
PathConfig,
|
|
30
|
+
OttoConfig,
|
|
31
|
+
} from './types/src/index.ts';
|
|
32
|
+
|
|
33
|
+
// =======================
|
|
34
|
+
// Providers (from internal providers module)
|
|
35
|
+
// =======================
|
|
36
|
+
export { catalog } from './providers/src/index.ts';
|
|
37
|
+
export {
|
|
38
|
+
isProviderId,
|
|
39
|
+
providerIds,
|
|
40
|
+
defaultModelFor,
|
|
41
|
+
hasModel,
|
|
42
|
+
getFastModel,
|
|
43
|
+
getFastModelForAuth,
|
|
44
|
+
getModelNpmBinding,
|
|
45
|
+
isAnthropicBasedModel,
|
|
46
|
+
getUnderlyingProviderKey,
|
|
47
|
+
getModelFamily,
|
|
48
|
+
getModelInfo,
|
|
49
|
+
modelSupportsReasoning,
|
|
50
|
+
} from './providers/src/index.ts';
|
|
51
|
+
export type { UnderlyingProviderKey } from './providers/src/index.ts';
|
|
52
|
+
export {
|
|
53
|
+
isProviderAuthorized,
|
|
54
|
+
ensureProviderEnv,
|
|
55
|
+
} from './providers/src/index.ts';
|
|
56
|
+
export { validateProviderModel } from './providers/src/index.ts';
|
|
57
|
+
export { estimateModelCostUsd } from './providers/src/index.ts';
|
|
58
|
+
export {
|
|
59
|
+
providerEnvVar,
|
|
60
|
+
readEnvKey,
|
|
61
|
+
setEnvKey,
|
|
62
|
+
} from './providers/src/index.ts';
|
|
63
|
+
export {
|
|
64
|
+
createSetuFetch,
|
|
65
|
+
createSetuModel,
|
|
66
|
+
fetchSetuBalance,
|
|
67
|
+
getPublicKeyFromPrivate,
|
|
68
|
+
fetchSolanaUsdcBalance,
|
|
69
|
+
} from './providers/src/index.ts';
|
|
70
|
+
export type {
|
|
71
|
+
SetuAuth,
|
|
72
|
+
SetuProviderOptions,
|
|
73
|
+
SetuBalanceResponse,
|
|
74
|
+
SolanaUsdcBalanceResponse,
|
|
75
|
+
} from './providers/src/index.ts';
|
|
76
|
+
export {
|
|
77
|
+
createOpenAIOAuthFetch,
|
|
78
|
+
createOpenAIOAuthModel,
|
|
79
|
+
} from './providers/src/index.ts';
|
|
80
|
+
export type { OpenAIOAuthConfig } from './providers/src/index.ts';
|
|
81
|
+
export {
|
|
82
|
+
isModelAllowedForOAuth,
|
|
83
|
+
filterModelsForAuthType,
|
|
84
|
+
getOAuthModelPrefixes,
|
|
85
|
+
} from './providers/src/index.ts';
|
|
86
|
+
export {
|
|
87
|
+
addAnthropicCacheControl,
|
|
88
|
+
createAnthropicCachingFetch,
|
|
89
|
+
createConditionalCachingFetch,
|
|
90
|
+
} from './providers/src/index.ts';
|
|
91
|
+
export {
|
|
92
|
+
createAnthropicOAuthFetch,
|
|
93
|
+
createAnthropicOAuthModel,
|
|
94
|
+
} from './providers/src/index.ts';
|
|
95
|
+
export type { AnthropicOAuthConfig } from './providers/src/index.ts';
|
|
96
|
+
export { createGoogleModel } from './providers/src/index.ts';
|
|
97
|
+
export type { GoogleProviderConfig } from './providers/src/index.ts';
|
|
98
|
+
export { createZaiModel, createZaiCodingModel } from './providers/src/index.ts';
|
|
99
|
+
export type { ZaiProviderConfig } from './providers/src/index.ts';
|
|
100
|
+
export {
|
|
101
|
+
getOpenRouterInstance,
|
|
102
|
+
createOpenRouterModel,
|
|
103
|
+
} from './providers/src/index.ts';
|
|
104
|
+
export type { OpenRouterProviderConfig } from './providers/src/index.ts';
|
|
105
|
+
export { createOpencodeModel } from './providers/src/index.ts';
|
|
106
|
+
export type { OpencodeProviderConfig } from './providers/src/index.ts';
|
|
107
|
+
export { createMoonshotModel } from './providers/src/index.ts';
|
|
108
|
+
export type { MoonshotProviderConfig } from './providers/src/index.ts';
|
|
109
|
+
export {
|
|
110
|
+
createCopilotFetch,
|
|
111
|
+
createCopilotModel,
|
|
112
|
+
} from './providers/src/index.ts';
|
|
113
|
+
export type { CopilotOAuthConfig } from './providers/src/index.ts';
|
|
114
|
+
|
|
115
|
+
// =======================
|
|
116
|
+
// Authentication (from internal auth module)
|
|
117
|
+
// =======================
|
|
118
|
+
export {
|
|
119
|
+
getAllAuth,
|
|
120
|
+
getAuth,
|
|
121
|
+
setAuth,
|
|
122
|
+
removeAuth,
|
|
123
|
+
authorize,
|
|
124
|
+
exchange,
|
|
125
|
+
refreshToken,
|
|
126
|
+
openAuthUrl,
|
|
127
|
+
createApiKey,
|
|
128
|
+
authorizeWeb,
|
|
129
|
+
exchangeWeb,
|
|
130
|
+
} from './auth/src/index.ts';
|
|
131
|
+
export {
|
|
132
|
+
authorizeOpenAI,
|
|
133
|
+
exchangeOpenAI,
|
|
134
|
+
refreshOpenAIToken,
|
|
135
|
+
openOpenAIAuthUrl,
|
|
136
|
+
obtainOpenAIApiKey,
|
|
137
|
+
authorizeOpenAIWeb,
|
|
138
|
+
exchangeOpenAIWeb,
|
|
139
|
+
} from './auth/src/index.ts';
|
|
140
|
+
export type { OpenAIOAuthResult } from './auth/src/index.ts';
|
|
141
|
+
export {
|
|
142
|
+
generateWallet,
|
|
143
|
+
importWallet,
|
|
144
|
+
getSetuWallet,
|
|
145
|
+
ensureSetuWallet,
|
|
146
|
+
} from './auth/src/index.ts';
|
|
147
|
+
export type { WalletInfo } from './auth/src/index.ts';
|
|
148
|
+
export {
|
|
149
|
+
authorizeCopilot,
|
|
150
|
+
pollForCopilotToken,
|
|
151
|
+
pollForCopilotTokenOnce,
|
|
152
|
+
openCopilotAuthUrl,
|
|
153
|
+
} from './auth/src/index.ts';
|
|
154
|
+
export type {
|
|
155
|
+
CopilotDeviceCodeResponse,
|
|
156
|
+
CopilotPollResult,
|
|
157
|
+
} from './auth/src/index.ts';
|
|
158
|
+
|
|
159
|
+
// =======================
|
|
160
|
+
// Configuration (from internal config module)
|
|
161
|
+
// =======================
|
|
162
|
+
export { loadConfig, read as readConfig } from './config/src/index.ts';
|
|
163
|
+
export {
|
|
164
|
+
getLocalDataDir,
|
|
165
|
+
getGlobalConfigDir,
|
|
166
|
+
getGlobalConfigPath,
|
|
167
|
+
getGlobalAgentsJsonPath,
|
|
168
|
+
getGlobalAgentsDir,
|
|
169
|
+
getGlobalToolsDir,
|
|
170
|
+
getGlobalCommandsDir,
|
|
171
|
+
getSecureAuthPath,
|
|
172
|
+
getHomeDir,
|
|
173
|
+
} from './config/src/paths.ts';
|
|
174
|
+
export {
|
|
175
|
+
read,
|
|
176
|
+
isAuthorized,
|
|
177
|
+
ensureEnv,
|
|
178
|
+
writeDefaults as setConfig,
|
|
179
|
+
writeAuth,
|
|
180
|
+
removeAuth as removeConfig,
|
|
181
|
+
getOnboardingComplete,
|
|
182
|
+
setOnboardingComplete,
|
|
183
|
+
} from './config/src/manager.ts';
|
|
184
|
+
export type { Scope } from './config/src/manager.ts';
|
|
185
|
+
|
|
186
|
+
// =======================
|
|
187
|
+
// Prompts (from internal prompts module)
|
|
188
|
+
// =======================
|
|
189
|
+
export {
|
|
190
|
+
providerBasePrompt,
|
|
191
|
+
type ProviderPromptResult,
|
|
192
|
+
} from './prompts/src/providers.ts';
|
|
193
|
+
|
|
194
|
+
// =======================
|
|
195
|
+
// Core AI Functions (from internal core module)
|
|
196
|
+
// =======================
|
|
197
|
+
// AI SDK re-exports
|
|
198
|
+
export {
|
|
199
|
+
generateText,
|
|
200
|
+
streamText,
|
|
201
|
+
generateObject,
|
|
202
|
+
streamObject,
|
|
203
|
+
tool,
|
|
204
|
+
} from './core/src/index.ts';
|
|
205
|
+
export type { ModelMessage, Tool } from './core/src/index.ts';
|
|
206
|
+
// Re-export from AI SDK
|
|
207
|
+
export type { ToolCallPart } from 'ai';
|
|
208
|
+
|
|
209
|
+
// Provider & Model Resolution
|
|
210
|
+
export { resolveModel } from './core/src/index.ts';
|
|
211
|
+
export type { ProviderName, ModelConfig } from './core/src/index.ts';
|
|
212
|
+
|
|
213
|
+
// Tools
|
|
214
|
+
export { discoverProjectTools } from './core/src/index.ts';
|
|
215
|
+
export type { DiscoveredTool } from './core/src/index.ts';
|
|
216
|
+
export { setTerminalManager, getTerminalManager } from './core/src/index.ts';
|
|
217
|
+
export { buildFsTools } from './core/src/index.ts';
|
|
218
|
+
export { buildGitTools } from './core/src/index.ts';
|
|
219
|
+
|
|
220
|
+
// Terminals
|
|
221
|
+
export { TerminalManager } from './core/src/index.ts';
|
|
222
|
+
export type {
|
|
223
|
+
Terminal,
|
|
224
|
+
TerminalOptions,
|
|
225
|
+
TerminalStatus,
|
|
226
|
+
TerminalCreator,
|
|
227
|
+
CreateTerminalOptions,
|
|
228
|
+
} from './core/src/index.ts';
|
|
229
|
+
|
|
230
|
+
// Streaming & Artifacts
|
|
231
|
+
export {
|
|
232
|
+
createFileDiffArtifact,
|
|
233
|
+
createToolResultPayload,
|
|
234
|
+
} from './core/src/index.ts';
|
|
235
|
+
export type {
|
|
236
|
+
Artifact,
|
|
237
|
+
FileDiffArtifact,
|
|
238
|
+
FileArtifact,
|
|
239
|
+
} from './core/src/index.ts';
|
|
240
|
+
|
|
241
|
+
// Core Types
|
|
242
|
+
export type { ExecutionContext, ToolResult } from './core/src/index.ts';
|
|
243
|
+
|
|
244
|
+
// Error Handling
|
|
245
|
+
export {
|
|
246
|
+
OttoError,
|
|
247
|
+
AuthError,
|
|
248
|
+
ConfigError,
|
|
249
|
+
ToolError,
|
|
250
|
+
ProviderError,
|
|
251
|
+
DatabaseError,
|
|
252
|
+
ValidationError,
|
|
253
|
+
NotFoundError,
|
|
254
|
+
ServiceError,
|
|
255
|
+
} from './core/src/index.ts';
|
|
256
|
+
|
|
257
|
+
// Logging & Debug
|
|
258
|
+
export {
|
|
259
|
+
logger,
|
|
260
|
+
debug,
|
|
261
|
+
info,
|
|
262
|
+
warn,
|
|
263
|
+
error,
|
|
264
|
+
time,
|
|
265
|
+
isDebugEnabled,
|
|
266
|
+
isTraceEnabled,
|
|
267
|
+
} from './core/src/index.ts';
|
|
268
|
+
|
|
269
|
+
// Schema Validation
|
|
270
|
+
export { z } from './core/src/index.ts';
|
|
271
|
+
|
|
272
|
+
// =======================
|
|
273
|
+
// SDK-specific Agent Types
|
|
274
|
+
// =======================
|
|
275
|
+
export type { AgentConfig, AgentConfigEntry } from './agent/types.ts';
|
|
276
|
+
|
|
277
|
+
// =======================
|
|
278
|
+
// Skills (from internal skills module)
|
|
279
|
+
// =======================
|
|
280
|
+
export type {
|
|
281
|
+
SkillScope,
|
|
282
|
+
SkillMetadata,
|
|
283
|
+
SkillDefinition,
|
|
284
|
+
DiscoveredSkill,
|
|
285
|
+
SkillLoadResult,
|
|
286
|
+
SkillErrorResult,
|
|
287
|
+
SkillResult,
|
|
288
|
+
} from './skills/index.ts';
|
|
289
|
+
|
|
290
|
+
export {
|
|
291
|
+
validateMetadata as validateSkillMetadata,
|
|
292
|
+
validateSkillName,
|
|
293
|
+
SkillValidationError,
|
|
294
|
+
} from './skills/index.ts';
|
|
295
|
+
|
|
296
|
+
export { parseSkillFile, extractFrontmatter } from './skills/index.ts';
|
|
297
|
+
|
|
298
|
+
export {
|
|
299
|
+
discoverSkills,
|
|
300
|
+
loadSkill,
|
|
301
|
+
getSkillCache,
|
|
302
|
+
clearSkillCache,
|
|
303
|
+
findGitRoot,
|
|
304
|
+
listSkillsInDir,
|
|
305
|
+
} from './skills/index.ts';
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
initializeSkills,
|
|
309
|
+
getDiscoveredSkills,
|
|
310
|
+
isSkillsInitialized,
|
|
311
|
+
buildSkillTool,
|
|
312
|
+
rebuildSkillDescription,
|
|
313
|
+
} from './skills/index.ts';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
You help with coding and build tasks.
|
|
2
|
+
- Be precise and practical.
|
|
3
|
+
- Inspect with tools; write with care and small diffs.
|
|
4
|
+
- Keep tool inputs short; avoid long prose inside tool parameters.
|
|
5
|
+
- Stream your answer, then call finish.
|
|
6
|
+
|
|
7
|
+
## Terminal Tool Workflow
|
|
8
|
+
|
|
9
|
+
- List existing terminals before starting new ones to avoid duplicate dev servers or watchers.
|
|
10
|
+
- Reuse running services when possible; read their output instead of spawning another copy.
|
|
11
|
+
- When starting a terminal, give it a descriptive purpose/title (e.g. "web dev server 9100" or "bun test --watch") and prefer `terminal(...)` over `bash(...)` for long-lived tasks.
|
|
12
|
+
- Use `terminal(operation: "write", input: "\u0003")` or `terminal(operation: "interrupt")` to stop a process before resorting to `kill`.
|
|
13
|
+
- Summarize active terminals (purpose, key command, port) in your updates so collaborators know what's running.
|
|
14
|
+
|
|
15
|
+
## File Editing Best Practices
|
|
16
|
+
|
|
17
|
+
**Using the `apply_patch` Tool** (Recommended):
|
|
18
|
+
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
19
|
+
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
20
|
+
- Prefer the enveloped format (`*** Begin Patch` ...); standard unified diffs (`---/+++`) are also accepted and auto-converted when provided
|
|
21
|
+
- Only requires the specific lines you want to change
|
|
22
|
+
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
23
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
24
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
25
|
+
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
26
|
+
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
27
|
+
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
28
|
+
- Set `allowRejects: true` when you expect some hunks might be stale so the tool applies what it can and reports the skipped parts
|
|
29
|
+
- Removal lines that are already gone (or additions already present) are treated as applied automatically—no need to resend them
|
|
30
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
31
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
32
|
+
|
|
33
|
+
**Patch Format Reminder**:
|
|
34
|
+
```
|
|
35
|
+
*** Update File: path
|
|
36
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
37
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
38
|
+
-line to remove ← Remove this line
|
|
39
|
+
+line to add ← Add this line
|
|
40
|
+
more context ← More context (space prefix)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ⚠️ Why Patches Fail (Common Mistakes)
|
|
44
|
+
|
|
45
|
+
**Mistake 1: Patching from Memory** (Most Common)
|
|
46
|
+
- ❌ Creating patches based on what you remember from earlier
|
|
47
|
+
- ✅ ALWAYS read the file FIRST in this same turn, then create patch
|
|
48
|
+
|
|
49
|
+
**Mistake 2: Context Lines Don't Match File**
|
|
50
|
+
- ❌ Guessing or inventing what context lines look like
|
|
51
|
+
- ✅ Copy context lines EXACTLY character-for-character from the file you just read
|
|
52
|
+
- Context lines (space prefix) must exist in the actual file
|
|
53
|
+
|
|
54
|
+
**Mistake 3: Wrong Indentation**
|
|
55
|
+
- ❌ File uses 2 spaces; patch uses tabs or 4 spaces
|
|
56
|
+
- ✅ Match indentation exactly: if file uses spaces, patch uses spaces (same count)
|
|
57
|
+
|
|
58
|
+
**Mistake 4: Missing Markers**
|
|
59
|
+
- ❌ Forgot `*** End Patch` or malformed `*** Begin Patch`
|
|
60
|
+
- ✅ Always wrap: `*** Begin Patch` ... hunks ... `*** End Patch`
|
|
61
|
+
|
|
62
|
+
**Mistake 5: Hallucinated Code**
|
|
63
|
+
- ❌ Adding lines that "should" be there but aren't
|
|
64
|
+
- ✅ Only use lines that actually exist in the file
|
|
65
|
+
|
|
66
|
+
**Success Formula:**
|
|
67
|
+
1. Read file with `read` tool
|
|
68
|
+
2. Note exact indentation (spaces/tabs), line content
|
|
69
|
+
3. Extract 2-3 context lines before/after your change
|
|
70
|
+
4. Copy them EXACTLY into patch with space prefix
|
|
71
|
+
5. Add your `-old` and `+new` lines
|
|
72
|
+
6. Verify markers: `*** Begin Patch` and `*** End Patch`
|
|
73
|
+
|
|
74
|
+
**When Patch Fails:**
|
|
75
|
+
- Error means context didn't match or file changed
|
|
76
|
+
- Solution: Read the file AGAIN, check character-for-character
|
|
77
|
+
- If still failing repeatedly, use `write` tool to rewrite the entire file instead
|
|
78
|
+
|
|
79
|
+
**Using the `write` Tool** (Last Resort):
|
|
80
|
+
- Use for creating NEW files
|
|
81
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
82
|
+
- NEVER use for targeted edits - it rewrites the entire file
|
|
83
|
+
- Wastes output tokens and risks hallucinating unchanged parts
|
|
84
|
+
|
|
85
|
+
**Never**:
|
|
86
|
+
- Use `write` for partial file edits (use `apply_patch` instead)
|
|
87
|
+
- Make multiple separate `apply_patch` calls for the same file (use multiple hunks with @@ headers instead)
|
|
88
|
+
- Assume file content remains unchanged between operations
|
|
89
|
+
- Use `bash` with `sed`/`awk` for programmatic file editing (use `apply_patch` instead)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
You are a pragmatic, concise assistant.
|
|
2
|
+
|
|
3
|
+
## Guidelines
|
|
4
|
+
|
|
5
|
+
- Provide clear, actionable answers
|
|
6
|
+
- Prefer minimal wording and precise guidance
|
|
7
|
+
- Use tools when helpful; keep inputs short
|
|
8
|
+
- When asked *how* to do something, explain first — do not jump into action
|
|
9
|
+
- When unsure about project setup (test commands, package manager, frameworks), check first or ask the user
|
|
10
|
+
|
|
11
|
+
## Conventions
|
|
12
|
+
|
|
13
|
+
- Mimic existing code style if editing code
|
|
14
|
+
- NEVER assume a library or tool is available — verify first
|
|
15
|
+
- Follow security best practices; never expose secrets or keys
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<system-reminder>
|
|
2
|
+
PLAN MODE ACTIVE - READ-ONLY PHASE.
|
|
3
|
+
STRICTLY FORBIDDEN: Any file edits, modifications, or system changes.
|
|
4
|
+
You may ONLY observe, analyze, and plan.
|
|
5
|
+
</system-reminder>
|
|
6
|
+
|
|
7
|
+
Your job: produce an actionable, minimal plan.
|
|
8
|
+
- Use only read/inspect tools (read, ls, tree, ripgrep, git_diff).
|
|
9
|
+
- Identify concrete steps with just enough detail to execute later.
|
|
10
|
+
- No changes. No write operations. No refactors.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
You are a research assistant with access to session history and codebase search tools.
|
|
2
|
+
|
|
3
|
+
## Primary Job
|
|
4
|
+
|
|
5
|
+
Help users find information from past sessions and the codebase.
|
|
6
|
+
|
|
7
|
+
## Critical: "This Session" Means Parent Session
|
|
8
|
+
|
|
9
|
+
When the user refers to "this session", they mean the PARENT SESSION, not this research chat. **ALWAYS call `get_parent_session` FIRST** for these questions.
|
|
10
|
+
|
|
11
|
+
## Database Structure
|
|
12
|
+
|
|
13
|
+
- **sessions**: UUID, title, agent, provider, model, sessionType, parentSessionId
|
|
14
|
+
- **messages**: role, status, belongs to a session
|
|
15
|
+
- **message_parts**: text chunks, tool calls, tool results (type: text|tool_call|tool_result|image|error|reasoning)
|
|
16
|
+
|
|
17
|
+
## Available Tools
|
|
18
|
+
|
|
19
|
+
1. **get_parent_session** - USE FIRST for "this session" questions. Returns parent session's messages.
|
|
20
|
+
2. **get_session_context** - Get details about ANY session by ID.
|
|
21
|
+
3. **query_sessions** - List/search sessions by agent, type, date range.
|
|
22
|
+
4. **query_messages** - Search messages across sessions.
|
|
23
|
+
5. **search_history** - Full-text search across ALL message content.
|
|
24
|
+
6. **present_action** - Present clickable session links at the end.
|
|
25
|
+
|
|
26
|
+
## Codebase Tools
|
|
27
|
+
|
|
28
|
+
- `read`, `ripgrep`, `tree`, `ls`
|
|
29
|
+
|
|
30
|
+
## Research Strategy
|
|
31
|
+
|
|
32
|
+
**"What did we do" questions:**
|
|
33
|
+
1. Call `get_parent_session`
|
|
34
|
+
2. Summarize key activities
|
|
35
|
+
|
|
36
|
+
**"Find past work on X" questions:**
|
|
37
|
+
1. Use `search_history` with keywords
|
|
38
|
+
2. Then `get_session_context` on promising sessions
|
|
39
|
+
|
|
40
|
+
**"What tools were used" questions:**
|
|
41
|
+
1. Call `get_parent_session`
|
|
42
|
+
2. Look at `toolCalls` in response
|
|
43
|
+
|
|
44
|
+
## Response Guidelines
|
|
45
|
+
|
|
46
|
+
1. Be specific - quote actual content
|
|
47
|
+
2. Cite sources - reference session IDs and timestamps
|
|
48
|
+
3. Summarize clearly - findings may be injected into another session
|
|
49
|
+
4. Don't hallucinate - only report what you find
|
|
50
|
+
5. **Use `present_action`** at the end with links to relevant sessions
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
You are a helpful, concise assistant.
|
|
2
|
+
- CRITICAL: Emit progress updates using the `progress_update` tool at key milestones — at the start (planning), after initial repo discovery (discovering), before file edits (preparing), during edits (writing), and when validating (verifying). Prefer short messages (<= 80 chars).
|
|
3
|
+
- Do not print pseudo tool calls like `call:tool{}`; invoke tools directly.
|
|
4
|
+
- Use sensible default filenames when needed.
|
|
5
|
+
- Prefer minimal, precise outputs and actionable steps.
|
|
6
|
+
|
|
7
|
+
## Finish Tool - CRITICAL
|
|
8
|
+
|
|
9
|
+
You MUST call the `finish` tool at the end of every response to signal completion. The correct workflow is:
|
|
10
|
+
|
|
11
|
+
1. Perform all necessary work (tool calls, file edits, searches, etc.)
|
|
12
|
+
2. Stream your final text response or summary to the user explaining what you did
|
|
13
|
+
3. **Call the `finish` tool** to signal you are done
|
|
14
|
+
|
|
15
|
+
**IMPORTANT**: Do NOT call `finish` before streaming your response. Always stream your message first, then call `finish`. If you forget to call `finish`, the system will hang and not complete properly.
|
|
16
|
+
|
|
17
|
+
File Editing Best Practices:
|
|
18
|
+
- ⚠️ CRITICAL: ALWAYS read a file immediately before using apply_patch - never patch from memory
|
|
19
|
+
- Read the file in THIS turn, not from previous context or memory. Copy context lines CHARACTER-FOR-CHARACTER from the read output — never reconstruct from memory
|
|
20
|
+
- When making multiple edits to the same file, use multiple `@@` hunks in a single `apply_patch` call
|
|
21
|
+
- Never assume file content remains unchanged between separate apply_patch operations
|
|
22
|
+
- When using apply_patch, ensure the patch is based on the current file content, not stale versions
|
|
23
|
+
- If a patch fails, it means you didn't read the file first or the content doesn't match what you expected
|
|
24
|
+
- If a patch fails with "expected to find" error: you likely hallucinated the code. Read the file AGAIN and copy the exact lines
|