@capybara-hq/plugin-sdk 0.1.0-rc.25 → 0.1.0-rc.26

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.
@@ -12,4 +12,6 @@ Contract: ModelProvider (`model.ts`); refs `model-provider@1` and `@2`
12
12
 
13
13
  Map the kernel's messages and tools to the vendor API and stream the result. Do not retry inside the extension; return a `ModelError` with the right kind and let the kernel degrade. History sent to the model is append-only. Declare parameters and media support.
14
14
 
15
+ Messages may carry an `image` or a `document` block, gated by `capabilities.vision` and `capabilities.documents`; the kernel replaces a block the model cannot take with an English placeholder and never sends the bytes. A `file` block is an attachment the model can only reference (an xlsx, say): the kernel resolves it to text before the request, so a provider never receives one. Resolve any block you do not recognize by skipping it. The `size` on an attachment block is display metadata (the UI chip, the reference line) and is never sent to a provider.
16
+
15
17
  See `extensions` for the rules every extension follows.
@@ -12,4 +12,6 @@ Contract: ObjectStore (`storage.ts`)
12
12
 
13
13
  Return `null` for a missing key, reject keys containing `${`, and enforce the size of presigned uploads in the store itself. The kernel adds key prefixes; extensions consume it as `ctx.storage`.
14
14
 
15
+ Optionally implement `uri(key)`: the store's canonical identifier for a key, such as `s3://bucket/key`. It is unsigned, stable and carries no credentials, and is never a presigned URL — the kernel may record it in an event log and show it to a model. A store with no notion of URIs simply leaves it out.
16
+
15
17
  See `extensions` for the rules every extension follows.
package/dist/hooks.d.ts CHANGED
@@ -49,21 +49,23 @@ export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch" | "
49
49
  */
50
50
  export type UsagePurpose = ModelCallPurpose | "embedding";
51
51
  /**
52
- * An image or document of a `model.request` payload. Hook payloads never carry media bytes or
53
- * attachment ids: each image or document block is replaced by this placeholder.
52
+ * An image, document or file of a `model.request` payload. Hook payloads never carry media bytes or
53
+ * attachment ids: each image / document / file block is replaced by this placeholder.
54
54
  * `size` is the size of the bytes sent to the provider, in bytes (0 when unknown).
55
55
  */
56
56
  export interface HookMediaPlaceholder {
57
57
  type: "media_omitted";
58
- kind: "image" | "document";
58
+ kind: "image" | "document" | "file";
59
59
  mediaType: string;
60
60
  size: number;
61
61
  }
62
- /** A content block of a `model.request` payload: image and document blocks become placeholders. */
62
+ /** A content block of a `model.request` payload: image, document and file blocks become placeholders. */
63
63
  export type HookContentBlock = Exclude<ContentBlock, {
64
64
  type: "image";
65
65
  } | {
66
66
  type: "document";
67
+ } | {
68
+ type: "file";
67
69
  }> | HookMediaPlaceholder;
68
70
  /** A message of a `model.request` payload (see {@link HookContentBlock}). */
69
71
  export type HookModelMessage = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.25";
1
+ export declare const SDK_VERSION = "0.1.0-rc.26";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.25";
1
+ export const SDK_VERSION = "0.1.0-rc.26";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/model.d.ts CHANGED
@@ -112,21 +112,37 @@ export type ContentBlock =
112
112
  isError: boolean;
113
113
  }
114
114
  /**
115
- * 图片(只出现在 user 消息里)。模型不支持 `vision` 时内核换成文字占位,插件不用把关;
116
- * 不认识此块的旧插件会跳过它。
115
+ * An image (only in user messages). When the model has no `vision` the kernel sends an English
116
+ * placeholder instead; a plugin need not check. An older plugin that does not know this block
117
+ * skips it. `size` is display metadata (the UI chip, the reference line) and is never sent.
117
118
  */
118
119
  | {
119
120
  type: "image";
120
121
  mediaType: ImageMediaType;
121
122
  source: MediaSource;
122
123
  name?: string;
124
+ size?: number;
123
125
  }
124
- /** 文档(只出现在 user 消息里),由 `capabilities.documents` 把关,规则同 image。 */
126
+ /** A document (only in user messages), gated by `capabilities.documents`; same rules as image. */
125
127
  | {
126
128
  type: "document";
127
129
  mediaType: DocumentMediaType;
128
130
  source: MediaSource;
129
131
  name?: string;
132
+ size?: number;
133
+ }
134
+ /**
135
+ * An attachment whose content the model cannot read (an xlsx, say): the kernel replaces it with
136
+ * text carrying an unsigned object reference before the request, so a provider **never** receives
137
+ * this block. `mediaType` is any non-empty `type/subtype`; `size` is display metadata (the UI
138
+ * chip, the reference line) and is never sent.
139
+ */
140
+ | {
141
+ type: "file";
142
+ mediaType: string;
143
+ source: MediaSource;
144
+ name?: string;
145
+ size?: number;
130
146
  };
