@yolk-sdk/agent 0.1.0-canary.22 → 0.1.0-canary.23
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.md +18 -3
- package/dist/protocol/content.d.mts +2 -1
- package/dist/protocol/content.d.mts.map +1 -1
- package/dist/protocol/content.mjs +8 -1
- package/dist/protocol/content.mjs.map +1 -1
- package/dist/protocol/index.d.mts +2 -2
- package/dist/protocol/index.d.mts.map +1 -1
- package/dist/protocol/index.mjs +2 -2
- package/dist/providers/anthropic/claude-provider.d.mts +6 -0
- package/dist/providers/anthropic/claude-provider.d.mts.map +1 -1
- package/dist/providers/anthropic/claude-provider.mjs +45 -24
- package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +2 -2
- package/dist/providers/openai/codex-provider.mjs.map +1 -1
- package/dist/providers/openai/provider.mjs +2 -2
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/package.json +1 -1
- package/src/protocol/content.ts +11 -0
- package/src/protocol/index.ts +1 -0
- package/src/providers/anthropic/claude-provider.ts +76 -34
- package/src/providers/openai/codex-provider.ts +2 -1
- package/src/providers/openai/provider.ts +2 -2
package/README.md
CHANGED
|
@@ -148,9 +148,24 @@ const ContextLayer = makeWindowCompactionTransformer({
|
|
|
148
148
|
- `AudioPart` with `InlineBase64`, `Url`, or host-owned `Ref` source
|
|
149
149
|
|
|
150
150
|
Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
|
|
151
|
-
`refAttachmentSource`. Providers
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
`refAttachmentSource`. Providers can pass through supported media URLs: OpenAI Chat, OpenAI Codex,
|
|
152
|
+
and Anthropic support image URLs; Anthropic also supports PDF URLs. Use inline base64 for simple apps,
|
|
153
|
+
durable URLs for app-owned uploads, or persist `Ref` values and call
|
|
154
|
+
`resolveContentAttachmentSources` at your storage boundary before provider execution. Host apps own
|
|
155
|
+
upload, auth, retention, URL durability, and ref hydration policy.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { ImagePart, UserMessage, urlAttachmentSource } from '@yolk-sdk/agent/protocol'
|
|
159
|
+
|
|
160
|
+
const message = UserMessage.make({
|
|
161
|
+
content: [
|
|
162
|
+
ImagePart.make({
|
|
163
|
+
source: urlAttachmentSource('https://cdn.example.com/image.webp'),
|
|
164
|
+
mimeType: 'image/webp'
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
})
|
|
168
|
+
```
|
|
154
169
|
|
|
155
170
|
For text files, use `documentPartFromText`, `inferTextDocumentMimeType`, and the client helper
|
|
156
171
|
`documentPartFromTextFile` to create UTF-8 inline `DocumentPart` values without trusting filename
|
|
@@ -63,6 +63,7 @@ declare const refAttachmentSource: (id: string) => RefAttachmentSource;
|
|
|
63
63
|
declare const inlineBase64Source: (data: string) => InlineBase64AttachmentSource;
|
|
64
64
|
declare const attachmentSourcePreview: (source: AttachmentSource) => string;
|
|
65
65
|
declare const attachmentSourceDataUrl: (source: AttachmentSource, mimeType: string) => Option.Option<string>;
|
|
66
|
+
declare const attachmentSourceUrl: (source: AttachmentSource, mimeType: string) => Option.Option<string>;
|
|
66
67
|
declare const isTextDocumentMimeType: (mimeType: string) => boolean;
|
|
67
68
|
declare const textDocumentMimeTypeFromFilename: (filename: string) => string | undefined;
|
|
68
69
|
declare const inferTextDocumentMimeType: (input: {
|
|
@@ -79,5 +80,5 @@ declare const documentPartFromText: (input: {
|
|
|
79
80
|
declare const attachmentSourceText: (source: AttachmentSource) => Effect.Effect<Option.Option<string>, unknown, never>;
|
|
80
81
|
declare const attachmentSourceBase64: (source: AttachmentSource) => Option.Option<string>;
|
|
81
82
|
//#endregion
|
|
82
|
-
export { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
83
|
+
export { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
83
84
|
//# sourceMappingURL=content.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.mts","names":[],"sources":["../../src/protocol/content.ts"],"mappings":";;;;cACuC,aAAA;;;cAE1B,QAAA,SAAiB,aAE5B;AAAA,cAAG,iCAAA;;;cAEQ,4BAAA,SAAqC,iCAKjD;AAAA,cAAG,wBAAA;;;cAES,mBAAA,SAA4B,wBAEvC;AAAA,cAAG,wBAAA;;;cAEQ,mBAAA,SAA4B,wBAEvC;AAAA,cAEW,gBAAA,EAAgB,MAAA,CAAA,KAAA,kBAAA,4BAAA,SAAA,mBAAA,SAAA,mBAAA;AAAA,KAKjB,gBAAA,UAA0B,gBAAA,CAAiB,IAAI;AAAA,cAAA,cAAA;;;;;;;;cAE9C,SAAA,SAAkB,cAO7B;AAAA,cAAG,iBAAA;;;;;;cAEQ,YAAA,SAAqB,iBAKhC;AAAA,cAAG,cAAA;;;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A;AAAA,cA2BY,oBAAA,GAAwB,MAAA,EAAQ,gBAAA,KAAgB,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA;AAAA,cAahD,sBAAA,GAA0B,MAAA,EAAQ,gBAAA,KAAgB,MAAA,CAAA,MAAA"}
|
|
@@ -108,6 +108,13 @@ const attachmentSourceDataUrl = (source, mimeType) => {
|
|
|
108
108
|
case "Ref": return Option.none();
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
|
+
const attachmentSourceUrl = (source, mimeType) => {
|
|
112
|
+
switch (source._tag) {
|
|
113
|
+
case "InlineBase64": return Option.some(`data:${mimeType};base64,${source.data}`);
|
|
114
|
+
case "Url": return Option.some(source.url);
|
|
115
|
+
case "Ref": return Option.none();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
111
118
|
const normalizeMimeType = (mimeType) => mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
112
119
|
const textDocumentMimeTypeByExtension = {
|
|
113
120
|
".csv": "text/csv",
|
|
@@ -191,6 +198,6 @@ const attachmentSourceBase64 = (source) => {
|
|
|
191
198
|
}
|
|
192
199
|
};
|
|
193
200
|
//#endregion
|
|
194
|
-
export { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
201
|
+
export { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
195
202
|
|
|
196
203
|
//# sourceMappingURL=content.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.mjs","names":["Arr"],"sources":["../../src/protocol/content.ts"],"sourcesContent":["import { Array as Arr, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\n\nexport class TextPart extends Schema.TaggedClass<TextPart>()('Text', {\n text: Schema.String\n}) {}\n\nexport class InlineBase64AttachmentSource extends Schema.TaggedClass<InlineBase64AttachmentSource>()(\n 'InlineBase64',\n {\n data: Schema.String\n }\n) {}\n\nexport class UrlAttachmentSource extends Schema.TaggedClass<UrlAttachmentSource>()('Url', {\n url: Schema.String\n}) {}\n\nexport class RefAttachmentSource extends Schema.TaggedClass<RefAttachmentSource>()('Ref', {\n id: Schema.String\n}) {}\n\nexport const AttachmentSource = Schema.Union([\n InlineBase64AttachmentSource,\n UrlAttachmentSource,\n RefAttachmentSource\n])\nexport type AttachmentSource = typeof AttachmentSource.Type\n\nexport class ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n title: Schema.optional(Schema.String),\n width: Schema.optional(Schema.Number),\n height: Schema.optional(Schema.Number)\n}) {}\n\nexport class DocumentPart extends Schema.TaggedClass<DocumentPart>()('Document', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.String,\n title: Schema.optional(Schema.String)\n}) {}\n\nexport class AudioPart extends Schema.TaggedClass<AudioPart>()('Audio', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n durationMs: Schema.optional(Schema.Number)\n}) {}\n\nexport const ContentPart = Schema.Union([TextPart, ImagePart, DocumentPart, AudioPart])\nexport type ContentPart = typeof ContentPart.Type\n\nexport const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)])\nexport type Content = typeof Content.Type\n\nexport type AttachmentContentPart = ImagePart | DocumentPart | AudioPart\n\nexport type AttachmentSourceResolver<E = never, R = never> = (\n part: AttachmentContentPart\n) => Effect.Effect<AttachmentSource, E, R>\n\nconst resolveContentPartAttachmentSource = <E, R>(\n part: ContentPart,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<ContentPart, E, R> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part)\n case 'Image':\n return resolver(part).pipe(\n Effect.map(source =>\n ImagePart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title,\n width: part.width,\n height: part.height\n })\n )\n )\n case 'Document':\n return resolver(part).pipe(\n Effect.map(source =>\n DocumentPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title\n })\n )\n )\n case 'Audio':\n return resolver(part).pipe(\n Effect.map(source =>\n AudioPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n durationMs: part.durationMs\n })\n )\n )\n }\n}\n\nexport const resolveContentAttachmentSources = <E, R>(\n content: Content,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<Content, E, R> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => resolveContentPartAttachmentSource(part, resolver))\n\nexport const contentPartText = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n case 'Document':\n case 'Audio':\n return ''\n }\n}\n\nexport const contentPartPreview = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n return 'Image'\n case 'Document':\n return `Document: ${part.title ?? part.filename}`\n case 'Audio':\n return 'Audio'\n }\n}\n\nexport const contentText = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartText).join('')\n\nexport const contentPreview = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartPreview).join(', ')\n\nexport const contentParts = (content: Content): ReadonlyArray<ContentPart> =>\n typeof content === 'string' ? [TextPart.make({ text: content })] : content\n\nexport const isContentEmpty = (content: Content) =>\n typeof content === 'string'\n ? content.length === 0\n : content.length === 0 ||\n Arr.every(content, part => part._tag === 'Text' && part.text.length === 0)\n\nexport const appendTextToContent = (content: Content, text: string): Content => {\n if (typeof content === 'string') {\n return `${content}${text}`\n }\n\n return Option.match(Arr.last(content), {\n onNone: () => [TextPart.make({ text })],\n onSome: last =>\n last._tag !== 'Text'\n ? [...content, TextPart.make({ text })]\n : Arr.map(content, (part, index) =>\n index === content.length - 1 && part._tag === 'Text'\n ? TextPart.make({ text: `${part.text}${text}` })\n : part\n )\n })\n}\n\nexport const inlineBase64AttachmentSource = (data: string) => InlineBase64AttachmentSource.make({ data })\n\nexport const urlAttachmentSource = (url: string) => UrlAttachmentSource.make({ url })\n\nexport const refAttachmentSource = (id: string) => RefAttachmentSource.make({ id })\n\nexport const inlineBase64Source = inlineBase64AttachmentSource\n\nexport const attachmentSourcePreview = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return 'inline'\n case 'Url':\n return source.url\n case 'Ref':\n return source.id\n }\n}\n\nexport const attachmentSourceDataUrl = (source: AttachmentSource, mimeType: string) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(`data:${mimeType};base64,${source.data}`)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n\nconst normalizeMimeType = (mimeType: string) => mimeType.split(';', 1)[0]?.trim().toLowerCase() ?? ''\n\nconst textDocumentMimeTypeByExtension: Readonly<Record<string, string>> = {\n '.csv': 'text/csv',\n '.css': 'text/css',\n '.gql': 'application/graphql',\n '.graphql': 'application/graphql',\n '.html': 'text/html',\n '.js': 'application/javascript',\n '.jsx': 'application/javascript',\n '.json': 'application/json',\n '.jsonl': 'application/x-ndjson',\n '.md': 'text/markdown',\n '.markdown': 'text/markdown',\n '.sql': 'application/sql',\n '.toml': 'application/toml',\n '.ts': 'application/typescript',\n '.tsx': 'application/typescript',\n '.txt': 'text/plain',\n '.xml': 'application/xml',\n '.yaml': 'application/yaml',\n '.yml': 'application/yaml'\n}\n\nconst isUnknownDocumentMimeType = (mimeType: string) =>\n mimeType.length === 0 || mimeType === 'application/octet-stream' || mimeType === 'binary/octet-stream'\n\nexport const isTextDocumentMimeType = (mimeType: string) => {\n const normalized = normalizeMimeType(mimeType)\n\n return (\n normalized.startsWith('text/') ||\n normalized === 'application/json' ||\n normalized === 'application/ld+json' ||\n normalized === 'application/jsonl' ||\n normalized === 'application/x-ndjson' ||\n normalized === 'application/javascript' ||\n normalized === 'application/x-javascript' ||\n normalized === 'application/typescript' ||\n normalized === 'application/x-typescript' ||\n normalized === 'application/xml' ||\n normalized === 'application/yaml' ||\n normalized === 'application/x-yaml' ||\n normalized === 'application/toml' ||\n normalized === 'application/markdown' ||\n normalized === 'application/sql' ||\n normalized === 'application/graphql' ||\n normalized.endsWith('+json') ||\n normalized.endsWith('+xml')\n )\n}\n\nexport const textDocumentMimeTypeFromFilename = (filename: string) => {\n const normalized = filename.trim().toLowerCase()\n const entry = Object.entries(textDocumentMimeTypeByExtension).find(([extension]) =>\n normalized.endsWith(extension)\n )\n\n return entry?.[1]\n}\n\nexport const inferTextDocumentMimeType = (input: {\n readonly filename: string\n readonly mimeType: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n\n if (isTextDocumentMimeType(normalized)) return normalized\n if (!isUnknownDocumentMimeType(normalized)) return undefined\n\n return textDocumentMimeTypeFromFilename(input.filename)\n}\n\nexport const textToBase64Utf8 = (text: string) => {\n const bytes = new TextEncoder().encode(text)\n let binary = ''\n\n for (const byte of bytes) {\n binary += String.fromCharCode(byte)\n }\n\n return globalThis.btoa(binary)\n}\n\nexport const documentPartFromText = (input: {\n readonly text: string\n readonly filename: string\n readonly mimeType: string\n readonly title?: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n const mimeType = inferTextDocumentMimeType({\n filename: input.filename,\n mimeType: input.mimeType\n }) ?? (isUnknownDocumentMimeType(normalized) ? 'text/plain' : undefined)\n\n if (mimeType === undefined) return undefined\n\n const base = {\n source: inlineBase64AttachmentSource(textToBase64Utf8(input.text)),\n mimeType,\n filename: input.filename\n }\n\n return input.title === undefined\n ? DocumentPart.make(base)\n : DocumentPart.make({ ...base, title: input.title })\n}\n\nconst decodeBase64Utf8 = (data: string) => {\n const binary = globalThis.atob(data)\n const bytes = Uint8Array.from(binary, character => character.charCodeAt(0))\n\n return new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n}\n\nexport const attachmentSourceText = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Effect.try({\n try: () => Option.some(decodeBase64Utf8(source.data)),\n catch: error => error\n })\n case 'Url':\n case 'Ref':\n return Effect.succeed(Option.none<string>())\n }\n}\n\nexport const attachmentSourceBase64 = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(source.data)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n"],"mappings":";;;AAGA,IAAa,WAAb,cAA8B,OAAO,YAAsB,EAAE,QAAQ,EACnE,MAAM,OAAO,OACf,CAAC,EAAE,CAAC;AAEJ,IAAa,+BAAb,cAAkD,OAAO,YAA0C,EACjG,gBACA,EACE,MAAM,OAAO,OACf,CACF,EAAE,CAAC;AAEH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,EAAE,OAAO,EACxF,KAAK,OAAO,OACd,CAAC,EAAE,CAAC;AAEJ,IAAa,sBAAb,cAAyC,OAAO,YAAiC,EAAE,OAAO,EACxF,IAAI,OAAO,OACb,CAAC,EAAE,CAAC;AAEJ,MAAa,mBAAmB,OAAO,MAAM;CAC3C;CACA;CACA;AACF,CAAC;AAGD,IAAa,YAAb,cAA+B,OAAO,YAAuB,EAAE,SAAS;CACtE,QAAQ;CACR,UAAU,OAAO;CACjB,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,SAAQ,cAAa,UAAU,WAAW,CAAC,CAAC;CAE1E,OAAO,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC,EAAE,OAAO,KAAK;AAC/D;AAEA,MAAa,wBAAwB,WAA6B;CAChE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,IAAI;GAChB,WAAW,OAAO,KAAK,iBAAiB,OAAO,IAAI,CAAC;GACpD,QAAO,UAAS;EAClB,CAAC;EACH,KAAK;EACL,KAAK,OACH,OAAO,OAAO,QAAQ,OAAO,KAAa,CAAC;CAC/C;AACF;AAEA,MAAa,0BAA0B,WAA6B;CAClE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,KAAK,OAAO,IAAI;EAChC,KAAK;EACL,KAAK,OACH,OAAO,OAAO,KAAa;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"content.mjs","names":["Arr"],"sources":["../../src/protocol/content.ts"],"sourcesContent":["import { Array as Arr, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\n\nexport class TextPart extends Schema.TaggedClass<TextPart>()('Text', {\n text: Schema.String\n}) {}\n\nexport class InlineBase64AttachmentSource extends Schema.TaggedClass<InlineBase64AttachmentSource>()(\n 'InlineBase64',\n {\n data: Schema.String\n }\n) {}\n\nexport class UrlAttachmentSource extends Schema.TaggedClass<UrlAttachmentSource>()('Url', {\n url: Schema.String\n}) {}\n\nexport class RefAttachmentSource extends Schema.TaggedClass<RefAttachmentSource>()('Ref', {\n id: Schema.String\n}) {}\n\nexport const AttachmentSource = Schema.Union([\n InlineBase64AttachmentSource,\n UrlAttachmentSource,\n RefAttachmentSource\n])\nexport type AttachmentSource = typeof AttachmentSource.Type\n\nexport class ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n title: Schema.optional(Schema.String),\n width: Schema.optional(Schema.Number),\n height: Schema.optional(Schema.Number)\n}) {}\n\nexport class DocumentPart extends Schema.TaggedClass<DocumentPart>()('Document', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.String,\n title: Schema.optional(Schema.String)\n}) {}\n\nexport class AudioPart extends Schema.TaggedClass<AudioPart>()('Audio', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n durationMs: Schema.optional(Schema.Number)\n}) {}\n\nexport const ContentPart = Schema.Union([TextPart, ImagePart, DocumentPart, AudioPart])\nexport type ContentPart = typeof ContentPart.Type\n\nexport const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)])\nexport type Content = typeof Content.Type\n\nexport type AttachmentContentPart = ImagePart | DocumentPart | AudioPart\n\nexport type AttachmentSourceResolver<E = never, R = never> = (\n part: AttachmentContentPart\n) => Effect.Effect<AttachmentSource, E, R>\n\nconst resolveContentPartAttachmentSource = <E, R>(\n part: ContentPart,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<ContentPart, E, R> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part)\n case 'Image':\n return resolver(part).pipe(\n Effect.map(source =>\n ImagePart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title,\n width: part.width,\n height: part.height\n })\n )\n )\n case 'Document':\n return resolver(part).pipe(\n Effect.map(source =>\n DocumentPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title\n })\n )\n )\n case 'Audio':\n return resolver(part).pipe(\n Effect.map(source =>\n AudioPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n durationMs: part.durationMs\n })\n )\n )\n }\n}\n\nexport const resolveContentAttachmentSources = <E, R>(\n content: Content,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<Content, E, R> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => resolveContentPartAttachmentSource(part, resolver))\n\nexport const contentPartText = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n case 'Document':\n case 'Audio':\n return ''\n }\n}\n\nexport const contentPartPreview = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n return 'Image'\n case 'Document':\n return `Document: ${part.title ?? part.filename}`\n case 'Audio':\n return 'Audio'\n }\n}\n\nexport const contentText = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartText).join('')\n\nexport const contentPreview = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartPreview).join(', ')\n\nexport const contentParts = (content: Content): ReadonlyArray<ContentPart> =>\n typeof content === 'string' ? [TextPart.make({ text: content })] : content\n\nexport const isContentEmpty = (content: Content) =>\n typeof content === 'string'\n ? content.length === 0\n : content.length === 0 ||\n Arr.every(content, part => part._tag === 'Text' && part.text.length === 0)\n\nexport const appendTextToContent = (content: Content, text: string): Content => {\n if (typeof content === 'string') {\n return `${content}${text}`\n }\n\n return Option.match(Arr.last(content), {\n onNone: () => [TextPart.make({ text })],\n onSome: last =>\n last._tag !== 'Text'\n ? [...content, TextPart.make({ text })]\n : Arr.map(content, (part, index) =>\n index === content.length - 1 && part._tag === 'Text'\n ? TextPart.make({ text: `${part.text}${text}` })\n : part\n )\n })\n}\n\nexport const inlineBase64AttachmentSource = (data: string) => InlineBase64AttachmentSource.make({ data })\n\nexport const urlAttachmentSource = (url: string) => UrlAttachmentSource.make({ url })\n\nexport const refAttachmentSource = (id: string) => RefAttachmentSource.make({ id })\n\nexport const inlineBase64Source = inlineBase64AttachmentSource\n\nexport const attachmentSourcePreview = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return 'inline'\n case 'Url':\n return source.url\n case 'Ref':\n return source.id\n }\n}\n\nexport const attachmentSourceDataUrl = (source: AttachmentSource, mimeType: string) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(`data:${mimeType};base64,${source.data}`)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n\nexport const attachmentSourceUrl = (source: AttachmentSource, mimeType: string) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(`data:${mimeType};base64,${source.data}`)\n case 'Url':\n return Option.some(source.url)\n case 'Ref':\n return Option.none<string>()\n }\n}\n\nconst normalizeMimeType = (mimeType: string) => mimeType.split(';', 1)[0]?.trim().toLowerCase() ?? ''\n\nconst textDocumentMimeTypeByExtension: Readonly<Record<string, string>> = {\n '.csv': 'text/csv',\n '.css': 'text/css',\n '.gql': 'application/graphql',\n '.graphql': 'application/graphql',\n '.html': 'text/html',\n '.js': 'application/javascript',\n '.jsx': 'application/javascript',\n '.json': 'application/json',\n '.jsonl': 'application/x-ndjson',\n '.md': 'text/markdown',\n '.markdown': 'text/markdown',\n '.sql': 'application/sql',\n '.toml': 'application/toml',\n '.ts': 'application/typescript',\n '.tsx': 'application/typescript',\n '.txt': 'text/plain',\n '.xml': 'application/xml',\n '.yaml': 'application/yaml',\n '.yml': 'application/yaml'\n}\n\nconst isUnknownDocumentMimeType = (mimeType: string) =>\n mimeType.length === 0 || mimeType === 'application/octet-stream' || mimeType === 'binary/octet-stream'\n\nexport const isTextDocumentMimeType = (mimeType: string) => {\n const normalized = normalizeMimeType(mimeType)\n\n return (\n normalized.startsWith('text/') ||\n normalized === 'application/json' ||\n normalized === 'application/ld+json' ||\n normalized === 'application/jsonl' ||\n normalized === 'application/x-ndjson' ||\n normalized === 'application/javascript' ||\n normalized === 'application/x-javascript' ||\n normalized === 'application/typescript' ||\n normalized === 'application/x-typescript' ||\n normalized === 'application/xml' ||\n normalized === 'application/yaml' ||\n normalized === 'application/x-yaml' ||\n normalized === 'application/toml' ||\n normalized === 'application/markdown' ||\n normalized === 'application/sql' ||\n normalized === 'application/graphql' ||\n normalized.endsWith('+json') ||\n normalized.endsWith('+xml')\n )\n}\n\nexport const textDocumentMimeTypeFromFilename = (filename: string) => {\n const normalized = filename.trim().toLowerCase()\n const entry = Object.entries(textDocumentMimeTypeByExtension).find(([extension]) =>\n normalized.endsWith(extension)\n )\n\n return entry?.[1]\n}\n\nexport const inferTextDocumentMimeType = (input: {\n readonly filename: string\n readonly mimeType: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n\n if (isTextDocumentMimeType(normalized)) return normalized\n if (!isUnknownDocumentMimeType(normalized)) return undefined\n\n return textDocumentMimeTypeFromFilename(input.filename)\n}\n\nexport const textToBase64Utf8 = (text: string) => {\n const bytes = new TextEncoder().encode(text)\n let binary = ''\n\n for (const byte of bytes) {\n binary += String.fromCharCode(byte)\n }\n\n return globalThis.btoa(binary)\n}\n\nexport const documentPartFromText = (input: {\n readonly text: string\n readonly filename: string\n readonly mimeType: string\n readonly title?: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n const mimeType = inferTextDocumentMimeType({\n filename: input.filename,\n mimeType: input.mimeType\n }) ?? (isUnknownDocumentMimeType(normalized) ? 'text/plain' : undefined)\n\n if (mimeType === undefined) return undefined\n\n const base = {\n source: inlineBase64AttachmentSource(textToBase64Utf8(input.text)),\n mimeType,\n filename: input.filename\n }\n\n return input.title === undefined\n ? DocumentPart.make(base)\n : DocumentPart.make({ ...base, title: input.title })\n}\n\nconst decodeBase64Utf8 = (data: string) => {\n const binary = globalThis.atob(data)\n const bytes = Uint8Array.from(binary, character => character.charCodeAt(0))\n\n return new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n}\n\nexport const attachmentSourceText = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Effect.try({\n try: () => Option.some(decodeBase64Utf8(source.data)),\n catch: error => error\n })\n case 'Url':\n case 'Ref':\n return Effect.succeed(Option.none<string>())\n }\n}\n\nexport const attachmentSourceBase64 = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(source.data)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n"],"mappings":";;;AAGA,IAAa,WAAb,cAA8B,OAAO,YAAsB,EAAE,QAAQ,EACnE,MAAM,OAAO,OACf,CAAC,EAAE,CAAC;AAEJ,IAAa,+BAAb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apabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
2
|
+
import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
3
3
|
import { ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, PlainHitlResponse, PlainQuestionAnswer, PlainQuestionResponse, PlainToolApprovalResponse, QuestionAnswer, QuestionOption, QuestionPrompt, QuestionRequest, QuestionResponse, QuestionResponseOutcome, QuestionResponseStructuredContent, QuestionToolParams, ToolApprovalDecision, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalResponse, ToolCall, ToolDef, ToolResult, formatQuestionResponseContent, makeErrorToolResult, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, questionResponseStructuredContent } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, DanglingHostToolCall, HostToolCallPart, MessageAnnotations, MessageAuthor, MessageEnvelope, ProviderToolCallPart, ProviderToolResultPart, RepairDanglingHostToolCallsOptions, ToolResultMessage, TranscriptInvariantValidation, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, danglingHostToolCalls, messageContextText, prependMessageContextToContent, repairDanglingHostToolCalls, validateNoDanglingHostToolCalls } from "./message.mjs";
|
|
5
5
|
import { AgentInputUsage, AgentOutputUsage, AgentUsage, addAgentUsage, zeroAgentUsage } from "./usage.mjs";
|
|
@@ -10,5 +10,5 @@ import { AgentWebSocketClientMessage, AgentWebSocketServerMessage, QuestionRespo
|
|
|
10
10
|
//#region src/protocol/index.d.ts
|
|
11
11
|
type MessageId = string;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, type AttachmentContentPart, AttachmentSource, type AttachmentSourceResolver, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, type DanglingHostToolCall, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, type PlainHitlResponse, type PlainQuestionAnswer, type PlainQuestionResponse, type PlainToolApprovalResponse, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, type QuestionResponseStructuredContent, QuestionToolParams, RefAttachmentSource, type RepairDanglingHostToolCallsOptions, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, type TranscriptInvariantValidation, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
13
|
+
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, type AttachmentContentPart, AttachmentSource, type AttachmentSourceResolver, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, type DanglingHostToolCall, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, type PlainHitlResponse, type PlainQuestionAnswer, type PlainQuestionResponse, type PlainToolApprovalResponse, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, type QuestionResponseStructuredContent, QuestionToolParams, RefAttachmentSource, type RepairDanglingHostToolCallsOptions, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, type TranscriptInvariantValidation, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
14
14
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/protocol/index.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/protocol/index.ts"],"mappings":";;;;;;;;;;KAkKY,SAAA"}
|
package/dist/protocol/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
2
|
+
import { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
3
3
|
import { HitlRequest, HitlResponse, HitlResponseSource, QuestionAnswer, QuestionOption, QuestionPrompt, QuestionRequest, QuestionResponse, QuestionResponseOutcome, QuestionToolParams, ToolApprovalDecision, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalResponse, ToolCall, ToolDef, ToolResult, formatQuestionResponseContent, makeErrorToolResult, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, questionResponseStructuredContent } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, MessageAnnotations, MessageAuthor, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, danglingHostToolCalls, messageContextText, prependMessageContextToContent, repairDanglingHostToolCalls, validateNoDanglingHostToolCalls } from "./message.mjs";
|
|
5
5
|
import { AgentInputUsage, AgentOutputUsage, AgentUsage, addAgentUsage, zeroAgentUsage } from "./usage.mjs";
|
|
6
6
|
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId } from "./event.mjs";
|
|
7
7
|
import { AgentReasoningEffort } from "./reasoning.mjs";
|
|
8
8
|
import { AgentWebSocketClientMessage, AgentWebSocketServerMessage, QuestionResponseInput, SessionSnapshot, ToolApprovalResponseInput, UserInput } from "./session.mjs";
|
|
9
|
-
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, AttachmentSource, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
9
|
+
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, AttachmentSource, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
@@ -21,6 +21,9 @@ type AnthropicImageBlock = {
|
|
|
21
21
|
readonly type: 'base64';
|
|
22
22
|
readonly media_type: string;
|
|
23
23
|
readonly data: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: 'url';
|
|
26
|
+
readonly url: string;
|
|
24
27
|
};
|
|
25
28
|
};
|
|
26
29
|
type AnthropicDocumentBlock = {
|
|
@@ -29,6 +32,9 @@ type AnthropicDocumentBlock = {
|
|
|
29
32
|
readonly type: 'base64';
|
|
30
33
|
readonly media_type: 'application/pdf';
|
|
31
34
|
readonly data: string;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: 'url';
|
|
37
|
+
readonly url: string;
|
|
32
38
|
};
|
|
33
39
|
readonly title?: string;
|
|
34
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-provider.d.mts","names":[],"sources":["../../../src/providers/anthropic/claude-provider.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"claude-provider.d.mts","names":[],"s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ACtB,QAAA,EAAU,aAAA,CAAc,gBAAA;EAAA,SACxB,UAAA;EAAA,SACA,MAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;AAAA;AAAA,cAosBpB,4BAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SAAoB,SAAA;EAAA,SAA6B,MAAA;AAAA,MAChD,MAAA,CAAO,MAAA,CAAO,oBAAA,EAAsB,QAAA;AAAA,cA8e1B,6BAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cAoFd,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { classifyProviderFailure, providerErrorInfo, providerFailureCause, providerFailureRetryable } from "../provider-error.mjs";
|
|
2
2
|
import { validateProviderTranscript } from "../transcript.mjs";
|
|
3
3
|
import { anthropicClaudeAuthorizationHeaders, anthropicClaudeCodeEntrypoint, anthropicClaudeCodeVersion, anthropicClaudeOAuthUserAgent } from "./claude.mjs";
|
|
4
|
-
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls,
|
|
4
|
+
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceText, isTextDocumentMimeType, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
|
|
5
5
|
import { Effect, Layer, Option, Ref, Stream } from "effect";
|
|
6
6
|
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
@@ -192,6 +192,48 @@ const unsupportedContentError = (contentType) => new LLMError({
|
|
|
192
192
|
message: `${contentType} content is not supported by the Anthropic Claude provider yet`,
|
|
193
193
|
retryable: false
|
|
194
194
|
});
|
|
195
|
+
const imageToAnthropicBlock = (part) => {
|
|
196
|
+
switch (part.source._tag) {
|
|
197
|
+
case "InlineBase64": return Effect.succeed({
|
|
198
|
+
type: "image",
|
|
199
|
+
source: {
|
|
200
|
+
type: "base64",
|
|
201
|
+
media_type: part.mimeType,
|
|
202
|
+
data: part.source.data
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
case "Url": return Effect.succeed({
|
|
206
|
+
type: "image",
|
|
207
|
+
source: {
|
|
208
|
+
type: "url",
|
|
209
|
+
url: part.source.url
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
case "Ref": return Effect.fail(unsupportedContentError("Unresolved image source"));
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const pdfDocumentToAnthropicBlock = (part) => {
|
|
216
|
+
switch (part.source._tag) {
|
|
217
|
+
case "InlineBase64": return Effect.succeed({
|
|
218
|
+
type: "document",
|
|
219
|
+
source: {
|
|
220
|
+
type: "base64",
|
|
221
|
+
media_type: "application/pdf",
|
|
222
|
+
data: part.source.data
|
|
223
|
+
},
|
|
224
|
+
title: part.title ?? part.filename
|
|
225
|
+
});
|
|
226
|
+
case "Url": return Effect.succeed({
|
|
227
|
+
type: "document",
|
|
228
|
+
source: {
|
|
229
|
+
type: "url",
|
|
230
|
+
url: part.source.url
|
|
231
|
+
},
|
|
232
|
+
title: part.title ?? part.filename
|
|
233
|
+
});
|
|
234
|
+
case "Ref": return Effect.fail(unsupportedContentError("Unresolved document source"));
|
|
235
|
+
}
|
|
236
|
+
};
|
|
195
237
|
const textDocumentToAnthropicBlock = (part) => attachmentSourceText(part.source).pipe(Effect.mapError(() => unsupportedContentError("Invalid document text")), Effect.flatMap(Option.match({
|
|
196
238
|
onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
|
|
197
239
|
onSome: (text) => {
|
|
@@ -208,29 +250,8 @@ const contentPartToUserBlock = (part) => {
|
|
|
208
250
|
type: "text",
|
|
209
251
|
text: part.text
|
|
210
252
|
});
|
|
211
|
-
case "Image": return
|
|
212
|
-
|
|
213
|
-
onSome: (data) => Effect.succeed({
|
|
214
|
-
type: "image",
|
|
215
|
-
source: {
|
|
216
|
-
type: "base64",
|
|
217
|
-
media_type: part.mimeType,
|
|
218
|
-
data
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
});
|
|
222
|
-
case "Document": return isTextDocumentMimeType(part.mimeType) ? textDocumentToAnthropicBlock(part) : part.mimeType === "application/pdf" ? Option.match(attachmentSourceBase64(part.source), {
|
|
223
|
-
onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
|
|
224
|
-
onSome: (data) => Effect.succeed({
|
|
225
|
-
type: "document",
|
|
226
|
-
source: {
|
|
227
|
-
type: "base64",
|
|
228
|
-
media_type: "application/pdf",
|
|
229
|
-
data
|
|
230
|
-
},
|
|
231
|
-
title: part.title ?? part.filename
|
|
232
|
-
})
|
|
233
|
-
}) : Effect.fail(unsupportedContentError(`Document ${part.mimeType}`));
|
|
253
|
+
case "Image": return imageToAnthropicBlock(part);
|
|
254
|
+
case "Document": return isTextDocumentMimeType(part.mimeType) ? textDocumentToAnthropicBlock(part) : part.mimeType === "application/pdf" ? pdfDocumentToAnthropicBlock(part) : Effect.fail(unsupportedContentError(`Document ${part.mimeType}`));
|
|
234
255
|
case "Audio": return Effect.fail(unsupportedContentError("Audio"));
|
|
235
256
|
}
|
|
236
257
|
};
|