@njuptlzf/agent-chat-protocol 0.1.0 → 0.2.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/dist/index.d.ts +890 -0
- package/dist/index.js +19 -0
- package/package.json +42 -40
- package/src/index.ts +834 -834
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol between the agent server and any chat UI.
|
|
3
|
+
*
|
|
4
|
+
* This file is the only contract the UI depends on. pi's own event shapes stay
|
|
5
|
+
* behind the server-side adapter, so upgrading pi never breaks a client.
|
|
6
|
+
* Bump PROTOCOL_VERSION on any breaking change.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 产品声明的「可选项」目录:导航、目录分组、本地偏好都用它。
|
|
10
|
+
* 平台只认 id / label / enabled;其余字段是产品扩展数据,平台原样透传、
|
|
11
|
+
* 由产品契约 narrow,不解释语义(平台仓不出现任何产品 DTO)。
|
|
12
|
+
*/
|
|
13
|
+
export interface ProductOption {
|
|
14
|
+
id: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/** 产品扩展字段的宽松声明:平台只做形状校验 / 原样透传,语义由产品契约 narrow。 */
|
|
18
|
+
level?: string;
|
|
19
|
+
direction?: string;
|
|
20
|
+
subjects?: string[];
|
|
21
|
+
agent?: {
|
|
22
|
+
systemPrompt?: string;
|
|
23
|
+
skills?: string[];
|
|
24
|
+
};
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export declare const PROTOCOL_VERSION: 7;
|
|
28
|
+
export interface TokenUsage {
|
|
29
|
+
input: number;
|
|
30
|
+
output: number;
|
|
31
|
+
cacheRead: number;
|
|
32
|
+
cacheWrite: number;
|
|
33
|
+
total: number;
|
|
34
|
+
/** Provider-reported cost in USD, when the model has pricing data. */
|
|
35
|
+
costUsd: number;
|
|
36
|
+
}
|
|
37
|
+
export type ErrorCode = "bad_request" | "unauthorized" | "quota_exceeded" | "payment_required" | "input_too_long" | "model_error" | "limit_exceeded"
|
|
38
|
+
/** 资源不存在(模型配置面 :未知 provider / 未装配的端点组)。 */
|
|
39
|
+
| "not_found"
|
|
40
|
+
/** The session belongs to another scope and cannot be resumed under this one. */
|
|
41
|
+
| "scope_mismatch" | "persona_mismatch"
|
|
42
|
+
/** casbin 策略拒绝(权限与会员):登录了,但这个动作不归你的角色。 */
|
|
43
|
+
| "forbidden"
|
|
44
|
+
/** 封号闸:身份被暂停,先于权限判定。 */
|
|
45
|
+
| "account_banned"
|
|
46
|
+
/** 模型配置面(设计稿):provider 仍被档位引用,先解绑再删。 */
|
|
47
|
+
| "provider_in_use"
|
|
48
|
+
/** 模型仍被档位引用,先从档位解绑再撤白名单。 */
|
|
49
|
+
| "model_in_use"
|
|
50
|
+
/** 档位候选引用了不在白名单里的模型。 */
|
|
51
|
+
| "model_not_in_whitelist"
|
|
52
|
+
/** 探测 provider 失败(refresh/test 出网:连不通、401、非 JSON…)。 */
|
|
53
|
+
| "provider_unreachable"
|
|
54
|
+
/**
|
|
55
|
+
* 业务接入试连失败:代理起不来 / spec 拉不通 / 超预算。
|
|
56
|
+
* 与 provider_unreachable 分开——排障路径不同(查 MCP_PROXY_BIN 与 spec 地址,不是模型 key)。
|
|
57
|
+
*/
|
|
58
|
+
| "mcp_unreachable" | "internal";
|
|
59
|
+
/** GET /api/whoami 的返回(权限与会员)。前端导航显隐只消费 roles,安全边界在服务器。 */
|
|
60
|
+
export interface WhoamiResponse {
|
|
61
|
+
userId: string;
|
|
62
|
+
roles: string[];
|
|
63
|
+
/**
|
|
64
|
+
* 授权内核是否装配(casbin 在场)。false = dev/测试部署、闸未启用——
|
|
65
|
+
* 前端**照常显示全部入口**(「未装配=保持现状」),不能拿 roles=["user"]
|
|
66
|
+
* 去藏业务数据,否则开发环境的业务数据页会无缘由消失。
|
|
67
|
+
*/
|
|
68
|
+
authzEnabled: boolean;
|
|
69
|
+
memberUntil: string | null;
|
|
70
|
+
bannedUntil: string | null;
|
|
71
|
+
/**
|
|
72
|
+
* 审计可见性。登录用户默认能看操作审计(不查 casbin);
|
|
73
|
+
* admin 可按用户取消——true=已取消,前端隐藏入口、手敲 URL 弹回。
|
|
74
|
+
*/
|
|
75
|
+
auditRevoked: boolean;
|
|
76
|
+
quota: {
|
|
77
|
+
runsToday: number;
|
|
78
|
+
runCap: number | null;
|
|
79
|
+
tokensToday: number;
|
|
80
|
+
tokenCap: number | null;
|
|
81
|
+
};
|
|
82
|
+
pool: {
|
|
83
|
+
month: string;
|
|
84
|
+
granted: number;
|
|
85
|
+
used: number;
|
|
86
|
+
} | null;
|
|
87
|
+
}
|
|
88
|
+
/** Result of a tool call as shown to the UI. `details` is tool-specific structured data. */
|
|
89
|
+
export interface ToolResultView {
|
|
90
|
+
text: string;
|
|
91
|
+
details?: unknown;
|
|
92
|
+
}
|
|
93
|
+
/** Server -> UI, delivered as Server-Sent Events (one JSON object per `data:` line). */
|
|
94
|
+
export type ChatEvent = {
|
|
95
|
+
type: "ready";
|
|
96
|
+
v: typeof PROTOCOL_VERSION;
|
|
97
|
+
sessionId: string;
|
|
98
|
+
product: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 工具的用户可见中文名:随首帧下发一次。
|
|
102
|
+
* 前端 ToolCard 只显示这句,绝不显示 `mcp__<server>__<tool>` 声明名
|
|
103
|
+
* (README「用户可见信息边界」)。未登记的工具走前端兜底文案。
|
|
104
|
+
*/
|
|
105
|
+
| {
|
|
106
|
+
type: "tools_meta";
|
|
107
|
+
labels: Record<string, string>;
|
|
108
|
+
} | {
|
|
109
|
+
type: "text_delta";
|
|
110
|
+
messageId: string;
|
|
111
|
+
delta: string;
|
|
112
|
+
} | {
|
|
113
|
+
type: "thinking_delta";
|
|
114
|
+
messageId: string;
|
|
115
|
+
delta: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: "tool_start";
|
|
118
|
+
toolCallId: string;
|
|
119
|
+
name: string;
|
|
120
|
+
args: unknown;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A tool the product marked in `confirmTools` is about to run; the server has
|
|
124
|
+
* PAUSED the run and waits for POST /api/decision for this exact call.
|
|
125
|
+
* The UI must show an approve/deny affordance; timeout denies.
|
|
126
|
+
*/
|
|
127
|
+
| {
|
|
128
|
+
type: "tool_confirm";
|
|
129
|
+
toolCallId: string;
|
|
130
|
+
name: string;
|
|
131
|
+
args: Record<string, unknown>;
|
|
132
|
+
} | {
|
|
133
|
+
type: "tool_update";
|
|
134
|
+
toolCallId: string;
|
|
135
|
+
partial: ToolResultView;
|
|
136
|
+
} | {
|
|
137
|
+
type: "tool_end";
|
|
138
|
+
toolCallId: string;
|
|
139
|
+
name: string;
|
|
140
|
+
ok: boolean;
|
|
141
|
+
result: ToolResultView;
|
|
142
|
+
durationMs?: number;
|
|
143
|
+
} | {
|
|
144
|
+
type: "message_end";
|
|
145
|
+
messageId: string;
|
|
146
|
+
text: string;
|
|
147
|
+
usage?: TokenUsage;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* An extension called `ctx.ui.select/confirm/input` during the run. The server
|
|
151
|
+
* keeps the run paused (inside the extension's await) until POST /api/ui-response
|
|
152
|
+
* answers this exact id; timeout or disconnect resolves to "cancelled", which
|
|
153
|
+
* each dialog maps to its fail-closed default (confirm -> false, others -> undefined).
|
|
154
|
+
*/
|
|
155
|
+
| {
|
|
156
|
+
type: "ui_prompt";
|
|
157
|
+
id: string;
|
|
158
|
+
kind: "select" | "confirm" | "input";
|
|
159
|
+
title: string;
|
|
160
|
+
/** confirm: body text; select/input: optional hint. */
|
|
161
|
+
message?: string;
|
|
162
|
+
/** select only: the options to choose from. */
|
|
163
|
+
options?: string[];
|
|
164
|
+
/** input only: empty-state placeholder. */
|
|
165
|
+
placeholder?: string;
|
|
166
|
+
}
|
|
167
|
+
/** Fire-and-forget message from an extension (`ctx.ui.notify`); no answer is expected. */
|
|
168
|
+
| {
|
|
169
|
+
type: "ui_notify";
|
|
170
|
+
message: string;
|
|
171
|
+
level: "info" | "warning" | "error";
|
|
172
|
+
}
|
|
173
|
+
/** The run is fully finished (agent will not continue on its own). Always the last event on success. */
|
|
174
|
+
| {
|
|
175
|
+
type: "done";
|
|
176
|
+
aborted: boolean;
|
|
177
|
+
usage: TokenUsage;
|
|
178
|
+
} | {
|
|
179
|
+
type: "error";
|
|
180
|
+
code: ErrorCode;
|
|
181
|
+
message: string;
|
|
182
|
+
retryable: boolean;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* One inline image attached to a chat message. `data` is bare base64 (no
|
|
186
|
+
* `data:` prefix); the server validates type and size and lets pi resize it.
|
|
187
|
+
*/
|
|
188
|
+
export interface ChatImage {
|
|
189
|
+
mimeType: string;
|
|
190
|
+
data: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* One document converted to text and attached to a chat message (批 B4-A).
|
|
194
|
+
* The browser does the conversion (pdf/docx/xlsx/md/csv/txt -> Markdown);
|
|
195
|
+
* the server parses nothing, it only validates count/size and weaves the
|
|
196
|
+
* text into the prompt.
|
|
197
|
+
*/
|
|
198
|
+
export interface ChatAttachment {
|
|
199
|
+
/** File name as the user sees it (server strips paths, caps length). */
|
|
200
|
+
name: string;
|
|
201
|
+
/** Extracted Markdown; the server caps length. */
|
|
202
|
+
text: string;
|
|
203
|
+
}
|
|
204
|
+
/** UI -> server: POST /api/chat */
|
|
205
|
+
/**
|
|
206
|
+
* 一个产品可以有几个「助手人格」。**人格由入口决定,不由模型自述**:
|
|
207
|
+
* 前端点某个人格入口就带 `persona: "<id>"`,服务端据此换 system prompt、换技能、
|
|
208
|
+
* 换工具白名单,并把它绑到会话上(中途改就是 `persona_mismatch`)。
|
|
209
|
+
*
|
|
210
|
+
* **id 由产品 manifest 声明,core 不认识任何具体名字**(通用化):
|
|
211
|
+
* 合法 id = `agent.defaultPersona`(默认助手)∪ `agent.personas.*` 的键。
|
|
212
|
+
* core 只回答「这个 id 产品声明了没有」——加人格、换产品都是改 manifest。
|
|
213
|
+
*/
|
|
214
|
+
export type Persona = string;
|
|
215
|
+
/**
|
|
216
|
+
* 产品**没有**声明 `agent.defaultPersona` 时用的兜底 id。
|
|
217
|
+
* core 只发明这一个 id(其余全部来自产品 manifest);它同时是配额/流水里
|
|
218
|
+
* 「默认助手那本账」的键。
|
|
219
|
+
*/
|
|
220
|
+
export declare const DEFAULT_PERSONA_ID = "default";
|
|
221
|
+
export interface ChatRequest {
|
|
222
|
+
/** Omit to start a new conversation; the server returns the id in the `ready` event. */
|
|
223
|
+
sessionId?: string;
|
|
224
|
+
message: string;
|
|
225
|
+
/** Optional host-page context (current page, selection, ...) the agent may use. */
|
|
226
|
+
context?: Record<string, unknown>;
|
|
227
|
+
/**
|
|
228
|
+
* Which tier of `GET /api/branding` this run uses. Omit for the manifest
|
|
229
|
+
* default. An unknown id is a 400; the id is never a model name.
|
|
230
|
+
*/
|
|
231
|
+
tier?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Which assistant this run talks to (). Omit for the product's default
|
|
234
|
+
* assistant, so every existing client keeps working unchanged. Like `scope`,
|
|
235
|
+
* the persona is bound to the session at creation and immutable afterwards:
|
|
236
|
+
* resuming with a contradicting value is a 400 `persona_mismatch`.
|
|
237
|
+
*
|
|
238
|
+
* The legal ids come from the product manifest (`agent.defaultPersona` ∪
|
|
239
|
+
* `agent.personas.*`); core knows none of them by name.
|
|
240
|
+
*/
|
|
241
|
+
persona?: Persona;
|
|
242
|
+
/**
|
|
243
|
+
* Which scope (qualification) this conversation belongs to. The scope is bound
|
|
244
|
+
* to the session when it is created and is immutable afterwards: resuming an
|
|
245
|
+
* existing session ignores this field, and a value that contradicts the stored
|
|
246
|
+
* scope is a 400 `scope_mismatch`. That is what stops one conversation from
|
|
247
|
+
* silently switching coaches mid-thread.
|
|
248
|
+
*
|
|
249
|
+
* The core calls it "scope" rather than "qualification" on purpose — the agent
|
|
250
|
+
* shell carries zero business knowledge, it only knows a conversation lives in
|
|
251
|
+
* some scope. A product maps its own dimension (here: qualification id) onto it.
|
|
252
|
+
*/
|
|
253
|
+
scope?: string;
|
|
254
|
+
/**
|
|
255
|
+
* Images to send with this message. Only meaningful on a fresh send (not on a
|
|
256
|
+
* steer/follow-up), and they are not replayed by GET /api/history.
|
|
257
|
+
*/
|
|
258
|
+
images?: ChatImage[];
|
|
259
|
+
/**
|
|
260
|
+
* Converted-document attachments for this message. Fresh sends only; unlike
|
|
261
|
+
* images the text persists, because the server weaves it into the stored
|
|
262
|
+
* message. The server caps count and per-attachment length.
|
|
263
|
+
*/
|
|
264
|
+
attachments?: ChatAttachment[];
|
|
265
|
+
}
|
|
266
|
+
/** UI -> server: POST /api/decision, answering a `tool_confirm` event. */
|
|
267
|
+
export interface ConfirmDecision {
|
|
268
|
+
sessionId: string;
|
|
269
|
+
toolCallId: string;
|
|
270
|
+
allow: boolean;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* UI -> server: POST /api/ui-response, answering a `ui_prompt` event.
|
|
274
|
+
* Exactly one answer field: `value` (select/input), `confirmed` (confirm),
|
|
275
|
+
* or `cancelled` (dismiss — the extension receives its fail-closed default).
|
|
276
|
+
*/
|
|
277
|
+
export interface UIResponse {
|
|
278
|
+
sessionId: string;
|
|
279
|
+
id: string;
|
|
280
|
+
value?: string;
|
|
281
|
+
confirmed?: boolean;
|
|
282
|
+
cancelled?: true;
|
|
283
|
+
}
|
|
284
|
+
/** One row of GET /api/sessions: a resumable conversation of this user. */
|
|
285
|
+
export interface SessionSummary {
|
|
286
|
+
sessionId: string;
|
|
287
|
+
/**
|
|
288
|
+
* Scope the session is bound to. `GET /api/sessions?scope=` filters by it; the
|
|
289
|
+
* global history drawer shows it as a badge so opening a row can switch scope
|
|
290
|
+
* first instead of resuming under the wrong persona.
|
|
291
|
+
*/
|
|
292
|
+
scope: string;
|
|
293
|
+
/** First user message, trimmed; doubles as the display title. */
|
|
294
|
+
title: string;
|
|
295
|
+
/** ISO timestamp of the last saved run. */
|
|
296
|
+
updatedAt: string;
|
|
297
|
+
messageCount: number;
|
|
298
|
+
/**
|
|
299
|
+
* 会话的人格。`null` = 的老会话(按产品默认助手处理)。
|
|
300
|
+
* 前端据此过滤:不同人格的历史不能混在一起,否则点开就是 `persona_mismatch`。
|
|
301
|
+
*/
|
|
302
|
+
persona?: string | null;
|
|
303
|
+
}
|
|
304
|
+
/** One display message of GET /api/history (text only; tools/thinking are not replayed). */
|
|
305
|
+
export interface HistoryMessage {
|
|
306
|
+
role: "user" | "assistant";
|
|
307
|
+
text: string;
|
|
308
|
+
at: string;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* One entry of GET /api/commands: a slash command the UI can offer. Commands are
|
|
312
|
+
* derived from the product's skills, and typing one is pure UI semantics — the
|
|
313
|
+
* server expands it into the skill body, so the "/" never reaches the model.
|
|
314
|
+
*/
|
|
315
|
+
export interface ChatCommand {
|
|
316
|
+
/** Typed after "/", e.g. "essay-grading". */
|
|
317
|
+
name: string;
|
|
318
|
+
description: string;
|
|
319
|
+
}
|
|
320
|
+
export type FeedbackRating = "up" | "down";
|
|
321
|
+
/** One balance movement. `amountCents` is positive for recharge/spend/membership
|
|
322
|
+
* (the `kind` gives the direction); an `adjust` row carries the signed delta —
|
|
323
|
+
* its direction has no kind to infer, so the frontend reads the sign. */
|
|
324
|
+
export interface BillingLedgerEntry {
|
|
325
|
+
at: string;
|
|
326
|
+
/**
|
|
327
|
+
* `recharge` = 充值到账;`spend` = 会话消耗(用量报表只统计它);
|
|
328
|
+
* `membership` = 买会员套餐——是消费,但不是聊天消耗,
|
|
329
|
+
* 所以单独一类,别混进「这个月聊了多少钱」;
|
|
330
|
+
* `adjust` = 管理端余额调整(人工退款/纠错,`funds.adjust` 审计留痕)。
|
|
331
|
+
*/
|
|
332
|
+
kind: "recharge" | "spend" | "membership" | "adjust";
|
|
333
|
+
amountCents: number;
|
|
334
|
+
balanceAfter: number;
|
|
335
|
+
/** Recharge/order id or chat sessionId. */
|
|
336
|
+
ref?: string;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 可售的会员套餐(随 GET /api/billing 下发)。
|
|
340
|
+
*
|
|
341
|
+
* 价格与权益都来自 manifest(`billing.plans` + `limits.personas`),前端不硬编码
|
|
342
|
+
* 「600 万池/50 轮」这种数字——改了配置页面就跟着变。
|
|
343
|
+
*/
|
|
344
|
+
export interface MembershipPlanView {
|
|
345
|
+
/** 账本产品 = 人格 id(由产品声明,如 default / helper)。 */
|
|
346
|
+
product: string;
|
|
347
|
+
/** 展示名(来自人格 ui 的 label;没有就用 id)。 */
|
|
348
|
+
label: string | null;
|
|
349
|
+
days: number;
|
|
350
|
+
priceCents: number;
|
|
351
|
+
/** 会员档每天可对话轮数;null = 不限。 */
|
|
352
|
+
runsPerDay: number | null;
|
|
353
|
+
/** 会员每月发放的 token 池;0 = 无池。 */
|
|
354
|
+
monthlyTokens: number;
|
|
355
|
+
/** 当前到期时刻(ISO);没买过 → null。 */
|
|
356
|
+
memberUntil: string | null;
|
|
357
|
+
}
|
|
358
|
+
/** 订阅页「待付订单」行(GET /api/billing 的 pendingOrders,2026-11-04)。 */
|
|
359
|
+
export interface PendingOrderView {
|
|
360
|
+
orderId: string;
|
|
361
|
+
kind: "recharge" | "membership";
|
|
362
|
+
/** 会员单的账本(人格 id);充值单为 null。 */
|
|
363
|
+
product: string | null;
|
|
364
|
+
days: number | null;
|
|
365
|
+
amountCents: number;
|
|
366
|
+
/** 下单时刻(ISO);老库补列前为 null(前端显示「—」)。 */
|
|
367
|
+
createdAt: string | null;
|
|
368
|
+
}
|
|
369
|
+
/** GET /api/billing payload. */
|
|
370
|
+
export interface BillingSummary {
|
|
371
|
+
balanceCents: number;
|
|
372
|
+
recent: BillingLedgerEntry[];
|
|
373
|
+
/** 可购买的会员套餐;没配 `billing.plans` 的部署为空数组(页面不显示卡片)。 */
|
|
374
|
+
plans: MembershipPlanView[];
|
|
375
|
+
/** 本人的待付订单(pending);没有时为空数组——列表块整块不渲染。 */
|
|
376
|
+
pendingOrders: PendingOrderView[];
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* One qualification's share of the spend window (GET /api/billing/usage).
|
|
380
|
+
* `scope` is "" for spends whose session left no history row — the UI labels
|
|
381
|
+
* that bucket 未知 rather than pretending it belongs somewhere.
|
|
382
|
+
*/
|
|
383
|
+
export interface BillingUsageScope {
|
|
384
|
+
scope: string;
|
|
385
|
+
spendCents: number;
|
|
386
|
+
/** Individual deductions, i.e. how many chats cost money. */
|
|
387
|
+
charges: number;
|
|
388
|
+
}
|
|
389
|
+
/** One UTC day of the spend window. Days with no spend are omitted, not zero-filled. */
|
|
390
|
+
export interface BillingUsageDay {
|
|
391
|
+
/** YYYY-MM-DD (UTC), matching the ledger timestamps. */
|
|
392
|
+
day: string;
|
|
393
|
+
spendCents: number;
|
|
394
|
+
charges: number;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* GET /api/billing/usage: spend rolled up by qualification and by day.
|
|
398
|
+
*
|
|
399
|
+
* The qualification is derived by joining the ledger's sessionId back to
|
|
400
|
+
* `history.scope`, so no schema change was needed — the scope column has been
|
|
401
|
+
* on `history` since S0 and every spend carries its session id. Recharges are
|
|
402
|
+
* account-level and deliberately excluded: they are not consumed by anything.
|
|
403
|
+
*/
|
|
404
|
+
export interface BillingUsageReport {
|
|
405
|
+
/** Window length in days that the buckets cover. */
|
|
406
|
+
days: number;
|
|
407
|
+
/**
|
|
408
|
+
* 日界用的时区偏移(东为正分钟数,与 `/api/progress` 的 `tzOffset` 同源)。
|
|
409
|
+
* `byDay` 的 day 就是这个时区的本地日——图表补零要用同一套键。
|
|
410
|
+
*/
|
|
411
|
+
tzOffset: number;
|
|
412
|
+
totalSpendCents: number;
|
|
413
|
+
byScope: BillingUsageScope[];
|
|
414
|
+
byDay: BillingUsageDay[];
|
|
415
|
+
}
|
|
416
|
+
/** POST /api/recharge response. `status` is "paid" only under `billing.mockAutoFulfill`. */
|
|
417
|
+
export interface RechargeResult {
|
|
418
|
+
orderId: string;
|
|
419
|
+
amountCents: number;
|
|
420
|
+
status: "pending" | "paid";
|
|
421
|
+
}
|
|
422
|
+
/** 订单品类:充值进钱包,会员买某个产品的有效期。 */
|
|
423
|
+
export type OrderKind = "recharge" | "membership";
|
|
424
|
+
/** POST /api/orders 的返回。`memberUntil` 只在会员单履约成功时出现。 */
|
|
425
|
+
export interface OrderResult {
|
|
426
|
+
orderId: string;
|
|
427
|
+
kind: OrderKind;
|
|
428
|
+
amountCents: number;
|
|
429
|
+
status: "pending" | "paid";
|
|
430
|
+
product?: string;
|
|
431
|
+
days?: number;
|
|
432
|
+
/** 履约后的新到期时刻(ISO);pending 时没有。 */
|
|
433
|
+
memberUntil?: string;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 反馈的两条腿:`rating` = 对某条回答的 👍/👎(信号,不进工单板);
|
|
437
|
+
* 其余四种 = 工单(有正文、有状态、有处理人)。**别把赞/踩混进工单队列**——
|
|
438
|
+
* 那是永远清不完的队列,也发不了奖励。
|
|
439
|
+
*/
|
|
440
|
+
export type FeedbackKind = "rating" | "bug" | "idea" | "other" | "membership";
|
|
441
|
+
/**
|
|
442
|
+
* 工单状态(四边:new→accepted→done / new→rejected)。
|
|
443
|
+
* `rejected` **不上公开板**:只回给提交者本人——公开打脸比不回复更伤。
|
|
444
|
+
*/
|
|
445
|
+
export type FeedbackStatus = "new" | "accepted" | "done" | "rejected";
|
|
446
|
+
/** One row of GET /api/feedback/report(也用于工单板/我的工单/管理队列)。 */
|
|
447
|
+
export interface FeedbackEntry {
|
|
448
|
+
/** 工单 id(内存实现自增;老 report 消费方不依赖它)。 */
|
|
449
|
+
id?: number;
|
|
450
|
+
at: string;
|
|
451
|
+
userId: string;
|
|
452
|
+
sessionId: string;
|
|
453
|
+
/** 缺省 = 工单行(没有 👍/👎 可言);`kind === "rating"` 时一定有值。 */
|
|
454
|
+
rating?: FeedbackRating;
|
|
455
|
+
kind?: FeedbackKind;
|
|
456
|
+
/** 工单正文,≤1000 字;rating 行没有。 */
|
|
457
|
+
content?: string;
|
|
458
|
+
status?: FeedbackStatus;
|
|
459
|
+
/** 官方回复(公开可见),≤500 字。 */
|
|
460
|
+
reply?: string;
|
|
461
|
+
handledBy?: string;
|
|
462
|
+
handledAt?: string;
|
|
463
|
+
/** 实际发放的会员天数;0/缺省 = 没发。 */
|
|
464
|
+
rewardDays?: number;
|
|
465
|
+
ref?: string;
|
|
466
|
+
/**
|
|
467
|
+
* 处理优先级(会员权益):会员/管理员的反馈=high,report 置顶——
|
|
468
|
+
* 「会员优先」不是门槛而是排队顺序(免费也能反馈,优先级不同)。
|
|
469
|
+
* 服务端按 roles 算,不信任 body。
|
|
470
|
+
*/
|
|
471
|
+
priority?: "normal" | "high";
|
|
472
|
+
}
|
|
473
|
+
/** 工单的用户可见视图:**不含 userId**——公开板与「我的工单」都不带身份。 */
|
|
474
|
+
export interface FeedbackTicketView {
|
|
475
|
+
id: number;
|
|
476
|
+
at: string;
|
|
477
|
+
kind: Exclude<FeedbackKind, "rating">;
|
|
478
|
+
content: string;
|
|
479
|
+
status: FeedbackStatus;
|
|
480
|
+
reply?: string;
|
|
481
|
+
rewardDays?: number;
|
|
482
|
+
}
|
|
483
|
+
/** 管理队列行:多提交者、优先级与处理痕迹(只有管理员看得到)。 */
|
|
484
|
+
export interface FeedbackQueueItem extends FeedbackTicketView {
|
|
485
|
+
userId: string;
|
|
486
|
+
priority: "normal" | "high";
|
|
487
|
+
handledBy?: string;
|
|
488
|
+
handledAt?: string;
|
|
489
|
+
}
|
|
490
|
+
/** pi's thinking levels we expose. `xhigh`/`max` need explicit provider helper, so they stay out. */
|
|
491
|
+
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high";
|
|
492
|
+
/**
|
|
493
|
+
* 人格的**展示文案**。
|
|
494
|
+
*
|
|
495
|
+
* 只装"用户看到的话",**绝不装能力**:`allowTools` / `skills` / `systemPrompt`
|
|
496
|
+
* 属于人格的能力面与正文,留在 manifest + 代码里,永不下发、永不进页面——
|
|
497
|
+
* 「某人格不替用户做业务」靠的是工具不存在,不是 prompt 里写一句。
|
|
498
|
+
*
|
|
499
|
+
* 全部字段可选:缺哪个,前端就回落到内置默认文案(前后端可分别升级)。
|
|
500
|
+
*/
|
|
501
|
+
export interface PersonaUi {
|
|
502
|
+
/** 侧栏入口显示名(如「声明人格」)。 */
|
|
503
|
+
label?: string;
|
|
504
|
+
/** 入口图标(emoji 或短文本)。 */
|
|
505
|
+
icon?: string;
|
|
506
|
+
/** 入口右侧 2 字标签(如「事务」)。 */
|
|
507
|
+
tag?: string;
|
|
508
|
+
/** 入口 tooltip。 */
|
|
509
|
+
hint?: string;
|
|
510
|
+
/** 对话区空态标题。 */
|
|
511
|
+
welcome?: string;
|
|
512
|
+
/** 常驻提示条(如「我是助手,不是人工」)。 */
|
|
513
|
+
policyNote?: string;
|
|
514
|
+
/** 空态快捷问法。 */
|
|
515
|
+
suggestions?: string[];
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* `PersonaUi` 的展示字段(顺序即页面顺序)。manifest 加载与运行时配置校验共用这一份,
|
|
519
|
+
* 避免两处各写一份清单后漂移——漂移的表现是「页面能存、manifest 读不懂」。
|
|
520
|
+
*/
|
|
521
|
+
export declare const PERSONA_UI_FIELDS: readonly ["label", "icon", "tag", "hint", "welcome", "policyNote", "suggestions"];
|
|
522
|
+
/** What the UI needs to re-skin itself for a product. Served by GET /api/branding. */
|
|
523
|
+
export interface Branding {
|
|
524
|
+
title: string;
|
|
525
|
+
logo?: string;
|
|
526
|
+
welcome?: string;
|
|
527
|
+
suggestions?: string[];
|
|
528
|
+
/**
|
|
529
|
+
* CSS custom properties injected on the app root, overriding the design
|
|
530
|
+
* tokens in the web bundle, e.g. { "--ac-primary": "#2563eb" } or a
|
|
531
|
+
* per-mode pair "light-dark(#2563eb, #6ea8fe)". The `--chat-primary` key
|
|
532
|
+
* from pre-token bundles is still honoured as a legacy alias.
|
|
533
|
+
*/
|
|
534
|
+
theme?: Record<string, string>;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* A selectable quality tier as shown to the user. Deliberately carries no model
|
|
538
|
+
* name: the physical model (and its price) stay server-side.
|
|
539
|
+
*/
|
|
540
|
+
export interface ModelTier {
|
|
541
|
+
id: string;
|
|
542
|
+
label: string;
|
|
543
|
+
/** Structured one-liner for the tier picker (e.g. what the tier is good at). */
|
|
544
|
+
description?: string;
|
|
545
|
+
/** Scales the manifest's per-1,000-token price, so the shown number is the charged number. */
|
|
546
|
+
multiplier: number;
|
|
547
|
+
/**
|
|
548
|
+
* Effective price per 1,000 tokens in cents (manifest base price × multiplier),
|
|
549
|
+
* present only when the product bills by tokens. This is the number to show.
|
|
550
|
+
*/
|
|
551
|
+
pricePerThousandTokensCents?: number;
|
|
552
|
+
}
|
|
553
|
+
/** GET /api/branding: manifest branding plus the server-derived tier list. */
|
|
554
|
+
export interface BrandingResponse extends Branding {
|
|
555
|
+
/** Tiers in manifest order. Absent when the product declares none. */
|
|
556
|
+
tiers?: ModelTier[];
|
|
557
|
+
/**
|
|
558
|
+
* Qualifications this product covers, in manifest order (V0). Served rather
|
|
559
|
+
* than baked into the web bundle: the shell is product-agnostic (it carries
|
|
560
|
+
* zero business knowledge), and the server already needs the list to map
|
|
561
|
+
* question-bank directories. `enabled: false` renders as 即将上线.
|
|
562
|
+
*/
|
|
563
|
+
quals?: ProductOption[];
|
|
564
|
+
/**
|
|
565
|
+
* 各人格的展示文案,键是 persona id。**只有 `ui`**——能力面
|
|
566
|
+
* (`allowTools`/`skills`/`systemPrompt`)一个字节都不下发,见 `PersonaUi`。
|
|
567
|
+
* 产品没声明人格时整个字段缺席,前端回落到内置默认文案。
|
|
568
|
+
*/
|
|
569
|
+
personas?: Record<string, PersonaUi>;
|
|
570
|
+
/**
|
|
571
|
+
* 产品**默认助手**的人格 id(通用化)。前端用它对齐两类东西:
|
|
572
|
+
* 老会话(`history.persona` 为 null = 默认助手那一批)与当前入口。
|
|
573
|
+
* 只是一个 id,不带任何能力信息,所以可以公开。
|
|
574
|
+
*/
|
|
575
|
+
defaultPersona?: string;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* 管理端模型配置。物理模型名只到这一层:
|
|
579
|
+
* `/api/branding` 仍然只下发档位的 id/label/multiplier/price,一个模型名都不出现。
|
|
580
|
+
*/
|
|
581
|
+
export interface ModelProviderView {
|
|
582
|
+
id: string;
|
|
583
|
+
enabled: boolean;
|
|
584
|
+
api?: string;
|
|
585
|
+
baseUrl?: string;
|
|
586
|
+
/** 只回布尔 + env 变量名,密钥本身永不出服务器。 */
|
|
587
|
+
keyConfigured: boolean;
|
|
588
|
+
/** `env:NAME` 里的 NAME(keyRef 的展示形态)。 */
|
|
589
|
+
keyEnv?: string;
|
|
590
|
+
/** 白名单:允许绑到档位的模型子集(`model-config.json` 的 `providers[].models`)。 */
|
|
591
|
+
models: string[];
|
|
592
|
+
/** 目录:最近一次从 `GET {baseUrl}/models` 拉回的全集;白名单 ⊆ 目录。 */
|
|
593
|
+
catalog: string[];
|
|
594
|
+
fetchedAt?: string;
|
|
595
|
+
}
|
|
596
|
+
export interface ModelCandidateRef {
|
|
597
|
+
provider: string;
|
|
598
|
+
model: string;
|
|
599
|
+
}
|
|
600
|
+
export interface ModelTierView {
|
|
601
|
+
/** 档位显示名(来自 manifest;配置只重绑、不新增档位)。 */
|
|
602
|
+
label?: string;
|
|
603
|
+
/** 计费倍率(manifest):换模型不改价,管理页回显用。 */
|
|
604
|
+
multiplier?: number;
|
|
605
|
+
/** 有序:第 0 个是主模型,其余为备份。 */
|
|
606
|
+
candidates: ModelCandidateRef[];
|
|
607
|
+
}
|
|
608
|
+
/** `GET /api/admin/models`:管理页首屏。 */
|
|
609
|
+
export interface ModelsResponse {
|
|
610
|
+
/** `file`=model-config.json 生效;`manifest`=回落(缺文件/坏 JSON)。 */
|
|
611
|
+
source: "file" | "manifest";
|
|
612
|
+
/** 候选上限(可配 1–5,缺省 3)。 */
|
|
613
|
+
maxCandidates: number;
|
|
614
|
+
providers: ModelProviderView[];
|
|
615
|
+
tiers: Record<string, ModelTierView>;
|
|
616
|
+
routing: {
|
|
617
|
+
failover: boolean;
|
|
618
|
+
cooldownSeconds: number;
|
|
619
|
+
stickyWithinRun: boolean;
|
|
620
|
+
};
|
|
621
|
+
/** 校验中被纠正或丢弃的项(服务端已同步打日志),管理页原样展示。 */
|
|
622
|
+
problems: string[];
|
|
623
|
+
/** 配置文件绝对路径——页面要告诉管理员「去改哪个文件」。 */
|
|
624
|
+
configPath: string;
|
|
625
|
+
}
|
|
626
|
+
/** `POST /api/admin/models/providers/:id/test`:一次 max_tokens:1 的最小请求。 */
|
|
627
|
+
export interface ModelTestResponse {
|
|
628
|
+
ok: boolean;
|
|
629
|
+
latencyMs: number;
|
|
630
|
+
model?: string;
|
|
631
|
+
error?: string;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* An MCP server the product wants connected. Mirrors the subset of pi's mcp.json
|
|
635
|
+
* shape we allow in a manifest. Server operators own this file (same trust level
|
|
636
|
+
* as `tools.inline`), so stdio commands are not user input.
|
|
637
|
+
* Relative `command`/`args`/`cwd` paths resolve against the product directory.
|
|
638
|
+
*/
|
|
639
|
+
export interface McpServerDecl {
|
|
640
|
+
/**
|
|
641
|
+
* "openapi" = runtime proxy (mcp-openapi-proxy, PyPI): the server translates it
|
|
642
|
+
* into a stdio spawn at session build. Declared explicitly or inferred from
|
|
643
|
+
* the presence of `openapi`.
|
|
644
|
+
*/
|
|
645
|
+
type?: "stdio" | "http" | "openapi";
|
|
646
|
+
/** stdio: program to spawn. */
|
|
647
|
+
command?: string;
|
|
648
|
+
args?: string[];
|
|
649
|
+
env?: Record<string, string>;
|
|
650
|
+
cwd?: string;
|
|
651
|
+
/** http: streamable-HTTP endpoint. Values may reference `${ENV_VAR}`. */
|
|
652
|
+
url?: string;
|
|
653
|
+
headers?: Record<string, string>;
|
|
654
|
+
/** openapi: spec source. Secrets stay in env — only the env *name* is stored here. */
|
|
655
|
+
openapi?: {
|
|
656
|
+
/** Absolute http(s) URL of the OpenAPI 3 spec. Subject to MCP_SPEC_ALLOWLIST. */
|
|
657
|
+
specUrl: string;
|
|
658
|
+
/** Overrides spec `servers[0].url` — required when that is a relative path (spike 缺陷③). */
|
|
659
|
+
baseUrl?: string;
|
|
660
|
+
/** Header auth: header name + the env var holding its value. Echoed as keyConfigured only. */
|
|
661
|
+
authEnv?: {
|
|
662
|
+
header: string;
|
|
663
|
+
valueEnv: string;
|
|
664
|
+
};
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Per-tool whitelist, passed through to pi (McpServerConfig.toolExposure):
|
|
668
|
+
* key = tool name or "*" pattern (exact beats pattern, first match wins);
|
|
669
|
+
* "hidden" removes the tool from the model's view. `{ "*": "hidden", ... }`
|
|
670
|
+
* = allowlist mode. Tool names come from the probe (openapi) or the server itself.
|
|
671
|
+
*/
|
|
672
|
+
toolExposure?: Record<string, "direct" | "hidden">;
|
|
673
|
+
/** Chinese display names per tool; merged into tools_meta as `mcp__<id>__<tool>`. */
|
|
674
|
+
labels?: Record<string, string>;
|
|
675
|
+
/**
|
|
676
|
+
* How the model reaches the tools. Default "direct" (declared like any other
|
|
677
|
+
* tool). "codemode" and "deferred" are not offered: this server session loads
|
|
678
|
+
* only the mcp built-in extension — never codemode or tool-search — so tools
|
|
679
|
+
* with those exposures would never be reachable (upstream only logs a warning).
|
|
680
|
+
*/
|
|
681
|
+
exposure?: "direct" | "hidden";
|
|
682
|
+
description?: string;
|
|
683
|
+
/** Set false to keep the entry without connecting. Default true. */
|
|
684
|
+
enabled?: boolean;
|
|
685
|
+
/** Per-request timeout, seconds. */
|
|
686
|
+
timeout?: number;
|
|
687
|
+
}
|
|
688
|
+
/** Product manifest as written on disk (paths are relative to the manifest file). */
|
|
689
|
+
export interface ProductManifest {
|
|
690
|
+
id: string;
|
|
691
|
+
branding: Branding;
|
|
692
|
+
/**
|
|
693
|
+
* Qualifications this product covers (V0). Omit for a single-track product:
|
|
694
|
+
* the whole `questions/` dir then belongs to the product's only track. With
|
|
695
|
+
* `quals`, question banks live under `questions/<qualId>/`.
|
|
696
|
+
*/
|
|
697
|
+
quals?: ProductOption[];
|
|
698
|
+
/** 当前选项注入 system prompt 的模板(产品文案)。占位符 {label}/{level}/{direction};不声明则不注入。 */
|
|
699
|
+
scopePromptTemplate?: string;
|
|
700
|
+
agent: {
|
|
701
|
+
/** Path to a markdown file used as the system prompt. */
|
|
702
|
+
systemPrompt: string;
|
|
703
|
+
/** Directories scanned for Agent Skills (SKILL.md). */
|
|
704
|
+
skills?: string[];
|
|
705
|
+
/**
|
|
706
|
+
* The id clients use for the product's **default** assistant (通用化).
|
|
707
|
+
* Omit it and the default assistant is addressed by `DEFAULT_PERSONA_ID`.
|
|
708
|
+
*
|
|
709
|
+
* Why it lives here and not in core: "our default assistant is called X" is a
|
|
710
|
+
* **product** fact. Core used to hardcode the two ids it happened to ship
|
|
711
|
+
* with, which meant a second product could not have a different set of
|
|
712
|
+
* assistants without patching core.
|
|
713
|
+
*
|
|
714
|
+
* It is also the accounting key for that assistant's quota / run ledger, so
|
|
715
|
+
* changing it later is a data migration, not a rename. It must NOT collide
|
|
716
|
+
* with a key of `personas` — the manifest loader rejects that at startup.
|
|
717
|
+
*/
|
|
718
|
+
defaultPersona?: string;
|
|
719
|
+
/**
|
|
720
|
+
* 保存 prompt 时**必须出现**的段落标题,行首匹配。产品声明自己的红线:
|
|
721
|
+
* 默认助手用这个字段,各人格用 `personas[x].requiredSections`(未声明则继承这里)。
|
|
722
|
+
* core 只提供校验器——它不该认识「三条硬规则」这句话。
|
|
723
|
+
*/
|
|
724
|
+
requiredSections?: string[];
|
|
725
|
+
/**
|
|
726
|
+
* Extra assistant personas (), keyed by persona id (e.g. `helper`). Each one
|
|
727
|
+
* replaces the prompt — and, when `skills` is declared, the skill set too.
|
|
728
|
+
* **Omitted `skills` means no skills**, not "inherit the product's": a
|
|
729
|
+
* secondary assistant that inherits the default persona's skills would start answering
|
|
730
|
+
* exam questions, which is exactly what the split exists to prevent.
|
|
731
|
+
*/
|
|
732
|
+
personas?: Record<string, {
|
|
733
|
+
systemPrompt: string;
|
|
734
|
+
skills?: string[];
|
|
735
|
+
/**
|
|
736
|
+
* Tool whitelist for this persona (). **Omitted = no tools at all**,
|
|
737
|
+
* not "inherit the product's" — the whitelist is the real boundary
|
|
738
|
+
* between the default persona and secondary persona: a secondary assistant that can call
|
|
739
|
+
* `pick_practice` will start answering exam questions no matter what
|
|
740
|
+
* its prompt says.
|
|
741
|
+
*
|
|
742
|
+
* Names are bare (`my_usage`), and apply to both layers: inline tools
|
|
743
|
+
* from the product's tool factory, and MCP tools (translated into
|
|
744
|
+
* per-server `toolExposure`, so a hidden tool never reaches the model).
|
|
745
|
+
*/
|
|
746
|
+
allowTools?: string[];
|
|
747
|
+
/** 该人格的必备段落;未声明则继承 `agent.requiredSections`。 */
|
|
748
|
+
requiredSections?: string[];
|
|
749
|
+
/**
|
|
750
|
+
* 展示文案。它**不进模型**,只决定入口/空态/提示条长什么样,
|
|
751
|
+
* 随 `/api/branding` 下发——所以改文案不用重建前端。
|
|
752
|
+
*/
|
|
753
|
+
ui?: PersonaUi;
|
|
754
|
+
}>;
|
|
755
|
+
/**
|
|
756
|
+
* pi extension modules to load (batch 3-4). Paths to `.ts`/`.js` files or
|
|
757
|
+
* package dirs, resolved against the manifest file. Operator-controlled:
|
|
758
|
+
* extensions run in-process with full privileges, so the trust boundary is
|
|
759
|
+
* code review of the repository, never `pi install` of third-party code.
|
|
760
|
+
*/
|
|
761
|
+
extensions?: string[];
|
|
762
|
+
/**
|
|
763
|
+
* Per-user/per-scope long-term memory (, plan B): turns the built-in
|
|
764
|
+
* scopedMemory plugin on (remember/recall/forget tools + a capped, ranked
|
|
765
|
+
* snapshot injected into the system prompt; on the server the plugin also
|
|
766
|
+
* runs an every-10-turns auto-capture pass). Default true. Storage is host-owned:
|
|
767
|
+
* `<dataDir>/memory/<userId>/<scope>/entries.jsonl`, never exposed to the
|
|
768
|
+
* browser and never rendered into the prompt itself.
|
|
769
|
+
*/
|
|
770
|
+
memory?: boolean;
|
|
771
|
+
model: {
|
|
772
|
+
provider: string;
|
|
773
|
+
id: string;
|
|
774
|
+
thinking?: ThinkingLevel;
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* Selectable quality tiers (batch 3-1). The UI sees only `id`/`label`/the
|
|
778
|
+
* derived price; the physical model stays here, server-side. Omit to run
|
|
779
|
+
* `agent.model` with no tier picker.
|
|
780
|
+
*/
|
|
781
|
+
tiers?: Array<{
|
|
782
|
+
id: string;
|
|
783
|
+
label: string;
|
|
784
|
+
/** Shown in the tier picker alongside the label. */
|
|
785
|
+
description?: string;
|
|
786
|
+
/** Overrides `agent.model.id` within the same provider. */
|
|
787
|
+
model?: string;
|
|
788
|
+
/** Overrides `agent.model.thinking`. */
|
|
789
|
+
thinking?: ThinkingLevel;
|
|
790
|
+
/** Scales the per-1,000-token price, so the shown price is the charged price. */
|
|
791
|
+
multiplier: number;
|
|
792
|
+
}>;
|
|
793
|
+
/**
|
|
794
|
+
* 工具的用户可见中文名:key=工具全名(含 `mcp__` 前缀),
|
|
795
|
+
* value=一句动宾短语(如「查询我的记录」)。server 在 SSE 首帧 tools_meta 下发,
|
|
796
|
+
* 前端 ToolCard 只显示这句——实现细节不进用户界面(README 用户可见信息边界)。
|
|
797
|
+
*/
|
|
798
|
+
toolLabels?: Record<string, string>;
|
|
799
|
+
limits?: {
|
|
800
|
+
maxInputChars?: number; /** Per-user token budget per UTC day. 明示公平限额(非暗闸,):撞闸提示词与权益卡都要写出本数(、)。 */
|
|
801
|
+
dailyTokenQuota?: number;
|
|
802
|
+
/** Abort a run after this many tool rounds (bounds one prompt's loop). */
|
|
803
|
+
maxToolRounds?: number;
|
|
804
|
+
/** 免费用户当日对话轮数上限;缺省或 <=0 = 不限(数值可改)。 */
|
|
805
|
+
freeDailyRuns?: number;
|
|
806
|
+
/** 会员(含 admin)当日上限。 */
|
|
807
|
+
memberDailyRuns?: number;
|
|
808
|
+
/** 会员当日 token 兜底覆写;缺省用 dailyTokenQuota。 */
|
|
809
|
+
memberDailyTokenQuota?: number;
|
|
810
|
+
/** 会员每月发放 token 池(池内免余额,池尽才扣余额)。 */
|
|
811
|
+
memberMonthlyTokenPool?: number;
|
|
812
|
+
/**
|
|
813
|
+
* 按人格(= 账本产品)覆盖上面的额度。缺省继承产品级。
|
|
814
|
+
* 例:声明人格 `freeDailyRuns: 0`(不限轮)但池只有 100 万。
|
|
815
|
+
*/
|
|
816
|
+
personas?: Record<string, {
|
|
817
|
+
freeDailyRuns?: number;
|
|
818
|
+
memberDailyRuns?: number;
|
|
819
|
+
dailyTokenQuota?: number;
|
|
820
|
+
memberDailyTokenQuota?: number;
|
|
821
|
+
memberMonthlyTokenPool?: number;
|
|
822
|
+
}>;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* 授权内核种子策略(策略种子出核):core 不内置业务策略——首启
|
|
826
|
+
* `casbin_rule` 零行时由 `Authz.create` 幂等种入本清单,之后管理页的
|
|
827
|
+
* 增删不被重启重放。obj/act 由产品自己声明,core 不内置任何值。
|
|
828
|
+
* 三向互钉(packages/server/test/authz.test.ts):manifest ≡ 测试
|
|
829
|
+
* fixture ≡ apps/<product>/lib/bank-policy-worlds.mjs 的 SEED_P,改动须同步。
|
|
830
|
+
*/
|
|
831
|
+
authz?: {
|
|
832
|
+
seedPolicies?: Array<{
|
|
833
|
+
sub: string;
|
|
834
|
+
obj: string;
|
|
835
|
+
act: string;
|
|
836
|
+
}>;
|
|
837
|
+
};
|
|
838
|
+
};
|
|
839
|
+
tools?: {
|
|
840
|
+
/** Module whose default export is `(ctx) => ToolDefinition[]`. */
|
|
841
|
+
inline?: string;
|
|
842
|
+
};
|
|
843
|
+
/** MCP servers to connect, keyed by server name (tools appear as `mcp__<name>__<tool>`). */
|
|
844
|
+
mcp?: Record<string, McpServerDecl>;
|
|
845
|
+
/**
|
|
846
|
+
* Tools that need explicit user confirmation before each call (write-ish or
|
|
847
|
+
* costly tools). Exact tool names; an entry ending in `*` matches by prefix
|
|
848
|
+
* (e.g. `mcp__demo__*`). Blocked calls surface to the model as an error result.
|
|
849
|
+
*/
|
|
850
|
+
confirmTools?: string[];
|
|
851
|
+
/**
|
|
852
|
+
* 产品业务路由的声明位。`routes` 指向产品目录内的一个 .ts 模块
|
|
853
|
+
* (相对产品根,必须 `./` 开头),模块导出 `createRoutes()`;main.ts 动态
|
|
854
|
+
* import 并挂到 ServerDeps.productRoutes / productAdminRoutes。
|
|
855
|
+
* 信任级别与 `tools.inline` / `agent.extensions` 相同——都是仓库内代码。
|
|
856
|
+
*/
|
|
857
|
+
server?: {
|
|
858
|
+
routes?: string;
|
|
859
|
+
assembly?: string;
|
|
860
|
+
};
|
|
861
|
+
/**
|
|
862
|
+
* Usage-based billing in integer cents (-8). When present (and the server
|
|
863
|
+
* wires a BillingStore), a chat run needs a positive balance up front and
|
|
864
|
+
* its cost is deducted after the run. Recharge orders are credited by
|
|
865
|
+
* fulfillOrder — operator-confirmed today, a payment-provider webhook later.
|
|
866
|
+
*/
|
|
867
|
+
billing?: {
|
|
868
|
+
/** Price per 1,000 tokens used, in cents. */
|
|
869
|
+
pricePerThousandTokensCents?: number;
|
|
870
|
+
/** Extra cents charged per call of a tool; a key ending in `*` matches by prefix. */
|
|
871
|
+
toolPricesCents?: Record<string, number>;
|
|
872
|
+
/**
|
|
873
|
+
* Demo/development only: POST /api/orders credits the order immediately,
|
|
874
|
+
* standing in for a payment-provider callback. Production keeps it off and
|
|
875
|
+
* fulfills via POST /api/recharge/fulfill (admin or verified webhook).
|
|
876
|
+
*/
|
|
877
|
+
mockAutoFulfill?: boolean;
|
|
878
|
+
/**
|
|
879
|
+
* 可售的会员套餐:键是人格 id(= 账本产品),值是这一期卖什么。
|
|
880
|
+
* 价格由产品定,core 不猜;没在这里声明的人格**买不了**(404/400),
|
|
881
|
+
* 也不会有一天"默认 29 元"混进来。
|
|
882
|
+
*/
|
|
883
|
+
plans?: Record<string, {
|
|
884
|
+
/** 一次购买获得的天数(续期语义:max(now, 现到期) + days)。 */
|
|
885
|
+
days: number;
|
|
886
|
+
/** 价格(分)。与余额同一货币单位,不做汇率/折扣。 */
|
|
887
|
+
priceCents: number;
|
|
888
|
+
}>;
|
|
889
|
+
};
|
|
890
|
+
}
|