@capybara-hq/plugin-sdk 0.1.0-rc.25 → 0.1.0-rc.27

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.
Files changed (50) hide show
  1. package/agent-docs/extension-points/model-provider.md +3 -1
  2. package/agent-docs/extension-points/object-store.md +2 -0
  3. package/dist/cards.d.ts +17 -8
  4. package/dist/cards.js +21 -10
  5. package/dist/channel.d.ts +91 -47
  6. package/dist/channel.js +10 -5
  7. package/dist/connector-auth.d.ts +5 -2
  8. package/dist/connector-auth.js +14 -8
  9. package/dist/connector.d.ts +67 -32
  10. package/dist/ctx.d.ts +41 -23
  11. package/dist/define-extension.d.ts +21 -11
  12. package/dist/define-extension.js +10 -4
  13. package/dist/device-protocol.d.ts +2 -1
  14. package/dist/extension-point.js +1 -1
  15. package/dist/hooks.d.ts +6 -4
  16. package/dist/identity.d.ts +22 -9
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/model-params.d.ts +41 -22
  20. package/dist/model-params.js +28 -15
  21. package/dist/model.d.ts +121 -70
  22. package/dist/model.js +49 -19
  23. package/dist/permissions.d.ts +6 -6
  24. package/dist/permissions.js +8 -32
  25. package/dist/plugin-package.d.ts +79 -38
  26. package/dist/plugin-package.js +57 -29
  27. package/dist/sandbox-linux-runtime-source.d.ts +15 -0
  28. package/dist/sandbox-linux-runtime-source.js +1412 -0
  29. package/dist/sandbox-runtime-source.d.ts +9 -3
  30. package/dist/sandbox-runtime-source.js +16 -4
  31. package/dist/sandbox.d.ts +4 -1
  32. package/dist/sandbox.js +7 -3
  33. package/dist/secret.d.ts +4 -1
  34. package/dist/secret.js +4 -1
  35. package/dist/setup-guide.d.ts +1 -1
  36. package/dist/setup-guide.js +1 -1
  37. package/dist/skill.d.ts +27 -17
  38. package/dist/skill.js +39 -25
  39. package/dist/storage.d.ts +52 -25
  40. package/dist/tool.d.ts +51 -23
  41. package/dist/tool.js +21 -9
  42. package/dist/ui-resolve.d.ts +2 -7
  43. package/dist/ui-resolve.js +7 -19
  44. package/dist/ui-slots.d.ts +1 -3
  45. package/dist/ui-slots.js +0 -9
  46. package/dist/ui.d.ts +63 -49
  47. package/dist/ui.js +36 -22
  48. package/dist/url.d.ts +4 -1
  49. package/dist/url.js +4 -1
  50. package/package.json +1 -1
@@ -8,8 +8,10 @@
8
8
  - Brokered by the platform: yes (extensions use it only through `ctx`)
9
9
  <!-- /generated -->
10
10
 
11
- Contract: ModelProvider (`model.ts`); refs `model-provider@1` and `@2`
11
+ Contract: ModelProvider (`model.ts`); ref `model-provider@2`
12
12
 
13
13
  Map the kernel's messages and tools to the vendor API and stream the result. Do not retry inside the extension; return a `ModelError` with the right kind and let the kernel degrade. History sent to the model is append-only. Declare parameters and media support.
14
14
 
15
+ Messages may carry an `image` or a `document` block, gated by `capabilities.vision` and `capabilities.documents`; the kernel replaces a block the model cannot take with an English placeholder and never sends the bytes. A `file` block is an attachment the model can only reference (an xlsx, say): the kernel resolves it to text before the request, so a provider never receives one. Resolve any block you do not recognize by skipping it. The `size` on an attachment block is display metadata (the UI chip, the reference line) and is never sent to a provider.
16
+
15
17
  See `extensions` for the rules every extension follows.
@@ -12,4 +12,6 @@ Contract: ObjectStore (`storage.ts`)
12
12
 
13
13
  Return `null` for a missing key, reject keys containing `${`, and enforce the size of presigned uploads in the store itself. The kernel adds key prefixes; extensions consume it as `ctx.storage`.
