@strav/brain 1.0.0-alpha.22 → 1.0.0-alpha.24
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 +3 -3
- package/src/agent_runner.ts +1 -1
- package/src/{provider.ts → brain_driver.ts} +11 -10
- package/src/brain_error.ts +86 -10
- package/src/brain_manager.ts +30 -7
- package/src/brain_provider.ts +16 -16
- package/src/drivers/anthropic/anthropic_brain_driver.ts +641 -0
- package/src/drivers/anthropic/anthropic_helpers.ts +65 -0
- package/src/drivers/anthropic/anthropic_message_builder.ts +258 -0
- package/src/drivers/anthropic/anthropic_response_mapper.ts +123 -0
- package/src/drivers/anthropic/anthropic_tool_loop.ts +246 -0
- package/src/drivers/anthropic/index.ts +1 -0
- package/src/{providers/deepseek_provider.ts → drivers/deepseek/deepseek_brain_driver.ts} +10 -10
- package/src/drivers/deepseek/index.ts +1 -0
- package/src/{providers/gemini_provider.ts → drivers/gemini/gemini_brain_driver.ts} +21 -21
- package/src/drivers/gemini/index.ts +1 -0
- package/src/drivers/ollama/index.ts +1 -0
- package/src/{providers/ollama_provider.ts → drivers/ollama/ollama_brain_driver.ts} +5 -5
- package/src/drivers/openai/index.ts +1 -0
- package/src/{providers/openai_provider.ts → drivers/openai/openai_brain_driver.ts} +152 -591
- package/src/drivers/openai/openai_helpers.ts +58 -0
- package/src/drivers/openai/openai_message_builder.ts +187 -0
- package/src/drivers/openai/openai_response_mapper.ts +70 -0
- package/src/drivers/openai/openai_tool_dispatch.ts +127 -0
- package/src/drivers/openai/openai_tool_loop.ts +191 -0
- package/src/drivers/openai_compat/index.ts +1 -0
- package/src/{providers/openai_compat_provider.ts → drivers/openai_compat/openai_compat_brain_driver.ts} +16 -16
- package/src/drivers/openai_responses/index.ts +1 -0
- package/src/{providers/openai_responses_provider.ts → drivers/openai_responses/openai_responses_brain_driver.ts} +24 -24
- package/src/index.ts +18 -12
- package/src/mcp/pool.ts +1 -1
- package/src/persistence/brain_message.ts +1 -1
- package/src/persistence/brain_message_repository.ts +3 -11
- package/src/persistence/brain_suspended_run.ts +1 -1
- package/src/persistence/brain_suspended_run_repository.ts +2 -11
- package/src/persistence/brain_thread.ts +1 -1
- package/src/persistence/brain_thread_repository.ts +2 -11
- package/src/persistence/index.ts +1 -1
- package/src/tool_runner.ts +1 -1
- package/src/types.ts +2 -2
- package/src/providers/anthropic_provider.ts +0 -1194
- /package/src/persistence/{schema → schemas}/brain_message_schema.ts +0 -0
- /package/src/persistence/{schema → schemas}/brain_suspended_run_schema.ts +0 -0
- /package/src/persistence/{schema → schemas}/brain_thread_schema.ts +0 -0
- /package/src/persistence/{schema → schemas}/index.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `GeminiBrainDriver` — implementation of `Provider` backed by the
|
|
3
3
|
* official `@google/genai` SDK (Gemini Developer API / Vertex AI).
|
|
4
4
|
*
|
|
5
5
|
* Maps framework shapes to Gemini's wire format:
|
|
@@ -56,12 +56,12 @@ import type {
|
|
|
56
56
|
GenerateContentResponse,
|
|
57
57
|
Part,
|
|
58
58
|
} from '@google/genai'
|
|
59
|
-
import type { AgentResult } from '
|
|
60
|
-
import { BrainError } from '
|
|
61
|
-
import type { GeminiProviderConfig } from '
|
|
62
|
-
import type { MCPServer } from '
|
|
63
|
-
import type { AgentGenerateResult } from '
|
|
64
|
-
import type { AgentStreamEvent } from '
|
|
59
|
+
import type { AgentResult } from '../../agent_result.ts'
|
|
60
|
+
import { BrainError } from '../../brain_error.ts'
|
|
61
|
+
import type { GeminiProviderConfig } from '../../brain_config.ts'
|
|
62
|
+
import type { MCPServer } from '../../mcp_server.ts'
|
|
63
|
+
import type { AgentGenerateResult } from '../../agent_generate_result.ts'
|
|
64
|
+
import type { AgentStreamEvent } from '../../agent_stream_event.ts'
|
|
65
65
|
import type {
|
|
66
66
|
AudioSource,
|
|
67
67
|
EmbedOptions,
|
|
@@ -69,17 +69,17 @@ import type {
|
|
|
69
69
|
ServerTool,
|
|
70
70
|
TranscribeOptions,
|
|
71
71
|
TranscribeResult,
|
|
72
|
-
} from '
|
|
73
|
-
import { resolveMcpTools, type ResolveMcpToolsOptions } from '
|
|
74
|
-
import { parseGenerated, type OutputSchema } from '
|
|
75
|
-
import { runToolWithRecovery } from '
|
|
72
|
+
} from '../../types.ts'
|
|
73
|
+
import { resolveMcpTools, type ResolveMcpToolsOptions } from '../../mcp/resolve_mcp_tools.ts'
|
|
74
|
+
import { parseGenerated, type OutputSchema } from '../../output_schema.ts'
|
|
75
|
+
import { runToolWithRecovery } from '../../tool_runner.ts'
|
|
76
76
|
import type {
|
|
77
|
-
|
|
77
|
+
BrainDriver,
|
|
78
78
|
RunWithToolsOptions,
|
|
79
79
|
RunWithToolsOptionsWithSuspend,
|
|
80
|
-
} from '
|
|
81
|
-
import type { SuspendedRun } from '
|
|
82
|
-
import type { Tool } from '
|
|
80
|
+
} from '../../brain_driver.ts'
|
|
81
|
+
import type { SuspendedRun } from '../../suspended_run.ts'
|
|
82
|
+
import type { Tool } from '../../tool.ts'
|
|
83
83
|
import type {
|
|
84
84
|
ChatOptions,
|
|
85
85
|
ChatResult,
|
|
@@ -92,7 +92,7 @@ import type {
|
|
|
92
92
|
TextBlock,
|
|
93
93
|
ToolResultBlock,
|
|
94
94
|
ToolUseBlock,
|
|
95
|
-
} from '
|
|
95
|
+
} from '../../types.ts'
|
|
96
96
|
|
|
97
97
|
const DEFAULT_GEMINI_MODEL = 'gemini-2.5-flash'
|
|
98
98
|
const DEFAULT_GEMINI_EMBED_MODEL = 'text-embedding-004'
|
|
@@ -128,7 +128,7 @@ export interface GeminiProviderOptions {
|
|
|
128
128
|
mcpPool?: ResolveMcpToolsOptions['pool']
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
export class
|
|
131
|
+
export class GeminiBrainDriver implements BrainDriver {
|
|
132
132
|
readonly name: string
|
|
133
133
|
private readonly models: GeminiModelsClient
|
|
134
134
|
private readonly defaultModel: string
|
|
@@ -264,7 +264,7 @@ export class GeminiProvider implements Provider {
|
|
|
264
264
|
if (options.signal !== undefined) config.abortSignal = options.signal
|
|
265
265
|
if (!this.models.embedContent) {
|
|
266
266
|
throw new BrainError(
|
|
267
|
-
`
|
|
267
|
+
`GeminiBrainDriver.embed: underlying SDK does not implement embedContent. This usually means a test stub omitted it.`,
|
|
268
268
|
{ context: { provider: this.name } },
|
|
269
269
|
)
|
|
270
270
|
}
|
|
@@ -349,7 +349,7 @@ export class GeminiProvider implements Provider {
|
|
|
349
349
|
|
|
350
350
|
const candidate = response.candidates?.[0]
|
|
351
351
|
if (!candidate) {
|
|
352
|
-
throw new BrainError('
|
|
352
|
+
throw new BrainError('GeminiBrainDriver: response had no candidates.')
|
|
353
353
|
}
|
|
354
354
|
const parts = candidate.content?.parts ?? []
|
|
355
355
|
const assistantContent = fromGeminiParts(parts)
|
|
@@ -453,7 +453,7 @@ export class GeminiProvider implements Provider {
|
|
|
453
453
|
|
|
454
454
|
const candidate = response.candidates?.[0]
|
|
455
455
|
if (!candidate) {
|
|
456
|
-
throw new BrainError('
|
|
456
|
+
throw new BrainError('GeminiBrainDriver: response had no candidates.')
|
|
457
457
|
}
|
|
458
458
|
const parts = candidate.content?.parts ?? []
|
|
459
459
|
const assistantContent = fromGeminiParts(parts)
|
|
@@ -953,7 +953,7 @@ function geminiServerTools(
|
|
|
953
953
|
out.push({ urlContext: {} })
|
|
954
954
|
} else if (t.type === 'web_fetch') {
|
|
955
955
|
throw new BrainError(
|
|
956
|
-
'
|
|
956
|
+
'GeminiBrainDriver: server tool `web_fetch` is Anthropic-only. Use `url_context` for Gemini or route the call to Anthropic.',
|
|
957
957
|
{ context: { provider: 'google' } },
|
|
958
958
|
)
|
|
959
959
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GeminiBrainDriver } from './gemini_brain_driver.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OllamaBrainDriver } from './ollama_brain_driver.ts'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `OllamaBrainDriver` — `OpenAICompatBrainDriver` pointed at a local
|
|
3
3
|
* Ollama server's OpenAI-compatible `/v1` endpoint.
|
|
4
4
|
*
|
|
5
5
|
* Why this matters: Ollama (and the wider local-LLM ecosystem —
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
import type OpenAI from 'openai'
|
|
43
|
-
import type { OllamaProviderConfig } from '
|
|
44
|
-
import type { ResolveMcpToolsOptions } from '
|
|
45
|
-
import {
|
|
43
|
+
import type { OllamaProviderConfig } from '../../brain_config.ts'
|
|
44
|
+
import type { ResolveMcpToolsOptions } from '../../mcp/resolve_mcp_tools.ts'
|
|
45
|
+
import { OpenAICompatBrainDriver } from '../openai_compat/openai_compat_brain_driver.ts'
|
|
46
46
|
|
|
47
47
|
const DEFAULT_OLLAMA_BASE_URL = 'http://localhost:11434/v1'
|
|
48
48
|
const DEFAULT_OLLAMA_API_KEY = 'ollama'
|
|
@@ -57,7 +57,7 @@ export interface OllamaProviderOptions {
|
|
|
57
57
|
mcpClientFactory?: ResolveMcpToolsOptions['clientFactory']
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export class
|
|
60
|
+
export class OllamaBrainDriver extends OpenAICompatBrainDriver {
|
|
61
61
|
constructor(
|
|
62
62
|
name: string,
|
|
63
63
|
config: OllamaProviderConfig,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OpenAIBrainDriver } from './openai_brain_driver.ts'
|