@soulcraft/sdk 3.5.0 → 3.6.1
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/dist/modules/ai/index.d.ts +14 -8
- package/dist/modules/ai/index.d.ts.map +1 -1
- package/dist/modules/ai/index.js +67 -14
- package/dist/modules/ai/index.js.map +1 -1
- package/dist/modules/ai/ollama.d.ts +27 -0
- package/dist/modules/ai/ollama.d.ts.map +1 -0
- package/dist/modules/ai/ollama.js +221 -0
- package/dist/modules/ai/ollama.js.map +1 -0
- package/dist/modules/ai/types.d.ts +78 -8
- package/dist/modules/ai/types.d.ts.map +1 -1
- package/dist/modules/ai/types.js +67 -6
- package/dist/modules/ai/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -35,21 +35,27 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import type { AiModule } from './types.js';
|
|
37
37
|
/**
|
|
38
|
-
* Creates an `AiModule`
|
|
38
|
+
* Creates an `AiModule` with pluggable provider support.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* By default, uses the Anthropic Claude API. Set `AI_DEFAULT_PROVIDER=local`
|
|
41
|
+
* or pass `provider: 'local'` per-call to route to Ollama instead.
|
|
42
42
|
*
|
|
43
43
|
* @returns A configured {@link AiModule} instance.
|
|
44
|
-
* @throws {Error} If `ANTHROPIC_API_KEY` is absent in production.
|
|
45
44
|
*
|
|
46
|
-
* @example
|
|
45
|
+
* @example Default (Claude)
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const ai = createAiModule()
|
|
48
|
+
* const result = await ai.complete({ messages: [...] }) // → Claude
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example Mixed providers
|
|
47
52
|
* ```typescript
|
|
48
53
|
* const ai = createAiModule()
|
|
49
|
-
* const
|
|
54
|
+
* const plan = await ai.complete({ provider: 'anthropic', model: 'opus', messages }) // → Claude
|
|
55
|
+
* const exec = await ai.complete({ provider: 'local', model: 'haiku', messages }) // → Ollama
|
|
50
56
|
* ```
|
|
51
57
|
*/
|
|
52
58
|
export declare function createAiModule(): AiModule;
|
|
53
|
-
export type { AiModule, AiCompleteOptions, AiCompleteResult, AiStreamOptions, AiStreamEvent, AiToolCall, AiMessage, AiContentBlock, AiTool, AiModel, } from './types.js';
|
|
54
|
-
export { AI_MODELS } from './types.js';
|
|
59
|
+
export type { AiModule, AiCompleteOptions, AiCompleteResult, AiStreamOptions, AiStreamEvent, AiToolCall, AiMessage, AiContentBlock, AiTool, AiModel, AiProvider, AiTier, } from './types.js';
|
|
60
|
+
export { AI_MODELS, AI_TIERS, PROVIDER_MODELS, resolveModelId } from './types.js';
|
|
55
61
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,KAAK,EACV,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,KAAK,EACV,QAAQ,EAOT,MAAM,YAAY,CAAA;AAgDnB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAqDzC;AA6MD,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,UAAU,EACV,SAAS,EACT,cAAc,EACd,MAAM,EACN,OAAO,EACP,UAAU,EACV,MAAM,GACP,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/modules/ai/index.js
CHANGED
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
import Anthropic from '@anthropic-ai/sdk';
|
|
37
|
-
import { AI_MODELS } from './types.js';
|
|
37
|
+
import { AI_MODELS, resolveModelId } from './types.js';
|
|
38
|
+
import { ollamaComplete, ollamaStream } from './ollama.js';
|
|
38
39
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
39
40
|
// Factory
|
|
40
41
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -53,31 +54,83 @@ import { AI_MODELS } from './types.js';
|
|
|
53
54
|
* const result = await ai.complete({ messages: [...], model: 'claude-sonnet-4-6' })
|
|
54
55
|
* ```
|
|
55
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* @description Resolve the Ollama base URL for a given provider type.
|
|
59
|
+
* @param provider - 'local' or 'remote'.
|
|
60
|
+
* @returns The Ollama API base URL.
|
|
61
|
+
*/
|
|
62
|
+
function _resolveOllamaUrl(provider) {
|
|
63
|
+
if (provider === 'local') {
|
|
64
|
+
return process.env['AI_LOCAL_URL'] || 'http://localhost:11434';
|
|
65
|
+
}
|
|
66
|
+
if (provider === 'remote') {
|
|
67
|
+
const url = process.env['AI_REMOTE_URL'];
|
|
68
|
+
if (!url)
|
|
69
|
+
throw new Error('AI_REMOTE_URL is required when using provider: "remote"');
|
|
70
|
+
return url;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @description Resolve which provider to use for a given call.
|
|
76
|
+
* Per-call `options.provider` overrides the `AI_DEFAULT_PROVIDER` env var.
|
|
77
|
+
*/
|
|
78
|
+
function _resolveProvider(options) {
|
|
79
|
+
return options.provider ?? process.env['AI_DEFAULT_PROVIDER'] ?? 'anthropic';
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates an `AiModule` with pluggable provider support.
|
|
83
|
+
*
|
|
84
|
+
* By default, uses the Anthropic Claude API. Set `AI_DEFAULT_PROVIDER=local`
|
|
85
|
+
* or pass `provider: 'local'` per-call to route to Ollama instead.
|
|
86
|
+
*
|
|
87
|
+
* @returns A configured {@link AiModule} instance.
|
|
88
|
+
*
|
|
89
|
+
* @example Default (Claude)
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const ai = createAiModule()
|
|
92
|
+
* const result = await ai.complete({ messages: [...] }) // → Claude
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Mixed providers
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const ai = createAiModule()
|
|
98
|
+
* const plan = await ai.complete({ provider: 'anthropic', model: 'opus', messages }) // → Claude
|
|
99
|
+
* const exec = await ai.complete({ provider: 'local', model: 'haiku', messages }) // → Ollama
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
56
102
|
export function createAiModule() {
|
|
57
103
|
const apiKey = process.env['ANTHROPIC_API_KEY'];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
104
|
+
const defaultProvider = process.env['AI_DEFAULT_PROVIDER'] ?? 'anthropic';
|
|
105
|
+
if (!apiKey && defaultProvider === 'anthropic' && process.env['NODE_ENV'] === 'production') {
|
|
106
|
+
throw new Error('ANTHROPIC_API_KEY is required when AI_DEFAULT_PROVIDER is "anthropic" in production.');
|
|
61
107
|
}
|
|
62
|
-
if (!apiKey) {
|
|
63
|
-
console.warn('[SDK/ai] ANTHROPIC_API_KEY is not set. ' +
|
|
64
|
-
'
|
|
108
|
+
if (!apiKey && defaultProvider === 'anthropic') {
|
|
109
|
+
console.warn('[SDK/ai] ANTHROPIC_API_KEY is not set. Anthropic provider will throw on use. ' +
|
|
110
|
+
'Set AI_DEFAULT_PROVIDER=local to use Ollama instead.');
|
|
65
111
|
}
|
|
66
|
-
// When the API key is absent in non-production, we defer the error to call time
|
|
67
|
-
// so the SDK can be constructed (e.g. for testing non-AI paths) without throwing.
|
|
68
112
|
const client = apiKey ? new Anthropic({ apiKey }) : null;
|
|
69
113
|
return {
|
|
70
114
|
async complete(options) {
|
|
115
|
+
const provider = _resolveProvider(options);
|
|
116
|
+
if (provider === 'local' || provider === 'remote') {
|
|
117
|
+
return ollamaComplete(_resolveOllamaUrl(provider), options);
|
|
118
|
+
}
|
|
71
119
|
if (!client) {
|
|
72
120
|
throw new Error('ANTHROPIC_API_KEY is not set. ' +
|
|
73
|
-
'
|
|
121
|
+
'Set it, or use provider: "local" / AI_DEFAULT_PROVIDER=local for Ollama.');
|
|
74
122
|
}
|
|
75
123
|
return _complete(client, options);
|
|
76
124
|
},
|
|
77
125
|
async *stream(options) {
|
|
126
|
+
const provider = _resolveProvider(options);
|
|
127
|
+
if (provider === 'local' || provider === 'remote') {
|
|
128
|
+
yield* ollamaStream(_resolveOllamaUrl(provider), options);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
78
131
|
if (!client) {
|
|
79
132
|
throw new Error('ANTHROPIC_API_KEY is not set. ' +
|
|
80
|
-
'
|
|
133
|
+
'Set it, or use provider: "local" / AI_DEFAULT_PROVIDER=local for Ollama.');
|
|
81
134
|
}
|
|
82
135
|
yield* _stream(client, options);
|
|
83
136
|
},
|
|
@@ -96,7 +149,7 @@ export function createAiModule() {
|
|
|
96
149
|
async function _complete(client, options) {
|
|
97
150
|
const { messages, systemPrompt, model, tools, maxTokens = 8192, temperature } = options;
|
|
98
151
|
const params = {
|
|
99
|
-
model: model
|
|
152
|
+
model: resolveModelId(model, 'anthropic'),
|
|
100
153
|
max_tokens: maxTokens,
|
|
101
154
|
messages: messages.map(_toAnthropicMessage),
|
|
102
155
|
...(systemPrompt ? { system: systemPrompt } : {}),
|
|
@@ -124,7 +177,7 @@ async function _complete(client, options) {
|
|
|
124
177
|
async function* _stream(client, options) {
|
|
125
178
|
const { messages, systemPrompt, model, tools, maxTokens = 8192, temperature } = options;
|
|
126
179
|
const params = {
|
|
127
|
-
model: model
|
|
180
|
+
model: resolveModelId(model, 'anthropic'),
|
|
128
181
|
max_tokens: maxTokens,
|
|
129
182
|
stream: true,
|
|
130
183
|
messages: messages.map(_toAnthropicMessage),
|
|
@@ -273,5 +326,5 @@ function _parseResponse(response) {
|
|
|
273
326
|
},
|
|
274
327
|
};
|
|
275
328
|
}
|
|
276
|
-
export { AI_MODELS } from './types.js';
|
|
329
|
+
export { AI_MODELS, AI_TIERS, PROVIDER_MODELS, resolveModelId } from './types.js';
|
|
277
330
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAUzC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;;;;;;;;;;;;GAcG;AACH;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,QAAoB;IAC7C,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,wBAAwB,CAAA;IAChE,CAAC;IACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QACxC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;QACpF,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,qBAA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B,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;QAClC,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACrC,SAAS,CAAC,IAAI,CAAC;gBACb,EAAE,EAAE,KAAK,CAAC,EAAE;gBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK,CAAC,KAAgC;aAC9C,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;QAClD,UAAU,EAAE,QAAQ,CAAC,WAAW,IAAI,UAAU;QAC9C,KAAK,EAAE;YACL,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY;YACxC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa;SAC3C;KACF,CAAA;AACH,CAAC;AAgBD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/ai/ollama
|
|
3
|
+
* @description Ollama provider for the SDK AI module. Translates Anthropic-format
|
|
4
|
+
* requests to Ollama's OpenAI-compatible API and back.
|
|
5
|
+
*
|
|
6
|
+
* Supports:
|
|
7
|
+
* - Non-streaming completion via `/api/chat`
|
|
8
|
+
* - Streaming completion via `/api/chat` with `stream: true`
|
|
9
|
+
* - Tool calling (Ollama supports OpenAI-format tools)
|
|
10
|
+
* - Automatic model tier mapping (claude-* → Ollama model names)
|
|
11
|
+
*/
|
|
12
|
+
import type { AiCompleteOptions, AiCompleteResult, AiStreamEvent } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* @description Execute a non-streaming completion against Ollama.
|
|
15
|
+
* @param baseUrl - The Ollama API base URL (e.g. 'http://localhost:11434').
|
|
16
|
+
* @param options - SDK completion options.
|
|
17
|
+
* @returns SDK-formatted completion result.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ollamaComplete(baseUrl: string, options: AiCompleteOptions): Promise<AiCompleteResult>;
|
|
20
|
+
/**
|
|
21
|
+
* @description Execute a streaming completion against Ollama.
|
|
22
|
+
* @param baseUrl - The Ollama API base URL.
|
|
23
|
+
* @param options - SDK completion options.
|
|
24
|
+
* @yields SDK-formatted stream events.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ollamaStream(baseUrl: string, options: AiCompleteOptions): AsyncIterable<AiStreamEvent>;
|
|
27
|
+
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/modules/ai/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAEd,MAAM,YAAY,CAAA;AAiEnB;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,gBAAgB,CAAC,CA6D3B;AAED;;;;;GAKG;AACH,wBAAuB,YAAY,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAAC,aAAa,CAAC,CAgG9B"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules/ai/ollama
|
|
3
|
+
* @description Ollama provider for the SDK AI module. Translates Anthropic-format
|
|
4
|
+
* requests to Ollama's OpenAI-compatible API and back.
|
|
5
|
+
*
|
|
6
|
+
* Supports:
|
|
7
|
+
* - Non-streaming completion via `/api/chat`
|
|
8
|
+
* - Streaming completion via `/api/chat` with `stream: true`
|
|
9
|
+
* - Tool calling (Ollama supports OpenAI-format tools)
|
|
10
|
+
* - Automatic model tier mapping (claude-* → Ollama model names)
|
|
11
|
+
*/
|
|
12
|
+
import { resolveModelId } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* @description Convert SDK messages to Ollama/OpenAI chat format.
|
|
15
|
+
*/
|
|
16
|
+
function toOllamaMessages(messages, systemPrompt) {
|
|
17
|
+
const result = [];
|
|
18
|
+
if (systemPrompt) {
|
|
19
|
+
result.push({ role: 'system', content: systemPrompt });
|
|
20
|
+
}
|
|
21
|
+
for (const msg of messages) {
|
|
22
|
+
if (typeof msg.content === 'string') {
|
|
23
|
+
result.push({ role: msg.role, content: msg.content });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Flatten content blocks to text + handle tool results
|
|
27
|
+
const textParts = [];
|
|
28
|
+
for (const block of msg.content) {
|
|
29
|
+
if (block.type === 'text') {
|
|
30
|
+
textParts.push(block.text);
|
|
31
|
+
}
|
|
32
|
+
else if (block.type === 'tool_result') {
|
|
33
|
+
result.push({ role: 'tool', content: block.content });
|
|
34
|
+
}
|
|
35
|
+
else if (block.type === 'tool_use') {
|
|
36
|
+
// Assistant's tool call — reconstruct as OpenAI format
|
|
37
|
+
result.push({
|
|
38
|
+
role: 'assistant',
|
|
39
|
+
content: '',
|
|
40
|
+
tool_calls: [{
|
|
41
|
+
id: block.id,
|
|
42
|
+
type: 'function',
|
|
43
|
+
function: { name: block.name, arguments: JSON.stringify(block.input) },
|
|
44
|
+
}],
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (textParts.length > 0) {
|
|
50
|
+
result.push({ role: msg.role, content: textParts.join('\n') });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description Convert SDK tool definitions to Ollama/OpenAI format.
|
|
58
|
+
*/
|
|
59
|
+
function toOllamaTools(tools) {
|
|
60
|
+
if (!tools || tools.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
return tools.map((t) => ({
|
|
63
|
+
type: 'function',
|
|
64
|
+
function: {
|
|
65
|
+
name: t.name,
|
|
66
|
+
description: t.description,
|
|
67
|
+
parameters: t.inputSchema,
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description Execute a non-streaming completion against Ollama.
|
|
73
|
+
* @param baseUrl - The Ollama API base URL (e.g. 'http://localhost:11434').
|
|
74
|
+
* @param options - SDK completion options.
|
|
75
|
+
* @returns SDK-formatted completion result.
|
|
76
|
+
*/
|
|
77
|
+
export async function ollamaComplete(baseUrl, options) {
|
|
78
|
+
const model = resolveModelId(options.model, 'ollama');
|
|
79
|
+
const messages = toOllamaMessages(options.messages, options.systemPrompt);
|
|
80
|
+
const tools = toOllamaTools(options.tools);
|
|
81
|
+
const body = {
|
|
82
|
+
model,
|
|
83
|
+
messages,
|
|
84
|
+
stream: false,
|
|
85
|
+
options: {
|
|
86
|
+
num_predict: options.maxTokens ?? 8192,
|
|
87
|
+
...(options.temperature !== undefined ? { temperature: options.temperature } : {}),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
if (tools)
|
|
91
|
+
body.tools = tools;
|
|
92
|
+
const res = await fetch(`${baseUrl}/api/chat`, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: { 'Content-Type': 'application/json' },
|
|
95
|
+
body: JSON.stringify(body),
|
|
96
|
+
});
|
|
97
|
+
if (!res.ok) {
|
|
98
|
+
const text = await res.text();
|
|
99
|
+
throw new Error(`Ollama error (${res.status}): ${text}`);
|
|
100
|
+
}
|
|
101
|
+
const data = await res.json();
|
|
102
|
+
const toolCalls = [];
|
|
103
|
+
if (data.message.tool_calls) {
|
|
104
|
+
for (const tc of data.message.tool_calls) {
|
|
105
|
+
let input = {};
|
|
106
|
+
try {
|
|
107
|
+
input = JSON.parse(tc.function.arguments);
|
|
108
|
+
}
|
|
109
|
+
catch { }
|
|
110
|
+
toolCalls.push({
|
|
111
|
+
id: `tool_${crypto.randomUUID().slice(0, 8)}`,
|
|
112
|
+
name: tc.function.name,
|
|
113
|
+
input,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
text: data.message.content || null,
|
|
119
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : null,
|
|
120
|
+
stopReason: toolCalls.length > 0 ? 'tool_use' : 'end_turn',
|
|
121
|
+
usage: {
|
|
122
|
+
inputTokens: data.prompt_eval_count ?? 0,
|
|
123
|
+
outputTokens: data.eval_count ?? 0,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @description Execute a streaming completion against Ollama.
|
|
129
|
+
* @param baseUrl - The Ollama API base URL.
|
|
130
|
+
* @param options - SDK completion options.
|
|
131
|
+
* @yields SDK-formatted stream events.
|
|
132
|
+
*/
|
|
133
|
+
export async function* ollamaStream(baseUrl, options) {
|
|
134
|
+
const model = resolveModelId(options.model, 'ollama');
|
|
135
|
+
const messages = toOllamaMessages(options.messages, options.systemPrompt);
|
|
136
|
+
const tools = toOllamaTools(options.tools);
|
|
137
|
+
const body = {
|
|
138
|
+
model,
|
|
139
|
+
messages,
|
|
140
|
+
stream: true,
|
|
141
|
+
options: {
|
|
142
|
+
num_predict: options.maxTokens ?? 8192,
|
|
143
|
+
...(options.temperature !== undefined ? { temperature: options.temperature } : {}),
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
if (tools)
|
|
147
|
+
body.tools = tools;
|
|
148
|
+
const res = await fetch(`${baseUrl}/api/chat`, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'Content-Type': 'application/json' },
|
|
151
|
+
body: JSON.stringify(body),
|
|
152
|
+
});
|
|
153
|
+
if (!res.ok) {
|
|
154
|
+
const text = await res.text();
|
|
155
|
+
throw new Error(`Ollama error (${res.status}): ${text}`);
|
|
156
|
+
}
|
|
157
|
+
const reader = res.body?.getReader();
|
|
158
|
+
if (!reader)
|
|
159
|
+
throw new Error('No response body from Ollama');
|
|
160
|
+
const decoder = new TextDecoder();
|
|
161
|
+
let buffer = '';
|
|
162
|
+
let accumulatedText = '';
|
|
163
|
+
const accumulatedToolCalls = [];
|
|
164
|
+
let totalInputTokens = 0;
|
|
165
|
+
let totalOutputTokens = 0;
|
|
166
|
+
while (true) {
|
|
167
|
+
const { done, value } = await reader.read();
|
|
168
|
+
if (done)
|
|
169
|
+
break;
|
|
170
|
+
buffer += decoder.decode(value, { stream: true });
|
|
171
|
+
const lines = buffer.split('\n');
|
|
172
|
+
buffer = lines.pop() ?? '';
|
|
173
|
+
for (const line of lines) {
|
|
174
|
+
if (!line.trim())
|
|
175
|
+
continue;
|
|
176
|
+
try {
|
|
177
|
+
const chunk = JSON.parse(line);
|
|
178
|
+
if (chunk.message?.content) {
|
|
179
|
+
accumulatedText += chunk.message.content;
|
|
180
|
+
yield { type: 'text', text: chunk.message.content };
|
|
181
|
+
}
|
|
182
|
+
if (chunk.message?.tool_calls) {
|
|
183
|
+
for (const tc of chunk.message.tool_calls) {
|
|
184
|
+
let input = {};
|
|
185
|
+
try {
|
|
186
|
+
input = JSON.parse(tc.function.arguments);
|
|
187
|
+
}
|
|
188
|
+
catch { }
|
|
189
|
+
const toolCall = {
|
|
190
|
+
id: `tool_${crypto.randomUUID().slice(0, 8)}`,
|
|
191
|
+
name: tc.function.name,
|
|
192
|
+
input,
|
|
193
|
+
};
|
|
194
|
+
accumulatedToolCalls.push(toolCall);
|
|
195
|
+
yield { type: 'tool_use', toolCall };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (chunk.done) {
|
|
199
|
+
totalInputTokens = chunk.prompt_eval_count ?? 0;
|
|
200
|
+
totalOutputTokens = chunk.eval_count ?? 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Skip malformed NDJSON lines
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
yield {
|
|
209
|
+
type: 'done',
|
|
210
|
+
result: {
|
|
211
|
+
text: accumulatedText || null,
|
|
212
|
+
toolCalls: accumulatedToolCalls.length > 0 ? accumulatedToolCalls : null,
|
|
213
|
+
stopReason: accumulatedToolCalls.length > 0 ? 'tool_use' : 'end_turn',
|
|
214
|
+
usage: {
|
|
215
|
+
inputTokens: totalInputTokens,
|
|
216
|
+
outputTokens: totalOutputTokens,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=ollama.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../../src/modules/ai/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C;;GAEG;AACH,SAAS,gBAAgB,CACvB,QAAuC,EACvC,YAAqB;IAErB,MAAM,MAAM,GAAqE,EAAE,CAAA;IAEnF,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;QACvD,CAAC;aAAM,CAAC;YACN,uDAAuD;YACvD,MAAM,SAAS,GAAa,EAAE,CAAA;YAC9B,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;gBAChC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CA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K,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;4BAC7C,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI;4BACtB,KAAK;yBACN,CAAA;wBACD,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;wBACnC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAA;oBACtC,CAAC;gBACH,CAAC;gBAED,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;oBACf,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,IAAI,CAAC,CAAA;oBAC/C,iBAAiB,GAAG,KAAK,CAAC,UAAU,IAAI,CAAC,CAAA;gBAC3C,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,8BAA8B;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM;QACJ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE;YACN,IAAI,EAAE,eAAe,IAAI,IAAI;YAC7B,SAAS,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI;YACxE,UAAU,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;YACrE,KAAK,EAAE;gBACL,WAAW,EAAE,gBAAgB;gBAC7B,YAAY,EAAE,iBAAiB;aAChC;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -16,16 +16,66 @@
|
|
|
16
16
|
* Use these constants instead of hardcoding model strings to ensure consistency
|
|
17
17
|
* across products and easier future upgrades.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* @description Abstract model tiers. Callers use these tier names — each
|
|
21
|
+
* provider maps them to its own concrete model automatically.
|
|
22
|
+
*
|
|
23
|
+
* - `fast` — speed-optimized, simple tasks, data extraction
|
|
24
|
+
* - `balanced` — general purpose, most operations (default)
|
|
25
|
+
* - `powerful` — complex reasoning, long-form synthesis, multi-step planning
|
|
26
|
+
*
|
|
27
|
+
* Raw model strings (e.g. 'claude-sonnet-4-6', 'qwen2.5:7b') are passed
|
|
28
|
+
* through to the provider unchanged for backwards compatibility.
|
|
29
|
+
*/
|
|
30
|
+
export declare const AI_TIERS: {
|
|
31
|
+
readonly fast: "fast";
|
|
32
|
+
readonly balanced: "balanced";
|
|
33
|
+
readonly powerful: "powerful";
|
|
34
|
+
};
|
|
35
|
+
export type AiTier = typeof AI_TIERS[keyof typeof AI_TIERS];
|
|
36
|
+
/**
|
|
37
|
+
* @description Concrete model IDs per provider, indexed by tier.
|
|
38
|
+
*/
|
|
39
|
+
export declare const PROVIDER_MODELS: {
|
|
40
|
+
readonly anthropic: {
|
|
41
|
+
readonly fast: "claude-haiku-4-5-20251001";
|
|
42
|
+
readonly balanced: "claude-sonnet-4-6";
|
|
43
|
+
readonly powerful: "claude-opus-4-6";
|
|
44
|
+
};
|
|
45
|
+
readonly ollama: {
|
|
46
|
+
readonly fast: "qwen2.5:7b";
|
|
47
|
+
readonly balanced: "qwen2.5:32b-instruct-q4_K_M";
|
|
48
|
+
readonly powerful: "llama3.1:70b";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* @description Legacy model constants for backwards compatibility.
|
|
53
|
+
* New code should use `AI_TIERS.fast`, `AI_TIERS.balanced`, `AI_TIERS.powerful`.
|
|
54
|
+
*/
|
|
19
55
|
export declare const AI_MODELS: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly sonnet: "claude-sonnet-4-6";
|
|
24
|
-
/** Most capable — complex reasoning, long-form synthesis, multi-step planning. */
|
|
25
|
-
readonly opus: "claude-opus-4-6";
|
|
56
|
+
haiku: "fast";
|
|
57
|
+
sonnet: "balanced";
|
|
58
|
+
opus: "powerful";
|
|
26
59
|
};
|
|
27
|
-
/**
|
|
28
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @description AI provider identifiers.
|
|
62
|
+
*
|
|
63
|
+
* - `anthropic` — Claude via Anthropic API (default)
|
|
64
|
+
* - `local` — Ollama on localhost (CPU/GPU inference)
|
|
65
|
+
* - `remote` — Ollama on a remote server (e.g. llm.bxl9000.com)
|
|
66
|
+
*/
|
|
67
|
+
export type AiProvider = 'anthropic' | 'local' | 'remote';
|
|
68
|
+
/**
|
|
69
|
+
* @description Resolve a model tier or raw model string to a concrete model ID.
|
|
70
|
+
* @param model - A tier name ('fast', 'balanced', 'powerful'), a legacy name
|
|
71
|
+
* ('haiku', 'sonnet', 'opus'), or a raw model string.
|
|
72
|
+
* @param providerType - 'anthropic' or 'ollama'.
|
|
73
|
+
* @returns The concrete model ID for the provider.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolveModelId(model: string | undefined, providerType: 'anthropic' | 'ollama'): string;
|
|
76
|
+
/** A valid model identifier — tier name ('fast', 'balanced', 'powerful'),
|
|
77
|
+
* legacy name ('haiku', 'sonnet', 'opus'), or raw model string. */
|
|
78
|
+
export type AiModel = AiTier | 'haiku' | 'sonnet' | 'opus' | string;
|
|
29
79
|
/**
|
|
30
80
|
* A single message in a Claude conversation.
|
|
31
81
|
*/
|
|
@@ -106,6 +156,26 @@ export interface AiCompleteOptions {
|
|
|
106
156
|
* @default AI_MODELS.sonnet
|
|
107
157
|
*/
|
|
108
158
|
model?: AiModel;
|
|
159
|
+
/**
|
|
160
|
+
* AI provider to use for this specific call. Overrides the default provider
|
|
161
|
+
* set via `AI_DEFAULT_PROVIDER` environment variable.
|
|
162
|
+
*
|
|
163
|
+
* - `'anthropic'` — Claude via Anthropic API (default)
|
|
164
|
+
* - `'local'` — Ollama on localhost (`AI_LOCAL_URL`, default `http://localhost:11434`)
|
|
165
|
+
* - `'remote'` — Ollama on a remote server (`AI_REMOTE_URL`)
|
|
166
|
+
*
|
|
167
|
+
* Enables mixing providers in a single workflow — e.g. Claude for planning,
|
|
168
|
+
* local models for fast execution tasks.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* // Deep reasoning with Claude
|
|
173
|
+
* const plan = await ai.complete({ provider: 'anthropic', model: 'opus', messages })
|
|
174
|
+
* // Fast execution with local LLM
|
|
175
|
+
* const result = await ai.complete({ provider: 'local', model: 'haiku', messages })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
provider?: AiProvider;
|
|
109
179
|
/**
|
|
110
180
|
* Tools available to Claude during this completion.
|
|
111
181
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/ai/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;GAKG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/ai/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;GAKG;AACH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ;;;;CAIX,CAAA;AAEV,MAAM,MAAM,MAAM,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;CAWlB,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,WAAW,GAAG,QAAQ,GACnC,MAAM,CAoBR;AAED;oEACoE;AACpE,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;AAMnE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,sCAAsC;IACtC,IAAI,EAAE,MAAM,GAAG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O,EAAE,eAAe,GAAG,aAAa,CAAC,aAAa,CAAC,CAAA;CAC/D"}
|
package/dist/modules/ai/types.js
CHANGED
|
@@ -19,12 +19,73 @@
|
|
|
19
19
|
* Use these constants instead of hardcoding model strings to ensure consistency
|
|
20
20
|
* across products and easier future upgrades.
|
|
21
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* @description Abstract model tiers. Callers use these tier names — each
|
|
24
|
+
* provider maps them to its own concrete model automatically.
|
|
25
|
+
*
|
|
26
|
+
* - `fast` — speed-optimized, simple tasks, data extraction
|
|
27
|
+
* - `balanced` — general purpose, most operations (default)
|
|
28
|
+
* - `powerful` — complex reasoning, long-form synthesis, multi-step planning
|
|
29
|
+
*
|
|
30
|
+
* Raw model strings (e.g. 'claude-sonnet-4-6', 'qwen2.5:7b') are passed
|
|
31
|
+
* through to the provider unchanged for backwards compatibility.
|
|
32
|
+
*/
|
|
33
|
+
export const AI_TIERS = {
|
|
34
|
+
fast: 'fast',
|
|
35
|
+
balanced: 'balanced',
|
|
36
|
+
powerful: 'powerful',
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @description Concrete model IDs per provider, indexed by tier.
|
|
40
|
+
*/
|
|
41
|
+
export const PROVIDER_MODELS = {
|
|
42
|
+
anthropic: {
|
|
43
|
+
fast: 'claude-haiku-4-5-20251001',
|
|
44
|
+
balanced: 'claude-sonnet-4-6',
|
|
45
|
+
powerful: 'claude-opus-4-6',
|
|
46
|
+
},
|
|
47
|
+
ollama: {
|
|
48
|
+
fast: 'qwen2.5:7b',
|
|
49
|
+
balanced: 'qwen2.5:32b-instruct-q4_K_M',
|
|
50
|
+
powerful: 'llama3.1:70b',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @description Legacy model constants for backwards compatibility.
|
|
55
|
+
* New code should use `AI_TIERS.fast`, `AI_TIERS.balanced`, `AI_TIERS.powerful`.
|
|
56
|
+
*/
|
|
22
57
|
export const AI_MODELS = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sonnet: 'claude-sonnet-4-6',
|
|
27
|
-
/** Most capable — complex reasoning, long-form synthesis, multi-step planning. */
|
|
28
|
-
opus: 'claude-opus-4-6',
|
|
58
|
+
haiku: 'fast',
|
|
59
|
+
sonnet: 'balanced',
|
|
60
|
+
opus: 'powerful',
|
|
29
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* @description Resolve a model tier or raw model string to a concrete model ID.
|
|
64
|
+
* @param model - A tier name ('fast', 'balanced', 'powerful'), a legacy name
|
|
65
|
+
* ('haiku', 'sonnet', 'opus'), or a raw model string.
|
|
66
|
+
* @param providerType - 'anthropic' or 'ollama'.
|
|
67
|
+
* @returns The concrete model ID for the provider.
|
|
68
|
+
*/
|
|
69
|
+
export function resolveModelId(model, providerType) {
|
|
70
|
+
const tier = model ?? 'balanced';
|
|
71
|
+
const models = PROVIDER_MODELS[providerType];
|
|
72
|
+
// Check tier names first
|
|
73
|
+
if (tier in models)
|
|
74
|
+
return models[tier];
|
|
75
|
+
// Legacy names (haiku/sonnet/opus → tier)
|
|
76
|
+
const legacyMap = { haiku: 'fast', sonnet: 'balanced', opus: 'powerful' };
|
|
77
|
+
if (tier in legacyMap)
|
|
78
|
+
return models[legacyMap[tier]];
|
|
79
|
+
// Legacy Claude model IDs → map to tier for Ollama
|
|
80
|
+
if (providerType === 'ollama') {
|
|
81
|
+
if (tier.includes('haiku'))
|
|
82
|
+
return models.fast;
|
|
83
|
+
if (tier.includes('sonnet'))
|
|
84
|
+
return models.balanced;
|
|
85
|
+
if (tier.includes('opus'))
|
|
86
|
+
return models.powerful;
|
|
87
|
+
}
|
|
88
|
+
// Raw model string — pass through unchanged
|
|
89
|
+
return tier;
|
|
90
|
+
}
|
|
30
91
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/ai/types.ts"],"names":[],"mappings":"AA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