@capybara-hq/kernel 0.1.0-rc.42 → 0.1.0-rc.44
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/marketplaces.service.d.ts +1 -1
- package/dist/catalog/scope-sync.d.ts +3 -2
- package/dist/catalog/scope-sync.js +3 -2
- package/dist/client/client-access.service.js +4 -4
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +30 -0
- package/dist/conversations/events.d.ts +3 -0
- package/dist/conversations/events.js +7 -3
- package/dist/ctx/create-ctx.d.ts +13 -6
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +10 -0
- package/dist/extensions/enabled.d.ts +24 -4
- package/dist/extensions/enabled.js +47 -10
- package/dist/extensions/host.d.ts +7 -3
- package/dist/extensions/host.js +13 -8
- package/dist/extensions/org-config.d.ts +5 -2
- package/dist/extensions/org-config.js +32 -22
- package/dist/infra/config/kernel-config.service.js +4 -0
- package/dist/models/enablement.d.ts +1 -1
- package/dist/models/enablement.js +1 -1
- package/dist/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- package/dist/platform/ops/models.ops.js +10 -0
- package/dist/runtime/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- package/dist/runtime/providers.d.ts +10 -6
- package/dist/runtime/providers.js +23 -4
- package/dist/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- package/dist/sandbox/review/permission-candidate.js +22 -6
- package/dist/sandbox/review/review.service.d.ts +1 -1
- package/dist/sandbox/review/review.service.js +43 -12
- package/dist/tools/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +4 -0
- package/dist/tools/builtins/builtin-tools.js +28 -5
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/sandbox/deliver.js +7 -49
- package/dist/tools/pipeline.js +15 -7
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +2 -2
- package/dist/tools/tools.module.js +3 -0
- package/package.json +4 -4
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.32";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -22,8 +22,9 @@ import { type ScopeJob } from "./scope-jobs.js";
|
|
|
22
22
|
* `via: "scope"` install or uninstall, so a person's switch committed meanwhile wins.
|
|
23
23
|
* The sync writes no switch row: those record people's choices, and `wantedOn` honours them for
|
|
24
24
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
25
|
-
* and back, layering spec §4). Builtin items are left alone
|
|
26
|
-
* extension
|
|
25
|
+
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
26
|
+
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
27
|
+
* failed install, uninstall or dependency install is logged, audited
|
|
27
28
|
* `plugin.scope_sync_failed`, kept as the pair's open failure (`plugin_scope_sync_failures`, the
|
|
28
29
|
* super admin's inbox, until a later sync of the pair does not fail) and not retried until the next
|
|
29
30
|
* sync of the item. An error outside those steps (a read, the failure write itself) ends the attempt
|
|
@@ -40,8 +40,9 @@ import { ScopeNoLongerWanted, ScopeStillWanted } from "./scope-state.js";
|
|
|
40
40
|
* `via: "scope"` install or uninstall, so a person's switch committed meanwhile wins.
|
|
41
41
|
* The sync writes no switch row: those record people's choices, and `wantedOn` honours them for
|
|
42
42
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
43
|
-
* and back, layering spec §4). Builtin items are left alone
|
|
44
|
-
* extension
|
|
43
|
+
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
44
|
+
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
45
|
+
* failed install, uninstall or dependency install is logged, audited
|
|
45
46
|
* `plugin.scope_sync_failed`, kept as the pair's open failure (`plugin_scope_sync_failures`, the
|
|
46
47
|
* super admin's inbox, until a later sync of the pair does not fail) and not retried until the next
|
|
47
48
|
* sync of the item. An error outside those steps (a read, the failure write itself) ends the attempt
|
|
@@ -11,7 +11,7 @@ import { CLIENT_API_VERSION, EXTENSION_NAME_RE, resolveUiSlots, validateUiContri
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
|
-
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
14
|
+
import { alwaysOnExtensionsQuery, enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
15
15
|
import { STALE_RECONCILE_PERIODS } from "../extensions/lifecycle-topics.js";
|
|
16
16
|
import { CLIENT_EXTENSIONS_SETTING, parseClientExtensions, readClientExtensions, } from "../identity/settings.js";
|
|
17
17
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -191,8 +191,8 @@ let ClientAccess = class ClientAccess {
|
|
|
191
191
|
.select("value")
|
|
192
192
|
.where("key", "=", CLIENT_EXTENSIONS_SETTING)
|
|
193
193
|
.as("kill"),
|
|
194
|
-
// enabled.ts's two sources, per account:
|
|
195
|
-
// otherwise the org's own switch row
|
|
194
|
+
// enabled.ts's two sources, per account: an always-on extension (required, or its plugin
|
|
195
|
+
// is builtin) is on in every org, otherwise the org's own switch row
|
|
196
196
|
eb
|
|
197
197
|
.exists(eb
|
|
198
198
|
.selectFrom("memberships as m")
|
|
@@ -201,7 +201,7 @@ let ClientAccess = class ClientAccess {
|
|
|
201
201
|
.where("m.account_id", "=", accountId)
|
|
202
202
|
.where("o.deleted_at", "is", null)
|
|
203
203
|
.where((w) => w.or([
|
|
204
|
-
w("i.
|
|
204
|
+
w("i.name", "in", alwaysOnExtensionsQuery(db)),
|
|
205
205
|
w.exists(w
|
|
206
206
|
.selectFrom("extension_org_configs as c")
|
|
207
207
|
.select(sql `1`.as("one"))
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -281,6 +281,9 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
281
281
|
models: z.ZodPrefault<z.ZodObject<{
|
|
282
282
|
listTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
283
283
|
embedTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
284
|
+
imageTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
285
|
+
imageMaxPerCall: z.ZodDefault<z.ZodNumber>;
|
|
286
|
+
imagePromptMaxChars: z.ZodDefault<z.ZodNumber>;
|
|
284
287
|
}, z.core.$strict>>;
|
|
285
288
|
hooks: z.ZodPrefault<z.ZodObject<{
|
|
286
289
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
package/dist/config/schema.js
CHANGED
|
@@ -1667,6 +1667,36 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1667
1667
|
hot: true,
|
|
1668
1668
|
description: "Time limit in milliseconds for one embed call to a model provider (one batch of an extension's ctx.models.embed); the call is aborted and fails with a timeout model error",
|
|
1669
1669
|
})),
|
|
1670
|
+
imageTimeoutMs: z
|
|
1671
|
+
.number()
|
|
1672
|
+
.int()
|
|
1673
|
+
.positive()
|
|
1674
|
+
.max(600_000)
|
|
1675
|
+
.default(300_000)
|
|
1676
|
+
.meta(meta({
|
|
1677
|
+
hot: true,
|
|
1678
|
+
description: "Time limit in milliseconds for one image generation call to a model provider (polling included); the call is aborted and fails with a timeout model error",
|
|
1679
|
+
})),
|
|
1680
|
+
imageMaxPerCall: z
|
|
1681
|
+
.number()
|
|
1682
|
+
.int()
|
|
1683
|
+
.positive()
|
|
1684
|
+
.max(10)
|
|
1685
|
+
.default(4)
|
|
1686
|
+
.meta(meta({
|
|
1687
|
+
hot: true,
|
|
1688
|
+
description: "Most images one image generation call may ask for, below each model's own maxImages; more is a validation error",
|
|
1689
|
+
})),
|
|
1690
|
+
imagePromptMaxChars: z
|
|
1691
|
+
.number()
|
|
1692
|
+
.int()
|
|
1693
|
+
.positive()
|
|
1694
|
+
.max(32_000)
|
|
1695
|
+
.default(4_000)
|
|
1696
|
+
.meta(meta({
|
|
1697
|
+
hot: true,
|
|
1698
|
+
description: "Longest prompt, in characters (code points), an image generation call accepts; longer is a validation error",
|
|
1699
|
+
})),
|
|
1670
1700
|
})
|
|
1671
1701
|
.prefault({}),
|
|
1672
1702
|
hooks: z
|
|
@@ -899,11 +899,13 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
899
899
|
outputTokens: z.ZodNumber;
|
|
900
900
|
cacheReadTokens: z.ZodNumber;
|
|
901
901
|
cacheWriteTokens: z.ZodNumber;
|
|
902
|
+
outputImages: z.ZodExactOptional<z.ZodNumber>;
|
|
902
903
|
step: z.ZodNumber;
|
|
903
904
|
provider: z.ZodString;
|
|
904
905
|
model: z.ZodString;
|
|
905
906
|
purpose: z.ZodOptional<z.ZodEnum<{
|
|
906
907
|
compaction: "compaction";
|
|
908
|
+
image: "image";
|
|
907
909
|
review: "review";
|
|
908
910
|
title: "title";
|
|
909
911
|
web_fetch: "web_fetch";
|
|
@@ -1578,6 +1580,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1578
1580
|
outputTokens: z.ZodNumber;
|
|
1579
1581
|
cacheReadTokens: z.ZodNumber;
|
|
1580
1582
|
cacheWriteTokens: z.ZodNumber;
|
|
1583
|
+
outputImages: z.ZodExactOptional<z.ZodNumber>;
|
|
1581
1584
|
}, z.core.$strip>;
|
|
1582
1585
|
}, z.core.$strip>;
|
|
1583
1586
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -441,6 +441,8 @@ const ModelUsageShape = {
|
|
|
441
441
|
outputTokens: count,
|
|
442
442
|
cacheReadTokens: count,
|
|
443
443
|
cacheWriteTokens: count,
|
|
444
|
+
/** Images produced (an image generation call). */
|
|
445
|
+
outputImages: count.exactOptional(),
|
|
444
446
|
};
|
|
445
447
|
/**
|
|
446
448
|
* How a sub-agent's run ended (`subagent_finished`, a `subagent_delivery` finish). `timed_out`:
|
|
@@ -835,14 +837,16 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
835
837
|
* `web_fetch` = a `WebFetch` extraction call (web tools spec §5: the tool call's run and step,
|
|
836
838
|
* `callId` = the call; not model-visible, billed and reported, counted on a sub-agent's parent);
|
|
837
839
|
* `review` = the command-review classifier's call (auto mode spec §5.3: not model-visible, billed
|
|
838
|
-
* and reported, `callId` = the reviewed tool call)
|
|
840
|
+
* and reported, `callId` = the reviewed tool call); `image` = a `GenerateImage` call (image
|
|
841
|
+
* generation spec §7: the tool call's run and step, `callId` = the call, `outputImages` = the
|
|
842
|
+
* images produced; not model-visible, billed and reported, counted on a sub-agent's parent).
|
|
839
843
|
*/
|
|
840
844
|
ev("usage", z.object({
|
|
841
845
|
step: count,
|
|
842
846
|
provider: z.string(),
|
|
843
847
|
model: z.string(),
|
|
844
848
|
...ModelUsageShape,
|
|
845
|
-
purpose: z.enum(["compaction", "title", "web_fetch", "review"]).optional(),
|
|
849
|
+
purpose: z.enum(["compaction", "title", "web_fetch", "review", "image"]).optional(),
|
|
846
850
|
/**
|
|
847
851
|
* The chunk a chunked compaction call summarised (1-based), with the number of calls the
|
|
848
852
|
* compaction attempted (the full chunk count on a completed one; on a failed or hook-denied
|
|
@@ -850,7 +854,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
850
854
|
*/
|
|
851
855
|
chunk: count.optional(),
|
|
852
856
|
chunks: count.optional(),
|
|
853
|
-
/** The tool call a `web_fetch` or `
|
|
857
|
+
/** The tool call a `web_fetch`, `review` or `image` usage belongs to. */
|
|
854
858
|
callId: z.string().optional(),
|
|
855
859
|
})),
|
|
856
860
|
ev("reminder", z.object({ step: count, text: z.string() })),
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type RegisteredHook } from "../extensions/hooks.js";
|
|
|
5
5
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
6
6
|
import type { LockService } from "../infra/lock/lock.service.js";
|
|
7
7
|
import type { ModelEmbeddings } from "../models/embeddings.js";
|
|
8
|
+
import type { ModelImages } from "../models/images.js";
|
|
8
9
|
import type { OrgRole } from "../orgs/roles.js";
|
|
9
10
|
import type { HookRunner } from "../runtime/hook-calls.js";
|
|
10
11
|
import type { EmbedTokens } from "../ui/embed-token.js";
|
|
@@ -27,17 +28,22 @@ export interface KernelDeps {
|
|
|
27
28
|
/** Verifies embed tokens (`ctx.ui` embed requests; the one `EmbedTokens` provider). */
|
|
28
29
|
embedTokens: Pick<EmbedTokens, "verify">;
|
|
29
30
|
/**
|
|
30
|
-
* The `ctx.models`
|
|
31
|
-
* test): `ctx.models` calls
|
|
31
|
+
* The `ctx.models` brokers: embeddings (the one `ModelEmbeddings` provider) and image generation
|
|
32
|
+
* (the one `ModelImages` provider). Absent (a ctx built alone in a test): `ctx.models` calls
|
|
33
|
+
* reject.
|
|
32
34
|
*/
|
|
33
|
-
models?:
|
|
35
|
+
models?: {
|
|
36
|
+
embeddings: Pick<ModelEmbeddings, "embed" | "describe">;
|
|
37
|
+
images: Pick<ModelImages, "generateForExtension" | "describeForExtension">;
|
|
38
|
+
};
|
|
34
39
|
/**
|
|
35
40
|
* What `ctx.net` reads per call: the kernel config (`net.*`) and the org network allowances.
|
|
36
41
|
* Absent (a ctx built alone in a test): `ctx.net.fetch` rejects every request.
|
|
37
42
|
*/
|
|
38
43
|
net?: ExtensionNetServices;
|
|
39
44
|
/**
|
|
40
|
-
* The host's hook registry: `ctx.models.embed`
|
|
45
|
+
* The host's hook registry: `ctx.models.embed` and `generateImage` fire `model.request` through
|
|
46
|
+
* it (spec B §5.4, image generation spec §5.6).
|
|
41
47
|
* A required key, so no builder leaves policy hooks out by omission (fail closed by
|
|
42
48
|
* construction); only a ctx built alone in a test passes `undefined` (no hooks fire).
|
|
43
49
|
*/
|
|
@@ -88,7 +94,7 @@ export interface ExtensionPointAccess {
|
|
|
88
94
|
plugin: string;
|
|
89
95
|
impl: unknown;
|
|
90
96
|
}[];
|
|
91
|
-
/** Names of the extensions enabled in the organization (`extension_org_configs.enabled` plus
|
|
97
|
+
/** Names of the extensions enabled in the organization (`extension_org_configs.enabled` plus always-on extensions, `enabled.ts`); queried every time, not cached. */
|
|
92
98
|
enabledPlugins(orgId: string): Promise<Set<string>>;
|
|
93
99
|
/**
|
|
94
100
|
* Whether the extension's effective config is valid in the organization (layering spec A §6):
|
|
@@ -166,7 +172,8 @@ export declare class LiveConfig {
|
|
|
166
172
|
* - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`, `net`
|
|
167
173
|
* (through `deps.net`, see `ctx/net.ts`);
|
|
168
174
|
* - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
|
|
169
|
-
* only with `permissions.models` (
|
|
175
|
+
* only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
|
|
176
|
+
* `image_generation` ones, through `deps.models`); `http.route`
|
|
170
177
|
* only the method + path declared in `permissions.http` (the record carries the declared access and
|
|
171
178
|
* its mount, see {@link Route}); `tools.register` only names declared in
|
|
172
179
|
* `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -2,6 +2,7 @@ import { EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableEr
|
|
|
2
2
|
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
3
3
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
4
4
|
import { kernelDb } from "../db/kernel-schema.js";
|
|
5
|
+
import { ApiError } from "../errors.js";
|
|
5
6
|
import { enabledExtensionsQuery, isExtensionEnabled } from "../extensions/enabled.js";
|
|
6
7
|
import { checkHookRegistration } from "../extensions/hooks.js";
|
|
7
8
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
@@ -184,7 +185,8 @@ export class LiveConfig {
|
|
|
184
185
|
* - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`, `net`
|
|
185
186
|
* (through `deps.net`, see `ctx/net.ts`);
|
|
186
187
|
* - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
|
|
187
|
-
* only with `permissions.models` (
|
|
188
|
+
* only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
|
|
189
|
+
* `image_generation` ones, through `deps.models`); `http.route`
|
|
188
190
|
* only the method + path declared in `permissions.http` (the record carries the declared access and
|
|
189
191
|
* its mount, see {@link Route}); `tools.register` only names declared in
|
|
190
192
|
* `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or
|
|
@@ -241,8 +243,9 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
241
243
|
plugins: async () => [name],
|
|
242
244
|
}).forPlugin(name)
|
|
243
245
|
: undefined;
|
|
244
|
-
// ctx.models: only with permissions.models;
|
|
245
|
-
// with kind embedding
|
|
246
|
+
// ctx.models: only with permissions.models; each broker accepts only the purposes declared there
|
|
247
|
+
// with its kind (embedding: spec B §5.4; image_generation: image generation spec §5.5), aborted
|
|
248
|
+
// by this instance's signal
|
|
246
249
|
// a frozen copy: the approved manifest, not an object the extension could change later
|
|
247
250
|
const declaredModels = Object.freeze(structuredClone(perms.models ?? []).map((m) => Object.freeze(m)));
|
|
248
251
|
const modelsApi = declaredModels.length > 0
|
|
@@ -250,12 +253,25 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
250
253
|
embed: async (req) => {
|
|
251
254
|
if (!deps.models)
|
|
252
255
|
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
253
|
-
return deps.models.embed(name, declaredModels, req, lifecycle.signal, deps.hooks);
|
|
256
|
+
return deps.models.embeddings.embed(name, declaredModels, req, lifecycle.signal, deps.hooks);
|
|
254
257
|
},
|
|
258
|
+
generateImage: async (req) => {
|
|
259
|
+
if (!deps.models)
|
|
260
|
+
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
261
|
+
return deps.models.images.generateForExtension(name, declaredModels, req, lifecycle.signal, deps.hooks);
|
|
262
|
+
},
|
|
263
|
+
// by the declared purpose's kind; an undeclared purpose has none, so its refusal
|
|
264
|
+
// (model.purpose_unknown) names no kind
|
|
255
265
|
describe: async (req) => {
|
|
256
266
|
if (!deps.models)
|
|
257
267
|
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
258
|
-
|
|
268
|
+
const kind = declaredModels.find((d) => d.purpose === req?.purpose)?.kind;
|
|
269
|
+
if (kind === undefined && typeof req?.purpose === "string") {
|
|
270
|
+
throw new ApiError("model.purpose_unknown", `Extension ${name} declared no model purpose "${req.purpose}" in permissions.models`);
|
|
271
|
+
}
|
|
272
|
+
return kind === "image_generation"
|
|
273
|
+
? deps.models.images.describeForExtension(name, declaredModels, req)
|
|
274
|
+
: deps.models.embeddings.describe(name, declaredModels, req);
|
|
259
275
|
},
|
|
260
276
|
}
|
|
261
277
|
: undefined;
|
|
@@ -1366,6 +1366,16 @@ export interface ModelUsageTable {
|
|
|
1366
1366
|
provider: string;
|
|
1367
1367
|
model: string;
|
|
1368
1368
|
input_tokens: number;
|
|
1369
|
+
/** 0160: the call's kind: `embedding` (default) or `image_generation`. */
|
|
1370
|
+
kind: Generated<"embedding" | "image_generation">;
|
|
1371
|
+
/** 0160: images the call produced (0 for an embedding call). */
|
|
1372
|
+
output_images: Generated<number>;
|
|
1373
|
+
/** 0160: the answer's output tokens (0 for an embedding call). */
|
|
1374
|
+
output_tokens: Generated<number>;
|
|
1375
|
+
/** 0160: the answer's cache read tokens (0 for an embedding call). */
|
|
1376
|
+
cache_read_tokens: Generated<number>;
|
|
1377
|
+
/** 0160: the answer's cache write tokens (0 for an embedding call). */
|
|
1378
|
+
cache_write_tokens: Generated<number>;
|
|
1369
1379
|
occurred_at: Ts;
|
|
1370
1380
|
reported_at: TsNullable;
|
|
1371
1381
|
/** Set when the row's `usage.report` job gave up after its last attempt. */
|
|
@@ -3,11 +3,26 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
|
3
3
|
* Which extensions an organization has enabled. Two sources, and every reader goes through these
|
|
4
4
|
* helpers so none of them misses one:
|
|
5
5
|
* - `extension_org_configs.enabled` (the org's own switch);
|
|
6
|
-
* - every
|
|
7
|
-
*
|
|
6
|
+
* - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
|
|
7
|
+
* future, without an org config row, whatever such a row says. That is a required bootstrap
|
|
8
|
+
* plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
|
|
9
|
+
* builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
|
|
10
|
+
* `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
|
|
11
|
+
* required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
|
|
12
|
+
* `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
|
|
8
13
|
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
9
|
-
* that need that check it themselves, as before.
|
|
14
|
+
* that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
|
|
15
|
+
* replica sees a change at once. `db` may be a transaction.
|
|
10
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
|
+
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
|
+
*/
|
|
21
|
+
export declare function alwaysOnExtensionsQuery(db: KernelSchemaDb): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
22
|
+
ri: import("../db/kernel-schema.js").ExtensionInstallsTable;
|
|
23
|
+
}, "ri", {
|
|
24
|
+
plugin: string;
|
|
25
|
+
}>;
|
|
11
26
|
/** The names of the extensions enabled in `orgId` (a subquery with one column, `plugin`). */
|
|
12
27
|
export declare function enabledExtensionsQuery(db: KernelSchemaDb, orgId: string): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
13
28
|
eoc: import("../db/kernel-schema.js").ExtensionOrgConfigsTable;
|
|
@@ -27,5 +42,10 @@ export declare function enabledExtensionsByOrg(db: KernelSchemaDb): import("kyse
|
|
|
27
42
|
}>;
|
|
28
43
|
/** Whether `plugin` is enabled in `orgId` (see the file header). */
|
|
29
44
|
export declare function isExtensionEnabled(db: KernelSchemaDb, orgId: string, plugin: string): Promise<boolean>;
|
|
30
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
47
|
+
* `extension.required`. Whether an extension is on in every org is {@link alwaysOnExtensions}.
|
|
48
|
+
*/
|
|
31
49
|
export declare function requiredExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
50
|
+
/** The names of the always-on extensions ({@link alwaysOnExtensionsQuery}). */
|
|
51
|
+
export declare function alwaysOnExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
@@ -3,11 +3,43 @@ import { sql } from "kysely";
|
|
|
3
3
|
* Which extensions an organization has enabled. Two sources, and every reader goes through these
|
|
4
4
|
* helpers so none of them misses one:
|
|
5
5
|
* - `extension_org_configs.enabled` (the org's own switch);
|
|
6
|
-
* - every
|
|
7
|
-
*
|
|
6
|
+
* - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
|
|
7
|
+
* future, without an org config row, whatever such a row says. That is a required bootstrap
|
|
8
|
+
* plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
|
|
9
|
+
* builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
|
|
10
|
+
* `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
|
|
11
|
+
* required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
|
|
12
|
+
* `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
|
|
8
13
|
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
9
|
-
* that need that check it themselves, as before.
|
|
14
|
+
* that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
|
|
15
|
+
* replica sees a change at once. `db` may be a transaction.
|
|
10
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
|
+
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
|
+
*/
|
|
21
|
+
export function alwaysOnExtensionsQuery(db) {
|
|
22
|
+
return db
|
|
23
|
+
.selectFrom("extension_installs as ri")
|
|
24
|
+
.select("ri.name as plugin")
|
|
25
|
+
.where("ri.required", "=", true)
|
|
26
|
+
.union(db
|
|
27
|
+
.selectFrom("extension_installs as ei")
|
|
28
|
+
.innerJoin("catalog_items as ci", "ci.id", "ei.catalog_item_id")
|
|
29
|
+
.select("ei.name as plugin")
|
|
30
|
+
.where("ci.builtin", "=", true)
|
|
31
|
+
.where("ci.disabled", "=", false)
|
|
32
|
+
.where("ci.deleted_at", "is", null)
|
|
33
|
+
.where("ci.owner_org_id", "is", null))
|
|
34
|
+
.union(db
|
|
35
|
+
.selectFrom("extension_catalog_sources as cs")
|
|
36
|
+
.innerJoin("catalog_items as si", "si.id", "cs.item_id")
|
|
37
|
+
.select("cs.plugin as plugin")
|
|
38
|
+
.where("si.builtin", "=", true)
|
|
39
|
+
.where("si.disabled", "=", false)
|
|
40
|
+
.where("si.deleted_at", "is", null)
|
|
41
|
+
.where("si.owner_org_id", "is", null));
|
|
42
|
+
}
|
|
11
43
|
/** The names of the extensions enabled in `orgId` (a subquery with one column, `plugin`). */
|
|
12
44
|
export function enabledExtensionsQuery(db, orgId) {
|
|
13
45
|
return db
|
|
@@ -15,10 +47,7 @@ export function enabledExtensionsQuery(db, orgId) {
|
|
|
15
47
|
.select("eoc.plugin as plugin")
|
|
16
48
|
.where("eoc.org_id", "=", orgId)
|
|
17
49
|
.where("eoc.enabled", "=", true)
|
|
18
|
-
.union(db
|
|
19
|
-
.selectFrom("extension_installs as ri")
|
|
20
|
-
.select("ri.name as plugin")
|
|
21
|
-
.where("ri.required", "=", true));
|
|
50
|
+
.union(db.selectFrom(alwaysOnExtensionsQuery(db).as("ao")).select("ao.plugin as plugin"));
|
|
22
51
|
}
|
|
23
52
|
/**
|
|
24
53
|
* Every (org, extension) pair that is enabled, for queries that join it (columns `org_id`,
|
|
@@ -32,8 +61,8 @@ export function enabledExtensionsByOrg(db) {
|
|
|
32
61
|
.where("eoc.enabled", "=", true)
|
|
33
62
|
.union(db
|
|
34
63
|
.selectFrom("orgs as ro")
|
|
35
|
-
.innerJoin(
|
|
36
|
-
.select(["ro.id as org_id", "
|
|
64
|
+
.innerJoin(alwaysOnExtensionsQuery(db).as("ao"), (j) => j.onTrue())
|
|
65
|
+
.select(["ro.id as org_id", "ao.plugin as plugin"]));
|
|
37
66
|
}
|
|
38
67
|
/** Whether `plugin` is enabled in `orgId` (see the file header). */
|
|
39
68
|
export async function isExtensionEnabled(db, orgId, plugin) {
|
|
@@ -44,7 +73,10 @@ export async function isExtensionEnabled(db, orgId, plugin) {
|
|
|
44
73
|
.executeTakeFirst();
|
|
45
74
|
return row !== undefined;
|
|
46
75
|
}
|
|
47
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
78
|
+
* `extension.required`. Whether an extension is on in every org is {@link alwaysOnExtensions}.
|
|
79
|
+
*/
|
|
48
80
|
export async function requiredExtensions(db) {
|
|
49
81
|
const rows = await db
|
|
50
82
|
.selectFrom("extension_installs")
|
|
@@ -53,3 +85,8 @@ export async function requiredExtensions(db) {
|
|
|
53
85
|
.execute();
|
|
54
86
|
return new Set(rows.map((r) => r.name));
|
|
55
87
|
}
|
|
88
|
+
/** The names of the always-on extensions ({@link alwaysOnExtensionsQuery}). */
|
|
89
|
+
export async function alwaysOnExtensions(db) {
|
|
90
|
+
const rows = await alwaysOnExtensionsQuery(db).execute();
|
|
91
|
+
return new Set(rows.map((r) => r.plugin));
|
|
92
|
+
}
|
|
@@ -12,6 +12,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
12
12
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
13
13
|
import type { KernelLogger } from "../log.js";
|
|
14
14
|
import { ModelEmbeddings } from "../models/embeddings.js";
|
|
15
|
+
import { ModelImages } from "../models/images.js";
|
|
15
16
|
import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
|
|
16
17
|
import { EmbedTokens } from "../ui/embed-token.js";
|
|
17
18
|
import type { UiActionHandler, UiRender } from "../ui/registry.js";
|
|
@@ -266,7 +267,9 @@ export declare class ExtensionHost {
|
|
|
266
267
|
*/
|
|
267
268
|
effective: Pick<EffectiveConfigs, "get">,
|
|
268
269
|
/** `ctx.models`: the embeddings broker (spec B §5.4). */
|
|
269
|
-
|
|
270
|
+
embeddings: Pick<ModelEmbeddings, "embed" | "describe">,
|
|
271
|
+
/** `ctx.models.generateImage`: the image generation calls (image generation spec §5.5). */
|
|
272
|
+
images: Pick<ModelImages, "generateForExtension" | "describeForExtension">,
|
|
270
273
|
/** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
|
|
271
274
|
allowances: OrgNetworkAllowances,
|
|
272
275
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
@@ -490,8 +493,9 @@ export declare class ExtensionHost {
|
|
|
490
493
|
/** 配置声明的插件名 → 来源(安装包不能与它们重名)。 */
|
|
491
494
|
declared(): Map<string, ExtensionSource>;
|
|
492
495
|
/**
|
|
493
|
-
* Extensions enabled in the org: `extension_org_configs.enabled` plus every
|
|
494
|
-
*
|
|
496
|
+
* Extensions enabled in the org: `extension_org_configs.enabled` plus every always-on extension
|
|
497
|
+
* (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
|
|
498
|
+
* time, not cached.
|
|
495
499
|
* Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
|
|
496
500
|
* Acceptable for now; if a cache is ever added, give it a short TTL so an org disabling a plugin
|
|
497
501
|
* takes effect quickly.
|
package/dist/extensions/host.js
CHANGED
|
@@ -26,6 +26,7 @@ import { LockService } from "../infra/lock/lock.service.js";
|
|
|
26
26
|
import { KERNEL_LOGGER, KEYRING, REDIS, REDIS_SUBSCRIBER } from "../infra/tokens.js";
|
|
27
27
|
import { KERNEL_APP_OPTIONS } from "../lifecycle/tokens.js";
|
|
28
28
|
import { ModelEmbeddings } from "../models/embeddings.js";
|
|
29
|
+
import { ModelImages } from "../models/images.js";
|
|
29
30
|
import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
|
|
30
31
|
import { packagePath } from "../packages/tgz.js";
|
|
31
32
|
import { EmbedTokens } from "../ui/embed-token.js";
|
|
@@ -413,7 +414,9 @@ let ExtensionHost = class ExtensionHost {
|
|
|
413
414
|
*/
|
|
414
415
|
effective,
|
|
415
416
|
/** `ctx.models`: the embeddings broker (spec B §5.4). */
|
|
416
|
-
|
|
417
|
+
embeddings,
|
|
418
|
+
/** `ctx.models.generateImage`: the image generation calls (image generation spec §5.5). */
|
|
419
|
+
images,
|
|
417
420
|
/** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
|
|
418
421
|
allowances,
|
|
419
422
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
@@ -445,8 +448,8 @@ let ExtensionHost = class ExtensionHost {
|
|
|
445
448
|
redisUrl: c.redis.url,
|
|
446
449
|
keyring,
|
|
447
450
|
embedTokens,
|
|
448
|
-
models,
|
|
449
|
-
// ctx.models.embed
|
|
451
|
+
models: { embeddings, images },
|
|
452
|
+
// ctx.models.embed and generateImage fire model.request through the same registry
|
|
450
453
|
hooks: this.hooks,
|
|
451
454
|
net: { config, allowances, ...(netSeams !== undefined && { seams: netSeams }) },
|
|
452
455
|
locks,
|
|
@@ -1668,8 +1671,9 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1668
1671
|
return this.registry.declared();
|
|
1669
1672
|
}
|
|
1670
1673
|
/**
|
|
1671
|
-
* Extensions enabled in the org: `extension_org_configs.enabled` plus every
|
|
1672
|
-
*
|
|
1674
|
+
* Extensions enabled in the org: `extension_org_configs.enabled` plus every always-on extension
|
|
1675
|
+
* (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
|
|
1676
|
+
* time, not cached.
|
|
1673
1677
|
* Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
|
|
1674
1678
|
* Acceptable for now; if a cache is ever added, give it a short TTL so an org disabling a plugin
|
|
1675
1679
|
* takes effect quickly.
|
|
@@ -2394,8 +2398,9 @@ ExtensionHost = __decorate([
|
|
|
2394
2398
|
__param(12, Inject(KERNEL_APP_OPTIONS)),
|
|
2395
2399
|
__param(13, Inject(EffectiveConfigs)),
|
|
2396
2400
|
__param(14, Inject(ModelEmbeddings)),
|
|
2397
|
-
__param(15, Inject(
|
|
2398
|
-
__param(16,
|
|
2399
|
-
__param(
|
|
2401
|
+
__param(15, Inject(ModelImages)),
|
|
2402
|
+
__param(16, Inject(OrgNetworkAllowances)),
|
|
2403
|
+
__param(17, Optional()),
|
|
2404
|
+
__param(17, Inject(EXTENSION_NET_SEAMS))
|
|
2400
2405
|
], ExtensionHost);
|
|
2401
2406
|
export { ExtensionHost };
|
|
@@ -48,7 +48,9 @@ export interface OrgExtensionView {
|
|
|
48
48
|
reason?: ExtensionUnavailableReason;
|
|
49
49
|
/**
|
|
50
50
|
* A required bootstrap plugin: enabled in every org (`enabled` is always true) and cannot be
|
|
51
|
-
* disabled here (`extension.required`); its org config, when it has one, can still be set.
|
|
51
|
+
* disabled here (`extension.required`); its org config, when it has one, can still be set. An
|
|
52
|
+
* extension of a builtin plugin is enabled in every org as well (`enabled.ts`) without being
|
|
53
|
+
* required: it is locked by its plugin (`switchable` false, `plugin.scope_locked`).
|
|
52
54
|
*/
|
|
53
55
|
required: boolean;
|
|
54
56
|
/** The catalog plugin the extension ships in and its scope (builtin counts as `all`); null without one. */
|
|
@@ -217,7 +219,8 @@ export declare class OrgExtensionConfigs {
|
|
|
217
219
|
private assertSwitchRules;
|
|
218
220
|
/**
|
|
219
221
|
* 读取并解密某插件在该组织下的完整配置(供运行时按组织构造插件实例)。
|
|
220
|
-
*
|
|
222
|
+
* An always-on extension (a required bootstrap plugin, or its plugin is builtin: `enabled.ts`) is
|
|
223
|
+
* enabled without a row (its stored config, or `{}`, is validated).
|
|
221
224
|
* 无记录 → undefined;插件无 `config.org` 或已停用(`enabled=false`,不校验、不读密钥)时 `config` 为 null。
|
|
222
225
|
* 配置行与密钥在同一个 `REPEATABLE READ` 只读事务里读取。
|
|
223
226
|
* A stored config that no longer matches the schema (e.g. after a plugin upgrade) throws
|