@celljs/ai-coding-agent 0.0.0-stage → 4.1.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 +225 -2
- package/cell.yml +16 -0
- package/esm/node/application-lifecycle.d.ts +7 -0
- package/esm/node/application-lifecycle.js +25 -0
- package/esm/node/application-lifecycle.js.map +1 -0
- package/esm/node/coding-agent-protocol.d.ts +92 -0
- package/esm/node/coding-agent-protocol.js +8 -0
- package/esm/node/coding-agent-protocol.js.map +1 -0
- package/esm/node/error/errors.d.ts +22 -0
- package/esm/node/error/errors.js +25 -0
- package/esm/node/error/errors.js.map +1 -0
- package/esm/node/error/index.d.ts +1 -0
- package/esm/node/error/index.js +2 -0
- package/esm/node/error/index.js.map +1 -0
- package/esm/node/event/agent-event-util.d.ts +1 -0
- package/esm/node/event/agent-event-util.js +3 -0
- package/esm/node/event/agent-event-util.js.map +1 -0
- package/esm/node/event/index.d.ts +1 -0
- package/esm/node/event/index.js +2 -0
- package/esm/node/event/index.js.map +1 -0
- package/esm/node/index.d.ts +8 -0
- package/esm/node/index.js +10 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/pi/index.d.ts +2 -0
- package/esm/node/pi/index.js +3 -0
- package/esm/node/pi/index.js.map +1 -0
- package/esm/node/pi/pi-sdk-util.d.ts +9 -0
- package/esm/node/pi/pi-sdk-util.js +20 -0
- package/esm/node/pi/pi-sdk-util.js.map +1 -0
- package/esm/node/pi/pi-types.d.ts +10 -0
- package/esm/node/pi/pi-types.js +2 -0
- package/esm/node/pi/pi-types.js.map +1 -0
- package/esm/node/runtime/index.d.ts +1 -0
- package/esm/node/runtime/index.js +2 -0
- package/esm/node/runtime/index.js.map +1 -0
- package/esm/node/runtime/model-runtime-provider.d.ts +11 -0
- package/esm/node/runtime/model-runtime-provider.js +67 -0
- package/esm/node/runtime/model-runtime-provider.js.map +1 -0
- package/esm/node/session/agent-session-factory.d.ts +23 -0
- package/esm/node/session/agent-session-factory.js +178 -0
- package/esm/node/session/agent-session-factory.js.map +1 -0
- package/esm/node/session/agent-session-manager.d.ts +16 -0
- package/esm/node/session/agent-session-manager.js +72 -0
- package/esm/node/session/agent-session-manager.js.map +1 -0
- package/esm/node/session/index.d.ts +2 -0
- package/esm/node/session/index.js +3 -0
- package/esm/node/session/index.js.map +1 -0
- package/esm/node/test/faux-models.d.ts +28 -0
- package/esm/node/test/faux-models.js +39 -0
- package/esm/node/test/faux-models.js.map +1 -0
- package/esm/node/test/index.d.ts +2 -0
- package/esm/node/test/index.js +3 -0
- package/esm/node/test/index.js.map +1 -0
- package/esm/node/test/test-container.d.ts +18 -0
- package/esm/node/test/test-container.js +25 -0
- package/esm/node/test/test-container.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/application-lifecycle.d.ts +8 -0
- package/lib/node/application-lifecycle.d.ts.map +1 -0
- package/lib/node/application-lifecycle.js +28 -0
- package/lib/node/application-lifecycle.js.map +1 -0
- package/lib/node/coding-agent-protocol.d.ts +93 -0
- package/lib/node/coding-agent-protocol.d.ts.map +1 -0
- package/lib/node/coding-agent-protocol.js +11 -0
- package/lib/node/coding-agent-protocol.js.map +1 -0
- package/lib/node/error/errors.d.ts +23 -0
- package/lib/node/error/errors.d.ts.map +1 -0
- package/lib/node/error/errors.js +32 -0
- package/lib/node/error/errors.js.map +1 -0
- package/lib/node/error/index.d.ts +2 -0
- package/lib/node/error/index.d.ts.map +1 -0
- package/lib/node/error/index.js +18 -0
- package/lib/node/error/index.js.map +1 -0
- package/lib/node/event/agent-event-util.d.ts +2 -0
- package/lib/node/event/agent-event-util.d.ts.map +1 -0
- package/lib/node/event/agent-event-util.js +7 -0
- package/lib/node/event/agent-event-util.js.map +1 -0
- package/lib/node/event/agent-event-util.spec.d.ts +2 -0
- package/lib/node/event/agent-event-util.spec.d.ts.map +1 -0
- package/lib/node/event/agent-event-util.spec.js +85 -0
- package/lib/node/event/agent-event-util.spec.js.map +1 -0
- package/lib/node/event/index.d.ts +2 -0
- package/lib/node/event/index.d.ts.map +1 -0
- package/lib/node/event/index.js +18 -0
- package/lib/node/event/index.js.map +1 -0
- package/lib/node/index.d.ts +9 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +28 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/pi/index.d.ts +3 -0
- package/lib/node/pi/index.d.ts.map +1 -0
- package/lib/node/pi/index.js +19 -0
- package/lib/node/pi/index.js.map +1 -0
- package/lib/node/pi/pi-sdk-util.d.ts +10 -0
- package/lib/node/pi/pi-sdk-util.d.ts.map +1 -0
- package/lib/node/pi/pi-sdk-util.js +23 -0
- package/lib/node/pi/pi-sdk-util.js.map +1 -0
- package/lib/node/pi/pi-types.d.ts +11 -0
- package/lib/node/pi/pi-types.d.ts.map +1 -0
- package/lib/node/pi/pi-types.js +3 -0
- package/lib/node/pi/pi-types.js.map +1 -0
- package/lib/node/runtime/index.d.ts +2 -0
- package/lib/node/runtime/index.d.ts.map +1 -0
- package/lib/node/runtime/index.js +18 -0
- package/lib/node/runtime/index.js.map +1 -0
- package/lib/node/runtime/model-runtime-provider.d.ts +12 -0
- package/lib/node/runtime/model-runtime-provider.d.ts.map +1 -0
- package/lib/node/runtime/model-runtime-provider.js +70 -0
- package/lib/node/runtime/model-runtime-provider.js.map +1 -0
- package/lib/node/session/agent-session-builtins.spec.d.ts +2 -0
- package/lib/node/session/agent-session-builtins.spec.d.ts.map +1 -0
- package/lib/node/session/agent-session-builtins.spec.js +55 -0
- package/lib/node/session/agent-session-builtins.spec.js.map +1 -0
- package/lib/node/session/agent-session-factory.d.ts +24 -0
- package/lib/node/session/agent-session-factory.d.ts.map +1 -0
- package/lib/node/session/agent-session-factory.js +181 -0
- package/lib/node/session/agent-session-factory.js.map +1 -0
- package/lib/node/session/agent-session-manager.d.ts +17 -0
- package/lib/node/session/agent-session-manager.d.ts.map +1 -0
- package/lib/node/session/agent-session-manager.js +75 -0
- package/lib/node/session/agent-session-manager.js.map +1 -0
- package/lib/node/session/agent-session-manager.spec.d.ts +33 -0
- package/lib/node/session/agent-session-manager.spec.d.ts.map +1 -0
- package/lib/node/session/agent-session-manager.spec.js +203 -0
- package/lib/node/session/agent-session-manager.spec.js.map +1 -0
- package/lib/node/session/index.d.ts +3 -0
- package/lib/node/session/index.d.ts.map +1 -0
- package/lib/node/session/index.js +19 -0
- package/lib/node/session/index.js.map +1 -0
- package/lib/node/test/faux-models.d.ts +29 -0
- package/lib/node/test/faux-models.d.ts.map +1 -0
- package/lib/node/test/faux-models.js +43 -0
- package/lib/node/test/faux-models.js.map +1 -0
- package/lib/node/test/index.d.ts +3 -0
- package/lib/node/test/index.d.ts.map +1 -0
- package/lib/node/test/index.js +19 -0
- package/lib/node/test/index.js.map +1 -0
- package/lib/node/test/test-container.d.ts +19 -0
- package/lib/node/test/test-container.d.ts.map +1 -0
- package/lib/node/test/test-container.js +28 -0
- package/lib/node/test/test-container.js.map +1 -0
- package/package.json +96 -4
- package/src/node/application-lifecycle.ts +13 -0
- package/src/node/coding-agent-protocol.ts +106 -0
- package/src/node/error/errors.ts +32 -0
- package/src/node/error/index.ts +1 -0
- package/src/node/event/agent-event-util.spec.ts +95 -0
- package/src/node/event/agent-event-util.ts +2 -0
- package/src/node/event/index.ts +1 -0
- package/src/node/index.ts +9 -0
- package/src/node/module.ts +4 -0
- package/src/node/pi/index.ts +2 -0
- package/src/node/pi/pi-sdk-util.ts +25 -0
- package/src/node/pi/pi-types.ts +12 -0
- package/src/node/runtime/index.ts +1 -0
- package/src/node/runtime/model-runtime-provider.ts +50 -0
- package/src/node/session/agent-session-builtins.spec.ts +59 -0
- package/src/node/session/agent-session-factory.ts +175 -0
- package/src/node/session/agent-session-manager.spec.ts +198 -0
- package/src/node/session/agent-session-manager.ts +64 -0
- package/src/node/session/index.ts +2 -0
- package/src/node/test/faux-models.ts +54 -0
- package/src/node/test/index.ts +2 -0
- package/src/node/test/test-container.ts +36 -0
package/README.md
CHANGED
|
@@ -1,3 +1,226 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cell - AI Coding Agent Component
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在 Cell 应用里运行 [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) coding agent 的会话。pi 负责模型调用、工具(read、bash、edit、write 等)、会话与上下文压缩;本组件把它接进 Cell:
|
|
4
|
+
|
|
5
|
+
- 会话和模型运行时由 DI 容器管理,应用停止时自动释放会话;
|
|
6
|
+
- 配置写在 `cell.yml` 的 `cell.ai.codingAgent` 下,选项名与 pi 的 `createAgentSession()` 一致;
|
|
7
|
+
- 工具写成 `AgentTool` 组件(与 @celljs/ai-agent 共用),pi 扩展写成 `AgentExtension` 组件,都可以直接用注入的服务;
|
|
8
|
+
- 按配置启用 pi 的 MCP 客户端、codemode 和 tool_search;
|
|
9
|
+
- 事件按 pi JSON/RPC 模式的格式输出,可直接作为 Server-Sent Events 返回给前端。
|
|
10
|
+
|
|
11
|
+
## 要求
|
|
12
|
+
|
|
13
|
+
Node.js >= 22.19 或 Bun(pi 的要求)。pi 是 ES module 包,本组件用动态 `import()` 加载它,CommonJS 和 ESM 两种构建都可用,只在第一次创建会话时加载。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @celljs/ai-coding-agent
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 配置
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
cell:
|
|
25
|
+
ai:
|
|
26
|
+
codingAgent:
|
|
27
|
+
cwd: /srv/repo # 会话的工作目录,工具在这里读写;默认进程当前目录
|
|
28
|
+
model: anthropic/claude-sonnet-4-5 # <provider>/<model id>;默认取 pi 的设置,再取第一个有凭据的模型
|
|
29
|
+
thinkingLevel: medium
|
|
30
|
+
tools: [read, grep, find, ls] # 工具白名单,支持 *;默认 read、bash、edit、write 加扩展注册的工具
|
|
31
|
+
appendSystemPrompt: Answer in Chinese.
|
|
32
|
+
apiKeys: # 只放进内存,不写 pi 的 auth.json
|
|
33
|
+
anthropic: "${ env.MY_ANTHROPIC_KEY }"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| 配置 | 默认 | 说明 |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `cwd` | 进程当前目录 | 会话工作目录,也是发现项目资源(AGENTS.md、`.pi/`)的位置 |
|
|
39
|
+
| `agentDir` | `~/.pi/agent` | pi 的全局目录:auth.json、models.json、settings.json、扩展、技能 |
|
|
40
|
+
| `model` / `thinkingLevel` | pi 的设置 | 模型写成 `<provider>/<model id>`,找不到时报 `AgentModelNotFoundError` 并列出可用模型 |
|
|
41
|
+
| `tools` / `excludeTools` | pi 的默认工具 | 白名单 / 黑名单 |
|
|
42
|
+
| `systemPrompt` / `appendSystemPrompt` | — | 替换 / 追加系统提示词 |
|
|
43
|
+
| `discoverResources` | `true` | 像 pi CLI 一样从 cwd 和 agentDir 加载扩展、技能、提示词模板和 AGENTS.md |
|
|
44
|
+
| `persistSessions` | `false` | 同时把会话写成 pi CLI 的 JSONL 文件,`pi --resume` 能看到 |
|
|
45
|
+
| `allowModelNetwork` | `false` | 创建模型运行时时是否联网刷新模型目录 |
|
|
46
|
+
| `mcp.enabled` / `mcp.servers` | `false` / — | 启用 pi 的 MCP 客户端:连接 agentDir(以及受信任项目)`mcp.json` 里的服务器,再加上 `servers`(格式同 `mcpServers`) |
|
|
47
|
+
| `codemode` | `off` | `on` / `only`:模型写 JavaScript,在沙箱里调用工具 |
|
|
48
|
+
| `toolSearch` | `false` | 启用 `tool_search`,让模型查找未声明的工具 |
|
|
49
|
+
| `apiKeys` | — | 按 provider 设置 API key,空值忽略;`cell.ai.pi.apiKeys`(@celljs/ai-pi)也用于会话,这里的同名项优先;pi 也会读 `ANTHROPIC_API_KEY` 等环境变量 |
|
|
50
|
+
|
|
51
|
+
## 使用
|
|
52
|
+
|
|
53
|
+
### 创建会话并提问
|
|
54
|
+
|
|
55
|
+
`AgentSessionManager.create()` 返回 pi 的 `AgentSession`,之后直接用 pi 的 API(`prompt`、`steer`、`followUp`、`abort`、`subscribe`、`messages` ……):
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Autowired, Component } from '@celljs/core';
|
|
59
|
+
import { AgentSessionManager } from '@celljs/ai-coding-agent';
|
|
60
|
+
|
|
61
|
+
@Component()
|
|
62
|
+
export class ReviewService {
|
|
63
|
+
|
|
64
|
+
@Autowired(AgentSessionManager)
|
|
65
|
+
protected readonly sessionManager: AgentSessionManager;
|
|
66
|
+
|
|
67
|
+
async review(): Promise<string | undefined> {
|
|
68
|
+
const session = await this.sessionManager.create({ tools: [ 'read', 'grep', 'find', 'ls' ] });
|
|
69
|
+
try {
|
|
70
|
+
await session.prompt('Review the changes in src/ and list the risks.');
|
|
71
|
+
return session.getLastAssistantText();
|
|
72
|
+
} finally {
|
|
73
|
+
this.sessionManager.dispose(session.sessionId);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`create()` 的参数(`cwd`、`model`、`thinkingLevel`、`tools`、`excludeTools`、`systemPrompt`、`appendSystemPrompt`)覆盖 `cell.ai.codingAgent` 中的同名配置。会话按 pi 的 `sessionId` 保存在内存里:`get(id)`(不存在时抛 `AgentSessionNotFoundError`)、`find(id)`、`info(id)`、`list()`、`dispose(id)`。
|
|
80
|
+
|
|
81
|
+
### 用 Cell 组件写工具
|
|
82
|
+
|
|
83
|
+
工具写成 [@celljs/ai-agent](../ai-agent) 的 `AgentTool` 组件(本包也导出 `AgentTool`),工具里可以直接用注入的服务;同一个组件既是编码会话的工具,也是 `AgentFactory` 创建的通用 agent 的工具:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { AgentTool } from '@celljs/ai-coding-agent';
|
|
87
|
+
import { Autowired, Component } from '@celljs/core';
|
|
88
|
+
import { TicketService } from './ticket-service';
|
|
89
|
+
|
|
90
|
+
@Component(AgentTool)
|
|
91
|
+
export class CreateTicketTool implements AgentTool {
|
|
92
|
+
readonly name = 'create_ticket';
|
|
93
|
+
readonly label = 'Create ticket';
|
|
94
|
+
readonly description = 'Creates a ticket in the issue tracker.';
|
|
95
|
+
readonly parameters = { type: 'object', properties: { title: { type: 'string' } }, required: [ 'title' ] };
|
|
96
|
+
|
|
97
|
+
@Autowired(TicketService)
|
|
98
|
+
protected readonly ticketService: TicketService;
|
|
99
|
+
|
|
100
|
+
async execute(_toolCallId: string, params: any) {
|
|
101
|
+
const ticket = await this.ticketService.create(params.title);
|
|
102
|
+
return { content: [ { type: 'text' as const, text: `Created ${ticket.id}` } ], details: {} };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`parameters` 是 JSON Schema;工具失败时抛异常。配置了 `tools` 白名单时,工具名要列进去。
|
|
108
|
+
|
|
109
|
+
### 用 Cell 组件写 pi 扩展
|
|
110
|
+
|
|
111
|
+
工具以外的扩展能力(命令、事件处理器、拦截工具调用、注册 MCP 服务器等,见 pi 文档 `docs/extensions.md`)写成 `AgentExtension`,`register` 在每个新会话里拿到 pi 的 `ExtensionAPI`:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { AgentExtension, type ExtensionAPI } from '@celljs/ai-coding-agent';
|
|
115
|
+
import { Autowired, Component, Logger } from '@celljs/core';
|
|
116
|
+
|
|
117
|
+
@Component(AgentExtension)
|
|
118
|
+
export class AuditExtension implements AgentExtension {
|
|
119
|
+
|
|
120
|
+
@Autowired(Logger)
|
|
121
|
+
protected readonly logger: Logger;
|
|
122
|
+
|
|
123
|
+
register(pi: ExtensionAPI): void {
|
|
124
|
+
pi.on('tool_call', async event => {
|
|
125
|
+
this.logger.info(`agent calls ${event.toolName}`);
|
|
126
|
+
return event.toolName === 'bash' ? { block: true, reason: 'bash is disabled' } : undefined;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`register` 抛错时创建会话失败,报 `AgentExtensionError`;从磁盘发现的扩展出错只记警告。
|
|
133
|
+
|
|
134
|
+
### MCP、codemode 与 tool_search
|
|
135
|
+
|
|
136
|
+
pi CLI 默认加载这三个扩展,SDK 默认不加载;在配置里打开即可。MCP 服务器的工具名是 `mcp__<服务器>__<工具>`,`exposure: direct` 时直接声明给模型,默认(`codemode`)时只能在 codemode 脚本里调用:
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
cell:
|
|
140
|
+
ai:
|
|
141
|
+
codingAgent:
|
|
142
|
+
codemode: "on"
|
|
143
|
+
mcp:
|
|
144
|
+
enabled: true
|
|
145
|
+
servers:
|
|
146
|
+
docs:
|
|
147
|
+
url: https://example.com/mcp
|
|
148
|
+
headers:
|
|
149
|
+
Authorization: "Bearer ${ env.DOCS_TOKEN }"
|
|
150
|
+
filesystem:
|
|
151
|
+
command: npx
|
|
152
|
+
args: [-y, "@modelcontextprotocol/server-filesystem", "."]
|
|
153
|
+
exposure: direct
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
配置了 `tools` 白名单时,要把 `codemode`、`tool_search` 或 `mcp__*` 也列进去。`AgentExtension` 里也可以用 `pi.registerMcpServer(name, config)` 按需注册服务器。
|
|
157
|
+
|
|
158
|
+
### 以 Server-Sent Events 返回事件
|
|
159
|
+
|
|
160
|
+
`AgentEventUtil.stream(session, response, run)` 在 `run` 执行期间把会话事件写成 SSE,结束后关闭响应;`run` 失败时写一个 `error` 事件:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { AgentEventUtil, AgentSessionManager, type EventStreamResponse } from '@celljs/ai-coding-agent';
|
|
164
|
+
import { Autowired } from '@celljs/core';
|
|
165
|
+
import { Body, Controller, Param, Post, Res } from '@celljs/mvc/lib/node';
|
|
166
|
+
|
|
167
|
+
@Controller('sessions')
|
|
168
|
+
export class AgentController {
|
|
169
|
+
|
|
170
|
+
@Autowired(AgentSessionManager)
|
|
171
|
+
protected readonly sessionManager: AgentSessionManager;
|
|
172
|
+
|
|
173
|
+
@Post(':id/prompt')
|
|
174
|
+
async prompt(@Param('id') id: string, @Body('text') text: string, @Res() response: EventStreamResponse): Promise<void> {
|
|
175
|
+
const session = this.sessionManager.get(id);
|
|
176
|
+
await AgentEventUtil.stream(session, response, () => session.prompt(text));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
每帧是 `event: <type>\ndata: <JSON>`,JSON 与 pi `--mode json` 的事件相同(pi 文档 `docs/json.md`):`message_update` 只带增量和 usage,完整消息在 `message_end` 里,`agent_settled` 表示这轮结束。另有本组件加的 `{ "type": "error", "message": "..." }`。客户端断开不会中止会话,需要时调用 `session.abort()`。完整的增删查、提问、中止接口见 [examples/coding-agent-app](../../examples/coding-agent-app)。
|
|
182
|
+
|
|
183
|
+
### 配置模型运行时
|
|
184
|
+
|
|
185
|
+
所有会话共享一个 pi `ModelRuntime`(`ModelRuntimeProvider`)。要注册自定义 provider、从密钥服务读取凭据,实现 `ModelRuntimeContribution`:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { type ModelRuntime, ModelRuntimeContribution } from '@celljs/ai-coding-agent';
|
|
189
|
+
import { Autowired, Component } from '@celljs/core';
|
|
190
|
+
import { SecretStore } from './secret-store';
|
|
191
|
+
|
|
192
|
+
@Component(ModelRuntimeContribution)
|
|
193
|
+
export class GatewayModels implements ModelRuntimeContribution {
|
|
194
|
+
|
|
195
|
+
@Autowired(SecretStore)
|
|
196
|
+
protected readonly secrets: SecretStore;
|
|
197
|
+
|
|
198
|
+
async configure(runtime: ModelRuntime): Promise<void> {
|
|
199
|
+
await runtime.setRuntimeApiKey('openai', await this.secrets.get('openai'));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## 测试
|
|
205
|
+
|
|
206
|
+
`@celljs/ai-coding-agent/lib/node/test` 提供基于 pi faux provider 的脚本化模型,不联网、不读写 `~/.pi`:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { AgentSessionManager } from '@celljs/ai-coding-agent';
|
|
210
|
+
import { createTestContainer } from '@celljs/ai-coding-agent/lib/node/test';
|
|
211
|
+
|
|
212
|
+
const { container, faux } = await createTestContainer({ tools: [ 'create_ticket' ] }, myModule);
|
|
213
|
+
faux.reply({ tool: 'create_ticket', args: { title: 'Fix login' } }, 'Created.');
|
|
214
|
+
const session = await container.get<AgentSessionManager>(AgentSessionManager).create();
|
|
215
|
+
await session.prompt('File a ticket for the login bug');
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`createTestContainer` 把会话的 cwd 和 agentDir 放在一个新临时目录里,默认模型是 `FauxModels.MODEL`,并关闭资源发现。
|
|
219
|
+
|
|
220
|
+
## 安全
|
|
221
|
+
|
|
222
|
+
pi 以服务进程的权限执行工具(读写文件、运行命令),没有沙箱。通过 HTTP 暴露会话时要加鉴权(如 `@celljs/security`),用 `tools` 只开放需要的工具,并把 `cwd` 限定在允许 agent 访问的目录;不要让客户端传入 `cwd`。详见 pi 文档 `docs/security.md`。
|
|
223
|
+
|
|
224
|
+
## 构建产物
|
|
225
|
+
|
|
226
|
+
pi 在 `cell build` 时保持为外部依赖(`cell.optionalDependencies`),连同它的依赖复制到 `.cell/output/server/node_modules`(约 160 MB),产物目录可以单独部署。
|
package/cell.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
cell:
|
|
2
|
+
ai:
|
|
3
|
+
codingAgent:
|
|
4
|
+
# Load extensions, skills, prompt templates and AGENTS.md from cwd and agentDir, as the pi CLI does.
|
|
5
|
+
discoverResources: true
|
|
6
|
+
# true: also write sessions where the pi CLI keeps them, so `pi --resume` lists them.
|
|
7
|
+
persistSessions: false
|
|
8
|
+
# true: refresh model catalogs over the network when the model runtime is created.
|
|
9
|
+
allowModelNetwork: false
|
|
10
|
+
# pi's MCP client: the servers of mcp.json in agentDir (and in the project once trusted), plus servers.
|
|
11
|
+
mcp:
|
|
12
|
+
enabled: false
|
|
13
|
+
servers: {}
|
|
14
|
+
# off | on | only: the model writes JavaScript that calls tools in a sandbox.
|
|
15
|
+
codemode: "off"
|
|
16
|
+
toolSearch: false
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApplicationLifecycle } from '@celljs/core';
|
|
2
|
+
import type { BackendApplication } from '@celljs/core/lib/node';
|
|
3
|
+
import { AgentSessionManager } from './coding-agent-protocol.js';
|
|
4
|
+
export declare class CodingAgentApplicationLifecycle implements ApplicationLifecycle<BackendApplication> {
|
|
5
|
+
protected readonly sessionManager: AgentSessionManager;
|
|
6
|
+
onStop(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
|
|
11
|
+
import { AgentSessionManager } from './coding-agent-protocol.js';
|
|
12
|
+
let CodingAgentApplicationLifecycle = class CodingAgentApplicationLifecycle {
|
|
13
|
+
onStop() {
|
|
14
|
+
this.sessionManager.disposeAll();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
Autowired(AgentSessionManager),
|
|
19
|
+
__metadata("design:type", Object)
|
|
20
|
+
], CodingAgentApplicationLifecycle.prototype, "sessionManager", void 0);
|
|
21
|
+
CodingAgentApplicationLifecycle = __decorate([
|
|
22
|
+
Component(ApplicationLifecycle)
|
|
23
|
+
], CodingAgentApplicationLifecycle);
|
|
24
|
+
export { CodingAgentApplicationLifecycle };
|
|
25
|
+
//# sourceMappingURL=application-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-lifecycle.js","sourceRoot":"","sources":["../../src/node/application-lifecycle.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGvD,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAIxC,MAAM;QACF,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AALsB;IADlB,SAAS,CAAC,mBAAmB,CAAC;;uEACwB;AAF9C,+BAA+B;IAD3C,SAAS,CAAC,oBAAoB,CAAC;GACnB,+BAA+B,CAO3C"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { AgentSession, ExtensionAPI, McpServerConfig, ModelRuntime, ThinkingLevel } from './pi/index.js';
|
|
2
|
+
export declare const ModelRuntimeProvider: unique symbol;
|
|
3
|
+
export declare const ModelRuntimeContribution: unique symbol;
|
|
4
|
+
export declare const AgentExtension: unique symbol;
|
|
5
|
+
export declare const AgentSessionFactory: unique symbol;
|
|
6
|
+
export declare const AgentSessionManager: unique symbol;
|
|
7
|
+
/** Configuration key of {@link CodingAgentOptions}. */
|
|
8
|
+
export declare const CODING_AGENT_OPTIONS = "cell.ai.codingAgent";
|
|
9
|
+
/** `cell.ai.codingAgent`. Names follow the options of pi's `createAgentSession()`. */
|
|
10
|
+
export interface CodingAgentOptions {
|
|
11
|
+
/** Working directory of sessions: tools act here and project resources are found here. Default: the process directory. */
|
|
12
|
+
cwd?: string;
|
|
13
|
+
/** pi's global directory (auth.json, models.json, settings.json, extensions, skills). Default: `~/.pi/agent`. */
|
|
14
|
+
agentDir?: string;
|
|
15
|
+
/** `<provider>/<model id>`. Default: pi's settings, then the first model with credentials. */
|
|
16
|
+
model?: string;
|
|
17
|
+
thinkingLevel?: ThinkingLevel;
|
|
18
|
+
/** Allowlist of tool names; `*` matches any characters. Default: read, bash, edit, write and extension tools. */
|
|
19
|
+
tools?: string[];
|
|
20
|
+
excludeTools?: string[];
|
|
21
|
+
/** Replaces pi's system prompt. */
|
|
22
|
+
systemPrompt?: string;
|
|
23
|
+
/** Appended to the system prompt. */
|
|
24
|
+
appendSystemPrompt?: string;
|
|
25
|
+
/** Load extensions, skills, prompt templates and AGENTS.md from cwd and agentDir as the pi CLI does. Default: true. */
|
|
26
|
+
discoverResources?: boolean;
|
|
27
|
+
/** Write sessions as JSONL files where the pi CLI keeps them (`pi --resume` lists them). Default: false. */
|
|
28
|
+
persistSessions?: boolean;
|
|
29
|
+
/** Let the model runtime refresh model catalogs over the network when it is created. Default: false. */
|
|
30
|
+
allowModelNetwork?: boolean;
|
|
31
|
+
/** pi's MCP client: the servers of mcp.json (agentDir, and the project once trusted) plus `servers`. */
|
|
32
|
+
mcp?: CodingAgentMcpOptions;
|
|
33
|
+
/** pi's codemode tool: the model writes JavaScript that calls tools in a sandbox. `only` hides the tools codemode can call. Default: off. */
|
|
34
|
+
codemode?: 'off' | 'on' | 'only';
|
|
35
|
+
/** pi's tool_search tool, which finds tools that are not declared to the model. Default: false. */
|
|
36
|
+
toolSearch?: boolean;
|
|
37
|
+
/** API keys by provider id, e.g. `anthropic: "${ env.MY_KEY }"`. Empty values are ignored. */
|
|
38
|
+
apiKeys?: Record<string, string | undefined>;
|
|
39
|
+
}
|
|
40
|
+
export interface CodingAgentMcpOptions {
|
|
41
|
+
/** Default: false. */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
/** MCP servers by name, in the `mcpServers` format of mcp.json (`command`/`args`/`env`, or `url`/`headers`). */
|
|
44
|
+
servers?: Record<string, McpServerConfig>;
|
|
45
|
+
/** How long the first prompt waits for servers with `direct` exposure that are still connecting. Default: 10000. */
|
|
46
|
+
startupWaitMs?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Options of one session; they override `cell.ai.codingAgent`. */
|
|
49
|
+
export type AgentSessionOptions = Pick<CodingAgentOptions, 'cwd' | 'model' | 'thinkingLevel' | 'tools' | 'excludeTools' | 'systemPrompt' | 'appendSystemPrompt'>;
|
|
50
|
+
export interface AgentSessionInfo {
|
|
51
|
+
id: string;
|
|
52
|
+
cwd: string;
|
|
53
|
+
/** `<provider>/<model id>`, undefined when no model is available. */
|
|
54
|
+
model?: string;
|
|
55
|
+
thinkingLevel: ThinkingLevel;
|
|
56
|
+
streaming: boolean;
|
|
57
|
+
messageCount: number;
|
|
58
|
+
createdAt: number;
|
|
59
|
+
}
|
|
60
|
+
/** The pi model runtime (catalogs and credentials) shared by all sessions. */
|
|
61
|
+
export interface ModelRuntimeProvider {
|
|
62
|
+
provide(): Promise<ModelRuntime>;
|
|
63
|
+
}
|
|
64
|
+
/** Configures the model runtime once it is created: register providers, set credentials. */
|
|
65
|
+
export interface ModelRuntimeContribution {
|
|
66
|
+
configure(runtime: ModelRuntime): void | Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A pi extension as a Cell component: `register` runs for each new session with pi's `ExtensionAPI`
|
|
70
|
+
* (`registerTool`, `registerCommand`, `on(event)`, ...), and the component can use injected services.
|
|
71
|
+
*/
|
|
72
|
+
export interface AgentExtension {
|
|
73
|
+
/** Name in pi's diagnostics. Default: the class name. */
|
|
74
|
+
readonly name?: string;
|
|
75
|
+
register(pi: ExtensionAPI): void | Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
/** Creates pi sessions from `cell.ai.codingAgent`, the model runtime and the {@link AgentExtension}s. */
|
|
78
|
+
export interface AgentSessionFactory {
|
|
79
|
+
create(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
80
|
+
}
|
|
81
|
+
/** Live sessions of the application, by pi's session id. They are disposed when the application stops. */
|
|
82
|
+
export interface AgentSessionManager {
|
|
83
|
+
create(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
84
|
+
/** Throws {@link AgentSessionNotFoundError} for an unknown id. */
|
|
85
|
+
get(id: string): AgentSession;
|
|
86
|
+
find(id: string): AgentSession | undefined;
|
|
87
|
+
info(id: string): AgentSessionInfo;
|
|
88
|
+
list(): AgentSessionInfo[];
|
|
89
|
+
/** Aborts the running work of the session and forgets it. */
|
|
90
|
+
dispose(id: string): void;
|
|
91
|
+
disposeAll(): void;
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ModelRuntimeProvider = Symbol('ModelRuntimeProvider');
|
|
2
|
+
export const ModelRuntimeContribution = Symbol('ModelRuntimeContribution');
|
|
3
|
+
export const AgentExtension = Symbol('AgentExtension');
|
|
4
|
+
export const AgentSessionFactory = Symbol('AgentSessionFactory');
|
|
5
|
+
export const AgentSessionManager = Symbol('AgentSessionManager');
|
|
6
|
+
/** Configuration key of {@link CodingAgentOptions}. */
|
|
7
|
+
export const CODING_AGENT_OPTIONS = 'cell.ai.codingAgent';
|
|
8
|
+
//# sourceMappingURL=coding-agent-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coding-agent-protocol.js","sourceRoot":"","sources":["../../src/node/coding-agent-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEjE,uDAAuD;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CustomError } from '@celljs/core';
|
|
2
|
+
export declare class CodingAgentError extends CustomError {
|
|
3
|
+
}
|
|
4
|
+
export declare class AgentSessionNotFoundError extends CodingAgentError {
|
|
5
|
+
readonly sessionId: string;
|
|
6
|
+
constructor(sessionId: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class AgentModelNotFoundError extends CodingAgentError {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly available: string[];
|
|
11
|
+
constructor(model: string, available: string[]);
|
|
12
|
+
}
|
|
13
|
+
export declare class AgentExtensionError extends CodingAgentError {
|
|
14
|
+
readonly errors: {
|
|
15
|
+
path: string;
|
|
16
|
+
error: string;
|
|
17
|
+
}[];
|
|
18
|
+
constructor(errors: {
|
|
19
|
+
path: string;
|
|
20
|
+
error: string;
|
|
21
|
+
}[]);
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CustomError } from '@celljs/core';
|
|
2
|
+
export class CodingAgentError extends CustomError {
|
|
3
|
+
}
|
|
4
|
+
export class AgentSessionNotFoundError extends CodingAgentError {
|
|
5
|
+
constructor(sessionId) {
|
|
6
|
+
super(`No agent session was found with the id ${sessionId}. Create one with AgentSessionManager.create(); sessions live in memory and end when the application stops.`);
|
|
7
|
+
this.sessionId = sessionId;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class AgentModelNotFoundError extends CodingAgentError {
|
|
11
|
+
constructor(model, available) {
|
|
12
|
+
super(`The model ${model} is not known to pi. Use "<provider>/<model id>"${available.length
|
|
13
|
+
? `, one of: ${available.join(', ')}`
|
|
14
|
+
: '; no model has credentials yet: set the API key of a provider (e.g. ANTHROPIC_API_KEY) or cell.ai.codingAgent.apiKeys'}.`);
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.available = available;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class AgentExtensionError extends CodingAgentError {
|
|
20
|
+
constructor(errors) {
|
|
21
|
+
super(`Agent extensions failed to load: ${errors.map(e => `${e.path}: ${e.error}`).join('; ')}`);
|
|
22
|
+
this.errors = errors;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/node/error/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,gBAAiB,SAAQ,WAAW;CAAG;AAEpD,MAAM,OAAO,yBAA0B,SAAQ,gBAAgB;IAC3D,YAAqB,SAAiB;QAClC,KAAK,CACD,0CAA0C,SAAS,6GAA6G,CACnK,CAAC;yBAHe,SAAS;IAI9B,CAAC;CACJ;AAED,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IACzD,YACa,KAAa,EACb,SAAmB;QAE5B,KAAK,CACD,aAAa,KAAK,mDACd,SAAS,CAAC,MAAM;YACZ,CAAC,CAAC,aAAa,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,CAAC,CAAC,uHACV,GAAG,CACN,CAAC;qBATO,KAAK;yBACL,SAAS;IAStB,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,gBAAgB;IACrD,YAAqB,MAAyC;QAC1D,KAAK,CAAC,oCAAoC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;sBADhF,MAAM;IAE3B,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type AgentErrorEvent, type AgentEventSource, AgentEventUtil, type AgentWireEvent, type EventStreamResponse } from '@celljs/ai-agent';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-event-util.js","sourceRoot":"","sources":["../../../src/node/event/agent-event-util.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,OAAO,EAA+C,cAAc,EAAiD,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './agent-event-util.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/event/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AgentTool } from '@celljs/ai-agent';
|
|
2
|
+
export * from './application-lifecycle.js';
|
|
3
|
+
export * from './coding-agent-protocol.js';
|
|
4
|
+
export * from './error/index.js';
|
|
5
|
+
export * from './event/index.js';
|
|
6
|
+
export * from './pi/index.js';
|
|
7
|
+
export * from './runtime/index.js';
|
|
8
|
+
export * from './session/index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Tools are written once, as @celljs/ai-agent's AgentTool components, for agents and coding agent sessions.
|
|
2
|
+
export { AgentTool } from '@celljs/ai-agent';
|
|
3
|
+
export * from './application-lifecycle.js';
|
|
4
|
+
export * from './coding-agent-protocol.js';
|
|
5
|
+
export * from './error/index.js';
|
|
6
|
+
export * from './event/index.js';
|
|
7
|
+
export * from './pi/index.js';
|
|
8
|
+
export * from './runtime/index.js';
|
|
9
|
+
export * from './session/index.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/pi/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The module namespace of `@earendil-works/pi-coding-agent`. */
|
|
2
|
+
export type PiSdk = typeof import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } });
|
|
3
|
+
export declare namespace PiSdkUtil {
|
|
4
|
+
/**
|
|
5
|
+
* Loads pi once. pi is an ES module package, so both builds of this package load it with a dynamic
|
|
6
|
+
* `import()`, which also keeps it out of the startup of applications that never create a session.
|
|
7
|
+
*/
|
|
8
|
+
function load(): Promise<PiSdk>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CodingAgentError } from '../error/index.js';
|
|
2
|
+
export var PiSdkUtil;
|
|
3
|
+
(function (PiSdkUtil) {
|
|
4
|
+
let sdk;
|
|
5
|
+
/**
|
|
6
|
+
* Loads pi once. pi is an ES module package, so both builds of this package load it with a dynamic
|
|
7
|
+
* `import()`, which also keeps it out of the startup of applications that never create a session.
|
|
8
|
+
*/
|
|
9
|
+
function load() {
|
|
10
|
+
if (!sdk) {
|
|
11
|
+
sdk = import('@earendil-works/pi-coding-agent').catch(cause => {
|
|
12
|
+
sdk = undefined;
|
|
13
|
+
throw new CodingAgentError('Cannot load @earendil-works/pi-coding-agent. Install it next to @celljs/ai-coding-agent; it needs Node.js >= 22.19.0 or Bun.', { cause });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return sdk;
|
|
17
|
+
}
|
|
18
|
+
PiSdkUtil.load = load;
|
|
19
|
+
})(PiSdkUtil || (PiSdkUtil = {}));
|
|
20
|
+
//# sourceMappingURL=pi-sdk-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-sdk-util.js","sourceRoot":"","sources":["../../../src/node/pi/pi-sdk-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK5C,MAAM,KAAW,SAAS,CAmBzB;AAnBD,WAAiB,SAAS;IACtB,IAAI,GAA+B,CAAC;IAEpC;;;OAGG;IACH,SAAgB,IAAI;QAChB,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,GAAG,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBAC1D,GAAG,GAAG,SAAS,CAAC;gBAChB,MAAM,IAAI,gBAAgB,CACtB,8HAA8H,EAC9H,EAAE,KAAK,EAAE,CACZ,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAXe,UAAA,IAAI,OAWnB,CAAA;AACL,CAAC,EAnBgB,SAAS,KAAT,SAAS,QAmBzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSession;
|
|
2
|
+
export type ModelRuntime = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ModelRuntime;
|
|
3
|
+
export type AgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSessionEvent;
|
|
4
|
+
export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).JsonAgentSessionEvent;
|
|
5
|
+
export type ExtensionAPI = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ExtensionAPI;
|
|
6
|
+
export type ExtensionFactory = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ExtensionFactory;
|
|
7
|
+
export type ToolDefinition = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ToolDefinition;
|
|
8
|
+
export type McpServerConfig = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).McpServerConfig;
|
|
9
|
+
export type ThinkingLevel = AgentSession['thinkingLevel'];
|
|
10
|
+
export type Model = NonNullable<AgentSession['model']>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.js","sourceRoot":"","sources":["../../../src/node/pi/pi-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './model-runtime-provider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type PiOptions } from '@celljs/ai-pi';
|
|
2
|
+
import { type CodingAgentOptions, ModelRuntimeContribution, ModelRuntimeProvider } from '../coding-agent-protocol.js';
|
|
3
|
+
import { type ModelRuntime } from '../pi/index.js';
|
|
4
|
+
export declare class DefaultModelRuntimeProvider implements ModelRuntimeProvider {
|
|
5
|
+
protected readonly options?: CodingAgentOptions;
|
|
6
|
+
protected readonly piOptions?: PiOptions;
|
|
7
|
+
protected readonly contributions: ModelRuntimeContribution[];
|
|
8
|
+
protected runtime?: Promise<ModelRuntime>;
|
|
9
|
+
provide(): Promise<ModelRuntime>;
|
|
10
|
+
protected doProvide(): Promise<ModelRuntime>;
|
|
11
|
+
}
|