@deepseek-ai/dsh-attachment 0.1.2-alpha.2 → 0.1.2-alpha.3

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 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: 01a5d6ee143ff53175dd7327cd6d419af61938a3
6
- README.zh.md: 1a1d297297a6815ce5338391af0182e471f99000
5
+ README.md: 709189ac8dd9591d89c0b0082ea0ae0247c97f97
6
+ README.zh.md: 24eee83874d2ad12025d4457f1fad74aadb73446
package/README.md CHANGED
@@ -75,7 +75,7 @@ The service family runs one admission-and-storage flow: every entry point enforc
75
75
  |---|---|
76
76
  | [`src/index.ts`](src/index.ts) | Plugin entry: abstract `AttachmentStore` service and re-exports |
77
77
  | [`src/types.ts`](src/types.ts) | Durable vocabulary: references, limits, upload and store payloads |
78
- | [`src/admission.ts`](src/admission.ts) | `admitEncodedImages`: canonical-base64 enforcement, then `saveImages` delegation |
78
+ | [`src/admission.ts`](src/admission.ts) | Browser prompt admission: canonical-base64 enforcement, `saveImages` delegation, and durable prompt-part projection |
79
79
  | [`src/error.ts`](src/error.ts) | `AttachmentError` class and the `isImageAdmissionError` runtime subset |
80
80
  | [`src/brand.ts`](src/brand.ts) | `AttachmentId` branded opaque identifier |
81
81
  | [`src/invariant.ts`](src/invariant.ts) | Invariant companion (no runtime invariant; implementations enforce immutable-store checks) |
package/README.zh.md CHANGED
@@ -75,7 +75,7 @@ kind: "package-reference"
75
75
  |---|---|
76
76
  | [`src/index.ts`](src/index.ts) | 插件入口:抽象 `AttachmentStore` 服务与再导出 |
77
77
  | [`src/types.ts`](src/types.ts) | 持久词汇:引用、限额、上传与存储载荷 |
78
- | [`src/admission.ts`](src/admission.ts) | `admitEncodedImages`:规范 base64 强制,随后委托 `saveImages` |
78
+ | [`src/admission.ts`](src/admission.ts) | 浏览器 prompt 准入:强制规范 base64、委托 `saveImages` 并投影持久 prompt part |
79
79
  | [`src/error.ts`](src/error.ts) | `AttachmentError` 类与 `isImageAdmissionError` 运行时子集 |
80
80
  | [`src/brand.ts`](src/brand.ts) | `AttachmentId` 带类型标记的不透明标识符 |
81
81
  | [`src/invariant.ts`](src/invariant.ts) | 不变式伴生插件(无运行时不变式;实现负责强制不可变存储检查) |