14
14
 
15
+ Optionally implement `uri(key)`: the store's canonical identifier for a key, such as `s3://bucket/key`. It is unsigned, stable and carries no credentials, and is never a presigned URL — the kernel may record it in an event log and show it to a model. A store with no notion of URIs simply leaves it out.
16
+
15
17
  See `extensions` for the rules every extension follows.
package/dist/cards.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type FormAnswer, type InputForm } from "./tool.js";
2
2
  /**
3
- * 渠道中立的 IM 卡片:由内核定义与产出,渠道插件按各自 IM 的原生格式渲染;
4
- * 不支持卡片的渠道用 {@link renderCardAsText} 退回为文本。
3
+ * Channel-neutral IM cards: defined and produced by the kernel, rendered by channel plugins in each
4
+ * IM's native format;
5
+ * channels without card support fall back to text with {@link renderCardAsText}.
5
6
  */
6
7
  export type ChannelCard = {
7
8
  kind: "approval";
@@ -32,7 +33,7 @@ export type ChannelCard = {
32
33
  decidedBy?: string;
33
34
  /** A denied approval: the reason the person gave (plain text, never formatted). */
34
35
  denyReason?: string;
35
- /** 可决定该审批的会话网页链接。 */
36
+ /** Web link to the conversation that can decide this approval. */
36
37
  webUrl: string;
37
38
  } | {
38
39
  kind: "question";
@@ -58,7 +59,10 @@ export type ChannelCard = {
58
59
  url: string;
59
60
  text: string;
60
61
  };
61
- /** 用户在 IM 卡片上的操作,由渠道插件解析后经入站事件交给内核。 */
62
+ /**
63
+ * A user action on an IM card, parsed by the channel plugin and handed to the kernel through an
64
+ * inbound event.
65
+ */
62
66
  export interface CardAction {
63
67
  cardKind: "approval" | "question";
64
68
  cardId: string;
@@ -66,7 +70,10 @@ export interface CardAction {
66
70
  scope?: "once" | "session" | "always";
67
71
  answer?: FormAnswer;
68
72
  }
69
- /** 发往 IM 的一条消息:text 为 Markdown(渠道插件转换为原生富文本),可附卡片。 */
73
+ /**
74
+ * One message sent to an IM: `text` is Markdown (the channel plugin converts it to native rich
75
+ * text); a card may be attached.
76
+ */
70
77
  export interface OutboundMessage {
71
78
  text: string;
72
79
  cards?: ChannelCard[];
@@ -80,7 +87,7 @@ export interface OutboundMessage {
80
87
  export declare function questionRenderableInline(form: InputForm, opts?: {
81
88
  textReply?: boolean;
82
89
  }): boolean;
83
- /** 校验卡片结构,返回问题列表(空 = 合法)。 */
90
+ /** Validates the card structure and returns the list of problems (empty = valid). */
84
91
  export declare function validateChannelCard(card: unknown): string[];
85
92
  /** A UI locale. */
86
93
  export type Locale = "zh" | "en";
@@ -92,7 +99,9 @@ export declare function questionTextReplyHint(mode: "plain" | "mention", locale:
92
99
  */
93
100
  export declare function questionStateLabel(state: string, locale: Locale): string;
94
101
  /**
95
- * 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
96
- * `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
102
+ * The uniform fallback text for channels without card support (links included); the fixed phrases
103
+ * are taken by locale, zh / en. The result is Markdown (put into
104
+ * `OutboundMessage.text`, converted by the channel plugin): model-controllable fields go into code
105
+ * (see `asCode`), so they never produce links.
97
106
  */
98
107
  export declare function renderCardAsText(card: ChannelCard, locale: Locale): string;
package/dist/cards.js CHANGED
@@ -34,7 +34,7 @@ const QUESTION_STATES = ["pending", "answered", "skipped", "expired", "cancelled
34
34
  const TEXT_REPLY = ["plain", "mention"];
35
35
  const ISO_8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
36
36
  const list = (xs) => xs.map((x) => JSON.stringify(x)).join(", ");
37
- /** 校验卡片结构,返回问题列表(空 = 合法)。 */
37
+ /** Validates the card structure and returns the list of problems (empty = valid). */
38
38
  export function validateChannelCard(card) {
39
39
  if (typeof card !== "object" || card === null || Array.isArray(card))
40
40
  return ["card must be an object"];
@@ -97,7 +97,8 @@ export function validateChannelCard(card) {
97
97
  out.push("answerSummary must be a string");
98
98
  if (c.textReply !== undefined)
99
99
  oneOf("textReply", TEXT_REPLY);
100
- // 不能在 IM 内作答的表单(见 questionRenderableInline)同样合法:渠道只渲染网页链接。
100
+ // A form that cannot be answered inside the IM (see questionRenderableInline) is equally
101
+ // valid: the channel renders only the web link.
101
102
  for (const p of validateInputForm(c.form))
102
103
  out.push(`form: ${p}`);
103
104
  return out;
@@ -115,10 +116,14 @@ export function validateChannelCard(card) {
115
116
  }
116
117
  }
117
118
  /**
118
- * 把模型可控的值(审批标题、调用摘要、提问标题、回答摘要)放进代码里,退回文本里它们不会变成链接、强调或 HTML:
119
- * 单行用行内代码,多行用围栏代码块(以换行开头),分隔符都比值里最长的反引号串更长(CommonMark 6.1 / 4.5)。
120
- * 选代码而不是给标点加反斜杠:代码是 CommonMark / GFM 里唯一保证内容按原样显示的写法(反斜杠挡不住 GFM 的裸网址
121
- * 自动链接,各渠道转换器对反斜杠的处理也不一致)。
119
+ * Puts model-controllable values (approval title, call summary, question title, answer summary)
120
+ * into code, so that in the fallback text they do not turn into links, emphasis or HTML:
121
+ * single-line values use inline code, multi-line values a fenced code block (starting with a
122
+ * newline); the delimiters are always longer than the longest backtick run in the value (CommonMark
123
+ * 6.1 / 4.5).
124
+ * Code is chosen over backslash-escaping punctuation because code is the only form CommonMark / GFM
125
+ * guarantee to display content verbatim (a backslash does not stop GFM bare-URL
126
+ * autolinks, and channel converters treat backslashes inconsistently).
122
127
  */
123
128
  function asCode(s) {
124
129
  const v = s.replace(/\r\n?/g, "\n");
@@ -128,11 +133,15 @@ function asCode(s) {
128
133
  return `\n${fence}\n${v}\n${fence}`;
129
134
  }
130
135
  const d = "`".repeat(longest + 1);
131
- // 值以反引号开头 / 结尾、或首尾都是空格时补一个空格(渲染时去掉),否则会与分隔符粘连或被吃掉空格
136
+ // When the value starts / ends with a backtick, or has spaces at both ends, add one space
137
+ // (stripped when rendered); otherwise it would stick to the delimiter or lose its spaces
132
138
  const pad = /^`|`$/.test(v) || (v.startsWith(" ") && v.endsWith(" ")) ? " " : "";
133
139
  return `${d}${pad}${v}${pad}${d}`;
134
140
  }
135
- /** 前缀 + 代码:代码是围栏块(以换行开头)时去掉前缀末尾的空格。 */
141
+ /**
142
+ * Prefix + code: when the code is a fenced block (starting with a newline), drop the trailing space
143
+ * of the prefix.
144
+ */
136
145
  const withCode = (prefix, code) => code.startsWith("\n") ? `${prefix.trimEnd()}${code}` : `${prefix}${code}`;
137
146
  const TEXT = {
138
147
  en: {
@@ -225,8 +234,10 @@ export function questionStateLabel(state, locale) {
225
234
  return states[state] ?? state;
226
235
  }
227
236
  /**
228
- * 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
229
- * `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
237
+ * The uniform fallback text for channels without card support (links included); the fixed phrases
238
+ * are taken by locale, zh / en. The result is Markdown (put into
239
+ * `OutboundMessage.text`, converted by the channel plugin): model-controllable fields go into code
240
+ * (see `asCode`), so they never produce links.
230
241
  */
231
242
  export function renderCardAsText(card, locale) {
232
243
  const t = TEXT[locale] ?? TEXT.en;
package/dist/channel.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import type { ZodTypeAny } from "zod";
2
2
  import type { CardAction, Locale, OutboundMessage } from "./cards.js";
3
3
  /**
4
- * 消息的投递目标。群聊里的 `threadId` 是话题**根消息的 `messageId`**(内核用它把同一话题归到一个会话,
5
- * 回复也投到这个话题):Slack 为插件所定义的根消息 `messageId`(如 `<频道>:<ts>`,ts 即回复的
6
- * `thread_ts`);飞书为根消息的 `message_id`(`root_id`,`om_…`),**不是** `thread_id`(`omt_…`)。私聊不带。
4
+ * The delivery target of a message. In a group chat `threadId` is the **`messageId` of the thread's
5
+ * root message** (the kernel uses it to map one thread to one conversation,
6
+ * and replies are delivered to this thread): for Slack it is the root message `messageId` as the
7
+ * plugin defines it (e.g. `<channel>:<ts>`, where ts is the reply's
8
+ * `thread_ts`); for Lark it is the root message's `message_id` (`root_id`, `om_…`), **not**
9
+ * `thread_id` (`omt_…`). Absent in direct messages.
7
10
  */
8
11
  export interface ChannelTarget {
9
12
  chatId: string;
@@ -11,10 +14,14 @@ export interface ChannelTarget {
11
14
  chatType: "dm" | "group";
12
15
  }
13
16
  /**
14
- * 入站事件的发言人 / 点击者。`tenantId` 为发言人所属企业:Slack 为 team id(Enterprise Grid 下是 team,
15
- * 不是 enterprise),飞书为 `tenant_key`;与连接的租户(`verify` 返回的 `tenantId`,同一口径)不同的人
16
- * (外部联系人、共享频道里的其他企业)内核只允许绑定,不按匿名访客处理。`displayName`、`avatarUrl` 为平台上的
17
- * 显示名与头像(拿得到就带):内核把显示名用在绑定确认页(没有时回落到 externalId)。
17
+ * The speaker / clicker of an inbound event. `tenantId` is the tenant (company) the speaker belongs
18
+ * to: for Slack the team id (under Enterprise Grid it is the team,
19
+ * not the Grid organization), for Lark `tenant_key`; a person whose tenant differs from the
20
+ * connection's tenant (the `tenantId` returned by `verify`, same convention)
21
+ * (an external contact, another company in a shared channel) can only be bound by the kernel, never
22
+ * treated as an anonymous guest. `displayName` and `avatarUrl` are the display name and avatar
23
+ * on the platform (include them when available): the kernel uses the display name on the binding
24
+ * confirmation page (falling back to externalId when absent).
18
25
  */
19
26
  export interface InboundSender {
20
27
  externalId: string;
@@ -38,14 +45,19 @@ export interface InboundSender {
38
45
  locale?: string;
39
46
  }
40
47
  /**
41
- * 渠道交给内核的入站事件。插件的约定:
42
- * - `message.messageId` 在本连接内唯一(内核按它去重);
43
- * - M4 只处理文本:附件、图片、文件等忽略(消息只有附件时不发事件);
44
- * - 用户编辑、撤回 / 删除消息不发事件(忽略);
45
- * - `text` 里去掉 @ 机器人的部分(`mentionsBot` 另行说明是否 @ 了机器人);
46
- * - `card_action`:`messageId` 为卡片所在消息的 id(同一张卡片的多次点击相同);`eventId` 为平台给这次点击的
47
- * 唯一 id(拿得到就带,本连接内唯一:内核按它去重平台重投);群聊里 `target.threadId` 拿得到就带,
48
- * 拿不到时内核取发出该卡片时记下的话题。
48
+ * An inbound event a channel hands to the kernel. The plugin's conventions:
49
+ * - `message.messageId` is unique within this connection (the kernel deduplicates by it);
50
+ * - M4 handles text only: attachments, images, files and the like are ignored (a message with
51
+ * only attachments emits no event);
52
+ * - user edits and message recalls / deletions emit no event (ignored);
53
+ * - the part of `text` that @-mentions the bot is removed (`mentionsBot` states separately
54
+ * whether the bot was @-mentioned);
55
+ * - `card_action`: `messageId` is the id of the message holding the card (the same for repeated
56
+ * clicks on one card); `eventId` is the platform's
57
+ * unique id for this click (include it when available; unique within this connection: the kernel
58
+ * deduplicates platform redeliveries by it); in a group chat include `target.threadId` when
59
+ * available,
60
+ * otherwise the kernel uses the thread recorded when it sent the card.
49
61
  */
50
62
  export type InboundEvent = {
51
63
  type: "message";
@@ -58,26 +70,34 @@ export type InboundEvent = {
58
70
  type: "card_action";
59
71
  target: ChannelTarget;
60
72
  messageId: string;
61
- /** 平台给这次点击的唯一 id(如飞书回调的 event_id、Slack 的 trigger / action 时间戳组合)。 */
73
+ /**
74
+ * The platform's unique id for this click (e.g. the event_id of a Lark callback, or a
75
+ * combination of Slack's trigger / action timestamps).
76
+ */
62
77
  eventId?: string;
63
78
  sender: InboundSender;
64
79
  action: CardAction;
65
80
  }
66
- /** 平台推送人员变动的提示,内核据此触发通讯录同步。 */
81
+ /** The platform pushes a personnel change hint; the kernel triggers a directory sync from it. */
67
82
  | {
68
83
  type: "directory_changed";
69
84
  tenantId: string;
70
85
  };
71
86
  export interface ChannelConnectArgs {
72
87
  connectionId: string;
73
- /** 已按 connectionSchema 校验,含密钥。 */
88
+ /** Already validated against connectionSchema, secrets included. */
74
89
  config: unknown;
75
90
  /**
76
- * 把入站事件交给内核。内核只做去重并把事件持久地排进队列(很快,不在这里处理消息),resolve 即表示内核已经
77
- * 可靠地收下了这条事件:插件**在它 resolve 之后**才向平台确认(ack);reject 时**不要**确认,让平台重投;
78
- * 插件自己不必重试 `onEvent`。去重范围:`message` 按 `messageId`、带 `eventId` 的 `card_action` 按 `eventId`
79
- * (各保留 24 小时)——重投只处理一次;不带 `eventId` 的 `card_action` 不去重(每次都处理,重复的审批 /
80
- * 回答由内核回「已处理」);`directory_changed` 不去重(同步任务本身按分钟合并)。
91
+ * Hands an inbound event to the kernel. The kernel only deduplicates and durably enqueues the
92
+ * event (fast; it does not process the message here); resolving means the kernel has
93
+ * reliably received the event: the plugin acknowledges (acks) to the platform **only after it
94
+ * resolves**; on reject **do not** acknowledge, so the platform redelivers;
95
+ * the plugin need not retry `onEvent` itself. Deduplication scope: `message` by `messageId`, a
96
+ * `card_action` with `eventId` by `eventId`
97
+ * (each kept for 24 hours), so a redelivery is processed once; a `card_action` without `eventId`
98
+ * is not deduplicated (processed every time; a repeated approval /
99
+ * answer gets an "already handled" reply from the kernel); `directory_changed` is not
100
+ * deduplicated (the sync task itself coalesces per minute).
81
101
  */
82
102
  onEvent(e: InboundEvent): Promise<void>;
83
103
  signal: AbortSignal;
@@ -86,8 +106,9 @@ export interface ChannelSendArgs {
86
106
  config: unknown;
87
107
  target: ChannelTarget;
88
108
  /**
89
- * 消息内容。`text` 超过平台单条长度上限时由插件自行拆成多条按序发送,返回**最后一条**的消息 id
90
- * (内核之后编辑的是这条)。
109
+ * The message content. When `text` exceeds the platform's per-message length limit the plugin
110
+ * splits it into several messages sent in order and returns the id of the **last one**
111
+ * (the kernel edits that one afterwards).
91
112
  */
92
113
  message: OutboundMessage;
93
114
  signal: AbortSignal;
@@ -98,9 +119,13 @@ export interface ChannelSendArgs {
98
119
  */
99
120
  locale: Locale;
100
121
  /**
101
- * 幂等键(可选):不超过 40 个 `[A-Za-z0-9_-]` 字符,同一条逻辑消息的每次重试(崩溃后其他副本续投、
102
- * 可重试失败后重发)都相同——内核由「会话 + 事件 seq」或「卡片 + 状态」稳定哈希得到。平台支持幂等发送
103
- * (如飞书的 `uuid`)时插件应原样透传或按平台要求映射,以免重复消息;不支持的平台忽略即可。
122
+ * Idempotency key (optional): at most 40 characters from `[A-Za-z0-9_-]`, identical for every
123
+ * retry of the same logical message (another replica continuing after a crash,
124
+ * a resend after a retryable failure); the kernel derives it as a stable hash of "conversation +
125
+ * event seq" or "card + state".
126
+ * When the platform supports idempotent sends (e.g. Lark's `uuid`) the plugin should pass it
127
+ * through unchanged or map it as the platform requires, to avoid duplicate messages; platforms
128
+ * without support can ignore it.
104
129
  */
105
130
  idempotencyKey?: string;
106
131
  }
@@ -177,13 +202,14 @@ export interface ChannelWebhook {
177
202
  signal: AbortSignal;
178
203
  }): Promise<ChannelWebhookResult>;
179
204
  }
180
- /** 渠道实现(bot 用渠道连接配置)。 */
205
+ /** A channel implementation (the bot uses the channel connection config). */
181
206
  export interface Channel {
182
- /** 渠道连接配置的 schema;密钥字段用 secret()。 */
207
+ /** Schema of the channel connection config; secret fields use secret(). */
183
208
  connectionSchema: ZodTypeAny;
184
209
  /**
185
- * `minEditIntervalMs`:平台允许的同一条消息两次编辑的最小间隔;内核流式草稿的更新间隔取
186
- * `max(1000, minEditIntervalMs)`。
210
+ * `minEditIntervalMs`: the minimum interval the platform allows between two edits of the same
211
+ * message; the kernel's streaming-draft update interval is
212
+ * `max(1000, minEditIntervalMs)`.
187
213
  */
188
214
  features: {
189
215
  cards: boolean;
@@ -199,16 +225,24 @@ export interface Channel {
199
225
  botName: string;
200
226
  tenantId: string;
201
227
  }>;
202
- /** 长连接循环:signal 中止时返回;断线自行重连。 */
228
+ /**
229
+ * Long-connection loop: returns when `signal` aborts; reconnects by itself after a disconnect.
230
+ */
203
231
  connect(args: ChannelConnectArgs): Promise<void>;
204
- /** 失败时抛 {@link ChannelSendError} 说明能否重试;其他异常内核按可重试处理(次数有限)。 */
232
+ /**
233
+ * On failure throw {@link ChannelSendError} to say whether it can be retried; the kernel treats
234
+ * other exceptions as retryable (a limited number of times).
235
+ */
205
236
  send(args: ChannelSendArgs): Promise<{
206
237
  messageId: string;
207
238
  }>;
208
239
  /**
209
- * features.edit 为 false 的渠道不会被调用。失败语义同 send。新文本超过平台单条上限、无法改成一条时
210
- * 抛不可重试的 {@link ChannelSendError}(`reason: "too_large"`):内核改为把完整文本作为新消息 `send`
211
- * (由插件拆分)。
240
+ * Never called for channels whose features.edit is false. Failure semantics are the same as send.
241
+ * When the new text exceeds the platform's per-message limit and cannot be turned into one
242
+ * message,
243
+ * throw a non-retryable {@link ChannelSendError} (`reason: "too_large"`): the kernel then `send`s
244
+ * the full text as a new message
245
+ * (split by the plugin).
212
246
  */
213
247
  update(args: ChannelSendArgs & {
214
248
  messageId: string;
@@ -221,18 +255,26 @@ export interface Channel {
221
255
  webhook?: ChannelWebhook;
222
256
  }
223
257
  /**
224
- * 不可重试失败的原因(`ChannelSendError.reason`),内核据此处理:
225
- * - `auth`:凭据失效 / 权限被收回 → 记连接 `last_error`,停止该会话本轮的投递;
226
- * - `target_gone`:机器人被移出群、会话不存在 → 停止该会话本轮的投递,不计入毒事件;
227
- * - `rejected`(内容被平台拒绝)、`too_large`(拆分后仍超限,如卡片过大)→ 按同一事件失败计数,满 3 次跳过它。
228
- * 未给出原因的按 `rejected` 处理。
258
+ * Reasons for a non-retryable failure (`ChannelSendError.reason`), which the kernel handles
259
+ * accordingly:
260
+ * - `auth`: credentials invalid / permission revoked -> record the connection's `last_error` and
261
+ * stop delivering for this conversation in this round;
262
+ * - `target_gone`: the bot was removed from the group or the conversation does not exist -> stop
263
+ * delivering for this conversation in this round, not counted as a poison event;
264
+ * - `rejected` (content rejected by the platform), `too_large` (still over the limit after
265
+ * splitting, e.g. a card that is too large) -> counted as failures of the same event; after 3 the
266
+ * event is skipped.
267
+ * A failure without a reason is treated as `rejected`.
229
268
  */
230
269
  export type ChannelSendFailure = "auth" | "target_gone" | "rejected" | "too_large";
231
270
  /**
232
- * 渠道发送 / 更新消息失败的分类:`retryable` 为 true(限流、平台 5xx、网络)时内核退避后重试,
233
- * `retryAfterMs` 为平台给出的建议等待时长;为 false 时按 `reason`(见 {@link ChannelSendFailure})处理。
234
- * 编辑流式草稿不可重试地失败(`auth` / `target_gone` 除外)时,内核改为把完整文本作为新消息发出。
235
- * 消息里不要带凭据。
271
+ * Classification of a channel send / update failure: when `retryable` is true (rate limit, platform
272
+ * 5xx, network) the kernel retries after backoff,
273
+ * `retryAfterMs` is the wait the platform suggests; when false it is handled by `reason` (see
274
+ * {@link ChannelSendFailure}).
275
+ * When editing a streaming draft fails non-retryably (except `auth` / `target_gone`), the kernel
276
+ * sends the full text as a new message instead.
277
+ * Do not put credentials in the message.
236
278
  */
237
279
  export declare class ChannelSendError extends Error {
238
280
  readonly retryable: boolean;
@@ -245,5 +287,7 @@ export declare class ChannelSendError extends Error {
245
287
  cause?: unknown;
246
288
  });
247
289
  }
248
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
290
+ /**
291
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
292
+ */
249
293
  export declare function isChannelSendError(e: unknown): e is ChannelSendError;
package/dist/channel.js CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
- * 渠道发送 / 更新消息失败的分类:`retryable` 为 true(限流、平台 5xx、网络)时内核退避后重试,
3
- * `retryAfterMs` 为平台给出的建议等待时长;为 false 时按 `reason`(见 {@link ChannelSendFailure})处理。
4
- * 编辑流式草稿不可重试地失败(`auth` / `target_gone` 除外)时,内核改为把完整文本作为新消息发出。
5
- * 消息里不要带凭据。
2
+ * Classification of a channel send / update failure: when `retryable` is true (rate limit, platform
3
+ * 5xx, network) the kernel retries after backoff,
4
+ * `retryAfterMs` is the wait the platform suggests; when false it is handled by `reason` (see
5
+ * {@link ChannelSendFailure}).
6
+ * When editing a streaming draft fails non-retryably (except `auth` / `target_gone`), the kernel
7
+ * sends the full text as a new message instead.
8
+ * Do not put credentials in the message.
6
9
  */
7
10
  export class ChannelSendError extends Error {
8
11
  retryable;
@@ -18,7 +21,9 @@ export class ChannelSendError extends Error {
18
21
  this.reason = opts.reason;
19
22
  }
20
23
  }
21
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
24
+ /**
25
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
26
+ */
22
27
  export function isChannelSendError(e) {
23
28
  return (e instanceof Error &&
24
29
  e.name === "ChannelSendError" &&
@@ -1,5 +1,8 @@
1
1
  import { z } from "zod";
2
- /** 认证方式:只有类型与非密钥字段;凭据值走内核的 `credential` / 凭据接口。 */
2
+ /**
3
+ * Authentication method: only the type and non-secret fields; credential values go through the
4
+ * kernel's `credential` / credentials API.
5
+ */
3
6
  export declare const ConnectorAuthSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
7
  type: z.ZodLiteral<"none">;
5
8
  }, z.core.$strict>, z.ZodObject<{
@@ -62,5 +65,5 @@ export declare const ConnectorAuthSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
62
65
  }>>;
63
66
  tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
67
  }, z.core.$strict>], "type">;
65
- /** 认证预设({@link ConnectorAuthSchema} 的输出)。 */
68
+ /** Auth preset (the output of {@link ConnectorAuthSchema}). */
66
69
  export type ConnectorAuthPreset = z.infer<typeof ConnectorAuthSchema>;
@@ -1,21 +1,24 @@
1
1
  import { z } from "zod";
2
2
  /*
3
- * 连接器的认证方式(只有类型与非密钥字段,凭据值不在这里):内核的连接器安装接口与企业目录里的连接器模板
4
- * (`ConnectorTemplateSpec.auth`)共用这一个 schema。各分支都是 strict:多出的字段(如 `token`)一律拒绝,
5
- * 所以合法的认证预设里不可能夹带凭据。OAuth 端点是否必须 https 由内核按部署配置再校验。
3
+ * A connector's authentication method (only the type and non-secret fields; credential values are
4
+ * not here): the kernel's connector install API and the connector templates in the catalog
5
+ * (`ConnectorTemplateSpec.auth`) share this one schema. Every branch is strict: extra fields (such
6
+ * as `token`) are always rejected,
7
+ * so a valid auth preset cannot smuggle in a credential. Whether OAuth endpoints must be https is
8
+ * checked again by the kernel per deployment config.
6
9
  */
7
- /** HTTP 头名(RFC 9110 token)。 */
10
+ /** HTTP header name (RFC 9110 token). */
8
11
  const HeaderName = z
9
12
  .string()
10
13
  .min(1)
11
14
  .max(100)
12
15
  .regex(/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/, "Invalid header name");
13
16
  const Ownership = z.enum(["org", "personal"]);
14
- /** OAuth 端点(https 等由内核按部署配置再校验)。 */
17
+ /** OAuth endpoint (https etc. is checked again by the kernel per deployment config). */
15
18
  const OAuthUrl = z.url().max(2000);
16
- /** 令牌端点的客户端认证方式(有客户端密钥时)。 */
19
+ /** Client authentication method at the token endpoint (when there is a client secret). */
17
20
  const TokenAuthMethod = z.enum(["client_secret_basic", "client_secret_post"]);
18
- /** OAuth scope(RFC 6749 §3.3 scope-token)。 */
21
+ /** OAuth scope (RFC 6749 §3.3 scope-token). */
19
22
  const Scopes = z
20
23
  .array(z
21
24
  .string()
@@ -36,7 +39,10 @@ const TokenTypes = z
36
39
  .regex(/^[A-Za-z][A-Za-z0-9_.-]*$/, "Invalid token type")
37
40
  .refine((t) => t.toLowerCase() !== "dpop", "DPoP tokens are not bearer tokens"))
38
41
  .max(5);
39
- /** 认证方式:只有类型与非密钥字段;凭据值走内核的 `credential` / 凭据接口。 */
42
+ /**
43
+ * Authentication method: only the type and non-secret fields; credential values go through the
44
+ * kernel's `credential` / credentials API.
45
+ */
40
46
  export const ConnectorAuthSchema = z.discriminatedUnion("type", [
41
47
  z.object({ type: z.literal("none") }).strict(),
42
48
  z.object({ type: z.literal("bearer"), ownership: Ownership }).strict(),