@capybara-hq/kernel 0.1.0-rc.86 → 0.1.0-rc.88

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.
Files changed (46) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/catalog/marketplaces.service.d.ts +1 -1
  3. package/dist/conversations/conversations.schemas.d.ts +2 -1
  4. package/dist/conversations/conversations.schemas.js +2 -1
  5. package/dist/ctx/create-ctx.d.ts +1 -1
  6. package/dist/ctx/create-ctx.js +11 -5
  7. package/dist/errors.d.ts +4 -0
  8. package/dist/errors.js +4 -0
  9. package/dist/files/files.module.d.ts +4 -1
  10. package/dist/files/files.module.js +6 -2
  11. package/dist/files/previewers.controller.d.ts +12 -0
  12. package/dist/files/previewers.controller.js +52 -0
  13. package/dist/files/previewers.d.ts +46 -3
  14. package/dist/files/previewers.js +107 -11
  15. package/dist/html/html-type.d.ts +2 -0
  16. package/dist/html/html-type.js +4 -0
  17. package/dist/http/plugin-route-access.js +1 -0
  18. package/dist/platform/exclusions.js +15 -0
  19. package/dist/platform/ops/skills.ops.d.ts +3 -1
  20. package/dist/platform/ops/skills.ops.js +30 -5
  21. package/dist/sandbox/device-services.d.ts +14 -4
  22. package/dist/sandbox/device-services.js +24 -7
  23. package/dist/sandbox/sandbox.service.d.ts +21 -0
  24. package/dist/sandbox/sandbox.service.js +76 -0
  25. package/dist/skills/skill-files.d.ts +91 -0
  26. package/dist/skills/skill-files.js +144 -0
  27. package/dist/skills/skills.controller.d.ts +23 -3
  28. package/dist/skills/skills.controller.js +74 -6
  29. package/dist/skills/skills.module.js +3 -0
  30. package/dist/skills/skills.schemas.d.ts +47 -0
  31. package/dist/skills/skills.schemas.js +67 -1
  32. package/dist/skills/skills.service.d.ts +28 -3
  33. package/dist/skills/skills.service.js +38 -34
  34. package/dist/tools/builtins/sandbox/deliver.d.ts +1 -0
  35. package/dist/tools/builtins/sandbox/deliver.js +7 -0
  36. package/dist/tools/builtins/skill-load.d.ts +8 -2
  37. package/dist/tools/builtins/skill-load.js +13 -4
  38. package/dist/ui/embed-token.d.ts +1 -1
  39. package/dist/ui/embed-token.js +43 -5
  40. package/dist/ui/ui.schemas.d.ts +3 -0
  41. package/dist/ui/ui.schemas.js +8 -0
  42. package/dist/ui/views.controller.d.ts +6 -4
  43. package/dist/ui/views.controller.js +22 -4
  44. package/dist/ui/views.d.ts +22 -1
  45. package/dist/ui/views.js +44 -1
  46. package/package.json +2 -2
@@ -7,13 +7,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { Controller, Delete, Get, HttpCode, Inject, Param, Post, Put } from "@nestjs/common";
10
+ import { Controller, Delete, Get, Header, HttpCode, Inject, Param, Post, Put, Res, } from "@nestjs/common";
11
11
  import { OwnedItems } from "../catalog/owned-items.js";
12
+ import { isInlineArtifactType } from "../conversations/artifacts.js";
12
13
  import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
13
14
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
14
- import { ZBody, ZParam } from "../infra/validation/zod-params.js";
15
+ import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
15
16
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
16
- import { SkillCreateBody, SkillIdParams, SkillShareableSchema, SkillUploadBody as UploadBody, } from "./skills.schemas.js";
17
+ import { attachmentDisposition } from "../shares/share-open.service.js";
18
+ import { SkillFiles, skillFileName, skillFileSentType } from "./skill-files.js";
19
+ import { SkillCreateBody, SkillFileContentQuery, SkillFilesQuery, SkillIdParams, SkillShareableSchema, SkillUploadBody as UploadBody, } from "./skills.schemas.js";
17
20
  import { SkillsService, } from "./skills.service.js";
18
21
  class SkillUploadBodyDto extends createZodDto(UploadBody, "SkillUploadBody") {
19
22
  }
