@capybara-hq/kernel 0.1.0-rc.106 → 0.1.0-rc.108
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/bootstrap.json +13 -13
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +4 -3
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +3 -3
- package/dist/channels/outbound.js +15 -13
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +12 -0
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +10 -9
- package/dist/conversations/conversations.service.js +28 -11
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +49 -27
- package/dist/conversations/events.js +54 -7
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.service.js +7 -2
- package/dist/ctx/create-ctx.d.ts +3 -1
- package/dist/ctx/create-ctx.js +19 -1
- package/dist/db/kernel-schema.d.ts +80 -2
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.js +13 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +3 -1
- package/dist/extensions/host.js +2 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +5 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/infra/outbox/registry.d.ts +82 -0
- package/dist/infra/outbox/registry.js +74 -2
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- package/dist/orgs/settings.service.d.ts +48 -2
- package/dist/orgs/settings.service.js +63 -3
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +5 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +15 -1
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +18 -1
- package/dist/runtime/context/build.js +19 -8
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +50 -17
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +10 -2
- package/dist/runtime/maintenance.js +48 -8
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- package/dist/runtime/run-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- package/dist/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/builtin-tools.d.ts +7 -1
- package/dist/tools/builtins/builtin-tools.js +17 -6
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- package/dist/tools/tools.module.js +6 -0
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
|
@@ -4,9 +4,10 @@ import type { BackgroundTaskStopper } from "../../../background/stop.js";
|
|
|
4
4
|
import type { BackgroundTaskStore } from "../../../background/store.js";
|
|
5
5
|
import type { KernelConfig } from "../../../config/schema.js";
|
|
6
6
|
import type { ChildAgent } from "../../../conversations/agent-tree.js";
|
|
7
|
-
import type { AttachmentsService } from "../../../conversations/attachments.service.js";
|
|
8
7
|
import type { EventLog } from "../../../conversations/event-log.js";
|
|
9
8
|
import { type ConversationDevices, type DeviceUnusableReason } from "../../../devices/conversation-devices.js";
|
|
9
|
+
import type { FileDeliveries } from "../../../files/deliveries.js";
|
|
10
|
+
import type { ReferencedFiles } from "../../../files/referenced-files.js";
|
|
10
11
|
import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
|
|
11
12
|
import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
|
|
12
13
|
import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
|
|
@@ -50,8 +51,11 @@ export interface SandboxToolDeps {
|
|
|
50
51
|
finisher: Pick<BackgroundTaskFinisher, "finish">;
|
|
51
52
|
stopper: Pick<BackgroundTaskStopper, "stop">;
|
|
52
53
|
};
|
|
53
|
-
|
|
54
|
+
/** The files sent into a conversation that `FetchAttachment` copies (file library). */
|
|
55
|
+
attachments: Pick<ReferencedFiles, "listForConversation" | "openForConversation">;
|
|
54
56
|
storage: Pick<StorageService, "kernel" | "deployment" | "available">;
|
|
57
|
+
/** `Deliver`'s blobs and delivery transaction (file library spec §4); absent in test stubs. */
|
|
58
|
+
deliveries?: Pick<FileDeliveries, "ensureBlob" | "appendDelivered">;
|
|
55
59
|
/**
|
|
56
60
|
* `readDeliveryScope`: `Deliver`'s delivery scope (truthful delivery spec §2). `publishChanged`:
|
|
57
61
|
* `Deliver` announces `changed: files` (UI refresh B).
|
|
@@ -11,9 +11,8 @@ const SPEC = {
|
|
|
11
11
|
description: "Deliver a file to the user as a downloadable artifact. Use it when the user should receive a " +
|
|
12
12
|
"file you produced (a report, chart, spreadsheet, archive and so on); files that stay on the " +
|
|
13
13
|
"device are not visible to the user, and images in tool results are shown to you, not " +
|
|
14
|
-
"delivered to the user. Pass file_path for a file on the device, or file_id for
|
|
15
|
-
"
|
|
16
|
-
"no device). Each call delivers only that one file, so a directory must first be packed into " +
|
|
14
|
+
"delivered to the user. Pass file_path for a file on the device, or file_id for a file id of " +
|
|
15
|
+
"this conversation, such as the file_id an image in a tool result names (needs no device). Each call delivers only that one file, so a directory must first be packed into " +
|
|
17
16
|
"one archive. The file size is limited (100 MB by default). Do not use it for intermediate " +
|
|
18
17
|
"files the user does not need. An HTML file is shown on its own: files it references by " +
|
|
19
18
|
"relative path are not delivered with it, so inline or embed them.",
|
|
@@ -28,7 +27,7 @@ const SPEC = {
|
|
|
28
27
|
file_id: {
|
|
29
28
|
type: "string",
|
|
30
29
|
minLength: 1,
|
|
31
|
-
description: "Instead of file_path:
|
|
30
|
+
description: "Instead of file_path: a file id of this conversation (a file the user sent, a delivered file, or the file_id of an image in a tool result).",
|
|
32
31
|
},
|
|
33
32
|
name: {
|
|
34
33
|
type: "string",
|
|
@@ -168,9 +167,9 @@ export function sandboxDeliverTool(deps) {
|
|
|
168
167
|
};
|
|
169
168
|
}
|
|
170
169
|
/**
|
|
171
|
-
* A `file_id` delivery:
|
|
172
|
-
* such as a tool result's image
|
|
173
|
-
* artifact's source path is `file_id/<id>`.
|
|
170
|
+
* A `file_id` delivery: a file of the conversation or its root ({@link findConversationFile}: a
|
|
171
|
+
* library file they refer to, or a `read` copy such as a tool result's image) read from the object
|
|
172
|
+
* store, no device; the artifact's source path is `file_id/<id>`.
|
|
174
173
|
*/
|
|
175
174
|
async function deliverById(deps, ctx, id, given, max) {
|
|
176
175
|
if (deps.read === undefined)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { BuiltinTool } from "../../registry.js";
|
|
2
2
|
import { type SandboxToolDeps } from "./common.js";
|
|
3
3
|
/**
|
|
4
|
-
* The builtin `FetchAttachment`: copy one
|
|
5
|
-
* ({@link attachmentsDir}); it runs
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The builtin `FetchAttachment`: copy one file sent into this conversation (its root's: the files
|
|
5
|
+
* its messages attached, file library spec §5) into the device ({@link attachmentsDir}); it runs
|
|
6
|
+
* nothing. A library file the person never attached to the conversation is not in the list.
|
|
7
|
+
* Names come from the conversation's whole attachment list ({@link assignAttachmentNames}), so a
|
|
8
|
+
* given attachment always lands on the same path; copying it twice writes the same bytes and
|
|
9
|
+
* returns the same path. A failure is an ordinary tool error and the run continues.
|
|
9
10
|
*/
|
|
10
11
|
export declare function sandboxFetchAttachmentTool(deps: SandboxToolDeps): BuiltinTool;
|
|
@@ -33,11 +33,11 @@ const goneText = (name) => `Attachment "${clip(name, 200)}" is no longer in this
|
|
|
33
33
|
const storageText = (name) => `File storage is unavailable, so "${clip(name, 200)}" could not be copied; ask an administrator to check the deployment's object store, then retry.`;
|
|
34
34
|
const copyFailedText = (name) => `Copying "${clip(name, 200)}" into the device failed (a temporary error); retry the call, or check that the device has free space.`;
|
|
35
35
|
/**
|
|
36
|
-
* The attachment `file` names, among the
|
|
37
|
-
* file name, then the name the copy assigns it (a sanitized or de-duplicated name shown in an
|
|
38
|
-
* earlier result's path), then the
|
|
39
|
-
*
|
|
40
|
-
* case-sensitive; nothing else resolves.
|
|
36
|
+
* The attachment `file` names, among the files sent into the conversation (the caller's list): the
|
|
37
|
+
* exact file name, then the name the copy assigns it (a sanitized or de-duplicated name shown in an
|
|
38
|
+
* earlier result's path), then the unsigned reference a reference line showed (the file's blob
|
|
39
|
+
* `s3://<bucket>/<key>`, or `capybara://attachments/<id>`), then the bare file id or a reference
|
|
40
|
+
* whose last path segment is the id. Names are exact and case-sensitive; nothing else resolves.
|
|
41
41
|
*/
|
|
42
42
|
function resolveAttachment(file, list, assigned) {
|
|
43
43
|
const byName = list.find((a) => a.name === file);
|
|
@@ -46,6 +46,9 @@ function resolveAttachment(file, list, assigned) {
|
|
|
46
46
|
const byAssigned = list.find((a) => assigned.get(a.id) === file);
|
|
47
47
|
if (byAssigned !== undefined)
|
|
48
48
|
return byAssigned;
|
|
49
|
+
const byUri = list.find((a) => a.uri === file);
|
|
50
|
+
if (byUri !== undefined)
|
|
51
|
+
return byUri;
|
|
49
52
|
const tail = file.slice(file.lastIndexOf("/") + 1);
|
|
50
53
|
if (!ATTACHMENT_ID.test(tail))
|
|
51
54
|
return undefined;
|
|
@@ -53,11 +56,12 @@ function resolveAttachment(file, list, assigned) {
|
|
|
53
56
|
return list.find((a) => a.id.toLowerCase() === id);
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
|
-
* The builtin `FetchAttachment`: copy one
|
|
57
|
-
* ({@link attachmentsDir}); it runs
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* The builtin `FetchAttachment`: copy one file sent into this conversation (its root's: the files
|
|
60
|
+
* its messages attached, file library spec §5) into the device ({@link attachmentsDir}); it runs
|
|
61
|
+
* nothing. A library file the person never attached to the conversation is not in the list.
|
|
62
|
+
* Names come from the conversation's whole attachment list ({@link assignAttachmentNames}), so a
|
|
63
|
+
* given attachment always lands on the same path; copying it twice writes the same bytes and
|
|
64
|
+
* returns the same path. A failure is an ordinary tool error and the run continues.
|
|
61
65
|
*/
|
|
62
66
|
export function sandboxFetchAttachmentTool(deps) {
|
|
63
67
|
return {
|
|
@@ -69,8 +73,11 @@ export function sandboxFetchAttachmentTool(deps) {
|
|
|
69
73
|
const file = input.file;
|
|
70
74
|
const conv = sandboxConversationOf(ctx);
|
|
71
75
|
// the list is read before any device is touched: an unknown file starts no device
|
|
72
|
-
const
|
|
73
|
-
|
|
76
|
+
const all = await deps.attachments.listForConversation(ctx.orgId, conv);
|
|
77
|
+
// names over every file ever sent here (a deleted one keeps its name taken), copies of the
|
|
78
|
+
// available ones only
|
|
79
|
+
const assigned = assignAttachmentNames(all, new Set());
|
|
80
|
+
const list = all.filter((a) => a.available !== false);
|
|
74
81
|
const attachment = resolveAttachment(file, list, assigned);
|
|
75
82
|
if (attachment === undefined) {
|
|
76
83
|
if (list.length === 0)
|
|
@@ -14,6 +14,8 @@ import { EventLogModule } from "../conversations/event-log.js";
|
|
|
14
14
|
import { ConversationLeakCheckModule } from "../conversations/leak-check.js";
|
|
15
15
|
import { DevicesModule } from "../devices/devices.module.js";
|
|
16
16
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
17
|
+
import { FileDeliveriesModule } from "../files/deliveries.module.js";
|
|
18
|
+
import { LibraryReadModule } from "../files/library-read.module.js";
|
|
17
19
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
18
20
|
import { ModelsModule } from "../models/models.module.js";
|
|
19
21
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
@@ -77,8 +79,12 @@ ToolsModule = __decorate([
|
|
|
77
79
|
// the approval decision's leak check of a person's card values
|
|
78
80
|
ConversationLeakCheckModule,
|
|
79
81
|
AttachmentsModule,
|
|
82
|
+
// the library files a conversation refers to (`Read`, `Deliver`, `FetchAttachment`, file refs)
|
|
83
|
+
LibraryReadModule,
|
|
80
84
|
ExtensionsModule,
|
|
81
85
|
StorageModule,
|
|
86
|
+
// `Deliver` and `GenerateImage` store files as library files on shared blobs
|
|
87
|
+
FileDeliveriesModule,
|
|
82
88
|
SkillsModule,
|
|
83
89
|
OrgLockModule,
|
|
84
90
|
// the `Agent` tool's dispatch
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
/**
|
|
3
|
-
* Calls an extension with a time limit and an abort signal (plugin views, actions
|
|
4
|
-
* previewers): over the limit the signal aborts and the call is 504
|
|
5
|
-
* `
|
|
3
|
+
* Calls an extension with a time limit and an abort signal (plugin views, actions, component
|
|
4
|
+
* queries and file previewers): over the limit the signal aborts and the call is 504
|
|
5
|
+
* `timeoutCode` (default `ui.timeout`); a throw is `failCode` (502) without echoing the
|
|
6
|
+
* extension's message. An `ApiError` thrown by `fn` passes.
|
|
6
7
|
*/
|
|
7
8
|
export declare function callExtension<T>(o: {
|
|
8
9
|
log: Pick<Logger, "warn">;
|
|
@@ -10,7 +11,8 @@ export declare function callExtension<T>(o: {
|
|
|
10
11
|
what: string;
|
|
11
12
|
fields: Record<string, unknown>;
|
|
12
13
|
timeoutMs: number;
|
|
13
|
-
failCode: "ui.render_failed" | "ui.action_failed";
|
|
14
|
+
failCode: "ui.render_failed" | "ui.action_failed" | "ui.query_failed";
|
|
15
|
+
timeoutCode?: "ui.timeout" | "ui.query_timeout";
|
|
14
16
|
failMessage: string;
|
|
15
17
|
fn: (signal: AbortSignal) => Promise<T>;
|
|
16
18
|
}): Promise<T>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ApiError } from "../errors.js";
|
|
2
2
|
/**
|
|
3
|
-
* Calls an extension with a time limit and an abort signal (plugin views, actions
|
|
4
|
-
* previewers): over the limit the signal aborts and the call is 504
|
|
5
|
-
* `
|
|
3
|
+
* Calls an extension with a time limit and an abort signal (plugin views, actions, component
|
|
4
|
+
* queries and file previewers): over the limit the signal aborts and the call is 504
|
|
5
|
+
* `timeoutCode` (default `ui.timeout`); a throw is `failCode` (502) without echoing the
|
|
6
|
+
* extension's message. An `ApiError` thrown by `fn` passes.
|
|
6
7
|
*/
|
|
7
8
|
export async function callExtension(o) {
|
|
8
9
|
const ac = new AbortController();
|
|
@@ -22,7 +23,7 @@ export async function callExtension(o) {
|
|
|
22
23
|
]);
|
|
23
24
|
if (r === "timeout") {
|
|
24
25
|
o.log.warn(`plugin ui ${o.what} timed out`, { ...o.fields, timeoutMs: o.timeoutMs });
|
|
25
|
-
throw new ApiError("ui.timeout", `Plugin ${o.plugin} did not respond within ${o.timeoutMs / 1000}s`);
|
|
26
|
+
throw new ApiError(o.timeoutCode ?? "ui.timeout", `Plugin ${o.plugin} did not respond within ${o.timeoutMs / 1000}s`);
|
|
26
27
|
}
|
|
27
28
|
return r.value;
|
|
28
29
|
}
|
package/dist/ui/embed-token.js
CHANGED
|
@@ -76,7 +76,8 @@ function decodeStrict(s) {
|
|
|
76
76
|
/**
|
|
77
77
|
* 逐字段核对声明:只认已知字段、类型正确,返回只含已知字段的新对象。The scope decides the shape:
|
|
78
78
|
* `"platform"` exactly when `orgId` is absent and `role` is `"superAdmin"`, with no
|
|
79
|
-
* `conversationId` / `agentId` / `fileId`; `"org"` needs an `orgId` and one of the org roles
|
|
79
|
+
* `conversationId` / `agentId` / `fileId`; `"org"` needs an `orgId` and one of the org roles (a
|
|
80
|
+
* `fileId` names a file of `conversationId`, or without one a library file of the account's own);
|
|
80
81
|
* `"share"` (file sharing spec §7) see {@link parseShareClaims}. `shareId` / `generation` only in
|
|
81
82
|
* the share scope. `skillFile` (a skill file's previewer, skill file browser spec) only in the org
|
|
82
83
|
* scope and never with `conversationId`, `agentId` or `fileId`.
|
|
@@ -124,12 +125,14 @@ function parseClaims(v) {
|
|
|
124
125
|
return null;
|
|
125
126
|
if (c.agentId !== undefined && (!isId(c.agentId) || c.conversationId !== undefined))
|
|
126
127
|
return null;
|
|
127
|
-
|
|
128
|
+
// a file of the conversation, or without one a library file of the account's own
|
|
129
|
+
if (c.fileId !== undefined && (!isId(c.fileId) || c.agentId !== undefined))
|
|
128
130
|
return null;
|
|
129
131
|
let skillFile;
|
|
130
132
|
if (c.skillFile !== undefined) {
|
|
131
|
-
if (c.conversationId !== undefined || c.agentId !== undefined)
|
|
133
|
+
if (c.conversationId !== undefined || c.agentId !== undefined || c.fileId !== undefined) {
|
|
132
134
|
return null;
|
|
135
|
+
}
|
|
133
136
|
skillFile = parseSkillFile(c.skillFile) ?? undefined;
|
|
134
137
|
if (skillFile === undefined)
|
|
135
138
|
return null;
|
package/dist/ui/registry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtensionManifest, UiActionArgs, UiActionResult, UiRenderArgs, UiSlotSpec, UiView } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { ExtensionManifest, JsonValue, UiActionArgs, UiActionResult, UiQueryArgs, UiRenderArgs, UiSlotSpec, UiView } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type OrgRole } from "../orgs/roles.js";
|
|
3
3
|
/** 会话 id 的格式(UUID)。 */
|
|
4
4
|
export declare const UUID_RE: RegExp;
|
|
@@ -10,7 +10,9 @@ export declare const UUID_RE: RegExp;
|
|
|
10
10
|
export declare function canUseSlot(slot: UiSlotSpec, role: OrgRole): boolean;
|
|
11
11
|
/** 插件视图的 render 函数(`ctx.ui.view` 注册)。 */
|
|
12
12
|
export type UiRender = (args: UiRenderArgs) => Promise<UiView>;
|
|
13
|
-
/**
|
|
13
|
+
/** The handler of a `ctx.ui.query` registration (a component's named queries, by `args.query`). */
|
|
14
|
+
export type UiQueryHandler = (args: UiQueryArgs) => Promise<JsonValue>;
|
|
15
|
+
/** The action handler of a plugin view (registered with `ctx.ui.action`). */
|
|
14
16
|
export type UiActionHandler = (args: UiActionArgs) => Promise<UiActionResult>;
|
|
15
17
|
/**
|
|
16
18
|
* 组织级界面刷新的内核 bus 主题(命名空间 `kernel`):`org-ui.<orgId>`。
|
|
@@ -32,15 +34,20 @@ export type UiInvalidateTarget = {
|
|
|
32
34
|
scope: "platform";
|
|
33
35
|
contribution: string;
|
|
34
36
|
};
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* The UI refresh message on `conv.<id>`, `org-ui.<orgId>` and `platform-ui`:
|
|
39
|
+
* `{ kind: "ui", plugin, contribution, queries? }`. `queries: true` (every `ctx.ui.invalidate`)
|
|
40
|
+
* tells the web to refetch the contribution's component queries too (plugin full pages spec §4.1).
|
|
41
|
+
*/
|
|
36
42
|
export interface UiBusMessage {
|
|
37
43
|
kind: "ui";
|
|
38
44
|
plugin: string;
|
|
39
45
|
contribution: string;
|
|
46
|
+
queries?: true;
|
|
40
47
|
}
|
|
41
48
|
/** 是否为界面刷新消息(bus 上的消息来自其他副本,按形状核对)。 */
|
|
42
49
|
export declare function isUiBusMessage(m: unknown): m is UiBusMessage;
|
|
43
|
-
/** SSE
|
|
50
|
+
/** The SSE frame `event: ui`, data `{ plugin, contribution, queries? }`. */
|
|
44
51
|
export declare const uiFrame: (m: UiBusMessage) => string;
|
|
45
52
|
/**
|
|
46
53
|
* 单个插件在 setup 期间注册的视图与动作:进程内的静态登记(同 `ctx.tools.register`),
|
|
@@ -58,7 +65,11 @@ export declare class PluginUiRegistration {
|
|
|
58
65
|
private readonly deny;
|
|
59
66
|
readonly views: Map<string, UiRender>;
|
|
60
67
|
readonly actions: Map<string, UiActionHandler>;
|
|
68
|
+
/** Query handlers registered by `ctx.ui.query`, by component id. */
|
|
69
|
+
readonly queries: Map<string, UiQueryHandler>;
|
|
61
70
|
private readonly declaredViews;
|
|
71
|
+
/** `permissions.ui.components`: the only ids `ctx.ui.query` accepts. */
|
|
72
|
+
private readonly declaredComponents;
|
|
62
73
|
private readonly contributions;
|
|
63
74
|
/** The ids of the manifest's `component` contributions: their permission is `ui.components`. */
|
|
64
75
|
private readonly components;
|
|
@@ -69,10 +80,15 @@ export declare class PluginUiRegistration {
|
|
|
69
80
|
* throws ExtensionPermissionError and writes an audit entry.
|
|
70
81
|
*/
|
|
71
82
|
deny: (item: string) => never);
|
|
72
|
-
/** setup
|
|
83
|
+
/** Called when setup ends: view / action / query throw from then on. */
|
|
73
84
|
seal(): void;
|
|
74
85
|
view(id: string, render: UiRender): void;
|
|
75
86
|
action(id: string, handler: UiActionHandler): void;
|
|
87
|
+
/**
|
|
88
|
+
* The named queries of a component (`usePluginQuery`, served by `POST …/ui/query/:plugin/:id`):
|
|
89
|
+
* only an id in `permissions.ui.components`.
|
|
90
|
+
*/
|
|
91
|
+
query(id: string, handler: UiQueryHandler): void;
|
|
76
92
|
/**
|
|
77
93
|
* 校验 invalidate 的目标。A contribution in `platform` (the ids of the extension's `platform.page`
|
|
78
94
|
* contributions) takes no `orgId` and no `conversationId`; every other contribution needs an
|
package/dist/ui/registry.js
CHANGED
|
@@ -26,8 +26,12 @@ export function isUiBusMessage(m) {
|
|
|
26
26
|
const x = m;
|
|
27
27
|
return x.kind === "ui" && typeof x.plugin === "string" && typeof x.contribution === "string";
|
|
28
28
|
}
|
|
29
|
-
/** SSE
|
|
30
|
-
export const uiFrame = (m) => `event: ui\ndata: ${JSON.stringify({
|
|
29
|
+
/** The SSE frame `event: ui`, data `{ plugin, contribution, queries? }`. */
|
|
30
|
+
export const uiFrame = (m) => `event: ui\ndata: ${JSON.stringify({
|
|
31
|
+
plugin: m.plugin,
|
|
32
|
+
contribution: m.contribution,
|
|
33
|
+
...(m.queries === true && { queries: true }),
|
|
34
|
+
})}\n\n`;
|
|
31
35
|
/**
|
|
32
36
|
* 单个插件在 setup 期间注册的视图与动作:进程内的静态登记(同 `ctx.tools.register`),
|
|
33
37
|
* 不是跨请求的共享状态——各副本加载同一插件得到同样的登记。
|
|
@@ -40,7 +44,11 @@ export class PluginUiRegistration {
|
|
|
40
44
|
deny;
|
|
41
45
|
views = new Map();
|
|
42
46
|
actions = new Map();
|
|
47
|
+
/** Query handlers registered by `ctx.ui.query`, by component id. */
|
|
48
|
+
queries = new Map();
|
|
43
49
|
declaredViews;
|
|
50
|
+
/** `permissions.ui.components`: the only ids `ctx.ui.query` accepts. */
|
|
51
|
+
declaredComponents;
|
|
44
52
|
contributions;
|
|
45
53
|
/** The ids of the manifest's `component` contributions: their permission is `ui.components`. */
|
|
46
54
|
components;
|
|
@@ -55,10 +63,11 @@ export class PluginUiRegistration {
|
|
|
55
63
|
this.deny = deny;
|
|
56
64
|
const ui = manifest.permissions?.ui;
|
|
57
65
|
this.declaredViews = new Set([...(ui?.views ?? []), ...(ui?.components ?? [])]);
|
|
66
|
+
this.declaredComponents = new Set(ui?.components ?? []);
|
|
58
67
|
this.contributions = new Set((manifest.ui ?? []).map((c) => c.id));
|
|
59
68
|
this.components = new Set((manifest.ui ?? []).filter((c) => c.kind === "component").map((c) => c.id));
|
|
60
69
|
}
|
|
61
|
-
/** setup
|
|
70
|
+
/** Called when setup ends: view / action / query throw from then on. */
|
|
62
71
|
seal() {
|
|
63
72
|
this.sealed = true;
|
|
64
73
|
}
|
|
@@ -68,6 +77,13 @@ export class PluginUiRegistration {
|
|
|
68
77
|
action(id, handler) {
|
|
69
78
|
this.register("action", this.actions, id, handler);
|
|
70
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* The named queries of a component (`usePluginQuery`, served by `POST …/ui/query/:plugin/:id`):
|
|
82
|
+
* only an id in `permissions.ui.components`.
|
|
83
|
+
*/
|
|
84
|
+
query(id, handler) {
|
|
85
|
+
this.register("query", this.queries, id, handler, this.declaredComponents);
|
|
86
|
+
}
|
|
71
87
|
/**
|
|
72
88
|
* 校验 invalidate 的目标。A contribution in `platform` (the ids of the extension's `platform.page`
|
|
73
89
|
* contributions) takes no `orgId` and no `conversationId`; every other contribution needs an
|
|
@@ -102,14 +118,16 @@ export class PluginUiRegistration {
|
|
|
102
118
|
contribution: x.contribution,
|
|
103
119
|
};
|
|
104
120
|
}
|
|
105
|
-
register(what, map, id, fn) {
|
|
121
|
+
register(what, map, id, fn, declared = this.declaredViews) {
|
|
106
122
|
const name = this.manifest.name;
|
|
107
123
|
if (this.sealed) {
|
|
108
124
|
throw new Error(`plugin ${name}: ui.${what} is only allowed during setup; setup has completed`);
|
|
109
125
|
}
|
|
110
|
-
if (typeof id !== "string" || !
|
|
126
|
+
if (typeof id !== "string" || !declared.has(id)) {
|
|
111
127
|
// name the list the id belongs in: a component's server view is declared under components
|
|
112
|
-
const list = typeof id === "string" && this.components.has(id)
|
|
128
|
+
const list = declared === this.declaredComponents || (typeof id === "string" && this.components.has(id))
|
|
129
|
+
? "components"
|
|
130
|
+
: "views";
|
|
113
131
|
this.deny(`permissions.ui.${list} ${String(id)}`);
|
|
114
132
|
}
|
|
115
133
|
if (typeof fn !== "function") {
|
package/dist/ui/ui.schemas.d.ts
CHANGED
|
@@ -33,6 +33,13 @@ export declare const ViewQuery: z.ZodObject<{
|
|
|
33
33
|
callId: z.ZodOptional<z.ZodString>;
|
|
34
34
|
key: z.ZodOptional<z.ZodString>;
|
|
35
35
|
}, z.core.$strip>;
|
|
36
|
+
/** The UTF-8 bytes of a value serialized as JSON (the measure of every UI payload limit). */
|
|
37
|
+
export declare const jsonBytes: (v: unknown) => number;
|
|
38
|
+
/**
|
|
39
|
+
* An action's body. `payload` is capped here at the component limit
|
|
40
|
+
* (`UI_LIMITS.componentActionPayloadBytes`); a view's action keeps `UI_LIMITS.payloadBytes`, which
|
|
41
|
+
* `UiViews.act` checks once it knows the contribution's kind.
|
|
42
|
+
*/
|
|
36
43
|
export declare const ActionBody: z.ZodObject<{
|
|
37
44
|
actionId: z.ZodString;
|
|
38
45
|
payload: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -44,6 +51,21 @@ export declare const ActionBody: z.ZodObject<{
|
|
|
44
51
|
zh: "zh";
|
|
45
52
|
}>>;
|
|
46
53
|
}, z.core.$strip>;
|
|
54
|
+
/**
|
|
55
|
+
* `POST query/:plugin/:id`: a component's named query. `params` is any JSON (default `null`), at
|
|
56
|
+
* most `UI_LIMITS.componentQueryParamsBytes` as JSON (checked by the service: 413
|
|
57
|
+
* `ui.query_params_too_large`); the context ids are those of the component's slot, as for an action.
|
|
58
|
+
*/
|
|
59
|
+
export declare const QueryBody: z.ZodObject<{
|
|
60
|
+
query: z.ZodString;
|
|
61
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
62
|
+
conversationId: z.ZodOptional<z.ZodString>;
|
|
63
|
+
agentId: z.ZodOptional<z.ZodUUID>;
|
|
64
|
+
locale: z.ZodDefault<z.ZodEnum<{
|
|
65
|
+
en: "en";
|
|
66
|
+
zh: "zh";
|
|
67
|
+
}>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
47
69
|
export declare const EmbedTokenBody: z.ZodDefault<z.ZodObject<{
|
|
48
70
|
conversationId: z.ZodOptional<z.ZodString>;
|
|
49
71
|
agentId: z.ZodOptional<z.ZodUUID>;
|
package/dist/ui/ui.schemas.js
CHANGED
|
@@ -33,15 +33,20 @@ const FormAnswerSchema = z
|
|
|
33
33
|
.refine((a) => Object.keys(a).length <= UI_LIMITS.tableRows, {
|
|
34
34
|
message: `answer must have at most ${UI_LIMITS.tableRows} fields`,
|
|
35
35
|
});
|
|
36
|
-
/**
|
|
37
|
-
const
|
|
36
|
+
/** The UTF-8 bytes of a value serialized as JSON (the measure of every UI payload limit). */
|
|
37
|
+
export const jsonBytes = (v) => Buffer.byteLength(JSON.stringify(v) ?? "", "utf8");
|
|
38
|
+
/**
|
|
39
|
+
* An action's body. `payload` is capped here at the component limit
|
|
40
|
+
* (`UI_LIMITS.componentActionPayloadBytes`); a view's action keeps `UI_LIMITS.payloadBytes`, which
|
|
41
|
+
* `UiViews.act` checks once it knows the contribution's kind.
|
|
42
|
+
*/
|
|
38
43
|
export const ActionBody = z.object({
|
|
39
44
|
actionId: z.string().min(1).max(200),
|
|
40
45
|
payload: z
|
|
41
46
|
.unknown()
|
|
42
47
|
.optional()
|
|
43
|
-
.refine((v) => v === undefined ||
|
|
44
|
-
message: `payload must be at most ${UI_LIMITS.
|
|
48
|
+
.refine((v) => v === undefined || jsonBytes(v) <= UI_LIMITS.componentActionPayloadBytes, {
|
|
49
|
+
message: `payload must be at most ${UI_LIMITS.componentActionPayloadBytes} bytes as JSON`,
|
|
45
50
|
}),
|
|
46
51
|
answer: FormAnswerSchema.optional(),
|
|
47
52
|
conversationId: z.string().min(1).max(100).optional(),
|
|
@@ -49,6 +54,19 @@ export const ActionBody = z.object({
|
|
|
49
54
|
agentId: z.uuid().optional(),
|
|
50
55
|
locale: Locale,
|
|
51
56
|
});
|
|
57
|
+
/**
|
|
58
|
+
* `POST query/:plugin/:id`: a component's named query. `params` is any JSON (default `null`), at
|
|
59
|
+
* most `UI_LIMITS.componentQueryParamsBytes` as JSON (checked by the service: 413
|
|
60
|
+
* `ui.query_params_too_large`); the context ids are those of the component's slot, as for an action.
|
|
61
|
+
*/
|
|
62
|
+
export const QueryBody = z.object({
|
|
63
|
+
query: z.string().min(1).max(200),
|
|
64
|
+
params: z.unknown().optional(),
|
|
65
|
+
conversationId: z.string().min(1).max(100).optional(),
|
|
66
|
+
/** Only a component of `agent.detail.section`. */
|
|
67
|
+
agentId: z.uuid().optional(),
|
|
68
|
+
locale: Locale,
|
|
69
|
+
});
|
|
52
70
|
export const EmbedTokenBody = z
|
|
53
71
|
.object({
|
|
54
72
|
conversationId: z.string().min(1).max(100).optional(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UiActionResult, UiView } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { JsonValue, UiActionResult, UiView } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
3
3
|
import type { z } from "zod";
|
|
4
4
|
import { ApiTokenService } from "../identity/api-tokens.js";
|
|
@@ -6,7 +6,7 @@ import { type Principal } from "../identity/principal.js";
|
|
|
6
6
|
import { SessionService } from "../identity/sessions.js";
|
|
7
7
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
8
8
|
import { EmbedTokens } from "./embed-token.js";
|
|
9
|
-
import { ActionBody, ContributionParams, ContributionsQuery, EmbedTokenBody, ViewQuery } from "./ui.schemas.js";
|
|
9
|
+
import { ActionBody, ContributionParams, ContributionsQuery, EmbedTokenBody, QueryBody, ViewQuery } from "./ui.schemas.js";
|
|
10
10
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
11
11
|
import { type UiArrangementSlot, type UiContributionItem, UiViews } from "./views.js";
|
|
12
12
|
export declare const BEARER_RE: RegExp;
|
|
@@ -27,10 +27,17 @@ export declare const embedSrc: (plugin: string, path: string) => string;
|
|
|
27
27
|
* → `{ view }`(`item`: the panel item to scroll to; `callId` / `key`: an inline card's tool call);
|
|
28
28
|
* - `POST /api/v1/orgs/:orgId/ui/actions/:plugin/:id`
|
|
29
29
|
* (`{ actionId, payload?, answer?, conversationId?, agentId?, locale? }`)→ `{ toast }` | `{ view }`;
|
|
30
|
+
* `payload` ≤ `UI_LIMITS.componentActionPayloadBytes` for a component, `payloadBytes` for a view;
|
|
31
|
+
* - `POST /api/v1/orgs/:orgId/ui/query/:plugin/:id` (`{ query, params?, conversationId?, agentId?,
|
|
32
|
+
* locale? }`) → `{ data }`: a component's named query (`ctx.ui.query`, plugin full pages spec
|
|
33
|
+
* §4.1), gated like the component's view; 404 `ui.query_not_found`, 413
|
|
34
|
+
* `ui.query_params_too_large`, 502 `ui.query_failed` / `ui.query_result_too_large`, 504
|
|
35
|
+
* `ui.query_timeout` (10 s);
|
|
30
36
|
* - `GET /api/v1/orgs/:orgId/ui/stream`:组织级刷新 SSE(`event: ui`,`data: {"plugin","contribution"}`),
|
|
31
37
|
* member and above;
|
|
32
38
|
* - `POST /api/v1/orgs/:orgId/ui/embeds/:plugin/:id/token` (`{ conversationId?, agentId?, fileId? }`,
|
|
33
|
-
*
|
|
39
|
+
* `{ fileId }` alone for a library file's previewer, or for a skill file's previewer
|
|
40
|
+
* `{ skillId, version?, path }`)
|
|
34
41
|
* → `{ token, src: "/plugin-ui/<plugin>/<path without /ui/>", expiresAt, expiresIn }`: an embed
|
|
35
42
|
* token (300 seconds, `expiresIn` in seconds, see `embed-token.ts`; `agentId` goes into the
|
|
36
43
|
* claims, a skill file as `skillFile` with its resolved version). The token is only for the
|
|
@@ -60,6 +67,9 @@ export declare class UiController {
|
|
|
60
67
|
view: UiView;
|
|
61
68
|
}>;
|
|
62
69
|
action(principal: Principal, org: OrgContext, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof ActionBody>): Promise<UiActionResult>;
|
|
70
|
+
query(principal: Principal, org: OrgContext, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof QueryBody>): Promise<{
|
|
71
|
+
data: JsonValue;
|
|
72
|
+
}>;
|
|
63
73
|
embedToken(principal: Principal, org: OrgContext, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof EmbedTokenBody>): Promise<{
|
|
64
74
|
token: string;
|
|
65
75
|
src: string;
|
|
@@ -17,7 +17,7 @@ import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
|
17
17
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
18
18
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
19
19
|
import { EMBED_TOKEN_TTL_SECONDS, EmbedTokens } from "./embed-token.js";
|
|
20
|
-
import { ActionBody, ContributionParams, ContributionsQuery, EmbedTokenBody, ViewQuery, } from "./ui.schemas.js";
|
|
20
|
+
import { ActionBody, ContributionParams, ContributionsQuery, EmbedTokenBody, QueryBody, ViewQuery, } from "./ui.schemas.js";
|
|
21
21
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
22
22
|
import { UiViews } from "./views.js";
|
|
23
23
|
export const BEARER_RE = /^Bearer\s+(\S+)$/i;
|
|
@@ -31,6 +31,8 @@ class UiViewQueryDto extends createZodDto(ViewQuery, "UiViewQuery") {
|
|
|
31
31
|
}
|
|
32
32
|
class UiActionBodyDto extends createZodDto(ActionBody, "UiActionBody") {
|
|
33
33
|
}
|
|
34
|
+
class UiQueryBodyDto extends createZodDto(QueryBody, "UiQueryBody") {
|
|
35
|
+
}
|
|
34
36
|
class UiEmbedTokenBodyDto extends createZodDto(EmbedTokenBody, "UiEmbedTokenBody") {
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
@@ -48,10 +50,17 @@ class UiEmbedTokenBodyDto extends createZodDto(EmbedTokenBody, "UiEmbedTokenBody
|
|
|
48
50
|
* → `{ view }`(`item`: the panel item to scroll to; `callId` / `key`: an inline card's tool call);
|
|
49
51
|
* - `POST /api/v1/orgs/:orgId/ui/actions/:plugin/:id`
|
|
50
52
|
* (`{ actionId, payload?, answer?, conversationId?, agentId?, locale? }`)→ `{ toast }` | `{ view }`;
|
|
53
|
+
* `payload` ≤ `UI_LIMITS.componentActionPayloadBytes` for a component, `payloadBytes` for a view;
|
|
54
|
+
* - `POST /api/v1/orgs/:orgId/ui/query/:plugin/:id` (`{ query, params?, conversationId?, agentId?,
|
|
55
|
+
* locale? }`) → `{ data }`: a component's named query (`ctx.ui.query`, plugin full pages spec
|
|
56
|
+
* §4.1), gated like the component's view; 404 `ui.query_not_found`, 413
|
|
57
|
+
* `ui.query_params_too_large`, 502 `ui.query_failed` / `ui.query_result_too_large`, 504
|
|
58
|
+
* `ui.query_timeout` (10 s);
|
|
51
59
|
* - `GET /api/v1/orgs/:orgId/ui/stream`:组织级刷新 SSE(`event: ui`,`data: {"plugin","contribution"}`),
|
|
52
60
|
* member and above;
|
|
53
61
|
* - `POST /api/v1/orgs/:orgId/ui/embeds/:plugin/:id/token` (`{ conversationId?, agentId?, fileId? }`,
|
|
54
|
-
*
|
|
62
|
+
* `{ fileId }` alone for a library file's previewer, or for a skill file's previewer
|
|
63
|
+
* `{ skillId, version?, path }`)
|
|
55
64
|
* → `{ token, src: "/plugin-ui/<plugin>/<path without /ui/>", expiresAt, expiresIn }`: an embed
|
|
56
65
|
* token (300 seconds, `expiresIn` in seconds, see `embed-token.ts`; `agentId` goes into the
|
|
57
66
|
* claims, a skill file as `skillFile` with its resolved version). The token is only for the
|
|
@@ -120,6 +129,19 @@ let UiController = class UiController {
|
|
|
120
129
|
...(body.answer !== undefined && { answer: body.answer }),
|
|
121
130
|
});
|
|
122
131
|
}
|
|
132
|
+
async query(principal, org, { plugin, id }, body) {
|
|
133
|
+
const p = requireUser(principal);
|
|
134
|
+
return this.views.query({
|
|
135
|
+
orgId: org.orgId,
|
|
136
|
+
accountId: p.account.id,
|
|
137
|
+
role: org.role,
|
|
138
|
+
plugin,
|
|
139
|
+
id,
|
|
140
|
+
...(body.conversationId !== undefined && { conversationId: body.conversationId }),
|
|
141
|
+
...(body.agentId !== undefined && { agentId: body.agentId }),
|
|
142
|
+
locale: body.locale,
|
|
143
|
+
}, { query: body.query, ...(body.params !== undefined && { params: body.params }) });
|
|
144
|
+
}
|
|
123
145
|
async embedToken(principal, org, { plugin, id }, body) {
|
|
124
146
|
const p = requireUser(principal);
|
|
125
147
|
if ((body.skillId === undefined) !== (body.path === undefined)) {
|
|
@@ -236,6 +258,15 @@ __decorate([
|
|
|
236
258
|
__param(2, ZParam(UiContributionParamsDto)),
|
|
237
259
|
__param(3, ZBody(UiActionBodyDto))
|
|
238
260
|
], UiController.prototype, "action", null);
|
|
261
|
+
__decorate([
|
|
262
|
+
Post("query/:plugin/:id"),
|
|
263
|
+
HttpCode(200),
|
|
264
|
+
OrgAction("ui.use"),
|
|
265
|
+
__param(0, CurrentPrincipal()),
|
|
266
|
+
__param(1, CurrentOrg()),
|
|
267
|
+
__param(2, ZParam(UiContributionParamsDto)),
|
|
268
|
+
__param(3, ZBody(UiQueryBodyDto))
|
|
269
|
+
], UiController.prototype, "query", null);
|
|
239
270
|
__decorate([
|
|
240
271
|
Post("embeds/:plugin/:id/token"),
|
|
241
272
|
HttpCode(200),
|