@capybara-hq/kernel 0.1.0-rc.61 → 0.1.0-rc.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/attachments.controller.d.ts +11 -3
- package/dist/conversations/attachments.controller.js +18 -5
- package/dist/conversations/conversations.controller.d.ts +11 -2
- package/dist/conversations/conversations.controller.js +17 -4
- package/dist/conversations/conversations.schemas.d.ts +8 -0
- package/dist/conversations/conversations.schemas.js +6 -0
- package/package.json +2 -2
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.47";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -8,14 +8,22 @@ declare const CreateBody: z.ZodObject<{
|
|
|
8
8
|
contentType: z.ZodString;
|
|
9
9
|
size: z.ZodNumber;
|
|
10
10
|
}, z.core.$strict>;
|
|
11
|
+
declare const DownloadQuery: z.ZodObject<{
|
|
12
|
+
as: z.ZodOptional<z.ZodEnum<{
|
|
13
|
+
url: "url";
|
|
14
|
+
}>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
11
16
|
/**
|
|
12
17
|
* 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
|
|
13
18
|
* 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
|
|
14
19
|
* 2. 浏览器直传对象存储;
|
|
15
20
|
* 3. `POST /:id/finalize` 核对大小与类型;
|
|
16
21
|
* 4. 发消息时在 `files` 里引用 id。
|
|
17
|
-
*
|
|
18
|
-
*
|
|
22
|
+
* Download: `GET /:id/download` redirects (302) to the presigned URL (`Cache-Control: private,
|
|
23
|
+
* max-age=60`); `?as=url` answers `{ url }` with that address instead. Limits: `GET /limits` (types,
|
|
24
|
+
* per-file size, files per message, the media budget per request, whether storage is available; for the
|
|
25
|
+
* web's pre-checks; needs no object store). Without an object store the other routes answer 503
|
|
26
|
+
* `storage.unavailable`.
|
|
19
27
|
*/
|
|
20
28
|
export declare class AttachmentsController {
|
|
21
29
|
private readonly attachments;
|
|
@@ -23,6 +31,6 @@ export declare class AttachmentsController {
|
|
|
23
31
|
limits(principal: Principal): AttachmentLimits;
|
|
24
32
|
create(principal: Principal, org: OrgContext, body: z.infer<typeof CreateBody>): Promise<CreatedAttachment>;
|
|
25
33
|
finalize(principal: Principal, org: OrgContext, id: string): Promise<AttachmentView>;
|
|
26
|
-
download(principal: Principal, org: OrgContext, id: string, reply: FastifyReply): Promise<void>;
|
|
34
|
+
download(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof DownloadQuery>, reply: FastifyReply): Promise<void>;
|
|
27
35
|
}
|
|
28
36
|
export {};
|
|
@@ -12,9 +12,10 @@ import { Controller, Get, HttpCode, Inject, Param, Post, Res } from "@nestjs/com
|
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { CurrentPrincipal, requireUser } from "../identity/principal.js";
|
|
14
14
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
15
|
-
import { ZBody } from "../infra/validation/zod-params.js";
|
|
15
|
+
import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
|
|
16
16
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
17
17
|
import { ATTACHMENT_DOWNLOAD_CACHE_SECONDS, AttachmentsService, } from "./attachments.service.js";
|
|
18
|
+
import { DOWNLOAD_AS } from "./conversations.schemas.js";
|
|
18
19
|
const CreateBody = z
|
|
19
20
|
.object({
|
|
20
21
|
name: z
|
|
@@ -28,14 +29,21 @@ const CreateBody = z
|
|
|
28
29
|
.strict();
|
|
29
30
|
class AttachmentCreateBodyDto extends createZodDto(CreateBody, "AttachmentCreateBody") {
|
|
30
31
|
}
|
|
32
|
+
// Not strict: the web adds a cache-busting `retry=1` when it reloads a failed image.
|
|
33
|
+
const DownloadQuery = z.object({ as: DOWNLOAD_AS.optional() });
|
|
34
|
+
class AttachmentDownloadQueryDto extends createZodDto(DownloadQuery, "AttachmentDownloadQuery") {
|
|
35
|
+
}
|
|
31
36
|
/**
|
|
32
37
|
* 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
|
|
33
38
|
* 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
|
|
34
39
|
* 2. 浏览器直传对象存储;
|
|
35
40
|
* 3. `POST /:id/finalize` 核对大小与类型;
|
|
36
41
|
* 4. 发消息时在 `files` 里引用 id。
|
|
37
|
-
*
|
|
38
|
-
*
|
|
42
|
+
* Download: `GET /:id/download` redirects (302) to the presigned URL (`Cache-Control: private,
|
|
43
|
+
* max-age=60`); `?as=url` answers `{ url }` with that address instead. Limits: `GET /limits` (types,
|
|
44
|
+
* per-file size, files per message, the media budget per request, whether storage is available; for the
|
|
45
|
+
* web's pre-checks; needs no object store). Without an object store the other routes answer 503
|
|
46
|
+
* `storage.unavailable`.
|
|
39
47
|
*/
|
|
40
48
|
let AttachmentsController = class AttachmentsController {
|
|
41
49
|
attachments;
|
|
@@ -54,9 +62,13 @@ let AttachmentsController = class AttachmentsController {
|
|
|
54
62
|
const p = requireUser(principal);
|
|
55
63
|
return this.attachments.finalize(org.orgId, p.account.id, id);
|
|
56
64
|
}
|
|
57
|
-
async download(principal, org, id, reply) {
|
|
65
|
+
async download(principal, org, id, q, reply) {
|
|
58
66
|
const p = requireUser(principal);
|
|
59
67
|
const location = await this.attachments.downloadUrl(org.orgId, p.account.id, id);
|
|
68
|
+
if (q.as === "url") {
|
|
69
|
+
await reply.header("cache-control", "private, no-store").send({ url: location });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
60
72
|
// 浏览器可在短时间内复用跳转(同一页面的缩略图);预签名有效期不短于这段时间
|
|
61
73
|
await reply
|
|
62
74
|
.header("cache-control", `private, max-age=${ATTACHMENT_DOWNLOAD_CACHE_SECONDS}`)
|
|
@@ -89,7 +101,8 @@ __decorate([
|
|
|
89
101
|
__param(0, CurrentPrincipal()),
|
|
90
102
|
__param(1, CurrentOrg()),
|
|
91
103
|
__param(2, Param("id")),
|
|
92
|
-
__param(3,
|
|
104
|
+
__param(3, ZQuery(AttachmentDownloadQueryDto)),
|
|
105
|
+
__param(4, Res())
|
|
93
106
|
], AttachmentsController.prototype, "download", null);
|
|
94
107
|
AttachmentsController = __decorate([
|
|
95
108
|
Controller("api/v1/orgs/:orgId/attachments"),
|
|
@@ -39,12 +39,19 @@ declare const OutputQuery: z.ZodObject<{
|
|
|
39
39
|
declare const FileContentQuery: z.ZodObject<{
|
|
40
40
|
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
41
41
|
}, z.core.$strip>;
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* `inline=1`: open inline (bitmaps only, see ConversationArtifacts). `as=url`: answer `{ url }`
|
|
44
|
+
* (the presigned location the 302 would send) instead of redirecting, so a page can hand a
|
|
45
|
+
* cookie-free URL to the system browser (a native shell's `openExternal@1`).
|
|
46
|
+
*/
|
|
43
47
|
declare const DownloadQuery: z.ZodObject<{
|
|
44
48
|
inline: z.ZodOptional<z.ZodEnum<{
|
|
45
49
|
0: "0";
|
|
46
50
|
1: "1";
|
|
47
51
|
}>>;
|
|
52
|
+
as: z.ZodOptional<z.ZodEnum<{
|
|
53
|
+
url: "url";
|
|
54
|
+
}>>;
|
|
48
55
|
}, z.core.$strip>;
|
|
49
56
|
declare const MessageBody: z.ZodObject<{
|
|
50
57
|
text: z.ZodString;
|
|
@@ -215,7 +222,9 @@ export declare class ConversationsController {
|
|
|
215
222
|
output: OutputPage;
|
|
216
223
|
}>;
|
|
217
224
|
/**
|
|
218
|
-
*
|
|
225
|
+
* Download an artifact the agent delivered (`artifact_created`): a 302 to the presigned URL (always
|
|
226
|
+
* `attachment`, with the file name);
|
|
227
|
+
* `as=url` answers `{ url }` with that address instead (never cached).
|
|
219
228
|
* 会话可见性与会话流相同,不可见 → `conversation.not_found`;不是该会话的产物 → `conversation.artifact_not_found`。
|
|
220
229
|
*/
|
|
221
230
|
downloadArtifact(principal: Principal, org: OrgContext, id: string, artifactId: string, q: z.infer<typeof DownloadQuery>, reply: FastifyReply): Promise<void>;
|
|
@@ -18,7 +18,7 @@ import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
|
18
18
|
import { MAX_ATTACHMENTS } from "../tools/connector-content.js";
|
|
19
19
|
import { ConversationToolInfo, TOOL_INFO_KEY_MAX, TOOL_INFO_MAX_KEYS, } from "../tools/info.js";
|
|
20
20
|
import { ARTIFACT_DOWNLOAD_CACHE_SECONDS, ConversationArtifacts, } from "./artifacts.js";
|
|
21
|
-
import { CompactBody, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
|
|
21
|
+
import { CompactBody, DOWNLOAD_AS, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
|
|
22
22
|
import { ConversationsService, } from "./conversations.service.js";
|
|
23
23
|
import { ConversationDeviceStatus } from "./device-status.js";
|
|
24
24
|
import { ConversationFiles, FILE_CONTENT_MAX_BYTES } from "./files.js";
|
|
@@ -46,8 +46,15 @@ const OutputQuery = z.object({
|
|
|
46
46
|
const FileContentQuery = z.object({
|
|
47
47
|
limit: z.coerce.number().int().min(1).max(FILE_CONTENT_MAX_BYTES).default(FILE_CONTENT_MAX_BYTES),
|
|
48
48
|
});
|
|
49
|
-
/**
|
|
50
|
-
|
|
49
|
+
/**
|
|
50
|
+
* `inline=1`: open inline (bitmaps only, see ConversationArtifacts). `as=url`: answer `{ url }`
|
|
51
|
+
* (the presigned location the 302 would send) instead of redirecting, so a page can hand a
|
|
52
|
+
* cookie-free URL to the system browser (a native shell's `openExternal@1`).
|
|
53
|
+
*/
|
|
54
|
+
const DownloadQuery = z.object({
|
|
55
|
+
inline: z.enum(["0", "1"]).optional(),
|
|
56
|
+
as: DOWNLOAD_AS.optional(),
|
|
57
|
+
});
|
|
51
58
|
const MessageFields = z.object({
|
|
52
59
|
/** 用户输入的文本;只有带 `files` 且不带 `attachments` 时可以为空(只发图片 / 文件)。 */
|
|
53
60
|
text: z.string().max(100_000),
|
|
@@ -333,7 +340,9 @@ let ConversationsController = class ConversationsController {
|
|
|
333
340
|
return { output: await this.outputs.read(org.orgId, id, p.account.id, outputId, q) };
|
|
334
341
|
}
|
|
335
342
|
/**
|
|
336
|
-
*
|
|
343
|
+
* Download an artifact the agent delivered (`artifact_created`): a 302 to the presigned URL (always
|
|
344
|
+
* `attachment`, with the file name);
|
|
345
|
+
* `as=url` answers `{ url }` with that address instead (never cached).
|
|
337
346
|
* 会话可见性与会话流相同,不可见 → `conversation.not_found`;不是该会话的产物 → `conversation.artifact_not_found`。
|
|
338
347
|
*/
|
|
339
348
|
async downloadArtifact(principal, org, id, artifactId, q, reply) {
|
|
@@ -341,6 +350,10 @@ let ConversationsController = class ConversationsController {
|
|
|
341
350
|
const { url } = await this.artifacts.downloadUrl(org.orgId, id, p.account.id, artifactId, {
|
|
342
351
|
inline: q.inline === "1",
|
|
343
352
|
});
|
|
353
|
+
if (q.as === "url") {
|
|
354
|
+
await reply.header("cache-control", "private, no-store").send({ url });
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
344
357
|
await reply
|
|
345
358
|
.header("cache-control", `private, max-age=${ARTIFACT_DOWNLOAD_CACHE_SECONDS}`)
|
|
346
359
|
.redirect(url, 302);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { RouteSchemas } from "../platform/route-schemas.js";
|
|
3
|
+
/**
|
|
4
|
+
* The download routes' answer form: `as=url` answers `{ url }` (the presigned location the 302
|
|
5
|
+
* would send, never cached) so a page can hand a cookie-free URL to the system browser (a native
|
|
6
|
+
* shell's `openExternal@1`). Shared by the attachment and the artifact download routes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DOWNLOAD_AS: z.ZodEnum<{
|
|
9
|
+
url: "url";
|
|
10
|
+
}>;
|
|
3
11
|
/** Shared by the list and groups queries: title search, run activity and the archived list. */
|
|
4
12
|
export declare const searchFields: {
|
|
5
13
|
q: z.ZodOptional<z.ZodString>;
|
|
@@ -2,6 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import { CONTROL_OR_HIDDEN_RE } from "../text.js";
|
|
3
3
|
import { CONVERSATION_TITLE_MAX_CHARS } from "./conversations.service.js";
|
|
4
4
|
import { FILES_PAGE_MAX } from "./files.js";
|
|
5
|
+
/**
|
|
6
|
+
* The download routes' answer form: `as=url` answers `{ url }` (the presigned location the 302
|
|
7
|
+
* would send, never cached) so a page can hand a cookie-free URL to the system browser (a native
|
|
8
|
+
* shell's `openExternal@1`). Shared by the attachment and the artifact download routes.
|
|
9
|
+
*/
|
|
10
|
+
export const DOWNLOAD_AS = z.enum(["url"]);
|
|
5
11
|
/** Shared by the list and groups queries: title search, run activity and the archived list. */
|
|
6
12
|
export const searchFields = {
|
|
7
13
|
q: z.string().min(1).max(100).optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.62",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.47"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|