@@ -24,10 +27,14 @@ class SkillIdParamsDto extends createZodDto(SkillIdParams, "SkillIdParams") {
24
27
  }
25
28
  class SkillShareableBody extends createZodDto(ShareableBody, "SkillShareableBody") {
26
29
  }
30
+ class SkillFilesQueryDto extends createZodDto(SkillFilesQuery, "SkillFilesQuery") {
31
+ }
32
+ class SkillFileContentQueryDto extends createZodDto(SkillFileContentQuery, "SkillFileContentQuery") {
33
+ }
27
34
  /**
28
35
  * The org skill library (`/api/v1/orgs/:orgId/skills`, human users only):
29
36
  * - read: `skills.read` (member and up) — `GET /` list, `GET /:id` detail (versions and file
30
- * lists);
37
+ * lists), `GET /:id/files` a version's files and `GET /:id/files/content` one file's bytes;
31
38
  * - write: `skills.manage` (admin and up) —
32
39
  * 1. `POST /uploads` registers a skill package upload (`application/zip`, ≤ 50MB, returns a
33
40
  * presigned form, used like chat attachments);
@@ -44,11 +51,13 @@ class SkillShareableBody extends createZodDto(ShareableBody, "SkillShareableBody
44
51
  let SkillsController = class SkillsController {
45
52
  skills;
46
53
  owned;
54
+ files;
47
55
  constructor(skills,
48
56
  /** The org's own items: 可共享 and the delete of a promoted skill (rulings P3-3, P3-19). */
49
- owned) {
57
+ owned, files) {
50
58
  this.skills = skills;
51
59
  this.owned = owned;
60
+ this.files = files;
52
61
  }
