@capybara-hq/kernel 0.1.0-rc.116 → 0.1.0-rc.117
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/dist/catalog/catalog-content.d.ts +11 -0
- package/dist/catalog/catalog-content.js +1 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +1 -0
- package/dist/catalog/org-catalog.service.js +44 -2
- package/dist/catalog/schema-path.d.ts +4 -6
- package/dist/catalog/schema-path.js +48 -21
- package/dist/channels/outbound.d.ts +5 -0
- package/dist/channels/outbound.js +6 -1
- package/dist/channels/supervisor.js +3 -0
- package/dist/conversations/events.d.ts +1 -0
- package/dist/conversations/events.js +6 -1
- package/dist/devices/devices.service.d.ts +8 -0
- package/dist/devices/devices.service.js +16 -0
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/ops/devices.ops.js +14 -0
- package/dist/sandbox/sandbox.service.d.ts +13 -0
- package/dist/sandbox/sandbox.service.js +51 -4
- package/dist/tools/builtins/sandbox/common.d.ts +2 -7
- package/dist/tools/builtins/sandbox/common.js +4 -2
- package/dist/tools/pipeline.d.ts +4 -0
- package/dist/tools/pipeline.js +55 -16
- package/dist/ui/admin-ui.controller.d.ts +5 -2
- package/dist/ui/admin-ui.controller.js +14 -1
- package/dist/ui/ui.schemas.d.ts +9 -0
- package/dist/ui/ui.schemas.js +2 -0
- package/dist/ui/views.d.ts +1 -1
- package/dist/ui/views.js +4 -5
- package/package.json +3 -3
|
@@ -73,6 +73,7 @@ export interface OrgCatalogTemplate {
|
|
|
73
73
|
connector: string;
|
|
74
74
|
endpoint: Record<string, unknown>;
|
|
75
75
|
editableEndpoint: string[];
|
|
76
|
+
editableEndpointTitles?: Record<string, string>;
|
|
76
77
|
auth: Record<string, unknown>;
|
|
77
78
|
ownership: "org" | "personal" | null;
|
|
78
79
|
/**
|
|
@@ -106,6 +107,13 @@ export interface OrgCatalogTemplate {
|
|
|
106
107
|
*/
|
|
107
108
|
icon: string | null;
|
|
108
109
|
}
|
|
110
|
+
/** A connector reference or described need for the org's plugin review. */
|
|
111
|
+
export type OrgCatalogAgentConnectorNeed = {
|
|
112
|
+
template: string;
|
|
113
|
+
} | {
|
|
114
|
+
label: string;
|
|
115
|
+
host?: string;
|
|
116
|
+
};
|
|
109
117
|
/** `GET /orgs/:orgId/catalog/:itemId`: the item and what the install wizard needs (latest version). */
|
|
110
118
|
export interface OrgCatalogDetail {
|
|
111
119
|
item: OrgCatalogItem;
|
|
@@ -127,6 +135,8 @@ export interface OrgCatalogDetail {
|
|
|
127
135
|
skills: string[];
|
|
128
136
|
/** The agent template files (`agents/<name>.md`, sub-agents spec §16). */
|
|
129
137
|
agents: string[];
|
|
138
|
+
/** Display details for agent templates with connector references, keyed by their paths in `agents`. */
|
|
139
|
+
agentConnectorNeeds?: Record<string, OrgCatalogAgentConnectorNeed[]>;
|
|
130
140
|
}
|
|
131
141
|
/**
|
|
132
142
|
* A connector template as an org sees it (the install wizard and the upgrade preview's inputs):
|
|
@@ -137,6 +147,7 @@ export declare function orgTemplateView(id: string, file: ConnectorTemplateFile,
|
|
|
137
147
|
on?: boolean;
|
|
138
148
|
connected?: boolean;
|
|
139
149
|
icon?: string | null;
|
|
150
|
+
editableEndpointTitles?: Record<string, string> | undefined;
|
|
140
151
|
}): OrgCatalogTemplate;
|
|
141
152
|
/** An item's icon (the latest version's plugin icon). */
|
|
142
153
|
export interface CatalogIcon {
|
|
@@ -27,6 +27,7 @@ export function orgTemplateView(id, file, o = {}) {
|
|
|
27
27
|
connector: t.connector,
|
|
28
28
|
endpoint: t.endpoint,
|
|
29
29
|
editableEndpoint: t.editableEndpoint ?? [],
|
|
30
|
+
...(o.editableEndpointTitles && { editableEndpointTitles: o.editableEndpointTitles }),
|
|
30
31
|
auth: t.auth,
|
|
31
32
|
ownership: t.ownership ??
|
|
32
33
|
(typeof t.auth.ownership === "string" ? t.auth.ownership : null),
|
|
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
208
208
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
209
209
|
export declare const HOST_VERSIONS: {
|
|
210
210
|
readonly kernel: string;
|
|
211
|
-
readonly sdk: "0.1.0-rc.
|
|
211
|
+
readonly sdk: "0.1.0-rc.92";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -66,6 +66,7 @@ export declare class OrgCatalogService {
|
|
|
66
66
|
*/
|
|
67
67
|
/** The account is an admin (or owner) of the org. */
|
|
68
68
|
private isOrgAdmin;
|
|
69
|
+
private endpointTitles;
|
|
69
70
|
detail(orgId: string, accountId: string, itemId: string): Promise<OrgCatalogDetail>;
|
|
70
71
|
/**
|
|
71
72
|
* The item's icon; members don't see disabled items, nobody outside its list sees a hidden
|
|
@@ -22,17 +22,30 @@ import { OrgLock } from "../orgs/org-lock.js";
|
|
|
22
22
|
import { can, roleAtLeast } from "../orgs/roles.js";
|
|
23
23
|
import { packagePath } from "../packages/tgz.js";
|
|
24
24
|
import { StorageService } from "../storage/storage.service.js";
|
|
25
|
-
import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
|
|
25
|
+
import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogAgentTemplates, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
|
|
26
26
|
import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
|
|
27
27
|
import { connectorTemplatesOn } from "./component-state.js";
|
|
28
28
|
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
29
29
|
import { itemPendingError, ownerOf, ownersOf } from "./ownership.js";
|
|
30
30
|
import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
|
|
31
|
+
import { schemaPathTitle } from "./schema-path.js";
|
|
31
32
|
import { requestable, switchable, visibleTo, wantedOn } from "./scope.js";
|
|
32
33
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
33
34
|
const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
|
|
34
35
|
const notOffered = () => new ApiError("catalog.approval_required", "This plugin is not offered to this organization; an org admin can request access");
|
|
35
36
|
const pluginDisabled = () => new ApiError("plugin.disabled", "This plugin is disabled by the super admin and cannot be switched on");
|
|
37
|
+
function connectorNeedHost(endpoint) {
|
|
38
|
+
const url = URL.parse(endpoint);
|
|
39
|
+
if (!url?.hostname)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (url.port)
|
|
42
|
+
return url.host;
|
|
43
|
+
// Parse the same authority with a different default port so an explicit default stays visible.
|
|
44
|
+
const scheme = url.protocol === "http:" || url.protocol === "ws:" ? "https" : "http";
|
|
45
|
+
const alternate = URL.parse(scheme + endpoint.slice(endpoint.indexOf(":")));
|
|
46
|
+
const port = alternate?.hostname === url.hostname ? alternate.port : undefined;
|
|
47
|
+
return port ? `${url.hostname}:${port}` : url.host;
|
|
48
|
+
}
|
|
36
49
|
/**
|
|
37
50
|
* Organizations see the platform catalog with the plugin scope rules applied (plugin and component
|
|
38
51
|
* management spec §5): a plugin is `all` (on in every org unless an org admin switched it off,
|
|
@@ -258,6 +271,19 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
258
271
|
.executeTakeFirst();
|
|
259
272
|
return m !== undefined && roleAtLeast(m.role, "admin");
|
|
260
273
|
}
|
|
274
|
+
endpointTitles(template) {
|
|
275
|
+
const paths = template.editableEndpoint;
|
|
276
|
+
if (!paths?.length)
|
|
277
|
+
return undefined;
|
|
278
|
+
const schema = findConnectorIn(this.registry, template.plugin, template.connector)?.endpointSchema;
|
|
279
|
+
if (!schema)
|
|
280
|
+
return undefined;
|
|
281
|
+
const entries = paths.flatMap((path) => {
|
|
282
|
+
const title = schemaPathTitle(schema, path.split("."));
|
|
283
|
+
return title ? [[path, title]] : [];
|
|
284
|
+
});
|
|
285
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
286
|
+
}
|
|
261
287
|
async detail(orgId, accountId, itemId) {
|
|
262
288
|
if (!UUID_RE.test(itemId))
|
|
263
289
|
throw itemNotFound();
|
|
@@ -273,7 +299,21 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
273
299
|
if (!v)
|
|
274
300
|
throw itemNotFound();
|
|
275
301
|
const m = v.manifest;
|
|
276
|
-
const templates = await
|
|
302
|
+
const [templates, agentTemplates] = await Promise.all([
|
|
303
|
+
readCatalogTemplates(this.storage, v),
|
|
304
|
+
readCatalogAgentTemplates(this.storage, v),
|
|
305
|
+
]);
|
|
306
|
+
const agentConnectorNeeds = {};
|
|
307
|
+
for (const { path, template } of agentTemplates) {
|
|
308
|
+
if (!template.connectors?.length)
|
|
309
|
+
continue;
|
|
310
|
+
agentConnectorNeeds[path] = template.connectors.map((connector) => {
|
|
311
|
+
if ("template" in connector)
|
|
312
|
+
return { template: connector.template };
|
|
313
|
+
const host = connectorNeedHost(connector.needs.endpoint);
|
|
314
|
+
return { label: connector.needs.label, ...(host && { host }) };
|
|
315
|
+
});
|
|
316
|
+
}
|
|
277
317
|
// Which templates are on in this org now: the install makes connectors of those, a
|
|
278
318
|
// default-off one an admin switched on included
|
|
279
319
|
const on = await connectorTemplatesOn(this.db, orgId, itemId, templates.map((t) => t.id));
|
|
@@ -304,6 +344,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
304
344
|
on: on.has(t.id),
|
|
305
345
|
connected: connected.has(t.id),
|
|
306
346
|
icon: iconOf(t.id),
|
|
347
|
+
editableEndpointTitles: this.endpointTitles(t.file.template),
|
|
307
348
|
})),
|
|
308
349
|
dependencies: [
|
|
309
350
|
...(m.dependencies ?? []).map((d) => ({ name: d.name, range: d.version })),
|
|
@@ -311,6 +352,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
311
352
|
],
|
|
312
353
|
skills: (m.skills ?? []).map((s) => packagePath(s.path)),
|
|
313
354
|
agents: (m.agents ?? []).map((a) => packagePath(a.path)),
|
|
355
|
+
...(Object.keys(agentConnectorNeeds).length > 0 && { agentConnectorNeeds }),
|
|
314
356
|
};
|
|
315
357
|
}
|
|
316
358
|
/**
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ZodTypeAny } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export declare function schemaHasPath(schema: ZodTypeAny, segs: string[], depth?: number): boolean;
|
|
2
|
+
/** Whether the Zod schema admits the template's editable path. */
|
|
3
|
+
export declare function schemaHasPath(schema: ZodTypeAny, segs: string[]): boolean;
|
|
4
|
+
/** The title shared by the endpoint field's titled alternatives, when available. */
|
|
5
|
+
export declare function schemaPathTitle(schema: ZodTypeAny, segs: string[]): string | undefined;
|
|
@@ -10,9 +10,10 @@ const WRAPPERS = new Set([
|
|
|
10
10
|
"success",
|
|
11
11
|
]);
|
|
12
12
|
const defOf = (s) => s._zod.def;
|
|
13
|
-
function unwrap(s, depth) {
|
|
13
|
+
function unwrap(s, depth, visit) {
|
|
14
14
|
let node = s;
|
|
15
15
|
for (let i = 0; i < 50; i++) {
|
|
16
|
+
visit?.(node);
|
|
16
17
|
const d = defOf(node);
|
|
17
18
|
if (WRAPPERS.has(d.type) && d.innerType)
|
|
18
19
|
node = d.innerType;
|
|
@@ -25,39 +26,65 @@ function unwrap(s, depth) {
|
|
|
25
26
|
}
|
|
26
27
|
return undefined;
|
|
27
28
|
}
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
export function
|
|
29
|
+
/** Whether the Zod schema admits the template's editable path. */
|
|
30
|
+
export function schemaHasPath(schema, segs) {
|
|
31
|
+
return schemaFields(schema, segs, 0).next().done === false;
|
|
32
|
+
}
|
|
33
|
+
/** The title shared by the endpoint field's titled alternatives, when available. */
|
|
34
|
+
export function schemaPathTitle(schema, segs) {
|
|
35
|
+
let title;
|
|
36
|
+
for (const field of schemaFields(schema, segs, 0)) {
|
|
37
|
+
let name;
|
|
38
|
+
unwrap(field, 0, (node) => {
|
|
39
|
+
if (name)
|
|
40
|
+
return;
|
|
41
|
+
const metadata = node.meta()?.title;
|
|
42
|
+
if (typeof metadata === "string")
|
|
43
|
+
name = metadata.trim();
|
|
44
|
+
});
|
|
45
|
+
if (!name)
|
|
46
|
+
continue;
|
|
47
|
+
if (title !== undefined && title !== name)
|
|
48
|
+
return undefined;
|
|
49
|
+
title = name;
|
|
50
|
+
}
|
|
51
|
+
return title;
|
|
52
|
+
}
|
|
53
|
+
function* schemaFields(schema, segs, depth) {
|
|
34
54
|
if (depth > 40)
|
|
35
|
-
return
|
|
55
|
+
return;
|
|
36
56
|
const node = unwrap(schema, depth);
|
|
37
57
|
if (!node)
|
|
38
|
-
return
|
|
39
|
-
if (segs.length === 0)
|
|
40
|
-
|
|
58
|
+
return;
|
|
59
|
+
if (segs.length === 0) {
|
|
60
|
+
yield schema;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
41
63
|
const [head, ...rest] = segs;
|
|
42
64
|
const d = defOf(node);
|
|
43
65
|
switch (d.type) {
|
|
44
66
|
case "object": {
|
|
45
67
|
const child = d.shape && Object.hasOwn(d.shape, head) ? d.shape[head] : undefined;
|
|
46
68
|
if (child)
|
|
47
|
-
|
|
48
|
-
if (d.catchall && defOf(d.catchall).type !== "never") {
|
|
49
|
-
|
|
69
|
+
yield* schemaFields(child, rest, depth + 1);
|
|
70
|
+
else if (d.catchall && defOf(d.catchall).type !== "never") {
|
|
71
|
+
yield* schemaFields(d.catchall, rest, depth + 1);
|
|
50
72
|
}
|
|
51
|
-
|
|
73
|
+
break;
|
|
52
74
|
}
|
|
53
75
|
case "record":
|
|
54
|
-
|
|
76
|
+
if (d.valueType)
|
|
77
|
+
yield* schemaFields(d.valueType, rest, depth + 1);
|
|
78
|
+
break;
|
|
55
79
|
case "union":
|
|
56
|
-
|
|
80
|
+
for (const option of d.options ?? [])
|
|
81
|
+
yield* schemaFields(option, segs, depth + 1);
|
|
82
|
+
break;
|
|
57
83
|
case "intersection":
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
84
|
+
if (d.left)
|
|
85
|
+
yield* schemaFields(d.left, segs, depth + 1);
|
|
86
|
+
if (d.right)
|
|
87
|
+
yield* schemaFields(d.right, segs, depth + 1);
|
|
88
|
+
break;
|
|
62
89
|
}
|
|
63
90
|
}
|
|
@@ -41,6 +41,11 @@ export declare const DRAFT_INTERVAL_MS = 1000;
|
|
|
41
41
|
export declare const MILESTONE_INTERVAL_MS = 60000;
|
|
42
42
|
/** 同一事件不可重试地失败这么多次后跳过它(Ruling A14)。 */
|
|
43
43
|
export declare const POISON_FAILURES = 3;
|
|
44
|
+
/**
|
|
45
|
+
* How a delivery failure starts in a connection's `last_error`: the connection holding again does
|
|
46
|
+
* not clear it (the supervisor clears only the connect failures it recovered from).
|
|
47
|
+
*/
|
|
48
|
+
export declare const DELIVERY_ERROR_PREFIX = "delivery failed: ";
|
|
44
49
|
/**
|
|
45
50
|
* The language of the kernel text a conversation's IM thread gets (cards, notices; maintainer
|
|
46
51
|
* decision 2026-11-08: in IM, language is per person). The person who triggered the run speaks:
|
|
@@ -83,6 +83,11 @@ const BACKOFF_BASE_MS = 1000;
|
|
|
83
83
|
const BACKOFF_MAX_MS = 60_000;
|
|
84
84
|
/** 补读事件的分页大小。 */
|
|
85
85
|
const PAGE = 200;
|
|
86
|
+
/**
|
|
87
|
+
* How a delivery failure starts in a connection's `last_error`: the connection holding again does
|
|
88
|
+
* not clear it (the supervisor clears only the connect failures it recovered from).
|
|
89
|
+
*/
|
|
90
|
+
export const DELIVERY_ERROR_PREFIX = "delivery failed: ";
|
|
86
91
|
/** `last_error` 的最大长度(同渠道选主)。 */
|
|
87
92
|
const MAX_ERROR_CHARS = 1000;
|
|
88
93
|
/** 可重试的投递失败:带已打码的说明与平台建议的等待时长,供退避策略与最后一次失败时记录。 */
|
|
@@ -396,7 +401,7 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
396
401
|
}
|
|
397
402
|
/** A non-retryable (or finally failed) send: the connection's `last_error` (already redacted). */
|
|
398
403
|
async recordError(connectionId, message) {
|
|
399
|
-
const text =
|
|
404
|
+
const text = `${DELIVERY_ERROR_PREFIX}${message}`.slice(0, MAX_ERROR_CHARS);
|
|
400
405
|
this.log.warn("channel delivery failed", { connectionId, error: text });
|
|
401
406
|
// org-filter: connectionId is the delivery's own connection (kernel-written job / row)
|
|
402
407
|
await this.kdb
|
|
@@ -23,6 +23,7 @@ import { createRedactor } from "../log.js";
|
|
|
23
23
|
import { CHANNEL_CHANGED_TOPIC, ChannelConnections, channelBackoffKey, channelFailsKey, } from "./connections.service.js";
|
|
24
24
|
import { ChannelInbound } from "./inbound.js";
|
|
25
25
|
import { GATEWAY_CHECK_JOB } from "./job-ids.js";
|
|
26
|
+
import { DELIVERY_ERROR_PREFIX } from "./outbound.js";
|
|
26
27
|
/** 长连接租约键(内核锁):值为持有方的随机 token。 */
|
|
27
28
|
export const channelLeaseKey = (connectionId) => `capk:channel-lease:${connectionId}`;
|
|
28
29
|
/**
|
|
@@ -358,6 +359,8 @@ let ChannelSupervisor = class ChannelSupervisor {
|
|
|
358
359
|
.set({ last_error: null })
|
|
359
360
|
.where("id", "=", id)
|
|
360
361
|
.where("last_error", "is not", null)
|
|
362
|
+
// a delivery failure is not a connect failure the connection recovered from
|
|
363
|
+
.where("last_error", "not like", `${DELIVERY_ERROR_PREFIX}%`)
|
|
361
364
|
.execute();
|
|
362
365
|
}
|
|
363
366
|
catch (e) {
|
|
@@ -871,6 +871,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
871
871
|
loopback: z.ZodOptional<z.ZodObject<{
|
|
872
872
|
service: z.ZodString;
|
|
873
873
|
port: z.ZodNumber;
|
|
874
|
+
readyRerunAttempt: z.ZodOptional<z.ZodNumber>;
|
|
874
875
|
}, z.core.$strip>>;
|
|
875
876
|
}, z.core.$strip>;
|
|
876
877
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -870,7 +870,12 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
870
870
|
* port it asked to reach on the person's own device. Not model-visible.
|
|
871
871
|
*/
|
|
872
872
|
loopback: z
|
|
873
|
-
.object({
|
|
873
|
+
.object({
|
|
874
|
+
service: z.string(),
|
|
875
|
+
port: z.number().int().min(1).max(65535),
|
|
876
|
+
/** The attempt that reran under a live grant already held (ready-grant rerun). */
|
|
877
|
+
readyRerunAttempt: z.number().int().positive().optional(),
|
|
878
|
+
})
|
|
874
879
|
.optional(),
|
|
875
880
|
})),
|
|
876
881
|
ev("permission_profile_changed", z.object({
|
|
@@ -63,6 +63,14 @@ export interface DeviceView {
|
|
|
63
63
|
reconcileRequired: boolean;
|
|
64
64
|
/** Its file system is gone at the provider; reset the files to use it again. */
|
|
65
65
|
filesLost: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* A retirement obligation refuses every use (permission runtime cutover 8.5): `recreateRequired`
|
|
68
|
+
* when an earlier instance may still run background work no evidence can cover (quarantined:
|
|
69
|
+
* `device.recreate_required`), `pending` while a try to confirm an earlier instance destroyed
|
|
70
|
+
* failed and is retried (`device.unavailable`); null when nothing blocks it (an obligation not
|
|
71
|
+
* tried yet clears at the next use).
|
|
72
|
+
*/
|
|
73
|
+
retirement: "pending" | "recreateRequired" | null;
|
|
66
74
|
instance: {
|
|
67
75
|
status: "running" | "suspended";
|
|
68
76
|
lastUsedAt: string;
|
|
@@ -873,6 +873,21 @@ let DevicesService = class DevicesService {
|
|
|
873
873
|
]);
|
|
874
874
|
return [r.id, { limits, state, box: facts.box, report }];
|
|
875
875
|
})));
|
|
876
|
+
// the devices a retirement obligation blocks: a quarantined one for good, an open one whose
|
|
877
|
+
// last try failed until a retry succeeds
|
|
878
|
+
const retirement = new Map();
|
|
879
|
+
for (const o of await this.db
|
|
880
|
+
.selectFrom("device_retirement_obligations")
|
|
881
|
+
.select(["device_id", "state", "attempts"])
|
|
882
|
+
.where("org_id", "=", orgId)
|
|
883
|
+
.where("device_id", "in", rows.map((r) => r.id))
|
|
884
|
+
.where("state", "in", ["open", "quarantined"])
|
|
885
|
+
.execute()) {
|
|
886
|
+
if (o.state === "quarantined")
|
|
887
|
+
retirement.set(o.device_id, "recreateRequired");
|
|
888
|
+
else if (o.attempts > 0 && !retirement.has(o.device_id))
|
|
889
|
+
retirement.set(o.device_id, "pending");
|
|
890
|
+
}
|
|
876
891
|
// a dial-in device is online while a replica holds its machine's connection
|
|
877
892
|
const dialIn = new Set(rows.filter((r) => this.isDialIn(r.provider)).map((r) => r.id));
|
|
878
893
|
const online = new Map(await Promise.all([...dialIn].map(async (deviceId) => [deviceId, await this.relay.online(deviceId)])));
|
|
@@ -913,6 +928,7 @@ let DevicesService = class DevicesService {
|
|
|
913
928
|
}),
|
|
914
929
|
reconcileRequired: r.permission_reconcile_required,
|
|
915
930
|
filesLost: r.fs_status === "lost",
|
|
931
|
+
retirement: retirement.get(r.id) ?? null,
|
|
916
932
|
instance: live
|
|
917
933
|
? {
|
|
918
934
|
status: r.status,
|
|
@@ -790,6 +790,11 @@ export const PLATFORM_EXCLUSIONS = [
|
|
|
790
790
|
category: "transport",
|
|
791
791
|
reason: "Runs an extension UI action from the web app",
|
|
792
792
|
},
|
|
793
|
+
{
|
|
794
|
+
route: "POST /api/v1/admin/ui/query/:plugin/:id",
|
|
795
|
+
category: "transport",
|
|
796
|
+
reason: "the web's channel for plugin components; agents use the plugin's tools",
|
|
797
|
+
},
|
|
793
798
|
{
|
|
794
799
|
route: "POST /api/v1/admin/ui/embeds/:plugin/:id/token",
|
|
795
800
|
category: "transport",
|
|
@@ -48,6 +48,20 @@ function stateOf(e) {
|
|
|
48
48
|
next: "Rebuild its files with devices.reset-files (the workspace is wiped), or ask the person to do it on its device page.",
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
if (e.retirement === "recreateRequired") {
|
|
52
|
+
return {
|
|
53
|
+
state: "recreate_required",
|
|
54
|
+
reason: "Background work an earlier instance of it started may still run and can no longer be confirmed stopped; nothing runs on it.",
|
|
55
|
+
next: "Ask the person to delete the device and create it again (a device served by their own machine: sign the machine in again); use another device meanwhile.",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (e.retirement === "pending") {
|
|
59
|
+
return {
|
|
60
|
+
state: "retirement_pending",
|
|
61
|
+
reason: "An earlier instance of it has not been confirmed destroyed yet; nothing runs on it until its provider confirms it.",
|
|
62
|
+
next: "It is retried on its own; use another device meanwhile.",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
51
65
|
return { state: e.instance?.status ?? "ready" };
|
|
52
66
|
}
|
|
53
67
|
const row = (e) => ({
|
|
@@ -941,6 +941,19 @@ export declare class SandboxService {
|
|
|
941
941
|
* rebuilt it the new one is used.
|
|
942
942
|
*/
|
|
943
943
|
private ensure;
|
|
944
|
+
/**
|
|
945
|
+
* Under the exclusive lease, before the rebuild of an instance its provider answered gone
|
|
946
|
+
* (`SandboxGoneError` during a use, or `resume` answering `gone`): the row's incarnation is
|
|
947
|
+
* destroyed through its provider with this holder's fence token (a no-op where it is really
|
|
948
|
+
* gone; on a provider whose `gone` means "never served again", such as a local machine whose
|
|
949
|
+
* program restarted, it ends what the generation left) and that confirmed destruction is
|
|
950
|
+
* recorded (8.5 evidence) before anything new is created. Its revoked starts and owed revokes
|
|
951
|
+
* then settle against the record once a new incarnation runs, instead of quarantining the
|
|
952
|
+
* device for an incarnation replaced without a recorded destruction. A destroy that fails fails
|
|
953
|
+
* the use with nothing rebuilt: the row still names the gone incarnation, so the next use is
|
|
954
|
+
* told gone again and retries (unavailable for now, never `device.recreate_required`).
|
|
955
|
+
*/
|
|
956
|
+
private destroyGone;
|
|
944
957
|
/**
|
|
945
958
|
* {@link create} from {@link ensure}, then, for a provider whose limits are fixed at its file
|
|
946
959
|
* system (the new instance keeps the network its file system enforces, E2B), the installed
|
|
@@ -3117,6 +3117,7 @@ let SandboxService = class SandboxService {
|
|
|
3117
3117
|
const createdAt = row.created_at.getTime();
|
|
3118
3118
|
const fsResets = row.fs_resets;
|
|
3119
3119
|
if (handle && isInstance(row, gone) && row.status === "running") {
|
|
3120
|
+
await this.destroyGone(id, p, held, row, handle, fence, signal);
|
|
3120
3121
|
const created = await this.createSettled(ctx, p, held, row, fence, signal, want);
|
|
3121
3122
|
return { ...created, fsResets, info: { fresh: true, restarted: true }, fence };
|
|
3122
3123
|
}
|
|
@@ -3198,6 +3199,7 @@ let SandboxService = class SandboxService {
|
|
|
3198
3199
|
this.log.info("sandbox instance is gone at the provider; recreating", {
|
|
3199
3200
|
deviceId: id,
|
|
3200
3201
|
});
|
|
3202
|
+
await this.destroyGone(id, p, held, row, handle, fence, signal);
|
|
3201
3203
|
}
|
|
3202
3204
|
const created = await this.createSettled(ctx, p, held, row, fence, signal, want);
|
|
3203
3205
|
// had_instance only ever becomes true: any earlier instance (even if a rebuild failed since)
|
|
@@ -3218,6 +3220,39 @@ let SandboxService = class SandboxService {
|
|
|
3218
3220
|
throw err;
|
|
3219
3221
|
}
|
|
3220
3222
|
}
|
|
3223
|
+
/**
|
|
3224
|
+
* Under the exclusive lease, before the rebuild of an instance its provider answered gone
|
|
3225
|
+
* (`SandboxGoneError` during a use, or `resume` answering `gone`): the row's incarnation is
|
|
3226
|
+
* destroyed through its provider with this holder's fence token (a no-op where it is really
|
|
3227
|
+
* gone; on a provider whose `gone` means "never served again", such as a local machine whose
|
|
3228
|
+
* program restarted, it ends what the generation left) and that confirmed destruction is
|
|
3229
|
+
* recorded (8.5 evidence) before anything new is created. Its revoked starts and owed revokes
|
|
3230
|
+
* then settle against the record once a new incarnation runs, instead of quarantining the
|
|
3231
|
+
* device for an incarnation replaced without a recorded destruction. A destroy that fails fails
|
|
3232
|
+
* the use with nothing rebuilt: the row still names the gone incarnation, so the next use is
|
|
3233
|
+
* told gone again and retries (unavailable for now, never `device.recreate_required`).
|
|
3234
|
+
*/
|
|
3235
|
+
async destroyGone(id, p, held, row, handle, fence, signal) {
|
|
3236
|
+
assertOwnRow(row, p);
|
|
3237
|
+
// still the holder (a fenced write), so the destroy's token is this holder's latest
|
|
3238
|
+
await this.fenced(held, id, fence, {});
|
|
3239
|
+
try {
|
|
3240
|
+
await p.impl.destroy(handle, signal, { token: fence.gen });
|
|
3241
|
+
}
|
|
3242
|
+
catch (err) {
|
|
3243
|
+
if (isStaleFenceError(err))
|
|
3244
|
+
throw await this.staleHolder(held, id, p.plugin, fence, "destroy", err);
|
|
3245
|
+
if (!signal.aborted)
|
|
3246
|
+
this.log.warn("cannot destroy the gone sandbox instance; it is rebuilt on a later use", {
|
|
3247
|
+
deviceId: id,
|
|
3248
|
+
err,
|
|
3249
|
+
});
|
|
3250
|
+
throw err;
|
|
3251
|
+
}
|
|
3252
|
+
if (!(await held.renew()))
|
|
3253
|
+
throw new SandboxLockLostError(id);
|
|
3254
|
+
await this.retirement.recordDestruction(id, p.plugin, String(row.created_at.getTime()));
|
|
3255
|
+
}
|
|
3221
3256
|
/**
|
|
3222
3257
|
* {@link create} from {@link ensure}, then, for a provider whose limits are fixed at its file
|
|
3223
3258
|
* system (the new instance keeps the network its file system enforces, E2B), the installed
|
|
@@ -3446,12 +3481,17 @@ let SandboxService = class SandboxService {
|
|
|
3446
3481
|
return null;
|
|
3447
3482
|
}
|
|
3448
3483
|
this.log.info("sandbox limits changed; recreating the instance on the kept files", facts);
|
|
3449
|
-
//
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3484
|
+
// the provider answered gone: destroyed with confirmation and recorded before the rebuild
|
|
3485
|
+
if (gone)
|
|
3486
|
+
await this.destroyGone(id, p, held, row, handle, fence, signal);
|
|
3487
|
+
else {
|
|
3488
|
+
// still the holder (a fenced write), so a holder whose lease ended meanwhile never destroys
|
|
3489
|
+
// what a newer one uses; the destroy's token is then this holder's latest
|
|
3490
|
+
await this.fenced(held, id, fence, {});
|
|
3491
|
+
let destroyed = false;
|
|
3453
3492
|
try {
|
|
3454
3493
|
await p.impl.destroy(handle, signal, { token: fence.gen });
|
|
3494
|
+
destroyed = true;
|
|
3455
3495
|
}
|
|
3456
3496
|
catch (err) {
|
|
3457
3497
|
if (isStaleFenceError(err))
|
|
@@ -3464,6 +3504,13 @@ let SandboxService = class SandboxService {
|
|
|
3464
3504
|
err,
|
|
3465
3505
|
});
|
|
3466
3506
|
}
|
|
3507
|
+
// the provider's destroy resolved: confirmed destruction of exactly this incarnation (8.5
|
|
3508
|
+
// evidence, as in destroyRow), so its owed revokes settle once the new one runs
|
|
3509
|
+
if (destroyed) {
|
|
3510
|
+
if (!(await held.renew()))
|
|
3511
|
+
throw new SandboxLockLostError(id);
|
|
3512
|
+
await this.retirement.recordDestruction(id, p.plugin, String(row.created_at.getTime()));
|
|
3513
|
+
}
|
|
3467
3514
|
}
|
|
3468
3515
|
return await this.lifecycleStep("recreate", id, p, signal, () => this.create(ctx, p, held, row, fence, signal, want));
|
|
3469
3516
|
}
|
|
@@ -254,13 +254,8 @@ export declare const PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands
|
|
|
254
254
|
* The device does not allow running outside the sandbox (`device.outside_sandbox_not_allowed`).
|
|
255
255
|
*/
|
|
256
256
|
export declare const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner whether its provider can allow it.";
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
* 8.5): the device's earlier instance may still run background work an earlier version started.
|
|
260
|
-
* Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
|
|
261
|
-
*/
|
|
262
|
-
export declare const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device.";
|
|
263
|
-
export declare const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device.";
|
|
257
|
+
export declare const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device. Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
|
|
258
|
+
export declare const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device. Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
|
|
264
259
|
/**
|
|
265
260
|
* A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
|
|
266
261
|
* the refusal's own message (a provider may write it).
|
|
@@ -276,8 +276,10 @@ export const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow run
|
|
|
276
276
|
* 8.5): the device's earlier instance may still run background work an earlier version started.
|
|
277
277
|
* Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
|
|
278
278
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
/** What still works without the device: attachments and artifacts are read from file storage. */
|
|
280
|
+
const READ_BY_ID_HINT = "Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
|
|
281
|
+
export const RETIREMENT_PENDING_TOOL_TEXT = `This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device. ${READ_BY_ID_HINT}`;
|
|
282
|
+
export const RETIREMENT_RECREATE_TOOL_TEXT = `Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device. ${READ_BY_ID_HINT}`;
|
|
281
283
|
/** The model-facing text of a retirement refusal's code (`device.unavailable` for any other). */
|
|
282
284
|
function retirementToolText(code) {
|
|
283
285
|
if (code === "device.recreate_required")
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -740,6 +740,10 @@ export declare class ToolPipeline {
|
|
|
740
740
|
private networkBlocked;
|
|
741
741
|
/** The call's live loopback port grant (null: none, ended, or no grants service). */
|
|
742
742
|
private loopbackGrantOf;
|
|
743
|
+
/**
|
|
744
|
+
* The attempt that recorded a ready-grant loopback rerun for this call, or null when none did.
|
|
745
|
+
*/
|
|
746
|
+
private readyLoopbackRerunOf;
|
|
743
747
|
/**
|
|
744
748
|
* A device service's loopback refusal (browser loopback port grants): the port of the person's
|
|
745
749
|
* own device a service of an extension declaring `permissions.deviceAccess.loopbackPorts` was
|
package/dist/tools/pipeline.js
CHANGED
|
@@ -615,8 +615,15 @@ function loopbackAskRerunAfter(ask) {
|
|
|
615
615
|
* the call's live loopback port grant (Full access or the review model granted the port to the
|
|
616
616
|
* attempt that was refused it).
|
|
617
617
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
618
|
+
/** The idempotency key of the `permission_reviewed` event tying a ready-grant rerun to a call. */
|
|
619
|
+
const loopbackReadyRerunIdemKey = (runId, callId) => `permission_reviewed:loopback_ready:${runId}:${callId}`;
|
|
620
|
+
function rerunPoints(ask, grant, readyRerun = null) {
|
|
621
|
+
const points = [
|
|
622
|
+
serviceRerunAfter(ask),
|
|
623
|
+
loopbackAskRerunAfter(ask),
|
|
624
|
+
grant?.attempt ?? null,
|
|
625
|
+
readyRerun,
|
|
626
|
+
];
|
|
620
627
|
return new Set(points.filter((p) => p !== null));
|
|
621
628
|
}
|
|
622
629
|
/** An ask whose approval runs the call again: it belongs to the attempt that asked. */
|
|
@@ -905,11 +912,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
905
912
|
// the call's network ask (one per call) and its live loopback port grant
|
|
906
913
|
const ask = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
907
914
|
const grant = await this.loopbackGrantOf(ctx.runId, call.id);
|
|
915
|
+
const readyRerun = await this.readyLoopbackRerunOf(ctx.conversationId, ctx.runId, call.id);
|
|
908
916
|
let attempt = rounds.length + 1;
|
|
909
917
|
// each time the call ran again (after its network ask, browser use spec §7.1, or a loopback
|
|
910
918
|
// grant or ask) took one attempt more: input rounds asked after a re-run come after it, so
|
|
911
919
|
// every re-run point the count has passed adds one, in order
|
|
912
|
-
const reruns = rerunPoints(ask, grant);
|
|
920
|
+
const reruns = rerunPoints(ask, grant, readyRerun);
|
|
913
921
|
if (rounds.length > 0) {
|
|
914
922
|
for (const p of [...reruns].sort((a, b) => a - b))
|
|
915
923
|
if (attempt > p)
|
|
@@ -945,10 +953,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
945
953
|
(!asksPerAttempt(ask) ||
|
|
946
954
|
ask.detail?.attempt === attempt);
|
|
947
955
|
const grantedHere = !askedHere && grant !== null && grant.attempt === attempt;
|
|
948
|
-
|
|
956
|
+
const readyRerunHere = !askedHere && !grantedHere && readyRerun === attempt;
|
|
957
|
+
if (askedHere || grantedHere || readyRerunHere) {
|
|
949
958
|
const notes = askedHere && ask !== null
|
|
950
959
|
? settledNetworkNotes(ask, approvalHours(ask))
|
|
951
|
-
:
|
|
960
|
+
: grantedHere
|
|
961
|
+
? [loopbackGrantedNote(grant.port)]
|
|
962
|
+
: [];
|
|
952
963
|
if (notes === null)
|
|
953
964
|
return approvalWait(ask);
|
|
954
965
|
const rerunsHere = !askedHere ||
|
|
@@ -2596,6 +2607,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2596
2607
|
async loopbackGrantOf(runId, callId) {
|
|
2597
2608
|
return (await this.loopbackGrants?.forCall(runId, callId)) ?? null;
|
|
2598
2609
|
}
|
|
2610
|
+
/**
|
|
2611
|
+
* The attempt that recorded a ready-grant loopback rerun for this call, or null when none did.
|
|
2612
|
+
*/
|
|
2613
|
+
async readyLoopbackRerunOf(conversationId, runId, callId) {
|
|
2614
|
+
const ev = await this.deps.eventLog.findByIdem(conversationId, loopbackReadyRerunIdemKey(runId, callId));
|
|
2615
|
+
return ev?.type === "permission_reviewed"
|
|
2616
|
+
? (ev.payload.loopback?.readyRerunAttempt ?? null)
|
|
2617
|
+
: null;
|
|
2618
|
+
}
|
|
2599
2619
|
/**
|
|
2600
2620
|
* A device service's loopback refusal (browser loopback port grants): the port of the person's
|
|
2601
2621
|
* own device a service of an extension declaring `permissions.deviceAccess.loopbackPorts` was
|
|
@@ -2659,17 +2679,6 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2659
2679
|
port,
|
|
2660
2680
|
};
|
|
2661
2681
|
const live = await grants.liveForRoot(ctx.orgId, device.deviceId, serviceId, facts.rootConversationId);
|
|
2662
|
-
if (live.some((g) => g.port === port)) {
|
|
2663
|
-
// granted already (the panel, an earlier call): the service had not applied it yet, so the
|
|
2664
|
-
// call runs again once; refused again (or granted to this call), its result stands
|
|
2665
|
-
if (rerunning || (await grants.forCall(ctx.runId, call.id)) !== null)
|
|
2666
|
-
return { kind: "write", notes: [loopbackNotAppliedNote(port)] };
|
|
2667
|
-
await this.writeResultIn(ctx, call.id, toolKey, kept, [...pre], callAudit, []);
|
|
2668
|
-
return { kind: "rerun", notes: [] };
|
|
2669
|
-
}
|
|
2670
|
-
// a call that ran again after its grant is not decided again (the port was closed meanwhile)
|
|
2671
|
-
if (rerunning)
|
|
2672
|
-
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2673
2682
|
const binding = {
|
|
2674
2683
|
orgId: facts.orgId,
|
|
2675
2684
|
rootConversationId: facts.rootConversationId,
|
|
@@ -2687,6 +2696,36 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2687
2696
|
scopeRevision: facts.scopeRevision,
|
|
2688
2697
|
authorityRevision: facts.authorityRevision,
|
|
2689
2698
|
};
|
|
2699
|
+
if (live.some((g) => g.port === port)) {
|
|
2700
|
+
// granted already (the panel, an earlier call): the service had not applied it yet, so the
|
|
2701
|
+
// call runs again once; refused again (or granted to this call), its result stands
|
|
2702
|
+
if (rerunning || (await grants.forCall(ctx.runId, call.id)) !== null)
|
|
2703
|
+
return { kind: "write", notes: [loopbackNotAppliedNote(port)] };
|
|
2704
|
+
const readyCandidate = {
|
|
2705
|
+
binding,
|
|
2706
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
2707
|
+
scopeKind: "loopback-port",
|
|
2708
|
+
loopback: { service: serviceId, port, readyRerunAttempt: attempt },
|
|
2709
|
+
};
|
|
2710
|
+
const readyEvent = {
|
|
2711
|
+
type: "permission_reviewed",
|
|
2712
|
+
runId: ctx.runId,
|
|
2713
|
+
idemKey: loopbackReadyRerunIdemKey(ctx.runId, call.id),
|
|
2714
|
+
payload: {
|
|
2715
|
+
...readyCandidate,
|
|
2716
|
+
candidateHash: permissionScopeHash(readyCandidate),
|
|
2717
|
+
outcome: "allow",
|
|
2718
|
+
reason: "Loopback port already granted for this conversation; retrying after the device applies it.",
|
|
2719
|
+
decisionSource: "rule",
|
|
2720
|
+
crossing: "loopback-port",
|
|
2721
|
+
},
|
|
2722
|
+
};
|
|
2723
|
+
await this.writeResultIn(ctx, call.id, toolKey, kept, [readyEvent, ...pre], callAudit, []);
|
|
2724
|
+
return { kind: "rerun", notes: [] };
|
|
2725
|
+
}
|
|
2726
|
+
// a call that ran again after its grant is not decided again (the port was closed meanwhile)
|
|
2727
|
+
if (rerunning)
|
|
2728
|
+
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2690
2729
|
const reviewed = (outcome, reason, decisionSource) => {
|
|
2691
2730
|
const candidate = {
|
|
2692
2731
|
binding,
|
|
@@ -1,11 +1,11 @@
|
|
|
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";
|
|
5
5
|
import { type Principal } from "../identity/principal.js";
|
|
6
6
|
import { SessionService } from "../identity/sessions.js";
|
|
7
7
|
import { EmbedTokens } from "./embed-token.js";
|
|
8
|
-
import { ContributionParams, PlatformActionBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
8
|
+
import { ContributionParams, PlatformActionBody, PlatformQueryBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
9
9
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
10
10
|
import { type UiArrangementSlot, type UiContributionItem, UiViews } from "./views.js";
|
|
11
11
|
/**
|
|
@@ -45,6 +45,9 @@ export declare class AdminUiController {
|
|
|
45
45
|
view: UiView;
|
|
46
46
|
}>;
|
|
47
47
|
action(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof PlatformActionBody>): Promise<UiActionResult>;
|
|
48
|
+
query(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof PlatformQueryBody>): Promise<{
|
|
49
|
+
data: JsonValue;
|
|
50
|
+
}>;
|
|
48
51
|
embedToken(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>): Promise<{
|
|
49
52
|
token: string;
|
|
50
53
|
src: string;
|
|
@@ -15,7 +15,7 @@ import { SessionService } from "../identity/sessions.js";
|
|
|
15
15
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
16
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
17
17
|
import { EMBED_TOKEN_TTL_SECONDS, EmbedTokens } from "./embed-token.js";
|
|
18
|
-
import { ContributionParams, PlatformActionBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
18
|
+
import { ContributionParams, PlatformActionBody, PlatformQueryBody, PlatformViewQuery, } from "./ui.schemas.js";
|
|
19
19
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
20
20
|
import { BEARER_RE, embedSrc } from "./views.controller.js";
|
|
21
21
|
import { UiViews } from "./views.js";
|
|
@@ -25,6 +25,8 @@ class AdminUiViewQueryDto extends createZodDto(PlatformViewQuery, "AdminUiViewQu
|
|
|
25
25
|
}
|
|
26
26
|
class AdminUiActionBodyDto extends createZodDto(PlatformActionBody, "AdminUiActionBody") {
|
|
27
27
|
}
|
|
28
|
+
class AdminUiQueryBodyDto extends createZodDto(PlatformQueryBody, "AdminUiQueryBody") {
|
|
29
|
+
}
|
|
28
30
|
/**
|
|
29
31
|
* Extension UI in the admin console (UI slots spec §7, platform scope): the `platform.page`
|
|
30
32
|
* contributions, for super admins only (`@SuperAdmin`, a person: service tokens are refused), with
|
|
@@ -85,6 +87,10 @@ let AdminUiController = class AdminUiController {
|
|
|
85
87
|
...(body.answer !== undefined && { answer: body.answer }),
|
|
86
88
|
});
|
|
87
89
|
}
|
|
90
|
+
async query(principal, { plugin, id }, body) {
|
|
91
|
+
const p = requireUser(principal);
|
|
92
|
+
return this.views.query({ scope: "platform", accountId: p.account.id, plugin, id, locale: body.locale }, { query: body.query, ...(body.params !== undefined && { params: body.params }) });
|
|
93
|
+
}
|
|
88
94
|
async embedToken(principal, { plugin, id }) {
|
|
89
95
|
const p = requireUser(principal);
|
|
90
96
|
const target = await this.views.embed({
|
|
@@ -168,6 +174,13 @@ __decorate([
|
|
|
168
174
|
__param(1, ZParam(AdminUiContributionParamsDto)),
|
|
169
175
|
__param(2, ZBody(AdminUiActionBodyDto))
|
|
170
176
|
], AdminUiController.prototype, "action", null);
|
|
177
|
+
__decorate([
|
|
178
|
+
Post("query/:plugin/:id"),
|
|
179
|
+
HttpCode(200),
|
|
180
|
+
__param(0, CurrentPrincipal()),
|
|
181
|
+
__param(1, ZParam(AdminUiContributionParamsDto)),
|
|
182
|
+
__param(2, ZBody(AdminUiQueryBodyDto))
|
|
183
|
+
], AdminUiController.prototype, "query", null);
|
|
171
184
|
__decorate([
|
|
172
185
|
Post("embeds/:plugin/:id/token"),
|
|
173
186
|
HttpCode(200),
|
package/dist/ui/ui.schemas.d.ts
CHANGED
|
@@ -91,5 +91,14 @@ export declare const PlatformActionBody: z.ZodObject<{
|
|
|
91
91
|
zh: "zh";
|
|
92
92
|
}>>;
|
|
93
93
|
}, z.core.$strip>;
|
|
94
|
+
/** `POST /api/v1/admin/ui/query/:plugin/:id`: a component query of a platform page (no context id). */
|
|
95
|
+
export declare const PlatformQueryBody: z.ZodObject<{
|
|
96
|
+
query: z.ZodString;
|
|
97
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
98
|
+
locale: z.ZodDefault<z.ZodEnum<{
|
|
99
|
+
en: "en";
|
|
100
|
+
zh: "zh";
|
|
101
|
+
}>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
94
103
|
/** The slot catalog route the Platform operation `ui.slots` mirrors (`check:platform-ops` key). */
|
|
95
104
|
export declare const UI_ROUTES: readonly RouteSchemas[];
|
package/dist/ui/ui.schemas.js
CHANGED
|
@@ -87,5 +87,7 @@ export const EmbedTokenBody = z
|
|
|
87
87
|
export const PlatformViewQuery = z.object({ locale: Locale });
|
|
88
88
|
/** `POST /api/v1/admin/ui/actions/:plugin/:id`: an action of a platform page (no context id). */
|
|
89
89
|
export const PlatformActionBody = ActionBody.omit({ conversationId: true, agentId: true });
|
|
90
|
+
/** `POST /api/v1/admin/ui/query/:plugin/:id`: a component query of a platform page (no context id). */
|
|
91
|
+
export const PlatformQueryBody = QueryBody.omit({ conversationId: true, agentId: true });
|
|
90
92
|
/** The slot catalog route the Platform operation `ui.slots` mirrors (`check:platform-ops` key). */
|
|
91
93
|
export const UI_ROUTES = [{ route: "GET /api/v1/ui/slots" }];
|
package/dist/ui/views.d.ts
CHANGED
|
@@ -225,7 +225,7 @@ export declare class UiViews {
|
|
|
225
225
|
* result that is not JSON or over `UI_LIMITS.componentQueryBytes` 502
|
|
226
226
|
* `ui.query_result_too_large`.
|
|
227
227
|
*/
|
|
228
|
-
query(t:
|
|
228
|
+
query(t: UiTarget, input: {
|
|
229
229
|
query: string;
|
|
230
230
|
params?: unknown;
|
|
231
231
|
}): Promise<{
|
package/dist/ui/views.js
CHANGED
|
@@ -488,18 +488,17 @@ let UiViews = class UiViews {
|
|
|
488
488
|
throw new ApiError("ui.query_params_too_large", `params must be at most ${UI_LIMITS.componentQueryParamsBytes} bytes as JSON`);
|
|
489
489
|
}
|
|
490
490
|
const handler = resolved.entry.query;
|
|
491
|
-
|
|
492
|
-
const args = resolved.args;
|
|
491
|
+
const scopeField = t.scope === "platform" ? { scope: "platform" } : { orgId: t.orgId };
|
|
493
492
|
const data = await callExtension({
|
|
494
493
|
log: this.d.log,
|
|
495
494
|
plugin: t.plugin,
|
|
496
495
|
what: "query",
|
|
497
|
-
fields: { plugin: t.plugin, contribution: t.id, query: input.query,
|
|
496
|
+
fields: { plugin: t.plugin, contribution: t.id, query: input.query, ...scopeField },
|
|
498
497
|
timeoutMs: UI_QUERY_TIMEOUT_MS,
|
|
499
498
|
failCode: "ui.query_failed",
|
|
500
499
|
timeoutCode: "ui.query_timeout",
|
|
501
500
|
failMessage: `Plugin ${t.plugin} failed to answer query ${input.query} of ${t.id}`,
|
|
502
|
-
fn: (signal) => handler({ ...args, query: input.query, params, signal }),
|
|
501
|
+
fn: (signal) => handler({ ...resolved.args, query: input.query, params, signal }),
|
|
503
502
|
});
|
|
504
503
|
let json;
|
|
505
504
|
try {
|
|
@@ -514,7 +513,7 @@ let UiViews = class UiViews {
|
|
|
514
513
|
plugin: t.plugin,
|
|
515
514
|
contribution: t.id,
|
|
516
515
|
query: input.query,
|
|
517
|
-
|
|
516
|
+
...scopeField,
|
|
518
517
|
...(bytes !== undefined && { bytes }),
|
|
519
518
|
});
|
|
520
519
|
throw new ApiError("ui.query_result_too_large", `Plugin ${t.plugin} returned a query result that is not JSON of at most ${UI_LIMITS.componentQueryBytes} bytes`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.117",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.92"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/ws": "^8.18.2",
|
|
76
76
|
"@types/yauzl": "3.4.0",
|
|
77
77
|
"ws": "^8.22.0",
|
|
78
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.51"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|