@capybara-hq/kernel 0.1.0-rc.106 → 0.1.0-rc.108
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 +13 -13
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +4 -3
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +3 -3
- package/dist/channels/outbound.js +15 -13
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +12 -0
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +10 -9
- package/dist/conversations/conversations.service.js +28 -11
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +49 -27
- package/dist/conversations/events.js +54 -7
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.service.js +7 -2
- package/dist/ctx/create-ctx.d.ts +3 -1
- package/dist/ctx/create-ctx.js +19 -1
- package/dist/db/kernel-schema.d.ts +80 -2
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.js +13 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +3 -1
- package/dist/extensions/host.js +2 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +5 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/infra/outbox/registry.d.ts +82 -0
- package/dist/infra/outbox/registry.js +74 -2
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- package/dist/orgs/settings.service.d.ts +48 -2
- package/dist/orgs/settings.service.js +63 -3
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +5 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +15 -1
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +18 -1
- package/dist/runtime/context/build.js +19 -8
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +50 -17
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +10 -2
- package/dist/runtime/maintenance.js +48 -8
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- package/dist/runtime/run-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- package/dist/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/builtin-tools.d.ts +7 -1
- package/dist/tools/builtins/builtin-tools.js +17 -6
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- package/dist/tools/tools.module.js +6 -0
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { FileCreateBody, FileIdParams, LibraryListQuery } from "../../files/library.schemas.js";
|
|
14
|
+
import { FileBlobClaimedError, LibraryFilesService } from "../../files/library-files.service.js";
|
|
15
|
+
import { LibraryQuery } from "../../files/library-query.js";
|
|
16
|
+
import { FileRefSchema } from "../file-ref.js";
|
|
17
|
+
import { defineOperation } from "../operation.js";
|
|
18
|
+
import { PlatformOperations } from "../registry.js";
|
|
19
|
+
import { named, orElse } from "./summary.js";
|
|
20
|
+
const PAGE = 50;
|
|
21
|
+
const FileId = FileIdParams.shape.id;
|
|
22
|
+
/** A list row: the compact form of a library entry. */
|
|
23
|
+
const row = (f) => ({
|
|
24
|
+
id: f.id,
|
|
25
|
+
name: f.name,
|
|
26
|
+
contentType: f.contentType,
|
|
27
|
+
size: f.size,
|
|
28
|
+
origin: f.origin,
|
|
29
|
+
...(f.agentName !== undefined && { agent: f.agentName }),
|
|
30
|
+
...(f.sourceConversation !== null && {
|
|
31
|
+
conversation: {
|
|
32
|
+
id: f.sourceConversation.id,
|
|
33
|
+
title: f.sourceConversation.title,
|
|
34
|
+
...(f.sourceConversation.deleted && { deleted: true }),
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
versionCount: f.versions,
|
|
38
|
+
createdAt: f.createdAt,
|
|
39
|
+
});
|
|
40
|
+
/** Model-visible: the bytes' blob kept being deleted while the file was added (a transient race). */
|
|
41
|
+
const BLOB_CLAIMED_TEXT = "The stored bytes were being cleaned up while the file was added, and nothing was added; call the operation again.";
|
|
42
|
+
/** The link of one file on the Files page. */
|
|
43
|
+
const fileLink = (id) => `/files#item=${encodeURIComponent(id)}`;
|
|
44
|
+
/**
|
|
45
|
+
* File library operations of the `Platform` tool (file library spec §6, §8): the person's own
|
|
46
|
+
* files, as the Files page shows them. Bytes, previews and the HTML document stay with the web
|
|
47
|
+
* (`transport` exclusions); deleting a file is confirmed by the person on the Files page, so
|
|
48
|
+
* `files.delete` only checks the file and hands them the link. `files.add` is the upload routes
|
|
49
|
+
* with a file reference in place of the bytes (platform web parity spec §5).
|
|
50
|
+
*/
|
|
51
|
+
let FilesOperations = class FilesOperations {
|
|
52
|
+
registry;
|
|
53
|
+
library;
|
|
54
|
+
files;
|
|
55
|
+
constructor(registry, library, files) {
|
|
56
|
+
this.registry = registry;
|
|
57
|
+
this.library = library;
|
|
58
|
+
this.files = files;
|
|
59
|
+
}
|
|
60
|
+
onModuleInit() {
|
|
61
|
+
this.registry.register([
|
|
62
|
+
defineOperation({
|
|
63
|
+
id: "files.list",
|
|
64
|
+
description: "List your files (the Files page), newest first: files you uploaded and files agents delivered or generated in your conversations, each with id, name, type, size, origin, the agent and the conversation it came from (deleted conversations keep their files) and the number of versions as versionCount (repeated deliveries of one path in one conversation are one entry). Filter by origin, agentId, type (image, document, text, other) or q (part of the name). Pages by 50: pass the returned next as params.cursor.",
|
|
65
|
+
input: LibraryListQuery.pick({
|
|
66
|
+
origin: true,
|
|
67
|
+
agentId: true,
|
|
68
|
+
type: true,
|
|
69
|
+
q: true,
|
|
70
|
+
cursor: true,
|
|
71
|
+
}).strict(),
|
|
72
|
+
example: { q: "report" },
|
|
73
|
+
authz: { orgAction: "agents.use" },
|
|
74
|
+
mirrors: ["GET /api/v1/orgs/:orgId/files"],
|
|
75
|
+
// the page size is fixed at 50
|
|
76
|
+
omits: ["limit"],
|
|
77
|
+
errors: [
|
|
78
|
+
{
|
|
79
|
+
code: "validation_failed",
|
|
80
|
+
next: "Pass the next value of the previous page as params.cursor, unchanged.",
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
confirm: "read",
|
|
84
|
+
run: async (input, ctx) => {
|
|
85
|
+
const out = await this.library.list(ctx.orgId, ctx.actorAccountId, {
|
|
86
|
+
limit: PAGE,
|
|
87
|
+
...(input.origin !== undefined && { origin: input.origin }),
|
|
88
|
+
...(input.agentId !== undefined && { agentId: input.agentId }),
|
|
89
|
+
...(input.type !== undefined && { type: input.type }),
|
|
90
|
+
...(input.q !== undefined && { q: input.q }),
|
|
91
|
+
...(input.cursor !== undefined && { cursor: input.cursor }),
|
|
92
|
+
});
|
|
93
|
+
return { files: out.files.map(row), next: out.next };
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
defineOperation({
|
|
97
|
+
id: "files.get",
|
|
98
|
+
description: "Read one of your files: its details, your conversations it was sent or delivered in, and its versions (newest first). Takes the id from files.list. File contents are opened on the web.",
|
|
99
|
+
input: z.object({ fileId: FileId }).strict(),
|
|
100
|
+
example: { fileId: "3f2b8a40-6c1d-4e0b-9a77-5d1e2c8b9f10" },
|
|
101
|
+
authz: { orgAction: "agents.use" },
|
|
102
|
+
mirrors: ["GET /api/v1/orgs/:orgId/files/:id"],
|
|
103
|
+
renames: { fileId: "id" },
|
|
104
|
+
errors: [
|
|
105
|
+
{
|
|
106
|
+
code: "file.not_found",
|
|
107
|
+
next: "Check the id with files.list: only your own files can be read.",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
confirm: "read",
|
|
111
|
+
run: async (input, ctx) => {
|
|
112
|
+
const d = await this.library.details(ctx.orgId, ctx.actorAccountId, input.fileId);
|
|
113
|
+
return { file: row(d.file), conversations: d.conversations, versions: d.versions };
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
defineOperation({
|
|
117
|
+
id: "files.usage",
|
|
118
|
+
description: "Read how much storage your files use: the number of your files and their bytes (a file stored twice counts once).",
|
|
119
|
+
input: z.object({}).strict(),
|
|
120
|
+
example: {},
|
|
121
|
+
authz: { orgAction: "agents.use" },
|
|
122
|
+
mirrors: ["GET /api/v1/orgs/:orgId/files/usage"],
|
|
123
|
+
confirm: "read",
|
|
124
|
+
run: async (_input, ctx) => this.library.usage(ctx.orgId, ctx.actorAccountId),
|
|
125
|
+
}),
|
|
126
|
+
defineOperation({
|
|
127
|
+
id: "files.add",
|
|
128
|
+
description: "Add a file of this conversation to your files (the Files page) as your own upload: an attachment, a generated image, an image a tool showed you or a delivered file, passed as file: { fileId } (Deliver a device file first). A file has one owner: a file of another person's files is refused (they add it themselves). name names the new entry (default: the file's name). A file that already is one of your files is returned as it is (with a different name, a renamed entry is added next to it), and so is your file of the same name and bytes: nothing is added twice. Bytes the org already stores are not stored again. Only the types and sizes the composer accepts can be added. The person sees the file on the card. Returns the entry's id, name, size and content type, and added: false when it was already there.",
|
|
129
|
+
input: z
|
|
130
|
+
.object({ file: FileRefSchema, name: FileCreateBody.shape.name.optional() })
|
|
131
|
+
.strict(),
|
|
132
|
+
example: { file: { fileId: "0b9f2c4e-1d3a-4c55-9e0a-7a2f6d1c8b11" } },
|
|
133
|
+
authz: { orgAction: "agents.use" },
|
|
134
|
+
mirrors: ["POST /api/v1/orgs/:orgId/files", "POST /api/v1/orgs/:orgId/files/:id/finalize"],
|
|
135
|
+
// the upload registration's fields come from the referenced file (its type, size and
|
|
136
|
+
// sha256, a library upload); the kernel adds the bytes it holds, so there is no upload to
|
|
137
|
+
// finalize and no id to pass
|
|
138
|
+
omits: ["contentType", "size", "sha256", "purpose", "id"],
|
|
139
|
+
extras: ["file"],
|
|
140
|
+
loosens: { name: "optional: the referenced file's name is the default" },
|
|
141
|
+
confirm: "personal",
|
|
142
|
+
errors: [
|
|
143
|
+
{
|
|
144
|
+
code: "file.type_not_allowed",
|
|
145
|
+
next: "This type of file cannot be added to the Files page (or its bytes are not of its type); tell the person, or convert it to an accepted type, deliver it and retry.",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
code: "file.too_large",
|
|
149
|
+
next: "The file is over the upload limit; tell the person, or make it smaller, deliver it and retry.",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
code: "storage.unavailable",
|
|
153
|
+
next: "File storage is unavailable; try again later, or tell the person to contact the super admin.",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
// the upload's types, signature and per-type size, and one owner per file, are checked
|
|
157
|
+
// before the card (and again before the run)
|
|
158
|
+
fileRef: (i) => {
|
|
159
|
+
const limits = this.files.limits();
|
|
160
|
+
return {
|
|
161
|
+
ref: i.file,
|
|
162
|
+
limits: {
|
|
163
|
+
maxBytes: Math.max(limits.maxBytes, limits.imageMaxBytes),
|
|
164
|
+
contentTypes: limits.types,
|
|
165
|
+
typeMaxBytes: Object.fromEntries(limits.types.map((t) => [t, this.files.limitFor(t)])),
|
|
166
|
+
ownFilesOnly: true,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
summary: async (i, ctx) => {
|
|
171
|
+
const f = named(ctx.file?.name ?? "?");
|
|
172
|
+
const own = await orElse(async () => (await this.files.ownerOf(ctx.orgId, i.file.fileId)) === ctx.actorAccountId, false);
|
|
173
|
+
const renamed = i.name !== undefined && i.name !== ctx.file?.name;
|
|
174
|
+
if (own && !renamed) {
|
|
175
|
+
return {
|
|
176
|
+
zh: `文件「${f}」已在你的文件中,不会重复添加`,
|
|
177
|
+
en: `The file "${f}" is already in your files; nothing is added`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return renamed
|
|
181
|
+
? {
|
|
182
|
+
zh: `把文件「${f}」以「${named(i.name ?? "")}」为名加入你的文件`,
|
|
183
|
+
en: `Add the file "${f}" to your files as "${named(i.name ?? "")}"`,
|
|
184
|
+
}
|
|
185
|
+
: { zh: `把文件「${f}」加入你的文件`, en: `Add the file "${f}" to your files` };
|
|
186
|
+
},
|
|
187
|
+
run: async (input, ctx) => {
|
|
188
|
+
const f = ctx.file;
|
|
189
|
+
if (f === undefined)
|
|
190
|
+
throw new Error("files.add: the file is missing");
|
|
191
|
+
const out = await this.files
|
|
192
|
+
.addFromBytes(ctx.orgId, ctx.actorAccountId, {
|
|
193
|
+
referencedId: input.file.fileId,
|
|
194
|
+
name: f.name,
|
|
195
|
+
...(input.name !== undefined && { rename: input.name }),
|
|
196
|
+
contentType: f.contentType,
|
|
197
|
+
bytes: f.bytes,
|
|
198
|
+
sha256: f.sha256,
|
|
199
|
+
signal: ctx.signal,
|
|
200
|
+
})
|
|
201
|
+
.catch((e) => {
|
|
202
|
+
if (e instanceof FileBlobClaimedError)
|
|
203
|
+
throw new ToolError(BLOB_CLAIMED_TEXT);
|
|
204
|
+
throw e;
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
id: out.id,
|
|
208
|
+
name: out.name,
|
|
209
|
+
size: out.size,
|
|
210
|
+
contentType: out.contentType,
|
|
211
|
+
added: !out.existing,
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
handoff: (_input, result) => {
|
|
215
|
+
const id = result?.id;
|
|
216
|
+
return typeof id === "string"
|
|
217
|
+
? {
|
|
218
|
+
kind: "handoff",
|
|
219
|
+
title: { zh: "在文件页查看这个文件", en: "View this file on the Files page" },
|
|
220
|
+
target: { type: "link", url: fileLink(id) },
|
|
221
|
+
}
|
|
222
|
+
: null;
|
|
223
|
+
},
|
|
224
|
+
}),
|
|
225
|
+
defineOperation({
|
|
226
|
+
id: "files.delete",
|
|
227
|
+
description: "Ask to delete one of your files: nothing is deleted here; this checks the file and hands the person a link to the Files page to confirm the deletion there (its shared links stop working, and conversations show it as no longer available). Takes the id from files.list.",
|
|
228
|
+
input: z.object({ fileId: FileId }).strict(),
|
|
229
|
+
example: { fileId: "3f2b8a40-6c1d-4e0b-9a77-5d1e2c8b9f10" },
|
|
230
|
+
authz: { orgAction: "agents.use" },
|
|
231
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/files/:id"],
|
|
232
|
+
renames: { fileId: "id" },
|
|
233
|
+
errors: [
|
|
234
|
+
{
|
|
235
|
+
code: "file.not_found",
|
|
236
|
+
next: "Check the id with files.list: only your own files can be read.",
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
// nothing is written: the person deletes on the Files page
|
|
240
|
+
confirm: "read",
|
|
241
|
+
run: async (input, ctx) => {
|
|
242
|
+
const d = await this.library.details(ctx.orgId, ctx.actorAccountId, input.fileId);
|
|
243
|
+
return {
|
|
244
|
+
id: d.file.id,
|
|
245
|
+
name: d.file.name,
|
|
246
|
+
next: "Ask the person to confirm the deletion on the Files page (the link card).",
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
handoff: (input) => ({
|
|
250
|
+
kind: "handoff",
|
|
251
|
+
title: {
|
|
252
|
+
zh: "在文件页确认删除这个文件",
|
|
253
|
+
en: "Confirm deleting this file on the Files page",
|
|
254
|
+
},
|
|
255
|
+
target: { type: "link", url: fileLink(input.fileId) },
|
|
256
|
+
}),
|
|
257
|
+
}),
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
FilesOperations = __decorate([
|
|
262
|
+
Injectable(),
|
|
263
|
+
__param(0, Inject(PlatformOperations)),
|
|
264
|
+
__param(1, Inject(LibraryQuery)),
|
|
265
|
+
__param(2, Inject(LibraryFilesService))
|
|
266
|
+
], FilesOperations);
|
|
267
|
+
export { FilesOperations };
|
|
@@ -39,7 +39,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
|
|
|
39
39
|
this.registry.register([
|
|
40
40
|
defineOperation({
|
|
41
41
|
id: "org-settings.get",
|
|
42
|
-
description: "Read this org's settings: toolSearch, locale, sandboxToolPolicy, platformTool (on, read-only or off), outsideSandbox (allowed or off: whether the org's devices may be granted running a call outside their sandbox; absent follows the deployment, and the org may never exceed it), deviceNetwork (the org's device sandbox network: default, the network a device gets when its owner chooses none, and ceiling, the widest a device may choose, each open or allowlist and absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay closed), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's outside-sandbox switch (outsideSandbox) and device network (deviceNetwork: its default and ceiling, its allowlist, orgHosts: extend lets the org go beyond the allowlist, within makes it the hosts' ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's devices really get), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, and the sandbox cpu / memory limits in effect.",
|
|
42
|
+
description: "Read this org's settings: toolSearch, locale, sandboxToolPolicy, platformTool (on, read-only or off), outsideSandbox (allowed or off: whether the org's devices may be granted running a call outside their sandbox; absent follows the deployment, and the org may never exceed it), deviceNetwork (the org's device sandbox network: default, the network a device gets when its owner chooses none, and ceiling, the widest a device may choose, each open or allowlist and absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay closed), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), navigation (pluginPages: per plugin page contribution key <extension>/<contribution>, the section primary or more an org admin chose; at most 3 primary; absent means every page follows its own suggestion), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's outside-sandbox switch (outsideSandbox) and device network (deviceNetwork: its default and ceiling, its allowlist, orgHosts: extend lets the org go beyond the allowlist, within makes it the hosts' ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's devices really get), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, and the sandbox cpu / memory limits in effect.",
|
|
43
43
|
input: z.object({}).strict(),
|
|
44
44
|
example: {},
|
|
45
45
|
authz: { orgAction: "org.read" },
|
|
@@ -57,7 +57,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
|
|
|
57
57
|
}),
|
|
58
58
|
defineOperation({
|
|
59
59
|
id: "org-settings.update",
|
|
60
|
-
description: "Change this org's settings (org admins). Give only the settings to change; null clears outsideSandbox, deviceNetwork or wakeOnBackgroundTask so they follow the deployment again (refused when the deployment value is wider than what this tool may set). outsideSandbox (allowed or off; the platform must allow it) and deviceNetwork ({ default?, ceiling?: open | allowlist, base?: platform | none, extraHosts?, excludedHosts? }, replaced whole, so send the stored fields you keep; neither default nor ceiling may be open where the platform's ceiling is allowlist, and the default may not be above the ceiling) may only narrow the org's devices here: allowing outside-sandbox runs where the org has them off, opening the default or the ceiling, adding an extra host, dropping an exclusion or moving base from none to platform is refused and needs a person in the organization settings on the web. theme: { id, personal } sets the org's default theme (a theme id from themes.list, or null to follow the platform) and whether members may pick their own (allowed) or not (locked); null clears it. uiArrangement: { <slot>: { hidden, order } } (a list slot) or { <slot>: { use } } (a single slot: shell.brand, conversation.empty, conversation.composer.frame) replaces that slot's entry, where hidden, order and use name contribution keys <extension>/<contribution> (hidden ones are not listed in the web UI but their pages still open by URL; use null is the built-in); null for a slot makes it follow the platform again; platform.page is refused. externalSharing (on or off; null clears it, off) may only be turned off through this tool: turning it on needs a person in the organization settings on the web, and the platform must allow it. promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) may be set either way through this tool. Setting platformTool to off or read-only takes effect from the next call and cuts this Platform tool off in the org; an org admin switches it back on in the web settings.",
|
|
60
|
+
description: "Change this org's settings (org admins). Give only the settings to change; null clears outsideSandbox, deviceNetwork or wakeOnBackgroundTask so they follow the deployment again (refused when the deployment value is wider than what this tool may set). outsideSandbox (allowed or off; the platform must allow it) and deviceNetwork ({ default?, ceiling?: open | allowlist, base?: platform | none, extraHosts?, excludedHosts? }, replaced whole, so send the stored fields you keep; neither default nor ceiling may be open where the platform's ceiling is allowlist, and the default may not be above the ceiling) may only narrow the org's devices here: allowing outside-sandbox runs where the org has them off, opening the default or the ceiling, adding an extra host, dropping an exclusion or moving base from none to platform is refused and needs a person in the organization settings on the web. theme: { id, personal } sets the org's default theme (a theme id from themes.list, or null to follow the platform) and whether members may pick their own (allowed) or not (locked); null clears it. uiArrangement: { <slot>: { hidden, order } } (a list slot) or { <slot>: { use } } (a single slot: shell.brand, conversation.empty, conversation.composer.frame) replaces that slot's entry, where hidden, order and use name contribution keys <extension>/<contribution> (hidden ones are not listed in the web UI but their pages still open by URL; use null is the built-in); null for a slot makes it follow the platform again; platform.page is refused. navigation: { pluginPages: [{ contribution: <extension>/<contribution>, section: primary or more }] } replaces where the org's plugin pages sit in the navigation (at most 3 primary, so send the whole list you keep); null clears it. externalSharing (on or off; null clears it, off) may only be turned off through this tool: turning it on needs a person in the organization settings on the web, and the platform must allow it. promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) may be set either way through this tool. compaction ({ enabled?, threshold? (0.5 to 0.95), keepRecentTurns? (0 to 20), reserveTokens? (0 to 50000), maxOutputTokens? (1024 to 32000) }: the org's conversation compaction overrides, merged into the stored fields; null clears the override so the org follows the platform) may be set either way. promptCache ({ longTtl }: true or false; whether requests use the model's prompt cache tier of at least 30 minutes, such as 1 hour, where cache writes cost more; null clears it so the org follows the platform) may be set either way. Setting platformTool to off or read-only takes effect from the next call and cuts this Platform tool off in the org; an org admin switches it back on in the web settings.",
|
|
61
61
|
input: OrgSettingsPatchSchema.refine((i) => Object.values(i).some((v) => v !== undefined), {
|
|
62
62
|
message: "give at least one setting",
|
|
63
63
|
}),
|
|
@@ -82,6 +82,10 @@ let OrgSettingsOperations = class OrgSettingsOperations {
|
|
|
82
82
|
code: "org.external_sharing_not_allowed",
|
|
83
83
|
next: "Through this tool external sharing may only be turned off; to turn it on, ask an org admin to change it in the organization settings on the web. When the platform denies external sharing (org-settings.get shows deployment.externalSharing), a super admin must allow it first.",
|
|
84
84
|
},
|
|
85
|
+
{
|
|
86
|
+
code: "org_settings.nav_primary_limit",
|
|
87
|
+
next: "At most 3 plugin pages can be in the primary navigation: move one to more, or drop it from the list, and send the whole navigation.pluginPages again.",
|
|
88
|
+
},
|
|
85
89
|
{
|
|
86
90
|
code: "theme.not_available",
|
|
87
91
|
next: "Pick a theme id that themes.list shows for this org, or null to follow the platform.",
|
|
@@ -56,7 +56,7 @@ let SharesOperations = class SharesOperations {
|
|
|
56
56
|
this.registry.register([
|
|
57
57
|
defineOperation({
|
|
58
58
|
id: "conversations.list-shares",
|
|
59
|
-
description: "List shared links to
|
|
59
|
+
description: "List shared links to files, newest first: your own (scope mine, the default) or every member's in the org (scope all, org admins only). Each row has the file name, state (live, suspended, expired, revoked), the audience (internal: signed-in members; external: anyone with the link), the expiry and who shared it; revoked and expired links stay listed for 7 days. Pages by 50: pass the returned next as params.cursor.",
|
|
60
60
|
input: z.object({ scope: ListSharesQuery.shape.scope, cursor: Cursor.optional() }).strict(),
|
|
61
61
|
example: { scope: "mine" },
|
|
62
62
|
authz: { orgAction: "agents.use" },
|
|
@@ -73,7 +73,7 @@ let SharesOperations = class SharesOperations {
|
|
|
73
73
|
}),
|
|
74
74
|
defineOperation({
|
|
75
75
|
id: "conversations.revoke-share",
|
|
76
|
-
description: "Revoke a shared link to a
|
|
76
|
+
description: "Revoke a shared link to a file: the link stops working at once (the file itself is kept). Takes the share id from conversations.list-shares. Your own shares, or any member's for org admins. Revoking a link already revoked changes nothing. The person confirms every revoke.",
|
|
77
77
|
input: z.object({ shareId: ShareIdParams.shape.shareId }).strict(),
|
|
78
78
|
example: { shareId: "3f2b8a40-6c1d-4e0b-9a77-5d1e2c8b9f10" },
|
|
79
79
|
authz: { orgAction: "agents.use" },
|
|
@@ -16,6 +16,7 @@ import { DevicesOperations } from "./ops/devices.ops.js";
|
|
|
16
16
|
import { EvalsOperations } from "./ops/evals.ops.js";
|
|
17
17
|
import { ExtensionsOperations } from "./ops/extensions.ops.js";
|
|
18
18
|
import { ExtensionsAdminOperations } from "./ops/extensions-admin.ops.js";
|
|
19
|
+
import { FilesOperations } from "./ops/files.ops.js";
|
|
19
20
|
import { InboxOperations } from "./ops/inbox.ops.js";
|
|
20
21
|
import { MarketplacesOperations } from "./ops/marketplaces.ops.js";
|
|
21
22
|
import { ModelsOperations } from "./ops/models.ops.js";
|
|
@@ -37,7 +38,7 @@ import { UiOperations } from "./ops/ui.ops.js";
|
|
|
37
38
|
* One provider per domain, each taking `PlatformOperations` as its first constructor argument:
|
|
38
39
|
* the parity test in `tools/checks` builds the operations from it without a Nest app.
|
|
39
40
|
*/
|
|
40
|
-
export declare const PLATFORM_OPERATION_PROVIDERS: readonly [typeof PlatformOperationsProvider, typeof SkillsOperations, typeof AgentsOperations, typeof AgentTemplatesOperations, typeof PluginsOperations, typeof MarketplacesOperations, typeof RequestsOperations, typeof ConnectorsOperations, typeof ExtensionsOperations, typeof ConversationsOperations, typeof ComponentsOperations, typeof AccountsOperations, typeof OrgsOperations, typeof AdminOperations, typeof CatalogAdminOperations, typeof OrgPluginsOperations, typeof ExtensionsAdminOperations, typeof ModelsOperations, typeof InboxOperations, typeof ApprovalsOperations, typeof ChannelsOperations, typeof OrgSettingsOperations, typeof EvalsOperations, typeof BackgroundOperations, typeof PreviewersOperations, typeof DevicesOperations, typeof AgentSkillsOperations, typeof ThemesOperations, typeof SetupOperations, typeof UiOperations, typeof AdminItemsOperations, typeof AutomationsOperations, typeof OutboxOperations, typeof SharesOperations, typeof PlatformIconsOperations];
|
|
41
|
+
export declare const PLATFORM_OPERATION_PROVIDERS: readonly [typeof PlatformOperationsProvider, typeof SkillsOperations, typeof AgentsOperations, typeof AgentTemplatesOperations, typeof PluginsOperations, typeof MarketplacesOperations, typeof RequestsOperations, typeof ConnectorsOperations, typeof ExtensionsOperations, typeof ConversationsOperations, typeof ComponentsOperations, typeof AccountsOperations, typeof OrgsOperations, typeof AdminOperations, typeof CatalogAdminOperations, typeof OrgPluginsOperations, typeof ExtensionsAdminOperations, typeof ModelsOperations, typeof InboxOperations, typeof ApprovalsOperations, typeof ChannelsOperations, typeof OrgSettingsOperations, typeof EvalsOperations, typeof BackgroundOperations, typeof PreviewersOperations, typeof DevicesOperations, typeof AgentSkillsOperations, typeof ThemesOperations, typeof SetupOperations, typeof UiOperations, typeof AdminItemsOperations, typeof AutomationsOperations, typeof OutboxOperations, typeof SharesOperations, typeof PlatformIconsOperations, typeof FilesOperations];
|
|
41
42
|
/**
|
|
42
43
|
* The `Platform` tool's operations (ruling P2): one provider per domain, each registering its
|
|
43
44
|
* operations into `PlatformOperations` from `onModuleInit`. It imports the domain modules, which
|
|
@@ -17,6 +17,7 @@ import { DevicesModule } from "../devices/devices.module.js";
|
|
|
17
17
|
import { EvalsModule } from "../evals/evals.module.js";
|
|
18
18
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
19
19
|
import { FilesModule } from "../files/files.module.js";
|
|
20
|
+
import { LibraryReadModule } from "../files/library-read.module.js";
|
|
20
21
|
import { IdentityModule } from "../identity/identity.module.js";
|
|
21
22
|
import { InboxModule } from "../inbox/inbox.module.js";
|
|
22
23
|
import { ModelsModule } from "../models/models.module.js";
|
|
@@ -46,6 +47,7 @@ import { DevicesOperations } from "./ops/devices.ops.js";
|
|
|
46
47
|
import { EvalsOperations } from "./ops/evals.ops.js";
|
|
47
48
|
import { ExtensionsOperations } from "./ops/extensions.ops.js";
|
|
48
49
|
import { ExtensionsAdminOperations } from "./ops/extensions-admin.ops.js";
|
|
50
|
+
import { FilesOperations } from "./ops/files.ops.js";
|
|
49
51
|
import { InboxOperations } from "./ops/inbox.ops.js";
|
|
50
52
|
import { MarketplacesOperations } from "./ops/marketplaces.ops.js";
|
|
51
53
|
import { ModelsOperations } from "./ops/models.ops.js";
|
|
@@ -118,6 +120,8 @@ export const PLATFORM_OPERATION_PROVIDERS = [
|
|
|
118
120
|
SharesOperations,
|
|
119
121
|
// the platform icon (mobile layout spec §10.2.1)
|
|
120
122
|
PlatformIconsOperations,
|
|
123
|
+
// the person's file library (file library spec §6)
|
|
124
|
+
FilesOperations,
|
|
121
125
|
];
|
|
122
126
|
/**
|
|
123
127
|
* The `Platform` tool's operations (ruling P2): one provider per domain, each registering its
|
|
@@ -148,6 +152,7 @@ PlatformOpsModule = __decorate([
|
|
|
148
152
|
DevicesModule,
|
|
149
153
|
BackgroundModule,
|
|
150
154
|
FilesModule,
|
|
155
|
+
LibraryReadModule,
|
|
151
156
|
ThemesModule,
|
|
152
157
|
SetupModule,
|
|
153
158
|
AutomationsModule,
|
|
@@ -22,6 +22,7 @@ import { CONVERSATION_ROUTES } from "../conversations/conversations.schemas.js";
|
|
|
22
22
|
import { DEVICE_ROUTES } from "../devices/devices.schemas.js";
|
|
23
23
|
import { EVAL_ROUTES } from "../evals/evals.schemas.js";
|
|
24
24
|
import { EXTENSION_POINT_ROUTES } from "../extensions/point-defaults.schemas.js";
|
|
25
|
+
import { FILE_ROUTES } from "../files/library.schemas.js";
|
|
25
26
|
import { FILE_PREVIEWER_ROUTES } from "../files/previewers.schemas.js";
|
|
26
27
|
import { ME_ROUTES } from "../identity/me.schemas.js";
|
|
27
28
|
import { INBOX_ROUTES } from "../inbox/inbox.schemas.js";
|
|
@@ -104,4 +105,6 @@ export const ROUTE_SCHEMAS = [
|
|
|
104
105
|
...LOGIN_SOURCE_ROUTES,
|
|
105
106
|
// shares of conversation files (file sharing spec §10)
|
|
106
107
|
...SHARE_ROUTES,
|
|
108
|
+
// the person's file library (file library spec §6)
|
|
109
|
+
...FILE_ROUTES,
|
|
107
110
|
];
|
|
@@ -29,6 +29,11 @@ import { EvalWorkersModule } from "../evals/evals.module.js";
|
|
|
29
29
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
30
30
|
import { PluginsReconcileJob } from "../extensions/lifecycle.js";
|
|
31
31
|
import { LifecycleHookWorkersModule } from "../extensions/lifecycle-hooks.js";
|
|
32
|
+
import { BlobSweepJob } from "../files/blob-sweep.job.js";
|
|
33
|
+
import { FileDraftCleanupJob } from "../files/draft-cleanup.job.js";
|
|
34
|
+
import { FileLibraryKickoffJob } from "../files/hash-job.js";
|
|
35
|
+
import { LibraryFilesModule } from "../files/library.module.js";
|
|
36
|
+
import { FileLibraryJobsModule } from "../files/library-jobs.module.js";
|
|
32
37
|
import { AccountAvatarCleanupJob } from "../identity/account-avatars.service.js";
|
|
33
38
|
import { IdentityModule } from "../identity/identity.module.js";
|
|
34
39
|
import { InitialPasswordCleanupJob } from "../identity/initial-passwords.job.js";
|
|
@@ -96,6 +101,10 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
|
|
|
96
101
|
TitlesModule,
|
|
97
102
|
PromptSuggestionsModule,
|
|
98
103
|
AttachmentsModule,
|
|
104
|
+
// the hourly cleanup of expired uploads and drafts
|
|
105
|
+
LibraryFilesModule,
|
|
106
|
+
// the hashing and catch-up copy the kickoff owes
|
|
107
|
+
FileLibraryJobsModule,
|
|
99
108
|
IdentityModule,
|
|
100
109
|
StorageModule,
|
|
101
110
|
SandboxModule,
|
|
@@ -109,7 +118,7 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
|
|
|
109
118
|
ChannelsModule,
|
|
110
119
|
// the automation scanner (`@LockedCron`) and the fire job's body
|
|
111
120
|
AutomationFireModule,
|
|
112
|
-
// the share
|
|
121
|
+
// the legacy share snapshot deletions the maintenance processor still runs
|
|
113
122
|
ShareObjectsModule,
|
|
114
123
|
// the owed conversation notices the sweep delivers
|
|
115
124
|
ConversationNoticesModule,
|
|
@@ -118,6 +127,11 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
|
|
|
118
127
|
// the one repair of a run nobody runs (transactional outbox spec §8.3)
|
|
119
128
|
RunOrphanCheck,
|
|
120
129
|
AttachmentCleanupJob,
|
|
130
|
+
// expired uploads and composer drafts of the file library (file library spec §3)
|
|
131
|
+
FileDraftCleanupJob,
|
|
132
|
+
// the daily blob sweep and the hourly kickoff of hashing and the catch-up copy (§7, §9)
|
|
133
|
+
BlobSweepJob,
|
|
134
|
+
FileLibraryKickoffJob,
|
|
121
135
|
StoragePurgeJob,
|
|
122
136
|
SandboxSweepJobs,
|
|
123
137
|
LegacySandboxCleanupJob,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
-
import { type CompactionSettings, SettingsService } from "../identity/settings.js";
|
|
2
|
+
import { type CompactionSettings, type PromptCacheSettings, SettingsService } from "../identity/settings.js";
|
|
3
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
export { COMPACTION_SETTINGS, type CompactionSettings, effectiveCompactionSettings, } from "../identity/settings.js";
|
|
5
5
|
/**
|
|
@@ -9,6 +9,16 @@ export { COMPACTION_SETTINGS, type CompactionSettings, effectiveCompactionSettin
|
|
|
9
9
|
* job), which would otherwise import the runtime module in a cycle.
|
|
10
10
|
*/
|
|
11
11
|
export declare function resolveCompactionSettings(settings: Pick<SettingsService, "get">, db: KernelSchemaDb, orgId: string): Promise<CompactionSettings>;
|
|
12
|
+
/** The settings a model step reads: compaction and the prompt cache, from one read of each source. */
|
|
13
|
+
export interface StepSettings {
|
|
14
|
+
compaction: CompactionSettings;
|
|
15
|
+
promptCache: PromptCacheSettings;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The effective compaction and prompt cache settings for `orgId` (org override > platform setting
|
|
19
|
+
* > built-in default), with one read of the platform settings and one of the org row.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveStepSettings(settings: Pick<SettingsService, "get">, db: KernelSchemaDb, orgId: string): Promise<StepSettings>;
|
|
12
22
|
/**
|
|
13
23
|
* The compaction settings in effect for one organization (context compaction spec §4.8):
|
|
14
24
|
* the organization's override over the platform's stored settings, which carry the built-in
|
|
@@ -21,4 +31,6 @@ export declare class CompactionSettingsService {
|
|
|
21
31
|
constructor(settings: Pick<SettingsService, "get">, db: KernelDb);
|
|
22
32
|
/** The effective settings for `orgId`: org override > platform setting > built-in default. */
|
|
23
33
|
resolve(orgId: string): Promise<CompactionSettings>;
|
|
34
|
+
/** What a model step reads for `orgId`: the compaction and prompt cache settings, one read each. */
|
|
35
|
+
resolveStep(orgId: string): Promise<StepSettings>;
|
|
24
36
|
}
|
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
-
import { effectiveCompactionSettings, SettingsService, } from "../identity/settings.js";
|
|
11
|
+
import { effectiveCompactionSettings, effectivePromptCacheSettings, SettingsService, } from "../identity/settings.js";
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
13
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
14
14
|
export { COMPACTION_SETTINGS, effectiveCompactionSettings, } from "../identity/settings.js";
|
|
@@ -22,6 +22,17 @@ export async function resolveCompactionSettings(settings, db, orgId) {
|
|
|
22
22
|
const [platform, org] = await Promise.all([settings.get(), readOrgSettings(db, orgId)]);
|
|
23
23
|
return effectiveCompactionSettings(platform.compaction, org.compaction);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The effective compaction and prompt cache settings for `orgId` (org override > platform setting
|
|
27
|
+
* > built-in default), with one read of the platform settings and one of the org row.
|
|
28
|
+
*/
|
|
29
|
+
export async function resolveStepSettings(settings, db, orgId) {
|
|
30
|
+
const [platform, org] = await Promise.all([settings.get(), readOrgSettings(db, orgId)]);
|
|
31
|
+
return {
|
|
32
|
+
compaction: effectiveCompactionSettings(platform.compaction, org.compaction),
|
|
33
|
+
promptCache: effectivePromptCacheSettings(platform.promptCache, org.promptCache),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
25
36
|
/**
|
|
26
37
|
* The compaction settings in effect for one organization (context compaction spec §4.8):
|
|
27
38
|
* the organization's override over the platform's stored settings, which carry the built-in
|
|
@@ -39,6 +50,10 @@ let CompactionSettingsService = class CompactionSettingsService {
|
|
|
39
50
|
resolve(orgId) {
|
|
40
51
|
return resolveCompactionSettings(this.settings, this.db.db, orgId);
|
|
41
52
|
}
|
|
53
|
+
/** What a model step reads for `orgId`: the compaction and prompt cache settings, one read each. */
|
|
54
|
+
resolveStep(orgId) {
|
|
55
|
+
return resolveStepSettings(this.settings, this.db.db, orgId);
|
|
56
|
+
}
|
|
42
57
|
};
|
|
43
58
|
CompactionSettingsService = __decorate([
|
|
44
59
|
Injectable(),
|
|
@@ -37,7 +37,9 @@ export interface ForcedCompaction {
|
|
|
37
37
|
* settings) and calls the shared {@link runCompaction} with `force: true`: the trigger,
|
|
38
38
|
* `enabled: false` and the failure backoff are bypassed, the compaction plan is still required, with
|
|
39
39
|
* the manual rule (`manual: true`: every turn before the latest summarized, about a fifth of the
|
|
40
|
-
* window of the latest turn kept; maintainer decision 2026-11-28).
|
|
40
|
+
* window of the latest turn kept; maintainer decision 2026-11-28). A manual compaction always
|
|
41
|
+
* summarizes the transcript with that plan, on a model the in-context gate lists too (ruling R13,
|
|
42
|
+
* idle compaction spec §9.4).
|
|
41
43
|
*
|
|
42
44
|
* The run writes only its outcome, with `step: 0`: `compaction_summary` / `compaction_failed` + the
|
|
43
45
|
* summary calls' `usage`, or `compaction_skipped` when there is nothing to summarize (maintainer
|
|
@@ -19,7 +19,9 @@ import { RunSteps } from "./run-steps.js";
|
|
|
19
19
|
* settings) and calls the shared {@link runCompaction} with `force: true`: the trigger,
|
|
20
20
|
* `enabled: false` and the failure backoff are bypassed, the compaction plan is still required, with
|
|
21
21
|
* the manual rule (`manual: true`: every turn before the latest summarized, about a fifth of the
|
|
22
|
-
* window of the latest turn kept; maintainer decision 2026-11-28).
|
|
22
|
+
* window of the latest turn kept; maintainer decision 2026-11-28). A manual compaction always
|
|
23
|
+
* summarizes the transcript with that plan, on a model the in-context gate lists too (ruling R13,
|
|
24
|
+
* idle compaction spec §9.4).
|
|
23
25
|
*
|
|
24
26
|
* The run writes only its outcome, with `step: 0`: `compaction_summary` / `compaction_failed` + the
|
|
25
27
|
* summary calls' `usage`, or `compaction_skipped` when there is nothing to summarize (maintainer
|
|
@@ -57,6 +57,11 @@ export interface ModelCallMeta {
|
|
|
57
57
|
toolsOmitted?: true;
|
|
58
58
|
/** 请求的 `toolChoice`(收尾调用为 `"none"`);未设置则没有该字段。 */
|
|
59
59
|
toolChoice?: "auto" | "none";
|
|
60
|
+
/**
|
|
61
|
+
* The request's prompt cache lifetime (`ModelRequest.cacheTtl`, seconds); absent when the
|
|
62
|
+
* request named none. A transport option, not model-visible.
|
|
63
|
+
*/
|
|
64
|
+
cacheTtl?: number;
|
|
60
65
|
/**
|
|
61
66
|
* 请求里每个附件的处理结果(按首次出现,同一附件一条);发了字节的带 finalize 时的 etag。没有媒体则没有该字段。
|
|
62
67
|
*/
|
|
@@ -115,6 +120,12 @@ export interface BuildModelRequestInput {
|
|
|
115
120
|
toolSearch?: boolean;
|
|
116
121
|
/** 本次请求的 `ModelRequest.toolChoice`;只在有工具时生效(没有工具时请求与 meta 都不带)。 */
|
|
117
122
|
toolChoice?: "auto" | "none";
|
|
123
|
+
/**
|
|
124
|
+
* The prompt cache lifetime to ask for (`ModelRequest.cacheTtl`, seconds), copied into the
|
|
125
|
+
* request and `meta`; absent sends none (the model's default). The runtime chooses it with
|
|
126
|
+
* `selectCacheTtl`, a reconstruction passes the recorded or recomputed value. Not model-visible.
|
|
127
|
+
*/
|
|
128
|
+
cacheTtl?: number;
|
|
118
129
|
/**
|
|
119
130
|
* 日志里媒体引用(`source.kind === "ref"`)对应的附件行(声明大小、PDF 页数):附件 id → 信息;
|
|
120
131
|
* 缺省表示没有行(已删除)→「不再可用」占位。预算({@link planMedia})只按这里的声明大小计算,结果确定。
|
|
@@ -344,11 +355,17 @@ export declare function summaryKeepsTail(events: readonly ConversationEvent[], s
|
|
|
344
355
|
* plain statement that the earlier conversation was compacted into it (maintainer decision
|
|
345
356
|
* 2026-11-28), then what follows it. `openers` is the number of covered opening messages re-rendered right after this
|
|
346
357
|
* text ({@link summaryOpeners}); `keptTail` says whether newer messages kept verbatim follow
|
|
347
|
-
* ({@link summaryKeepsTail})
|
|
358
|
+
* ({@link summaryKeepsTail}); `method` is the summary's `compaction_summary.method` (idle
|
|
359
|
+
* compaction spec §9.4): an in-context summary was written from the whole conversation up to its
|
|
360
|
+
* boundary, so its tail sentence says only that it covers what came before the kept messages; a
|
|
361
|
+
* transcript one (or one without the field) says it was written without seeing them. With
|
|
362
|
+
* boundary mode `all` an in-context summary normally keeps no tail (only messages logged while it
|
|
363
|
+
* was written follow it). Model-facing English, derived from the log alone.
|
|
348
364
|
*/
|
|
349
365
|
export declare function summaryText(summary: string, framing: {
|
|
350
366
|
openers: number;
|
|
351
367
|
keptTail: boolean;
|
|
368
|
+
method?: "transcript" | "in_context";
|
|
352
369
|
}): string;
|
|
353
370
|
/**
|
|
354
371
|
* 由会话事件日志 + agent 定义构建模型请求(纯函数,不做 I/O)。
|