@corbat-tech/coco 2.37.0 → 2.38.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 +149 -13
- package/dist/adapters/index.d.ts +37 -0
- package/dist/adapters/index.js +46 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/agent-runtime-DeLcB0Ie.d.ts +756 -0
- package/dist/blueprints-BWcCJfnN.d.ts +99 -0
- package/dist/cli/index.js +471 -27
- package/dist/cli/index.js.map +1 -1
- package/dist/extension-manifests-DcvOnrp3.d.ts +113 -0
- package/dist/index-Dp1o8c9g.d.ts +2807 -0
- package/dist/index.d.ts +25 -913
- package/dist/index.js +1086 -16
- package/dist/index.js.map +1 -1
- package/dist/presets/index.d.ts +39 -0
- package/dist/presets/index.js +26585 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/profiles-BcyL-gQ9.d.ts +76 -0
- package/dist/rag-BakFRE-u.d.ts +31 -0
- package/dist/registry-CEpl9Jq0.d.ts +115 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +26855 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +18726 -0
- package/dist/tools/index.js.map +1 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
<br/>
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/@corbat-tech/coco)
|
|
8
|
+
[](https://www.npmjs.com/package/@corbat-tech/coco)
|
|
9
|
+
[](https://github.com/corbat-tech/coco/actions/workflows/ci.yml)
|
|
10
|
+
[](https://github.com/corbat-tech/coco/actions/workflows/codeql.yml)
|
|
8
11
|
[](https://nodejs.org/)
|
|
9
12
|
[](LICENSE)
|
|
10
13
|
|
|
11
|
-
[Install](#install) · [Quick Start](#quick-start) · [
|
|
14
|
+
[Install](#install) · [Quick Start](#quick-start) · [Why Coco](#why-coco) · [Runtime](#runtime-reuse) · [Web Assistant Example](#example-web-assistant-runtime) · [Providers](#providers) · [Documentation](#documentation)
|
|
12
15
|
|
|
13
16
|
</div>
|
|
14
17
|
|
|
15
|
-
**Coco is an open-source CLI coding agent for real
|
|
16
|
-
It plans work, edits files, runs tools/tests, and iterates until quality checks pass.
|
|
18
|
+
**Coco is an open-source CLI coding agent and reusable agent runtime for real-world automation.**
|
|
19
|
+
It plans work, edits files, runs tools/tests, and iterates until quality checks pass. Underneath the CLI, Coco exposes a runtime for building custom agents with providers, tools, permissions, sessions, events, and workflows.
|
|
17
20
|
|
|
18
21
|
---
|
|
19
22
|
|
|
@@ -27,15 +30,62 @@ Best fit:
|
|
|
27
30
|
- Teams and solo developers working on existing repos (not only greenfield demos).
|
|
28
31
|
- Workflows that require multi-step execution and verification, not just text generation.
|
|
29
32
|
|
|
33
|
+
## Why Coco?
|
|
34
|
+
|
|
35
|
+
Coco is built for two related jobs:
|
|
36
|
+
|
|
37
|
+
- A terminal-first coding agent that can work inside real repositories.
|
|
38
|
+
- A reusable agent runtime for building future assistants and business automation without depending on the interactive CLI.
|
|
39
|
+
|
|
40
|
+
That runtime boundary is intentionally practical: provider selection, model turns, tool registration, permission policy, runtime sessions, event logs, workflow metadata, and replay hooks live behind reusable APIs. The CLI is the first product built on that foundation, not the only surface it can support.
|
|
41
|
+
|
|
42
|
+
## See Coco In Action
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
coco "/plan add validation for the provider config parser"
|
|
46
|
+
# Coco inspects the repo with read-only tools and returns a plan.
|
|
47
|
+
|
|
48
|
+
coco "implement the plan and run the relevant tests"
|
|
49
|
+
# Coco edits files, runs checks, reviews failures, and summarizes the diff.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Typical final output includes changed files, checks run, risks, and next steps. For runtime embedding, see the web assistant and RAG examples below.
|
|
53
|
+
|
|
54
|
+
## Built For Two Use Cases
|
|
55
|
+
|
|
56
|
+
### For Developers
|
|
57
|
+
|
|
58
|
+
Use Coco as a coding agent that can inspect an existing repo, plan changes, edit files, run checks, review diffs, and iterate toward a passing result.
|
|
59
|
+
|
|
60
|
+
### For Teams And Products
|
|
61
|
+
|
|
62
|
+
Use Coco Runtime as a base for custom agents: internal assistants, support copilots, operations workflows, sales/product assistants, documentation agents, or client-specific automation. These products can use Coco's runtime without exposing shell, filesystem, git, or publishing tools unless you explicitly register them.
|
|
63
|
+
|
|
30
64
|
## What Coco Does
|
|
31
65
|
|
|
66
|
+
**Coding Agent**
|
|
67
|
+
|
|
32
68
|
- Multi-step execution in one run: explore -> implement -> test -> refine.
|
|
33
69
|
- Quality mode with convergence scoring (configurable threshold and max iterations).
|
|
34
|
-
- Native tool use
|
|
35
|
-
- Multi-provider support (API, subscription, and local models).
|
|
70
|
+
- Native tool use for files, git, shell, search/web, review, diff, build/test, and MCP servers.
|
|
36
71
|
- Session-oriented REPL with slash commands, context compaction, and resumable workflows.
|
|
37
|
-
|
|
38
|
-
-
|
|
72
|
+
|
|
73
|
+
**Multi-provider Runtime**
|
|
74
|
+
|
|
75
|
+
- Provider support across API, subscription-backed, OpenAI-compatible, and local models.
|
|
76
|
+
- Runtime APIs for sessions, model turns, tool registration, permission policy, events, and workflow metadata.
|
|
77
|
+
- Reusable foundation for Coco-powered agents beyond the CLI.
|
|
78
|
+
|
|
79
|
+
**Reliability And Safety**
|
|
80
|
+
|
|
81
|
+
- Provider retry/circuit-breaker support for long sessions.
|
|
82
|
+
- Robust tool-call parsing and safer stream error handling.
|
|
83
|
+
- Strict read-only planning mode by default.
|
|
84
|
+
|
|
85
|
+
**Extensibility**
|
|
86
|
+
|
|
87
|
+
- MCP support for external tools and services.
|
|
88
|
+
- Skills for project-specific workflows and agent interoperability.
|
|
39
89
|
- Replay harness support to reproduce agent-loop behaviors from fixtures for regression testing.
|
|
40
90
|
|
|
41
91
|
Coco is designed to be useful on medium and large repos, not only toy examples.
|
|
@@ -91,6 +141,87 @@ On first run, Coco guides provider/model setup.
|
|
|
91
141
|
|
|
92
142
|
Quality mode is configurable and can be turned on/off per session.
|
|
93
143
|
|
|
144
|
+
## Runtime Reuse
|
|
145
|
+
|
|
146
|
+
Coco's CLI runs on a reusable agent runtime that wires providers, tools, permissions, sessions, event logs, and workflow metadata behind a stable internal boundary. This keeps the programming CLI as the main product while making the same foundation reusable for future client-specific agents.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { createAgentRuntime, ToolRegistry } from "@corbat-tech/coco";
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Runtime consumers can create their own backend, register only the tools they trust, and use Coco for model/provider orchestration, session state, permissions, event logging, and workflow execution.
|
|
153
|
+
|
|
154
|
+
- [Runtime Architecture](docs/architecture/RUNTIME.md)
|
|
155
|
+
- [Platform Layers](docs/architecture/PLATFORM_LAYERS.md)
|
|
156
|
+
- [Public API v0](docs/PUBLIC_API_V0.md)
|
|
157
|
+
- [Product Family](docs/PRODUCT_FAMILY.md)
|
|
158
|
+
- [Build Custom Agents](docs/guides/BUILD_CUSTOM_AGENTS.md)
|
|
159
|
+
- [Support/RAG Assistant](docs/guides/SUPPORT_RAG_ASSISTANT.md)
|
|
160
|
+
- [Web Assistant Runtime Example](examples/web-assistant-runtime/README.md)
|
|
161
|
+
|
|
162
|
+
Subpath imports are available for embedders:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { createAgentRuntime } from "@corbat-tech/coco/runtime";
|
|
166
|
+
import { createSupportRagToolRegistry } from "@corbat-tech/coco/tools";
|
|
167
|
+
import { supportRagAssistantPreset } from "@corbat-tech/coco/presets";
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## What Coco Adds To Business Agents
|
|
171
|
+
|
|
172
|
+
Coco does not replace your business systems. It gives you a reusable agent layer
|
|
173
|
+
that connects models, tools, permissions, sessions, guardrails, and logs in the
|
|
174
|
+
same way across channels.
|
|
175
|
+
|
|
176
|
+
For example, in a RAG assistant:
|
|
177
|
+
|
|
178
|
+
```txt
|
|
179
|
+
Google Drive / Notion / PDFs / website docs
|
|
180
|
+
-> your retriever or vector database
|
|
181
|
+
-> Coco Runtime
|
|
182
|
+
-> selected model
|
|
183
|
+
-> answer with sources, policy, session, and event logs
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The retriever still owns document indexing and search. Coco standardizes how the
|
|
187
|
+
agent uses that search safely: answer from approved knowledge, cite sources, say
|
|
188
|
+
"I don't know" when retrieval is weak, avoid dangerous tools, and record what
|
|
189
|
+
happened. The same runtime pattern can then be reused for a website widget,
|
|
190
|
+
WhatsApp assistant, customer-support draft flow, appointment assistant, or
|
|
191
|
+
internal operations agent.
|
|
192
|
+
|
|
193
|
+
## Runtime Maturity
|
|
194
|
+
|
|
195
|
+
| Surface | Status | Notes |
|
|
196
|
+
|---------|--------|-------|
|
|
197
|
+
| Coco CLI | Beta | Main product surface, used for coding-agent workflows. |
|
|
198
|
+
| Runtime APIs | Beta | Exported from `@corbat-tech/coco`; package split is planned later. |
|
|
199
|
+
| Agent presets | Experimental | Safe defaults for public web, RAG, sales, support, appointments, internal ops, and coding. |
|
|
200
|
+
| Adapters | Experimental | HTTP, streaming HTTP, and webhook-style adapter shapes. |
|
|
201
|
+
|
|
202
|
+
## Example: Web Assistant Runtime
|
|
203
|
+
|
|
204
|
+
For a website such as `corbat.tech`, the web app should own authentication, users, tenants, UI, and HTTP streaming. Coco Runtime should sit behind that app and own provider selection, model turns, session state, permission checks, tool registration, and event logs.
|
|
205
|
+
|
|
206
|
+
The recommended pattern is:
|
|
207
|
+
|
|
208
|
+
1. Build a small authenticated backend endpoint for the website chat.
|
|
209
|
+
2. Create a Coco runtime instance in that backend.
|
|
210
|
+
3. Register only narrow, domain-specific tools such as public-doc search, service listing, project-scope estimation, or lead-draft creation.
|
|
211
|
+
4. Stream runtime responses back to the frontend.
|
|
212
|
+
|
|
213
|
+
Do not reuse Coco's full coding-agent tool registry in a public web assistant. Shell access, arbitrary filesystem operations, git writes, deployment, package publishing, secrets, and private customer data should stay unavailable unless a product-specific backend explicitly gates them.
|
|
214
|
+
|
|
215
|
+
See [examples/web-assistant-runtime](examples/web-assistant-runtime/README.md) for a concrete embedding sketch.
|
|
216
|
+
|
|
217
|
+
## Why Coco vs Other Coding Agents?
|
|
218
|
+
|
|
219
|
+
- **Reusable runtime underneath the CLI:** Coco can power coding workflows and future custom assistants.
|
|
220
|
+
- **Multi-provider by design:** API, subscription-backed, OpenAI-compatible, and local models can share runtime policy.
|
|
221
|
+
- **Permission-first tooling:** public presets default to no tools; coding tools stay in trusted developer contexts.
|
|
222
|
+
- **Interop-friendly:** skills and MCP configuration can reuse existing agent ecosystem conventions.
|
|
223
|
+
- **Replay and release gates:** quality and provider behavior can be tested through replay fixtures and release checks.
|
|
224
|
+
|
|
94
225
|
## Reliability and Quality
|
|
95
226
|
|
|
96
227
|
- Provider calls use retry and circuit-breaker protection by default (can be disabled with `COCO_PROVIDER_RESILIENCE=0`).
|
|
@@ -156,12 +287,6 @@ For setup details and model matrix:
|
|
|
156
287
|
|
|
157
288
|
- [Provider Guide](docs/guides/PROVIDERS.md)
|
|
158
289
|
|
|
159
|
-
## Runtime Reuse
|
|
160
|
-
|
|
161
|
-
Coco's CLI runs on a reusable agent runtime that wires providers, tools, permissions, sessions, event logs, and workflow metadata behind a stable internal boundary. This keeps the programming CLI as the main product while making the same foundation reusable for future client-specific agents.
|
|
162
|
-
|
|
163
|
-
- [Runtime Architecture](docs/architecture/RUNTIME.md)
|
|
164
|
-
|
|
165
290
|
## Skills
|
|
166
291
|
|
|
167
292
|
Skills are instruction files (SKILL.md) that Coco injects into its context to follow project-specific conventions or workflows. They activate automatically by context or manually via `/skill-name`.
|
|
@@ -283,6 +408,13 @@ See:
|
|
|
283
408
|
- [Quality Guide](docs/guides/QUALITY.md)
|
|
284
409
|
- [Providers](docs/guides/PROVIDERS.md)
|
|
285
410
|
- [Architecture](docs/architecture/ARCHITECTURE.md)
|
|
411
|
+
- [Platform Layers](docs/architecture/PLATFORM_LAYERS.md)
|
|
412
|
+
- [Build Custom Agents](docs/guides/BUILD_CUSTOM_AGENTS.md)
|
|
413
|
+
- [Public Assistant Runtime](docs/guides/PUBLIC_ASSISTANT_RUNTIME.md)
|
|
414
|
+
- [RAG Assistant](docs/guides/RAG_ASSISTANT.md)
|
|
415
|
+
- [WhatsApp Assistant](docs/guides/WHATSAPP_ASSISTANT.md)
|
|
416
|
+
- [Security For Public Agents](docs/guides/SECURITY_FOR_PUBLIC_AGENTS.md)
|
|
417
|
+
- [Client Agent Integration](docs/guides/CLIENT_AGENT_INTEGRATION.md)
|
|
286
418
|
- [Troubleshooting](docs/guides/TROUBLESHOOTING.md)
|
|
287
419
|
- [Release Workflow](docs/RELEASE_WORKFLOW.md)
|
|
288
420
|
|
|
@@ -325,6 +457,10 @@ Coco sends prompts and selected context to the configured provider.
|
|
|
325
457
|
- Provider-side data handling depends on each provider policy.
|
|
326
458
|
- Local providers (`ollama`, `lmstudio`) keep inference on your machine.
|
|
327
459
|
|
|
460
|
+
## Built By Corbat
|
|
461
|
+
|
|
462
|
+
Coco is developed by [Corbat](https://corbat.tech) as an open-source foundation for coding automation and custom AI agents.
|
|
463
|
+
|
|
328
464
|
## Contributing
|
|
329
465
|
|
|
330
466
|
- [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { W as RuntimeTurnStreamEvent, t as AgentRuntime } from '../agent-runtime-DeLcB0Ie.js';
|
|
2
|
+
import '../registry-CEpl9Jq0.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
interface ChannelInput {
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
content: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
metadata?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
interface ChannelOutput {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
content: string;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
interface ChannelAdapter {
|
|
17
|
+
id: string;
|
|
18
|
+
surface: "web" | "whatsapp" | "slack" | "api" | "internal";
|
|
19
|
+
handle(input: ChannelInput): Promise<ChannelOutput>;
|
|
20
|
+
}
|
|
21
|
+
interface HttpAssistantAdapter {
|
|
22
|
+
createSession(metadata?: Record<string, unknown>): {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
};
|
|
25
|
+
handleMessage(input: ChannelInput): Promise<ChannelOutput>;
|
|
26
|
+
}
|
|
27
|
+
interface StreamingHttpAssistantAdapter extends HttpAssistantAdapter {
|
|
28
|
+
streamMessage(input: ChannelInput): AsyncIterable<RuntimeTurnStreamEvent>;
|
|
29
|
+
}
|
|
30
|
+
declare function createHttpAssistantAdapter(runtime: AgentRuntime): HttpAssistantAdapter;
|
|
31
|
+
declare function createStreamingHttpAssistantAdapter(runtime: AgentRuntime): StreamingHttpAssistantAdapter;
|
|
32
|
+
declare function createWebhookAssistantAdapter(runtime: AgentRuntime, options?: {
|
|
33
|
+
id?: string;
|
|
34
|
+
surface?: ChannelAdapter["surface"];
|
|
35
|
+
}): ChannelAdapter;
|
|
36
|
+
|
|
37
|
+
export { type ChannelAdapter, type ChannelInput, type ChannelOutput, type HttpAssistantAdapter, type StreamingHttpAssistantAdapter, createHttpAssistantAdapter, createStreamingHttpAssistantAdapter, createWebhookAssistantAdapter };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/adapters/index.ts
|
|
2
|
+
function createHttpAssistantAdapter(runtime) {
|
|
3
|
+
return {
|
|
4
|
+
createSession(metadata = {}) {
|
|
5
|
+
const session = runtime.createSession({ mode: "ask", metadata });
|
|
6
|
+
return { sessionId: session.id };
|
|
7
|
+
},
|
|
8
|
+
async handleMessage(input) {
|
|
9
|
+
const sessionId = input.sessionId ?? runtime.createSession({ mode: "ask", metadata: input.metadata }).id;
|
|
10
|
+
const result = await runtime.runTurn({
|
|
11
|
+
sessionId,
|
|
12
|
+
content: input.content,
|
|
13
|
+
metadata: input.metadata
|
|
14
|
+
});
|
|
15
|
+
return { sessionId, content: result.content, metadata: { model: result.model } };
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createStreamingHttpAssistantAdapter(runtime) {
|
|
20
|
+
const base = createHttpAssistantAdapter(runtime);
|
|
21
|
+
return {
|
|
22
|
+
...base,
|
|
23
|
+
async *streamMessage(input) {
|
|
24
|
+
const sessionId = input.sessionId ?? runtime.createSession({ mode: "ask", metadata: input.metadata }).id;
|
|
25
|
+
yield* runtime.streamTurn({
|
|
26
|
+
sessionId,
|
|
27
|
+
content: input.content,
|
|
28
|
+
metadata: input.metadata
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function createWebhookAssistantAdapter(runtime, options = {}) {
|
|
34
|
+
return {
|
|
35
|
+
id: options.id ?? "webhook-assistant",
|
|
36
|
+
surface: options.surface ?? "api",
|
|
37
|
+
async handle(input) {
|
|
38
|
+
const adapter = createHttpAssistantAdapter(runtime);
|
|
39
|
+
return adapter.handleMessage(input);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { createHttpAssistantAdapter, createStreamingHttpAssistantAdapter, createWebhookAssistantAdapter };
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/index.ts"],"names":[],"mappings":";AA+BO,SAAS,2BAA2B,OAAA,EAA6C;AACtF,EAAA,OAAO;AAAA,IACL,aAAA,CAAc,QAAA,GAAW,EAAC,EAAG;AAC3B,MAAA,MAAM,UAAU,OAAA,CAAQ,aAAA,CAAc,EAAE,IAAA,EAAM,KAAA,EAAO,UAAU,CAAA;AAC/D,MAAA,OAAO,EAAE,SAAA,EAAW,OAAA,CAAQ,EAAA,EAAG;AAAA,IACjC,CAAA;AAAA,IACA,MAAM,cAAc,KAAA,EAAO;AACzB,MAAA,MAAM,SAAA,GACJ,KAAA,CAAM,SAAA,IAAa,OAAA,CAAQ,aAAA,CAAc,EAAE,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,KAAA,CAAM,QAAA,EAAU,CAAA,CAAE,EAAA;AACtF,MAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,OAAA,CAAQ;AAAA,QACnC,SAAA;AAAA,QACA,SAAS,KAAA,CAAM,OAAA;AAAA,QACf,UAAU,KAAA,CAAM;AAAA,OACjB,CAAA;AACD,MAAA,OAAO,EAAE,SAAA,EAAW,OAAA,EAAS,MAAA,CAAO,OAAA,EAAS,UAAU,EAAE,KAAA,EAAO,MAAA,CAAO,KAAA,EAAM,EAAE;AAAA,IACjF;AAAA,GACF;AACF;AAEO,SAAS,oCACd,OAAA,EAC+B;AAC/B,EAAA,MAAM,IAAA,GAAO,2BAA2B,OAAO,CAAA;AAC/C,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,OAAO,cAAc,KAAA,EAAO;AAC1B,MAAA,MAAM,SAAA,GACJ,KAAA,CAAM,SAAA,IAAa,OAAA,CAAQ,aAAA,CAAc,EAAE,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,KAAA,CAAM,QAAA,EAAU,CAAA,CAAE,EAAA;AACtF,MAAA,OAAO,QAAQ,UAAA,CAAW;AAAA,QACxB,SAAA;AAAA,QACA,SAAS,KAAA,CAAM,OAAA;AAAA,QACf,UAAU,KAAA,CAAM;AAAA,OACjB,CAAA;AAAA,IACH;AAAA,GACF;AACF;AAEO,SAAS,6BAAA,CACd,OAAA,EACA,OAAA,GAAgE,EAAC,EACjD;AAChB,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,QAAQ,EAAA,IAAM,mBAAA;AAAA,IAClB,OAAA,EAAS,QAAQ,OAAA,IAAW,KAAA;AAAA,IAC5B,MAAM,OAAO,KAAA,EAAO;AAClB,MAAA,MAAM,OAAA,GAAU,2BAA2B,OAAO,CAAA;AAClD,MAAA,OAAO,OAAA,CAAQ,cAAc,KAAK,CAAA;AAAA,IACpC;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { AgentRuntime } from \"../runtime/agent-runtime.js\";\nimport type { RuntimeTurnStreamEvent } from \"../runtime/types.js\";\n\nexport interface ChannelInput {\n sessionId?: string;\n content: string;\n userId?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface ChannelOutput {\n sessionId: string;\n content: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface ChannelAdapter {\n id: string;\n surface: \"web\" | \"whatsapp\" | \"slack\" | \"api\" | \"internal\";\n handle(input: ChannelInput): Promise<ChannelOutput>;\n}\n\nexport interface HttpAssistantAdapter {\n createSession(metadata?: Record<string, unknown>): { sessionId: string };\n handleMessage(input: ChannelInput): Promise<ChannelOutput>;\n}\n\nexport interface StreamingHttpAssistantAdapter extends HttpAssistantAdapter {\n streamMessage(input: ChannelInput): AsyncIterable<RuntimeTurnStreamEvent>;\n}\n\nexport function createHttpAssistantAdapter(runtime: AgentRuntime): HttpAssistantAdapter {\n return {\n createSession(metadata = {}) {\n const session = runtime.createSession({ mode: \"ask\", metadata });\n return { sessionId: session.id };\n },\n async handleMessage(input) {\n const sessionId =\n input.sessionId ?? runtime.createSession({ mode: \"ask\", metadata: input.metadata }).id;\n const result = await runtime.runTurn({\n sessionId,\n content: input.content,\n metadata: input.metadata,\n });\n return { sessionId, content: result.content, metadata: { model: result.model } };\n },\n };\n}\n\nexport function createStreamingHttpAssistantAdapter(\n runtime: AgentRuntime,\n): StreamingHttpAssistantAdapter {\n const base = createHttpAssistantAdapter(runtime);\n return {\n ...base,\n async *streamMessage(input) {\n const sessionId =\n input.sessionId ?? runtime.createSession({ mode: \"ask\", metadata: input.metadata }).id;\n yield* runtime.streamTurn({\n sessionId,\n content: input.content,\n metadata: input.metadata,\n });\n },\n };\n}\n\nexport function createWebhookAssistantAdapter(\n runtime: AgentRuntime,\n options: { id?: string; surface?: ChannelAdapter[\"surface\"] } = {},\n): ChannelAdapter {\n return {\n id: options.id ?? \"webhook-assistant\",\n surface: options.surface ?? \"api\",\n async handle(input) {\n const adapter = createHttpAssistantAdapter(runtime);\n return adapter.handleMessage(input);\n },\n };\n}\n"]}
|