@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90
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 +3 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +2 -0
- package/agent-docs/extension-points/model-provider.md +5 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extension-points/trigger-source.md +19 -0
- package/agent-docs/extensions.md +98 -4
- package/agent-docs/plugin-format.md +45 -10
- package/agent-docs/setup.md +54 -0
- package/api/plugin-sdk.api.md +5983 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/agents-ctx.d.ts +116 -0
- package/dist/agents-ctx.js +22 -0
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +121 -13
- package/dist/cards.js +161 -19
- package/dist/channel.d.ts +133 -47
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +344 -31
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +18 -12
- package/dist/define-extension.js +18 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +348 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +286 -49
- package/dist/device-protocol.js +766 -89
- package/dist/device-provider.d.ts +820 -0
- package/dist/device-provider.js +432 -0
- package/dist/device-service.d.ts +204 -0
- package/dist/device-service.js +291 -0
- package/dist/dial-in.d.ts +286 -0
- package/dist/dial-in.js +213 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +8 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +46 -9
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +185 -22
- package/dist/hooks.js +6 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/inbox.d.ts +103 -0
- package/dist/inbox.js +173 -0
- package/dist/index.d.ts +30 -4
- package/dist/index.js +30 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +295 -77
- package/dist/model.js +249 -21
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +95 -25
- package/dist/permissions.js +175 -54
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +30 -6
- package/dist/plugin-manifest.js +147 -55
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +480 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +216 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +25 -9
- package/dist/theme-assets.js +87 -47
- package/dist/theme-tokens.generated.d.ts +40 -12
- package/dist/theme-tokens.generated.js +36 -8
- package/dist/theme.d.ts +56 -10
- package/dist/theme.js +117 -23
- package/dist/tool.d.ts +242 -28
- package/dist/tool.js +135 -13
- package/dist/trigger-source.d.ts +35 -0
- package/dist/trigger-source.js +2 -0
- package/dist/triggers.d.ts +88 -0
- package/dist/triggers.js +71 -0
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +374 -0
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +27 -5
- package/dist/ui-slots.js +112 -19
- package/dist/ui.d.ts +203 -64
- package/dist/ui.js +117 -23
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +62 -4
- package/schemas/plugin.v1.schema.json +74 -143
- package/schemas/theme.v1.schema.json +77 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
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,19 +202,51 @@ export interface ChannelWebhook {
|
|
|
177
202
|
signal: AbortSignal;
|
|
178
203
|
}): Promise<ChannelWebhookResult>;
|
|
179
204
|
}
|
|
180
|
-
/**
|
|
205
|
+
/** One conversation artifact handed to {@link Channel.sendFile}. */
|
|
206
|
+
export interface ChannelFile {
|
|
207
|
+
/** File name shown to the user. Model-controlled: never interpret it as markup, a path or a mention. */
|
|
208
|
+
name: string;
|
|
209
|
+
contentType: string;
|
|
210
|
+
/** Chosen by the kernel (an image type within the image cap, else a file). */
|
|
211
|
+
kind: "image" | "file";
|
|
212
|
+
data: Uint8Array;
|
|
213
|
+
}
|
|
214
|
+
/** Arguments of {@link Channel.sendFile}: one file for one message; the whole file is in memory. */
|
|
215
|
+
export interface ChannelSendFileArgs {
|
|
216
|
+
config: unknown;
|
|
217
|
+
target: ChannelTarget;
|
|
218
|
+
file: ChannelFile;
|
|
219
|
+
signal: AbortSignal;
|
|
220
|
+
locale: Locale;
|
|
221
|
+
/** Same semantics as {@link ChannelSendArgs.idempotencyKey}. */
|
|
222
|
+
idempotencyKey?: string;
|
|
223
|
+
}
|
|
224
|
+
/** A channel implementation (the bot uses the channel connection config). */
|
|
181
225
|
export interface Channel {
|
|
182
|
-
/**
|
|
226
|
+
/** Schema of the channel connection config; secret fields use secret(). */
|
|
183
227
|
connectionSchema: ZodTypeAny;
|
|
184
228
|
/**
|
|
185
|
-
* `minEditIntervalMs
|
|
186
|
-
*
|
|
229
|
+
* `minEditIntervalMs`: the minimum interval the platform allows between two edits of the same
|
|
230
|
+
* message; the kernel's streaming-draft update interval is
|
|
231
|
+
* `max(1000, minEditIntervalMs)`.
|
|
232
|
+
*
|
|
233
|
+
* `files`: present iff `sendFile` is implemented; the kernel never hands a file larger than
|
|
234
|
+
* `maxBytes`, and sends `kind: "image"` only within `imageMaxBytes ?? maxBytes`.
|
|
235
|
+
*
|
|
236
|
+
* `progress`: the plugin renders the `progress` `ChannelCard` natively (send and update).
|
|
237
|
+
* Absent or false: the kernel sends a run's progress card as Markdown text built by
|
|
238
|
+
* `renderCardAsText` instead, and edits that text message in place.
|
|
187
239
|
*/
|
|
188
240
|
features: {
|
|
189
241
|
cards: boolean;
|
|
190
242
|
edit: boolean;
|
|
191
243
|
threads: boolean;
|
|
244
|
+
progress?: boolean;
|
|
192
245
|
minEditIntervalMs?: number;
|
|
246
|
+
files?: {
|
|
247
|
+
maxBytes: number;
|
|
248
|
+
imageMaxBytes?: number;
|
|
249
|
+
};
|
|
193
250
|
};
|
|
194
251
|
verify(args: {
|
|
195
252
|
config: unknown;
|
|
@@ -199,20 +256,39 @@ export interface Channel {
|
|
|
199
256
|
botName: string;
|
|
200
257
|
tenantId: string;
|
|
201
258
|
}>;
|
|
202
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Long-connection loop: returns when `signal` aborts; reconnects by itself after a disconnect.
|
|
261
|
+
*/
|
|
203
262
|
connect(args: ChannelConnectArgs): Promise<void>;
|
|
204
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* On failure throw {@link ChannelSendError} to say whether it can be retried; the kernel treats
|
|
265
|
+
* other exceptions as retryable (a limited number of times).
|
|
266
|
+
*/
|
|
205
267
|
send(args: ChannelSendArgs): Promise<{
|
|
206
268
|
messageId: string;
|
|
207
269
|
}>;
|
|
208
270
|
/**
|
|
209
|
-
* features.edit
|
|
210
|
-
*
|
|
211
|
-
*
|
|
271
|
+
* Never called for channels whose features.edit is false. Failure semantics are the same as send.
|
|
272
|
+
* When the new text exceeds the platform's per-message limit and cannot be turned into one
|
|
273
|
+
* message,
|
|
274
|
+
* throw a non-retryable {@link ChannelSendError} (`reason: "too_large"`): the kernel then `send`s
|
|
275
|
+
* the full text as a new message
|
|
276
|
+
* (split by the plugin).
|
|
212
277
|
*/
|
|
213
278
|
update(args: ChannelSendArgs & {
|
|
214
279
|
messageId: string;
|
|
215
280
|
}): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Optional file delivery: one message per file; the kernel picks `kind`; an extension may send an
|
|
283
|
+
* `image` as a file when the platform refuses it as an image, never the reverse; `messageId`
|
|
284
|
+
* when the platform returns it; failures as {@link ChannelSendError} (`send`); never put an
|
|
285
|
+
* upload URL in an error. Throw a missing upload permission or scope as a non-retryable
|
|
286
|
+
* {@link ChannelSendError} with `reason: "rejected"`, never `auth`: `auth` stops the whole
|
|
287
|
+
* delivery of the conversation, text included, while `rejected` only turns this file into a link.
|
|
288
|
+
*/
|
|
289
|
+
sendFile?(args: ChannelSendFileArgs): Promise<{
|
|
290
|
+
messageId?: string;
|
|
291
|
+
}>;
|
|
216
292
|
/**
|
|
217
293
|
* Optional webhook inbound (see {@link ChannelWebhook}). Only connections of plugins that
|
|
218
294
|
* implement it can be switched from the default long connection to webhook mode; a connection in
|
|
@@ -221,18 +297,26 @@ export interface Channel {
|
|
|
221
297
|
webhook?: ChannelWebhook;
|
|
222
298
|
}
|
|
223
299
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* - `
|
|
227
|
-
*
|
|
228
|
-
*
|
|
300
|
+
* Reasons for a non-retryable failure (`ChannelSendError.reason`), which the kernel handles
|
|
301
|
+
* accordingly:
|
|
302
|
+
* - `auth`: credentials invalid / permission revoked -> record the connection's `last_error` and
|
|
303
|
+
* stop delivering for this conversation in this round;
|
|
304
|
+
* - `target_gone`: the bot was removed from the group or the conversation does not exist -> stop
|
|
305
|
+
* delivering for this conversation in this round, not counted as a poison event;
|
|
306
|
+
* - `rejected` (content rejected by the platform), `too_large` (still over the limit after
|
|
307
|
+
* splitting, e.g. a card that is too large) -> counted as failures of the same event; after 3 the
|
|
308
|
+
* event is skipped.
|
|
309
|
+
* A failure without a reason is treated as `rejected`.
|
|
229
310
|
*/
|
|
230
311
|
export type ChannelSendFailure = "auth" | "target_gone" | "rejected" | "too_large";
|
|
231
312
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
313
|
+
* Classification of a channel send / update failure: when `retryable` is true (rate limit, platform
|
|
314
|
+
* 5xx, network) the kernel retries after backoff,
|
|
315
|
+
* `retryAfterMs` is the wait the platform suggests; when false it is handled by `reason` (see
|
|
316
|
+
* {@link ChannelSendFailure}).
|
|
317
|
+
* When editing a streaming draft fails non-retryably (except `auth` / `target_gone`), the kernel
|
|
318
|
+
* sends the full text as a new message instead.
|
|
319
|
+
* Do not put credentials in the message.
|
|
236
320
|
*/
|
|
237
321
|
export declare class ChannelSendError extends Error {
|
|
238
322
|
readonly retryable: boolean;
|
|
@@ -245,5 +329,7 @@ export declare class ChannelSendError extends Error {
|
|
|
245
329
|
cause?: unknown;
|
|
246
330
|
});
|
|
247
331
|
}
|
|
248
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
|
|
334
|
+
*/
|
|
249
335
|
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" &&
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client stylesheet rule (client extensions spec §4.1, §7.2): one function both sides run, so
|
|
3
|
+
* a stylesheet that packs cleanly imports cleanly. `capybara-plugin pack` wraps every file in
|
|
4
|
+
* `@layer extensions { … }` ({@link wrapClientCss}) and checks the wrapped text; the kernel checks
|
|
5
|
+
* the stored bytes again at import, because a tgz can be written by hand. A file must be one
|
|
6
|
+
* `@layer extensions` block, may not `@import`, and a URL may name only an asset of the plugin
|
|
7
|
+
* (`../assets/<path>`, a file of `client.assets`), a `data:` URL or a `#fragment`. Any other URL,
|
|
8
|
+
* relative ones included, is refused: the stylesheet is served from
|
|
9
|
+
* `/api/v1/client/<plugin>/<build>/styles/`, so `../../../../…` would reach the kernel's own
|
|
10
|
+
* routes with the viewer's cookies.
|
|
11
|
+
*
|
|
12
|
+
* Two passes, both must pass:
|
|
13
|
+
* - a plain-text pass over the escape-decoded file (`cssRemoteProblem`);
|
|
14
|
+
* - a tokenizer that follows the CSS Syntax tokenization (comments, strings, escapes, url tokens)
|
|
15
|
+
* closely enough that every brace it skips is one a browser skips too: the file must start with
|
|
16
|
+
* `@layer extensions {` and the block that opens must close at the file's last character, so no
|
|
17
|
+
* rule lands outside the layer. Every `url(…)` (token or string) is checked after decoding
|
|
18
|
+
* escapes, and an `@import` at-keyword is refused however it is spelled.
|
|
19
|
+
*
|
|
20
|
+
* Two rules close the spellings a plain string check would miss:
|
|
21
|
+
* - URLs are trimmed with CSS whitespace only (space, tab, LF, CR, FF), and a file holding any other
|
|
22
|
+
* whitespace, a zero-width character (U+200B-U+200D, U+2060) or U+FEFF anywhere, escaped or not,
|
|
23
|
+
* is refused: JavaScript's `trim()` strips an NBSP that CSS and the URL parser keep, so
|
|
24
|
+
* `url("\a0 data:/../../v1")` would pass as `data:` and resolve to `/api/v1`;
|
|
25
|
+
* - functions that turn a plain string (or a `var()`) into a URL or reach outside the stylesheet are
|
|
26
|
+
* refused outright: `image-set(var(--u) 1x)` takes its URL from a custom property no string check
|
|
27
|
+
* can see. Plugins write `url(../assets/x)` directly.
|
|
28
|
+
*/
|
|
29
|
+
/** A stylesheet as the packer stores it: wrapped in `@layer extensions { … }` (spec §4.1). */
|
|
30
|
+
export declare function wrapClientCss(css: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* The problem of a client stylesheet as stored (see the file header), or undefined when it is one
|
|
33
|
+
* `@layer extensions` block with no `@import` and every URL a `#fragment`, a `data:` URL or one of
|
|
34
|
+
* the plugin's `assets` (paths relative to `assets/`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function clientCssProblem(css: string, assets: ReadonlySet<string>): string | undefined;
|