131
147
  /** 媒体块 `name` 的最大长度(字符)。 */
132
148
  export declare const MEDIA_NAME_MAX_CHARS = 255;
@@ -142,9 +158,12 @@ export declare function hasControlChars(s: string): boolean;
142
158
  /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
143
159
  export declare function isAttachmentId(s: unknown): s is string;
144
160
  /**
145
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
146
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
147
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
161
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
162
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
163
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
164
+ * `attachmentId` is a UUID; `name`, when present, is a string of at most
165
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
166
+ * non-negative integer (display metadata, never sent by a plugin).
148
167
  */
149
168
  export declare function validateMediaBlock(b: unknown): string[];
150
169
  export type ModelMessage = {
package/dist/model.js CHANGED
@@ -42,14 +42,22 @@ export function hasControlChars(s) {
42
42
  export function isAttachmentId(s) {
43
43
  return typeof s === "string" && UUID_RE.test(s);
44
44
  }
45
+ /** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
46
+ const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
45
47
  const MEDIA = {
46
48
  image: { types: IMAGE_MEDIA_TYPES, limit: MEDIA_LIMITS.imageBytes },
47
49
  document: { types: DOCUMENT_MEDIA_TYPES, limit: MEDIA_LIMITS.documentBytes },
50
+ // A file the model cannot read: the kernel resolves it to text before the request, so no media
51
+ // type list applies. The byte ceiling is the one attachments already have.
52
+ file: { types: [], limit: MEDIA_LIMITS.documentBytes, anyType: true },
48
53
  };
49
54
  /**
50
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
51
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
52
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
55
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
56
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
57
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
58
+ * `attachmentId` is a UUID; `name`, when present, is a string of at most
59
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
60
+ * non-negative integer (display metadata, never sent by a plugin).
53
61
  */
54
62
  export function validateMediaBlock(b) {
55
63
  if (typeof b !== "object" || b === null || Array.isArray(b))
@@ -57,9 +65,16 @@ export function validateMediaBlock(b) {
57
65
  const o = b;
58
66
  const spec = typeof o.type === "string" && Object.hasOwn(MEDIA, o.type) ? MEDIA[o.type] : undefined;
59
67
  if (!spec)
60
- return ['block type must be "image" or "document"'];
68
+ return ['block type must be "image", "document" or "file"'];
61
69
  const errs = [];
62
- if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
70
+ if (spec.anyType) {
71
+ if (typeof o.mediaType !== "string" ||
72
+ !MEDIA_TYPE_RE.test(o.mediaType) ||
73
+ hasControlChars(o.mediaType)) {
74
+ errs.push(`${o.type} mediaType must be a non-empty type/subtype string`);
75
+ }
76
+ }
77
+ else if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
63
78
  errs.push(`${o.type} mediaType must be one of ${spec.types.join(", ")}`);
64
79
  }
65
80
  if (o.name !== undefined) {
@@ -72,6 +87,10 @@ export function validateMediaBlock(b) {
72
87
  errs.push(`${o.type} name must not contain control characters`);
73
88
  }
74
89
  }
90
+ if (o.size !== undefined &&
91
+ (typeof o.size !== "number" || !Number.isInteger(o.size) || o.size < 0)) {
92
+ errs.push(`${o.type} size must be a non-negative integer`);
93
+ }
75
94
  const src = o.source;
76
95
  if (typeof src !== "object" || src === null) {
77
96
  errs.push(`${o.type} source must be an object`);
package/dist/storage.d.ts CHANGED
@@ -67,6 +67,13 @@ export interface ObjectStore {
67
67
  maxSize: number;
68
68
  ttlSeconds: number;
69
69
  }): Promise<PresignedUpload>;
70
+ /**
71
+ * The canonical URI of a key in this store: unsigned, stable, no credentials
72
+ * (`s3://bucket/key`). This is an identifier, never a presigned URL: it may be recorded in an
73
+ * event log and shown to a model, so it must stay valid and carry no secret. Optional: a store
74
+ * with no notion of URIs leaves it out and the kernel falls back to its own reference.
75
+ */
76
+ uri?(key: string): string;
70
77
  }
71
78
  /** 预签名下载的选项。 */
72
79
  export interface PresignGetOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.25",
3
+ "version": "0.1.0-rc.26",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {