@capybara-hq/kernel 0.1.0-rc.65 → 0.1.0-rc.67
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 +0 -8
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/admin-agents.d.ts +2 -2
- package/dist/agents/admin-agents.js +2 -1
- package/dist/agents/agent-lookup.js +2 -1
- package/dist/agents/agent-profile.service.d.ts +5 -2
- package/dist/agents/agent-profile.service.js +13 -2
- package/dist/agents/agents.controller.d.ts +4 -3
- package/dist/agents/agents.controller.js +7 -3
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.schemas.d.ts +6 -6
- package/dist/agents/agents.service.d.ts +23 -2
- package/dist/agents/agents.service.js +61 -6
- package/dist/agents/avatar-view.d.ts +8 -0
- package/dist/agents/avatar-view.js +12 -0
- package/dist/agents/profile.d.ts +38 -13
- package/dist/agents/profile.js +31 -20
- package/dist/attribution/platform-attribution.d.ts +15 -6
- package/dist/attribution/platform-attribution.js +31 -14
- package/dist/background/poll.job.d.ts +1 -1
- package/dist/background/poll.job.js +8 -6
- package/dist/background/tasks.service.js +1 -1
- package/dist/catalog/catalog-content.d.ts +6 -3
- package/dist/catalog/catalog-content.js +7 -8
- package/dist/catalog/claude/translate.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/marketplaces.service.js +2 -1
- package/dist/catalog/plugin-package.d.ts +3 -2
- package/dist/channels/file-delivery.d.ts +2 -0
- package/dist/channels/file-delivery.js +1 -1
- package/dist/channels/inbound.d.ts +8 -4
- package/dist/channels/inbound.js +14 -7
- package/dist/channels/outbound.js +11 -5
- package/dist/channels/phrases.d.ts +21 -13
- package/dist/channels/phrases.js +21 -14
- package/dist/client/client-files.js +1 -1
- package/dist/config/product-name.d.ts +8 -0
- package/dist/config/product-name.js +9 -0
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +17 -4
- package/dist/conversations/conversations.service.d.ts +4 -3
- package/dist/conversations/conversations.service.js +15 -2
- package/dist/ctx/create-ctx.js +5 -2
- package/dist/ctx/device-provider-check.d.ts +7 -0
- package/dist/ctx/device-provider-check.js +21 -0
- package/dist/db/kernel-schema.d.ts +7 -0
- package/dist/devices/access.d.ts +16 -46
- package/dist/devices/access.js +26 -62
- package/dist/devices/access.module.js +2 -2
- package/dist/devices/conversation-devices.d.ts +38 -18
- package/dist/devices/conversation-devices.js +69 -51
- package/dist/devices/default-provider-setting.d.ts +45 -0
- package/dist/devices/default-provider-setting.js +59 -0
- package/dist/devices/device-projects.service.js +7 -2
- package/dist/devices/device-provider-selection.d.ts +37 -0
- package/dist/devices/device-provider-selection.js +86 -0
- package/dist/devices/device-provider-selection.module.d.ts +3 -0
- package/dist/devices/device-provider-selection.module.js +22 -0
- package/dist/devices/devices.controller.d.ts +8 -5
- package/dist/devices/devices.controller.js +7 -4
- package/dist/devices/devices.module.js +3 -1
- package/dist/devices/devices.schemas.js +2 -2
- package/dist/devices/devices.service.d.ts +72 -83
- package/dist/devices/devices.service.js +139 -248
- package/dist/devices/dto.d.ts +9 -0
- package/dist/devices/dto.js +15 -2
- package/dist/devices/label.d.ts +3 -5
- package/dist/devices/label.js +3 -14
- package/dist/devices/legacy-cleanup.job.d.ts +2 -2
- package/dist/devices/legacy-cleanup.job.js +6 -6
- package/dist/errors.d.ts +15 -1
- package/dist/errors.js +15 -1
- package/dist/extensions/guide-places.d.ts +2 -1
- package/dist/extensions/guide-places.js +8 -2
- package/dist/extensions/locks.d.ts +1 -1
- package/dist/extensions/locks.js +1 -1
- package/dist/extensions/org-config.d.ts +20 -4
- package/dist/extensions/org-config.js +23 -6
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/permission-view.js +2 -2
- package/dist/extensions/plugin-guides.d.ts +1 -1
- package/dist/extensions/plugin-guides.js +11 -3
- package/dist/extensions/point-defaults.d.ts +14 -0
- package/dist/extensions/point-defaults.js +70 -47
- package/dist/extensions/resolve.js +7 -2
- package/dist/git/gateway.d.ts +9 -0
- package/dist/git/gateway.js +36 -17
- package/dist/git/gateway.route.d.ts +1 -1
- package/dist/git/gateway.route.js +1 -3
- package/dist/http/app.d.ts +1 -1
- package/dist/identity/app-auth.d.ts +4 -3
- package/dist/identity/app-auth.js +7 -8
- package/dist/identity/settings.d.ts +8 -0
- package/dist/identity/settings.js +30 -3
- package/dist/identity/sso.d.ts +13 -7
- package/dist/identity/sso.js +21 -7
- package/dist/infra/config/kernel-config.service.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +7 -6
- package/dist/local-devices/device-routes.d.ts +1 -1
- package/dist/local-devices/device-routes.js +2 -2
- package/dist/local-devices/local-device-provider.d.ts +14 -11
- package/dist/local-devices/local-device-provider.js +14 -0
- package/dist/local-devices/local-devices.module.d.ts +4 -4
- package/dist/local-devices/local-devices.module.js +5 -3
- package/dist/local-devices/owner-report.js +2 -1
- package/dist/local-devices/targets.d.ts +2 -0
- package/dist/local-devices/targets.js +10 -0
- package/dist/orgs/offboarding.js +9 -0
- package/dist/orgs/settings.service.d.ts +26 -1
- package/dist/orgs/settings.service.js +44 -3
- package/dist/platform/ops/admin.ops.js +8 -3
- package/dist/platform/ops/agents.ops.d.ts +6 -1
- package/dist/platform/ops/agents.ops.js +38 -11
- package/dist/platform/ops/devices.ops.js +25 -20
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/platform-icons.ops.js +4 -4
- package/dist/platform/ops/platform.ops.js +2 -1
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/runtime/plugin-context.service.js +1 -12
- package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
- package/dist/sandbox/cloud-permission-snapshot.js +3 -3
- package/dist/sandbox/device-reports.d.ts +50 -0
- package/dist/sandbox/device-reports.js +157 -0
- package/dist/sandbox/held-operations.d.ts +8 -8
- package/dist/sandbox/leases.d.ts +1 -1
- package/dist/sandbox/leases.js +1 -1
- package/dist/sandbox/operation-authority.d.ts +5 -2
- package/dist/sandbox/operation-authority.js +12 -11
- package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
- package/dist/sandbox/operation-reconcile.job.js +5 -5
- package/dist/sandbox/permission-availability.d.ts +2 -2
- package/dist/sandbox/permission-call-types.d.ts +5 -0
- package/dist/sandbox/permission-facts.d.ts +2 -2
- package/dist/sandbox/permission-facts.js +5 -5
- package/dist/sandbox/providers.d.ts +23 -24
- package/dist/sandbox/providers.js +38 -46
- package/dist/sandbox/providers.module.js +3 -3
- package/dist/sandbox/review/classifier.d.ts +6 -0
- package/dist/sandbox/review/classifier.js +12 -1
- package/dist/sandbox/review/index.d.ts +1 -1
- package/dist/sandbox/review/index.js +1 -1
- package/dist/sandbox/sandbox.module.d.ts +1 -1
- package/dist/sandbox/sandbox.module.js +7 -2
- package/dist/sandbox/sandbox.service.d.ts +95 -68
- package/dist/sandbox/sandbox.service.js +212 -208
- package/dist/setup/setup-guides.service.d.ts +4 -1
- package/dist/setup/setup-guides.service.js +6 -1
- package/dist/themes/avatar-preset-key.d.ts +6 -0
- package/dist/themes/avatar-preset-key.js +9 -0
- package/dist/themes/platform-icon.service.js +1 -1
- package/dist/themes/theme-delivery.service.d.ts +10 -2
- package/dist/themes/theme-delivery.service.js +26 -11
- package/dist/themes/theme-state.d.ts +43 -2
- package/dist/themes/theme-state.js +61 -4
- package/dist/themes/themes-public.controller.d.ts +3 -3
- package/dist/themes/themes-public.controller.js +3 -3
- package/dist/themes/themes.service.d.ts +28 -1
- package/dist/themes/themes.service.js +36 -2
- package/dist/tools/builtins/image/generate.d.ts +3 -0
- package/dist/tools/builtins/image/generate.js +21 -11
- package/dist/tools/builtins/image/index.d.ts +1 -1
- package/dist/tools/builtins/image/index.js +1 -1
- package/dist/tools/builtins/platform.js +25 -17
- package/dist/tools/builtins/sandbox/common.d.ts +37 -13
- package/dist/tools/builtins/sandbox/common.js +63 -19
- package/dist/tools/builtins/sandbox/read.d.ts +5 -2
- package/dist/tools/builtins/sandbox/read.js +9 -6
- package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-output.js +6 -5
- package/dist/tools/builtins/skill-load.js +13 -4
- package/dist/tools/connectors.service.js +2 -1
- package/dist/tools/oauth/discovery.d.ts +2 -0
- package/dist/tools/oauth/discovery.js +3 -1
- package/dist/until-aborted.d.ts +5 -0
- package/dist/until-aborted.js +16 -0
- package/package.json +4 -4
- package/src/migrations/0176_device_report.sql +6 -0
|
@@ -6,7 +6,7 @@ import type { KernelConfig } from "../../../config/schema.js";
|
|
|
6
6
|
import type { ChildAgent } from "../../../conversations/agent-tree.js";
|
|
7
7
|
import type { AttachmentsService } from "../../../conversations/attachments.service.js";
|
|
8
8
|
import type { EventLog } from "../../../conversations/event-log.js";
|
|
9
|
-
import { type ConversationDevices, type WorkingFacts } from "../../../devices/conversation-devices.js";
|
|
9
|
+
import { type ConversationDevices, type DeviceUnusableReason, type WorkingFacts } from "../../../devices/conversation-devices.js";
|
|
10
10
|
import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
|
|
11
11
|
import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
|
|
12
12
|
import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
|
|
@@ -24,14 +24,15 @@ export interface SandboxToolDeps {
|
|
|
24
24
|
* `currentInstance` too: a background `Bash` launch records the instance it started in; and
|
|
25
25
|
* `ifRunning`, which `TaskOutput` reads a task through.
|
|
26
26
|
*/
|
|
27
|
-
sandbox: Pick<SandboxService, "
|
|
27
|
+
sandbox: Pick<SandboxService, "withSandbox"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning" | "withOperations">>;
|
|
28
28
|
/**
|
|
29
29
|
* The device a call enters: the root conversation's, checked for its owner every call.
|
|
30
|
-
* `usableNow` (absent in test stubs:
|
|
31
|
-
* conversation's device
|
|
32
|
-
* in test stubs: free mode) gives what decides the working root, read as the review
|
|
30
|
+
* `usableNow` (absent in test stubs: the device's provider serves the org) tells a listing
|
|
31
|
+
* whether a conversation's device has its provider on in the org (ruling R8). `workingFacts`
|
|
32
|
+
* (absent in test stubs: free mode) gives what decides the working root, read as the review
|
|
33
|
+
* reads it.
|
|
33
34
|
*/
|
|
34
|
-
devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "modeLevel" | "workingFacts" | "projectReach">>;
|
|
35
|
+
devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "unusableReason" | "modeLevel" | "workingFacts" | "projectReach">>;
|
|
35
36
|
/** Background `Bash` tasks; absent in test stubs, where `run_in_background` is refused. */
|
|
36
37
|
background?: Pick<BackgroundTaskStore, "releaseStop" | "get" | "advanceOffset" | "runningOwnedBy" | "finishedOwnedBy"> & Partial<Pick<BackgroundTaskStore, "reserveManaged" | "failManagedPreEffect">>;
|
|
37
38
|
/**
|
|
@@ -125,10 +126,17 @@ export declare const SANDBOX_RESTARTED_NOTICE = "The device's instance was resta
|
|
|
125
126
|
export declare const sandboxFilesResetNotice: (roots: SandboxRoots) => string;
|
|
126
127
|
/** {@link sandboxFilesResetNotice} of an instance with the default roots. */
|
|
127
128
|
export declare const SANDBOX_FILES_RESET_NOTICE: string;
|
|
129
|
+
/**
|
|
130
|
+
* A conversation with no device while device providers are on in the org: its owner has no default
|
|
131
|
+
* device and the org has no default device provider to make one.
|
|
132
|
+
*/
|
|
133
|
+
export declare const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
|
|
128
134
|
/** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
|
|
129
135
|
export declare const SANDBOX_UNAVAILABLE_REASON: string;
|
|
130
|
-
/** The error of a sandbox call
|
|
136
|
+
/** The error of a sandbox call with no device provider on in the org. */
|
|
131
137
|
export declare function noSandboxError(): ToolError;
|
|
138
|
+
/** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
|
|
139
|
+
export declare const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
|
|
132
140
|
/**
|
|
133
141
|
* A provider call that never connected (refused, unknown host, unreachable network): the request
|
|
134
142
|
* did not reach the provider, so the call did nothing in the sandbox.
|
|
@@ -286,7 +294,7 @@ export declare function admissionUnavailableText(cause: PermissionAvailabilityCa
|
|
|
286
294
|
* sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
|
|
287
295
|
* model's doing; whether anything ran is not proven.
|
|
288
296
|
*/
|
|
289
|
-
export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in
|
|
297
|
+
export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
|
|
290
298
|
/**
|
|
291
299
|
* A device request whose machine came back as a new run of capybara-device before answering
|
|
292
300
|
* (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
|
|
@@ -375,14 +383,30 @@ export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
|
|
|
375
383
|
*/
|
|
376
384
|
export declare function withPathLease<T>(deps: Pick<SandboxToolDeps, "sandbox">, s: Pick<SandboxSession, "deviceId">, path: string, signal: AbortSignal, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
377
385
|
/**
|
|
378
|
-
* Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
|
|
379
|
-
*
|
|
380
|
-
*
|
|
386
|
+
* Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
|
|
387
|
+
* (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
|
|
388
|
+
* provider on in the org. Without a conversation: some device provider is on in the org
|
|
389
|
+
* ({@link ConversationDevices.usableNow}).
|
|
390
|
+
*/
|
|
391
|
+
export declare function sandboxUsable(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<boolean>;
|
|
392
|
+
/**
|
|
393
|
+
* Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
|
|
394
|
+
* or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
|
|
395
|
+
* its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
|
|
396
|
+
* ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
|
|
397
|
+
* stub with only `usableNow` reads a false answer as the last.
|
|
398
|
+
*/
|
|
399
|
+
export declare function sandboxUnusableText(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<string | null>;
|
|
400
|
+
/**
|
|
401
|
+
* The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
|
|
402
|
+
* or null when it can.
|
|
381
403
|
*/
|
|
382
|
-
export declare function
|
|
404
|
+
export declare function sandboxUnusableError(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<ToolError | null>;
|
|
405
|
+
/** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
|
|
406
|
+
export declare function sandboxUnusableReason(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<DeviceUnusableReason | null>;
|
|
383
407
|
/**
|
|
384
408
|
* The reason the registry reports the sandbox tools unavailable with, or null when they can run
|
|
385
|
-
* ({@link
|
|
409
|
+
* ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
|
|
386
410
|
* lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
|
|
387
411
|
* makes every sandbox tool of a listing share one answer.
|
|
388
412
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
|
|
2
|
+
import { ANONYMOUS_NO_DEVICE, NO_DEVICE, } from "../../../devices/conversation-devices.js";
|
|
3
3
|
import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
|
|
4
4
|
import { ApiError } from "../../../errors.js";
|
|
5
5
|
import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
|
|
@@ -34,10 +34,15 @@ export const sandboxFilesResetNotice = (roots) => `The device's files were reset
|
|
|
34
34
|
/** {@link sandboxFilesResetNotice} of an instance with the default roots. */
|
|
35
35
|
export const SANDBOX_FILES_RESET_NOTICE = sandboxFilesResetNotice(DEFAULT_SANDBOX_ROOTS);
|
|
36
36
|
const BUSY_TEXT = "The device is busy: all its command slots are taken by commands of this or another conversation sharing it; wait for one to finish and retry.";
|
|
37
|
-
const NO_SANDBOX_TEXT = "No
|
|
37
|
+
const NO_SANDBOX_TEXT = "No device provider is on in this organization; ask an org admin to switch one on, or do the task without the sandbox.";
|
|
38
|
+
/**
|
|
39
|
+
* A conversation with no device while device providers are on in the org: its owner has no default
|
|
40
|
+
* device and the org has no default device provider to make one.
|
|
41
|
+
*/
|
|
42
|
+
export const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
|
|
38
43
|
/** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
|
|
39
44
|
export const SANDBOX_UNAVAILABLE_REASON = NO_SANDBOX_TEXT.slice(0, -1);
|
|
40
|
-
/** The error of a sandbox call
|
|
45
|
+
/** The error of a sandbox call with no device provider on in the org. */
|
|
41
46
|
export function noSandboxError() {
|
|
42
47
|
return new ToolError(NO_SANDBOX_TEXT);
|
|
43
48
|
}
|
|
@@ -45,7 +50,8 @@ const PATH_BUSY_TEXT = "Another sub-agent or another conversation on this device
|
|
|
45
50
|
const ANONYMOUS_TEXT = "The sandbox is not available to anonymous IM senders; do the task without the sandbox, or ask the person to link their account and start a new conversation.";
|
|
46
51
|
const ENV_NOT_FOUND_TEXT = "This conversation's device was deleted or its owner can no longer use it; ask the user to start a new conversation on another device.";
|
|
47
52
|
const ENV_FORBIDDEN_TEXT = "This conversation's owner may no longer use its device; ask the user to start a new conversation on a device they can use.";
|
|
48
|
-
|
|
53
|
+
/** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
|
|
54
|
+
export const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
|
|
49
55
|
const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page, then retry.";
|
|
50
56
|
/**
|
|
51
57
|
* A provider call that never connected (refused, unknown host, unreachable network): the request
|
|
@@ -332,7 +338,7 @@ export function admissionUnavailableText(cause) {
|
|
|
332
338
|
* sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
|
|
333
339
|
* model's doing; whether anything ran is not proven.
|
|
334
340
|
*/
|
|
335
|
-
export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in
|
|
341
|
+
export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
|
|
336
342
|
/**
|
|
337
343
|
* A device request whose machine came back as a new run of capybara-device before answering
|
|
338
344
|
* (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
|
|
@@ -433,6 +439,8 @@ export function mapSandboxError(e, log) {
|
|
|
433
439
|
const reason = e.details?.[0]?.reason;
|
|
434
440
|
if (reason === ANONYMOUS_NO_DEVICE)
|
|
435
441
|
return new ToolError(ANONYMOUS_TEXT);
|
|
442
|
+
if (reason === NO_DEVICE)
|
|
443
|
+
return new ToolError(NO_DEVICE_TEXT);
|
|
436
444
|
return new ToolError(NO_SANDBOX_TEXT);
|
|
437
445
|
}
|
|
438
446
|
const detail = e.details?.[0];
|
|
@@ -714,20 +722,54 @@ export async function withPathLease(deps, s, path, signal, fn) {
|
|
|
714
722
|
}
|
|
715
723
|
}
|
|
716
724
|
/**
|
|
717
|
-
* Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
|
|
718
|
-
*
|
|
719
|
-
*
|
|
725
|
+
* Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
|
|
726
|
+
* (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
|
|
727
|
+
* provider on in the org. Without a conversation: some device provider is on in the org
|
|
728
|
+
* ({@link ConversationDevices.usableNow}).
|
|
720
729
|
*/
|
|
721
730
|
export async function sandboxUsable(deps, orgId, conversationId) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
731
|
+
return deps.devices.usableNow ? deps.devices.usableNow(orgId, conversationId) : true;
|
|
732
|
+
}
|
|
733
|
+
/** The model-facing text of each {@link DeviceUnusableReason}. */
|
|
734
|
+
const UNUSABLE_TEXT = {
|
|
735
|
+
"provider-off": ENV_UNAVAILABLE_TEXT,
|
|
736
|
+
"no-device": NO_DEVICE_TEXT,
|
|
737
|
+
none: NO_SANDBOX_TEXT,
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
|
|
741
|
+
* or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
|
|
742
|
+
* its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
|
|
743
|
+
* ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
|
|
744
|
+
* stub with only `usableNow` reads a false answer as the last.
|
|
745
|
+
*/
|
|
746
|
+
export async function sandboxUnusableText(deps, orgId, conversationId) {
|
|
747
|
+
const reason = await sandboxUnusableReason(deps, orgId, conversationId);
|
|
748
|
+
return reason === null ? null : UNUSABLE_TEXT[reason];
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
|
|
752
|
+
* or null when it can.
|
|
753
|
+
*/
|
|
754
|
+
export async function sandboxUnusableError(deps, orgId, conversationId) {
|
|
755
|
+
const reason = await sandboxUnusableReason(deps, orgId, conversationId);
|
|
756
|
+
if (reason === null)
|
|
757
|
+
return null;
|
|
758
|
+
if (reason === "provider-off")
|
|
759
|
+
return new ToolError(ENV_UNAVAILABLE_TEXT);
|
|
760
|
+
if (reason === "no-device")
|
|
761
|
+
return new ToolError(NO_DEVICE_TEXT);
|
|
762
|
+
return noSandboxError();
|
|
763
|
+
}
|
|
764
|
+
/** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
|
|
765
|
+
export async function sandboxUnusableReason(deps, orgId, conversationId) {
|
|
766
|
+
if (deps.devices.unusableReason)
|
|
767
|
+
return deps.devices.unusableReason(orgId, conversationId);
|
|
768
|
+
return (await sandboxUsable(deps, orgId, conversationId)) ? null : "none";
|
|
727
769
|
}
|
|
728
770
|
/**
|
|
729
771
|
* The reason the registry reports the sandbox tools unavailable with, or null when they can run
|
|
730
|
-
* ({@link
|
|
772
|
+
* ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
|
|
731
773
|
* lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
|
|
732
774
|
* makes every sandbox tool of a listing share one answer.
|
|
733
775
|
*/
|
|
@@ -735,12 +777,14 @@ export const unavailableWhenNoSandbox = (deps) => async (ctx) => {
|
|
|
735
777
|
if (ctx.replay === true)
|
|
736
778
|
return null;
|
|
737
779
|
const key = "sandboxUsable";
|
|
738
|
-
let
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
ctx.memo?.set(key,
|
|
780
|
+
let text = ctx.memo?.get(key);
|
|
781
|
+
if (text === undefined) {
|
|
782
|
+
text = sandboxUnusableText(deps, ctx.orgId, ctx.conversationId);
|
|
783
|
+
ctx.memo?.set(key, text);
|
|
742
784
|
}
|
|
743
|
-
|
|
785
|
+
const t = await text;
|
|
786
|
+
// the listing's reason has no final period
|
|
787
|
+
return t === null ? null : t.slice(0, -1);
|
|
744
788
|
};
|
|
745
789
|
/** 读出的字节是否像二进制(开头 8 KB 里有 NUL)。 */
|
|
746
790
|
export function looksBinary(data) {
|
|
@@ -9,8 +9,11 @@ export declare const READ_MAX_BYTES: number;
|
|
|
9
9
|
export declare const READ_DESCRIPTION: string;
|
|
10
10
|
/** Neither or both of `file_path` and `file_id` (spec §1.1). */
|
|
11
11
|
export declare const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A `file_path` read without a usable device: why the device cannot be used
|
|
14
|
+
* ({@link sandboxUnusableText}), then the `file_id` way in.
|
|
15
|
+
*/
|
|
16
|
+
export declare const readNoDeviceText: (unusable: string) => string;
|
|
14
17
|
/** A `file_id` that is no file of this conversation or its root. */
|
|
15
18
|
export declare const unknownFileIdText: (id: string) => string;
|
|
16
19
|
/** A `file_id` read in a deployment without an object store. */
|
|
@@ -6,7 +6,7 @@ import { viewPath } from "../../view.js";
|
|
|
6
6
|
import { findConversationFile, } from "../conversation-files.js";
|
|
7
7
|
import { sizeText } from "../size-text.js";
|
|
8
8
|
import { readImageWithVisionModel } from "../vision/read-image.js";
|
|
9
|
-
import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf,
|
|
9
|
+
import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableText, unavailableWhenNoSandbox, withNotices, } from "./common.js";
|
|
10
10
|
import { normalizeSandboxPath, recordedFile } from "./file-state.js";
|
|
11
11
|
/** 不给 `limit` 时一次读的行数。 */
|
|
12
12
|
const DEFAULT_LIMIT = 2000;
|
|
@@ -68,8 +68,11 @@ const isDirectory = (path) => `${clip(path, 200)} is a directory; use Glob to li
|
|
|
68
68
|
const pastEnd = (offset, total) => `offset ${offset} is past the end of the file (${total} lines); pass an offset of at most ${total}.`;
|
|
69
69
|
/** Neither or both of `file_path` and `file_id` (spec §1.1). */
|
|
70
70
|
export const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
|
|
71
|
-
/**
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* A `file_path` read without a usable device: why the device cannot be used
|
|
73
|
+
* ({@link sandboxUnusableText}), then the `file_id` way in.
|
|
74
|
+
*/
|
|
75
|
+
export const readNoDeviceText = (unusable) => `${unusable} To read an attachment or artifact of this conversation, pass file_id instead.`;
|
|
73
76
|
/** A `file_id` that is no file of this conversation or its root. */
|
|
74
77
|
export const unknownFileIdText = (id) => `file_id ${clip(id, 100)} is not an attachment or artifact of this conversation; pass the id of one.`;
|
|
75
78
|
/** A `file_id` read in a deployment without an object store. */
|
|
@@ -154,9 +157,9 @@ export function sandboxReadTool(deps) {
|
|
|
154
157
|
return readById(deps, ctx, input, input.file_id);
|
|
155
158
|
const filePath = input.file_path;
|
|
156
159
|
checkFilePathShape(filePath);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
const unusable = await sandboxUnusableText(deps, ctx.orgId, sandboxConversationOf(ctx));
|
|
161
|
+
if (unusable !== null)
|
|
162
|
+
throw new ToolError(readNoDeviceText(unusable));
|
|
160
163
|
let path = "";
|
|
161
164
|
const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
|
|
162
165
|
const { h, p, signal } = s;
|
|
@@ -19,8 +19,8 @@ export interface TaskEnv {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The task tools' dependencies; throws the tool's error when they are missing, or when the
|
|
22
|
-
* conversation's device cannot run (
|
|
23
|
-
*
|
|
22
|
+
* conversation's device cannot run (its provider off in the org, or no provider on there: ruling
|
|
23
|
+
* R8, {@link sandboxUnusableError}).
|
|
24
24
|
*/
|
|
25
25
|
export declare function taskEnv(deps: SandboxToolDeps, ctx: BuiltinCallContext): Promise<TaskEnv>;
|
|
26
26
|
/**
|
|
@@ -8,7 +8,7 @@ import { formatElapsed, taskReasonText } from "../../../background/render.js";
|
|
|
8
8
|
import { notRunningAs, RECREATED } from "../../../background/stop.js";
|
|
9
9
|
import { isManagedTask } from "../../../background/store.js";
|
|
10
10
|
import { RetirementPendingError, retirementPending, } from "../../../sandbox/sandbox.service.js";
|
|
11
|
-
import { clip, display, mapSandboxError,
|
|
11
|
+
import { clip, display, mapSandboxError, runTimeLeftMs, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableError, unavailableWhenNoSandbox, } from "./common.js";
|
|
12
12
|
import { parseDeviceCode } from "./device-code.js";
|
|
13
13
|
import { assertDeviceOfRunAccount } from "./device-owner.js";
|
|
14
14
|
/** How long `TaskOutput` waits with `block` when `timeout` is not given (ms). */
|
|
@@ -57,12 +57,13 @@ const SPEC = {
|
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
59
59
|
* The task tools' dependencies; throws the tool's error when they are missing, or when the
|
|
60
|
-
* conversation's device cannot run (
|
|
61
|
-
*
|
|
60
|
+
* conversation's device cannot run (its provider off in the org, or no provider on there: ruling
|
|
61
|
+
* R8, {@link sandboxUnusableError}).
|
|
62
62
|
*/
|
|
63
63
|
export async function taskEnv(deps, ctx) {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const unusable = await sandboxUnusableError(deps, ctx.orgId, sandboxConversationOf(ctx));
|
|
65
|
+
if (unusable !== null)
|
|
66
|
+
throw unusable;
|
|
66
67
|
const { background, tasks } = deps;
|
|
67
68
|
if (!background || !tasks || !deps.sandbox.ifRunning) {
|
|
68
69
|
throw new ToolError("Background tasks are not available here; use Bash without run_in_background instead.");
|
|
@@ -11,7 +11,7 @@ import { resolveSkillForkType } from "../../runtime/subagents/roster.js";
|
|
|
11
11
|
import { invocationOf, resolveSkills } from "../../skills/catalog.js";
|
|
12
12
|
import { PLATFORM_SOURCE, skillFileStore } from "../../skills/usable.js";
|
|
13
13
|
import { AGENT_TOOL, SANDBOX_TOOL_NAMES } from "../builtin-names.js";
|
|
14
|
-
import { checkToolPath, clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf,
|
|
14
|
+
import { checkToolPath, clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableReason, withNotices, withPathLease, } from "./sandbox/common.js";
|
|
15
15
|
/**
|
|
16
16
|
* Builtin tool `Skill` (M5 T14, ruling M17): resolves the name against the latest skills catalog
|
|
17
17
|
* snapshot in the log to an id and version, and returns that version's SKILL.md body and file list
|
|
@@ -533,6 +533,12 @@ async function loadProjectSkill(deps, ctx, asked, bare, args) {
|
|
|
533
533
|
display: display(`加载项目技能 ${asked}`, `Loaded project skill ${asked}`),
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
|
+
/** Why a skill's files cannot reach the device, per {@link DeviceUnusableReason}. */
|
|
537
|
+
const SKILL_NO_DEVICE_CAUSE = {
|
|
538
|
+
"provider-off": "This conversation's device runs on a device provider that is off in this organization or not installed",
|
|
539
|
+
"no-device": "This conversation has no device (its owner has no default device and the organization has no default device provider)",
|
|
540
|
+
none: "No device provider is on in this organization",
|
|
541
|
+
};
|
|
536
542
|
/** 内置工具 `Skill`(见文件头)。 */
|
|
537
543
|
export function skillLoadTool(deps) {
|
|
538
544
|
return {
|
|
@@ -603,14 +609,17 @@ export function skillLoadTool(deps) {
|
|
|
603
609
|
const others = manifest.files.filter((f) => f.path !== SKILL_ENTRY_FILE);
|
|
604
610
|
let notices = [];
|
|
605
611
|
let filesText;
|
|
612
|
+
const unusable = others.length === 0
|
|
613
|
+
? null
|
|
614
|
+
: await sandboxUnusableReason(deps, ctx.orgId, sandboxConversationOf(ctx));
|
|
606
615
|
if (others.length === 0) {
|
|
607
616
|
filesText = "This skill has no files besides its instructions.";
|
|
608
617
|
}
|
|
609
|
-
else if (
|
|
618
|
+
else if (unusable !== null) {
|
|
610
619
|
filesText =
|
|
611
620
|
`Skill files (for reference):\n${fileList(manifest.files)}\n` +
|
|
612
|
-
|
|
613
|
-
"follow the instructions without running them.";
|
|
621
|
+
SKILL_NO_DEVICE_CAUSE[unusable] +
|
|
622
|
+
", so the skill's scripts and other files are not available; follow the instructions without running them.";
|
|
614
623
|
}
|
|
615
624
|
else if (!hasSandboxTools(ctx)) {
|
|
616
625
|
// 模型跑不了脚本:不为它创建沙箱、不复制
|
|
@@ -14,6 +14,7 @@ import { sql } from "kysely";
|
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
import { connectorTemplateState } from "../catalog/component-state.js";
|
|
16
16
|
import { assertItemInstallable } from "../catalog/request-rules.js";
|
|
17
|
+
import { productName } from "../config/product-name.js";
|
|
17
18
|
import { ApiError } from "../errors.js";
|
|
18
19
|
import { PluginGuides, } from "../extensions/plugin-guides.js";
|
|
19
20
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -289,7 +290,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
289
290
|
if (!meta)
|
|
290
291
|
throw fail("auth.client", "Dynamic client registration requires discovery mcp");
|
|
291
292
|
try {
|
|
292
|
-
const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, auth.tokenAuthMethod);
|
|
293
|
+
const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, productName(this.config.get()), auth.tokenAuthMethod);
|
|
293
294
|
return { client };
|
|
294
295
|
}
|
|
295
296
|
catch (e) {
|
|
@@ -83,5 +83,7 @@ export declare function pickAuthMethod(supported: string[] | undefined, hasSecre
|
|
|
83
83
|
* client)。注册失败只报 HTTP 状态,不带对方正文。
|
|
84
84
|
*/
|
|
85
85
|
export declare function registerClient(meta: McpAuthMetadata, redirectUri: string, http: OAuthHttpOptions,
|
|
86
|
+
/** The client name the authorization server shows on its consent screen (`platform.name`). */
|
|
87
|
+
clientName: string,
|
|
86
88
|
/** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
|
|
87
89
|
preferred?: TokenAuthMethod): Promise<OAuthClientRecord>;
|
|
@@ -273,6 +273,8 @@ export function pickAuthMethod(supported, hasSecret) {
|
|
|
273
273
|
* client)。注册失败只报 HTTP 状态,不带对方正文。
|
|
274
274
|
*/
|
|
275
275
|
export async function registerClient(meta, redirectUri, http,
|
|
276
|
+
/** The client name the authorization server shows on its consent screen (`platform.name`). */
|
|
277
|
+
clientName,
|
|
276
278
|
/** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
|
|
277
279
|
preferred) {
|
|
278
280
|
if (!meta.registrationEndpoint) {
|
|
@@ -286,7 +288,7 @@ preferred) {
|
|
|
286
288
|
method: "POST",
|
|
287
289
|
headers: { "content-type": "application/json", accept: "application/json" },
|
|
288
290
|
body: JSON.stringify({
|
|
289
|
-
client_name:
|
|
291
|
+
client_name: clientName,
|
|
290
292
|
redirect_uris: [redirectUri],
|
|
291
293
|
grant_types: ["authorization_code", "refresh_token"],
|
|
292
294
|
response_types: ["code"],
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `p`, or a rejection with `signal.reason` once `signal` aborts, whatever `p` does: an extension
|
|
3
|
+
* call that ignores its signal never holds the caller past it (a late settle of `p` is dropped).
|
|
4
|
+
*/
|
|
5
|
+
export declare function untilAborted<T>(p: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `p`, or a rejection with `signal.reason` once `signal` aborts, whatever `p` does: an extension
|
|
3
|
+
* call that ignores its signal never holds the caller past it (a late settle of `p` is dropped).
|
|
4
|
+
*/
|
|
5
|
+
export function untilAborted(p, signal) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const onAbort = () => reject(signal.reason);
|
|
8
|
+
if (signal.aborted) {
|
|
9
|
+
p.catch(() => { });
|
|
10
|
+
onAbort();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
14
|
+
p.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
15
|
+
});
|
|
16
|
+
}
|
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.67",
|
|
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.51"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,8 +75,8 @@
|
|
|
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.
|
|
79
|
-
"@capybara-hq/device": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.33",
|
|
79
|
+
"@capybara-hq/device": "0.1.0-rc.27"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "tsc -b"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Device providers (spec 2026-11-21-device-provider-design): what a device's provider last told
|
|
2
|
+
-- about it (`device-provider@1` `report()`, a DeviceReport as JSON) and when. Shown to people
|
|
3
|
+
-- only, never used for enforcement; request paths read this copy and never call the provider.
|
|
4
|
+
-- Expand-only, no backfill: null until the device's next create or resume refreshes it.
|
|
5
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS report jsonb;
|
|
6
|
+
ALTER TABLE devices ADD COLUMN IF NOT EXISTS report_at timestamptz;
|