package/lib/index.js CHANGED
@@ -93,6 +93,29 @@ function saveInput(image) {
93
93
  async function admitEncodedImages(attachments, images) {
94
94
  return attachments.saveImages(images.map(saveInput));
95
95
  }
96
+ /**
97
+ * Admit one browser prompt and replace each uploaded image with its durable reference.
98
+ * Text-only prompts do not access the attachment store.
99
+ * @param attachments - the deployment attachment store owning batch policy.
100
+ * @param content - browser prompt parts in message order.
101
+ * @returns admitted prompt parts in the same order as `content`.
102
+ * @throws AttachmentError when the image batch is refused.
103
+ */
104
+ async function admitPromptContent(attachments, content) {
105
+ if (content.every((part) => part.type === "text")) return content.map((part) => ({
106
+ type: "text",
107
+ text: part.text
108
+ }));
109
+ const refs = await admitEncodedImages(attachments, content.filter((part) => part.type === "image"));
110
+ let next = 0;
111
+ return content.map((part) => part.type === "text" ? {
112
+ type: "text",
113
+ text: part.text
114
+ } : {
115
+ type: "image",
116
+ attachment: refs[next++]
117
+ });
118
+ }
96
119
  //#endregion
97
120
  //#region lib/types/request-projection.js
98
121
  /**
@@ -189,4 +212,4 @@ var AttachmentStore = class extends Service {
189
212
  }
190
213
  };
191
214
  //#endregion
192
- export { AttachmentError, AttachmentId, AttachmentStore, AttachmentStore as default, ImageVariantId, admitEncodedImages, isImageAdmissionError, requestImageDimensions };
215
+ export { AttachmentError, AttachmentId, AttachmentStore, AttachmentStore as default, ImageVariantId, admitEncodedImages, admitPromptContent, isImageAdmissionError, requestImageDimensions };
@@ -1,6 +1,6 @@
1
1
  /** Wire-form admission of base64-encoded image uploads. @module @deepseek-ai/dsh-attachment/admission */
2
2
  import type { AttachmentStore } from './index.ts';
3
- import type { EncodedImageAttachment, ImageAttachmentRef } from './types.ts';
3
+ import type { AdmittedPromptContentPart, EncodedImageAttachment, ImageAttachmentRef, PromptContentPart } from './types.ts';
4
4
  /**
5
5
  * Admit one wire image batch: enforce canonical base64 on every member, then
6
6
  * delegate batch admission — count and aggregate-byte limits, media-type and
@@ -12,4 +12,13 @@ import type { EncodedImageAttachment, ImageAttachmentRef } from './types.ts';
12
12
  * @throws AttachmentError on a non-canonical payload or a refused batch.
13
13
  */
14
14
  export declare function admitEncodedImages(attachments: AttachmentStore, images: readonly EncodedImageAttachment[]): Promise<readonly ImageAttachmentRef[]>;
15
+ /**
16
+ * Admit one browser prompt and replace each uploaded image with its durable reference.
17
+ * Text-only prompts do not access the attachment store.
18
+ * @param attachments - the deployment attachment store owning batch policy.
19
+ * @param content - browser prompt parts in message order.
20
+ * @returns admitted prompt parts in the same order as `content`.
21
+ * @throws AttachmentError when the image batch is refused.
22
+ */
23
+ export declare function admitPromptContent(attachments: AttachmentStore, content: readonly PromptContentPart[]): Promise<AdmittedPromptContentPart[]>;
15
24
  //# sourceMappingURL=admission.d.ts.map
@@ -30,4 +30,23 @@ function saveInput(image) {
30
30
  export async function admitEncodedImages(attachments, images) {
31
31
  return attachments.saveImages(images.map(saveInput));
32
32
  }
33
+ /**
34
+ * Admit one browser prompt and replace each uploaded image with its durable reference.
35
+ * Text-only prompts do not access the attachment store.
36
+ * @param attachments - the deployment attachment store owning batch policy.
37
+ * @param content - browser prompt parts in message order.
38
+ * @returns admitted prompt parts in the same order as `content`.
39
+ * @throws AttachmentError when the image batch is refused.
40
+ */
41
+ export async function admitPromptContent(attachments, content) {
42
+ if (content.every(part => part.type === 'text')) {
43
+ return content.map(part => ({ type: 'text', text: part.text }));
44
+ }
45
+ const refs = await admitEncodedImages(attachments, content.filter(part => part.type === 'image'));
46
+ let next = 0;
47
+ return content.map(part => part.type === 'text'
48
+ ? { type: 'text', text: part.text }
49
+ // admitEncodedImages returns one reference per image part in order.
50
+ : { type: 'image', attachment: refs[next++] });
51
+ }
33
52
  //# sourceMappingURL=admission.js.map
@@ -4,9 +4,9 @@ import type { ImageAttachmentLimits, ImageAttachmentRef, ImageRequestPolicy, Req
4
4
  export { AttachmentId, ImageVariantId } from './brand.ts';
5
5
  export { AttachmentError, isImageAdmissionError } from './error.ts';
6
6
  export type { AttachmentErrorCode, ImageAdmissionErrorCode } from './error.ts';
7
- export { admitEncodedImages } from './admission.ts';
7
+ export { admitEncodedImages, admitPromptContent } from './admission.ts';
8
8
  export { requestImageDimensions } from './request-projection.ts';
9
- export type { AttachmentId as AttachmentIdType, EncodedImageAttachment, ImageAttachmentLimits, ImageAttachmentRef, ImageRequestPolicy, ImageMediaType, RequestImageAttachment, SaveImageAttachment, StoredImageAttachment, } from './types.ts';
9
+ export type { AttachmentId as AttachmentIdType, AdmittedPromptContentPart, EncodedImageAttachment, ImageAttachmentLimits, ImageAttachmentRef, ImageRequestPolicy, ImageMediaType, PromptContentPart, RequestImageAttachment, SaveImageAttachment, StoredImageAttachment, } from './types.ts';
10
10
  declare module '@deepseek-ai/cordis' {
11
11
  interface Context {
12
12
  attachments: AttachmentStore;
@@ -3,7 +3,7 @@ import { Service } from '@deepseek-ai/cordis';
3
3
  import { AttachmentError } from "./error.js";
4
4
  export { AttachmentId, ImageVariantId } from "./brand.js";
5
5
  export { AttachmentError, isImageAdmissionError } from "./error.js";
6
- export { admitEncodedImages } from "./admission.js";
6
+ export { admitEncodedImages, admitPromptContent } from "./admission.js";
7
7
  export { requestImageDimensions } from "./request-projection.js";
8
8
  /** Immutable binary attachment service. Implementations validate bytes before publishing a reference. */
9
9
  export class AttachmentStore extends Service {
@@ -45,6 +45,29 @@ export interface EncodedImageAttachment {
45
45
  /** Optional display name; it is never interpreted as a path. */
46
46
  name?: string;
47
47
  }
48
+ /**
49
+ * Browser-submitted prompt content accepted by Host prompt endpoints; the
50
+ * accepting Host promotes image parts to durable references through
51
+ * `admitPromptContent` before any message is created, so a wire caller can
52
+ * never cite an attachment it did not upload.
53
+ */
54
+ export type PromptContentPart = {
55
+ readonly type: 'text';
56
+ readonly text: string;
57
+ } | {
58
+ readonly type: 'image';
59
+ readonly mediaType: ImageMediaType;
60
+ readonly data: string;
61
+ readonly name?: string;
62
+ };
63
+ /** Host-admitted prompt content with each uploaded image replaced by its durable reference. */
64
+ export type AdmittedPromptContentPart = {
65
+ readonly type: 'text';
66
+ readonly text: string;
67
+ } | {
68
+ readonly type: 'image';
69
+ readonly attachment: ImageAttachmentRef;
70
+ };
48
71
  /** Request to validate and durably commit one image. */
49
72
  export interface SaveImageAttachment {
50
73
  data: Uint8Array;
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.2-alpha.2",
4
+ "version": "0.1.2-alpha.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -37,13 +37,13 @@
37
37
  ],
38
38
  "license": "MIT",
39
39
  "peerDependencies": {
40
- "@deepseek-ai/cordis": "^4.0.2",
41
- "@deepseek-ai/dsh-brand": "^0.1.2-alpha.2",
42
- "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2"
40
+ "@deepseek-ai/dsh-brand": "^0.1.2-alpha.3",
41
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.3",
42
+ "@deepseek-ai/cordis": "^4.0.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@deepseek-ai/dsh-brand": "^0.1.2-alpha.2",
46
- "@deepseek-ai/cordis": "^4.0.2",
47
- "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2"
45
+ "@deepseek-ai/dsh-brand": "^0.1.2-alpha.3",
46
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.3",
47
+ "@deepseek-ai/cordis": "^4.0.2"
48
48
  }
49
49
  }