modular-voice-agent-sdk 2.3.1 → 2.5.0
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 +4 -0
- package/dist/backends/agent/index.d.ts +16 -0
- package/dist/backends/agent/index.d.ts.map +1 -0
- package/dist/backends/agent/index.js +14 -0
- package/dist/backends/agent/index.js.map +1 -0
- package/dist/backends/agent/llm.d.ts +40 -0
- package/dist/backends/agent/llm.d.ts.map +1 -0
- package/dist/backends/agent/llm.js +110 -0
- package/dist/backends/agent/llm.js.map +1 -0
- package/dist/backends/agent/opencode-provider.d.ts +94 -0
- package/dist/backends/agent/opencode-provider.d.ts.map +1 -0
- package/dist/backends/agent/opencode-provider.js +169 -0
- package/dist/backends/agent/opencode-provider.js.map +1 -0
- package/dist/backends/agent/pi-agent-provider.d.ts +76 -0
- package/dist/backends/agent/pi-agent-provider.d.ts.map +1 -0
- package/dist/backends/agent/pi-agent-provider.js +149 -0
- package/dist/backends/agent/pi-agent-provider.js.map +1 -0
- package/dist/backends/agent/pi-coding-agent-provider.d.ts +87 -0
- package/dist/backends/agent/pi-coding-agent-provider.d.ts.map +1 -0
- package/dist/backends/agent/pi-coding-agent-provider.js +156 -0
- package/dist/backends/agent/pi-coding-agent-provider.js.map +1 -0
- package/dist/backends/agent/provider.d.ts +61 -0
- package/dist/backends/agent/provider.d.ts.map +1 -0
- package/dist/backends/agent/provider.js +11 -0
- package/dist/backends/agent/provider.js.map +1 -0
- package/dist/backends/cloud/llm.d.ts.map +1 -1
- package/dist/backends/cloud/llm.js +6 -4
- package/dist/backends/cloud/llm.js.map +1 -1
- package/dist/server/handler.d.ts +3 -1
- package/dist/server/handler.d.ts.map +1 -1
- package/dist/server/handler.js +19 -3
- package/dist/server/handler.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/text-normalizer.d.ts +33 -0
- package/dist/services/text-normalizer.d.ts.map +1 -1
- package/dist/services/text-normalizer.js +24 -0
- package/dist/services/text-normalizer.js.map +1 -1
- package/dist/voice-pipeline.d.ts +22 -0
- package/dist/voice-pipeline.d.ts.map +1 -1
- package/dist/voice-pipeline.js +24 -5
- package/dist/voice-pipeline.js.map +1 -1
- package/package.json +22 -2
package/README.md
CHANGED
|
@@ -53,6 +53,9 @@ Each component can run in the browser, on a server, or in the cloud. Pick any fr
|
|
|
53
53
|
N/A ☁️ Cloud Audio LLM N/A
|
|
54
54
|
(GPT Audio, multimodal)
|
|
55
55
|
|
|
56
|
+
N/A 🤖 Agent SDK N/A
|
|
57
|
+
(OpenCode, Pi Agent)
|
|
58
|
+
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
Want browser speech recognition + a cloud LLM + browser speech synthesis? Done. Want everything running locally on your server with native binaries? Also done. Same code structure, same events, different backends.
|
|
@@ -61,6 +64,7 @@ Want browser speech recognition + a cloud LLM + browser speech synthesis? Done.
|
|
|
61
64
|
|
|
62
65
|
- **Streaming** — responses stream token-by-token to TTS
|
|
63
66
|
- **Function calling** — tools work across all LLM backends (cloud, native, transformers)
|
|
67
|
+
- **Agent SDK support** — wrap coding agents (OpenCode, Pi Agent) as voice-controlled backends
|
|
64
68
|
- **Conversation history** — automatic context management
|
|
65
69
|
- **Hybrid configs** — mix browser and server components freely
|
|
66
70
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Backend - Agent SDK support
|
|
3
|
+
* Wraps coding agent SDKs (OpenCode, Pi Agent, Pi Coding Agent, etc.) as LLM backends.
|
|
4
|
+
*
|
|
5
|
+
* The agent handles tool execution internally — the voice pipeline
|
|
6
|
+
* only receives text responses and tool activity notifications.
|
|
7
|
+
*/
|
|
8
|
+
export { AgentLLM } from './llm';
|
|
9
|
+
export type { AgentProvider, AgentSession, AgentStreamEvent } from './provider';
|
|
10
|
+
export { OpenCodeAgentProvider } from './opencode-provider';
|
|
11
|
+
export type { OpenCodeAgentProviderConfig, OpenCodeClient } from './opencode-provider';
|
|
12
|
+
export { PiAgentProvider } from './pi-agent-provider';
|
|
13
|
+
export type { PiAgentProviderConfig, PiAgent } from './pi-agent-provider';
|
|
14
|
+
export { PiCodingAgentProvider } from './pi-coding-agent-provider';
|
|
15
|
+
export type { PiCodingAgentProviderConfig, PiCodingAgentSession } from './pi-coding-agent-provider';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backends/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Backend - Agent SDK support
|
|
3
|
+
* Wraps coding agent SDKs (OpenCode, Pi Agent, Pi Coding Agent, etc.) as LLM backends.
|
|
4
|
+
*
|
|
5
|
+
* The agent handles tool execution internally — the voice pipeline
|
|
6
|
+
* only receives text responses and tool activity notifications.
|
|
7
|
+
*/
|
|
8
|
+
// Core
|
|
9
|
+
export { AgentLLM } from './llm';
|
|
10
|
+
// Providers
|
|
11
|
+
export { OpenCodeAgentProvider } from './opencode-provider';
|
|
12
|
+
export { PiAgentProvider } from './pi-agent-provider';
|
|
13
|
+
export { PiCodingAgentProvider } from './pi-coding-agent-provider';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/backends/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACP,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,YAAY;AACZ,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent LLM Pipeline
|
|
3
|
+
* Wraps agent SDKs (OpenCode, Pi Agent, etc.) as an LLMPipeline backend.
|
|
4
|
+
*
|
|
5
|
+
* Unlike CloudLLM which makes raw API calls and lets the voice pipeline handle
|
|
6
|
+
* tool execution, AgentLLM delegates to an agent SDK that manages its own
|
|
7
|
+
* tool execution loop internally. From the voice pipeline's perspective,
|
|
8
|
+
* this backend always returns finishReason: 'stop' — the tool loop is
|
|
9
|
+
* handled entirely within the agent.
|
|
10
|
+
*
|
|
11
|
+
* Tool activity events are forwarded via onToolCall callbacks so the UI
|
|
12
|
+
* can display "Reading file...", "Writing code...", etc.
|
|
13
|
+
*/
|
|
14
|
+
import type { LLMPipeline, ProgressCallback, Message, LLMGenerateOptions, LLMGenerateResult } from '../../types';
|
|
15
|
+
import type { AgentProvider } from './provider';
|
|
16
|
+
export declare class AgentLLM implements LLMPipeline {
|
|
17
|
+
private provider;
|
|
18
|
+
private session;
|
|
19
|
+
private ready;
|
|
20
|
+
constructor(provider: AgentProvider);
|
|
21
|
+
initialize(_onProgress?: ProgressCallback): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Agent backends handle tools internally — the voice pipeline
|
|
24
|
+
* should not pass tool definitions or expect tool_calls back.
|
|
25
|
+
*/
|
|
26
|
+
supportsTools(): boolean;
|
|
27
|
+
generate(messages: Message[], options?: LLMGenerateOptions): Promise<LLMGenerateResult>;
|
|
28
|
+
isReady(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Destroy the current session and release resources.
|
|
31
|
+
* A new session will be created on the next generate() call.
|
|
32
|
+
*/
|
|
33
|
+
destroySession(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Extract the latest user message from the conversation history.
|
|
36
|
+
* We walk backwards to find the most recent 'user' role message.
|
|
37
|
+
*/
|
|
38
|
+
private extractLatestUserMessage;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../../src/backends/agent/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAC;AAE9D,qBAAa,QAAS,YAAW,WAAW;IAC1C,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,KAAK,CAAS;gBAEV,QAAQ,EAAE,aAAa;IAI7B,UAAU,CAAC,WAAW,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/D;;;OAGG;IACH,aAAa,IAAI,OAAO;IAIlB,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA6D7F,OAAO,IAAI,OAAO;IAIlB;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;CAQjC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent LLM Pipeline
|
|
3
|
+
* Wraps agent SDKs (OpenCode, Pi Agent, etc.) as an LLMPipeline backend.
|
|
4
|
+
*
|
|
5
|
+
* Unlike CloudLLM which makes raw API calls and lets the voice pipeline handle
|
|
6
|
+
* tool execution, AgentLLM delegates to an agent SDK that manages its own
|
|
7
|
+
* tool execution loop internally. From the voice pipeline's perspective,
|
|
8
|
+
* this backend always returns finishReason: 'stop' — the tool loop is
|
|
9
|
+
* handled entirely within the agent.
|
|
10
|
+
*
|
|
11
|
+
* Tool activity events are forwarded via onToolCall callbacks so the UI
|
|
12
|
+
* can display "Reading file...", "Writing code...", etc.
|
|
13
|
+
*/
|
|
14
|
+
export class AgentLLM {
|
|
15
|
+
provider;
|
|
16
|
+
session = null;
|
|
17
|
+
ready = false;
|
|
18
|
+
constructor(provider) {
|
|
19
|
+
this.provider = provider;
|
|
20
|
+
}
|
|
21
|
+
async initialize(_onProgress) {
|
|
22
|
+
console.log('Initializing Agent LLM...');
|
|
23
|
+
this.ready = true;
|
|
24
|
+
console.log('Agent LLM ready (session will be created on first message).');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Agent backends handle tools internally — the voice pipeline
|
|
28
|
+
* should not pass tool definitions or expect tool_calls back.
|
|
29
|
+
*/
|
|
30
|
+
supportsTools() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
async generate(messages, options) {
|
|
34
|
+
if (!this.ready) {
|
|
35
|
+
throw new Error('Agent LLM pipeline not initialized');
|
|
36
|
+
}
|
|
37
|
+
// Lazily create the agent session on first generate() call
|
|
38
|
+
if (!this.session) {
|
|
39
|
+
console.log('Creating agent session...');
|
|
40
|
+
this.session = await this.provider.createSession();
|
|
41
|
+
console.log('Agent session created.');
|
|
42
|
+
}
|
|
43
|
+
// Extract the latest user message from the conversation history.
|
|
44
|
+
// The agent SDK maintains its own history, so we only need the new message.
|
|
45
|
+
const latestUserMessage = this.extractLatestUserMessage(messages);
|
|
46
|
+
if (!latestUserMessage) {
|
|
47
|
+
return { content: '', finishReason: 'stop' };
|
|
48
|
+
}
|
|
49
|
+
// Stream the response from the agent
|
|
50
|
+
let fullContent = '';
|
|
51
|
+
for await (const event of this.session.sendMessage(latestUserMessage)) {
|
|
52
|
+
switch (event.type) {
|
|
53
|
+
case 'text_delta':
|
|
54
|
+
if (event.content) {
|
|
55
|
+
fullContent += event.content;
|
|
56
|
+
options?.onToken?.(event.content);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 'tool_call_start':
|
|
60
|
+
if (event.toolCall) {
|
|
61
|
+
options?.onToolCall?.({
|
|
62
|
+
id: event.toolCall.id,
|
|
63
|
+
name: event.toolCall.name,
|
|
64
|
+
arguments: event.toolCall.arguments ?? {},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case 'tool_call_end':
|
|
69
|
+
// Tool results are informational only — the agent already handled them.
|
|
70
|
+
break;
|
|
71
|
+
case 'error':
|
|
72
|
+
throw new Error(`Agent error: ${event.error ?? 'Unknown error'}`);
|
|
73
|
+
case 'done':
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Always return 'stop' — the agent handles its own tool loop.
|
|
78
|
+
// The voice pipeline's tool loop will exit on the first iteration.
|
|
79
|
+
return {
|
|
80
|
+
content: fullContent,
|
|
81
|
+
finishReason: 'stop',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
isReady() {
|
|
85
|
+
return this.ready;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Destroy the current session and release resources.
|
|
89
|
+
* A new session will be created on the next generate() call.
|
|
90
|
+
*/
|
|
91
|
+
async destroySession() {
|
|
92
|
+
if (this.session) {
|
|
93
|
+
await this.session.destroy();
|
|
94
|
+
this.session = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract the latest user message from the conversation history.
|
|
99
|
+
* We walk backwards to find the most recent 'user' role message.
|
|
100
|
+
*/
|
|
101
|
+
extractLatestUserMessage(messages) {
|
|
102
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
103
|
+
if (messages[i].role === 'user') {
|
|
104
|
+
return messages[i].content;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=llm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../../src/backends/agent/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAWH,MAAM,OAAO,QAAQ;IACX,QAAQ,CAAgB;IACxB,OAAO,GAAwB,IAAI,CAAC;IACpC,KAAK,GAAG,KAAK,CAAC;IAEtB,YAAY,QAAuB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,WAA8B;QAC7C,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;IAC7E,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAmB,EAAE,OAA4B;QAC9D,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,2DAA2D;QAC3D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;Y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KAAK,MAAM;oBACT,MAAM;YACV,CAAC;QACH,CAAC;QAED,8DAA8D;QAC9D,mEAAmE;QACnE,OAAO;YACL,OAAO,EAAE,WAAW;YACpB,YAAY,EAAE,MAAM;SACrB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,wBAAwB,CAAC,QAAmB;QAClD,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Agent Provider
|
|
3
|
+
* Wraps an OpenCode SDK session as an AgentProvider.
|
|
4
|
+
*
|
|
5
|
+
* The user creates the OpenCode client externally and passes in
|
|
6
|
+
* the session API. This provider handles creating sessions and
|
|
7
|
+
* mapping SSE events to AgentStreamEvents.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createOpencode } from '@opencode-ai/sdk';
|
|
12
|
+
*
|
|
13
|
+
* const opencode = await createOpencode({ ... });
|
|
14
|
+
*
|
|
15
|
+
* const pipeline = createVoicePipeline({
|
|
16
|
+
* create: () => ({
|
|
17
|
+
* stt: new CloudSTT({ ... }),
|
|
18
|
+
* llm: new AgentLLM(new OpenCodeAgentProvider({
|
|
19
|
+
* client: opencode.client,
|
|
20
|
+
* })),
|
|
21
|
+
* tts: null,
|
|
22
|
+
* systemPrompt: 'You are a coding assistant.',
|
|
23
|
+
* }),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { AgentProvider, AgentSession } from './provider';
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for the OpenCode agent provider.
|
|
30
|
+
*/
|
|
31
|
+
export interface OpenCodeAgentProviderConfig {
|
|
32
|
+
/**
|
|
33
|
+
* The OpenCode SDK client instance.
|
|
34
|
+
* Created externally via createOpencode() or createOpencodeClient().
|
|
35
|
+
*/
|
|
36
|
+
client: OpenCodeClient;
|
|
37
|
+
/**
|
|
38
|
+
* Model override (e.g., { providerID: 'anthropic', modelID: 'claude-sonnet-4-20250514' }).
|
|
39
|
+
* If omitted, uses the server's default model.
|
|
40
|
+
*/
|
|
41
|
+
model?: {
|
|
42
|
+
providerID: string;
|
|
43
|
+
modelID: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* OpenCode Agent Provider
|
|
48
|
+
* Wraps an externally-created OpenCode client.
|
|
49
|
+
*/
|
|
50
|
+
export declare class OpenCodeAgentProvider implements AgentProvider {
|
|
51
|
+
private config;
|
|
52
|
+
constructor(config: OpenCodeAgentProviderConfig);
|
|
53
|
+
createSession(): Promise<AgentSession>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Minimal type definitions for the OpenCode SDK client.
|
|
57
|
+
* These match the SDK's API surface without requiring the SDK at build time.
|
|
58
|
+
* The user passes in the real SDK client which satisfies this interface.
|
|
59
|
+
*/
|
|
60
|
+
interface OpenCodePromptBody {
|
|
61
|
+
parts: Array<{
|
|
62
|
+
type: string;
|
|
63
|
+
text: string;
|
|
64
|
+
}>;
|
|
65
|
+
model?: {
|
|
66
|
+
providerID: string;
|
|
67
|
+
modelID: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export interface OpenCodeClient {
|
|
71
|
+
session: {
|
|
72
|
+
create(opts: {
|
|
73
|
+
body: Record<string, unknown>;
|
|
74
|
+
}): Promise<any>;
|
|
75
|
+
prompt(opts: {
|
|
76
|
+
path: {
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
body: OpenCodePromptBody;
|
|
80
|
+
}): Promise<any>;
|
|
81
|
+
delete(opts: {
|
|
82
|
+
path: {
|
|
83
|
+
id: string;
|
|
84
|
+
};
|
|
85
|
+
}): Promise<any>;
|
|
86
|
+
};
|
|
87
|
+
event: {
|
|
88
|
+
subscribe(): Promise<{
|
|
89
|
+
stream: AsyncIterable<any>;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=opencode-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-provider.d.ts","sourceRoot":"","sources":["../../../src/backends/agent/opencode-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,MAAM,EAAE,cAAc,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD;AAED;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,aAAa;IACzD,OAAO,CAAC,MAAM,CAA8B;gBAEhC,MAAM,EAAE,2BAA2B;IAIzC,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC;CAY7C;AAoID;;;;GAIG;AAGH,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7C,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE;QACP,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9D,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE;gBAAE,EAAE,EAAE,MAAM,CAAA;aAAE,CAAC;YAAC,IAAI,EAAE,kBAAkB,CAAA;SAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/E,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE;gBAAE,EAAE,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;KACtD,CAAC;IACF,KAAK,EAAE;QACL,SAAS,IAAI,OAAO,CAAC;YAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;SAAE,CAAC,CAAC;KACtD,CAAC;CACH"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Agent Provider
|
|
3
|
+
* Wraps an OpenCode SDK session as an AgentProvider.
|
|
4
|
+
*
|
|
5
|
+
* The user creates the OpenCode client externally and passes in
|
|
6
|
+
* the session API. This provider handles creating sessions and
|
|
7
|
+
* mapping SSE events to AgentStreamEvents.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createOpencode } from '@opencode-ai/sdk';
|
|
12
|
+
*
|
|
13
|
+
* const opencode = await createOpencode({ ... });
|
|
14
|
+
*
|
|
15
|
+
* const pipeline = createVoicePipeline({
|
|
16
|
+
* create: () => ({
|
|
17
|
+
* stt: new CloudSTT({ ... }),
|
|
18
|
+
* llm: new AgentLLM(new OpenCodeAgentProvider({
|
|
19
|
+
* client: opencode.client,
|
|
20
|
+
* })),
|
|
21
|
+
* tts: null,
|
|
22
|
+
* systemPrompt: 'You are a coding assistant.',
|
|
23
|
+
* }),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* OpenCode Agent Provider
|
|
29
|
+
* Wraps an externally-created OpenCode client.
|
|
30
|
+
*/
|
|
31
|
+
export class OpenCodeAgentProvider {
|
|
32
|
+
config;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = config;
|
|
35
|
+
}
|
|
36
|
+
async createSession() {
|
|
37
|
+
const client = this.config.client;
|
|
38
|
+
// Create a new session on the OpenCode server
|
|
39
|
+
const session = await client.session.create({ body: {} });
|
|
40
|
+
const sessionId = session.id ?? session.data?.id;
|
|
41
|
+
if (!sessionId) {
|
|
42
|
+
throw new Error('OpenCode: Failed to create session — no session ID returned');
|
|
43
|
+
}
|
|
44
|
+
return new OpenCodeAgentSession(client, sessionId, this.config.model);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Active OpenCode agent session.
|
|
49
|
+
* Manages the SSE event subscription and prompt sending.
|
|
50
|
+
*/
|
|
51
|
+
class OpenCodeAgentSession {
|
|
52
|
+
client;
|
|
53
|
+
sessionId;
|
|
54
|
+
model;
|
|
55
|
+
constructor(client, sessionId, model) {
|
|
56
|
+
this.client = client;
|
|
57
|
+
this.sessionId = sessionId;
|
|
58
|
+
this.model = model;
|
|
59
|
+
}
|
|
60
|
+
async *sendMessage(text) {
|
|
61
|
+
// Subscribe to SSE events before sending the prompt.
|
|
62
|
+
// This ensures we capture all events including the first ones.
|
|
63
|
+
const events = await this.client.event.subscribe();
|
|
64
|
+
// Build prompt body
|
|
65
|
+
const promptBody = {
|
|
66
|
+
parts: [{ type: 'text', text }],
|
|
67
|
+
};
|
|
68
|
+
if (this.model) {
|
|
69
|
+
promptBody.model = this.model;
|
|
70
|
+
}
|
|
71
|
+
// Send the prompt (don't await — we process events as they stream)
|
|
72
|
+
const promptPromise = this.client.session.prompt({
|
|
73
|
+
path: { id: this.sessionId },
|
|
74
|
+
body: promptBody,
|
|
75
|
+
});
|
|
76
|
+
// Track text we've already emitted to compute deltas.
|
|
77
|
+
// OpenCode message.part.updated events contain the full accumulated text,
|
|
78
|
+
// so we diff against what we've sent to produce incremental deltas.
|
|
79
|
+
let emittedTextLength = 0;
|
|
80
|
+
let done = false;
|
|
81
|
+
try {
|
|
82
|
+
for await (const event of events.stream) {
|
|
83
|
+
// Filter events for our session
|
|
84
|
+
const props = event.properties ?? event;
|
|
85
|
+
const eventSessionId = props.sessionID ?? props.session_id;
|
|
86
|
+
if (eventSessionId !== this.sessionId) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const eventType = event.type ?? event.event ?? '';
|
|
90
|
+
if (eventType === 'message.part.updated') {
|
|
91
|
+
const part = props.part ?? props;
|
|
92
|
+
const partType = part?.type ?? '';
|
|
93
|
+
if (partType === 'text') {
|
|
94
|
+
// Text delta — OpenCode sends cumulative text, so compute the delta
|
|
95
|
+
const fullText = part.text ?? part.content ?? '';
|
|
96
|
+
if (fullText.length > emittedTextLength) {
|
|
97
|
+
const delta = fullText.slice(emittedTextLength);
|
|
98
|
+
emittedTextLength = fullText.length;
|
|
99
|
+
yield { type: 'text_delta', content: delta };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (partType === 'tool-invocation' || partType === 'tool_use') {
|
|
103
|
+
const toolInvocation = part.toolInvocation ?? part;
|
|
104
|
+
const state = toolInvocation.state ?? '';
|
|
105
|
+
const toolName = toolInvocation.toolName ?? part.name ?? 'unknown';
|
|
106
|
+
const toolCallId = toolInvocation.toolCallId ?? part.id ?? '';
|
|
107
|
+
if (state === 'calling' || state === 'partial-call') {
|
|
108
|
+
yield {
|
|
109
|
+
type: 'tool_call_start',
|
|
110
|
+
toolCall: {
|
|
111
|
+
id: toolCallId,
|
|
112
|
+
name: toolName,
|
|
113
|
+
arguments: toolInvocation.args ?? {},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else if (state === 'result') {
|
|
118
|
+
yield {
|
|
119
|
+
type: 'tool_call_end',
|
|
120
|
+
toolCall: {
|
|
121
|
+
id: toolCallId,
|
|
122
|
+
name: toolName,
|
|
123
|
+
result: toolInvocation.result,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (eventType === 'session.error') {
|
|
130
|
+
yield {
|
|
131
|
+
type: 'error',
|
|
132
|
+
error: props.error ?? props.message ?? 'Unknown OpenCode error',
|
|
133
|
+
};
|
|
134
|
+
done = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
else if (eventType === 'session.idle') {
|
|
138
|
+
// Reset text tracking for next message in this session
|
|
139
|
+
emittedTextLength = 0;
|
|
140
|
+
done = true;
|
|
141
|
+
yield { type: 'done' };
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
if (!done) {
|
|
148
|
+
yield { type: 'done' };
|
|
149
|
+
}
|
|
150
|
+
// Wait for the prompt to resolve to catch any errors
|
|
151
|
+
try {
|
|
152
|
+
await promptPromise;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
console.warn('OpenCode prompt error:', err);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async destroy() {
|
|
160
|
+
try {
|
|
161
|
+
await this.client.session.delete({ path: { id: this.sessionId } });
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Session may already be cleaned up
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
169
|
+
//# sourceMappingURL=opencode-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-provider.js","sourceRoot":"","sources":["../../../src/backends/agent/opencode-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAoBH;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAA8B;IAE5C,YAAY,MAAmC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAElC,8CAA8C;QAC9C,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAW,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACzD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,IAAI,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,oBAAoB;IAChB,MAAM,CAAiB;IACvB,SAAS,CAAS;IAClB,KAAK,CAA2C;IAExD,YACE,MAAsB,EACtB,SAAiB,EACjB,KAA+C;QAE/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,CAAC,WAAW,CAAC,IAAY;QAC7B,qDAAqD;QACrD,+DAA+D;QAC/D,MAAM,MAAM,GAAG,MAAM,IAAI,C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AC;qBAAM,IAAI,SAAS,KAAK,eAAe,EAAE,CAAC;oBACzC,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,IAAI,wBAAwB;qBAChE,CAAC;oBACF,IAAI,GAAG,IAAI,CAAC;oBACZ,MAAM;gBACR,CAAC;qBAAM,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;oBACxC,uDAAuD;oBACvD,iBAAiB,GAAG,CAAC,CAAC;oBACtB,IAAI,GAAG,IAAI,CAAC;oBACZ,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oBACvB,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YACzB,CAAC;YACD,qDAAqD;YACrD,IAAI,CAAC;gBACH,MAAM,aAAa,CAAC;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,oCAAoC;QACtC,CAAC;IACH,CAAC;CACF;AAwBD,sDAAsD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Agent Provider
|
|
3
|
+
* Wraps a Pi Agent instance (@mariozechner/pi-agent-core) as an AgentProvider.
|
|
4
|
+
*
|
|
5
|
+
* The user creates the Agent externally with their own model, tools, and config.
|
|
6
|
+
* This provider wraps it and maps its event stream to AgentStreamEvents.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Agent } from '@mariozechner/pi-agent-core';
|
|
11
|
+
* import { getModel } from '@mariozechner/pi-ai';
|
|
12
|
+
* import { codingTools } from '@mariozechner/pi-coding-agent';
|
|
13
|
+
*
|
|
14
|
+
* const agent = new Agent({
|
|
15
|
+
* initialState: {
|
|
16
|
+
* systemPrompt: 'You are a coding assistant.',
|
|
17
|
+
* model: getModel('anthropic', 'claude-sonnet-4-20250514'),
|
|
18
|
+
* thinkingLevel: 'medium',
|
|
19
|
+
* tools: codingTools,
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const pipeline = createVoicePipeline({
|
|
24
|
+
* create: () => ({
|
|
25
|
+
* stt: new CloudSTT({ ... }),
|
|
26
|
+
* llm: new AgentLLM(new PiAgentProvider({ agent })),
|
|
27
|
+
* tts: null,
|
|
28
|
+
* systemPrompt: 'You are a coding assistant.',
|
|
29
|
+
* }),
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import type { AgentProvider, AgentSession } from './provider';
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for the Pi Agent provider.
|
|
36
|
+
*/
|
|
37
|
+
export interface PiAgentProviderConfig {
|
|
38
|
+
/**
|
|
39
|
+
* A pre-created Pi Agent instance.
|
|
40
|
+
* Created externally with your own model, tools, and configuration.
|
|
41
|
+
*/
|
|
42
|
+
agent: PiAgent;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Pi Agent Provider
|
|
46
|
+
* Wraps an externally-created Pi Agent instance.
|
|
47
|
+
*/
|
|
48
|
+
export declare class PiAgentProvider implements AgentProvider {
|
|
49
|
+
private agent;
|
|
50
|
+
constructor(config: PiAgentProviderConfig);
|
|
51
|
+
createSession(): Promise<AgentSession>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Minimal type definitions for the Pi Agent SDK.
|
|
55
|
+
* These match the SDK's API surface without requiring the SDK at build time.
|
|
56
|
+
* The user passes in the real Agent instance which satisfies this interface.
|
|
57
|
+
*/
|
|
58
|
+
interface PiAgentEvent {
|
|
59
|
+
type: string;
|
|
60
|
+
assistantMessageEvent?: {
|
|
61
|
+
type: string;
|
|
62
|
+
delta?: string;
|
|
63
|
+
};
|
|
64
|
+
toolCallId?: string;
|
|
65
|
+
toolName?: string;
|
|
66
|
+
args?: Record<string, unknown>;
|
|
67
|
+
result?: any;
|
|
68
|
+
isError?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface PiAgent {
|
|
71
|
+
prompt(text: string | any, images?: any[]): Promise<void>;
|
|
72
|
+
subscribe(listener: (event: PiAgentEvent) => void): () => void;
|
|
73
|
+
abort(): void;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=pi-agent-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-agent-provider.d.ts","sourceRoot":"","sources":["../../../src/backends/agent/pi-agent-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,aAAa;IACnD,OAAO,CAAC,KAAK,CAAU;gBAEX,MAAM,EAAE,qBAAqB;IAInC,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC;CAG7C;AA+GD;;;;GAIG;AAGH,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,qBAAqB,CAAC,EAAE;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,KAAK,IAAI,IAAI,CAAC;CACf"}
|