53
62
  async createUpload(principal, org, body) {
54
63
  const p = requireUser(principal);
@@ -67,6 +76,46 @@ let SkillsController = class SkillsController {
67
76
  requireUser(principal);
68
77
  return this.skills.get(org.orgId, id);
69
78
  }
79
+ /**
80
+ * The files of a version of the skill (`?version=`, default the current one): `{ version, files:
81
+ * { path, size, contentType, previewable }[] }`. Visibility as `GET /:id`; an unknown version →
82
+ * 404 `skill.file_not_found`.
83
+ */
84
+ async listFiles(principal, org, params, q) {
85
+ requireUser(principal);
86
+ return this.files.list(org.orgId, params.id, q.version);
87
+ }
88
+ /**
89
+ * One file's bytes (`?path=` a path of the version's manifest, `version=`, `limit=`, `inline=`),
90
+ * checked against the manifest (409 `skill.file_changed`); unknown version or path → 404
91
+ * `skill.file_not_found`. Never sniffed and sandboxed; `attachment` unless `inline=1` for a
92
+ * raster image (HTML and SVG never inline). A text file is sent as `text/plain`, anything not
93
+ * inline as `application/octet-stream`, the type by extension in `X-Content-Original-Type`;
94
+ * `X-Content-Truncated: true` when `limit` cut it. `as=url` (not with `limit`, 400) answers
95
+ * `{ url }` instead: a short-lived presigned attachment URL for that object, after the same
96
+ * manifest check (ruling R3: a native shell hands it to the system browser).
97
+ */
98
+ async fileContent(principal, org, params, q, reply) {
99
+ requireUser(principal);
100
+ if (q.as === "url") {
101
+ const { url } = await this.files.downloadUrl(org.orgId, params.id, q.version, q.path);
102
+ await reply.header("cache-control", "private, no-store").send({ url });
103
+ return;
104
+ }
105
+ const { file, body, truncated } = await this.files.read(org.orgId, params.id, q.version, q.path, q.limit);
106
+ const inline = q.inline === "1" && isInlineArtifactType(file.contentType);
107
+ const name = skillFileName(file.path);
108
+ reply
109
+ .header("content-type", skillFileSentType(file.contentType, inline))
110
+ .header("x-content-original-type", file.contentType)
111
+ .header("content-disposition", inline ? "inline" : attachmentDisposition(name))
112
+ .header("cache-control", "private, no-store")
113
+ .header("x-content-type-options", "nosniff")
114
+ .header("content-security-policy", "sandbox; default-src 'none'");
115
+ if (truncated)
116
+ reply.header("x-content-truncated", "true");
117
+ await reply.send(body);
118
+ }
70
119
  /**
71
120
  * Sets 可共享 on the org's own skill (`{ shareable }` -> 200 `{ id, shareable }`): only an org
72
121
  * skill of the org's own (P3-6: an agent's skill or a copy of another owner's platform skill ->
@@ -124,6 +173,24 @@ __decorate([
124
173
  __param(1, CurrentOrg()),
125
174
  __param(2, Param("id"))
126
175
  ], SkillsController.prototype, "get", null);
176
+ __decorate([
177
+ Get(":id/files"),
178
+ Header("cache-control", "private, no-store"),
179
+ OrgAction("skills.read"),
180
+ __param(0, CurrentPrincipal()),
181
+ __param(1, CurrentOrg()),
182
+ __param(2, ZParam(SkillIdParamsDto)),
183
+ __param(3, ZQuery(SkillFilesQueryDto))
184
+ ], SkillsController.prototype, "listFiles", null);
185
+ __decorate([
186
+ Get(":id/files/content"),
187
+ OrgAction("skills.read"),
188
+ __param(0, CurrentPrincipal()),
189
+ __param(1, CurrentOrg()),
190
+ __param(2, ZParam(SkillIdParamsDto)),
191
+ __param(3, ZQuery(SkillFileContentQueryDto)),
192
+ __param(4, Res())
193
+ ], SkillsController.prototype, "fileContent", null);
127
194
  __decorate([
128
195
  Put(":id/shareable"),
129
196
  OrgAction("skills.manage"),
@@ -150,6 +217,7 @@ __decorate([
150
217
  SkillsController = __decorate([
151
218
  Controller("api/v1/orgs/:orgId/skills"),
152
219
  __param(0, Inject(SkillsService)),
153
- __param(1, Inject(OwnedItems))
220
+ __param(1, Inject(OwnedItems)),
221
+ __param(2, Inject(SkillFiles))
154
222
  ], SkillsController);
155
223
  export { SkillsController };
@@ -17,6 +17,7 @@ import { AgentSkillsService } from "./agent-skills.service.js";
17
17
  import { SkillsCatalogService } from "./catalog.js";
18
18
  import { SkillChangesService } from "./changes.service.js";
19
19
  import { SkillInvoker } from "./invoke.js";
20
+ import { SkillFiles } from "./skill-files.js";
20
21
  import { SkillsService } from "./skills.service.js";
21
22
  /**
22
23
  * Skills: the org library, agent-written skills and their approvals, the run start's skills
@@ -41,6 +42,7 @@ SkillsModule = __decorate([
41
42
  providers: [
42
43
  AgentSkillsService,
43
44
  SkillsService,
45
+ SkillFiles,
44
46
  SkillChangesService,
45
47
  SkillsCatalogService,
46
48
  SkillInvoker,
@@ -48,6 +50,7 @@ SkillsModule = __decorate([
48
50
  exports: [
49
51
  AgentSkillsService,
50
52
  SkillsService,
53
+ SkillFiles,
51
54
  SkillChangesService,
52
55
  SkillsCatalogService,
53
56
  SkillInvoker,
@@ -18,6 +18,53 @@ export declare const SkillIdParams: z.ZodObject<{
18
18
  export declare const SkillPathParams: z.ZodObject<{
19
19
  id: z.ZodString;
20
20
  }, z.core.$strip>;
21
+ /**
22
+ * A path of a skill version's manifest as a request names it: at most
23
+ * {@link SKILL_LIMITS.pathMaxChars} code points, the manifest's own unit (`chars` in the SDK). The
24
+ * code point check is explicit rather than left to how a zod version measures strings; `max` in
25
+ * UTF-16 code units only bounds the work before it.
26
+ */
27
+ export declare const SkillFilePathSchema: z.ZodString;
28
+ /** `?version=` of `GET /skills/:id/files`: a version of the skill (default: the current one). */
29
+ export declare const SkillFilesQuery: z.ZodObject<{
30
+ version: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
31
+ }, z.core.$strict>;
32
+ /**
33
+ * `GET /skills/:id/files/content`: `path` a path of that version's manifest, `limit` at most that
34
+ * many bytes, `inline=1` inline for a raster image (never for HTML or SVG), `as=url` a presigned
35
+ * download URL instead of the bytes (not with `limit`).
36
+ */
37
+ export declare const SkillFileContentQuery: z.ZodObject<{
38
+ version: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
39
+ path: z.ZodString;
40
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
41
+ inline: z.ZodOptional<z.ZodEnum<{
42
+ 0: "0";
43
+ 1: "1";
44
+ }>>;
45
+ as: z.ZodOptional<z.ZodEnum<{
46
+ url: "url";
47
+ }>>;
48
+ }, z.core.$strict>;
49
+ /** `?version=&path=` of `GET /skills/:id/files/previewers`: one file of a version. */
50
+ export declare const SkillFilePreviewersQuery: z.ZodObject<{
51
+ version: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
52
+ path: z.ZodString;
53
+ }, z.core.$strict>;
54
+ /** `GET /skills/:id/files/previews/:plugin/:previewerId?version=&path=&locale=`. */
55
+ export declare const SkillFilePreviewQuery: z.ZodObject<{
56
+ version: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
57
+ path: z.ZodString;
58
+ locale: z.ZodDefault<z.ZodEnum<{
59
+ en: "en";
60
+ zh: "zh";
61
+ }>>;
62
+ }, z.core.$strict>;
63
+ export declare const SkillFilePreviewParams: z.ZodObject<{
64
+ id: z.ZodString;
65
+ plugin: z.ZodString;
66
+ previewerId: z.ZodString;
67
+ }, z.core.$strip>;
21
68
  export declare const SkillShareableSchema: z.ZodObject<{
22
69
  shareable: z.ZodBoolean;
23
70
  }, z.core.$strict>;
@@ -1,6 +1,7 @@
1
- import { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
1
+ import { hasControlChars, MEDIA_NAME_MAX_CHARS, SKILL_LIMITS } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { SKILL_PACKAGE_UPLOAD_MAX_BYTES } from "../conversations/attachments.service.js";
4
+ import { DOWNLOAD_AS } from "../conversations/conversations.schemas.js";
4
5
  /** `POST /skills/uploads`: registers a skill package upload (a presigned form). */
5
6
  export const SkillUploadBody = z
6
7
  .object({
@@ -20,6 +21,51 @@ export const SkillCreateBody = z
20
21
  export const SkillIdParams = z.object({ id: z.string().min(1).max(100) });
21
22
  /** `:id` where the route takes it as is (`@Param`). */
22
23
  export const SkillPathParams = z.object({ id: z.string().min(1) });
24
+ /**
25
+ * A path of a skill version's manifest as a request names it: at most
26
+ * {@link SKILL_LIMITS.pathMaxChars} code points, the manifest's own unit (`chars` in the SDK). The
27
+ * code point check is explicit rather than left to how a zod version measures strings; `max` in
28
+ * UTF-16 code units only bounds the work before it.
29
+ */
30
+ export const SkillFilePathSchema = z
31
+ .string()
32
+ .min(1)
33
+ .max(2 * SKILL_LIMITS.pathMaxChars)
34
+ .refine((s) => [...s].length <= SKILL_LIMITS.pathMaxChars, {
35
+ message: `path must be at most ${SKILL_LIMITS.pathMaxChars} characters`,
36
+ });
37
+ /** `?version=` of `GET /skills/:id/files`: a version of the skill (default: the current one). */
38
+ export const SkillFilesQuery = z
39
+ .object({ version: z.coerce.number().int().min(1).max(2_147_483_647).optional() })
40
+ .strict();
41
+ /**
42
+ * `GET /skills/:id/files/content`: `path` a path of that version's manifest, `limit` at most that
43
+ * many bytes, `inline=1` inline for a raster image (never for HTML or SVG), `as=url` a presigned
44
+ * download URL instead of the bytes (not with `limit`).
45
+ */
46
+ export const SkillFileContentQuery = SkillFilesQuery.extend({
47
+ path: SkillFilePathSchema,
48
+ limit: z.coerce.number().int().min(1).max(SKILL_LIMITS.fileBytes).optional(),
49
+ inline: z.enum(["0", "1"]).optional(),
50
+ as: DOWNLOAD_AS.optional(),
51
+ })
52
+ .strict()
53
+ .refine((q) => q.as === undefined || q.limit === undefined, {
54
+ message: "as=url cannot be combined with limit",
55
+ path: ["limit"],
56
+ });
57
+ /** `?version=&path=` of `GET /skills/:id/files/previewers`: one file of a version. */
58
+ export const SkillFilePreviewersQuery = SkillFilesQuery.extend({
59
+ path: SkillFilePathSchema,
60
+ }).strict();
61
+ /** `GET /skills/:id/files/previews/:plugin/:previewerId?version=&path=&locale=`. */
62
+ export const SkillFilePreviewQuery = SkillFilePreviewersQuery.extend({
63
+ locale: z.enum(["zh", "en"]).default("en"),
64
+ }).strict();
65
+ export const SkillFilePreviewParams = SkillIdParams.extend({
66
+ plugin: z.string().min(1).max(100),
67
+ previewerId: z.string().min(1).max(100),
68
+ });
23
69
  export const SkillShareableSchema = z.object({ shareable: z.boolean() }).strict();
24
70
  /** `:id` of `GET /skill-changes/:id` (taken as is). */
25
71
  export const SkillChangePathParams = z.object({ id: z.string().min(1).max(100) });
@@ -73,6 +119,26 @@ export const SKILL_ROUTES = [
73
119
  },
74
120
  { route: "GET /api/v1/orgs/:orgId/skills" },
75
121
  { route: "GET /api/v1/orgs/:orgId/skills/:id", params: SkillPathParams },
122
+ {
123
+ route: "GET /api/v1/orgs/:orgId/skills/:id/files",
124
+ params: SkillIdParams,
125
+ query: SkillFilesQuery,
126
+ },
127
+ {
128
+ route: "GET /api/v1/orgs/:orgId/skills/:id/files/content",
129
+ params: SkillIdParams,
130
+ query: SkillFileContentQuery,
131
+ },
132
+ {
133
+ route: "GET /api/v1/orgs/:orgId/skills/:id/files/previewers",
134
+ params: SkillIdParams,
135
+ query: SkillFilePreviewersQuery,
136
+ },
137
+ {
138
+ route: "GET /api/v1/orgs/:orgId/skills/:id/files/previews/:plugin/:previewerId",
139
+ params: SkillFilePreviewParams,
140
+ query: SkillFilePreviewQuery,
141
+ },
76
142
  { route: "POST /api/v1/orgs/:orgId/skills/uploads", body: SkillUploadBody },
77
143
  { route: "POST /api/v1/orgs/:orgId/skills", body: SkillCreateBody },
78
144
  {
@@ -102,6 +102,20 @@ export interface SkillDetail extends SkillSummary {
102
102
  */
103
103
  body: string | null;
104
104
  }
105
+ /** A stored version of a skill as {@link SkillsService.resolve} returns it. */
106
+ export interface ResolvedSkillVersion {
107
+ version: number;
108
+ manifest: SkillManifest;
109
+ created_by: string | null;
110
+ created_at: Date;
111
+ /** The version's snapshot `source`: `platform:<prefix>` for a platform version (`skillFileStore`). */
112
+ object_prefix: string;
113
+ }
114
+ /** A skill as the org sees it under an id (the rule of `GET /skills/:id`); versions newest first. */
115
+ export interface ResolvedSkill {
116
+ summary: SkillSummary;
117
+ versions: ResolvedSkillVersion[];
118
+ }
105
119
  /** 详情里读取 SKILL.md 正文的上限。 */
106
120
  export declare const SKILL_BODY_MAX_BYTES: number;
107
121
  /** `POST /skills` 的结果:`created` 为 true 表示新技能,否则是已有技能的新版本。 */
@@ -284,10 +298,21 @@ export declare class SkillsService {
284
298
  /** The skill's detail without `agentsOff` (no agents scan; for names and checks). */
285
299
  detail(orgId: string, skillId: string): Promise<SkillDetail>;
286
300
  /**
287
- * A platform skill's detail (phase 2): only while it is on in the org, else `skill.not_found`.
288
- * Its versions are the platform skill's.
301
+ * The skill the org sees under `skillId`, the visibility rule of `GET /skills/:id` (and of the
302
+ * skill's file routes): the org's own skill with its versions; an org copy linked to a platform
303
+ * skill without a pin (ruling B2) is the platform skill (its id, versions; `skill.not_found`
304
+ * while that skill is off in the org), except the org's own skill it promoted (ruling P3-3),
305
+ * which keeps its id and summary over the platform row's versions while it serves its stored
306
+ * version, and the platform's newer version under its id otherwise (ruling P3-4); any other id
307
+ * is a platform skill on in the org, else `skill.not_found`. Versions newest first, each with
308
+ * its snapshot `source` (`platform:<prefix>` for a platform version; see `skillFileStore`).
309
+ */
310
+ resolve(orgId: string, skillId: string): Promise<ResolvedSkill>;
311
+ /**
312
+ * A platform skill as {@link resolve} sees it (phase 2): only while it is on in the org, else
313
+ * `skill.not_found`. Its versions are the platform skill's, sources in the `platform:` form.
289
314
  */
290
- private getPlatform;
315
+ private resolvePlatform;
291
316
  /** 读某版本 SKILL.md 的正文(见 {@link SkillDetail.body});任何读取问题都返回 null,不让详情失败。 */
292
317
  private readBody;
293
318
  /**
@@ -890,6 +890,31 @@ let SkillsService = class SkillsService {
890
890
  }
891
891
  /** The skill's detail without `agentsOff` (no agents scan; for names and checks). */
892
892
  async detail(orgId, skillId) {
893
+ const { summary: s, versions } = await this.resolve(orgId, skillId);
894
+ const current = versions.find((v) => v.version === s.currentVersion);
895
+ return {
896
+ ...s,
897
+ body: current ? await this.readBody(orgId, current) : null,
898
+ versions: versions.map((v) => ({
899
+ version: v.version,
900
+ description: v.manifest.description,
901
+ files: v.manifest.files,
902
+ createdBy: v.created_by,
903
+ createdAt: v.created_at,
904
+ })),
905
+ };
906
+ }
907
+ /**
908
+ * The skill the org sees under `skillId`, the visibility rule of `GET /skills/:id` (and of the
909
+ * skill's file routes): the org's own skill with its versions; an org copy linked to a platform
910
+ * skill without a pin (ruling B2) is the platform skill (its id, versions; `skill.not_found`
911
+ * while that skill is off in the org), except the org's own skill it promoted (ruling P3-3),
912
+ * which keeps its id and summary over the platform row's versions while it serves its stored
913
+ * version, and the platform's newer version under its id otherwise (ruling P3-4); any other id
914
+ * is a platform skill on in the org, else `skill.not_found`. Versions newest first, each with
915
+ * its snapshot `source` (`platform:<prefix>` for a platform version; see `skillFileStore`).
916
+ */
917
+ async resolve(orgId, skillId) {
893
918
  const link = await this.db
894
919
  .selectFrom("skills")
895
920
  .select("platform_skill_id")
@@ -905,10 +930,13 @@ let SkillsService = class SkillsService {
905
930
  // the platform's current one, else the platform's newer version under its id (ruling P3-4)
906
931
  const served = (await skillVersionsById(this.db.db, orgId, [skillId])).get(skillId);
907
932
  if (served?.origin !== "org")
908
- return this.getPlatform(orgId, link.platform_skill_id);
933
+ return this.resolvePlatform(orgId, link.platform_skill_id);
909
934
  if (served.source.startsWith(PLATFORM_SOURCE)) {
910
- const detail = await this.getPlatform(orgId, link.platform_skill_id);
911
- return { ...detail, ...(await this.promotedSummary(skillId, link.platform_skill_id)) };
935
+ const platform = await this.resolvePlatform(orgId, link.platform_skill_id);
936
+ return {
937
+ ...platform,
938
+ summary: await this.promotedSummary(skillId, link.platform_skill_id),
939
+ };
912
940
  }
913
941
  }
914
942
  const row = await summaryQuery(this.db.db)
@@ -918,31 +946,20 @@ let SkillsService = class SkillsService {
918
946
  .where("s.deleted_at", "is", null)
919
947
  .executeTakeFirst();
920
948
  if (!row)
921
- return this.getPlatform(orgId, skillId);
949
+ return this.resolvePlatform(orgId, skillId);
922
950
  const versions = await this.db
923
951
  .selectFrom("skill_versions")
924
952
  .select(["version", "manifest", "created_by", "created_at", "object_prefix"])
925
953
  .where("skill_id", "=", skillId)
926
954
  .orderBy("version", "desc")
927
955
  .execute();
928
- const current = versions.find((v) => v.version === row.current_version);
929
- return {
930
- ...summary(row),
931
- body: current ? await this.readBody(orgId, current) : null,
932
- versions: versions.map((v) => ({
933
- version: v.version,
934
- description: v.manifest.description,
935
- files: v.manifest.files,
936
- createdBy: v.created_by,
937
- createdAt: v.created_at,
938
- })),
939
- };
956
+ return { summary: summary(row), versions };
940
957
  }
941
958
  /**
942
- * A platform skill's detail (phase 2): only while it is on in the org, else `skill.not_found`.
943
- * Its versions are the platform skill's.
959
+ * A platform skill as {@link resolve} sees it (phase 2): only while it is on in the org, else
960
+ * `skill.not_found`. Its versions are the platform skill's, sources in the `platform:` form.
944
961
  */
945
- async getPlatform(orgId, skillId) {
962
+ async resolvePlatform(orgId, skillId) {
946
963
  const usable = (await skillVersionsById(this.db.db, orgId, [skillId])).get(skillId);
947
964
  if (usable?.origin !== "platform" || usable.platformSkillId !== skillId)
948
965
  throw notFound();
@@ -957,22 +974,9 @@ let SkillsService = class SkillsService {
957
974
  .where("skill_id", "=", skillId)
958
975
  .orderBy("version", "desc")
959
976
  .execute();
960
- const current = versions.find((v) => v.version === row.current_version);
961
977
  return {
962
- ...platformSummary(row),
963
- body: current
964
- ? await this.readBody(orgId, {
965
- manifest: current.manifest,
966
- object_prefix: platformSource(current.object_prefix),
967
- })
968
- : null,
969
- versions: versions.map((v) => ({
970
- version: v.version,
971
- description: v.manifest.description,
972
- files: v.manifest.files,
973
- createdBy: v.created_by,
974
- createdAt: v.created_at,
975
- })),
978
+ summary: platformSummary(row),
979
+ versions: versions.map((v) => ({ ...v, object_prefix: platformSource(v.object_prefix) })),
976
980
  };
977
981
  }
978
982
  /** 读某版本 SKILL.md 的正文(见 {@link SkillDetail.body});任何读取问题都返回 null,不让详情失败。 */
@@ -1,5 +1,6 @@
1
1
  import type { BuiltinTool } from "../../registry.js";
2
2
  import { type SandboxToolDeps } from "./common.js";
3
+ /** The content type of a file name by its extension (Deliver, skill files); unknown: octet-stream. */
3
4
  export declare function contentTypeFor(name: string): string;
4
5
  /** 内置工具 `Deliver`:把沙箱里的文件存进对象存储,写 `artifact_created`,用户可下载。 */
5
6
  export declare function sandboxDeliverTool(deps: SandboxToolDeps): BuiltinTool;
@@ -48,6 +48,12 @@ const CONTENT_TYPES = {
48
48
  css: "text/css",
49
49
  js: "text/javascript",
50
50
  ts: "text/plain",
51
+ tsx: "text/plain",
52
+ jsx: "text/plain",
53
+ mjs: "text/javascript",
54
+ cjs: "text/javascript",
55
+ sh: "text/x-shellscript",
56
+ bash: "text/x-shellscript",
51
57
  py: "text/x-python",
52
58
  sql: "application/sql",
53
59
  pdf: "application/pdf",
@@ -67,6 +73,7 @@ const CONTENT_TYPES = {
67
73
  mp4: "video/mp4",
68
74
  wav: "audio/wav",
69
75
  };
76
+ /** The content type of a file name by its extension (Deliver, skill files); unknown: octet-stream. */
70
77
  export function contentTypeFor(name) {
71
78
  const dot = name.lastIndexOf(".");
72
79
  const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
@@ -42,9 +42,15 @@ export declare class SkillIntegrityError extends Error {
42
42
  /**
43
43
  * Reads one skill file and checks it against its manifest entry (size and sha256). A missing or
44
44
  * mismatching object throws {@link SkillIntegrityError}; a storage error is rethrown as is
45
- * (`storage.unavailable` from the store). Shared with a person's skill invocation (phase D).
45
+ * (`storage.unavailable` from the store). Shared with a person's skill invocation (phase D), the
46
+ * skill file routes and the previewers' read grant. `keepBytes`: the whole object is still read
47
+ * and hashed, but only its first `keepBytes` bytes are kept and returned (the result is shorter
48
+ * than `file.size` when the file is longer).
46
49
  */
47
- export declare function readSkillFile(store: ObjectStore, key: string, file: SkillManifest["files"][number], signal?: AbortSignal): Promise<Uint8Array>;
50
+ export declare function readSkillFile(store: ObjectStore, key: string, file: SkillManifest["files"][number], opts?: {
51
+ signal?: AbortSignal;
52
+ keepBytes?: number;
53
+ }): Promise<Uint8Array>;
48
54
  /**
49
55
  * 目录条目对应的内容,按条目的 `source`(对象前缀,T15)精确解析:先找该技能前缀相同的已生成版本(技能未删除;
50
56
  * 批准时草稿前缀原样成为版本前缀,版本号变了也能找到),再找本对话发起、仍待批准、前缀相同的技能改动(试用草稿:
@@ -120,15 +120,20 @@ export class SkillIntegrityError extends Error {
120
120
  /**
121
121
  * Reads one skill file and checks it against its manifest entry (size and sha256). A missing or
122
122
  * mismatching object throws {@link SkillIntegrityError}; a storage error is rethrown as is
123
- * (`storage.unavailable` from the store). Shared with a person's skill invocation (phase D).
123
+ * (`storage.unavailable` from the store). Shared with a person's skill invocation (phase D), the
124
+ * skill file routes and the previewers' read grant. `keepBytes`: the whole object is still read
125
+ * and hashed, but only its first `keepBytes` bytes are kept and returned (the result is shorter
126
+ * than `file.size` when the file is longer).
124
127
  */
125
- export async function readSkillFile(store, key, file, signal) {
128
+ export async function readSkillFile(store, key, file, opts = {}) {
129
+ const { signal, keepBytes = Number.POSITIVE_INFINITY } = opts;
126
130
  const got = await store.get(key, signal && { signal });
127
131
  if (!got)
128
132
  throw new SkillIntegrityError(`${key} is missing`);
129
133
  const hash = createHash("sha256");
130
134
  const chunks = [];
131
135
  let n = 0;
136
+ let kept = 0;
132
137
  const reader = got.body.getReader();
133
138
  try {
134
139
  for (;;) {
@@ -139,7 +144,11 @@ export async function readSkillFile(store, key, file, signal) {
139
144
  if (n > file.size)
140
145
  throw new SkillIntegrityError(`${key} is larger than its manifest says`);
141
146
  hash.update(value);
142
- chunks.push(value);
147
+ if (kept < keepBytes) {
148
+ const part = kept + value.byteLength > keepBytes ? value.subarray(0, keepBytes - kept) : value;
149
+ chunks.push(part);
150
+ kept += part.byteLength;
151
+ }
143
152
  }
144
153
  }
145
154
  finally {
@@ -153,7 +162,7 @@ export async function readSkillFile(store, key, file, signal) {
153
162
  /** {@link readSkillFile} for the model: integrity and storage failures become tool errors. */
154
163
  async function readVerified(store, key, file, skill, signal) {
155
164
  try {
156
- return await readSkillFile(store, key, file, signal);
165
+ return await readSkillFile(store, key, file, { signal });
157
166
  }
158
167
  catch (e) {
159
168
  if (e instanceof SkillIntegrityError)
@@ -1,4 +1,4 @@
1
- import type { EmbedClaims, OrgEmbedClaims, PlatformEmbedClaims, ShareEmbedClaims } from "@capybara-hq/plugin-sdk";
1
+ import { type EmbedClaims, type OrgEmbedClaims, type PlatformEmbedClaims, type ShareEmbedClaims } from "@capybara-hq/plugin-sdk";
2
2
  import type { Keyring } from "../ctx/secrets.js";
3
3
  /** 嵌入令牌的有效期(秒)。网页在过期前 60 秒续期。 */
4
4
  export declare const EMBED_TOKEN_TTL_SECONDS = 300;