@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.
- package/agent-docs/extension-points/model-provider.md +2 -0
- package/agent-docs/extension-points/object-store.md +2 -0
- package/dist/hooks.d.ts +6 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +25 -6
- package/dist/model.js +24 -5
- package/dist/storage.d.ts +7 -0
- package/package.json +1 -1
|
@@ -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
|
|
53
|
-
* attachment ids: each image
|
|
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
|
|
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
package/dist/index.js
CHANGED
package/dist/model.d.ts
CHANGED
|
@@ -112,21 +112,37 @@ export type ContentBlock =
|
|
|
112
112
|
isError: boolean;
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
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
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
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 "
|
|
68
|
+
return ['block type must be "image", "document" or "file"'];
|
|
61
69
|
const errs = [];
|
|
62
|
-
if (
|
|
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 {
|