@capybara-hq/kernel 0.1.0-rc.48 → 0.1.0-rc.49
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/admin/admin.module.js +2 -0
- package/dist/admin/admin.schemas.d.ts +4 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +8 -4
- package/dist/agents/agents.schemas.js +1 -1
- package/dist/agents/instruction-files.js +0 -3
- package/dist/background/launch.d.ts +4 -0
- package/dist/background/launch.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/delivery-scope.d.ts +34 -0
- package/dist/conversations/delivery-scope.js +23 -0
- package/dist/conversations/event-log.d.ts +18 -0
- package/dist/conversations/event-log.js +54 -0
- package/dist/conversations/events.d.ts +2 -0
- package/dist/conversations/events.js +15 -2
- package/dist/conversations/prompt-suggestion-request.d.ts +95 -0
- package/dist/conversations/prompt-suggestion-request.js +213 -0
- package/dist/conversations/prompt-suggestion-store.d.ts +51 -0
- package/dist/conversations/prompt-suggestion-store.js +136 -0
- package/dist/conversations/prompt-suggestions.d.ts +153 -0
- package/dist/conversations/prompt-suggestions.js +563 -0
- package/dist/conversations/titles.js +11 -5
- package/dist/evals/reconstruct.d.ts +26 -1
- package/dist/evals/reconstruct.js +25 -6
- package/dist/identity/settings.d.ts +13 -0
- package/dist/identity/settings.js +37 -2
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/kernel.module.js +4 -1
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +13 -7
- package/dist/models/image-usable.d.ts +30 -6
- package/dist/models/image-usable.js +38 -7
- package/dist/models/images.js +6 -4
- package/dist/models/purposes.d.ts +1 -1
- package/dist/models/purposes.js +10 -4
- package/dist/orgs/settings.service.d.ts +16 -0
- package/dist/orgs/settings.service.js +46 -5
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/availability.d.ts +5 -0
- package/dist/platform/availability.js +7 -3
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +1 -1
- package/dist/platform/ops/admin.ops.js +3 -2
- package/dist/platform/ops/agent-skills.ops.js +5 -5
- package/dist/platform/ops/agents.ops.js +3 -3
- package/dist/platform/ops/approvals.ops.d.ts +1 -1
- package/dist/platform/ops/approvals.ops.js +2 -2
- package/dist/platform/ops/background.ops.js +1 -1
- package/dist/platform/ops/catalog-admin.ops.js +3 -3
- package/dist/platform/ops/conversations.ops.js +2 -2
- package/dist/platform/ops/devices.ops.js +2 -2
- package/dist/platform/ops/extensions-admin.ops.js +2 -2
- package/dist/platform/ops/extensions.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/org-plugins.ops.js +4 -4
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +3 -3
- package/dist/platform/ops/requests.ops.js +1 -1
- package/dist/platform/ops/schedules.ops.js +6 -6
- package/dist/roles/worker-role.d.ts +6 -3
- package/dist/roles/worker-role.js +21 -13
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/compaction-settings.service.d.ts +8 -0
- package/dist/runtime/compaction-settings.service.js +12 -6
- package/dist/runtime/run-processors.d.ts +14 -6
- package/dist/runtime/run-processors.js +43 -8
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +24 -16
- package/dist/runtime/runtime.module.d.ts +1 -1
- package/dist/runtime/runtime.module.js +7 -1
- package/dist/runtime/stream.d.ts +7 -1
- package/dist/runtime/stream.js +54 -3
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +2 -1
- package/dist/sandbox/sandbox-file-reader.js +1 -1
- package/dist/tools/builtins/agent.js +5 -5
- package/dist/tools/builtins/artifacts.d.ts +33 -7
- package/dist/tools/builtins/artifacts.js +92 -14
- package/dist/tools/builtins/image/generate.d.ts +4 -1
- package/dist/tools/builtins/image/generate.js +70 -14
- package/dist/tools/builtins/platform.d.ts +0 -2
- package/dist/tools/builtins/platform.js +3 -5
- package/dist/tools/builtins/sandbox/bash.js +15 -11
- package/dist/tools/builtins/sandbox/common.d.ts +3 -2
- package/dist/tools/builtins/sandbox/deliver.js +13 -7
- package/dist/tools/builtins/sandbox/glob.js +1 -1
- package/dist/tools/builtins/sandbox/grep.js +1 -1
- package/dist/tools/builtins/sandbox/read.js +3 -3
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +13 -11
- package/dist/tools/builtins/send-message.d.ts +1 -1
- package/dist/tools/builtins/send-message.js +3 -3
- package/dist/tools/builtins/skill-load.d.ts +1 -1
- package/dist/tools/builtins/tool-search.js +1 -1
- package/dist/tools/builtins/web/extract.js +1 -1
- package/dist/tools/builtins/web/search.js +2 -4
- package/dist/tools/connector-account-policies.js +1 -1
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +1 -1
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ import { latestSummary, mediaRefs, planMedia, } from "../runtime/context/build.j
|
|
|
8
8
|
import { applyFit, estimateAfterFit, planFit, planningBounds, planSqueezedFit, sentOutputCap, } from "../runtime/context/fit.js";
|
|
9
9
|
import { assertRecordedPermissionEvents, permissionContextHistory, RecordedPermissionContextError, } from "../runtime/context/permission-profile.js";
|
|
10
10
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
11
|
-
import { assembleModelRequest } from "../runtime/model-call.js";
|
|
11
|
+
import { assembleModelRequest, } from "../runtime/model-call.js";
|
|
12
12
|
import { CHILD_REMOVED_TOOLS } from "../runtime/subagents/definition.js";
|
|
13
13
|
import { AGENT_TOOL } from "../tools/builtin-names.js";
|
|
14
14
|
import { canonicalJson } from "./recorded-tools.js";
|
|
@@ -105,7 +105,12 @@ const sameParams = (a, b) => {
|
|
|
105
105
|
};
|
|
106
106
|
const sameList = (a, b) => (a ?? []).length === (b ?? []).length &&
|
|
107
107
|
(a ?? []).every((x, i) => x.key === b?.[i]?.key && x.specHash === b?.[i]?.specHash);
|
|
108
|
-
|
|
108
|
+
/**
|
|
109
|
+
* The inputs {@link reconstructRequest} hands {@link assembleModelRequest} for the `model_call` at
|
|
110
|
+
* `modelCallSeq`, with the drift found on the way. One path: `reconstructRequest` builds from it,
|
|
111
|
+
* and the prompt suggestion side request extends the same input with later events.
|
|
112
|
+
*/
|
|
113
|
+
export function reconstructInputs(s, modelCallSeq, opts) {
|
|
109
114
|
const all = toEvents(s);
|
|
110
115
|
const call = findCall(all, modelCallSeq);
|
|
111
116
|
const rec = call.payload.request;
|
|
@@ -159,7 +164,6 @@ export function reconstructRequest(s, modelCallSeq, opts) {
|
|
|
159
164
|
// 工具:按记录的顺序从快照取定义;取不到的从请求里去掉(基线与候选一样)
|
|
160
165
|
const tools = [];
|
|
161
166
|
const seen = new Set();
|
|
162
|
-
const kept = (list) => list.filter((t) => s.toolSpecs[t.specHash] !== undefined);
|
|
163
167
|
for (const t of [...rec.tools, ...(rec.catalog ?? [])]) {
|
|
164
168
|
if (seen.has(t.key))
|
|
165
169
|
continue;
|
|
@@ -188,7 +192,7 @@ export function reconstructRequest(s, modelCallSeq, opts) {
|
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
194
|
const budget = opts.mediaBudgetBytes ?? rec.mediaBudgetBytes;
|
|
191
|
-
const
|
|
195
|
+
const input = {
|
|
192
196
|
events: inputEvents(all, call),
|
|
193
197
|
agent,
|
|
194
198
|
agentVersion: version,
|
|
@@ -209,8 +213,23 @@ export function reconstructRequest(s, modelCallSeq, opts) {
|
|
|
209
213
|
...(baseline && { recordedMaxOutputTokens: rec.maxOutputTokens }),
|
|
210
214
|
// the baseline replays the recorded trim (no reserve needed); a candidate below recomputes it
|
|
211
215
|
...(baseline && rec.fit !== undefined ? { fit: rec.fit } : {}),
|
|
212
|
-
}
|
|
213
|
-
|
|
216
|
+
};
|
|
217
|
+
return { input, drift, baseline, call, events: all };
|
|
218
|
+
}
|
|
219
|
+
export function reconstructRequest(s, modelCallSeq, opts) {
|
|
220
|
+
return reconstructFromInputs(s, reconstructInputs(s, modelCallSeq, opts), opts);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* {@link reconstructRequest} from inputs {@link reconstructInputs} already gathered (with the same
|
|
224
|
+
* `s` and `opts`): assembles the request and judges the remaining drift. Leaves `gathered.input`
|
|
225
|
+
* as it was, so a caller may assemble from it again.
|
|
226
|
+
*/
|
|
227
|
+
export function reconstructFromInputs(s, gathered, opts) {
|
|
228
|
+
const { input, baseline, call, events: all } = gathered;
|
|
229
|
+
const drift = new Set(gathered.drift);
|
|
230
|
+
const rec = call.payload.request;
|
|
231
|
+
const kept = (list) => list.filter((t) => s.toolSpecs[t.specHash] !== undefined);
|
|
232
|
+
const { request, meta, mediaTokens } = assembleModelRequest(input);
|
|
214
233
|
if (!baseline) {
|
|
215
234
|
// The hard fit guard against the candidate's window (spec §4.9), as the runtime runs it: plan
|
|
216
235
|
// against the planning target `W - O_p - R_p` (squeezed to `W - 1 - R_p` when out of reach),
|
|
@@ -177,7 +177,16 @@ export type DeploymentSettingsView = DeploymentSettings & {
|
|
|
177
177
|
externalSharing: ExternalSharingView;
|
|
178
178
|
/** The longest expiry a share may take, in days, and where it comes from. */
|
|
179
179
|
shareMaxExpiryDays: ShareMaxExpiryView;
|
|
180
|
+
/** The platform's prompt suggestions switch (absent reads `on`). */
|
|
181
|
+
promptSuggestions: "on" | "off";
|
|
180
182
|
};
|
|
183
|
+
/** The `deployment_settings` key of the platform's prompt suggestions switch (`"on" | "off"`). */
|
|
184
|
+
export declare const PROMPT_SUGGESTIONS_SETTING = "promptSuggestions";
|
|
185
|
+
/**
|
|
186
|
+
* The platform's prompt suggestions switch, read live from PG (in the caller's transaction when
|
|
187
|
+
* there is one): absent is `on`; an invalid stored value reads as `off` with a warning.
|
|
188
|
+
*/
|
|
189
|
+
export declare function readPromptSuggestions(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<"on" | "off">;
|
|
181
190
|
/**
|
|
182
191
|
* 设置的修改(PUT /api/v1/admin/settings 的 body):只改给出的键。
|
|
183
192
|
* `runConcurrencyOverrides` 按组织合并:值为正整数 → 设置该组织的上限;值为 null → 删除该组织的覆盖
|
|
@@ -249,6 +258,10 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
|
|
|
249
258
|
deny: "deny";
|
|
250
259
|
}>>>;
|
|
251
260
|
shareMaxExpiryDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
261
|
+
promptSuggestions: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
262
|
+
off: "off";
|
|
263
|
+
on: "on";
|
|
264
|
+
}>>>;
|
|
252
265
|
htmlRenderCdnAllowlist: z.ZodOptional<z.ZodArray<z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>>>;
|
|
253
266
|
}, z.core.$strict>;
|
|
254
267
|
export type DeploymentSettingsPatch = z.infer<typeof DEPLOYMENT_SETTINGS_PATCH>;
|
|
@@ -219,6 +219,29 @@ export const DEPLOYMENT_SETTINGS = z.object({
|
|
|
219
219
|
});
|
|
220
220
|
const DEFAULTS = DEPLOYMENT_SETTINGS.parse({});
|
|
221
221
|
const autoModeWidenRefused = () => new ApiError("deployment.auto_mode_not_allowed", "Allowing Full permission at the platform level (devicesFullAccess) needs a super admin in the admin console; an API token or the Platform tool may only turn it off.");
|
|
222
|
+
/** The `deployment_settings` key of the platform's prompt suggestions switch (`"on" | "off"`). */
|
|
223
|
+
export const PROMPT_SUGGESTIONS_SETTING = "promptSuggestions";
|
|
224
|
+
const PromptSuggestionsValue = z.enum(["on", "off"]);
|
|
225
|
+
/**
|
|
226
|
+
* The platform's prompt suggestions switch, read live from PG (in the caller's transaction when
|
|
227
|
+
* there is one): absent is `on`; an invalid stored value reads as `off` with a warning.
|
|
228
|
+
*/
|
|
229
|
+
export async function readPromptSuggestions(db, log) {
|
|
230
|
+
const row = await db
|
|
231
|
+
.selectFrom("deployment_settings")
|
|
232
|
+
.select("value")
|
|
233
|
+
.where("key", "=", PROMPT_SUGGESTIONS_SETTING)
|
|
234
|
+
.executeTakeFirst();
|
|
235
|
+
if (row === undefined)
|
|
236
|
+
return "on";
|
|
237
|
+
const parsed = PromptSuggestionsValue.safeParse(row.value);
|
|
238
|
+
if (parsed.success)
|
|
239
|
+
return parsed.data;
|
|
240
|
+
log?.warn("invalid deployment setting; it reads as prompt suggestions off", {
|
|
241
|
+
key: PROMPT_SUGGESTIONS_SETTING,
|
|
242
|
+
});
|
|
243
|
+
return "off";
|
|
244
|
+
}
|
|
222
245
|
const externalSharingWidenRefused = () => new ApiError("deployment.external_sharing_not_allowed", "Allowing external sharing at the platform level (externalSharing) needs a super admin in the admin console; an API token or the Platform tool may only turn it off.");
|
|
223
246
|
const sharingWidenRefused = (field, message) => new ApiError("deployment.sharing_widen_not_allowed", message, [{ path: field }]);
|
|
224
247
|
/**
|
|
@@ -302,6 +325,11 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
|
|
|
302
325
|
* value set in the startup config is read-only (409 `deployment.setting_readonly`).
|
|
303
326
|
*/
|
|
304
327
|
shareMaxExpiryDays: ShareMaxExpiryDays.nullable().optional(),
|
|
328
|
+
/**
|
|
329
|
+
* Whether the composer suggests the person's next message after a completed run, for the whole
|
|
330
|
+
* platform; null clears it (back to the default, on). An org's own switch must be on too.
|
|
331
|
+
*/
|
|
332
|
+
promptSuggestions: PromptSuggestionsValue.nullable().optional(),
|
|
305
333
|
/** The CDN allowlist of rendered HTML files, replaced whole (stored without duplicates). */
|
|
306
334
|
htmlRenderCdnAllowlist: HtmlCdnAllowlistSchema.optional(),
|
|
307
335
|
})
|
|
@@ -475,7 +503,7 @@ export function normalizeDeploymentSettingsPatch(patch) {
|
|
|
475
503
|
throw new ApiError("validation_failed", "Invalid deployment settings", [
|
|
476
504
|
{
|
|
477
505
|
path: "devicesAutoMode",
|
|
478
|
-
message: "
|
|
506
|
+
message: "pass devicesFullAccess only, not together with devicesAutoMode",
|
|
479
507
|
},
|
|
480
508
|
]);
|
|
481
509
|
const { devicesAutoMode, ...rest } = patch;
|
|
@@ -501,12 +529,13 @@ let SettingsService = class SettingsService {
|
|
|
501
529
|
}
|
|
502
530
|
/** The settings with the platform's Full switch and attribution defaults in effect. */
|
|
503
531
|
async view() {
|
|
504
|
-
const [settings, devicesFullAccess, attribution, externalSharing, shareMaxExpiryDays] = await Promise.all([
|
|
532
|
+
const [settings, devicesFullAccess, attribution, externalSharing, shareMaxExpiryDays, promptSuggestions,] = await Promise.all([
|
|
505
533
|
this.get(),
|
|
506
534
|
readDevicesFullAccess(this.db.db, this.config, this.log),
|
|
507
535
|
readStoredPlatformAttribution(this.db.db, this.log),
|
|
508
536
|
readExternalSharing(this.db.db, this.config, this.log),
|
|
509
537
|
readShareMaxExpiry(this.db.db, this.config, this.log),
|
|
538
|
+
readPromptSuggestions(this.db.db, this.log),
|
|
510
539
|
]);
|
|
511
540
|
return {
|
|
512
541
|
...settings,
|
|
@@ -515,6 +544,7 @@ let SettingsService = class SettingsService {
|
|
|
515
544
|
attribution: this.attributionView(attribution),
|
|
516
545
|
externalSharing,
|
|
517
546
|
shareMaxExpiryDays,
|
|
547
|
+
promptSuggestions,
|
|
518
548
|
};
|
|
519
549
|
}
|
|
520
550
|
attributionView(stored) {
|
|
@@ -764,6 +794,11 @@ let SettingsService = class SettingsService {
|
|
|
764
794
|
writes.push([key, value]);
|
|
765
795
|
}
|
|
766
796
|
}
|
|
797
|
+
if (patch.promptSuggestions === null)
|
|
798
|
+
deletes.push(PROMPT_SUGGESTIONS_SETTING);
|
|
799
|
+
else if (patch.promptSuggestions !== undefined) {
|
|
800
|
+
writes.push([PROMPT_SUGGESTIONS_SETTING, patch.promptSuggestions]);
|
|
801
|
+
}
|
|
767
802
|
if (deletes.length > 0) {
|
|
768
803
|
await this.db.deleteFrom("deployment_settings").where("key", "in", deletes).execute();
|
|
769
804
|
}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (admin/health.service.ts) lists the same names from the feature constants;
|
|
5
5
|
* test/infra/queue-names.test.ts keeps the two equal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
|
|
7
|
+
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
|
|
8
8
|
export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
|
package/dist/kernel.module.js
CHANGED
|
@@ -10,6 +10,7 @@ import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
|
10
10
|
import { CatalogModule } from "./catalog/catalog.module.js";
|
|
11
11
|
import { ChannelsModule } from "./channels/channels.module.js";
|
|
12
12
|
import { ClientModule } from "./client/client.module.js";
|
|
13
|
+
import { PromptSuggestionsModule } from "./conversations/prompt-suggestions.js";
|
|
13
14
|
import { TitlesModule } from "./conversations/titles.js";
|
|
14
15
|
import { ExtensionsModule } from "./extensions/extensions.module.js";
|
|
15
16
|
import { ApiModule } from "./http/api.module.js";
|
|
@@ -113,12 +114,14 @@ let KernelModule = KernelModule_1 = class KernelModule {
|
|
|
113
114
|
ErrorFilterModule,
|
|
114
115
|
KernelAppOptionsModule.forRoot({ ...options, logger }),
|
|
115
116
|
// KernelLifecycle's setup check, the extension host it drives, the catalog it syncs and
|
|
116
|
-
// the producers its stop closes on every role (titles, usage.report,
|
|
117
|
+
// the producers its stop closes on every role (titles, prompt suggestions, usage.report,
|
|
118
|
+
// channel deliveries)
|
|
117
119
|
IdentityModule,
|
|
118
120
|
PermissionAuthorityModule,
|
|
119
121
|
ExtensionsModule,
|
|
120
122
|
CatalogModule,
|
|
121
123
|
TitlesModule,
|
|
124
|
+
PromptSuggestionsModule,
|
|
122
125
|
UsageReportModule,
|
|
123
126
|
ChannelsModule,
|
|
124
127
|
// the access check of extension routes (the plugin dispatch, api and gateway roles)
|
|
@@ -7,6 +7,7 @@ import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
|
7
7
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
8
8
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
9
9
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
10
|
+
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
10
11
|
import { TitleQueue } from "../conversations/titles.js";
|
|
11
12
|
import { ExtensionBlobs } from "../extensions/blobs.js";
|
|
12
13
|
import { BootstrapService } from "../extensions/bootstrap.js";
|
|
@@ -84,6 +85,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
84
85
|
private readonly bus;
|
|
85
86
|
private readonly usageReport;
|
|
86
87
|
private readonly titles;
|
|
88
|
+
private readonly suggestions;
|
|
87
89
|
private readonly channelJobs;
|
|
88
90
|
private readonly channelOutbound;
|
|
89
91
|
private readonly presence;
|
|
@@ -103,7 +105,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
103
105
|
private bootstrapCarry;
|
|
104
106
|
/** The packages the first bootstrap pass obtained, so the second downloads nothing again. */
|
|
105
107
|
private bootstrapPackages;
|
|
106
|
-
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, marketplaces: MarketplacesService, pluginImport: PluginImport, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
108
|
+
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, 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);
|
|
107
109
|
/** The kernel HTTP application (set up by `buildKernelApp` before `init()`). */
|
|
108
110
|
get http(): KernelHttpApp;
|
|
109
111
|
attachHttp(http: KernelHttpApp): void;
|
|
@@ -14,6 +14,7 @@ import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
|
14
14
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
15
15
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
16
16
|
import { ChannelOutbound } from "../channels/outbound.js";
|
|
17
|
+
import { PromptSuggestionQueue } from "../conversations/prompt-suggestions.js";
|
|
17
18
|
import { TitleQueue } from "../conversations/titles.js";
|
|
18
19
|
import { migrate } from "../db/migrator.js";
|
|
19
20
|
import { ExtensionBlobs } from "../extensions/blobs.js";
|
|
@@ -104,6 +105,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
104
105
|
bus;
|
|
105
106
|
usageReport;
|
|
106
107
|
titles;
|
|
108
|
+
suggestions;
|
|
107
109
|
channelJobs;
|
|
108
110
|
channelOutbound;
|
|
109
111
|
presence;
|
|
@@ -127,7 +129,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
127
129
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
128
130
|
pool, redis, kdb, shutdown, host, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, marketplaces, pluginImport, bus,
|
|
129
131
|
// the producers closed on every role (their consumers are the worker role's)
|
|
130
|
-
usageReport, titles, channelJobs, channelOutbound,
|
|
132
|
+
usageReport, titles, suggestions, channelJobs, channelOutbound,
|
|
131
133
|
// this process's presence beat, on every role (admin overview spec §5.1)
|
|
132
134
|
presence,
|
|
133
135
|
// The role modules' parts: a role module is imported only when `roles` names it, so each is
|
|
@@ -154,6 +156,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
154
156
|
this.bus = bus;
|
|
155
157
|
this.usageReport = usageReport;
|
|
156
158
|
this.titles = titles;
|
|
159
|
+
this.suggestions = suggestions;
|
|
157
160
|
this.channelJobs = channelJobs;
|
|
158
161
|
this.channelOutbound = channelOutbound;
|
|
159
162
|
this.presence = presence;
|
|
@@ -468,6 +471,8 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
468
471
|
await within("maintenance", worker?.closeMaintenance() ?? Promise.resolve(), Math.max(0, runsDeadline - Date.now()));
|
|
469
472
|
// titles before usage.report: a finishing title call enqueues its usage report
|
|
470
473
|
await within("titles", this.titles.stop(), Math.max(0, runsDeadline - Date.now()));
|
|
474
|
+
// prompt suggestions likewise: the call in flight is aborted and its job dropped
|
|
475
|
+
await within("prompt-suggestions", this.suggestions.stop(), Math.max(0, runsDeadline - Date.now()));
|
|
471
476
|
// usage.report: in-flight deliveries are aborted and retried by any replica; before the plugins close
|
|
472
477
|
await within("usage-report", this.usageReport.stop(), Math.max(0, runsDeadline - Date.now()));
|
|
473
478
|
// 出站投递:进行中的任务交还队列(由其他副本从 last_seq 续投),必须在插件关闭之前
|
|
@@ -501,12 +506,13 @@ KernelLifecycle = __decorate([
|
|
|
501
506
|
__param(18, Inject(KERNEL_BUS)),
|
|
502
507
|
__param(19, Inject(UsageReporter)),
|
|
503
508
|
__param(20, Inject(TitleQueue)),
|
|
504
|
-
__param(21, Inject(
|
|
505
|
-
__param(22, Inject(
|
|
506
|
-
__param(23, Inject(
|
|
507
|
-
__param(24,
|
|
508
|
-
__param(24, Inject(WorkerRole)),
|
|
509
|
+
__param(21, Inject(PromptSuggestionQueue)),
|
|
510
|
+
__param(22, Inject(ChannelJobs)),
|
|
511
|
+
__param(23, Inject(ChannelOutbound)),
|
|
512
|
+
__param(24, Inject(ReplicaPresence)),
|
|
509
513
|
__param(25, Optional()),
|
|
510
|
-
__param(25, Inject(
|
|
514
|
+
__param(25, Inject(WorkerRole)),
|
|
515
|
+
__param(26, Optional()),
|
|
516
|
+
__param(26, Inject(GatewayRole))
|
|
511
517
|
], KernelLifecycle);
|
|
512
518
|
export { KernelLifecycle };
|
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
2
3
|
import { type ProviderRegistry } from "../runtime/providers.js";
|
|
3
4
|
import type { StorageService } from "../storage/storage.service.js";
|
|
4
5
|
import type { ModelPurposesService } from "./purposes.js";
|
|
5
6
|
/** The model purpose `GenerateImage` calls (image generation spec §5.4; no fallback). */
|
|
6
7
|
export declare const IMAGE_PURPOSE = "image";
|
|
7
|
-
/**
|
|
8
|
-
export
|
|
8
|
+
/** The image counts one call may ask for in an org: the config cap and the model's own limits. */
|
|
9
|
+
export interface ImageInputCaps {
|
|
10
|
+
maxImages: number;
|
|
11
|
+
maxReferenceImages: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The one place the effective counts are decided (the tool's listed schema and
|
|
15
|
+
* `ModelImages.prepare`'s refusals both read it): images per call are the lower of
|
|
16
|
+
* `models.imageMaxPerCall` and the model's `maxImages`; reference images are the model's own.
|
|
17
|
+
*/
|
|
18
|
+
export declare function imageInputCaps(limits: {
|
|
19
|
+
imageMaxPerCall: number;
|
|
20
|
+
}, gen: {
|
|
21
|
+
maxImages: number;
|
|
22
|
+
maxReferenceImages: number;
|
|
23
|
+
}): ImageInputCaps;
|
|
24
|
+
/** Whether `GenerateImage` can run in an org now (with the counts it accepts), or why not. */
|
|
25
|
+
export type ImagePurposeState = ({
|
|
26
|
+
usable: "usable";
|
|
27
|
+
} & ImageInputCaps) | {
|
|
28
|
+
usable: "no-model" | "no-storage";
|
|
29
|
+
};
|
|
9
30
|
/**
|
|
10
31
|
* The one predicate of `GenerateImage`'s availability (image generation spec §5.3), shared by the
|
|
11
32
|
* tool's listing and the member-readable purpose availability the agent form reads, so the two
|
|
12
33
|
* never disagree: the org's `image` purpose resolves to an image model the org can call now (an
|
|
13
34
|
* unmapped, disabled or unavailable model, or a provider whose model list fails, is `no-model`),
|
|
14
|
-
* and an object store is there to deliver the images (`no-storage`).
|
|
15
|
-
* and rethrown: it is a kernel
|
|
35
|
+
* and an object store is there to deliver the images (`no-storage`). A usable state carries the
|
|
36
|
+
* effective {@link ImageInputCaps}. Any other failure is logged and rethrown: it is a kernel
|
|
37
|
+
* fault, not an unavailable model. `memo` (one listing) keeps the answer for the listing's
|
|
38
|
+
* `unavailable` and `specFor` calls.
|
|
16
39
|
*/
|
|
17
|
-
export declare function
|
|
40
|
+
export declare function imagePurposeState(deps: {
|
|
18
41
|
purposes: Pick<ModelPurposesService, "resolve">;
|
|
19
42
|
providers: Pick<ProviderRegistry, "resolve">;
|
|
20
43
|
storage: Pick<StorageService, "available">;
|
|
21
44
|
log: Pick<Logger, "warn">;
|
|
22
|
-
|
|
45
|
+
config: Pick<KernelConfigService, "get">;
|
|
46
|
+
}, orgId: string, memo?: Map<string, unknown>): Promise<ImagePurposeState>;
|
|
@@ -2,28 +2,59 @@ import { ApiError } from "../errors.js";
|
|
|
2
2
|
import { ProviderListError } from "../runtime/providers.js";
|
|
3
3
|
/** The model purpose `GenerateImage` calls (image generation spec §5.4; no fallback). */
|
|
4
4
|
export const IMAGE_PURPOSE = "image";
|
|
5
|
+
/**
|
|
6
|
+
* The one place the effective counts are decided (the tool's listed schema and
|
|
7
|
+
* `ModelImages.prepare`'s refusals both read it): images per call are the lower of
|
|
8
|
+
* `models.imageMaxPerCall` and the model's `maxImages`; reference images are the model's own.
|
|
9
|
+
*/
|
|
10
|
+
export function imageInputCaps(limits, gen) {
|
|
11
|
+
return {
|
|
12
|
+
maxImages: Math.min(limits.imageMaxPerCall, gen.maxImages),
|
|
13
|
+
maxReferenceImages: gen.maxReferenceImages,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const MEMO_KEY = "image-purpose-state";
|
|
5
17
|
/**
|
|
6
18
|
* The one predicate of `GenerateImage`'s availability (image generation spec §5.3), shared by the
|
|
7
19
|
* tool's listing and the member-readable purpose availability the agent form reads, so the two
|
|
8
20
|
* never disagree: the org's `image` purpose resolves to an image model the org can call now (an
|
|
9
21
|
* unmapped, disabled or unavailable model, or a provider whose model list fails, is `no-model`),
|
|
10
|
-
* and an object store is there to deliver the images (`no-storage`).
|
|
11
|
-
* and rethrown: it is a kernel
|
|
22
|
+
* and an object store is there to deliver the images (`no-storage`). A usable state carries the
|
|
23
|
+
* effective {@link ImageInputCaps}. Any other failure is logged and rethrown: it is a kernel
|
|
24
|
+
* fault, not an unavailable model. `memo` (one listing) keeps the answer for the listing's
|
|
25
|
+
* `unavailable` and `specFor` calls.
|
|
12
26
|
*/
|
|
13
|
-
export
|
|
27
|
+
export function imagePurposeState(deps, orgId, memo) {
|
|
28
|
+
const key = `${MEMO_KEY}:${orgId}`;
|
|
29
|
+
const known = memo?.get(key);
|
|
30
|
+
if (known !== undefined)
|
|
31
|
+
return known;
|
|
32
|
+
const state = compute(deps, orgId);
|
|
33
|
+
memo?.set(key, state);
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
async function compute(deps, orgId) {
|
|
37
|
+
let gen;
|
|
14
38
|
try {
|
|
15
39
|
const target = await deps.purposes.resolve(orgId, IMAGE_PURPOSE);
|
|
16
|
-
await deps.providers.resolve(orgId, target.model, {
|
|
40
|
+
const { info } = await deps.providers.resolve(orgId, target.model, {
|
|
41
|
+
kind: "image_generation",
|
|
42
|
+
});
|
|
43
|
+
gen = info.imageGeneration;
|
|
17
44
|
}
|
|
18
45
|
catch (e) {
|
|
19
46
|
if (e instanceof ProviderListError)
|
|
20
|
-
return "no-model";
|
|
47
|
+
return { usable: "no-model" };
|
|
21
48
|
if (e instanceof ApiError &&
|
|
22
49
|
(e.code === "model.unconfigured" || e.code === "agent.model_unavailable")) {
|
|
23
|
-
return "no-model";
|
|
50
|
+
return { usable: "no-model" };
|
|
24
51
|
}
|
|
25
52
|
deps.log.warn("image purpose availability check failed", { orgId, err: e });
|
|
26
53
|
throw e;
|
|
27
54
|
}
|
|
28
|
-
|
|
55
|
+
if (gen === undefined)
|
|
56
|
+
return { usable: "no-model" };
|
|
57
|
+
if (!deps.storage.available)
|
|
58
|
+
return { usable: "no-storage" };
|
|
59
|
+
return { usable: "usable", ...imageInputCaps(deps.config.get().models, gen) };
|
|
29
60
|
}
|
package/dist/models/images.js
CHANGED
|
@@ -21,6 +21,7 @@ import { base64Bytes, fireObserve, imageDeniedAudit, } from "../runtime/hook-cal
|
|
|
21
21
|
import { modelDeniedText } from "../runtime/model-call.js";
|
|
22
22
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
23
23
|
import { UsageReportJobs } from "../runtime/usage-report-jobs.js";
|
|
24
|
+
import { imageInputCaps } from "./image-usable.js";
|
|
24
25
|
import { ModelPurposesService } from "./purposes.js";
|
|
25
26
|
/** Standard padded base64 (the check `validateImageGenerateResult` applies to results). */
|
|
26
27
|
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
@@ -223,17 +224,18 @@ let ModelImages = class ModelImages {
|
|
|
223
224
|
// the registry refuses such models; kept as a guard
|
|
224
225
|
throw new ApiError("model.unconfigured", `The model configured for the "${purpose}" purpose cannot generate images`);
|
|
225
226
|
}
|
|
226
|
-
const
|
|
227
|
+
const caps = imageInputCaps(limits, gen);
|
|
228
|
+
const cap = caps.maxImages;
|
|
227
229
|
const n = input.n ?? 1;
|
|
228
230
|
if (!Number.isInteger(n) || n < 1)
|
|
229
231
|
bad(`n must be a whole number from 1 to ${cap}`);
|
|
230
232
|
if (n > cap)
|
|
231
233
|
bad(`n must be at most ${cap} for this model`);
|
|
232
234
|
const refs = input.referenceImages ?? [];
|
|
233
|
-
if (refs.length >
|
|
234
|
-
bad(
|
|
235
|
+
if (refs.length > caps.maxReferenceImages) {
|
|
236
|
+
bad(caps.maxReferenceImages === 0
|
|
235
237
|
? "this model takes no reference images"
|
|
236
|
-
: `this model takes at most ${
|
|
238
|
+
: `this model takes at most ${caps.maxReferenceImages} reference images`);
|
|
237
239
|
}
|
|
238
240
|
refs.forEach((r, i) => {
|
|
239
241
|
const okType = IMAGE_MEDIA_TYPES.includes(r?.mediaType);
|
|
@@ -175,7 +175,7 @@ export declare class ModelPurposesService {
|
|
|
175
175
|
* Whether each purpose (kernel and extension-declared) resolves to a usable model for the org
|
|
176
176
|
* now, as {@link resolve} decides, without naming the model (the agent form's gate for
|
|
177
177
|
* `GenerateImage`, readable by every member). The `image` purpose reads `GenerateImage`'s own
|
|
178
|
-
* predicate ({@link
|
|
178
|
+
* predicate ({@link imagePurposeState}: an image model callable now and an object store).
|
|
179
179
|
*/
|
|
180
180
|
availability(orgId: string): Promise<{
|
|
181
181
|
purpose: string;
|
package/dist/models/purposes.js
CHANGED
|
@@ -26,7 +26,7 @@ import { estimateTokens } from "../runtime/context/tokens.js";
|
|
|
26
26
|
import { consumeModelStream } from "../runtime/model-call.js";
|
|
27
27
|
import { ProviderListError, ProviderRegistry } from "../runtime/providers.js";
|
|
28
28
|
import { StorageService } from "../storage/storage.service.js";
|
|
29
|
-
import { IMAGE_PURPOSE,
|
|
29
|
+
import { IMAGE_PURPOSE, imagePurposeState } from "./image-usable.js";
|
|
30
30
|
/**
|
|
31
31
|
* Purposes the kernel declares: the eval judge, and the three sub-agent model tiers (phase C,
|
|
32
32
|
* spec §5.4: `fast` / `standard` / `capable` → `subagent_<tier>`; an unmapped tier runs on the
|
|
@@ -201,15 +201,21 @@ let ModelPurposesService = class ModelPurposesService {
|
|
|
201
201
|
* Whether each purpose (kernel and extension-declared) resolves to a usable model for the org
|
|
202
202
|
* now, as {@link resolve} decides, without naming the model (the agent form's gate for
|
|
203
203
|
* `GenerateImage`, readable by every member). The `image` purpose reads `GenerateImage`'s own
|
|
204
|
-
* predicate ({@link
|
|
204
|
+
* predicate ({@link imagePurposeState}: an image model callable now and an object store).
|
|
205
205
|
*/
|
|
206
206
|
async availability(orgId) {
|
|
207
207
|
const out = [];
|
|
208
208
|
for (const d of this.declared()) {
|
|
209
209
|
if (d.purpose === IMAGE_PURPOSE) {
|
|
210
210
|
// `GenerateImage`'s own predicate: the form offers the tool exactly when it is listed
|
|
211
|
-
const
|
|
212
|
-
|
|
211
|
+
const state = await imagePurposeState({
|
|
212
|
+
purposes: this,
|
|
213
|
+
providers: this.providers,
|
|
214
|
+
storage: this.storage,
|
|
215
|
+
log: this.log,
|
|
216
|
+
config: this.config,
|
|
217
|
+
}, orgId);
|
|
218
|
+
out.push({ purpose: d.purpose, available: state.usable === "usable" });
|
|
213
219
|
continue;
|
|
214
220
|
}
|
|
215
221
|
const available = await this.resolve(orgId, d.purpose).then(() => true, (e) => {
|
|
@@ -123,6 +123,8 @@ export declare const GIT_GATEWAY_INVALID: {
|
|
|
123
123
|
readonly enabled: false;
|
|
124
124
|
};
|
|
125
125
|
export type GitGatewaySetting = z.infer<typeof GitGatewaySettingSchema>;
|
|
126
|
+
/** Whether prompt suggestions run for an org: the platform is on and the org has not turned it off. */
|
|
127
|
+
export declare function effectivePromptSuggestions(platform: "on" | "off", org: "on" | "off" | undefined): boolean;
|
|
126
128
|
export declare const OrgSettingsSchema: z.ZodObject<{
|
|
127
129
|
toolSearch: z.ZodCatch<z.ZodDefault<z.ZodEnum<{
|
|
128
130
|
off: "off";
|
|
@@ -197,6 +199,10 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
197
199
|
off: "off";
|
|
198
200
|
on: "on";
|
|
199
201
|
}>>>;
|
|
202
|
+
promptSuggestions: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
|
|
203
|
+
off: "off";
|
|
204
|
+
on: "on";
|
|
205
|
+
}>>>;
|
|
200
206
|
}, z.core.$strip>;
|
|
201
207
|
export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
|
|
202
208
|
/**
|
|
@@ -287,6 +293,10 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
287
293
|
off: "off";
|
|
288
294
|
on: "on";
|
|
289
295
|
}>>>;
|
|
296
|
+
promptSuggestions: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
297
|
+
off: "off";
|
|
298
|
+
on: "on";
|
|
299
|
+
}>>>;
|
|
290
300
|
}, z.core.$strict>;
|
|
291
301
|
export type OrgSettingsPatch = z.infer<typeof OrgSettingsPatchSchema>;
|
|
292
302
|
/** A patch with the old `autoMode` moved to `fullAccess` (the schema refuses both together). */
|
|
@@ -347,6 +357,8 @@ export interface OrgSettingsDeployment {
|
|
|
347
357
|
externalSharing: ExternalSharingView;
|
|
348
358
|
/** The longest expiry a share may take, in days. */
|
|
349
359
|
shareMaxExpiryDays: number;
|
|
360
|
+
/** The platform's prompt suggestions switch (off: the org's own switch has no effect). */
|
|
361
|
+
promptSuggestions: "on" | "off";
|
|
350
362
|
}
|
|
351
363
|
/**
|
|
352
364
|
* Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). Until 8.6 `fullAccess` is read
|
|
@@ -383,6 +395,8 @@ export declare const FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR = "The organization'
|
|
|
383
395
|
export declare function logUnreadableSecuritySettings(log: (msg: string, fields: Record<string, unknown>) => void, orgId: string, raw: unknown): void;
|
|
384
396
|
/** Whether a stored settings object holds an `externalSharing` this version reads as `off`. */
|
|
385
397
|
export declare function invalidStoredExternalSharing(raw: unknown): boolean;
|
|
398
|
+
/** Whether a stored settings object holds a `promptSuggestions` this version reads as `off`. */
|
|
399
|
+
export declare function invalidStoredPromptSuggestions(raw: unknown): boolean;
|
|
386
400
|
/** Whether a stored settings object holds a `fullAccess` this version reads as `off`. */
|
|
387
401
|
export declare function invalidStoredFullAccess(raw: unknown): boolean;
|
|
388
402
|
/** Whether a stored settings object holds a `cloudNetwork` this version reads as an empty allowlist. */
|
|
@@ -419,6 +433,8 @@ export declare class OrgSettingsService {
|
|
|
419
433
|
private parseStored;
|
|
420
434
|
/** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
|
|
421
435
|
deployment(): Promise<OrgSettingsDeployment>;
|
|
436
|
+
/** Whether prompt suggestions run for the org now: one read of the platform and of the org. */
|
|
437
|
+
promptSuggestionsEnabled(orgId: string): Promise<boolean>;
|
|
422
438
|
/**
|
|
423
439
|
* The org's effective sandbox-mode network (spec §D3): the cloud network's mode and the hosts,
|
|
424
440
|
* from the platform's `sandbox.limits` and the org's stored delta.
|