@capybara-hq/kernel 0.1.0-rc.35 → 0.1.0-rc.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +8 -19
- package/dist/agents/readiness.controller.js +11 -25
- package/dist/agents/readiness.service.d.ts +42 -0
- package/dist/agents/readiness.service.js +78 -0
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.d.ts +3 -3
- package/dist/platform/ops/agents.ops.js +7 -10
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -26,13 +26,18 @@ import { IanaTimeZone } from "../time-zone.js";
|
|
|
26
26
|
import { mergeArrangement, OrgUiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
|
|
27
27
|
import { OrgLock, OrgLockModule } from "./org-lock.js";
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* - `
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
29
|
+
* Org settings (`capybara.orgs.settings` jsonb). Read leniently: a missing or invalid field reads
|
|
30
|
+
* as its default and unknown keys are kept (merged with the stored value on update), so a new
|
|
31
|
+
* field needs no migration.
|
|
32
|
+
* - `toolSearch`: whether to switch to a catalog + `ToolSearch` once the tools pass the threshold
|
|
33
|
+
* (D11, default on).
|
|
34
|
+
* - `locale`: the org's default language (`zh` / `en`, default en); the bot's fixed phrases in IM
|
|
35
|
+
* follow it.
|
|
36
|
+
* - `sandboxToolPolicy`: the default policy of the sandbox tools (M5 T8, default allow). With
|
|
37
|
+
* `ask`, every tool but the read-only `Read` / `Glob` / `Grep` needs approval (read live at
|
|
38
|
+
* execution). An invalid stored value reads as `ask` (narrower, never wider) and is logged.
|
|
39
|
+
* - `wakeOnBackgroundTask`: the org's override of `runtime.wakeOnBackgroundTask` (absent follows
|
|
40
|
+
* the deployment), see {@link effectiveWakeOnBackgroundTask}.
|
|
36
41
|
* - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
|
|
37
42
|
* follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
|
|
38
43
|
* (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
|
|
@@ -118,7 +123,9 @@ const posInt = (max, def) => z.number().int().min(1).max(max).default(def).catch
|
|
|
118
123
|
const isForbiddenToolEntry = (v) => typeof v === "string" && v.length >= 1 && v.length <= 200;
|
|
119
124
|
/**
|
|
120
125
|
* Org settings of scheduled tasks (spec §9); every field reads leniently (invalid = default,
|
|
121
|
-
* except `forbiddenTools`, which keeps its valid entries).
|
|
126
|
+
* except `forbiddenTools`, which keeps its valid entries). A stored `forbiddenTools` that is not a
|
|
127
|
+
* list (or a group that is not an object) reads as `[]` here, for display; enforcement checks
|
|
128
|
+
* {@link invalidStoredForbiddenTools} and fails unattended runs instead (never wider).
|
|
122
129
|
*/
|
|
123
130
|
export const ScheduledTasksSettingsSchema = z.object({
|
|
124
131
|
enabled: z.boolean().default(true).catch(true),
|
|
@@ -170,7 +177,8 @@ export const GIT_GATEWAY_INVALID = { enabled: false };
|
|
|
170
177
|
export const OrgSettingsSchema = z.object({
|
|
171
178
|
toolSearch: z.enum(["on", "off"]).default("on").catch("on"),
|
|
172
179
|
locale: z.enum(["zh", "en"]).default("en").catch("en"),
|
|
173
|
-
|
|
180
|
+
/** Absent = `allow`; an invalid stored value reads as `ask` (narrower, never wider). */
|
|
181
|
+
sandboxToolPolicy: z.enum(["allow", "ask"]).default("allow").catch("ask"),
|
|
174
182
|
platformTool: z.enum(["on", "read-only", "off"]).default("on").catch("on"),
|
|
175
183
|
/** The org's auto-mode switch (auto mode spec §4.3); absent follows the platform. */
|
|
176
184
|
autoMode: AutoModeSetting.optional().catch("off"),
|
|
@@ -194,6 +202,13 @@ export const OrgSettingsSchema = z.object({
|
|
|
194
202
|
*/
|
|
195
203
|
compaction: COMPACTION_SETTINGS_PARTIAL.optional().catch(undefined),
|
|
196
204
|
});
|
|
205
|
+
/** {@link OrgSettingsView} of `settings`, flagged from the stored value `raw`. */
|
|
206
|
+
const viewOf = (settings, raw) => invalidStoredForbiddenTools(raw)
|
|
207
|
+
? {
|
|
208
|
+
...settings,
|
|
209
|
+
scheduledTasks: { ...settings.scheduledTasks, forbiddenToolsUnreadable: true },
|
|
210
|
+
}
|
|
211
|
+
: settings;
|
|
197
212
|
/** PATCH 体:只改给出的字段;未知字段 → 400。 */
|
|
198
213
|
export const OrgSettingsPatchSchema = z
|
|
199
214
|
.object({
|
|
@@ -259,15 +274,65 @@ const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v)
|
|
|
259
274
|
export function parseOrgSettings(raw) {
|
|
260
275
|
return OrgSettingsSchema.parse(asObject(raw));
|
|
261
276
|
}
|
|
262
|
-
/**
|
|
263
|
-
export async function
|
|
277
|
+
/** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
|
|
278
|
+
export async function readStoredOrgSettings(db, orgId) {
|
|
264
279
|
const row = await db
|
|
265
280
|
.selectFrom("orgs")
|
|
266
281
|
.select("settings")
|
|
267
282
|
.where("id", "=", orgId)
|
|
268
283
|
.where("deleted_at", "is", null)
|
|
269
284
|
.executeTakeFirst();
|
|
270
|
-
return
|
|
285
|
+
return row?.settings;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Reads the org settings (live from PG every time, so a change applies at once across replicas);
|
|
289
|
+
* a missing or deleted org reads as the defaults. With `log`, an
|
|
290
|
+
* unreadable security setting ({@link logUnreadableSecuritySettings}) is logged.
|
|
291
|
+
*/
|
|
292
|
+
export async function readOrgSettings(db, orgId,
|
|
293
|
+
/** Per-call paths (the tool policy) log at debug; the settings reads and the fire warn. */
|
|
294
|
+
log) {
|
|
295
|
+
const raw = await readStoredOrgSettings(db, orgId);
|
|
296
|
+
if (log !== undefined) {
|
|
297
|
+
logUnreadableSecuritySettings((msg, f) => log.debug(msg, f), orgId, raw);
|
|
298
|
+
}
|
|
299
|
+
return parseOrgSettings(raw);
|
|
300
|
+
}
|
|
301
|
+
/** Whether a stored settings object holds a `sandboxToolPolicy` this version reads as `ask`. */
|
|
302
|
+
export function invalidStoredSandboxToolPolicy(raw) {
|
|
303
|
+
const v = asObject(raw).sandboxToolPolicy;
|
|
304
|
+
return v !== undefined && !OrgSettingsPatchSchema.shape.sandboxToolPolicy.safeParse(v).success;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Whether the stored scheduled-task `forbiddenTools` cannot be read: the group or the field is
|
|
308
|
+
* present but not an object / a list. Unattended runs of such an org fail
|
|
309
|
+
* ({@link FORBIDDEN_TOOLS_UNREADABLE_ERROR}) rather than run with nothing forbidden. Invalid
|
|
310
|
+
* entries inside a list are dropped instead (the valid ones stay forbidden).
|
|
311
|
+
*/
|
|
312
|
+
export function invalidStoredForbiddenTools(raw) {
|
|
313
|
+
const group = asObject(raw).scheduledTasks;
|
|
314
|
+
if (group === undefined)
|
|
315
|
+
return false;
|
|
316
|
+
if (group === null || typeof group !== "object" || Array.isArray(group))
|
|
317
|
+
return true;
|
|
318
|
+
const v = group.forbiddenTools;
|
|
319
|
+
return v !== undefined && !Array.isArray(v);
|
|
320
|
+
}
|
|
321
|
+
/** The refusal of an unattended run of an org whose `forbiddenTools` cannot be read. */
|
|
322
|
+
export const FORBIDDEN_TOOLS_UNREADABLE_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so this scheduled run cannot continue; an org admin must save the list again in the organization's scheduled task settings.";
|
|
323
|
+
/** The refusal of a new task grant while the org's `forbiddenTools` cannot be read. */
|
|
324
|
+
export const FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so no tool can be approved for a task now; an org admin must save the list again in the organization's scheduled task settings.";
|
|
325
|
+
/**
|
|
326
|
+
* Logs (through `log`, at the caller's level) the security settings a stored value reads narrower
|
|
327
|
+
* than written, with the org id.
|
|
328
|
+
*/
|
|
329
|
+
export function logUnreadableSecuritySettings(log, orgId, raw) {
|
|
330
|
+
if (invalidStoredSandboxToolPolicy(raw)) {
|
|
331
|
+
log("org settings: stored sandboxToolPolicy is invalid; it reads as ask", { orgId });
|
|
332
|
+
}
|
|
333
|
+
if (invalidStoredForbiddenTools(raw)) {
|
|
334
|
+
log("org settings: stored scheduledTasks.forbiddenTools is unreadable; unattended runs fail until an org admin saves it again", { orgId });
|
|
335
|
+
}
|
|
271
336
|
}
|
|
272
337
|
const autoModeNotAllowed = (message) => new ApiError("org.auto_mode_not_allowed", message);
|
|
273
338
|
/** Whether a stored settings object holds an `autoMode` this version reads as `off`. */
|
|
@@ -321,8 +386,9 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
321
386
|
this.config = config;
|
|
322
387
|
this.log = log;
|
|
323
388
|
}
|
|
324
|
-
/** Parses stored settings, warning when an invalid `autoMode` narrows to `off
|
|
325
|
-
* `cloudNetwork` to an empty allowlist
|
|
389
|
+
/** Parses stored settings, warning when an invalid `autoMode` narrows to `off`, an invalid
|
|
390
|
+
* `cloudNetwork` to an empty allowlist, or a security setting reads narrower
|
|
391
|
+
* ({@link logUnreadableSecuritySettings}, warn). */
|
|
326
392
|
parseStored(orgId, raw) {
|
|
327
393
|
if (invalidStoredAutoMode(raw)) {
|
|
328
394
|
this.log?.warn("org settings: stored autoMode is invalid; it reads as off", { orgId });
|
|
@@ -332,6 +398,9 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
332
398
|
orgId,
|
|
333
399
|
});
|
|
334
400
|
}
|
|
401
|
+
const log = this.log;
|
|
402
|
+
if (log !== undefined)
|
|
403
|
+
logUnreadableSecuritySettings((m, f) => log.warn(m, f), orgId, raw);
|
|
335
404
|
return parseOrgSettings(raw);
|
|
336
405
|
}
|
|
337
406
|
/** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
|
|
@@ -384,7 +453,7 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
384
453
|
.executeTakeFirst();
|
|
385
454
|
if (!row)
|
|
386
455
|
throw new ApiError("org.not_found", "Organization not found");
|
|
387
|
-
return this.parseStored(orgId, row.settings);
|
|
456
|
+
return viewOf(this.parseStored(orgId, row.settings), row.settings);
|
|
388
457
|
}
|
|
389
458
|
/**
|
|
390
459
|
* The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
|
|
@@ -518,8 +587,11 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
518
587
|
}
|
|
519
588
|
if (after.compaction === undefined)
|
|
520
589
|
delete after.compaction;
|
|
521
|
-
|
|
522
|
-
|
|
590
|
+
// saving an unreadable security setting writes it even when it equals what it read as
|
|
591
|
+
const repairs = (invalidStoredForbiddenTools(stored) && patch.scheduledTasks?.forbiddenTools !== undefined) ||
|
|
592
|
+
(invalidStoredSandboxToolPolicy(stored) && patch.sandboxToolPolicy !== undefined);
|
|
593
|
+
if (!repairs && sameSettings(before, after))
|
|
594
|
+
return viewOf(before, stored);
|
|
523
595
|
// Lock order: the org row (orgLock above), then the theme's catalog item and its row FOR
|
|
524
596
|
// SHARE (assertThemeOnIn), then the check, so no scope writer changes what it read first
|
|
525
597
|
if (patch.theme?.id != null && patch.theme.id !== before.theme?.id) {
|
|
@@ -528,9 +600,19 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
528
600
|
// Merge with the stored value: keep the keys this version does not know (a cleared autoMode /
|
|
529
601
|
// cloudNetwork is not kept)
|
|
530
602
|
const { autoMode: _oldAutoMode, cloudNetwork: _oldNetwork, wakeOnBackgroundTask: _oldWake, timeZone: _oldZone, theme: _oldTheme, uiArrangement: _oldArrangement, scheduledTasks: _oldScheduled, compaction: _oldCompaction, ...rest } = stored;
|
|
603
|
+
const written = { ...rest, ...after };
|
|
604
|
+
// An unreadable forbiddenTools reads as [] for display only: a write that does not replace the
|
|
605
|
+
// list keeps it unreadable (never healed to "nothing forbidden"); saving the list fixes it
|
|
606
|
+
if (invalidStoredForbiddenTools(stored) && patch.scheduledTasks?.forbiddenTools === undefined) {
|
|
607
|
+
const group = asObject(stored.scheduledTasks);
|
|
608
|
+
written.scheduledTasks = {
|
|
609
|
+
...after.scheduledTasks,
|
|
610
|
+
forbiddenTools: group.forbiddenTools ?? null,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
531
613
|
await this.db
|
|
532
614
|
.updateTable("orgs")
|
|
533
|
-
.set({ settings: JSON.stringify(
|
|
615
|
+
.set({ settings: JSON.stringify(written) })
|
|
534
616
|
.where("id", "=", orgId)
|
|
535
617
|
.execute();
|
|
536
618
|
await audit(this.db.db, {
|
|
@@ -539,9 +621,9 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
539
621
|
orgId,
|
|
540
622
|
action: "org.settings_updated",
|
|
541
623
|
target: orgId,
|
|
542
|
-
detail: { before, after, ...auditDetail },
|
|
624
|
+
detail: { before, after, ...(repairs && { repaired: true }), ...auditDetail },
|
|
543
625
|
});
|
|
544
|
-
return after;
|
|
626
|
+
return viewOf(after, written);
|
|
545
627
|
}
|
|
546
628
|
};
|
|
547
629
|
__decorate([
|
package/dist/overrides.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NestInterceptor } from "@nestjs/common";
|
|
2
2
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
3
3
|
import { ADMIN_USAGE_TIMINGS, type AdminUsageTimings } from "./admin/usage.service.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
|
|
5
5
|
import { CHANNEL_WEBHOOK_TIMINGS, type ChannelWebhookTimings } from "./channels/webhook.js";
|
|
6
6
|
import type { EvalReplayHooks } from "./evals/run-replay.js";
|
|
7
7
|
import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
|
|
@@ -13,7 +13,6 @@ import { GIT_IDENTITY_API_BASE, type GitIdentityApiBase } from "./git/identity.j
|
|
|
13
13
|
import { PLUGIN_PUBLIC_WRITE_LIMIT } from "./http/plugin-route-access.js";
|
|
14
14
|
import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
|
|
15
15
|
import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
|
|
16
|
-
import { OUTBOX_STRICT_CONFLICTS } from "./infra/outbox/outbox.service.js";
|
|
17
16
|
import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
|
|
18
17
|
import type { KernelQueueName } from "./infra/queue/queue-names.js";
|
|
19
18
|
import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
|
|
@@ -46,8 +45,6 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
|
46
45
|
* `CurrentTime` builtin the time;
|
|
47
46
|
* - `GIT_IDENTITY_API_BASE`: the API base of a git host for the commit identity (a loopback fake);
|
|
48
47
|
* - `GIT_UPSTREAM_ORIGIN`: the origin the git gateway relays a git host to (a loopback fake);
|
|
49
|
-
* - `OUTBOX_STRICT_CONFLICTS`: a reused outbox job id with different data throws (tests) instead
|
|
50
|
-
* of logging an error;
|
|
51
48
|
* - `OUTBOX_DISPATCH_FAILS`: returns true to make the outbox dispatcher's adds to the given queue
|
|
52
49
|
* fail (a Redis outage);
|
|
53
50
|
* - `USAGE_SUBSCRIBERS_CLOCK`: the clock the `usage.report` subscriber cache ages with;
|
|
@@ -59,7 +56,7 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
|
59
56
|
* - `PROJECT_KNOWLEDGE_TIMEOUT`: the run-start read of a bound project's time limit, read at every
|
|
60
57
|
* read (a test shortens it for one run);
|
|
61
58
|
* - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
|
|
62
|
-
* - `
|
|
59
|
+
* - `SCOPE_ORG_CHUNK_SIZE`: fewer orgs per plugin scope sync chunk job (several chunks in a test);
|
|
63
60
|
* - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes).
|
|
64
61
|
*/
|
|
65
62
|
interface KernelSeams {
|
|
@@ -80,12 +77,11 @@ interface KernelSeams {
|
|
|
80
77
|
[RUN_CONTEXT_CLOCK]: () => number;
|
|
81
78
|
[GIT_IDENTITY_API_BASE]: GitIdentityApiBase;
|
|
82
79
|
[GIT_UPSTREAM_ORIGIN]: GitUpstreamOrigin;
|
|
83
|
-
[OUTBOX_STRICT_CONFLICTS]: boolean;
|
|
84
80
|
[OUTBOX_DISPATCH_FAILS]: (queue: KernelQueueName) => boolean;
|
|
85
81
|
[USAGE_SUBSCRIBERS_CLOCK]: () => number;
|
|
86
82
|
[OUTBOX_FAST_PATH_SETTLED]: (pass: Promise<void>) => void;
|
|
87
83
|
[ENSURE_RUN_FAILS]: () => boolean;
|
|
88
|
-
[
|
|
84
|
+
[SCOPE_ORG_CHUNK_SIZE]: number;
|
|
89
85
|
[PROJECT_KNOWLEDGE_TIMEOUT]: () => number;
|
|
90
86
|
[PLUGIN_PUBLIC_WRITE_LIMIT]: number;
|
|
91
87
|
[DEVICE_POLICY_AFTER_CALL]: (opId: string) => void;
|
package/dist/overrides.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
2
2
|
import { ADMIN_USAGE_TIMINGS } from "./admin/usage.service.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
|
|
4
4
|
import { CHANNEL_WEBHOOK_TIMINGS } from "./channels/webhook.js";
|
|
5
5
|
import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
|
|
6
6
|
import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
|
|
@@ -11,7 +11,6 @@ import { GIT_IDENTITY_API_BASE } from "./git/identity.js";
|
|
|
11
11
|
import { PLUGIN_PUBLIC_WRITE_LIMIT } from "./http/plugin-route-access.js";
|
|
12
12
|
import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
|
|
13
13
|
import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
|
|
14
|
-
import { OUTBOX_STRICT_CONFLICTS } from "./infra/outbox/outbox.service.js";
|
|
15
14
|
import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
|
|
16
15
|
import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
|
|
17
16
|
import { PROJECT_KNOWLEDGE_TIMEOUT } from "./runtime/project/knowledge.service.js";
|
|
@@ -44,11 +43,10 @@ const SEAM_TOKENS = [
|
|
|
44
43
|
RUN_CONTEXT_CLOCK,
|
|
45
44
|
GIT_IDENTITY_API_BASE,
|
|
46
45
|
GIT_UPSTREAM_ORIGIN,
|
|
47
|
-
OUTBOX_STRICT_CONFLICTS,
|
|
48
46
|
OUTBOX_DISPATCH_FAILS,
|
|
49
47
|
OUTBOX_FAST_PATH_SETTLED,
|
|
50
48
|
ENSURE_RUN_FAILS,
|
|
51
|
-
|
|
49
|
+
SCOPE_ORG_CHUNK_SIZE,
|
|
52
50
|
PROJECT_KNOWLEDGE_TIMEOUT,
|
|
53
51
|
PLUGIN_PUBLIC_WRITE_LIMIT,
|
|
54
52
|
DEVICE_POLICY_AFTER_CALL,
|
package/dist/packages/tgz.d.ts
CHANGED
|
@@ -34,8 +34,6 @@ export declare const PACKAGE_TGZ_LIMITS: {
|
|
|
34
34
|
* `syncPackage` links for extensions.
|
|
35
35
|
*/
|
|
36
36
|
export declare const HOST_ZOD_VERSION: string;
|
|
37
|
-
/** The message for a tgz in the pre-0.1.0 format (follows the package's name). */
|
|
38
|
-
export declare const LEGACY_FORMAT_MESSAGE = "uses the pre-0.1.0 package format (capybara section / app.yaml); repack it as a plugin with .capybara-plugin/plugin.json (pnpm pack-plugin)";
|
|
39
37
|
/** `./skills/x` → `skills/x` (manifest paths start with `./`). */
|
|
40
38
|
export declare const packagePath: (p: string) => string;
|
|
41
39
|
/** A tgz or `package.json` problem; `issues` lists them (English, shown to the admin). */
|
package/dist/packages/tgz.js
CHANGED
|
@@ -39,8 +39,6 @@ export const PACKAGE_TGZ_LIMITS = {
|
|
|
39
39
|
* `syncPackage` links for extensions.
|
|
40
40
|
*/
|
|
41
41
|
export const HOST_ZOD_VERSION = createRequire(import.meta.url)("zod/package.json").version;
|
|
42
|
-
/** The message for a tgz in the pre-0.1.0 format (follows the package's name). */
|
|
43
|
-
export const LEGACY_FORMAT_MESSAGE = "uses the pre-0.1.0 package format (capybara section / app.yaml); repack it as a plugin with .capybara-plugin/plugin.json (pnpm pack-plugin)";
|
|
44
42
|
/** `./skills/x` → `skills/x` (manifest paths start with `./`). */
|
|
45
43
|
export const packagePath = (p) => p.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
46
44
|
/** A tgz or `package.json` problem; `issues` lists them (English, shown to the admin). */
|
|
@@ -339,11 +339,6 @@ export const PLATFORM_EXCLUSIONS = [
|
|
|
339
339
|
category: "internal",
|
|
340
340
|
reason: "Deprecated message queue the web no longer uses; leftover items drain until the table is dropped",
|
|
341
341
|
},
|
|
342
|
-
{
|
|
343
|
-
route: "POST /api/v1/orgs/:orgId/conversations/:id/queue",
|
|
344
|
-
category: "internal",
|
|
345
|
-
reason: "Deprecated alias of POST messages, which stays with the person",
|
|
346
|
-
},
|
|
347
342
|
{
|
|
348
343
|
route: "POST /api/v1/orgs/:orgId/conversations/:id/queue/resume",
|
|
349
344
|
category: "internal",
|
|
@@ -49,7 +49,7 @@ export const PLATFORM_DOMAINS = [
|
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
id: "orgs",
|
|
52
|
-
description: "This org (read, rename, members) and, for the super admin, every org and its limits.",
|
|
52
|
+
description: "This org (read, rename, members, its audit log) and, for the super admin, every org and its limits.",
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
id: "accounts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { AuditLogService } from "../../admin/audit-log.service.js";
|
|
2
3
|
import { AdminHealthService } from "../../admin/health.service.js";
|
|
3
4
|
import { AdminOverviewService } from "../../admin/overview.service.js";
|
|
4
|
-
import { PlatformAuditService } from "../../admin/platform-audit.service.js";
|
|
5
5
|
import { AdminUsageService } from "../../admin/usage.service.js";
|
|
6
6
|
import { ExtensionDisplayNames } from "../../extensions/display-name.js";
|
|
7
7
|
import { ExtensionRegistry } from "../../extensions/registry.js";
|
|
@@ -32,7 +32,7 @@ export declare class AdminOperations implements OnModuleInit {
|
|
|
32
32
|
private readonly overview;
|
|
33
33
|
private readonly health;
|
|
34
34
|
private readonly usage;
|
|
35
|
-
constructor(registry: PlatformOperations, settings: SettingsService, providers: ProviderRegistry, displayNames: ExtensionDisplayNames, extensionRegistry: ExtensionRegistry, enablement: ModelEnablement, prices: PricesService, purposes: ModelPurposesService, themes: ThemesService, audit:
|
|
35
|
+
constructor(registry: PlatformOperations, settings: SettingsService, providers: ProviderRegistry, displayNames: ExtensionDisplayNames, extensionRegistry: ExtensionRegistry, enablement: ModelEnablement, prices: PricesService, purposes: ModelPurposesService, themes: ThemesService, audit: AuditLogService, overview: AdminOverviewService, health: AdminHealthService, usage: AdminUsageService);
|
|
36
36
|
private assertProvider;
|
|
37
37
|
onModuleInit(): void;
|
|
38
38
|
}
|
|
@@ -11,10 +11,10 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { DeploymentSettingsBody, PurposeParams } from "../../admin/admin.schemas.js";
|
|
13
13
|
import { AuditListQuery } from "../../admin/audit.schemas.js";
|
|
14
|
+
import { AuditLogService } from "../../admin/audit-log.service.js";
|
|
14
15
|
import { AdminHealthService } from "../../admin/health.service.js";
|
|
15
16
|
import { UsageQuery } from "../../admin/overview.schemas.js";
|
|
16
17
|
import { AdminOverviewService } from "../../admin/overview.service.js";
|
|
17
|
-
import { PlatformAuditService } from "../../admin/platform-audit.service.js";
|
|
18
18
|
import { AdminUsageService } from "../../admin/usage.service.js";
|
|
19
19
|
import { ApiError } from "../../errors.js";
|
|
20
20
|
import { ExtensionDisplayNames } from "../../extensions/display-name.js";
|
|
@@ -154,7 +154,7 @@ let AdminOperations = class AdminOperations {
|
|
|
154
154
|
}),
|
|
155
155
|
defineOperation({
|
|
156
156
|
id: "admin.attention",
|
|
157
|
-
description: "What needs the super admin besides the platform inbox (super admin), one compact row each (kind, id, name, state, reason, next step): extensions (reason config, load_failed, approval, dependency, conflict,
|
|
157
|
+
description: "What needs the super admin besides the platform inbox (super admin), one compact row each (kind, id, name, state, reason, next step): extensions (reason config, load_failed, approval, dependency, conflict, or converging), platform plugins with a newer marketplace version (reason names both versions) model providers (reason list_failed or no_chat_model) background work the kernel could not queue (kind outbox: how many outbox rows are dead and since when) and run jobs the queue lost (kind queue: Redis lost data; the runs were queued again). Each kind lists at most 20 rows; more counts the rest per kind. unavailable names a kind that could not be read right now (try again later). The platform inbox itself is inbox.platform-list.",
|
|
158
158
|
input: z.object({}).strict(),
|
|
159
159
|
example: {},
|
|
160
160
|
authz: { superAdmin: true },
|
|
@@ -190,13 +190,16 @@ let AdminOperations = class AdminOperations {
|
|
|
190
190
|
}),
|
|
191
191
|
defineOperation({
|
|
192
192
|
id: "admin.audit",
|
|
193
|
-
description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with a personal access token), viaAgent (done through the Platform tool), action and target; never the event's details, and never an org's own events. limit is 1 to 100 (default 20); pages by keyset: pass the returned next as params.after (null: no more).",
|
|
194
|
-
|
|
193
|
+
description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with a personal access token), viaAgent (done through the Platform tool), action and target; never the event's details, and never an org's own events (an org's log is orgs.audit, in that org). action filters by an action name or its prefix (e.g. marketplace.). limit is 1 to 100 (default 20); pages by keyset: pass the returned next as params.after (null: no more).",
|
|
194
|
+
// Another org's events are never read through an agent (the conversation's org: orgs.audit).
|
|
195
|
+
// The route's `orgId` query field is left out; parity treats `orgId` as implicit (never an
|
|
196
|
+
// operation field), so it needs no `omits` entry.
|
|
197
|
+
input: AuditListQuery.omit({ orgId: true }).strict(),
|
|
195
198
|
example: { limit: 20 },
|
|
196
199
|
authz: { superAdmin: true },
|
|
197
200
|
mirrors: ["GET /api/v1/admin/audit"],
|
|
198
201
|
confirm: "read",
|
|
199
|
-
run: (input) => this.audit.list(input),
|
|
202
|
+
run: (input) => this.audit.list({ platform: true }, input),
|
|
200
203
|
}),
|
|
201
204
|
defineOperation({
|
|
202
205
|
id: "admin.settings",
|
|
@@ -538,7 +541,7 @@ AdminOperations = __decorate([
|
|
|
538
541
|
__param(6, Inject(PricesService)),
|
|
539
542
|
__param(7, Inject(ModelPurposesService)),
|
|
540
543
|
__param(8, Inject(ThemesService)),
|
|
541
|
-
__param(9, Inject(
|
|
544
|
+
__param(9, Inject(AuditLogService)),
|
|
542
545
|
__param(10, Inject(AdminOverviewService)),
|
|
543
546
|
__param(11, Inject(AdminHealthService)),
|
|
544
547
|
__param(12, Inject(AdminUsageService))
|
|
@@ -4,9 +4,9 @@ import { AgentsService } from "../../agents/agents.service.js";
|
|
|
4
4
|
import { AgentsFromTemplate } from "../../agents/from-template.service.js";
|
|
5
5
|
import { OrgAgentTemplates } from "../../agents/org-templates.js";
|
|
6
6
|
import { PendingConnectorsService } from "../../agents/pending-connectors.service.js";
|
|
7
|
+
import { ReadinessService } from "../../agents/readiness.service.js";
|
|
7
8
|
import { CatalogRequestsService } from "../../catalog/requests.service.js";
|
|
8
9
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
9
|
-
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
10
10
|
import { ConnectorsService } from "../../tools/connectors.service.js";
|
|
11
11
|
import { PlatformOperations } from "../registry.js";
|
|
12
12
|
/** Agent operations of the `Platform` tool (spec §7); visibility is the person's own agents. */
|
|
@@ -19,9 +19,9 @@ export declare class AgentsOperations implements OnModuleInit {
|
|
|
19
19
|
private readonly pending;
|
|
20
20
|
private readonly requests;
|
|
21
21
|
private readonly connectors;
|
|
22
|
-
private readonly
|
|
22
|
+
private readonly readiness;
|
|
23
23
|
private readonly kdb;
|
|
24
|
-
constructor(registry: PlatformOperations, agents: AgentsService, profiles: AgentProfileService, fromTemplate: AgentsFromTemplate, orgTemplates: OrgAgentTemplates, pending: PendingConnectorsService, requests: CatalogRequestsService, connectors: ConnectorsService,
|
|
24
|
+
constructor(registry: PlatformOperations, agents: AgentsService, profiles: AgentProfileService, fromTemplate: AgentsFromTemplate, orgTemplates: OrgAgentTemplates, pending: PendingConnectorsService, requests: CatalogRequestsService, connectors: ConnectorsService, readiness: ReadinessService, kdb: KernelDb);
|
|
25
25
|
/**
|
|
26
26
|
* The edit rule the service enforces, read before the card: the agent is visible, and the actor
|
|
27
27
|
* owns it or is an org admin. Returns the agent too for the checks that follow.
|
|
@@ -18,10 +18,10 @@ import { AgentsFromTemplate } from "../../agents/from-template.service.js";
|
|
|
18
18
|
import { OrgAgentTemplates } from "../../agents/org-templates.js";
|
|
19
19
|
import { PendingConnectorsService } from "../../agents/pending-connectors.service.js";
|
|
20
20
|
import { PresetAvatarSchema } from "../../agents/profile.js";
|
|
21
|
+
import { ReadinessService } from "../../agents/readiness.service.js";
|
|
21
22
|
import { CatalogRequestsService } from "../../catalog/requests.service.js";
|
|
22
23
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
23
24
|
import { roleAtLeast } from "../../orgs/roles.js";
|
|
24
|
-
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
25
25
|
import { rootConversationOf } from "../../runtime/subagents/child.js";
|
|
26
26
|
import { ConnectorsService } from "../../tools/connectors.service.js";
|
|
27
27
|
import { defineOperation, } from "../operation.js";
|
|
@@ -113,9 +113,9 @@ let AgentsOperations = class AgentsOperations {
|
|
|
113
113
|
pending;
|
|
114
114
|
requests;
|
|
115
115
|
connectors;
|
|
116
|
-
|
|
116
|
+
readiness;
|
|
117
117
|
kdb;
|
|
118
|
-
constructor(registry, agents, profiles, fromTemplate, orgTemplates, pending, requests, connectors,
|
|
118
|
+
constructor(registry, agents, profiles, fromTemplate, orgTemplates, pending, requests, connectors, readiness, kdb) {
|
|
119
119
|
this.registry = registry;
|
|
120
120
|
this.agents = agents;
|
|
121
121
|
this.profiles = profiles;
|
|
@@ -124,7 +124,7 @@ let AgentsOperations = class AgentsOperations {
|
|
|
124
124
|
this.pending = pending;
|
|
125
125
|
this.requests = requests;
|
|
126
126
|
this.connectors = connectors;
|
|
127
|
-
this.
|
|
127
|
+
this.readiness = readiness;
|
|
128
128
|
this.kdb = kdb;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
@@ -696,16 +696,13 @@ let AgentsOperations = class AgentsOperations {
|
|
|
696
696
|
}),
|
|
697
697
|
defineOperation({
|
|
698
698
|
id: "agents.readiness",
|
|
699
|
-
description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org (
|
|
699
|
+
description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org; org_fixable when 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.",
|
|
700
700
|
input: z.object({}).strict(),
|
|
701
701
|
example: {},
|
|
702
702
|
authz: { orgAction: "org.read" },
|
|
703
703
|
mirrors: ["GET /api/v1/orgs/:orgId/readiness"],
|
|
704
704
|
confirm: "read",
|
|
705
|
-
run:
|
|
706
|
-
modelProvider: (await this.providers.hasProvider(ctx.orgId)) ? "ready" : "none",
|
|
707
|
-
agents: (await this.agents.listVisible(ctx.orgId, ctx.actorAccountId)).length,
|
|
708
|
-
}),
|
|
705
|
+
run: (_input, ctx) => this.readiness.get(ctx.orgId, ctx.actorAccountId),
|
|
709
706
|
}),
|
|
710
707
|
]);
|
|
711
708
|
}
|
|
@@ -720,7 +717,7 @@ AgentsOperations = __decorate([
|
|
|
720
717
|
__param(5, Inject(PendingConnectorsService)),
|
|
721
718
|
__param(6, Inject(CatalogRequestsService)),
|
|
722
719
|
__param(7, Inject(ConnectorsService)),
|
|
723
|
-
__param(8, Inject(
|
|
720
|
+
__param(8, Inject(ReadinessService)),
|
|
724
721
|
__param(9, Inject(KernelDb))
|
|
725
722
|
], AgentsOperations);
|
|
726
723
|
export { AgentsOperations };
|
|
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { ComponentScopeService } from "../../catalog/component-scope.service.js";
|
|
13
|
-
import { ConnectorPathParams } from "../../tools/connectors.schemas.js";
|
|
13
|
+
import { ConnectorPathParams, GitPushPolicyBody } from "../../tools/connectors.schemas.js";
|
|
14
14
|
import { ConnectorsService, } from "../../tools/connectors.service.js";
|
|
15
15
|
import { publicEndpoint } from "../../tools/endpoint.js";
|
|
16
16
|
import { defineOperation } from "../operation.js";
|
|
@@ -19,6 +19,11 @@ import { precheckBy, viaAgent } from "./errors.js";
|
|
|
19
19
|
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
20
20
|
import { named, orElse } from "./summary.js";
|
|
21
21
|
const PAGE = 50;
|
|
22
|
+
/** `connectors.set-git-push-policy`: the route's path param and body. */
|
|
23
|
+
const SetGitPushPolicyInput = z
|
|
24
|
+
.object({ connectorId: ConnectorPathParams.shape.connectorId.max(100) })
|
|
25
|
+
.extend(GitPushPolicyBody.shape)
|
|
26
|
+
.strict();
|
|
22
27
|
/**
|
|
23
28
|
* A connector without anything secret: the auth method and who holds the credential (the org or
|
|
24
29
|
* each person), never the auth preset's fields or a credential. The endpoint is always the public
|
|
@@ -42,6 +47,8 @@ const summary = (c) => ({
|
|
|
42
47
|
/** A connector's detail: its tools (name, description, state, default policy) and your credential state. */
|
|
43
48
|
const detail = (c) => ({
|
|
44
49
|
...summary(c),
|
|
50
|
+
// the org's default for git pushes through its credential, when it serves git hosts
|
|
51
|
+
gitPushPolicy: c.git !== null ? c.gitPushPolicy : null,
|
|
45
52
|
credential: c.credential,
|
|
46
53
|
tools: c.tools.map((t) => ({
|
|
47
54
|
name: t.name,
|
|
@@ -178,6 +185,44 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
178
185
|
return { connector: detail(r.connector), issues: r.issues, changes: r.changes };
|
|
179
186
|
},
|
|
180
187
|
}),
|
|
188
|
+
defineOperation({
|
|
189
|
+
id: "connectors.set-git-push-policy",
|
|
190
|
+
description: "Set the org's default for git pushes through a connector's credential in sandboxes (org admins): deny refuses every push, ask asks the person for each repository, allow pushes without asking. Through this tool it may only be tightened (allow to ask or deny, ask to deny); loosening needs a person on the connector's settings page. Only a connector that declares git hosts.",
|
|
191
|
+
input: SetGitPushPolicyInput,
|
|
192
|
+
example: { connectorId: "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60", policy: "deny" },
|
|
193
|
+
authz: { orgAction: "connectors.manage" },
|
|
194
|
+
mirrors: ["PUT /api/v1/orgs/:orgId/connectors/:connectorId/git-push-policy"],
|
|
195
|
+
confirm: "org",
|
|
196
|
+
errors: [
|
|
197
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
198
|
+
{
|
|
199
|
+
code: "connector.git_push_widen_not_allowed",
|
|
200
|
+
next: {
|
|
201
|
+
orgAdmin: "Loosen the git push policy yourself on the connector's settings page on the web.",
|
|
202
|
+
member: "Ask an org admin to loosen the git push policy on the connector's settings page on the web.",
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
code: "validation_failed",
|
|
207
|
+
next: "The connector declares no git hosts, so it has no git push policy; connectors.get shows gitPushPolicy null for such a connector.",
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
precheck: (i, ctx) => precheckBy(() => this.connectors.checkGitPushPolicy(ctx.orgId, i.connectorId, i.policy, true)),
|
|
211
|
+
summary: async (i, ctx) => {
|
|
212
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
213
|
+
const zh = { allow: "允许", ask: "需审批", deny: "禁止" }[i.policy];
|
|
214
|
+
return {
|
|
215
|
+
zh: `把连接器「${n}」的 git 推送默认策略设为「${zh}」`,
|
|
216
|
+
en: `Set the default git push policy of connector "${n}" to ${i.policy}`,
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
run: async (input, ctx) => ({
|
|
220
|
+
connector: detail(await this.connectors.setGitPushPolicy(ctx.orgId, input.connectorId, ctx.actorAccountId, input.policy, {
|
|
221
|
+
auditDetail: viaAgent("connectors.set-git-push-policy", ctx),
|
|
222
|
+
onlyNarrows: true,
|
|
223
|
+
})),
|
|
224
|
+
}),
|
|
225
|
+
}),
|
|
181
226
|
]);
|
|
182
227
|
}
|
|
183
228
|
};
|
|
@@ -313,70 +313,7 @@ let EvalsOperations = class EvalsOperations {
|
|
|
313
313
|
},
|
|
314
314
|
],
|
|
315
315
|
precheck: async (i, ctx) => {
|
|
316
|
-
|
|
317
|
-
if (!found.ok)
|
|
318
|
-
return found;
|
|
319
|
-
const set = await this.sets.get(ctx.orgId, i.setId);
|
|
320
|
-
const conv = await this.kdb.db
|
|
321
|
-
.selectFrom("conversations")
|
|
322
|
-
.select(["agent_id", "kind"])
|
|
323
|
-
.where("id", "=", i.conversationId)
|
|
324
|
-
.where("org_id", "=", ctx.orgId)
|
|
325
|
-
.executeTakeFirst();
|
|
326
|
-
if (conv?.kind !== "chat" && conv?.kind !== "subagent") {
|
|
327
|
-
return {
|
|
328
|
-
ok: false,
|
|
329
|
-
code: "conversation.not_found",
|
|
330
|
-
message: "Conversation or run not found",
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
const sets = await this.kdb.db
|
|
334
|
-
.selectFrom("eval_sets")
|
|
335
|
-
.select("agent_id")
|
|
336
|
-
.where("id", "=", i.setId)
|
|
337
|
-
.executeTakeFirstOrThrow();
|
|
338
|
-
if (conv.agent_id !== sets.agent_id) {
|
|
339
|
-
return {
|
|
340
|
-
ok: false,
|
|
341
|
-
code: "eval.agent_mismatch",
|
|
342
|
-
message: "The run belongs to a different agent",
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
if (set.cases.some((c) => c.sourceRunId === i.runId)) {
|
|
346
|
-
return {
|
|
347
|
-
ok: false,
|
|
348
|
-
code: "eval.case_exists",
|
|
349
|
-
message: "That run is already a case of the eval set",
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
const run = await this.kdb.db
|
|
353
|
-
.selectFrom("runs")
|
|
354
|
-
.select(["status", "compact"])
|
|
355
|
-
.where("id", "=", i.runId)
|
|
356
|
-
.where("conversation_id", "=", i.conversationId)
|
|
357
|
-
.executeTakeFirst();
|
|
358
|
-
if (run === undefined) {
|
|
359
|
-
return {
|
|
360
|
-
ok: false,
|
|
361
|
-
code: "conversation.not_found",
|
|
362
|
-
message: "Conversation or run not found",
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
if (run.compact) {
|
|
366
|
-
return {
|
|
367
|
-
ok: false,
|
|
368
|
-
code: "eval.compact_not_replayable",
|
|
369
|
-
message: "A manual compaction run has no model step to replay",
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
if (run.status === "running" || run.status === "queued") {
|
|
373
|
-
return {
|
|
374
|
-
ok: false,
|
|
375
|
-
code: "eval.run_not_finished",
|
|
376
|
-
message: "The run has not finished yet",
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return this.roomCheck(ctx, i.setId);
|
|
316
|
+
return precheckBy(() => this.sets.checkAddCase(ctx.orgId, i.setId, i));
|
|
380
317
|
},
|
|
381
318
|
summary: async (i, ctx) => {
|
|
382
319
|
const n = await this.setName(ctx, i.setId);
|