@capybara-hq/plugin-sdk 0.1.0-rc.85 → 0.1.0-rc.87

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.
@@ -10,8 +10,10 @@
10
10
 
11
11
  Contract: TriggerSource (`trigger-source.ts`), with `ctx.triggers` (`triggers.ts`)
12
12
 
13
- Declare the event types the extension emits in `permissions.triggers.emit` (lower-case dotted names such as `item.created`, at most 64) and implement `TriggerSource.events()` with one `TriggerEventDeclaration` per type: a name, whether the event is directed at one agent, and its facts (a type, a name and whether automations may filter on it). Emit with `ctx.triggers.emit(event)`; the result says whether the `dedupeKey` was already seen (`duplicate`). An event carries the org, the subject (kind, id, title, optional url), scalar or string-list facts, a summary of at most 4096 UTF-8 bytes for the agent, and optionally the cause (the tool call or the account) and an audience for directed events. `emit` throws `TriggerError`: `type_not_declared`, `invalid_event` or `org_disabled`.
13
+ Declare the event types the extension emits in `permissions.triggers.emit` (lower-case dotted names such as `item.created`, at most 64) and implement `TriggerSource.events()` with one `TriggerEventDeclaration` per type: a name, whether the event is directed at one agent, and its facts (a type, a name and whether automations may filter on it). Emit with `ctx.triggers.emit(event)`; the result says whether the `dedupeKey` was already seen (`duplicate`). An event carries the org, the subject (kind, id, title, optional url), scalar or string-list facts, a summary of at most 4096 UTF-8 bytes for the agent, and optionally the cause (the tool call, a handle made from one, or the account) and an audience for directed events. `emit` throws `TriggerError`: `type_not_declared`, `invalid_event` or `org_disabled`. An event that must not be lost is emitted from a `ctx.queue` job, where no tool call context exists: in the tool call, get `await ctx.triggers.causeOf(call)` (a handle valid for 24 hours, bound to the call's org and run and to this extension), put it in the job's payload, and emit with `cause: { handle }`, so the event keeps the call's chain depth and self-trigger check.
14
14
 
15
15
  `visible` answers which of the given accounts may see a subject; the kernel only wakes agents of accounts it lists, and a throw or a missing answer means nobody. `subjectLink` optionally gives people a link to the subject. Automation filters are conjunctions over facts: `eq` compares scalars, `in` matches a scalar fact against a list, `contains` matches a list fact against a scalar, and a missing fact never matches.
16
16
 
17
+ A directed event (its declaration says so, and `audience` names a person and an agent) never reaches automations people made: it runs only through the audience person's acceptance rule for the source (`auto`, `confirm` or `off`; the person sets it on their own page and the org sets the default), so an assignment may be offered, accepted at once, or not accepted; the `run.lifecycle` hook reports the outcome (see `extensions`).
18
+
17
19
  See `extensions` for the rules every extension follows.
@@ -107,6 +107,25 @@ ctx.setup.check("bot-token", {
107
107
  - The platform runs checks only when a person or an agent asks, caches results for five minutes,
108
108
  times a run out after 10 seconds and redacts known secrets from results.
109
109
 
110
+ ## Inbox, people and run notices
111
+
112
+ - `ctx.inbox` (`permissions.inbox: true`) posts a personal item for one active member of an org that
113
+ enabled the extension: a title, a short body, a link under `/p/<extension name>/` and up to three
114
+ actions, each naming a UI action of the extension that the kernel calls as the person who clicked
115
+ (actions must be idempotent). Pass a `dedupeKey` to keep one open item per subject; items expire
116
+ (30 days by default, 90 at most) and the person's push settings apply. `ctx.inbox.resolve` closes
117
+ an item the extension posted. Errors are `InboxError` (`invalid_item`, `org_disabled`, `not_found`).
118
+ - `ctx.agents.usableBy`, `ctx.conversations.bySubject` and `ctx.people.get` / `search` read org
119
+ facts for pages (`permissions.agents`, `conversations`, `people`; each call names an `orgId`, and
120
+ the extension must be enabled there). They return ids, names and avatars, never emails or
121
+ conversation content.
122
+ - The `run.lifecycle` hook (`permissions.hooks`) tells the extension each phase of a run of a
123
+ conversation about its subject: `started`, `waiting` (on a person), `resumed` (that wait
124
+ cleared), `finished`, `failed` or `aborted`; and that directed work was not run
125
+ (`offer_declined`, `reason` `off`, `declined`, `paused`, `expired` or `undelivered`). It is
126
+ delivered at least once: make the handler idempotent and treat it as a hint. For events about
127
+ your subjects see `trigger-source`.
128
+
110
129
  ## Extension points
111
130
 
112
131
  An extension *provides* a point (`provides`) or *consumes* one (`requires`, or `optional`). Refs
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Read-only org facts an extension needs to build people-facing pages (collaboration spec): the
3
+ * agents a member may use, the conversations that serve one of the extension's own subjects, and
4
+ * the members' names and avatars. Each member of `ctx` sits behind its own permission key
5
+ * (`permissions.agents`, `permissions.conversations`, `permissions.people`); every call names the
6
+ * org and runs in its scope, and the extension must be enabled there.
7
+ */
8
+ import type { BuiltinAvatarPresetId } from "./avatar-presets.js";
9
+ /**
10
+ * An avatar a page can draw, structurally the same as the design system's `AvatarValue` (what
11
+ * `Avatar` and `PrincipalPicker` take; the type is copied because the SDK imports no design
12
+ * package): a built-in preset, an image (`src` is a path the web app serves, such as
13
+ * `/api/v1/accounts/<id>/avatar?v=…`, or an absolute URL), or none (the initial is drawn).
14
+ */
15
+ export type AvatarValue = {
16
+ kind: "preset";
17
+ id: BuiltinAvatarPresetId;
18
+ } | {
19
+ kind: "image";
20
+ src: string;
21
+ } | null;
22
+ /** The most account ids one {@link PeopleCtx.get} call takes. */
23
+ export declare const PEOPLE_GET_MAX = 200;
24
+ /** The most results one {@link PeopleCtx.search} call returns (a larger `limit` is clamped). */
25
+ export declare const PEOPLE_SEARCH_MAX = 50;
26
+ /** The most conversations one {@link ConversationsCtx.bySubject} call returns (newest first). */
27
+ export declare const CONVERSATIONS_BY_SUBJECT_MAX = 200;
28
+ /** An agent a member may use. */
29
+ export interface UsableAgent {
30
+ id: string;
31
+ name: string;
32
+ /** A preset stays a preset; an upload, an external image or a theme preset is an image. */
33
+ avatar: AvatarValue;
34
+ }
35
+ /**
36
+ * `ctx.agents` (requires `permissions.agents: { read: true }`).
37
+ */
38
+ export interface AgentsCtx {
39
+ /**
40
+ * The agents `accountId` may use in the org (their own, the org's and those shared with them).
41
+ * An account that is not an active member of the org gets `[]`.
42
+ */
43
+ usableBy(args: {
44
+ orgId: string;
45
+ accountId: string;
46
+ }): Promise<UsableAgent[]>;
47
+ }
48
+ /** What a conversation of a subject is doing now. */
49
+ export type SubjectConversationState = "idle" | "running" | "waiting";
50
+ /** A conversation serving a subject: metadata only, never its content. */
51
+ export interface SubjectConversation {
52
+ id: string;
53
+ ownerAccountId: string;
54
+ agentId: string;
55
+ /** From the latest run: queued or running is `running`, waiting on something is `waiting`. */
56
+ state: SubjectConversationState;
57
+ /** ISO time of the conversation's last activity. */
58
+ lastActivityAt: string;
59
+ }
60
+ /**
61
+ * `ctx.conversations` (requires `permissions.conversations: { subjects: true }`).
62
+ */
63
+ export interface ConversationsCtx {
64
+ /**
65
+ * The live conversations of the org whose subject is `{ source: this extension, kind, id }`
66
+ * (set by `subject`-mode event automations), newest activity first, at most
67
+ * {@link CONVERSATIONS_BY_SUBJECT_MAX}. Another extension's subjects are never returned.
68
+ */
69
+ bySubject(args: {
70
+ orgId: string;
71
+ subject: {
72
+ kind: string;
73
+ id: string;
74
+ };
75
+ }): Promise<SubjectConversation[]>;
76
+ }
77
+ /** A member as {@link PeopleCtx.get} returns it: no email or other profile field. */
78
+ export interface PersonView {
79
+ id: string;
80
+ name: string;
81
+ avatar: AvatarValue;
82
+ /** False once the account is disabled (it is still a member until removed). */
83
+ active: boolean;
84
+ }
85
+ /**
86
+ * `ctx.people` (requires `permissions.people: { read: true }`): members of the org only.
87
+ */
88
+ export interface PeopleCtx {
89
+ /**
90
+ * The given accounts that are members of the org (others are dropped), at most
91
+ * {@link PEOPLE_GET_MAX} ids.
92
+ */
93
+ get(args: {
94
+ orgId: string;
95
+ accountIds: string[];
96
+ }): Promise<PersonView[]>;
97
+ /**
98
+ * Active members whose display name contains `query` (case-insensitive), by name; an empty
99
+ * `query` returns active members up to the limit. `limit` defaults to 20 and is clamped to
100
+ * {@link PEOPLE_SEARCH_MAX}.
101
+ */
102
+ search(args: {
103
+ orgId: string;
104
+ query: string;
105
+ limit?: number;
106
+ }): Promise<Pick<PersonView, "id" | "name" | "avatar">[]>;
107
+ }
108
+ /** Why a read of `ctx.agents`, `ctx.conversations` or `ctx.people` was refused. */
109
+ export type CtxReadErrorCode = "invalid_args" | "org_disabled";
110
+ /** A call of `ctx.agents` / `ctx.conversations` / `ctx.people` was refused. */
111
+ export declare class CtxReadError extends Error {
112
+ readonly code: CtxReadErrorCode;
113
+ constructor(code: CtxReadErrorCode, message: string, opts?: {
114
+ cause?: unknown;
115
+ });
116
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Read-only org facts an extension needs to build people-facing pages (collaboration spec): the
3
+ * agents a member may use, the conversations that serve one of the extension's own subjects, and
4
+ * the members' names and avatars. Each member of `ctx` sits behind its own permission key
5
+ * (`permissions.agents`, `permissions.conversations`, `permissions.people`); every call names the
6
+ * org and runs in its scope, and the extension must be enabled there.
7
+ */
8
+ /** The most account ids one {@link PeopleCtx.get} call takes. */
9
+ export const PEOPLE_GET_MAX = 200;
10
+ /** The most results one {@link PeopleCtx.search} call returns (a larger `limit` is clamped). */
11
+ export const PEOPLE_SEARCH_MAX = 50;
12
+ /** The most conversations one {@link ConversationsCtx.bySubject} call returns (newest first). */
13
+ export const CONVERSATIONS_BY_SUBJECT_MAX = 200;
14
+ /** A call of `ctx.agents` / `ctx.conversations` / `ctx.people` was refused. */
15
+ export class CtxReadError extends Error {
16
+ code;
17
+ constructor(code, message, opts) {
18
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
19
+ this.name = "CtxReadError";
20
+ this.code = code;
21
+ }
22
+ }
package/dist/ctx.d.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import type { Kysely } from "kysely";
2
+ import type { AgentsCtx, ConversationsCtx, PeopleCtx } from "./agents-ctx.js";
2
3
  import type { DeviceServiceSpec, DeviceServiceStatus, ServiceBlockedHost } from "./device-provider.js";
3
4
  import type { DevicesCtx, DialInChannel } from "./dial-in.js";
4
5
  import type { ExtensionPointRef } from "./extension-point.js";
5
6
  import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
6
7
  import type { RouteCaller } from "./http-access.js";
8
+ import type { InboxCtx } from "./inbox.js";
7
9
  import type { ImageAspectRatio, ImageMediaType, ImageSize, ModelEmbeddingInfo, ModelImageGenerationInfo, ModelKind } from "./model.js";
8
10
  import type { ExtensionNet } from "./net.js";
9
11
  import type { SetupCheckDefinition } from "./setup-check.js";
10
12
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
11
13
  import type { ToolCallContext, ToolHandler, ToolSpec, ToolWatcher } from "./tool.js";
12
14
  import type { TriggersCtx } from "./triggers.js";
13
- import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
15
+ import type { EmbedClaims, JsonValue, UiActionArgs, UiActionResult, UiQueryArgs, UiRenderArgs, UiView } from "./ui.js";
14
16
  /** Logger interface. */
15
17
  export interface Logger {
16
18
  info(msg: string, fields?: Record<string, unknown>): void;
@@ -379,6 +381,18 @@ export interface ExtensionContext {
379
381
  ui: {
380
382
  view(id: string, render: (args: UiRenderArgs) => Promise<UiView>): void;
381
383
  action(id: string, handler: (args: UiActionArgs) => Promise<UiActionResult>): void;
384
+ /**
385
+ * Registers the data source of `usePluginQuery` for a component (only during `setup`). `id`
386
+ * must be a component id declared in `permissions.ui.components`; the kernel refuses any other
387
+ * id. Queries work in any org-scoped component slot (`org.page`, conversation and agent slots
388
+ * alike). The result is JSON of at most `UI_LIMITS.componentQueryBytes` bytes and the call's
389
+ * params at most `UI_LIMITS.componentQueryParamsBytes`. Push refresh reaches queries only
390
+ * through org-stream invalidations (`invalidate({ orgId, contribution })` without a
391
+ * `conversationId`): a conversation-scoped invalidation does not refetch them, so a component
392
+ * in a conversation slot refetches through an action result's `invalidate` query names (or
393
+ * its own `refetch`).
394
+ */
395
+ query(id: string, handler: (args: UiQueryArgs) => Promise<JsonValue>): void;
382
396
  invalidate(target: {
383
397
  /** Required, except for a `platform.page` contribution, where it must be omitted. */
384
398
  orgId?: string;
@@ -432,6 +446,20 @@ export interface ExtensionContext {
432
446
  * {@link TriggersCtx}).
433
447
  */
434
448
  triggers: TriggersCtx;
449
+ /**
450
+ * Posts personal inbox items and resolves them (requires `permissions.inbox`, see
451
+ * {@link InboxCtx}).
452
+ */
453
+ inbox: InboxCtx;
454
+ /** The agents a member may use (requires `permissions.agents`, see {@link AgentsCtx}). */
455
+ agents: AgentsCtx;
456
+ /**
457
+ * The conversations serving the extension's own subjects (requires `permissions.conversations`,
458
+ * see {@link ConversationsCtx}).
459
+ */
460
+ conversations: ConversationsCtx;
461
+ /** Names and avatars of an org's members (requires `permissions.people`, see {@link PeopleCtx}). */
462
+ people: PeopleCtx;
435
463
  provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
436
464
  /**
437
465
  * The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
@@ -67,7 +67,11 @@ export interface FilePreviewConversationArgs extends FilePreviewArgsBase {
67
67
  source: "conversation";
68
68
  orgId: string;
69
69
  accountId: string;
70
- conversationId: string;
70
+ /**
71
+ * The conversation the file is previewed in; absent for a library file previewed outside a
72
+ * conversation (the Files page).
73
+ */
74
+ conversationId?: string;
71
75
  }
72
76
  /**
73
77
  * A preview on a share page: there is no account and no conversation. A previewer that needs the
package/dist/hooks.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { ContentBlock, ImageSize, ModelRequest, ModelUsage } from "./model.
4
4
  * `HOOK_MOUNT_POINTS` (`session.*`, `agent.preStep`) stay reserved: they validate in a manifest but
5
5
  * cannot be registered yet.
6
6
  */
7
- export declare const HOOKS_AVAILABLE: readonly ["model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
7
+ export declare const HOOKS_AVAILABLE: readonly ["model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted", "run.lifecycle"];
8
8
  /** Lifecycle mount points: observe-only notices that something was removed. */
9
9
  export declare const LIFECYCLE_HOOKS: readonly ["org.member_removed", "agent.deleted", "org.deleted"];
10
10
  /** A mount point that `ctx.hooks.on` accepts. */
@@ -302,6 +302,52 @@ export interface AgentDeletedPayload {
302
302
  export interface OrgDeletedPayload {
303
303
  orgId: string;
304
304
  }
305
+ /**
306
+ * `run.lifecycle`: what happened to a run of a conversation that has a subject, or to directed work
307
+ * the kernel did not run (collaboration spec §4.8). Observe-only, delivered durably through a
308
+ * queue, at least once, after the change committed, and only to the plugin named by the
309
+ * conversation's subject `source` (for `offer_declined`, the plugin that emitted the event), when
310
+ * it declares `run.lifecycle` in `permissions.hooks` and the org has it enabled (checked when the
311
+ * change commits and again at delivery); `call.config` is the extension's effective config for the
312
+ * org. A handler that fails never affects the run. Handlers must be idempotent. The payload carries
313
+ * ids only. Compact runs (context compaction) are never reported.
314
+ *
315
+ * - `started`: a run of the conversation was created (queued).
316
+ * - `waiting`: the run suspended on a person (`waitingOn`: an `approval`, or `input`: a question
317
+ * or a connect card).
318
+ * - `resumed`: the person's wait cleared (answered, decided or timed out) and the run continues;
319
+ * one per wait, like `waiting`.
320
+ * - `finished`: the run completed. `failed`: it failed. `aborted`: a person or the kernel stopped
321
+ * it.
322
+ * - `offer_declined`: directed work was not run (`reason`): the person's rule is `off`, the person
323
+ * `declined` the offer, their acceptance automation is `paused`, the offer `expired` unanswered
324
+ * (seven days), or the event stayed `undelivered` (the kernel gave up routing it). No run and no
325
+ * conversation: `accountId` and `agentId` are the event's audience.
326
+ */
327
+ export interface RunLifecyclePayload {
328
+ orgId: string;
329
+ /** The run's trigger account; for `offer_declined` the event's audience person. */
330
+ accountId: string;
331
+ agentId: string;
332
+ /** Absent for `offer_declined`. */
333
+ agentVersion?: number;
334
+ /** Absent for `offer_declined`. */
335
+ conversationId?: string;
336
+ /** Absent for `offer_declined`. */
337
+ runId?: string;
338
+ phase: "started" | "waiting" | "resumed" | "finished" | "failed" | "aborted" | "offer_declined";
339
+ /** The conversation's subject (or the directed event's subject). */
340
+ subject: {
341
+ kind: string;
342
+ id: string;
343
+ };
344
+ /** Set for `waiting` and `resumed`. */
345
+ waitingOn?: "approval" | "input";
346
+ /** Set for `offer_declined`. */
347
+ reason?: RunLifecycleDeclineReason;
348
+ }
349
+ /** Why directed work was not run (`run.lifecycle` `offer_declined`). */
350
+ export type RunLifecycleDeclineReason = "declined" | "off" | "paused" | "expired" | "undelivered";
305
351
  /** Payload type of each mount point. */
306
352
  export interface HookPayloads {
307
353
  "model.request": ModelRequestHookPayload;
@@ -312,6 +358,7 @@ export interface HookPayloads {
312
358
  "org.member_removed": OrgMemberRemovedPayload;
313
359
  "agent.deleted": AgentDeletedPayload;
314
360
  "org.deleted": OrgDeletedPayload;
361
+ "run.lifecycle": RunLifecyclePayload;
315
362
  }
316
363
  /**
317
364
  * What a hook returns: nothing, or `{ deny: reason }`. A deny only takes effect for a `policy` hook
package/dist/hooks.js CHANGED
@@ -12,6 +12,7 @@ export const HOOKS_AVAILABLE = [
12
12
  "org.member_removed",
13
13
  "agent.deleted",
14
14
  "org.deleted",
15
+ "run.lifecycle",
15
16
  ];
16
17
  /** Lifecycle mount points: observe-only notices that something was removed. */
17
18
  export const LIFECYCLE_HOOKS = ["org.member_removed", "agent.deleted", "org.deleted"];
@@ -0,0 +1,95 @@
1
+ import type { LocalizedName } from "./plugin-package.js";
2
+ /**
3
+ * One button on an inbox item: clicking it calls `uiAction.actionId` of the extension's UI
4
+ * contribution `uiAction.contribution` (registered with `ctx.ui.action`) as the person who
5
+ * clicked, with `payload`, then resolves the item. The contribution must be one of an org-wide
6
+ * slot (such as `org.page`): the call carries no conversation or agent. The action must be
7
+ * idempotent: delivery is at least once (a click whose result was lost may be pressed again).
8
+ */
9
+ export interface InboxAction {
10
+ /** Unique within the item ({@link INBOX_ID_RE}). */
11
+ id: string;
12
+ label: LocalizedName;
13
+ style?: "primary" | "danger";
14
+ uiAction: {
15
+ contribution: string;
16
+ actionId: string;
17
+ payload?: unknown;
18
+ };
19
+ }
20
+ /** A personal inbox item an extension posts through `ctx.inbox.post`. */
21
+ export interface InboxPost {
22
+ orgId: string;
23
+ /** The one person the item is for: an active member of `orgId`. */
24
+ accountId: string;
25
+ /** What kind of item it is, for the extension ({@link INBOX_KIND_RE}). */
26
+ kind: string;
27
+ /** At most {@link INBOX_LIMITS}.titleChars characters. */
28
+ title: string;
29
+ /** At most {@link INBOX_LIMITS}.bodyChars characters. */
30
+ body?: string;
31
+ /**
32
+ * An in-app path opened from the item: an extension's item may only link to its own pages,
33
+ * `/p/<extension name>/...` (at most {@link INBOX_LIMITS}.linkChars characters).
34
+ */
35
+ link?: string;
36
+ /** At most {@link INBOX_ACTIONS_MAX}. */
37
+ actions?: InboxAction[];
38
+ /**
39
+ * Seconds until the item expires and leaves the inbox (default
40
+ * {@link INBOX_LIMITS}.defaultExpirySeconds, at most {@link INBOX_LIMITS}.maxExpirySeconds).
41
+ */
42
+ expiresInSeconds?: number;
43
+ /**
44
+ * Idempotency key: while an item of this extension with the same key is open for the same
45
+ * person in the same org, a post returns that item instead of adding another.
46
+ */
47
+ dedupeKey?: string;
48
+ }
49
+ /** `ctx.inbox` (requires `permissions.inbox`): personal inbox items. */
50
+ export interface InboxCtx {
51
+ /** Posts an item for one person (see {@link InboxPost}); the person's push settings apply. */
52
+ post(p: InboxPost): Promise<{
53
+ itemId: string;
54
+ }>;
55
+ /** Resolves an open item this extension posted (an item already closed is left as it is). */
56
+ resolve(args: {
57
+ orgId: string;
58
+ itemId: string;
59
+ }): Promise<void>;
60
+ }
61
+ export type InboxErrorCode = "invalid_item" | "org_disabled" | "not_found";
62
+ /** A {@link InboxCtx} call was refused. */
63
+ export declare class InboxError extends Error {
64
+ readonly code: InboxErrorCode;
65
+ constructor(code: InboxErrorCode, message: string, opts?: {
66
+ cause?: unknown;
67
+ });
68
+ }
69
+ /** The most actions one inbox item carries. */
70
+ export declare const INBOX_ACTIONS_MAX = 3;
71
+ /** Limits of an inbox item. */
72
+ export declare const INBOX_LIMITS: {
73
+ readonly titleChars: 200;
74
+ readonly bodyChars: 2000;
75
+ readonly linkChars: 512;
76
+ readonly kindChars: 64;
77
+ readonly labelChars: 40;
78
+ readonly idChars: 64;
79
+ readonly dedupeKeyChars: 200;
80
+ /** UTF-8 bytes of one action's `payload` as JSON (as a UI button's). */
81
+ readonly payloadBytes: 2000;
82
+ readonly defaultExpirySeconds: number;
83
+ readonly maxExpirySeconds: number;
84
+ };
85
+ /** The shape of an item's `kind`: dotted lower-case words. */
86
+ export declare const INBOX_KIND_RE: RegExp;
87
+ /** The shape of an action id, a contribution id and a UI action id. */
88
+ export declare const INBOX_ID_RE: RegExp;
89
+ /**
90
+ * Checks a post before it is stored; returns error codes (empty = valid): `missing_<field>`,
91
+ * `<field>_too_long`, `kind_invalid`, `link_invalid` (not a path of the extension's own pages
92
+ * `/p/<plugin>/`), `too_many_actions`, `action_invalid`, `action_duplicate`, `payload_too_large`,
93
+ * `expiry_invalid`. `plugin` is the posting extension's name.
94
+ */
95
+ export declare function validateInboxPost(p: InboxPost, plugin: string): string[];
package/dist/inbox.js ADDED
@@ -0,0 +1,152 @@
1
+ import { UI_LIMITS } from "./ui.js";
2
+ /** A {@link InboxCtx} call was refused. */
3
+ export class InboxError extends Error {
4
+ code;
5
+ constructor(code, message, opts) {
6
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
7
+ this.name = "InboxError";
8
+ this.code = code;
9
+ }
10
+ }
11
+ /** The most actions one inbox item carries. */
12
+ export const INBOX_ACTIONS_MAX = 3;
13
+ /** Limits of an inbox item. */
14
+ export const INBOX_LIMITS = {
15
+ titleChars: 200,
16
+ bodyChars: 2000,
17
+ linkChars: 512,
18
+ kindChars: 64,
19
+ labelChars: 40,
20
+ idChars: 64,
21
+ dedupeKeyChars: 200,
22
+ /** UTF-8 bytes of one action's `payload` as JSON (as a UI button's). */
23
+ payloadBytes: UI_LIMITS.payloadBytes,
24
+ defaultExpirySeconds: 30 * 24 * 3600,
25
+ maxExpirySeconds: 90 * 24 * 3600,
26
+ };
27
+ /** The shape of an item's `kind`: dotted lower-case words. */
28
+ export const INBOX_KIND_RE = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$/;
29
+ /** The shape of an action id, a contribution id and a UI action id. */
30
+ export const INBOX_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
31
+ /**
32
+ * Checks a post before it is stored; returns error codes (empty = valid): `missing_<field>`,
33
+ * `<field>_too_long`, `kind_invalid`, `link_invalid` (not a path of the extension's own pages
34
+ * `/p/<plugin>/`), `too_many_actions`, `action_invalid`, `action_duplicate`, `payload_too_large`,
35
+ * `expiry_invalid`. `plugin` is the posting extension's name.
36
+ */
37
+ export function validateInboxPost(p, plugin) {
38
+ const errs = [];
39
+ const str = (v) => typeof v === "string";
40
+ const blank = (v) => !str(v) || v.trim() === "";
41
+ if (blank(p.orgId))
42
+ errs.push("missing_org_id");
43
+ if (blank(p.accountId))
44
+ errs.push("missing_account_id");
45
+ if (blank(p.kind))
46
+ errs.push("missing_kind");
47
+ else if (p.kind.length > INBOX_LIMITS.kindChars || !INBOX_KIND_RE.test(p.kind))
48
+ errs.push("kind_invalid");
49
+ if (blank(p.title))
50
+ errs.push("missing_title");
51
+ else if (p.title.length > INBOX_LIMITS.titleChars)
52
+ errs.push("title_too_long");
53
+ if (p.body !== undefined) {
54
+ if (!str(p.body))
55
+ errs.push("body_invalid");
56
+ else if (p.body.length > INBOX_LIMITS.bodyChars)
57
+ errs.push("body_too_long");
58
+ }
59
+ if (p.link !== undefined) {
60
+ if (!str(p.link) || p.link.length > INBOX_LIMITS.linkChars || !ownPageLink(p.link, plugin))
61
+ errs.push("link_invalid");
62
+ }
63
+ if (p.dedupeKey !== undefined) {
64
+ if (blank(p.dedupeKey) || p.dedupeKey.length > INBOX_LIMITS.dedupeKeyChars)
65
+ errs.push("dedupe_key_invalid");
66
+ }
67
+ if (p.expiresInSeconds !== undefined) {
68
+ const s = p.expiresInSeconds;
69
+ if (typeof s !== "number" || !Number.isInteger(s) || s < 1 || s > INBOX_LIMITS.maxExpirySeconds)
70
+ errs.push("expiry_invalid");
71
+ }
72
+ if (p.actions !== undefined) {
73
+ if (!Array.isArray(p.actions))
74
+ errs.push("action_invalid");
75
+ else {
76
+ if (p.actions.length > INBOX_ACTIONS_MAX)
77
+ errs.push("too_many_actions");
78
+ const ids = new Set();
79
+ for (const a of p.actions) {
80
+ const problem = actionProblem(a);
81
+ if (problem !== null) {
82
+ errs.push(problem);
83
+ continue;
84
+ }
85
+ if (ids.has(a.id))
86
+ errs.push("action_duplicate");
87
+ ids.add(a.id);
88
+ }
89
+ }
90
+ }
91
+ return [...new Set(errs)];
92
+ }
93
+ const idOk = (v) => typeof v === "string" && v.length <= INBOX_LIMITS.idChars && INBOX_ID_RE.test(v);
94
+ const labelOk = (v) => typeof v === "string" && v.trim() !== "" && v.length <= INBOX_LIMITS.labelChars;
95
+ function actionProblem(a) {
96
+ if (typeof a !== "object" || a === null)
97
+ return "action_invalid";
98
+ const x = a;
99
+ if (!idOk(x.id))
100
+ return "action_invalid";
101
+ if (typeof x.label !== "object" || x.label === null)
102
+ return "action_invalid";
103
+ if (!labelOk(x.label.zh) || !labelOk(x.label.en))
104
+ return "action_invalid";
105
+ if (x.style !== undefined && x.style !== "primary" && x.style !== "danger")
106
+ return "action_invalid";
107
+ const u = x.uiAction;
108
+ if (typeof u !== "object" || u === null)
109
+ return "action_invalid";
110
+ if (!idOk(u.contribution) || !idOk(u.actionId))
111
+ return "action_invalid";
112
+ if (u.payload !== undefined) {
113
+ let json;
114
+ try {
115
+ json = JSON.stringify(u.payload);
116
+ }
117
+ catch {
118
+ return "action_invalid";
119
+ }
120
+ if (json === undefined)
121
+ return "action_invalid";
122
+ if (new TextEncoder().encode(json).length > INBOX_LIMITS.payloadBytes)
123
+ return "payload_too_large";
124
+ }
125
+ return null;
126
+ }
127
+ /**
128
+ * Whether `link` is a path of the extension's own pages: `/p/<plugin>/` followed by at least one
129
+ * character, with no backslash or control character, no dot segment (`.`, `..`, also spelled with
130
+ * `%2e` in any case), and a path that still starts with `/p/<plugin>/` once a URL parser resolved
131
+ * it.
132
+ */
133
+ function ownPageLink(link, plugin) {
134
+ const prefix = `/p/${plugin}/`;
135
+ if (!link.startsWith(prefix) || link.length === prefix.length)
136
+ return false;
137
+ if (/[\\\p{Cc}]/u.test(link))
138
+ return false;
139
+ const path = link.split(/[?#]/, 1)[0] ?? "";
140
+ const dot = (s) => {
141
+ const d = s.replace(/%2e/gi, ".");
142
+ return d === "." || d === "..";
143
+ };
144
+ if (path.split("/").some(dot))
145
+ return false;
146
+ try {
147
+ return new URL(link, "http://x").pathname.startsWith(prefix);
148
+ }
149
+ catch {
150
+ return false;
151
+ }
152
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.85";
1
+ export declare const SDK_VERSION = "0.1.0-rc.87";
2
2
  export * from "./agent-template.js";
3
+ export * from "./agents-ctx.js";
3
4
  export * from "./avatar-presets.js";
4
5
  export * from "./bootstrap.js";
5
6
  export * from "./cards.js";
@@ -25,6 +26,7 @@ export * from "./git-hosts.js";
25
26
  export * from "./hooks.js";
26
27
  export * from "./http-access.js";
27
28
  export * from "./identity.js";
29
+ export * from "./inbox.js";
28
30
  export * from "./marketplace.js";
29
31
  export * from "./model.js";
30
32
  export * from "./model-params.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export const SDK_VERSION = "0.1.0-rc.85";
1
+ export const SDK_VERSION = "0.1.0-rc.87";
2
2
  export * from "./agent-template.js";
3
+ export * from "./agents-ctx.js";
3
4
  export * from "./avatar-presets.js";
4
5
  export * from "./bootstrap.js";
5
6
  export * from "./cards.js";
@@ -25,6 +26,7 @@ export * from "./git-hosts.js";
25
26
  export * from "./hooks.js";
26
27
  export * from "./http-access.js";
27
28
  export * from "./identity.js";
29
+ export * from "./inbox.js";
28
30
  export * from "./marketplace.js";
29
31
  export * from "./model.js";
30
32
  export * from "./model-params.js";
package/dist/model.d.ts CHANGED
@@ -145,8 +145,8 @@ export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/pl
145
145
  export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
146
146
  export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
147
147
  /**
148
- * The source of media content: `base64` is the bytes themselves, `ref` is a reference to a kernel
149
- * attachment.
148
+ * The source of media content: `base64` is the bytes themselves, `ref` names a kernel file by its
149
+ * id (a library file the conversation refers to, or a file the kernel stored for a tool result).
150
150
  * The event log stores only `ref` (bytes never enter the log); when building a request the kernel
151
151
  * resolves `ref` into `base64`, so plugins only ever receive `base64`.
152
152
  */
@@ -155,7 +155,7 @@ export type MediaSource = {
155
155
  data: string;
156
156
  } | {
157
157
  kind: "ref";
158
- attachmentId: string;
158
+ fileId: string;
159
159
  };
160
160
  /**
161
161
  * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
@@ -241,11 +241,13 @@ export declare function clipMediaName(name: string, max?: number): string;
241
241
  export declare function hasControlChars(s: string): boolean;
242
242
  /** Whether the attachment id is a UUID (any version, case-insensitive). */
243
243
  export declare function isAttachmentId(s: unknown): s is string;
244
+ /** Whether the file id (a media `ref`'s `fileId`) is a UUID (any version, case-insensitive). */
245
+ export declare function isFileId(s: unknown): s is string;
244
246
  /**
245
247
  * Validates an image / document / file block, returning a list of errors (empty means valid): the
246
248
  * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
247
249
  * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
248
- * `attachmentId` is a UUID; `name`, when present, is a string of at most
250
+ * `fileId` is a UUID; `name`, when present, is a string of at most
249
251
  * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
250
252
  * non-negative integer (display metadata, never sent by a plugin).
251
253
  */
package/dist/model.js CHANGED
@@ -110,6 +110,10 @@ export function hasControlChars(s) {
110
110
  export function isAttachmentId(s) {
111
111
  return typeof s === "string" && UUID_RE.test(s);
112
112
  }
113
+ /** Whether the file id (a media `ref`'s `fileId`) is a UUID (any version, case-insensitive). */
114
+ export function isFileId(s) {
115
+ return typeof s === "string" && UUID_RE.test(s);
116
+ }
113
117
  /** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
114
118
  const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
115
119
  const MEDIA = {
@@ -123,7 +127,7 @@ const MEDIA = {
123
127
  * Validates an image / document / file block, returning a list of errors (empty means valid): the
124
128
  * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
125
129
  * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
126
- * `attachmentId` is a UUID; `name`, when present, is a string of at most
130
+ * `fileId` is a UUID; `name`, when present, is a string of at most
127
131
  * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
128
132
  * non-negative integer (display metadata, never sent by a plugin).
129
133
  */
@@ -166,8 +170,8 @@ export function validateMediaBlock(b) {
166
170
  }
167
171
  const source = src;
168
172
  if (source.kind === "ref") {
169
- if (!isAttachmentId(source.attachmentId)) {
170
- errs.push(`${o.type} source.attachmentId must be a UUID`);
173
+ if (!isFileId(source.fileId)) {
174
+ errs.push(`${o.type} source.fileId must be a UUID file id`);
171
175
  }
172
176
  }
173
177
  else if (source.kind === "base64") {
@@ -83,11 +83,32 @@ export interface ExtensionPermissions {
83
83
  triggers?: {
84
84
  emit: string[];
85
85
  };
86
+ /**
87
+ * `ctx.inbox`: personal inbox items for the members of orgs that enabled the extension, each
88
+ * linking only to the extension's own pages, with buttons that call its UI actions as the
89
+ * person who clicks.
90
+ */
91
+ inbox?: boolean;
92
+ /** `ctx.agents`: which agents a member of an org that enabled the extension may use. */
93
+ agents?: {
94
+ read: true;
95
+ };
96
+ /**
97
+ * `ctx.conversations`: the conversations serving the extension's own subjects (metadata only,
98
+ * never content).
99
+ */
100
+ conversations?: {
101
+ subjects: true;
102
+ };
103
+ /** `ctx.people`: names and avatars of an org's members (never email or other profile fields). */
104
+ people?: {
105
+ read: true;
106
+ };
86
107
  }
87
108
  /** The most services `permissions.deviceAccess.services` may list. */
88
109
  export declare const DEVICE_ACCESS_MAX_SERVICES = 4;
89
110
  /** Hook mount points (a closed list, see the overall design 2.4). */
90
- export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
111
+ export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted", "run.lifecycle"];
91
112
  /** A hook mount point name. */
92
113
  export type HookMountPoint = (typeof HOOK_MOUNT_POINTS)[number];
93
114
  /** A platform API not declared in the manifest was used. */
@@ -4,7 +4,7 @@ import { POLICY_HOOKS } from "./hooks.js";
4
4
  import { HTTP_ACCESS } from "./http-access.js";
5
5
  import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
6
6
  import { TRIGGER_MAX_TYPES, TRIGGER_TYPE_RE } from "./triggers.js";
7
- import { UI_ICONS } from "./ui.js";
7
+ import { UI_ICONS, UI_PAGE_FRAMES, UI_PAGE_NAVS } from "./ui.js";
8
8
  import { isCompactForm, parseSlotRef, uiSlot } from "./ui-slots.js";
9
9
  /** The most services `permissions.deviceAccess.services` may list. */
10
10
  export const DEVICE_ACCESS_MAX_SERVICES = 4;
@@ -21,6 +21,7 @@ export const HOOK_MOUNT_POINTS = [
21
21
  "org.member_removed",
22
22
  "agent.deleted",
23
23
  "org.deleted",
24
+ "run.lifecycle",
24
25
  ];
25
26
  const HOOKS = new Set(HOOK_MOUNT_POINTS);
26
27
  /** A platform API not declared in the manifest was used. */
@@ -52,6 +53,10 @@ const KEYS = new Set([
52
53
  "dialIn",
53
54
  "deviceAccess",
54
55
  "triggers",
56
+ "inbox",
57
+ "agents",
58
+ "conversations",
59
+ "people",
55
60
  ]);
56
61
  const POLICY = new Set(POLICY_HOOKS);
57
62
  const METHODS = new Set(["GET", "POST", "PUT", "DELETE"]);
@@ -87,11 +92,21 @@ export function validatePermissions(plugin, p, provides = []) {
87
92
  if (!KEYS.has(k))
88
93
  errs.push(`unknown permissions key "${k}"`);
89
94
  }
90
- for (const k of ["secrets", "storage", "client"]) {
95
+ for (const k of ["secrets", "storage", "client", "inbox"]) {
91
96
  if (p[k] !== undefined && typeof p[k] !== "boolean") {
92
97
  errs.push(`permissions.${k} must be a boolean`);
93
98
  }
94
99
  }
100
+ for (const [k, flag] of [
101
+ ["agents", "read"],
102
+ ["conversations", "subjects"],
103
+ ["people", "read"],
104
+ ]) {
105
+ const v = p[k];
106
+ if (v !== undefined &&
107
+ (!isObj(v) || Object.keys(v).some((x) => x !== flag) || v[flag] !== true))
108
+ errs.push(`permissions.${k} must be { ${flag}: true }`);
109
+ }
95
110
  if (p.tools !== undefined)
96
111
  strList("permissions.tools", p.tools, errs);
97
112
  if (p.hooks !== undefined) {
@@ -343,6 +358,20 @@ export function validateUiContributions(ui, permissions) {
343
358
  if (seen.has(id))
344
359
  errs.push(`ui has duplicate id "${id}"`);
345
360
  seen.set(id, c.kind);
361
+ if (c.frame !== undefined || c.nav !== undefined) {
362
+ const onPage = slotRef?.id === "org.page" && c.kind === "component";
363
+ for (const [k, allowed] of [
364
+ ["frame", UI_PAGE_FRAMES],
365
+ ["nav", UI_PAGE_NAVS],
366
+ ]) {
367
+ if (c[k] === undefined)
368
+ continue;
369
+ if (!onPage)
370
+ errs.push(`ui "${id}" ${k} is only allowed on a component of the org.page slot`);
371
+ else if (!allowed.includes(c[k]))
372
+ errs.push(`ui "${id}" ${k} must be one of ${allowed.join(", ")}`);
373
+ }
374
+ }
346
375
  if (c.kind === "view") {
347
376
  if (c.path !== undefined)
348
377
  errs.push(`ui "${id}" path is only allowed for kind embed`);
@@ -8,9 +8,15 @@ export interface TriggerSubject {
8
8
  title: string;
9
9
  url?: string;
10
10
  }
11
- /** Who caused an event: a tool call of the extension, or an account acting outside a call. */
11
+ /**
12
+ * Who caused an event: a tool call of the extension (`call`, the context the kernel passed to the
13
+ * handler), a handle the kernel made from such a call ({@link TriggersCtx.causeOf}; for an event
14
+ * emitted later, from a queue job), or an account acting outside a call.
15
+ */
12
16
  export type TriggerCause = {
13
17
  call: ToolCallContext;
18
+ } | {
19
+ handle: string;
14
20
  } | {
15
21
  accountId: string;
16
22
  };
@@ -45,6 +51,16 @@ export interface TriggersCtx {
45
51
  eventId: string;
46
52
  duplicate: boolean;
47
53
  }>;
54
+ /**
55
+ * A serializable cause for an event emitted after the tool call returned: an opaque handle for
56
+ * `call` (the context the kernel passed to the handler) that the kernel binds to the call's org
57
+ * and run and to this extension, valid for 24 hours. Pass it in the `ctx.queue` job's payload
58
+ * and emit with `cause: { handle }`: the event keeps the call's chain depth and self-trigger
59
+ * check. One handle may be used for several events of that org. Throws `TriggerError`
60
+ * (`invalid_event`) for a context the kernel did not make; `emit` refuses an expired handle, or
61
+ * one of another org or extension, the same way.
62
+ */
63
+ causeOf(call: ToolCallContext): Promise<string>;
48
64
  }
49
65
  export type TriggerErrorCode = "type_not_declared" | "invalid_event" | "org_disabled";
50
66
  /** A {@link TriggersCtx} call was refused. */
package/dist/ui-slots.js CHANGED
@@ -85,13 +85,13 @@ const SLOT_DATA = [
85
85
  accepts: ["view", "embed", "component"],
86
86
  cardinality: "list",
87
87
  minRole: "member",
88
- args: [],
88
+ args: ["params"],
89
89
  density: "regular",
90
90
  icon: "optional",
91
91
  compact: "kept",
92
92
  description: {
93
- en: "A full page in the organization navigation.",
94
- zh: "组织导航中的完整页面。",
93
+ en: "A full page in the organization navigation. Only component contributions receive `params` (the page query string); views and embeds do not.",
94
+ zh: "组织导航中的完整页面。只有 component 贡献会收到 `params`(页面查询串),view 与 embed 不会。",
95
95
  },
96
96
  },
97
97
  {
package/dist/ui.d.ts CHANGED
@@ -55,7 +55,26 @@ export interface UiContribution {
55
55
  * see `effectiveCompact`. Omitted = the slot's form.
56
56
  */
57
57
  compact?: CompactForm;
58
+ /**
59
+ * `org.page` component only. `"host"` (default): the host draws the page title and the page
60
+ * chrome around the component; `"page"`: the component draws the whole page itself.
61
+ */
62
+ frame?: UiPageFrame;
63
+ /**
64
+ * `org.page` component only, a suggestion an org admin's saved choice beats. `"more"`
65
+ * (default): listed under the navigation's more entry; `"primary"`: listed in the primary
66
+ * navigation (at most 3 plugin pages there).
67
+ */
68
+ nav?: UiPageNav;
58
69
  }
70
+ /** How an `org.page` component page is framed ({@link UiContribution.frame}). */
71
+ export type UiPageFrame = "host" | "page";
72
+ /** Where an `org.page` component page is listed ({@link UiContribution.nav}). */
73
+ export type UiPageNav = "primary" | "more";
74
+ /** The accepted values of {@link UiContribution.frame}. */
75
+ export declare const UI_PAGE_FRAMES: readonly UiPageFrame[];
76
+ /** The accepted values of {@link UiContribution.nav}. */
77
+ export declare const UI_PAGE_NAVS: readonly UiPageNav[];
59
78
  /**
60
79
  * Blocks of the render schema. Text is for humans and shown as is (the plugin decides the language
61
80
  * itself, usually taking `locale`).
@@ -154,6 +173,11 @@ export interface UiView {
154
173
  * - `textChars`: total characters of all text in the whole view (form JSON included);
155
174
  * - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
156
175
  * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
176
+ * - `componentQueryBytes`: the UTF-8 bytes of a `ctx.ui.query` result as JSON.
177
+ * - `componentQueryParamsBytes`: the UTF-8 bytes of a query's `params` as JSON.
178
+ * - `componentActionPayloadBytes`: the UTF-8 bytes of a component action's `payload` as JSON
179
+ * (view block buttons keep `payloadBytes`).
180
+ * - `pageParamsBytes`: the UTF-8 bytes of a page's URL params (all keys and values).
157
181
  */
158
182
  export declare const UI_LIMITS: {
159
183
  readonly blocks: 50;
@@ -162,6 +186,10 @@ export declare const UI_LIMITS: {
162
186
  readonly textChars: 20000;
163
187
  readonly payloadBytes: 2000;
164
188
  readonly componentDataBytes: 32768;
189
+ readonly componentQueryBytes: 1048576;
190
+ readonly componentQueryParamsBytes: 16384;
191
+ readonly componentActionPayloadBytes: 65536;
192
+ readonly pageParamsBytes: 2048;
165
193
  };
166
194
  /**
167
195
  * Validates the view a plugin returns and returns the list of problems (empty = valid). Links and
@@ -265,14 +293,29 @@ export interface UiPlatformActionArgs extends UiPlatformRenderArgs, UiActionInpu
265
293
  * `answer`.
266
294
  */
267
295
  export type UiActionArgs = UiOrgActionArgs | UiPlatformActionArgs;
268
- /** An action result: a notice, or a new view. */
296
+ /**
297
+ * The args of a `ctx.ui.query` handler: the org position of the call, the query id and its params
298
+ * (JSON of at most `UI_LIMITS.componentQueryParamsBytes` bytes). `signal` aborts when the caller
299
+ * goes away.
300
+ */
301
+ export interface UiQueryArgs extends UiOrgRenderArgs {
302
+ query: string;
303
+ params: JsonValue;
304
+ signal: AbortSignal;
305
+ }
306
+ /**
307
+ * An action result: a notice, or a new view. `invalidate` names queries the host refetches
308
+ * (component actions only).
309
+ */
269
310
  export type UiActionResult = {
270
311
  toast?: {
271
312
  zh: string;
272
313
  en: string;
273
314
  };
315
+ invalidate?: string[];
274
316
  } | {
275
317
  view: UiView;
318
+ invalidate?: string[];
276
319
  };
277
320
  /** The embed claims every scope shares. `exp` is Unix seconds. */
278
321
  export interface EmbedClaimsBase {
@@ -293,7 +336,10 @@ export interface OrgEmbedClaims extends EmbedClaimsBase {
293
336
  conversationId?: string;
294
337
  /** Only an agent embed's token (`agent.detail.section`): the agent it was issued for. */
295
338
  agentId?: string;
296
- /** Only a `file-preview` embed's token: the one file (of `conversationId`) it previews. */
339
+ /**
340
+ * Only a `file-preview` embed's token: the one file it previews, of `conversationId`, or without
341
+ * one a library file of `accountId`'s own.
342
+ */
297
343
  fileId?: string;
298
344
  /**
299
345
  * Only a `file-preview` embed's token for a skill file (no `conversationId`, `agentId` or
package/dist/ui.js CHANGED
@@ -17,6 +17,10 @@ export const UI_ICONS = [
17
17
  "globe",
18
18
  "puzzle",
19
19
  ];
20
+ /** The accepted values of {@link UiContribution.frame}. */
21
+ export const UI_PAGE_FRAMES = ["host", "page"];
22
+ /** The accepted values of {@link UiContribution.nav}. */
23
+ export const UI_PAGE_NAVS = ["primary", "more"];
20
24
  /**
21
25
  * View limits (checked uniformly by {@link validateUiView}):
22
26
  * - `blocks`: number of blocks;
@@ -26,6 +30,11 @@ export const UI_ICONS = [
26
30
  * - `textChars`: total characters of all text in the whole view (form JSON included);
27
31
  * - `payloadBytes`: UTF-8 bytes of a single button `payload` after JSON serialization.
28
32
  * - `componentDataBytes`: the UTF-8 bytes of a component view's `data` as JSON.
33
+ * - `componentQueryBytes`: the UTF-8 bytes of a `ctx.ui.query` result as JSON.
34
+ * - `componentQueryParamsBytes`: the UTF-8 bytes of a query's `params` as JSON.
35
+ * - `componentActionPayloadBytes`: the UTF-8 bytes of a component action's `payload` as JSON
36
+ * (view block buttons keep `payloadBytes`).
37
+ * - `pageParamsBytes`: the UTF-8 bytes of a page's URL params (all keys and values).
29
38
  */
30
39
  export const UI_LIMITS = {
31
40
  blocks: 50,
@@ -34,6 +43,10 @@ export const UI_LIMITS = {
34
43
  textChars: 20000,
35
44
  payloadBytes: 2000,
36
45
  componentDataBytes: 32768,
46
+ componentQueryBytes: 1048576,
47
+ componentQueryParamsBytes: 16384,
48
+ componentActionPayloadBytes: 65536,
49
+ pageParamsBytes: 2048,
37
50
  };
38
51
  const BADGE_MAX = 32;
39
52
  /** Longest item / block `id` and open target `item`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.85",
3
+ "version": "0.1.0-rc.87",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {