pi-courier 0.1.38 → 0.1.39
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 +55 -2
- package/README.zh-CN.md +55 -2
- package/dist/auth/headless-login.d.ts +140 -0
- package/dist/auth/headless-login.d.ts.map +1 -0
- package/dist/auth/headless-login.js +386 -0
- package/dist/auth/headless-login.js.map +1 -0
- package/dist/quote-cache.d.ts +35 -0
- package/dist/quote-cache.d.ts.map +1 -0
- package/dist/quote-cache.js +51 -0
- package/dist/quote-cache.js.map +1 -0
- package/dist/rpc/command-map.d.ts +63 -0
- package/dist/rpc/command-map.d.ts.map +1 -1
- package/dist/rpc/command-map.js +327 -3
- package/dist/rpc/command-map.js.map +1 -1
- package/dist/rpc/message-router.d.ts +67 -2
- package/dist/rpc/message-router.d.ts.map +1 -1
- package/dist/rpc/message-router.js +297 -3
- package/dist/rpc/message-router.js.map +1 -1
- package/dist/rpc/pi-rpc.d.ts +64 -3
- package/dist/rpc/pi-rpc.d.ts.map +1 -1
- package/dist/rpc/pi-rpc.js +73 -16
- package/dist/rpc/pi-rpc.js.map +1 -1
- package/dist/rpc/project-manager.d.ts +5 -0
- package/dist/rpc/project-manager.d.ts.map +1 -1
- package/dist/rpc/project-manager.js +7 -0
- package/dist/rpc/project-manager.js.map +1 -1
- package/dist/transports/matrix.d.ts +2 -0
- package/dist/transports/matrix.d.ts.map +1 -1
- package/dist/transports/matrix.js +17 -0
- package/dist/transports/matrix.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Matrix bot ←→ pi-courier ←→ pi --mode rpc (system-installed)
|
|
|
16
16
|
|
|
17
17
|
- **You talk to a Matrix bot account**; messages are forwarded to pi over the RPC protocol
|
|
18
18
|
- **Full command support**: `/new`, `/compact`, `/model`, `/thinking`, `/skill:name`, prompt templates, extension commands
|
|
19
|
+
- **Chat-native control**: steer, queue or interrupt while pi runs; answer extension questions right in the room; log a provider in without leaving Matrix
|
|
19
20
|
- **pi is not bundled** — installed independently on the system, upgraded on its own
|
|
20
21
|
- **Sessions persist** to `~/.pi/agent/sessions` and resume automatically after restarts
|
|
21
22
|
- **One-command CLI**: setup wizard, systemd auto-start, self-update
|
|
@@ -167,14 +168,66 @@ You are now a trusted user (the first trusted user also becomes admin). In multi
|
|
|
167
168
|
| `/name <name>` | Name the session |
|
|
168
169
|
| `/export [path]` | Export session HTML |
|
|
169
170
|
| `/bash <cmd>` | Run a shell command |
|
|
170
|
-
| `/stop` | Stop all tasks immediately (like Esc in the TUI; alias `/abort
|
|
171
|
-
| `/
|
|
171
|
+
| `/stop` | Stop all tasks immediately (like Esc in the TUI; alias `/abort`; queued messages are not cleared — see below) |
|
|
172
|
+
| `/queue [text]` | Show the queue / queue a message for after the running task (Alt+Enter semantics) |
|
|
173
|
+
| `/interrupt <text>` | Interrupt the running task and send a new instruction — one message does both |
|
|
174
|
+
| `/last` | Repeat the agent's last reply |
|
|
175
|
+
| `/cyclemodel` / `/cyclethinking` | Cycle to the next model / thinking level |
|
|
176
|
+
| `/sessions` / `/switch <n>` | List recent sessions / switch to one (rejected while streaming) |
|
|
177
|
+
| `/autocompact on\|off` / `/autoretry on\|off` | Toggle pi's auto-compaction / auto-retry (writes pi's global settings — affects every pi process on this machine, survives restarts) |
|
|
178
|
+
| `/login` / `/logout <provider>` / `/auth` | Provider login management (admin + management room only) |
|
|
179
|
+
| `/reload` | Restart pi (after installing extensions/config); `/reload all` restarts every idle pi process of the instance |
|
|
172
180
|
| `/help` | Full help |
|
|
173
181
|
|
|
174
182
|
**Bridge admin commands**: `/trusted`, `/revoke <userId>`, `/channels`, `/enable [chatId] <mode>`, `/disable <chatId>`, `/toggletools`
|
|
175
183
|
|
|
176
184
|
**Anything else** starting with `/` passes through to pi directly — extension commands, `/skill:name`, prompt templates. Plain text is a normal conversation turn.
|
|
177
185
|
|
|
186
|
+
### While pi is busy: steer, queue, interrupt
|
|
187
|
+
|
|
188
|
+
Since 0.1.39 sending mirrors pi's TUI. A plain text message always rides with steering semantics (TUI Enter): pi idle → it runs immediately; pi mid-task → it is injected into the running task.
|
|
189
|
+
|
|
190
|
+
- `/queue <text>` — TUI Alt+Enter: while pi runs, the message is queued and executes when the task finishes; an idle pi simply runs it at once
|
|
191
|
+
- `/queue` — show the current steering/followUp queues (count + content, cross-checked against pi's own pending-message count)
|
|
192
|
+
- `/interrupt <text>` — idle: runs directly; mid-task: stops the current task and sends the new instruction
|
|
193
|
+
- `/stop` — stop everything now; semantics unchanged
|
|
194
|
+
|
|
195
|
+
**Queue limitation, stated up front**: pi's RPC has no "clear queue" — aborting does not discard messages that were queued before the stop. After `/stop` or `/interrupt`, messages queued beforehand take effect on the **next** turn; both commands reply with an explicit `⚠️ 队列中仍有 N 条消息将在下一轮生效` listing them, so nothing fires unseen.
|
|
196
|
+
|
|
197
|
+
### Extension questions land in the room
|
|
198
|
+
|
|
199
|
+
When an extension asks you something (confirm / select / input / editor dialogs over RPC), the bot posts the question as a chat message — your next plain reply IS the answer:
|
|
200
|
+
|
|
201
|
+
- confirm → reply `y` / `n` (`yes` / `no` work too); select → reply the number; input / editor → just type the content
|
|
202
|
+
- send 「取消」 (exactly) to back out
|
|
203
|
+
- several questions pending: the oldest is answered first; messages starting with `/` still go through the command channel
|
|
204
|
+
- extension notifications are filtered by level: warning / error reach the room, info stays in the log
|
|
205
|
+
|
|
206
|
+
Pending questions auto-cancel after `extensionUiTimeoutMinutes` (default 10) — the room gets a notice and the extension receives a cancel. This field is **not** part of the setup wizard: add it to `~/.pi/pi-courier.json` by hand, then `pi-courier restart`:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{ "extensionUiTimeoutMinutes": 10 }
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### When a model call fails
|
|
213
|
+
|
|
214
|
+
A failed turn (usage exhausted, auth expired, provider unreachable…) tells the room: `❌ 本轮失败: <原因>`. Auto-retries are visible too — `⚠️ 调用失败,正在重试 n/N` per attempt, and the final error once retries are exhausted. A manual `/stop` never produces error notices.
|
|
215
|
+
|
|
216
|
+
### Provider login from chat: `/login`
|
|
217
|
+
|
|
218
|
+
No shell needed to (re-)login a provider:
|
|
219
|
+
|
|
220
|
+
- `/login` — list login-able providers (oauth / api_key capability, ✅ badge for authenticated ones)
|
|
221
|
+
- `/login <provider> [oauth|api_key]` — interactive login in the room; send 「取消」 at any moment to abort. **OAuth**: open the link in any browser, authorize, then paste the redirect URL back into the chat. **API key**: just paste the key. ⚠️ What you paste stays in the room history — delete the message afterwards if that matters to you.
|
|
222
|
+
- `/logout <provider>` — delete a stored credential (running pi processes keep theirs in memory; `/reload all` once idle)
|
|
223
|
+
- `/auth` — the authenticated providers
|
|
224
|
+
|
|
225
|
+
Gate: admin + management room only (single-project mode: your DM with the bot). On success the **idle** pi processes restart automatically so the new credential loads; busy ones are told to `/reload` later. Credentials go straight into pi's standard credential file (`~/.pi/agent/auth.json`), shared with every pi process on the machine — pi-courier itself neither stores nor displays them.
|
|
226
|
+
|
|
227
|
+
### Replying to an earlier message
|
|
228
|
+
|
|
229
|
+
Reply (Matrix reply) to an earlier **user** message — e.g. one of your own long prompts — and send the new instruction: a one-line excerpt (≈200 chars) of the referenced text is prepended to the prompt, so "这个" / "the one above" resolve for the agent. The excerpt cache is per-room, in-memory, 50 most recent messages; the bot's own replies are not cached, and quotes that miss (too old, or from before a restart) are silently ignored — the message just goes out without the prefix.
|
|
230
|
+
|
|
178
231
|
**Group chats**: rooms with **more than 2 members** are silent by default — the bot posts a one-time hint when invited, then answers nothing until enabled. **Enable without the room ID**: send `/enable <all|mentions|trusted-only>` right in the group (trusted users only, defaults to `trusted-only`), or in a DM with `/enable <roomId> <mode>` (or add it during `setup`). Two-person rooms (you + the bot) answer automatically. Room IDs look like `!xxx:server`.
|
|
179
232
|
|
|
180
233
|
### Single-project vs multi-project mode
|
package/README.zh-CN.md
CHANGED
|
@@ -16,6 +16,7 @@ Matrix bot ←→ pi-courier ←→ pi --mode rpc(系统安装)
|
|
|
16
16
|
|
|
17
17
|
- **你和 Matrix bot 账号对话**;消息通过 RPC 协议转发给 pi
|
|
18
18
|
- **命令全支持**:`/new`、`/compact`、`/model`、`/thinking`、`/skill:名称`、提示词模板、扩展命令
|
|
19
|
+
- **聊天原生操控**:pi 运行中可 steer / 排队 / 打断;扩展提问在房间里直接答;登录 provider 不用离开 Matrix
|
|
19
20
|
- **不捆绑 pi** —— pi 独立安装、独立升级
|
|
20
21
|
- **会话持久化**到 `~/.pi/agent/sessions`,重启自动恢复
|
|
21
22
|
- **一条命令的 CLI**:配置向导、systemd 开机自启、自动更新
|
|
@@ -208,14 +209,66 @@ pi-courier enable # 安装 systemd 服务:开机自启 + 立即启动
|
|
|
208
209
|
| `/name <名字>` | 会话命名 |
|
|
209
210
|
| `/export [路径]` | 导出会话 HTML |
|
|
210
211
|
| `/bash <命令>` | 执行 shell 命令 |
|
|
211
|
-
| `/stop` | 立即停止所有任务(≈ TUI 的 Esc;别名 `/abort
|
|
212
|
-
| `/
|
|
212
|
+
| `/stop` | 立即停止所有任务(≈ TUI 的 Esc;别名 `/abort`;已排队的消息不会被清空 —— 见下文) |
|
|
213
|
+
| `/queue [文本]` | 查看队列 / 排队一条消息到运行中的任务之后(Alt+Enter 语义) |
|
|
214
|
+
| `/interrupt <文本>` | 打断运行中的任务并发送新指令 —— 一条消息完成两件事 |
|
|
215
|
+
| `/last` | 复述 agent 最近一次回复 |
|
|
216
|
+
| `/cyclemodel` / `/cyclethinking` | 轮换到下一个模型 / 思考级别 |
|
|
217
|
+
| `/sessions` / `/switch <序号>` | 列出最近会话 / 切换(流式中拒绝) |
|
|
218
|
+
| `/autocompact on\|off` / `/autoretry on\|off` | 自动压缩 / 自动重试开关(写入 pi 全局设置 —— 本机全部 pi 进程生效,重启后仍有效) |
|
|
219
|
+
| `/login` / `/logout <provider>` / `/auth` | provider 登录管理(仅管理员 + 管理房间) |
|
|
220
|
+
| `/reload` | 重启 pi(装完扩展/配置后);`/reload all` 重启本实例全部空闲 pi 进程 |
|
|
213
221
|
| `/help` | 完整帮助 |
|
|
214
222
|
|
|
215
223
|
**bridge 管理命令**:`/trusted`、`/revoke <userId>`、`/channels`、`/enable [chatId] <模式>`、`/disable <chatId>`、`/toggletools`
|
|
216
224
|
|
|
217
225
|
**其他任何 `/` 开头的内容**都直接透传给 pi —— 扩展命令、`/skill:名称`、提示词模板由 pi 展开。普通文本就是正常对话。
|
|
218
226
|
|
|
227
|
+
### pi 运行中:steer / 排队 / 打断
|
|
228
|
+
|
|
229
|
+
0.1.39 起发送语义与 pi 的 TUI 对齐。普通文本消息恒定以 steering 语义发送(≈ TUI 的 Enter):pi 空闲 → 立即执行;pi 运行中 → 注入当前运行的任务。
|
|
230
|
+
|
|
231
|
+
- `/queue <文本>` — TUI 的 Alt+Enter:pi 运行中时排队,任务跑完自动执行;空闲时退化为立即执行
|
|
232
|
+
- `/queue` — 查看当前 steering / followUp 队列(条数 + 内容,并与 pi 上报的待处理条数交叉核对)
|
|
233
|
+
- `/interrupt <文本>` — 空闲:直接执行;运行中:打断当前任务并发送新指令
|
|
234
|
+
- `/stop` — 立即停止所有任务;语义不变
|
|
235
|
+
|
|
236
|
+
**队列局限,提前说明**:pi 的 RPC 没有"清空队列"—— 中止不会丢弃打断前已排队的消息。`/stop` 或 `/interrupt` 之后,此前排队的消息会在**下一轮**生效;两条命令的回复都会显式附带 `⚠️ 队列中仍有 N 条消息将在下一轮生效` 并列出内容,不会有消息悄悄触发。
|
|
237
|
+
|
|
238
|
+
### 扩展提问直接在房间回答
|
|
239
|
+
|
|
240
|
+
扩展经 RPC 发起 confirm / select / input / editor 交互时,bot 会把问题发成一条聊天消息 —— 你的下一条普通回复就是答案:
|
|
241
|
+
|
|
242
|
+
- confirm → 回复 `y` / `n`(`yes` / `no` 也可以);select → 回复序号;input / editor → 直接打字
|
|
243
|
+
- 发送「取消」(精确匹配)即可放弃
|
|
244
|
+
- 多个问题悬置时最老的先答;`/` 开头的消息仍走命令通道
|
|
245
|
+
- 扩展通知按级别分档:warning / error 进房间,info 只留日志
|
|
246
|
+
|
|
247
|
+
悬置问题超过 `extensionUiTimeoutMinutes`(默认 10)分钟后自动按取消处理 —— 房间收到通知,扩展收到取消应答。该字段**不进** setup 向导:手动加进 `~/.pi/pi-courier.json`,然后 `pi-courier restart` 生效:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{ "extensionUiTimeoutMinutes": 10 }
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 模型调用失败时
|
|
254
|
+
|
|
255
|
+
某一轮调用失败(用量耗尽、认证过期、provider 不可达……)会通知房间:`❌ 本轮失败: <原因>`。自动重试全程可见 —— 每次重试发 `⚠️ 调用失败,正在重试 n/N`,重试耗尽后发最终错误。用户主动 `/stop` 不会触发错误通知。
|
|
256
|
+
|
|
257
|
+
### 聊天里登录 provider:`/login`
|
|
258
|
+
|
|
259
|
+
不用开终端也能(重新)登录 provider:
|
|
260
|
+
|
|
261
|
+
- `/login` — 列出可登录的 provider(标注 oauth / api_key 能力,已认证的带 ✅ 标记)
|
|
262
|
+
- `/login <provider> [oauth|api_key]` — 在房间里交互式登录,任意时刻发送「取消」可中止。**OAuth**:点开链接在任意浏览器完成授权,把重定向 URL 粘贴回房间。**API key**:直接粘贴。⚠️ 粘贴的内容会留在房间历史 —— 在意的话事后删除该消息。
|
|
263
|
+
- `/logout <provider>` — 删除已存凭据(运行中的 pi 进程仍持有内存里的旧凭据;空闲后执行 `/reload all` 生效)
|
|
264
|
+
- `/auth` — 查看已认证的 provider
|
|
265
|
+
|
|
266
|
+
门禁:仅管理员 + 仅管理房间(单工程模式 = 与 bot 的私聊)。登录成功后**空闲的** pi 进程自动重启以加载新凭据;忙碌的会提示稍后 `/reload`。凭据直写 pi 的标准凭据文件(`~/.pi/agent/auth.json`),与本机全部 pi 进程共享 —— pi-courier 自身既不保存也不显示密钥。
|
|
267
|
+
|
|
268
|
+
### 引用更早的消息
|
|
269
|
+
|
|
270
|
+
在房间里回复(reply)一条更早的**用户**消息(比如你自己之前发的长指令)再发新指令:被引用原文的单行摘录(约 200 字)会自动拼进 prompt 前缀,让 agent 能理解"这个""上面那个"的指代。摘录缓存是每房间独立的内存缓存(最近 50 条);bot 自己的回复不入缓存,未命中的引用(太旧、或重启之前的消息)静默忽略 —— 消息照常发出,只是没有前缀。
|
|
271
|
+
|
|
219
272
|
### 服务管理
|
|
220
273
|
|
|
221
274
|
```bash
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless login (issue #55, spec #51 ticket 4) — provider login without
|
|
3
|
+
* leaving Matrix.
|
|
4
|
+
*
|
|
5
|
+
* The admin runs `/login <provider> <oauth|api_key>` in the management room
|
|
6
|
+
* (single-project mode: a DM). An independent ModelRuntime (authPath pointing
|
|
7
|
+
* at pi's standard credential file, shared with every pi subprocess) drives
|
|
8
|
+
* the upstream login flow; the AuthInteraction callbacks are translated into
|
|
9
|
+
* chat messages — auth_url / device_code / progress become display messages,
|
|
10
|
+
* prompts (secret/text/select/manual_code) become questions whose answer is
|
|
11
|
+
* the room's next plain message, and 「取消」 aborts the flow at any time.
|
|
12
|
+
*
|
|
13
|
+
* The courier holds no credentials itself: the runtime writes them straight
|
|
14
|
+
* to <agentDir>/auth.json (file-locked merge write). pi subprocesses only
|
|
15
|
+
* read that file at startup, so after a successful login the caller restarts
|
|
16
|
+
* the IDLE rpcs (restartIdleRpcs in command-map) and tells the room to
|
|
17
|
+
* /reload the busy ones later.
|
|
18
|
+
*
|
|
19
|
+
* Capture priority: while a login flow in a room waits for an answer, plain
|
|
20
|
+
* messages there are captured BEFORE pending extension_ui questions (ticket
|
|
21
|
+
* requirement) — see the router's handleIncoming ordering.
|
|
22
|
+
*
|
|
23
|
+
* Upstream contract verified against
|
|
24
|
+
* node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts (AuthInteraction:
|
|
25
|
+
* prompt rejects = abnormal exit, which is exactly the cancel path) and
|
|
26
|
+
* dist/core/model-runtime.d.ts (login/logout/listCredentials; listCredentials
|
|
27
|
+
* is ASYNC upstream — Promise<readonly CredentialInfo[]>).
|
|
28
|
+
*/
|
|
29
|
+
import type { AuthEvent, AuthInteraction, AuthPrompt, Credential, CredentialInfo } from "@earendil-works/pi-ai";
|
|
30
|
+
import type { PiRpc } from "../rpc/pi-rpc.js";
|
|
31
|
+
/** One login-able provider with its interactive auth capabilities. */
|
|
32
|
+
export interface LoginProviderInfo {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
oauth: boolean;
|
|
36
|
+
apiKey: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Enumerate the builtin providers that support an INTERACTIVE login. Presence
|
|
40
|
+
* of `auth.apiKey`/`auth.oauth` alone is not enough — ambient-only providers
|
|
41
|
+
* (env vars, AWS profiles) omit `login` and cannot be logged in from a chat.
|
|
42
|
+
* Sorted by id for a stable listing.
|
|
43
|
+
*/
|
|
44
|
+
export declare function listLoginProviders(): LoginProviderInfo[];
|
|
45
|
+
/**
|
|
46
|
+
* Render the /login (no-arg) listing: one line per provider with its methods
|
|
47
|
+
* and a ✅ 已认证(<type>) badge for each stored credential. Pure.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatLoginProviders(providers: readonly LoginProviderInfo[], credentials?: readonly CredentialInfo[]): string;
|
|
50
|
+
/** /auth — the stored credentials, one line each (no secrets, metadata only). */
|
|
51
|
+
export declare function formatCredentials(credentials: readonly CredentialInfo[]): string;
|
|
52
|
+
/** The room message for an upstream login prompt (issue #55). Secret prompts
|
|
53
|
+
* must warn that the key stays in the room history. */
|
|
54
|
+
export declare function translateAuthPrompt(prompt: AuthPrompt): string;
|
|
55
|
+
/** The room message for an upstream login event: auth_url / device_code /
|
|
56
|
+
* progress / info → display-only lines (no answer expected). */
|
|
57
|
+
export declare function translateAuthEvent(event: AuthEvent): string;
|
|
58
|
+
/** Parsed room message as an answer to a pending login prompt. */
|
|
59
|
+
export type LoginAnswer = {
|
|
60
|
+
kind: "cancel";
|
|
61
|
+
} | {
|
|
62
|
+
kind: "value";
|
|
63
|
+
value: string;
|
|
64
|
+
} | {
|
|
65
|
+
kind: "invalid";
|
|
66
|
+
hint: string;
|
|
67
|
+
};
|
|
68
|
+
/** Map a room message onto a login prompt's answer (issue #55). Pure.
|
|
69
|
+
* 「取消」 is exact; select maps the 1-based index onto the option ID
|
|
70
|
+
* (out of range re-asks); every other prompt type takes the whole message. */
|
|
71
|
+
export declare function parseLoginAnswer(prompt: AuthPrompt, text: string): LoginAnswer;
|
|
72
|
+
/** Structural seam over ModelRuntime (injected in tests; production binds
|
|
73
|
+
* the real ModelRuntime at pi's auth file). */
|
|
74
|
+
export interface LoginRuntime {
|
|
75
|
+
login(providerId: string, type: "oauth" | "api_key", interaction: AuthInteraction): Promise<Credential>;
|
|
76
|
+
logout(providerId: string): Promise<void>;
|
|
77
|
+
listCredentials(): Promise<readonly CredentialInfo[]>;
|
|
78
|
+
}
|
|
79
|
+
/** The credential file this module writes: pi's standard auth.json under the
|
|
80
|
+
* agent dir (PI_CODING_AGENT_DIR respected) — shared with every pi subprocess. */
|
|
81
|
+
export declare function defaultAuthPath(): string;
|
|
82
|
+
/** Rejection carried out of a cancelled login flow (prompt rejects = upstream
|
|
83
|
+
* exits abnormally — the documented cancel path). */
|
|
84
|
+
export declare class LoginCancelledError extends Error {
|
|
85
|
+
constructor();
|
|
86
|
+
}
|
|
87
|
+
export interface LoginManagerDeps {
|
|
88
|
+
/** Room reply (the router's sendReply). */
|
|
89
|
+
sendReply: (chatId: string, transport: string, text: string) => Promise<void>;
|
|
90
|
+
/** Every rpc of this instance (default + started project rpcs): the idle
|
|
91
|
+
* ones restart after a successful login so the new credential loads. */
|
|
92
|
+
allRpcs: () => PiRpc[];
|
|
93
|
+
/** Router hook: drop per-rpc transient state (queue mirror, pending
|
|
94
|
+
* extension questions) for each rpc this manager restarts — the new
|
|
95
|
+
* subprocess knows nothing of the old question ids. */
|
|
96
|
+
onRestarted?: (rpc: PiRpc) => void;
|
|
97
|
+
/** Runtime seam (tests inject a mock; default = real ModelRuntime). */
|
|
98
|
+
runtimeFactory?: (authPath: string) => Promise<LoginRuntime>;
|
|
99
|
+
/** pi credential file (defaults to <agentDir>/auth.json; tests inject a tmp dir). */
|
|
100
|
+
authPath?: string;
|
|
101
|
+
}
|
|
102
|
+
export declare class LoginManager {
|
|
103
|
+
private readonly deps;
|
|
104
|
+
private readonly pending;
|
|
105
|
+
private runtime?;
|
|
106
|
+
constructor(deps: LoginManagerDeps);
|
|
107
|
+
/** Whether a login flow is active in this room (router capture gate). */
|
|
108
|
+
isPending(chatId: string): boolean;
|
|
109
|
+
/** /login with no arguments — the login-able provider list with auth badges. */
|
|
110
|
+
listProviders(chatId: string, transport: string): Promise<void>;
|
|
111
|
+
/** /login <provider> [oauth|api_key] — start a flow. Gates (admin +
|
|
112
|
+
* management room) are the router's job; this validates the target. */
|
|
113
|
+
startLogin(chatId: string, transport: string, providerId: string, method?: string): Promise<void>;
|
|
114
|
+
/** Feed a plain room message into the pending flow. Returns true when the
|
|
115
|
+
* message was consumed. 「取消」 aborts at ANY moment; otherwise only
|
|
116
|
+
* messages arriving while a prompt is waiting count as the answer — the
|
|
117
|
+
* room stays usable during long OAuth waits (device polling etc.). */
|
|
118
|
+
deliver(chatId: string, text: string): Promise<boolean>;
|
|
119
|
+
/** Abort the room's pending flow (「取消」 or a replacement command). */
|
|
120
|
+
cancel(chatId: string): Promise<boolean>;
|
|
121
|
+
/** /logout <provider> — delete the stored credential (metadata check first;
|
|
122
|
+
* logout itself never sees the secret). Running pi processes keep their
|
|
123
|
+
* in-memory credential until restarted. */
|
|
124
|
+
logout(chatId: string, transport: string, providerId: string): Promise<void>;
|
|
125
|
+
/** /auth — which providers are authenticated and how. */
|
|
126
|
+
authStatus(chatId: string, transport: string): Promise<void>;
|
|
127
|
+
private getRuntime;
|
|
128
|
+
/** Drive one login flow to completion: translate the AuthInteraction into
|
|
129
|
+
* chat round-trips, then restart the idle rpcs on success. */
|
|
130
|
+
private run;
|
|
131
|
+
/** Remove this flow's pending entry — and only its own: after a quick
|
|
132
|
+
* cancel + re-login in the same room, a still-draining old flow must not
|
|
133
|
+
* evict the NEW entry (the map is keyed by chat). */
|
|
134
|
+
private drop;
|
|
135
|
+
/** Park a prompt: post the question, resolve with the room's next answer,
|
|
136
|
+
* reject on abort (upstream treats a rejected prompt as abnormal exit —
|
|
137
|
+
* the documented cancel path). */
|
|
138
|
+
private promptUser;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=headless-login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-login.d.ts","sourceRoot":"","sources":["../../src/auth/headless-login.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACf,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAM9C,sEAAsE;AACtE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,EAAE,CAUxD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,WAAW,GAAE,SAAS,cAAc,EAAO,GAC1C,MAAM,CAmBR;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAMhF;AAMD;wDACwD;AACxD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,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