@deepseek-ai/dsh-attachment 0.1.0-rc.3 → 0.1.0-rc.7
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/README.i18n.yaml +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/index.js +49 -13
- package/lib/types/error.d.ts +16 -2
- package/lib/types/index.d.ts +11 -1
- package/package.json +8 -8
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/attachment/attachment/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 4fe608552492c33d2bd9acddce51ea1cf20acae4
|
|
6
|
+
README.zh.md: a3093fc9dd1f926cb1c54831c6302eb7bbca25c5
|
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
The durable attachment seam. `ctx.attachments` validates and
|
|
5
|
+
The durable attachment seam. `ctx.attachments` validates and durably commits immutable image bytes, then returns a serializable `ImageAttachmentRef`; consumers never persist browser paths, object URLs, provider URLs, or base64 in session events.
|
|
6
6
|
|
|
7
|
-
Unsent composer images remain browser-owned temporary drafts. `validateImage` runs the same admission policy without persisting
|
|
7
|
+
Unsent composer images remain browser-owned temporary drafts. `validateImage` runs the same admission policy without persisting. `saveImages` owns batch count and aggregate-byte limits, validates every member before writing any member, then commits in order and returns references only after the complete batch succeeds. A later storage failure returns no partial references, although an earlier immutable content-addressed object may remain unreachable until reference-aware garbage collection exists. `AttachmentError.code` uses the closed `AttachmentErrorCode` string union. Its `ImageAdmissionErrorCode` subset marks caller-correctable image-input failures; `isImageAdmissionError` recognizes that subset at runtime so each protocol adapter can map its own error vocabulary. `saveImage` commits one accepted image before any model-visible session event is published, and `readImage` verifies the content-addressed object against its logged metadata. Callers may cancel `readImage`; implementations observe cancellation around backend and verification work and preserve it instead of translating it into a storage failure.
|
|
8
8
|
|
|
9
9
|
## Model Experience
|
|
10
10
|
|
package/README.zh.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
持久附件服务边界。`ctx.attachments`
|
|
5
|
+
持久附件服务边界。`ctx.attachments` 校验并持久提交不可变图片字节,随后返回可序列化的 `ImageAttachmentRef`;消费方绝不会在会话事件中持久保存浏览器路径、对象 URL、提供方 URL 或 base64。
|
|
6
6
|
|
|
7
|
-
未发送的输入区图片仍是由浏览器持有的临时草稿。`validateImage`
|
|
7
|
+
未发送的输入区图片仍是由浏览器持有的临时草稿。`validateImage` 运行相同的准入策略,但不执行持久化。`saveImages` 负责批次图片数量和总字节限制,先校验全部成员,再按顺序提交,并且只在完整批次成功后返回引用。后续存储失败不会返回部分引用,但较早写入的不可变内容寻址对象可能保持不可达,直至具备按引用感知的垃圾回收。`AttachmentError.code` 使用封闭的 `AttachmentErrorCode` 字符串联合类型。其 `ImageAdmissionErrorCode` 子集标记可由调用方修正的图片输入失败;`isImageAdmissionError` 在运行时识别该子集,使每个协议适配器可以映射自己的错误词汇。`saveImage` 会在发布任何模型可见的会话事件前提交一张已接受的图片,`readImage` 则根据已记录的元数据校验内容寻址对象。调用方可以取消 `readImage`;实现会在后端读取与校验工作的边界观察取消,并保留取消语义,而不会将其转换为存储失败。
|
|
8
8
|
|
|
9
9
|
## 模型体验
|
|
10
10
|
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
-
//#region lib/types/brand.js
|
|
3
|
-
/** Attachment identifier brand. @module @deepseek-ai/dsh-attachment/brand */
|
|
4
|
-
/**
|
|
5
|
-
* Brand a validated storage identifier.
|
|
6
|
-
* @param value - backend-produced opaque identifier.
|
|
7
|
-
* @returns the branded identifier.
|
|
8
|
-
*/
|
|
9
|
-
function AttachmentId(value) {
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
2
|
//#region lib/types/error.js
|
|
14
|
-
/**
|
|
3
|
+
/** Runtime membership for structurally compatible errors crossing package boundaries. */
|
|
4
|
+
const IMAGE_ADMISSION_ERROR_CODE_SET = new Set([
|
|
5
|
+
"TOO_MANY_IMAGES",
|
|
6
|
+
"IMAGES_TOO_LARGE",
|
|
7
|
+
"UNSUPPORTED_IMAGE_TYPE",
|
|
8
|
+
"INVALID_IMAGE_BASE64",
|
|
9
|
+
"INVALID_IMAGE",
|
|
10
|
+
"IMAGE_TYPE_MISMATCH",
|
|
11
|
+
"IMAGE_TOO_LARGE",
|
|
12
|
+
"IMAGE_TOO_MANY_PIXELS"
|
|
13
|
+
]);
|
|
15
14
|
/**
|
|
16
15
|
* Stable failures suitable for host RPC error mapping.
|
|
17
16
|
*
|
|
@@ -35,6 +34,25 @@ var AttachmentError = class extends Error {
|
|
|
35
34
|
this.code = code;
|
|
36
35
|
}
|
|
37
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Distinguish caller-correctable image admission failures from storage faults.
|
|
39
|
+
* @param error - failure raised while validating or persisting an image batch.
|
|
40
|
+
* @returns whether the caller can correct the proposed image content or batch.
|
|
41
|
+
*/
|
|
42
|
+
function isImageAdmissionError(error) {
|
|
43
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" && IMAGE_ADMISSION_ERROR_CODE_SET.has(error.code);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region lib/types/brand.js
|
|
47
|
+
/** Attachment identifier brand. @module @deepseek-ai/dsh-attachment/brand */
|
|
48
|
+
/**
|
|
49
|
+
* Brand a validated storage identifier.
|
|
50
|
+
* @param value - backend-produced opaque identifier.
|
|
51
|
+
* @returns the branded identifier.
|
|
52
|
+
*/
|
|
53
|
+
function AttachmentId(value) {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
38
56
|
//#endregion
|
|
39
57
|
//#region lib/types/index.js
|
|
40
58
|
/** Durable attachment storage seam (`ctx.attachments`). @module @deepseek-ai/dsh-attachment */
|
|
@@ -43,6 +61,24 @@ var AttachmentStore = class extends Service {
|
|
|
43
61
|
constructor(ctx) {
|
|
44
62
|
super(ctx, "attachments");
|
|
45
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Validate one ordered image batch before committing any member.
|
|
66
|
+
* Validation failures start no writes; storage failures return no partial
|
|
67
|
+
* references, although already published content-addressed objects may stay
|
|
68
|
+
* unreachable until a future retention policy collects them.
|
|
69
|
+
* @param inputs - encoded images in their owning message order.
|
|
70
|
+
* @returns durable references in the exact input order.
|
|
71
|
+
*/
|
|
72
|
+
async saveImages(inputs) {
|
|
73
|
+
const { maxImagesPerMessage, maxMessageImageBytes, mediaTypes } = this.imageLimits;
|
|
74
|
+
if (inputs.length > maxImagesPerMessage) throw new AttachmentError("Image batch exceeds the configured image-count limit.", "TOO_MANY_IMAGES");
|
|
75
|
+
if (inputs.reduce((sum, input) => sum + input.data.byteLength, 0) > maxMessageImageBytes) throw new AttachmentError("Image batch exceeds the configured aggregate image-byte limit.", "IMAGES_TOO_LARGE");
|
|
76
|
+
for (const input of inputs) if (!mediaTypes.includes(input.mediaType)) throw new AttachmentError(`Image type ${input.mediaType} is not accepted by this deployment.`, "UNSUPPORTED_IMAGE_TYPE");
|
|
77
|
+
for (const input of inputs) await this.validateImage(input);
|
|
78
|
+
const refs = [];
|
|
79
|
+
for (const input of inputs) refs.push(await this.saveImage(input));
|
|
80
|
+
return refs;
|
|
81
|
+
}
|
|
46
82
|
};
|
|
47
83
|
//#endregion
|
|
48
|
-
export { AttachmentError, AttachmentId, AttachmentStore, AttachmentStore as default };
|
|
84
|
+
export { AttachmentError, AttachmentId, AttachmentStore, AttachmentStore as default, isImageAdmissionError };
|
package/lib/types/error.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
/** Attachment failure class. @module @deepseek-ai/dsh-attachment/error */
|
|
2
|
+
declare const IMAGE_ADMISSION_ERROR_CODES: readonly ["TOO_MANY_IMAGES", "IMAGES_TOO_LARGE", "UNSUPPORTED_IMAGE_TYPE", "INVALID_IMAGE_BASE64", "INVALID_IMAGE", "IMAGE_TYPE_MISMATCH", "IMAGE_TOO_LARGE", "IMAGE_TOO_MANY_PIXELS"];
|
|
3
|
+
/** Caller-correctable attachment failure codes raised while admitting image input. */
|
|
4
|
+
export type ImageAdmissionErrorCode = typeof IMAGE_ADMISSION_ERROR_CODES[number];
|
|
5
|
+
/** Stable attachment failure codes used for protocol error routing. */
|
|
6
|
+
export type AttachmentErrorCode = ImageAdmissionErrorCode | 'INVALID_ATTACHMENT_REF' | 'ATTACHMENT_CORRUPT' | 'ATTACHMENT_WRITE_FAILED' | 'ATTACHMENT_NOT_FOUND' | 'ATTACHMENT_READ_FAILED';
|
|
2
7
|
/**
|
|
3
8
|
* Stable failures suitable for host RPC error mapping.
|
|
4
9
|
*
|
|
@@ -10,12 +15,21 @@
|
|
|
10
15
|
*/
|
|
11
16
|
export declare class AttachmentError extends Error {
|
|
12
17
|
/** Stable machine-routing failure code. */
|
|
13
|
-
readonly code:
|
|
18
|
+
readonly code: AttachmentErrorCode;
|
|
14
19
|
/**
|
|
15
20
|
* @param message - human-readable failure description without raw bytes or host paths.
|
|
16
21
|
* @param code - stable machine-routing code.
|
|
17
22
|
* @param options - optional chained cause.
|
|
18
23
|
*/
|
|
19
|
-
constructor(message: string, code:
|
|
24
|
+
constructor(message: string, code: AttachmentErrorCode, options?: ErrorOptions);
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Distinguish caller-correctable image admission failures from storage faults.
|
|
28
|
+
* @param error - failure raised while validating or persisting an image batch.
|
|
29
|
+
* @returns whether the caller can correct the proposed image content or batch.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isImageAdmissionError(error: unknown): error is AttachmentError & {
|
|
32
|
+
readonly code: ImageAdmissionErrorCode;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
21
35
|
//# sourceMappingURL=error.d.ts.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { Context, Service } from '@deepseek-ai/cordis';
|
|
3
3
|
import type { ImageAttachmentLimits, ImageAttachmentRef, SaveImageAttachment, StoredImageAttachment } from './types.ts';
|
|
4
4
|
export { AttachmentId } from './brand.ts';
|
|
5
|
-
export { AttachmentError } from './error.ts';
|
|
5
|
+
export { AttachmentError, isImageAdmissionError } from './error.ts';
|
|
6
|
+
export type { AttachmentErrorCode, ImageAdmissionErrorCode } from './error.ts';
|
|
6
7
|
export type { AttachmentId as AttachmentIdType, ImageAttachmentLimits, ImageAttachmentRef, ImageMediaType, SaveImageAttachment, StoredImageAttachment, } from './types.ts';
|
|
7
8
|
declare module '@deepseek-ai/cordis' {
|
|
8
9
|
interface Context {
|
|
@@ -21,6 +22,15 @@ export declare abstract class AttachmentStore extends Service {
|
|
|
21
22
|
* @returns completion after the encoded raster has been fully decoded.
|
|
22
23
|
*/
|
|
23
24
|
abstract validateImage(input: SaveImageAttachment): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate one ordered image batch before committing any member.
|
|
27
|
+
* Validation failures start no writes; storage failures return no partial
|
|
28
|
+
* references, although already published content-addressed objects may stay
|
|
29
|
+
* unreachable until a future retention policy collects them.
|
|
30
|
+
* @param inputs - encoded images in their owning message order.
|
|
31
|
+
* @returns durable references in the exact input order.
|
|
32
|
+
*/
|
|
33
|
+
saveImages(inputs: readonly SaveImageAttachment[]): Promise<readonly ImageAttachmentRef[]>;
|
|
24
34
|
/**
|
|
25
35
|
* Validate and durably commit one image before its owning session event is appended.
|
|
26
36
|
* @param input - encoded bytes, declared media type, and optional display name.
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-attachment",
|
|
3
3
|
"description": "Durable immutable attachment storage seam for the DeepSeek Harness",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.7",
|
|
5
5
|
"publishConfig": {
|
|
6
|
-
"access": "
|
|
6
|
+
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
],
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@deepseek-ai/dsh-brand": "^0.1.0-rc.
|
|
36
|
-
"@deepseek-ai/
|
|
37
|
-
"@deepseek-ai/
|
|
35
|
+
"@deepseek-ai/dsh-brand": "^0.1.0-rc.7",
|
|
36
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
37
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@deepseek-ai/dsh-
|
|
41
|
-
"@deepseek-ai/
|
|
42
|
-
"@deepseek-ai/
|
|
40
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.7",
|
|
41
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
42
|
+
"@deepseek-ai/dsh-brand": "^0.1.0-rc.7"
|
|
43
43
|
}
|
|
44
44
|
}
|