@open33/harness-attachment 0.0.0-stage → 0.1.0

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/src/types.ts ADDED
@@ -0,0 +1,169 @@
1
+ /** Durable attachment vocabulary. @module @open33/harness-attachment/types */
2
+
3
+ import type { AttachmentId, ImageVariantId } from './brand.ts'
4
+
5
+ export type { AttachmentId, ImageVariantId } from './brand.ts'
6
+
7
+ /** Raster image formats accepted by the version-one attachment path. */
8
+ export type ImageMediaType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif'
9
+
10
+ /** Durable, serializable reference to one immutable normalized image. */
11
+ export interface ImageAttachmentRef {
12
+ /** Opaque storage identifier; never a filesystem path or bearer URL. */
13
+ attachmentId: AttachmentId
14
+ /** Media type verified from the stored bytes. */
15
+ mediaType: ImageMediaType
16
+ /** Exact encoded byte length. */
17
+ bytes: number
18
+ /** Intrinsic encoded width in pixels. */
19
+ width: number
20
+ /** Intrinsic encoded height in pixels. */
21
+ height: number
22
+ /** Optional display name stripped of local path information. */
23
+ name?: string
24
+ /**
25
+ * Input dimensions after applying EXIF orientation and before normalization
26
+ * scaling. Present only when normalization reduced the image.
27
+ */
28
+ originalDimensions?: {
29
+ width: number
30
+ height: number
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Durable, serializable reference to one verbatim stored file. Files are
36
+ * stored byte-for-byte with no normalization; `attachmentId` is the sha256
37
+ * digest of exactly those bytes.
38
+ */
39
+ export interface FileAttachmentRef {
40
+ /** Opaque content-addressed storage identifier; never a filesystem path or bearer URL. */
41
+ attachmentId: AttachmentId
42
+ /** Sanitized display filename, also the stored object's leaf name. */
43
+ name: string
44
+ /** Exact byte length. */
45
+ bytes: number
46
+ }
47
+
48
+ /** Base64-encoded file upload accompanying one wire request. */
49
+ export interface EncodedFileAttachment {
50
+ /** Canonical base64 encoding of the file bytes. */
51
+ data: string
52
+ /** Optional display name; it is never interpreted as a path. */
53
+ name?: string
54
+ }
55
+
56
+ /** Request to durably commit one file verbatim. */
57
+ export interface SaveFileAttachment {
58
+ data: Uint8Array
59
+ /** Optional browser/provider display name; it is never interpreted as a path. */
60
+ name?: string
61
+ }
62
+
63
+ /** Request to durably commit one file from bounded byte chunks. */
64
+ export interface SaveFileStreamAttachment {
65
+ /** Exact file bytes in order; providers must not retain the complete sequence in memory. */
66
+ data: AsyncIterable<Uint8Array>
67
+ /** Optional cancellation for source reads and storage writes. */
68
+ signal?: AbortSignal
69
+ /** Optional browser/provider display name; it is never interpreted as a path. */
70
+ name?: string
71
+ }
72
+
73
+ /** Deployment-resolved limits used by upload admission and request buffering. */
74
+ export interface ImageAttachmentLimits {
75
+ maxImageBytes: number
76
+ maxImagesPerMessage: number
77
+ maxMessageImageBytes: number
78
+ maxImagePixels: number
79
+ /** Maximum intrinsic width and maximum intrinsic height in pixels for one image. */
80
+ maxImageDimension: number
81
+ mediaTypes: readonly ImageMediaType[]
82
+ }
83
+
84
+ /** Base64-encoded image upload accompanying one wire request. */
85
+ export interface EncodedImageAttachment {
86
+ /** Declared media type, verified against the decoded bytes during admission. */
87
+ mediaType: ImageMediaType
88
+ /** Canonical base64 encoding of the image bytes. */
89
+ data: string
90
+ /** Optional display name; it is never interpreted as a path. */
91
+ name?: string
92
+ }
93
+
94
+ /**
95
+ * Browser-submitted prompt content accepted by Host prompt endpoints; the
96
+ * accepting Host promotes image parts to durable references through
97
+ * `ctx.attachments.admitPromptContent()` before any message is created, so a wire caller can
98
+ * never cite an attachment it did not upload.
99
+ */
100
+ export type PromptContentPart =
101
+ | { readonly type: 'text'; readonly text: string }
102
+ | {
103
+ readonly type: 'image'
104
+ readonly mediaType: ImageMediaType
105
+ readonly data: string
106
+ readonly name?: string
107
+ }
108
+
109
+ /**
110
+ * Host prompt content whose upload receipts are resolved. An image part
111
+ * carries encoded bytes awaiting admission, or references an image this
112
+ * service already stored for an upload the same Session staged, with
113
+ * `encodedBytes` holding the byte length of that upload.
114
+ */
115
+ export type AttachmentAdmissionPart =
116
+ | PromptContentPart
117
+ | { readonly type: 'file'; readonly attachment: FileAttachmentRef }
118
+ | { readonly type: 'image'; readonly attachment: ImageAttachmentRef; readonly encodedBytes: number }
119
+
120
+ /** Host-admitted prompt content with every attachment represented by its durable reference. */
121
+ export type AdmittedPromptContentPart =
122
+ | { readonly type: 'text'; readonly text: string }
123
+ | { readonly type: 'image'; readonly attachment: ImageAttachmentRef }
124
+ | { readonly type: 'file'; readonly attachment: FileAttachmentRef }
125
+
126
+ /** Request to validate and durably commit one image. */
127
+ export interface SaveImageAttachment {
128
+ data: Uint8Array
129
+ /** Caller-declared media type, checked against fully decoded bytes. */
130
+ mediaType: ImageMediaType
131
+ /** Optional browser/provider display name; it is never interpreted as a path. */
132
+ name?: string
133
+ }
134
+
135
+ /** Stored image bytes returned after reference and digest verification. */
136
+ export interface StoredImageAttachment {
137
+ ref: ImageAttachmentRef
138
+ data: Uint8Array
139
+ }
140
+
141
+ /** Deterministic request-image target selected by one exact model route for one attachment. */
142
+ export interface ImageRequestTarget {
143
+ /** Target width in pixels; a target above the source keeps the source width. */
144
+ width: number
145
+ /** Target height in pixels; a target above the source keeps the source height. */
146
+ height: number
147
+ /** Encoded-byte target before base64 expansion or Files API upload; the smallest quality-ladder output is kept when no quality fits. */
148
+ maxBytes: number
149
+ }
150
+
151
+ /** Cached request version derived from one provider-independent normalized attachment. */
152
+ export interface RequestImageAttachment {
153
+ /** Cache and upload-index key over the attachment id, policy, and fixed encoder parameters. */
154
+ variantId: ImageVariantId
155
+ /** Durable normalized attachment from which this request version was derived. */
156
+ attachment: ImageAttachmentRef
157
+ /** Encoded request bytes. */
158
+ data: Uint8Array
159
+ mediaType: ImageMediaType
160
+ bytes: number
161
+ width: number
162
+ height: number
163
+ /** Provider-compatible sample depth proven after request encoding. */
164
+ depth: 'uchar'
165
+ /** Provider-compatible color space proven after request encoding. */
166
+ space: 'srgb'
167
+ /** Whether the encoded request version retains an alpha channel. */
168
+ hasAlpha: boolean
169
+ }