@strav/brain 1.0.0-alpha.21 → 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,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `OpenAICompatBrainDriver` — abstract intermediate that captures the
|
|
3
3
|
* "OpenAI-compatible local / third-party endpoint" pattern shared by
|
|
4
|
-
* `
|
|
4
|
+
* `DeepSeekBrainDriver`, `OllamaBrainDriver`, and anything else (Groq,
|
|
5
5
|
* Together, Fireworks, vLLM, llama.cpp's server, …) that exposes a
|
|
6
6
|
* `/v1/chat/completions` surface that is request-/response-shape-
|
|
7
7
|
* identical to OpenAI's.
|
|
8
8
|
*
|
|
9
|
-
* What it does, factored out of
|
|
9
|
+
* What it does, factored out of OpenAIBrainDriver:
|
|
10
10
|
*
|
|
11
11
|
* - **Strips `reasoning_effort`.** Compat endpoints typically
|
|
12
12
|
* reject unknown fields. `buildParams` removes it on every
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
import type OpenAI from 'openai'
|
|
42
|
-
import type { AgentGenerateResult } from '
|
|
43
|
-
import type { AgentStreamEvent } from '
|
|
44
|
-
import { BrainError } from '
|
|
45
|
-
import { parseGenerated, type OutputSchema } from '
|
|
46
|
-
import type { RunWithToolsOptions } from '
|
|
47
|
-
import type { Tool } from '
|
|
48
|
-
import { recoverOrThrow, runToolWithRecovery } from '
|
|
49
|
-
import { ToolExecutionError } from '
|
|
42
|
+
import type { AgentGenerateResult } from '../../agent_generate_result.ts'
|
|
43
|
+
import type { AgentStreamEvent } from '../../agent_stream_event.ts'
|
|
44
|
+
import { BrainError } from '../../brain_error.ts'
|
|
45
|
+
import { parseGenerated, type OutputSchema } from '../../output_schema.ts'
|
|
46
|
+
import type { RunWithToolsOptions } from '../../brain_driver.ts'
|
|
47
|
+
import type { Tool } from '../../tool.ts'
|
|
48
|
+
import { recoverOrThrow, runToolWithRecovery } from '../../tool_runner.ts'
|
|
49
|
+
import { ToolExecutionError } from '../../tool_execution_error.ts'
|
|
50
50
|
import type {
|
|
51
51
|
ChatOptions,
|
|
52
52
|
ChatUsage,
|
|
@@ -56,10 +56,10 @@ import type {
|
|
|
56
56
|
SystemPrompt,
|
|
57
57
|
ToolResultBlock,
|
|
58
58
|
ToolUseBlock,
|
|
59
|
-
} from '
|
|
60
|
-
import {
|
|
59
|
+
} from '../../types.ts'
|
|
60
|
+
import { OpenAIBrainDriver } from '../openai/openai_brain_driver.ts'
|
|
61
61
|
|
|
62
|
-
export abstract class
|
|
62
|
+
export abstract class OpenAICompatBrainDriver extends OpenAIBrainDriver {
|
|
63
63
|
/**
|
|
64
64
|
* Same as the OpenAI build but strips `reasoning_effort` — most
|
|
65
65
|
* compat endpoints reject unknown fields. Subclasses that target
|
|
@@ -528,7 +528,7 @@ function prepareToolForcing(
|
|
|
528
528
|
const respondName = `${RESPOND_TOOL_PREFIX}${schema.name}`
|
|
529
529
|
if (userTools.some((t) => t.name === respondName)) {
|
|
530
530
|
throw new BrainError(
|
|
531
|
-
`
|
|
531
|
+
`OpenAICompatBrainDriver.runWithToolsAndSchema: synthetic tool name "${respondName}" collides with a user-supplied tool. Rename your tool or the OutputSchema.name to avoid the clash.`,
|
|
532
532
|
{ context: { conflictingName: respondName } },
|
|
533
533
|
)
|
|
534
534
|
}
|
|
@@ -601,7 +601,7 @@ function fromOpenAIAssistant(
|
|
|
601
601
|
function addUsageHere(
|
|
602
602
|
acc: ChatUsage,
|
|
603
603
|
u: OpenAI.CompletionUsage | undefined,
|
|
604
|
-
provider:
|
|
604
|
+
provider: OpenAICompatBrainDriver,
|
|
605
605
|
): void {
|
|
606
606
|
if (!u) return
|
|
607
607
|
// Cast: `mapUsage` is protected on the abstract class; we're
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OpenAIResponsesBrainDriver } from './openai_responses_brain_driver.ts'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `OpenAIResponsesBrainDriver` — implementation of `Provider` backed
|
|
3
3
|
* by the `openai` SDK's Responses API
|
|
4
4
|
* (`client.responses.create`).
|
|
5
5
|
*
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* For everything else (plain chat, embeddings, transcription,
|
|
12
12
|
* function calling without server tools), the standard
|
|
13
|
-
* `
|
|
13
|
+
* `OpenAIBrainDriver` (driver `'openai'`) is simpler. Apps that
|
|
14
14
|
* use both register them as two separate providers and route
|
|
15
15
|
* per-call.
|
|
16
16
|
*
|
|
17
|
-
* Inherits `embed` + `transcribe` from `
|
|
17
|
+
* Inherits `embed` + `transcribe` from `OpenAIBrainDriver`
|
|
18
18
|
* (embeddings + Whisper live on different endpoints unchanged).
|
|
19
19
|
*
|
|
20
20
|
* V1 coverage:
|
|
@@ -32,27 +32,27 @@
|
|
|
32
32
|
*
|
|
33
33
|
* The Responses API's message shape (`input_items`) is different
|
|
34
34
|
* from chat completions' `messages`, so this is a separate
|
|
35
|
-
* provider class rather than a strategy inside `
|
|
35
|
+
* provider class rather than a strategy inside `OpenAIBrainDriver`.
|
|
36
36
|
* Translation lives in this file.
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
import OpenAI from 'openai'
|
|
40
|
-
import type { AgentGenerateResult } from '
|
|
41
|
-
import type { AgentResult } from '
|
|
42
|
-
import type { AgentStreamEvent } from '
|
|
43
|
-
import { BrainError } from '
|
|
44
|
-
import type { OpenAIResponsesProviderConfig } from '
|
|
45
|
-
import { resolveMcpTools, type ResolveMcpToolsOptions } from '
|
|
46
|
-
import type { MCPServer } from '
|
|
47
|
-
import { parseGenerated, type OutputSchema } from '
|
|
40
|
+
import type { AgentGenerateResult } from '../../agent_generate_result.ts'
|
|
41
|
+
import type { AgentResult } from '../../agent_result.ts'
|
|
42
|
+
import type { AgentStreamEvent } from '../../agent_stream_event.ts'
|
|
43
|
+
import { BrainError } from '../../brain_error.ts'
|
|
44
|
+
import type { OpenAIResponsesProviderConfig } from '../../brain_config.ts'
|
|
45
|
+
import { resolveMcpTools, type ResolveMcpToolsOptions } from '../../mcp/resolve_mcp_tools.ts'
|
|
46
|
+
import type { MCPServer } from '../../mcp_server.ts'
|
|
47
|
+
import { parseGenerated, type OutputSchema } from '../../output_schema.ts'
|
|
48
48
|
import type {
|
|
49
|
-
|
|
49
|
+
BrainDriver,
|
|
50
50
|
RunWithToolsOptions,
|
|
51
51
|
RunWithToolsOptionsWithSuspend,
|
|
52
|
-
} from '
|
|
53
|
-
import type { SuspendedRun } from '
|
|
54
|
-
import type { Tool } from '
|
|
55
|
-
import { runToolWithRecovery } from '
|
|
52
|
+
} from '../../brain_driver.ts'
|
|
53
|
+
import type { SuspendedRun } from '../../suspended_run.ts'
|
|
54
|
+
import type { Tool } from '../../tool.ts'
|
|
55
|
+
import { runToolWithRecovery } from '../../tool_runner.ts'
|
|
56
56
|
import type {
|
|
57
57
|
ChatOptions,
|
|
58
58
|
ChatResult,
|
|
@@ -66,8 +66,8 @@ import type {
|
|
|
66
66
|
TextBlock,
|
|
67
67
|
ToolResultBlock,
|
|
68
68
|
ToolUseBlock,
|
|
69
|
-
} from '
|
|
70
|
-
import {
|
|
69
|
+
} from '../../types.ts'
|
|
70
|
+
import { OpenAIBrainDriver } from '../openai/openai_brain_driver.ts'
|
|
71
71
|
|
|
72
72
|
const DEFAULT_OPENAI_MODEL = 'gpt-5'
|
|
73
73
|
const DEFAULT_OPENAI_MAX_TOKENS = 4096
|
|
@@ -83,13 +83,13 @@ export interface OpenAIResponsesProviderOptions {
|
|
|
83
83
|
/** Translation: framework `ServerTool` → Responses API tool entry. */
|
|
84
84
|
type ResponsesTool = Record<string, unknown>
|
|
85
85
|
|
|
86
|
-
export class
|
|
86
|
+
export class OpenAIResponsesBrainDriver extends OpenAIBrainDriver implements BrainDriver {
|
|
87
87
|
constructor(
|
|
88
88
|
name: string,
|
|
89
89
|
config: OpenAIResponsesProviderConfig,
|
|
90
90
|
options: OpenAIResponsesProviderOptions = {},
|
|
91
91
|
) {
|
|
92
|
-
// Reuse
|
|
92
|
+
// Reuse OpenAIBrainDriver's constructor for the SDK client + the
|
|
93
93
|
// chat / embed / transcribe model defaults. Inheritance keeps
|
|
94
94
|
// `client`, `defaultEmbedModel`, `defaultTranscribeModel`
|
|
95
95
|
// working unchanged.
|
|
@@ -951,12 +951,12 @@ function responsesServerTools(serverTools: readonly ServerTool[]): ResponsesTool
|
|
|
951
951
|
out.push({ type: 'code_interpreter', container: { type: 'auto' } })
|
|
952
952
|
} else if (t.type === 'web_fetch') {
|
|
953
953
|
throw new BrainError(
|
|
954
|
-
'
|
|
954
|
+
'OpenAIResponsesBrainDriver: server tool `web_fetch` is Anthropic-only. Use `web_search` for OpenAI, or route to Anthropic.',
|
|
955
955
|
{ context: { provider: 'openai-responses' } },
|
|
956
956
|
)
|
|
957
957
|
} else if (t.type === 'url_context') {
|
|
958
958
|
throw new BrainError(
|
|
959
|
-
'
|
|
959
|
+
'OpenAIResponsesBrainDriver: server tool `url_context` is Gemini-only. Route to Gemini, or include the URL in the prompt and use `web_search`.',
|
|
960
960
|
{ context: { provider: 'openai-responses' } },
|
|
961
961
|
)
|
|
962
962
|
}
|
|
@@ -1003,7 +1003,7 @@ async function tryRecoverParseError(
|
|
|
1003
1003
|
cause: Error,
|
|
1004
1004
|
options: RunWithToolsOptions,
|
|
1005
1005
|
): Promise<{ content: string; isError: boolean }> {
|
|
1006
|
-
const { ToolExecutionError } = await import('
|
|
1006
|
+
const { ToolExecutionError } = await import('../../tool_execution_error.ts')
|
|
1007
1007
|
const err = new ToolExecutionError(
|
|
1008
1008
|
toolName,
|
|
1009
1009
|
callId,
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Public API of @strav/brain.
|
|
2
2
|
//
|
|
3
|
-
// V1:
|
|
3
|
+
// V1: BrainDriver interface + AnthropicBrainDriver, BrainManager, Thread,
|
|
4
4
|
// BrainProvider service-wiring, prompt caching.
|
|
5
5
|
// V2 (this slice): tools + agents — defineTool, Agent base + AgentRunner,
|
|
6
|
-
// BrainManager.runTools / .agent(Class),
|
|
6
|
+
// BrainManager.runTools / .agent(Class), BrainDriver.runWithTools.
|
|
7
7
|
// Still deferred: MCP, embeddings, streaming agent loops, server-side
|
|
8
8
|
// tools, structured outputs, other providers.
|
|
9
9
|
|
|
@@ -29,7 +29,13 @@ export {
|
|
|
29
29
|
type OpenAIResponsesProviderConfig,
|
|
30
30
|
type ProviderConfig,
|
|
31
31
|
} from './brain_config.ts'
|
|
32
|
-
export {
|
|
32
|
+
export {
|
|
33
|
+
BrainConfigError,
|
|
34
|
+
BrainError,
|
|
35
|
+
BrainProviderError,
|
|
36
|
+
BrainUsageError,
|
|
37
|
+
UnknownProviderError,
|
|
38
|
+
} from './brain_error.ts'
|
|
33
39
|
export {
|
|
34
40
|
type AgentResolver,
|
|
35
41
|
BrainManager,
|
|
@@ -40,18 +46,18 @@ export { defineTool, type DefineToolSpec } from './define_tool.ts'
|
|
|
40
46
|
export { MCPClientPool, type MCPClientFactory } from './mcp/pool.ts'
|
|
41
47
|
export type { MCPServer, MCPServerToolConfig } from './mcp_server.ts'
|
|
42
48
|
export type { OutputSchema } from './output_schema.ts'
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
46
|
-
export {
|
|
47
|
-
export {
|
|
48
|
-
export {
|
|
49
|
-
export {
|
|
49
|
+
export { AnthropicBrainDriver } from './drivers/anthropic/anthropic_brain_driver.ts'
|
|
50
|
+
export { DeepSeekBrainDriver } from './drivers/deepseek/deepseek_brain_driver.ts'
|
|
51
|
+
export { GeminiBrainDriver } from './drivers/gemini/gemini_brain_driver.ts'
|
|
52
|
+
export { OllamaBrainDriver } from './drivers/ollama/ollama_brain_driver.ts'
|
|
53
|
+
export { OpenAICompatBrainDriver } from './drivers/openai_compat/openai_compat_brain_driver.ts'
|
|
54
|
+
export { OpenAIBrainDriver } from './drivers/openai/openai_brain_driver.ts'
|
|
55
|
+
export { OpenAIResponsesBrainDriver } from './drivers/openai_responses/openai_responses_brain_driver.ts'
|
|
50
56
|
export type {
|
|
51
|
-
|
|
57
|
+
BrainDriver,
|
|
52
58
|
RunWithToolsOptions,
|
|
53
59
|
RunWithToolsOptionsWithSuspend,
|
|
54
|
-
} from './
|
|
60
|
+
} from './brain_driver.ts'
|
|
55
61
|
export {
|
|
56
62
|
appendResumeResults,
|
|
57
63
|
isSuspended,
|
package/src/mcp/pool.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { Model } from '@strav/database'
|
|
15
15
|
import type { ChatUsage, ContentBlock } from '../types.ts'
|
|
16
|
-
import { brainMessageSchema } from './
|
|
16
|
+
import { brainMessageSchema } from './schemas/brain_message_schema.ts'
|
|
17
17
|
|
|
18
18
|
export type BrainMessageRole = 'user' | 'assistant'
|
|
19
19
|
|
|
@@ -13,13 +13,11 @@
|
|
|
13
13
|
* pagination UIs.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
// biome-ignore lint/style/useImportType: EventBus value import for @inject().
|
|
19
|
-
import { EventBus, inject, ulid } from '@strav/kernel'
|
|
16
|
+
import { quoteIdent, Repository, type RepositoryScope } from '@strav/database'
|
|
17
|
+
import { ulid } from '@strav/kernel'
|
|
20
18
|
import type { ChatUsage, ContentBlock } from '../types.ts'
|
|
21
19
|
import { BrainMessage, type BrainMessageRole } from './brain_message.ts'
|
|
22
|
-
import { brainMessageSchema } from './
|
|
20
|
+
import { brainMessageSchema } from './schemas/brain_message_schema.ts'
|
|
23
21
|
|
|
24
22
|
export interface AppendTurnInput {
|
|
25
23
|
threadId: string
|
|
@@ -37,16 +35,10 @@ export interface LoadMessagesOptions {
|
|
|
37
35
|
offset?: number
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
@inject()
|
|
41
38
|
export class BrainMessageRepository extends Repository<BrainMessage> {
|
|
42
39
|
static override readonly schema = brainMessageSchema
|
|
43
40
|
static override readonly model = BrainMessage
|
|
44
41
|
|
|
45
|
-
// biome-ignore lint/complexity/noUselessConstructor: explicit constructor for @inject() metadata emission.
|
|
46
|
-
constructor(db: PostgresDatabase, events: EventBus) {
|
|
47
|
-
super(db, events)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
42
|
/**
|
|
51
43
|
* Insert a new turn at the next `turn_index` for the thread. The
|
|
52
44
|
* `turn_index` is computed in-SQL so two concurrent appends
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { Model } from '@strav/database'
|
|
12
12
|
import type { SuspendedState } from '../suspended_run.ts'
|
|
13
13
|
import type { ToolUseBlock } from '../types.ts'
|
|
14
|
-
import { brainSuspendedRunSchema } from './
|
|
14
|
+
import { brainSuspendedRunSchema } from './schemas/brain_suspended_run_schema.ts'
|
|
15
15
|
|
|
16
16
|
export type BrainSuspendedRunStatus = 'pending' | 'resumed' | 'cancelled'
|
|
17
17
|
|
|
@@ -12,12 +12,9 @@
|
|
|
12
12
|
* filtered by `user_id` or `thread_id`.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
import { PostgresDatabase, Repository } from '@strav/database'
|
|
17
|
-
// biome-ignore lint/style/useImportType: EventBus value import for @inject().
|
|
18
|
-
import { EventBus, inject } from '@strav/kernel'
|
|
15
|
+
import { Repository } from '@strav/database'
|
|
19
16
|
import { BrainSuspendedRun, type BrainSuspendedRunStatus } from './brain_suspended_run.ts'
|
|
20
|
-
import { brainSuspendedRunSchema } from './
|
|
17
|
+
import { brainSuspendedRunSchema } from './schemas/brain_suspended_run_schema.ts'
|
|
21
18
|
|
|
22
19
|
export interface ListPendingOptions {
|
|
23
20
|
/** Filter by app-defined user — useful when an app has per-user approval queues. */
|
|
@@ -29,16 +26,10 @@ export interface ListPendingOptions {
|
|
|
29
26
|
offset?: number
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
@inject()
|
|
33
29
|
export class BrainSuspendedRunRepository extends Repository<BrainSuspendedRun> {
|
|
34
30
|
static override readonly schema = brainSuspendedRunSchema
|
|
35
31
|
static override readonly model = BrainSuspendedRun
|
|
36
32
|
|
|
37
|
-
// biome-ignore lint/complexity/noUselessConstructor: explicit constructor for @inject() metadata emission.
|
|
38
|
-
constructor(db: PostgresDatabase, events: EventBus) {
|
|
39
|
-
super(db, events)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
33
|
/** Flip status to `resumed` after `brain.resumeTools(state, ...)` succeeds. */
|
|
43
34
|
async markResumed(run: BrainSuspendedRun): Promise<BrainSuspendedRun> {
|
|
44
35
|
return this.markStatus(run, 'resumed')
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { Model } from '@strav/database'
|
|
15
15
|
import type { ChatOptions, SystemPrompt } from '../types.ts'
|
|
16
|
-
import { brainThreadSchema } from './
|
|
16
|
+
import { brainThreadSchema } from './schemas/brain_thread_schema.ts'
|
|
17
17
|
|
|
18
18
|
export class BrainThread extends Model {
|
|
19
19
|
static override readonly schema = brainThreadSchema
|
|
@@ -14,12 +14,9 @@
|
|
|
14
14
|
* shows up in this code — the database enforces isolation.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
import { PostgresDatabase, Repository } from '@strav/database'
|
|
19
|
-
// biome-ignore lint/style/useImportType: EventBus has the same constraint as PostgresDatabase.
|
|
20
|
-
import { EventBus, inject } from '@strav/kernel'
|
|
17
|
+
import { Repository } from '@strav/database'
|
|
21
18
|
import { BrainThread } from './brain_thread.ts'
|
|
22
|
-
import { brainThreadSchema } from './
|
|
19
|
+
import { brainThreadSchema } from './schemas/brain_thread_schema.ts'
|
|
23
20
|
|
|
24
21
|
export interface ListThreadsOptions {
|
|
25
22
|
/** Pagination — defaults to 50. */
|
|
@@ -27,16 +24,10 @@ export interface ListThreadsOptions {
|
|
|
27
24
|
offset?: number
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
@inject()
|
|
31
27
|
export class BrainThreadRepository extends Repository<BrainThread> {
|
|
32
28
|
static override readonly schema = brainThreadSchema
|
|
33
29
|
static override readonly model = BrainThread
|
|
34
30
|
|
|
35
|
-
// biome-ignore lint/complexity/noUselessConstructor: explicit constructor forces TypeScript to emit `design:paramtypes` metadata on the subclass for the @inject() decorator above.
|
|
36
|
-
constructor(db: PostgresDatabase, events: EventBus) {
|
|
37
|
-
super(db, events)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
31
|
/**
|
|
41
32
|
* List threads for a given app-defined user, newest-first. Empty
|
|
42
33
|
* `userId` lists every thread visible under RLS — useful for
|
package/src/persistence/index.ts
CHANGED
package/src/tool_runner.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* message content; Gemini `functionResponse` with `{ error }`).
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import type { RunWithToolsOptions } from './
|
|
25
|
+
import type { RunWithToolsOptions } from './brain_driver.ts'
|
|
26
26
|
import type { Tool, ToolContext } from './tool.ts'
|
|
27
27
|
import { ToolExecutionError } from './tool_execution_error.ts'
|
|
28
28
|
|
package/src/types.ts
CHANGED
|
@@ -376,7 +376,7 @@ export interface ChatOptions {
|
|
|
376
376
|
* subsequent requests (Thread does this automatically). Saves
|
|
377
377
|
* tokens on long threads without lossy client-side pruning.
|
|
378
378
|
*
|
|
379
|
-
* Only honored by `
|
|
379
|
+
* Only honored by `AnthropicBrainDriver` (driver `'anthropic'`),
|
|
380
380
|
* via the `compact-2026-01-12` beta. Silently ignored by every
|
|
381
381
|
* other provider so apps targeting multiple providers with the
|
|
382
382
|
* same options object don't have to special-case.
|
|
@@ -388,7 +388,7 @@ export interface ChatOptions {
|
|
|
388
388
|
* from the prior `Response` identified by this id and replays
|
|
389
389
|
* the conversation server-side. Saves tokens on long threads.
|
|
390
390
|
*
|
|
391
|
-
* Only honored by `
|
|
391
|
+
* Only honored by `OpenAIResponsesBrainDriver` (driver
|
|
392
392
|
* `'openai-responses'`); silently ignored by every other provider
|
|
393
393
|
* — apps that target multiple providers with the same options
|
|
394
394
|
* object don't have to special-case.
|