@capybara-hq/plugin-sdk 0.1.0-rc.26 → 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.
- package/agent-docs/extension-points/model-provider.md +1 -1
- package/dist/cards.d.ts +17 -8
- package/dist/cards.js +21 -10
- package/dist/channel.d.ts +91 -47
- package/dist/channel.js +10 -5
- package/dist/connector-auth.d.ts +5 -2
- package/dist/connector-auth.js +14 -8
- package/dist/connector.d.ts +67 -32
- package/dist/ctx.d.ts +41 -23
- package/dist/define-extension.d.ts +21 -11
- package/dist/define-extension.js +10 -4
- package/dist/device-protocol.d.ts +2 -1
- package/dist/extension-point.js +1 -1
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +96 -64
- package/dist/model.js +25 -14
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +8 -32
- package/dist/plugin-package.d.ts +79 -38
- package/dist/plugin-package.js +57 -29
- package/dist/sandbox-linux-runtime-source.d.ts +15 -0
- package/dist/sandbox-linux-runtime-source.js +1412 -0
- package/dist/sandbox-runtime-source.d.ts +9 -3
- package/dist/sandbox-runtime-source.js +16 -4
- package/dist/sandbox.d.ts +4 -1
- package/dist/sandbox.js +7 -3
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-guide.d.ts +1 -1
- package/dist/setup-guide.js +1 -1
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +39 -25
- package/dist/storage.d.ts +45 -25
- package/dist/tool.d.ts +51 -23
- package/dist/tool.js +21 -9
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +1 -3
- package/dist/ui-slots.js +0 -9
- package/dist/ui.d.ts +63 -49
- package/dist/ui.js +36 -22
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
- Brokered by the platform: yes (extensions use it only through `ctx`)
|
|
9
9
|
<!-- /generated -->
|
|
10
10
|
|
|
11
|
-
Contract: ModelProvider (`model.ts`);
|
|
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
|
|
package/dist/cards.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type FormAnswer, type InputForm } from "./tool.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
96
|
-
*
|
|
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
|
-
//
|
|
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
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
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
|
-
*
|
|
229
|
-
*
|
|
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
* -
|
|
46
|
-
* - `
|
|
47
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
88
|
+
/** Already validated against connectionSchema, secrets included. */
|
|
74
89
|
config: unknown;
|
|
75
90
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
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
|
-
/**
|
|
205
|
+
/** A channel implementation (the bot uses the channel connection config). */
|
|
181
206
|
export interface Channel {
|
|
182
|
-
/**
|
|
207
|
+
/** Schema of the channel connection config; secret fields use secret(). */
|
|
183
208
|
connectionSchema: ZodTypeAny;
|
|
184
209
|
/**
|
|
185
|
-
* `minEditIntervalMs
|
|
186
|
-
*
|
|
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
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* Long-connection loop: returns when `signal` aborts; reconnects by itself after a disconnect.
|
|
230
|
+
*/
|
|
203
231
|
connect(args: ChannelConnectArgs): Promise<void>;
|
|
204
|
-
/**
|
|
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
|
|
210
|
-
*
|
|
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
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* - `
|
|
227
|
-
*
|
|
228
|
-
*
|
|
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
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
-
/**
|
|
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" &&
|
package/dist/connector-auth.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
/**
|
|
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
|
-
/**
|
|
68
|
+
/** Auth preset (the output of {@link ConnectorAuthSchema}). */
|
|
66
69
|
export type ConnectorAuthPreset = z.infer<typeof ConnectorAuthSchema>;
|
package/dist/connector-auth.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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(),
|