@capybara-hq/kernel 0.1.0-rc.75 → 0.1.0-rc.76
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/agents/readiness.controller.d.ts +4 -3
- package/dist/agents/readiness.controller.js +4 -3
- package/dist/agents/readiness.service.d.ts +44 -11
- package/dist/agents/readiness.service.js +59 -16
- package/dist/catalog/catalog-import.module.d.ts +1 -1
- package/dist/catalog/catalog-import.module.js +1 -1
- package/dist/catalog/cli.d.ts +9 -2
- package/dist/catalog/cli.js +10 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.d.ts +4 -2
- package/dist/catalog/plugin-upgrade.js +9 -3
- package/dist/db/kernel-schema.d.ts +5 -0
- package/dist/devices/device-projects.service.d.ts +3 -12
- package/dist/devices/device-projects.service.js +16 -59
- package/dist/extensions/bootstrap.d.ts +17 -3
- package/dist/extensions/bootstrap.js +56 -14
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +16 -11
- package/dist/overrides.d.ts +0 -5
- package/dist/overrides.js +0 -2
- package/dist/platform/file-ref.d.ts +6 -5
- package/dist/platform/ops/agent-skills.ops.js +1 -1
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/runtime/model-call.d.ts +2 -2
- package/dist/runtime/project/knowledge.d.ts +1 -1
- package/dist/runtime/project/knowledge.js +1 -1
- package/dist/runtime/project/knowledge.service.d.ts +5 -11
- package/dist/runtime/project/knowledge.service.js +12 -23
- package/dist/runtime/providers.d.ts +34 -1
- package/dist/runtime/providers.js +56 -7
- package/dist/runtime/run-steps.d.ts +4 -6
- package/dist/runtime/run-steps.js +7 -15
- package/dist/runtime/runtime.module.js +1 -1
- package/dist/sandbox/held-operations.d.ts +2 -5
- package/dist/sandbox/held-operations.js +0 -14
- package/dist/sandbox/managed-device-context.d.ts +1 -1
- package/dist/sandbox/managed-device-context.js +1 -1
- package/dist/sandbox/permission-context-types.d.ts +0 -11
- package/dist/sandbox/permission-context-types.js +0 -13
- package/dist/sandbox/providers.d.ts +5 -0
- package/dist/sandbox/providers.js +1 -1
- package/dist/sandbox/sandbox-file-reader.d.ts +7 -12
- package/dist/sandbox/sandbox-file-reader.js +12 -29
- package/dist/sandbox/sandbox.service.d.ts +53 -32
- package/dist/sandbox/sandbox.service.js +217 -141
- package/dist/sandbox/use-context.d.ts +4 -1
- package/dist/skills/invoke.d.ts +13 -35
- package/dist/skills/invoke.js +23 -162
- package/dist/tools/builtins/builtin-tools.d.ts +2 -11
- package/dist/tools/builtins/builtin-tools.js +5 -23
- package/dist/tools/builtins/image/generate.js +2 -2
- package/dist/tools/builtins/sandbox/common.d.ts +32 -80
- package/dist/tools/builtins/sandbox/common.js +61 -173
- package/dist/tools/builtins/sandbox/deliver.js +2 -2
- package/dist/tools/builtins/sandbox/device-owner.d.ts +4 -5
- package/dist/tools/builtins/sandbox/device-owner.js +5 -6
- package/dist/tools/builtins/sandbox/fetch-attachment.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +1 -1
- package/dist/tools/builtins/sandbox/grep.js +1 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -2
- package/dist/tools/builtins/sandbox/index.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +1 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -3
- package/dist/tools/builtins/sandbox/task-output.js +4 -4
- package/dist/tools/builtins/sandbox/task-stop.js +1 -1
- package/dist/tools/builtins/skill-load.js +2 -2
- package/dist/tools/connectors.service.d.ts +4 -2
- package/dist/tools/connectors.service.js +15 -3
- package/dist/tools/pipeline.d.ts +0 -2
- package/dist/tools/pipeline.js +7 -14
- package/dist/tools/tools.module.js +1 -1
- package/package.json +2 -2
- package/src/migrations/0179_device_report_limit_text.sql +28 -0
- package/src/migrations/0180_device_instance_abandoned.sql +6 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type PluginImport } from "../catalog/plugin-import.js";
|
|
2
|
+
import type { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
2
3
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
3
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
5
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -148,6 +149,11 @@ export declare const BOOTSTRAP_LOCK_TTL_MS = 120000;
|
|
|
148
149
|
export declare const BOOTSTRAP_LOCK_TTL: unique symbol;
|
|
149
150
|
/** What a run imports a declarative entry or an entry's catalog version with. */
|
|
150
151
|
export type BootstrapImports = Pick<PluginImport, "prepare" | "prepareGit" | "confirm">;
|
|
152
|
+
/**
|
|
153
|
+
* What a run moves the platform to a raised pin of a plugin without an extension with (the
|
|
154
|
+
* platform plugin update, acting as the kernel).
|
|
155
|
+
*/
|
|
156
|
+
export type BootstrapUpdater = Pick<PlatformPluginUpdater, "preview" | "update">;
|
|
151
157
|
export declare class BootstrapService {
|
|
152
158
|
private readonly kdb;
|
|
153
159
|
readonly txHost: TransactionHost;
|
|
@@ -221,6 +227,8 @@ export declare class BootstrapService {
|
|
|
221
227
|
packages?: ReadonlyMap<string, Uint8Array>;
|
|
222
228
|
/** The plugin import a declarative entry (or an entry's catalog version) goes through. */
|
|
223
229
|
imports: BootstrapImports;
|
|
230
|
+
/** The platform update a raised pin of a declarative entry goes through. */
|
|
231
|
+
updater: BootstrapUpdater;
|
|
224
232
|
}): Promise<BootstrapResult>;
|
|
225
233
|
/**
|
|
226
234
|
* A pin whose plugin name an org holds (a live org-owned catalog item): the bootstrap takes no
|
|
@@ -247,8 +255,11 @@ export declare class BootstrapService {
|
|
|
247
255
|
/** The entry names the last completed run handled (undefined before any run completed). */
|
|
248
256
|
private lastRunNames;
|
|
249
257
|
private entry;
|
|
250
|
-
/**
|
|
251
|
-
|
|
258
|
+
/**
|
|
259
|
+
* The live (not deleted) platform catalog item of this name: its platform version (the one orgs
|
|
260
|
+
* install, else its latest) and where that version came from. undefined: no such item.
|
|
261
|
+
*/
|
|
262
|
+
private platformVersion;
|
|
252
263
|
/**
|
|
253
264
|
* The catalog item of a bootstrap entry follows `required` / `builtin`: such an entry is builtin,
|
|
254
265
|
* offered to every org (scope `all`, which an org admin cannot switch off) and not disabled
|
|
@@ -272,7 +283,10 @@ export declare class BootstrapService {
|
|
|
272
283
|
private gitPlugin;
|
|
273
284
|
/** Stages a git entry from its files as an admin git import would (translation included). */
|
|
274
285
|
private prepareGitEntry;
|
|
275
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* A declarative plugin: catalog only. Returns false when that version is already imported.
|
|
288
|
+
* `updateFollows`: a platform update to this version follows (it owes the scope sync).
|
|
289
|
+
*/
|
|
276
290
|
private importOnly;
|
|
277
291
|
/**
|
|
278
292
|
* Imports, approves, installs and enables (one review; its confirm deploys the extension). When
|
|
@@ -244,7 +244,7 @@ let BootstrapService = class BootstrapService {
|
|
|
244
244
|
const fetchErr = fetchFailed.get(e.name);
|
|
245
245
|
if (fetchErr !== undefined)
|
|
246
246
|
throw fetchErr;
|
|
247
|
-
const r = await this.entry(e, files.get(e.name), handled, o
|
|
247
|
+
const r = await this.entry(e, files.get(e.name), handled, o, {
|
|
248
248
|
manifest: o.manifest,
|
|
249
249
|
tree: gitTrees.get(e.name),
|
|
250
250
|
});
|
|
@@ -370,7 +370,7 @@ let BootstrapService = class BootstrapService {
|
|
|
370
370
|
return undefined;
|
|
371
371
|
return new Set(results.filter((r) => r.action !== "required_cleared").map((r) => r.name));
|
|
372
372
|
}
|
|
373
|
-
async entry(e, bytes, handled, imports,
|
|
373
|
+
async entry(e, bytes, handled, { imports, updater },
|
|
374
374
|
/** For a git entry: the manifest (its marketplaces) and the tree oid when read from git now. */
|
|
375
375
|
at) {
|
|
376
376
|
let plugin;
|
|
@@ -432,9 +432,31 @@ let BootstrapService = class BootstrapService {
|
|
|
432
432
|
const builtin = e.required || e.builtin === true;
|
|
433
433
|
if (!plugin.extension) {
|
|
434
434
|
await this.markBuiltin(e.name, builtin);
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
const live = await this.platformVersion(e.name);
|
|
436
|
+
if (live !== undefined) {
|
|
437
|
+
// As the extension path does: a version the bootstrap put there is raised to the pin; one
|
|
438
|
+
// the super admin moved to (another source, or a higher version) stays
|
|
439
|
+
if (live.source !== "bootstrap" || !isLower(live.version, e.version)) {
|
|
440
|
+
return { name: e.name, action: "kept", version: live.version };
|
|
441
|
+
}
|
|
442
|
+
if (live.disabled) {
|
|
443
|
+
// The update refuses a disabled item: the version waits in the catalog, and the super
|
|
444
|
+
// admin applies it once they enable the plugin
|
|
445
|
+
await this.importOnly(e, bytes, source, imports, git);
|
|
446
|
+
this.log.info("bootstrap: the plugin is disabled on the deployment; the pinned version is imported, not applied", { plugin: e.name, version: e.version, current: live.version });
|
|
447
|
+
return { name: e.name, action: "kept", version: live.version };
|
|
448
|
+
}
|
|
449
|
+
await this.importOnly(e, bytes, source, imports, git, true);
|
|
450
|
+
const preview = await updater.preview(live.itemId, e.version);
|
|
451
|
+
await updater.update(null, live.itemId, {
|
|
452
|
+
version: e.version,
|
|
453
|
+
diffHash: preview.diffHash,
|
|
454
|
+
});
|
|
455
|
+
return { name: e.name, action: "upgraded", version: e.version };
|
|
437
456
|
}
|
|
457
|
+
// A builtin entry a super admin removed is put back; an optional one stays out (Ruling 5)
|
|
458
|
+
if (!isNew && !builtin)
|
|
459
|
+
return { name: e.name, action: "kept", version: e.version };
|
|
438
460
|
const imported = await this.importOnly(e, bytes, source, imports, git);
|
|
439
461
|
await this.markBuiltin(e.name, builtin);
|
|
440
462
|
return { name: e.name, action: imported ? "imported" : "kept", version: e.version };
|
|
@@ -489,16 +511,32 @@ let BootstrapService = class BootstrapService {
|
|
|
489
511
|
await this.markBuiltin(e.name, builtin);
|
|
490
512
|
return leftDisabled === undefined ? result : { ...result, leftDisabled };
|
|
491
513
|
}
|
|
492
|
-
/**
|
|
493
|
-
|
|
514
|
+
/**
|
|
515
|
+
* The live (not deleted) platform catalog item of this name: its platform version (the one orgs
|
|
516
|
+
* install, else its latest) and where that version came from. undefined: no such item.
|
|
517
|
+
*/
|
|
518
|
+
async platformVersion(name) {
|
|
494
519
|
const row = await this.db
|
|
495
|
-
.selectFrom("catalog_items")
|
|
496
|
-
.
|
|
497
|
-
.
|
|
498
|
-
.
|
|
499
|
-
.
|
|
520
|
+
.selectFrom("catalog_items as i")
|
|
521
|
+
.leftJoin("catalog_item_versions as v", (j) => j
|
|
522
|
+
.onRef("v.item_id", "=", "i.id")
|
|
523
|
+
.on("v.version", "=", sql `coalesce(i.platform_synced_version, i.latest_version)`))
|
|
524
|
+
.select([
|
|
525
|
+
"i.id",
|
|
526
|
+
sql `coalesce(i.platform_synced_version, i.latest_version)`.as("version"),
|
|
527
|
+
"v.source",
|
|
528
|
+
"i.disabled",
|
|
529
|
+
])
|
|
530
|
+
.where("i.name", "=", name)
|
|
531
|
+
.where("i.owner_org_id", "is", null)
|
|
532
|
+
.where("i.deleted_at", "is", null)
|
|
500
533
|
.executeTakeFirst();
|
|
501
|
-
return row
|
|
534
|
+
return (row && {
|
|
535
|
+
itemId: row.id,
|
|
536
|
+
version: row.version,
|
|
537
|
+
source: row.source ?? null,
|
|
538
|
+
disabled: row.disabled,
|
|
539
|
+
});
|
|
502
540
|
}
|
|
503
541
|
/**
|
|
504
542
|
* The catalog item of a bootstrap entry follows `required` / `builtin`: such an entry is builtin,
|
|
@@ -585,8 +623,11 @@ let BootstrapService = class BootstrapService {
|
|
|
585
623
|
}
|
|
586
624
|
return staged;
|
|
587
625
|
}
|
|
588
|
-
/**
|
|
589
|
-
|
|
626
|
+
/**
|
|
627
|
+
* A declarative plugin: catalog only. Returns false when that version is already imported.
|
|
628
|
+
* `updateFollows`: a platform update to this version follows (it owes the scope sync).
|
|
629
|
+
*/
|
|
630
|
+
async importOnly(e, bytes, source, imports, git, updateFollows = false) {
|
|
590
631
|
try {
|
|
591
632
|
const { stagingId, review } = git !== undefined
|
|
592
633
|
? await this.prepareGitEntry(e, git, source, imports)
|
|
@@ -594,6 +635,7 @@ let BootstrapService = class BootstrapService {
|
|
|
594
635
|
await imports.confirm(null, stagingId, {
|
|
595
636
|
reviewHash: review.reviewHash,
|
|
596
637
|
scope: e.scope ?? "optional",
|
|
638
|
+
...(updateFollows && { updateFollows: true }),
|
|
597
639
|
});
|
|
598
640
|
return true;
|
|
599
641
|
}
|
|
@@ -5,6 +5,7 @@ import { type Kysely } from "kysely";
|
|
|
5
5
|
import type { KernelAppOptions } from "../app.js";
|
|
6
6
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
7
7
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
8
|
+
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
8
9
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
9
10
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
10
11
|
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
@@ -84,6 +85,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
84
85
|
private readonly bootstrapDefaults;
|
|
85
86
|
private readonly marketplaces;
|
|
86
87
|
private readonly pluginImport;
|
|
88
|
+
private readonly pluginUpdater;
|
|
87
89
|
private readonly bus;
|
|
88
90
|
private readonly usageReport;
|
|
89
91
|
private readonly titles;
|
|
@@ -109,7 +111,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
109
111
|
private bootstrapPackages;
|
|
110
112
|
/** The merged bootstrap manifest, read once per start. */
|
|
111
113
|
private mergedManifest;
|
|
112
|
-
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
114
|
+
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
113
115
|
/** The kernel HTTP application (set up by `buildKernelApp` before `init()`). */
|
|
114
116
|
get http(): KernelHttpApp;
|
|
115
117
|
attachHttp(http: KernelHttpApp): void;
|
|
@@ -12,6 +12,7 @@ import { Inject, Injectable, Optional, } from "@nestjs/common";
|
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
14
14
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
15
|
+
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
15
16
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
16
17
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
17
18
|
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
@@ -105,6 +106,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
105
106
|
bootstrapDefaults;
|
|
106
107
|
marketplaces;
|
|
107
108
|
pluginImport;
|
|
109
|
+
pluginUpdater;
|
|
108
110
|
bus;
|
|
109
111
|
usageReport;
|
|
110
112
|
titles;
|
|
@@ -132,7 +134,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
132
134
|
mergedManifest;
|
|
133
135
|
constructor(permissionConfig, accounts, configService, log, options,
|
|
134
136
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
135
|
-
pool, redis, kdb, shutdown, host, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, bus,
|
|
137
|
+
pool, redis, kdb, shutdown, host, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, bus,
|
|
136
138
|
// the producers closed on every role (their consumers are the worker role's)
|
|
137
139
|
usageReport, titles, suggestions, channelJobs, channelOutbound,
|
|
138
140
|
// this process's presence beat, on every role (admin overview spec §5.1)
|
|
@@ -159,6 +161,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
159
161
|
this.bootstrapDefaults = bootstrapDefaults;
|
|
160
162
|
this.marketplaces = marketplaces;
|
|
161
163
|
this.pluginImport = pluginImport;
|
|
164
|
+
this.pluginUpdater = pluginUpdater;
|
|
162
165
|
this.bus = bus;
|
|
163
166
|
this.usageReport = usageReport;
|
|
164
167
|
this.titles = titles;
|
|
@@ -387,6 +390,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
387
390
|
await bootstrap.run({
|
|
388
391
|
manifest,
|
|
389
392
|
imports: this.pluginImport,
|
|
393
|
+
updater: this.pluginUpdater,
|
|
390
394
|
...(dir !== undefined && { dir }),
|
|
391
395
|
signal: this.shutdown.signal,
|
|
392
396
|
...(this.bootstrapCarry !== undefined && { carry: this.bootstrapCarry }),
|
|
@@ -557,16 +561,17 @@ KernelLifecycle = __decorate([
|
|
|
557
561
|
__param(16, Inject(BootstrapDefaultsService)),
|
|
558
562
|
__param(17, Inject(MarketplacesService)),
|
|
559
563
|
__param(18, Inject(PluginImport)),
|
|
560
|
-
__param(19, Inject(
|
|
561
|
-
__param(20, Inject(
|
|
562
|
-
__param(21, Inject(
|
|
563
|
-
__param(22, Inject(
|
|
564
|
-
__param(23, Inject(
|
|
565
|
-
__param(24, Inject(
|
|
566
|
-
__param(25, Inject(
|
|
567
|
-
__param(26,
|
|
568
|
-
__param(26, Inject(WorkerRole)),
|
|
564
|
+
__param(19, Inject(PlatformPluginUpdater)),
|
|
565
|
+
__param(20, Inject(KERNEL_BUS)),
|
|
566
|
+
__param(21, Inject(UsageReporter)),
|
|
567
|
+
__param(22, Inject(TitleQueue)),
|
|
568
|
+
__param(23, Inject(PromptSuggestionQueue)),
|
|
569
|
+
__param(24, Inject(ChannelJobs)),
|
|
570
|
+
__param(25, Inject(ChannelOutbound)),
|
|
571
|
+
__param(26, Inject(ReplicaPresence)),
|
|
569
572
|
__param(27, Optional()),
|
|
570
|
-
__param(27, Inject(
|
|
573
|
+
__param(27, Inject(WorkerRole)),
|
|
574
|
+
__param(28, Optional()),
|
|
575
|
+
__param(28, Inject(GatewayRole))
|
|
571
576
|
], KernelLifecycle);
|
|
572
577
|
export { KernelLifecycle };
|
package/dist/overrides.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ import { RUN_HOOKS, type RunHooks } from "./runtime/run-worker.js";
|
|
|
28
28
|
import { SUBAGENT_MESSAGES_HOOKS, type SubagentMessagesHooks } from "./runtime/subagents/messages.js";
|
|
29
29
|
import { SANDBOX_LEASE_TIMINGS, type SandboxLeaseTimings } from "./sandbox/leases.js";
|
|
30
30
|
import { PERMISSION_AUTO_GRANT_HOOKS, type PermissionAutoGrantHooks } from "./sandbox/permission-auto-grants.js";
|
|
31
|
-
import { PERMISSION_CONTEXT_ACTIVATION } from "./sandbox/permission-context-types.js";
|
|
32
31
|
import { SETUP_CHECK_TIMEOUT } from "./setup/setup-checks.service.js";
|
|
33
32
|
import { TOOL_PIPELINE_HOOKS, type ToolPipelineHooks } from "./tools/pipeline.js";
|
|
34
33
|
import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
@@ -68,9 +67,6 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
|
68
67
|
* - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
|
|
69
68
|
* served by a loopback fake);
|
|
70
69
|
* - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
|
|
71
|
-
* - `PERMISSION_CONTEXT_ACTIVATION`: the recorded permission context producers (the request
|
|
72
|
-
* boundary and the managed device context writer); production leaves them on, and a test may
|
|
73
|
-
* turn them off to exercise the dormant state;
|
|
74
70
|
* - `PERMISSION_AUTO_GRANT_HOOKS`: a barrier after a Full access auto-grant's precheck (two
|
|
75
71
|
* replicas racing the same crossing).
|
|
76
72
|
*/
|
|
@@ -104,7 +100,6 @@ interface KernelSeams {
|
|
|
104
100
|
[PLUGIN_PUBLIC_WRITE_LIMIT]: number;
|
|
105
101
|
[EXTENSION_NET_SEAMS]: ExtensionNetSeams;
|
|
106
102
|
[APP_INTERCEPTOR]: NestInterceptor;
|
|
107
|
-
[PERMISSION_CONTEXT_ACTIVATION]: boolean;
|
|
108
103
|
[PERMISSION_AUTO_GRANT_HOOKS]: PermissionAutoGrantHooks;
|
|
109
104
|
}
|
|
110
105
|
/**
|
package/dist/overrides.js
CHANGED
|
@@ -25,7 +25,6 @@ import { RUN_HOOKS } from "./runtime/run-worker.js";
|
|
|
25
25
|
import { SUBAGENT_MESSAGES_HOOKS, } from "./runtime/subagents/messages.js";
|
|
26
26
|
import { SANDBOX_LEASE_TIMINGS } from "./sandbox/leases.js";
|
|
27
27
|
import { PERMISSION_AUTO_GRANT_HOOKS, } from "./sandbox/permission-auto-grants.js";
|
|
28
|
-
import { PERMISSION_CONTEXT_ACTIVATION } from "./sandbox/permission-context-types.js";
|
|
29
28
|
import { SETUP_CHECK_TIMEOUT } from "./setup/setup-checks.service.js";
|
|
30
29
|
import { TOOL_PIPELINE_HOOKS } from "./tools/pipeline.js";
|
|
31
30
|
import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
@@ -59,7 +58,6 @@ const SEAM_TOKENS = [
|
|
|
59
58
|
PLUGIN_PUBLIC_WRITE_LIMIT,
|
|
60
59
|
EXTENSION_NET_SEAMS,
|
|
61
60
|
APP_INTERCEPTOR,
|
|
62
|
-
PERMISSION_CONTEXT_ACTIVATION,
|
|
63
61
|
PERMISSION_AUTO_GRANT_HOOKS,
|
|
64
62
|
];
|
|
65
63
|
const allSeamsListed = true;
|
|
@@ -5,11 +5,12 @@ import { StorageService } from "../storage/storage.service.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* File references (platform web parity spec §5): a `Platform` write the web does with an upload
|
|
7
7
|
* takes a file the agent already has instead, a conversation file (`fileId`: an attachment, a
|
|
8
|
-
* generated or delivered artifact, a `read` copy). A file on the conversation's device is
|
|
9
|
-
* first (`Deliver`: the device rules, the command review and the
|
|
10
|
-
* by the delivered file's id, so device files have one reading path. The tool
|
|
11
|
-
* policy step (limits, sha256, a thumbnail for an image: the card's
|
|
12
|
-
* before the run, which refuses bytes that differ from the ones the
|
|
8
|
+
* generated or delivered artifact, a `read` copy). A file on the conversation's device is
|
|
9
|
+
* delivered first (`Deliver`: the device rules, the command review and the permission profile
|
|
10
|
+
* apply) and passed by the delivered file's id, so device files have one reading path. The tool
|
|
11
|
+
* resolves it at the policy step (limits, sha256, a thumbnail for an image: the card's
|
|
12
|
+
* `detail.file`) and again right before the run, which refuses bytes that differ from the ones the
|
|
13
|
+
* person confirmed.
|
|
13
14
|
*/
|
|
14
15
|
export type FileRef = {
|
|
15
16
|
fileId: string;
|
|
@@ -475,7 +475,7 @@ let AgentSkillsOperations = class AgentSkillsOperations {
|
|
|
475
475
|
path: input.filePath,
|
|
476
476
|
maxBytes: SKILL_PACKAGE_MAX_BYTES,
|
|
477
477
|
signal: ctx.signal,
|
|
478
|
-
// the read is this call's managed operation
|
|
478
|
+
// the read is this call's managed operation
|
|
479
479
|
...(ctx.callId !== undefined && { callId: ctx.callId }),
|
|
480
480
|
});
|
|
481
481
|
const o = await this.agentSkills.register({
|
|
@@ -779,7 +779,7 @@ let AgentsOperations = class AgentsOperations {
|
|
|
779
779
|
}),
|
|
780
780
|
defineOperation({
|
|
781
781
|
id: "agents.readiness",
|
|
782
|
-
description: "Whether the org can run agents: modelProvider is ready when a model provider
|
|
782
|
+
description: "Whether the org can run agents: modelProvider is ready when the org has a chat model an agent can pick (the list agents.create chooses from); no_models when model providers are on but none gives one (unusableProviders names each provider and its reason: list_failed with errorKind, e.g. auth for a rejected key, or no_chat_models; orgCanFix says whether an org admin can fix it on Settings > Models, else only the super admin can on the admin Models page); org_fixable when no provider is on but an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config); none when only the super admin can help; and how many agents you can see.",
|
|
783
783
|
input: z.object({}).strict(),
|
|
784
784
|
example: {},
|
|
785
785
|
authz: { orgAction: "org.read" },
|
|
@@ -96,8 +96,8 @@ export interface ModelStepDeps {
|
|
|
96
96
|
* before each agent-history request construction, record (live) or feed (full-run replay) the
|
|
97
97
|
* permission context, then rebuild from the complete log. Called at every request construction
|
|
98
98
|
* of the attempt ladder (a retry, a fallback, the rebuild after a forced compaction, wrap-up);
|
|
99
|
-
* absent, no call and no reread (old requests build byte for byte). Live runs get the
|
|
100
|
-
*
|
|
99
|
+
* absent, no call and no reread (old requests build byte for byte). Live runs always get the
|
|
100
|
+
* recorder (`RunSteps`); full-run replays strip any live one and
|
|
101
101
|
* install only the recorded feeder (`evals/recorded-permission-context.ts`).
|
|
102
102
|
*/
|
|
103
103
|
permissionContext?: PermissionContextPort;
|
|
@@ -88,7 +88,7 @@ export declare const projectUnavailable: {
|
|
|
88
88
|
reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
|
|
89
89
|
message: string;
|
|
90
90
|
};
|
|
91
|
-
/** A host machine whose runtime cannot enforce the kernel's read-only read
|
|
91
|
+
/** A host machine whose runtime cannot enforce the kernel's read-only read. */
|
|
92
92
|
readonly notEnforceable: (root: string) => {
|
|
93
93
|
reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
|
|
94
94
|
message: string;
|
|
@@ -41,7 +41,7 @@ export const projectUnavailable = {
|
|
|
41
41
|
/** The device's own error text is logged, never recorded: the message stays the same per root. */
|
|
42
42
|
unreadable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} could not be read.`),
|
|
43
43
|
removed: (project) => unavailable("removed", `The project "${clipped(project, 80)}" was removed from the device's projects.`),
|
|
44
|
-
/** A host machine whose runtime cannot enforce the kernel's read-only read
|
|
44
|
+
/** A host machine whose runtime cannot enforce the kernel's read-only read. */
|
|
45
45
|
notEnforceable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime cannot enforce a read-only read on its host; turn on its sandbox enforcement or use another device.`),
|
|
46
46
|
/** A device runtime that refused the kernel's read-only read scope (its text is logged). */
|
|
47
47
|
refused: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime refused the kernel's read-only read.`),
|
|
@@ -42,9 +42,8 @@ export interface ProjectKnowledgeInput {
|
|
|
42
42
|
* latest snapshot differs from the child's latest; the renderer then shows it to the child as is.
|
|
43
43
|
*
|
|
44
44
|
* Reads in the device's effective mode (`DeviceProjectsService.scopeFor`, the same scope the
|
|
45
|
-
* binding was checked against) and through `SandboxService.
|
|
46
|
-
*
|
|
47
|
-
* activation gate is on the read goes through `SandboxService.withKernelRead` instead: every
|
|
45
|
+
* binding was checked against) and through `SandboxService.withKernelRead`, so a bound
|
|
46
|
+
* conversation starts its device eagerly (the accepted cost, spec §4.4): every
|
|
48
47
|
* stat / readFile / list a kernel read under the run's current execution claim while the run is
|
|
49
48
|
* still queued, acting for the run's trigger, its scope narrowed to the root, `AGENTS.md` and
|
|
50
49
|
* `.agents/skills` (permission activation L2). A project the
|
|
@@ -64,11 +63,7 @@ export declare class ProjectKnowledgeService {
|
|
|
64
63
|
private readonly sandbox;
|
|
65
64
|
private readonly log;
|
|
66
65
|
private readonly timeoutMs;
|
|
67
|
-
|
|
68
|
-
private readonly activation?;
|
|
69
|
-
constructor(db: KernelDb, eventLog: Pick<EventLog, "appendIn" | "notify">, txHost: TransactionHost, devices: Pick<ConversationDevices, "forTool">, projects: Pick<DeviceProjectsService, "scopeFor" | "keeps">, sandbox: Pick<SandboxService, "withSandbox" | "withKernelRead">, log: KernelLogger, timeoutMs?: () => number,
|
|
70
|
-
/** The paired activation gate: once on, the read is a set of kernel reads. */
|
|
71
|
-
activation?: boolean | undefined);
|
|
66
|
+
constructor(db: KernelDb, eventLog: Pick<EventLog, "appendIn" | "notify">, txHost: TransactionHost, devices: Pick<ConversationDevices, "forTool">, projects: Pick<DeviceProjectsService, "scopeFor" | "keeps">, sandbox: Pick<SandboxService, "withKernelRead">, log: KernelLogger, timeoutMs?: () => number);
|
|
72
67
|
/**
|
|
73
68
|
* Reads and records (see the class); notifies after the commit. False: the run had ended under
|
|
74
69
|
* the locks (a stop landed while the device was read), so nothing was appended and the run must
|
|
@@ -84,9 +79,8 @@ export declare class ProjectKnowledgeService {
|
|
|
84
79
|
/** The snapshot read on the device, or null when the device could not be asked (logged). */
|
|
85
80
|
private read;
|
|
86
81
|
/**
|
|
87
|
-
* How the read enters the device
|
|
88
|
-
*
|
|
89
|
-
* start runs inside it; another run's claim or none admits nothing), acting for the run's
|
|
82
|
+
* How the read enters the device: `withKernelRead` under the run's current execution claim (the
|
|
83
|
+
* run start runs inside it; another run's claim or none admits nothing), acting for the run's
|
|
90
84
|
* trigger, reading the bound root only.
|
|
91
85
|
*/
|
|
92
86
|
private entry;
|
|
@@ -21,9 +21,8 @@ import { Transactional } from "../../infra/database/transactional.decorator.js";
|
|
|
21
21
|
import { KERNEL_LOGGER } from "../../infra/tokens.js";
|
|
22
22
|
import { KernelReadNotAdmitted, KernelReadUnsupported } from "../../sandbox/kernel-read.js";
|
|
23
23
|
import { SandboxLockLostError, SandboxPathBusyError } from "../../sandbox/leases.js";
|
|
24
|
-
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../../sandbox/permission-context-types.js";
|
|
25
24
|
import { homeOf } from "../../sandbox/review/rules.js";
|
|
26
|
-
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
25
|
+
import { SandboxService, } from "../../sandbox/sandbox.service.js";
|
|
27
26
|
import { providerConnectionFailure } from "../../sandbox/unreachable.js";
|
|
28
27
|
import { currentExecutionClaim } from "../run-execution.js";
|
|
29
28
|
import { runEndedIn } from "../run-status.js";
|
|
@@ -48,8 +47,8 @@ class KnowledgeClaimMissing extends Error {
|
|
|
48
47
|
/**
|
|
49
48
|
* An error that says the device could not be asked, not that the project is unreadable: the
|
|
50
49
|
* provider unreachable, a kernel refusal (the device offline, gone or busy, a relay given up), a
|
|
51
|
-
* malformed device answer, a lost lease, a kernel read that was not admitted (
|
|
52
|
-
*
|
|
50
|
+
* malformed device answer, a lost lease, a kernel read that was not admitted (nothing was sent
|
|
51
|
+
* to the device).
|
|
53
52
|
*/
|
|
54
53
|
function isDeviceFailure(e) {
|
|
55
54
|
return (providerConnectionFailure(e) !== undefined ||
|
|
@@ -72,9 +71,8 @@ function isDeviceFailure(e) {
|
|
|
72
71
|
* latest snapshot differs from the child's latest; the renderer then shows it to the child as is.
|
|
73
72
|
*
|
|
74
73
|
* Reads in the device's effective mode (`DeviceProjectsService.scopeFor`, the same scope the
|
|
75
|
-
* binding was checked against) and through `SandboxService.
|
|
76
|
-
*
|
|
77
|
-
* activation gate is on the read goes through `SandboxService.withKernelRead` instead: every
|
|
74
|
+
* binding was checked against) and through `SandboxService.withKernelRead`, so a bound
|
|
75
|
+
* conversation starts its device eagerly (the accepted cost, spec §4.4): every
|
|
78
76
|
* stat / readFile / list a kernel read under the run's current execution claim while the run is
|
|
79
77
|
* still queued, acting for the run's trigger, its scope narrowed to the root, `AGENTS.md` and
|
|
80
78
|
* `.agents/skills` (permission activation L2). A project the
|
|
@@ -94,10 +92,7 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
94
92
|
sandbox;
|
|
95
93
|
log;
|
|
96
94
|
timeoutMs;
|
|
97
|
-
|
|
98
|
-
constructor(db, eventLog, txHost, devices, projects, sandbox, log, timeoutMs = () => PROJECT_KNOWLEDGE_TIMEOUT_MS,
|
|
99
|
-
/** The paired activation gate: once on, the read is a set of kernel reads. */
|
|
100
|
-
activation) {
|
|
95
|
+
constructor(db, eventLog, txHost, devices, projects, sandbox, log, timeoutMs = () => PROJECT_KNOWLEDGE_TIMEOUT_MS) {
|
|
101
96
|
this.db = db;
|
|
102
97
|
this.eventLog = eventLog;
|
|
103
98
|
this.txHost = txHost;
|
|
@@ -106,7 +101,6 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
106
101
|
this.sandbox = sandbox;
|
|
107
102
|
this.log = log;
|
|
108
103
|
this.timeoutMs = timeoutMs;
|
|
109
|
-
this.activation = activation;
|
|
110
104
|
}
|
|
111
105
|
/**
|
|
112
106
|
* Reads and records (see the class); notifies after the commit. False: the run had ended under
|
|
@@ -195,7 +189,7 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
195
189
|
});
|
|
196
190
|
return unavailableProject(bound.project, bound.root, projectUnavailable.unsupported());
|
|
197
191
|
}
|
|
198
|
-
const enter = await this.entry(input, bound.
|
|
192
|
+
const enter = await this.entry(input, bound.root);
|
|
199
193
|
return await enter({
|
|
200
194
|
orgId: input.orgId,
|
|
201
195
|
deviceId,
|
|
@@ -246,7 +240,7 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
246
240
|
});
|
|
247
241
|
return unavailableProject(bound.project, bound.root, projectUnavailable.refused(bound.root));
|
|
248
242
|
}
|
|
249
|
-
//
|
|
243
|
+
// a host runtime without restricted enforcement gets no kernel read; the
|
|
250
244
|
// project is recorded unreadable with the reason and the run goes on
|
|
251
245
|
if (!(e instanceof KernelReadUnsupported))
|
|
252
246
|
throw e;
|
|
@@ -268,14 +262,11 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
268
262
|
}
|
|
269
263
|
}
|
|
270
264
|
/**
|
|
271
|
-
* How the read enters the device
|
|
272
|
-
*
|
|
273
|
-
* start runs inside it; another run's claim or none admits nothing), acting for the run's
|
|
265
|
+
* How the read enters the device: `withKernelRead` under the run's current execution claim (the
|
|
266
|
+
* run start runs inside it; another run's claim or none admits nothing), acting for the run's
|
|
274
267
|
* trigger, reading the bound root only.
|
|
275
268
|
*/
|
|
276
|
-
async entry(input,
|
|
277
|
-
if (!permissionContextActive(this.activation))
|
|
278
|
-
return Object.assign(this.sandbox.withSandbox.bind(this.sandbox), { accountId: owner });
|
|
269
|
+
async entry(input, root) {
|
|
279
270
|
const claim = currentExecutionClaim();
|
|
280
271
|
if (!claim ||
|
|
281
272
|
claim.runId !== input.runId ||
|
|
@@ -350,8 +341,6 @@ ProjectKnowledgeService = __decorate([
|
|
|
350
341
|
__param(5, Inject(SandboxService)),
|
|
351
342
|
__param(6, Inject(KERNEL_LOGGER)),
|
|
352
343
|
__param(7, Optional()),
|
|
353
|
-
__param(7, Inject(PROJECT_KNOWLEDGE_TIMEOUT))
|
|
354
|
-
__param(8, Optional()),
|
|
355
|
-
__param(8, Inject(PERMISSION_CONTEXT_ACTIVATION))
|
|
344
|
+
__param(7, Inject(PROJECT_KNOWLEDGE_TIMEOUT))
|
|
356
345
|
], ProjectKnowledgeService);
|
|
357
346
|
export { ProjectKnowledgeService };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EmbedRequest, type EmbedResult, type ExtensionManifest, type ExtensionPointRef, type ImageGenerateRequest, type ImageGenerateResult, type Logger, type ModelInfo, type ModelKind, type ModelRequest, type ModelStreamEvent } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type EmbedRequest, type EmbedResult, type ExtensionManifest, type ExtensionPointRef, type ImageGenerateRequest, type ImageGenerateResult, type Logger, type ModelErrorKind, type ModelInfo, type ModelKind, type ModelRequest, type ModelStreamEvent } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
4
4
|
import { ApiError } from "../errors.js";
|
|
@@ -16,6 +16,11 @@ export declare const LIST_MODELS_TIMEOUT: unique symbol;
|
|
|
16
16
|
* 只用于列表;`resolve`(运行时)照常每次请求,失败由降级梯子重试。
|
|
17
17
|
*/
|
|
18
18
|
export declare const LIST_FAILURE_TTL_SECONDS = 15;
|
|
19
|
+
/**
|
|
20
|
+
* Why a provider's model list failed, as the views report it: the provider's `ModelError` kind
|
|
21
|
+
* (`timeout` too when the kernel's `models.listTimeoutMs` passed), else `unknown`.
|
|
22
|
+
*/
|
|
23
|
+
export type ListErrorKind = ModelErrorKind | "unknown";
|
|
19
24
|
/**
|
|
20
25
|
* The host view the registry needs: a subset of `ExtensionRegistry` (version, digest and
|
|
21
26
|
* `current` optional, for test doubles).
|
|
@@ -83,8 +88,28 @@ export interface ProviderStatus {
|
|
|
83
88
|
plugin: string;
|
|
84
89
|
status: "ok" | "error" | "org_configured";
|
|
85
90
|
error?: string;
|
|
91
|
+
/** With `error` from a failed list (not a provider that needs configuration): why it failed. */
|
|
92
|
+
errorKind?: ListErrorKind;
|
|
86
93
|
models: ListedModelInfo[];
|
|
87
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether a provider gives an agent something to pick in an org ({@link ProviderRegistry.chatUsability}):
|
|
97
|
+
* `usable`, at least one enabled chat model; `list_failed`, its list failed (`errorKind`);
|
|
98
|
+
* `no_chat_models`, it lists but no chat model is on in the org (`orgCanEnable`: a chat model the
|
|
99
|
+
* platform left on is on the org's own disabled list, so an org admin can switch one on).
|
|
100
|
+
*/
|
|
101
|
+
export type ProviderChatUsability = {
|
|
102
|
+
provider: string;
|
|
103
|
+
state: "usable";
|
|
104
|
+
} | {
|
|
105
|
+
provider: string;
|
|
106
|
+
state: "list_failed";
|
|
107
|
+
errorKind: ListErrorKind;
|
|
108
|
+
} | {
|
|
109
|
+
provider: string;
|
|
110
|
+
state: "no_chat_models";
|
|
111
|
+
orgCanEnable: boolean;
|
|
112
|
+
};
|
|
88
113
|
/**
|
|
89
114
|
* 供应商的 `listModels()` 失败(上游不可用等)。仍是 `agent.model_unavailable`,HTTP 调用方照常
|
|
90
115
|
* 得到该错误码;运行时(`runModelStep`)据此类型把它当作可重试的失败交给降级梯子,
|
|
@@ -173,6 +198,14 @@ export declare class ProviderRegistry {
|
|
|
173
198
|
* `disabled` for the org's own list. Reads the same cached lists (no extra provider call).
|
|
174
199
|
*/
|
|
175
200
|
catalog(orgId: string): Promise<ProviderStatus[]>;
|
|
201
|
+
/**
|
|
202
|
+
* Whether each provider gives an agent a model to pick in `orgId` (org readiness): the same
|
|
203
|
+
* cached lists, time limit and failure markers as {@link catalog}, and the same rule as the
|
|
204
|
+
* agent form's list (`list(orgId, { kind: "chat" })`: a chat model neither the platform nor the
|
|
205
|
+
* org disabled). Only providers enabled in the org with a valid effective config there are
|
|
206
|
+
* listed (the {@link hasProvider} gate); the others are left out, never called.
|
|
207
|
+
*/
|
|
208
|
+
chatUsability(orgId: string): Promise<ProviderChatUsability[]>;
|
|
176
209
|
/**
|
|
177
210
|
* Every installed provider with its status (in plugin load order), for `orgId` (the providers it enabled, their enabled
|
|
178
211
|
* models only), or the platform view when undefined (`/admin/models`: every model, `disabled`
|