@yolk-sdk/agent 0.0.1-canary.8 → 0.0.1-canary.9
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 +8 -3
- package/dist/protocol/content.d.mts +36 -5
- package/dist/protocol/content.d.mts.map +1 -1
- package/dist/protocol/content.mjs +72 -12
- 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/package.json +1 -1
- package/src/protocol/content.ts +132 -6
- package/src/protocol/index.ts +14 -0
package/README.md
CHANGED
|
@@ -66,9 +66,14 @@ const program = run({
|
|
|
66
66
|
`Content` is either plain text or ordered parts:
|
|
67
67
|
|
|
68
68
|
- `TextPart`
|
|
69
|
-
- `ImagePart`
|
|
70
|
-
- `DocumentPart`
|
|
71
|
-
- `AudioPart`
|
|
69
|
+
- `ImagePart` with `InlineBase64`, `Url`, or host-owned `Ref` source
|
|
70
|
+
- `DocumentPart` with `InlineBase64`, `Url`, or host-owned `Ref` source
|
|
71
|
+
- `AudioPart` with `InlineBase64`, `Url`, or host-owned `Ref` source
|
|
72
|
+
|
|
73
|
+
Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
|
|
74
|
+
`refAttachmentSource`. Providers require inline/resolved media before lowering. Use inline base64
|
|
75
|
+
for simple apps, or persist `Ref` values and call `resolveContentAttachmentSources` at your storage
|
|
76
|
+
boundary before provider execution. Host apps own upload, auth, retention, and ref hydration policy.
|
|
72
77
|
|
|
73
78
|
Use model capabilities like `textOnlyModelCapabilities`, `textImageModelCapabilities`, or
|
|
74
79
|
`textImageDocumentModelCapabilities` so the loop rejects unsupported inputs before provider calls.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
1
2
|
import * as Schema from "effect/Schema";
|
|
2
3
|
|
|
3
4
|
//#region src/protocol/content.d.ts
|
|
@@ -5,27 +6,50 @@ declare const TextPart_base: Schema.Class<TextPart, Schema.TaggedStruct<"Text",
|
|
|
5
6
|
readonly text: Schema.String;
|
|
6
7
|
}>, {}>;
|
|
7
8
|
declare class TextPart extends TextPart_base {}
|
|
8
|
-
declare const
|
|
9
|
+
declare const InlineBase64AttachmentSource_base: Schema.Class<InlineBase64AttachmentSource, Schema.TaggedStruct<"InlineBase64", {
|
|
9
10
|
readonly data: Schema.String;
|
|
11
|
+
}>, {}>;
|
|
12
|
+
declare class InlineBase64AttachmentSource extends InlineBase64AttachmentSource_base {}
|
|
13
|
+
declare const UrlAttachmentSource_base: Schema.Class<UrlAttachmentSource, Schema.TaggedStruct<"Url", {
|
|
14
|
+
readonly url: Schema.String;
|
|
15
|
+
}>, {}>;
|
|
16
|
+
declare class UrlAttachmentSource extends UrlAttachmentSource_base {}
|
|
17
|
+
declare const RefAttachmentSource_base: Schema.Class<RefAttachmentSource, Schema.TaggedStruct<"Ref", {
|
|
18
|
+
readonly id: Schema.String;
|
|
19
|
+
}>, {}>;
|
|
20
|
+
declare class RefAttachmentSource extends RefAttachmentSource_base {}
|
|
21
|
+
declare const AttachmentSource: Schema.Union<readonly [typeof InlineBase64AttachmentSource, typeof UrlAttachmentSource, typeof RefAttachmentSource]>;
|
|
22
|
+
type AttachmentSource = typeof AttachmentSource.Type;
|
|
23
|
+
declare const ImagePart_base: Schema.Class<ImagePart, Schema.TaggedStruct<"Image", {
|
|
24
|
+
readonly source: Schema.Union<readonly [typeof InlineBase64AttachmentSource, typeof UrlAttachmentSource, typeof RefAttachmentSource]>;
|
|
10
25
|
readonly mimeType: Schema.String;
|
|
26
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
27
|
+
readonly title: Schema.optional<Schema.String>;
|
|
28
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
29
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
11
30
|
}>, {}>;
|
|
12
31
|
declare class ImagePart extends ImagePart_base {}
|
|
13
32
|
declare const DocumentPart_base: Schema.Class<DocumentPart, Schema.TaggedStruct<"Document", {
|
|
14
|
-
readonly
|
|
33
|
+
readonly source: Schema.Union<readonly [typeof InlineBase64AttachmentSource, typeof UrlAttachmentSource, typeof RefAttachmentSource]>;
|
|
15
34
|
readonly mimeType: Schema.String;
|
|
16
35
|
readonly filename: Schema.String;
|
|
17
36
|
readonly title: Schema.optional<Schema.String>;
|
|
18
37
|
}>, {}>;
|
|
19
38
|
declare class DocumentPart extends DocumentPart_base {}
|
|
20
39
|
declare const AudioPart_base: Schema.Class<AudioPart, Schema.TaggedStruct<"Audio", {
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
40
|
+
readonly source: Schema.Union<readonly [typeof InlineBase64AttachmentSource, typeof UrlAttachmentSource, typeof RefAttachmentSource]>;
|
|
41
|
+
readonly mimeType: Schema.String;
|
|
42
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
43
|
+
readonly durationMs: Schema.optional<Schema.Number>;
|
|
23
44
|
}>, {}>;
|
|
24
45
|
declare class AudioPart extends AudioPart_base {}
|
|
25
46
|
declare const ContentPart: Schema.Union<readonly [typeof TextPart, typeof ImagePart, typeof DocumentPart, typeof AudioPart]>;
|
|
26
47
|
type ContentPart = typeof ContentPart.Type;
|
|
27
48
|
declare const Content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [typeof TextPart, typeof ImagePart, typeof DocumentPart, typeof AudioPart]>>]>;
|
|
28
49
|
type Content = typeof Content.Type;
|
|
50
|
+
type AttachmentContentPart = ImagePart | DocumentPart | AudioPart;
|
|
51
|
+
type AttachmentSourceResolver<E = never, R = never> = (part: AttachmentContentPart) => Effect.Effect<AttachmentSource, E, R>;
|
|
52
|
+
declare const resolveContentAttachmentSources: <E, R>(content: Content, resolver: AttachmentSourceResolver<E, R>) => Effect.Effect<Content, E, R>;
|
|
29
53
|
declare const contentPartText: (part: ContentPart) => string;
|
|
30
54
|
declare const contentPartPreview: (part: ContentPart) => string;
|
|
31
55
|
declare const contentText: (content: Content) => string;
|
|
@@ -33,6 +57,13 @@ declare const contentPreview: (content: Content) => string;
|
|
|
33
57
|
declare const contentParts: (content: Content) => ReadonlyArray<ContentPart>;
|
|
34
58
|
declare const isContentEmpty: (content: Content) => boolean;
|
|
35
59
|
declare const appendTextToContent: (content: Content, text: string) => Content;
|
|
60
|
+
declare const inlineBase64AttachmentSource: (data: string) => InlineBase64AttachmentSource;
|
|
61
|
+
declare const urlAttachmentSource: (url: string) => UrlAttachmentSource;
|
|
62
|
+
declare const refAttachmentSource: (id: string) => RefAttachmentSource;
|
|
63
|
+
declare const inlineBase64Source: (data: string) => InlineBase64AttachmentSource;
|
|
64
|
+
declare const attachmentSourcePreview: (source: AttachmentSource) => string;
|
|
65
|
+
declare const attachmentSourceDataUrl: (source: AttachmentSource, mimeType: string) => Option.Option<string>;
|
|
66
|
+
declare const attachmentSourceBase64: (source: AttachmentSource) => Option.Option<string>;
|
|
36
67
|
//#endregion
|
|
37
|
-
export { AudioPart, Content, ContentPart, DocumentPart, ImagePart, TextPart, appendTextToContent, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, isContentEmpty };
|
|
68
|
+
export { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, urlAttachmentSource };
|
|
38
69
|
//# sourceMappingURL=content.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.mts","names":[],"sources":["../../src/protocol/content.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"content.d.mts","names":[],"sources":["../../src/protocol/content.ts"],"mappings":";;;;cACuC,aAAA;;;cAE1B,QAAA,SAAiB,aA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AgB,EAAP,OAAO;AAAA,cAG/B,cAAA,GAAkB,OAAgB,EAAP,OAAO;AAAA,cAGlC,YAAA,GAAgB,OAAA,EAAS,OAAA,KAAU,aAAA,CAAc,WAAA;AAAA,cAGjD,cAAA,GAAkB,OAAgB,EAAP,OAAO;AAAA,cAMlC,mBAAA,GAAuB,OAAA,EAAS,OAAA,EAAS,IAAA,aAAe,OAgBpE;AAAA,cAEY,4BAAA,GAAgC,IAAA,aAAY,4BAAgD;AAAA,cAE5F,mBAAA,GAAuB,GAAA,aAAW,mBAAsC;AAAA,cAExE,mBAAA,GAAuB,EAAA,aAAU,mBAAqC;AAAA,cAEtE,kBAAA,GAAkB,IAAA,aAN0B,4BAMK;AAAA,cAEjD,uBAAA,GAA2B,MAAwB,EAAhB,gBAAgB;AAAA,cAWnD,uBAAA,GAA2B,MAAA,EAAQ,gBAAA,EAAkB,QAAA,aAAgB,MAAA,CAAA,MAAA;AAAA,cAUrE,sBAAA,GAA0B,MAAA,EAAQ,gBAAA,KAAgB,MAAA,CAAA,MAAA"}
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
import { Array, Option } from "effect";
|
|
1
|
+
import { Array, Effect, Option } from "effect";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
3
|
//#region src/protocol/content.ts
|
|
4
4
|
var TextPart = class extends Schema.TaggedClass()("Text", { text: Schema.String }) {};
|
|
5
|
+
var InlineBase64AttachmentSource = class extends Schema.TaggedClass()("InlineBase64", { data: Schema.String }) {};
|
|
6
|
+
var UrlAttachmentSource = class extends Schema.TaggedClass()("Url", { url: Schema.String }) {};
|
|
7
|
+
var RefAttachmentSource = class extends Schema.TaggedClass()("Ref", { id: Schema.String }) {};
|
|
8
|
+
const AttachmentSource = Schema.Union([
|
|
9
|
+
InlineBase64AttachmentSource,
|
|
10
|
+
UrlAttachmentSource,
|
|
11
|
+
RefAttachmentSource
|
|
12
|
+
]);
|
|
5
13
|
var ImagePart = class extends Schema.TaggedClass()("Image", {
|
|
6
|
-
|
|
7
|
-
mimeType: Schema.String
|
|
14
|
+
source: AttachmentSource,
|
|
15
|
+
mimeType: Schema.String,
|
|
16
|
+
filename: Schema.optional(Schema.String),
|
|
17
|
+
title: Schema.optional(Schema.String),
|
|
18
|
+
width: Schema.optional(Schema.Number),
|
|
19
|
+
height: Schema.optional(Schema.Number)
|
|
8
20
|
}) {};
|
|
9
21
|
var DocumentPart = class extends Schema.TaggedClass()("Document", {
|
|
10
|
-
|
|
22
|
+
source: AttachmentSource,
|
|
11
23
|
mimeType: Schema.String,
|
|
12
24
|
filename: Schema.String,
|
|
13
25
|
title: Schema.optional(Schema.String)
|
|
14
26
|
}) {};
|
|
15
27
|
var AudioPart = class extends Schema.TaggedClass()("Audio", {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"mp3",
|
|
21
|
-
"opus"
|
|
22
|
-
])
|
|
28
|
+
source: AttachmentSource,
|
|
29
|
+
mimeType: Schema.String,
|
|
30
|
+
filename: Schema.optional(Schema.String),
|
|
31
|
+
durationMs: Schema.optional(Schema.Number)
|
|
23
32
|
}) {};
|
|
24
33
|
const ContentPart = Schema.Union([
|
|
25
34
|
TextPart,
|
|
@@ -28,6 +37,32 @@ const ContentPart = Schema.Union([
|
|
|
28
37
|
AudioPart
|
|
29
38
|
]);
|
|
30
39
|
const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)]);
|
|
40
|
+
const resolveContentPartAttachmentSource = (part, resolver) => {
|
|
41
|
+
switch (part._tag) {
|
|
42
|
+
case "Text": return Effect.succeed(part);
|
|
43
|
+
case "Image": return resolver(part).pipe(Effect.map((source) => ImagePart.make({
|
|
44
|
+
source,
|
|
45
|
+
mimeType: part.mimeType,
|
|
46
|
+
filename: part.filename,
|
|
47
|
+
title: part.title,
|
|
48
|
+
width: part.width,
|
|
49
|
+
height: part.height
|
|
50
|
+
})));
|
|
51
|
+
case "Document": return resolver(part).pipe(Effect.map((source) => DocumentPart.make({
|
|
52
|
+
source,
|
|
53
|
+
mimeType: part.mimeType,
|
|
54
|
+
filename: part.filename,
|
|
55
|
+
title: part.title
|
|
56
|
+
})));
|
|
57
|
+
case "Audio": return resolver(part).pipe(Effect.map((source) => AudioPart.make({
|
|
58
|
+
source,
|
|
59
|
+
mimeType: part.mimeType,
|
|
60
|
+
filename: part.filename,
|
|
61
|
+
durationMs: part.durationMs
|
|
62
|
+
})));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const resolveContentAttachmentSources = (content, resolver) => typeof content === "string" ? Effect.succeed(content) : Effect.forEach(content, (part) => resolveContentPartAttachmentSource(part, resolver));
|
|
31
66
|
const contentPartText = (part) => {
|
|
32
67
|
switch (part._tag) {
|
|
33
68
|
case "Text": return part.text;
|
|
@@ -55,7 +90,32 @@ const appendTextToContent = (content, text) => {
|
|
|
55
90
|
onSome: (last) => last._tag !== "Text" ? [...content, TextPart.make({ text })] : Array.map(content, (part, index) => index === content.length - 1 && part._tag === "Text" ? TextPart.make({ text: `${part.text}${text}` }) : part)
|
|
56
91
|
});
|
|
57
92
|
};
|
|
93
|
+
const inlineBase64AttachmentSource = (data) => InlineBase64AttachmentSource.make({ data });
|
|
94
|
+
const urlAttachmentSource = (url) => UrlAttachmentSource.make({ url });
|
|
95
|
+
const refAttachmentSource = (id) => RefAttachmentSource.make({ id });
|
|
96
|
+
const inlineBase64Source = inlineBase64AttachmentSource;
|
|
97
|
+
const attachmentSourcePreview = (source) => {
|
|
98
|
+
switch (source._tag) {
|
|
99
|
+
case "InlineBase64": return "inline";
|
|
100
|
+
case "Url": return source.url;
|
|
101
|
+
case "Ref": return source.id;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const attachmentSourceDataUrl = (source, mimeType) => {
|
|
105
|
+
switch (source._tag) {
|
|
106
|
+
case "InlineBase64": return Option.some(`data:${mimeType};base64,${source.data}`);
|
|
107
|
+
case "Url":
|
|
108
|
+
case "Ref": return Option.none();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const attachmentSourceBase64 = (source) => {
|
|
112
|
+
switch (source._tag) {
|
|
113
|
+
case "InlineBase64": return Option.some(source.data);
|
|
114
|
+
case "Url":
|
|
115
|
+
case "Ref": return Option.none();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
58
118
|
//#endregion
|
|
59
|
-
export { AudioPart, Content, ContentPart, DocumentPart, ImagePart, TextPart, appendTextToContent, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, isContentEmpty };
|
|
119
|
+
export { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, urlAttachmentSource };
|
|
60
120
|
|
|
61
121
|
//# sourceMappingURL=content.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.mjs","names":["Arr"],"sources":["../../src/protocol/content.ts"],"sourcesContent":["import { Array as Arr, 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 ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {\n
|
|
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 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,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,QAAQ,OAAO,SAAS,OAAO,MAAM;AACvC,CAAC,EAAE,CAAC;AAEJ,IAAa,eAAb,cAAkC,OAAO,YAA0B,EAAE,YAAY;CAC/E,QAAQ;CACR,UAAU,OAAO;CACjB,UAAU,OAAO;CAC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AoB,KAAK,EAAE,GAAG,CAAC;AAElF,MAAa,qBAAqB;AAElC,MAAa,2BAA2B,WAA6B;CACnE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO;EACT,KAAK,OACH,OAAO,OAAO;EAChB,KAAK,OACH,OAAO,OAAO;CAClB;AACF;AAEA,MAAa,2BAA2B,QAA0B,aAAqB;CACrF,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,KAAK,QAAQ,SAAS,UAAU,OAAO,MAAM;EAC7D,KAAK;EACL,KAAK,OACH,OAAO,OAAO,KAAa;CAC/B;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,5 +1,5 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AudioPart, Content, ContentPart, DocumentPart, ImagePart, TextPart, appendTextToContent, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, isContentEmpty } from "./content.mjs";
|
|
2
|
+
import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, 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 } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText } 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, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageId, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, 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, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, isContentEmpty, makeSubagentRunId, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, 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, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageId, 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, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, makeSubagentRunId, refAttachmentSource, resolveContentAttachmentSources, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, urlAttachmentSource, 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":";;;;;;;;;;KA6HY,SAAA"}
|
package/dist/protocol/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AudioPart, Content, ContentPart, DocumentPart, ImagePart, TextPart, appendTextToContent, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, isContentEmpty } from "./content.mjs";
|
|
2
|
+
import { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, 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 } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText } 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, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, 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, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, 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, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, isContentEmpty, makeSubagentRunId, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, 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, 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, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, makeSubagentRunId, refAttachmentSource, resolveContentAttachmentSources, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, urlAttachmentSource, zeroAgentUsage };
|
package/package.json
CHANGED
package/src/protocol/content.ts
CHANGED
|
@@ -1,25 +1,53 @@
|
|
|
1
|
-
import { Array as Arr, Option } from 'effect'
|
|
1
|
+
import { Array as Arr, Effect, Option } from 'effect'
|
|
2
2
|
import * as Schema from 'effect/Schema'
|
|
3
3
|
|
|
4
4
|
export class TextPart extends Schema.TaggedClass<TextPart>()('Text', {
|
|
5
5
|
text: Schema.String
|
|
6
6
|
}) {}
|
|
7
7
|
|
|
8
|
+
export class InlineBase64AttachmentSource extends Schema.TaggedClass<InlineBase64AttachmentSource>()(
|
|
9
|
+
'InlineBase64',
|
|
10
|
+
{
|
|
11
|
+
data: Schema.String
|
|
12
|
+
}
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
export class UrlAttachmentSource extends Schema.TaggedClass<UrlAttachmentSource>()('Url', {
|
|
16
|
+
url: Schema.String
|
|
17
|
+
}) {}
|
|
18
|
+
|
|
19
|
+
export class RefAttachmentSource extends Schema.TaggedClass<RefAttachmentSource>()('Ref', {
|
|
20
|
+
id: Schema.String
|
|
21
|
+
}) {}
|
|
22
|
+
|
|
23
|
+
export const AttachmentSource = Schema.Union([
|
|
24
|
+
InlineBase64AttachmentSource,
|
|
25
|
+
UrlAttachmentSource,
|
|
26
|
+
RefAttachmentSource
|
|
27
|
+
])
|
|
28
|
+
export type AttachmentSource = typeof AttachmentSource.Type
|
|
29
|
+
|
|
8
30
|
export class ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {
|
|
9
|
-
|
|
10
|
-
mimeType: Schema.String
|
|
31
|
+
source: AttachmentSource,
|
|
32
|
+
mimeType: Schema.String,
|
|
33
|
+
filename: Schema.optional(Schema.String),
|
|
34
|
+
title: Schema.optional(Schema.String),
|
|
35
|
+
width: Schema.optional(Schema.Number),
|
|
36
|
+
height: Schema.optional(Schema.Number)
|
|
11
37
|
}) {}
|
|
12
38
|
|
|
13
39
|
export class DocumentPart extends Schema.TaggedClass<DocumentPart>()('Document', {
|
|
14
|
-
|
|
40
|
+
source: AttachmentSource,
|
|
15
41
|
mimeType: Schema.String,
|
|
16
42
|
filename: Schema.String,
|
|
17
43
|
title: Schema.optional(Schema.String)
|
|
18
44
|
}) {}
|
|
19
45
|
|
|
20
46
|
export class AudioPart extends Schema.TaggedClass<AudioPart>()('Audio', {
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
source: AttachmentSource,
|
|
48
|
+
mimeType: Schema.String,
|
|
49
|
+
filename: Schema.optional(Schema.String),
|
|
50
|
+
durationMs: Schema.optional(Schema.Number)
|
|
23
51
|
}) {}
|
|
24
52
|
|
|
25
53
|
export const ContentPart = Schema.Union([TextPart, ImagePart, DocumentPart, AudioPart])
|
|
@@ -28,6 +56,65 @@ export type ContentPart = typeof ContentPart.Type
|
|
|
28
56
|
export const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)])
|
|
29
57
|
export type Content = typeof Content.Type
|
|
30
58
|
|
|
59
|
+
export type AttachmentContentPart = ImagePart | DocumentPart | AudioPart
|
|
60
|
+
|
|
61
|
+
export type AttachmentSourceResolver<E = never, R = never> = (
|
|
62
|
+
part: AttachmentContentPart
|
|
63
|
+
) => Effect.Effect<AttachmentSource, E, R>
|
|
64
|
+
|
|
65
|
+
const resolveContentPartAttachmentSource = <E, R>(
|
|
66
|
+
part: ContentPart,
|
|
67
|
+
resolver: AttachmentSourceResolver<E, R>
|
|
68
|
+
): Effect.Effect<ContentPart, E, R> => {
|
|
69
|
+
switch (part._tag) {
|
|
70
|
+
case 'Text':
|
|
71
|
+
return Effect.succeed(part)
|
|
72
|
+
case 'Image':
|
|
73
|
+
return resolver(part).pipe(
|
|
74
|
+
Effect.map(source =>
|
|
75
|
+
ImagePart.make({
|
|
76
|
+
source,
|
|
77
|
+
mimeType: part.mimeType,
|
|
78
|
+
filename: part.filename,
|
|
79
|
+
title: part.title,
|
|
80
|
+
width: part.width,
|
|
81
|
+
height: part.height
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
case 'Document':
|
|
86
|
+
return resolver(part).pipe(
|
|
87
|
+
Effect.map(source =>
|
|
88
|
+
DocumentPart.make({
|
|
89
|
+
source,
|
|
90
|
+
mimeType: part.mimeType,
|
|
91
|
+
filename: part.filename,
|
|
92
|
+
title: part.title
|
|
93
|
+
})
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
case 'Audio':
|
|
97
|
+
return resolver(part).pipe(
|
|
98
|
+
Effect.map(source =>
|
|
99
|
+
AudioPart.make({
|
|
100
|
+
source,
|
|
101
|
+
mimeType: part.mimeType,
|
|
102
|
+
filename: part.filename,
|
|
103
|
+
durationMs: part.durationMs
|
|
104
|
+
})
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const resolveContentAttachmentSources = <E, R>(
|
|
111
|
+
content: Content,
|
|
112
|
+
resolver: AttachmentSourceResolver<E, R>
|
|
113
|
+
): Effect.Effect<Content, E, R> =>
|
|
114
|
+
typeof content === 'string'
|
|
115
|
+
? Effect.succeed(content)
|
|
116
|
+
: Effect.forEach(content, part => resolveContentPartAttachmentSource(part, resolver))
|
|
117
|
+
|
|
31
118
|
export const contentPartText = (part: ContentPart) => {
|
|
32
119
|
switch (part._tag) {
|
|
33
120
|
case 'Text':
|
|
@@ -84,3 +171,42 @@ export const appendTextToContent = (content: Content, text: string): Content =>
|
|
|
84
171
|
)
|
|
85
172
|
})
|
|
86
173
|
}
|
|
174
|
+
|
|
175
|
+
export const inlineBase64AttachmentSource = (data: string) => InlineBase64AttachmentSource.make({ data })
|
|
176
|
+
|
|
177
|
+
export const urlAttachmentSource = (url: string) => UrlAttachmentSource.make({ url })
|
|
178
|
+
|
|
179
|
+
export const refAttachmentSource = (id: string) => RefAttachmentSource.make({ id })
|
|
180
|
+
|
|
181
|
+
export const inlineBase64Source = inlineBase64AttachmentSource
|
|
182
|
+
|
|
183
|
+
export const attachmentSourcePreview = (source: AttachmentSource) => {
|
|
184
|
+
switch (source._tag) {
|
|
185
|
+
case 'InlineBase64':
|
|
186
|
+
return 'inline'
|
|
187
|
+
case 'Url':
|
|
188
|
+
return source.url
|
|
189
|
+
case 'Ref':
|
|
190
|
+
return source.id
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const attachmentSourceDataUrl = (source: AttachmentSource, mimeType: string) => {
|
|
195
|
+
switch (source._tag) {
|
|
196
|
+
case 'InlineBase64':
|
|
197
|
+
return Option.some(`data:${mimeType};base64,${source.data}`)
|
|
198
|
+
case 'Url':
|
|
199
|
+
case 'Ref':
|
|
200
|
+
return Option.none<string>()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const attachmentSourceBase64 = (source: AttachmentSource) => {
|
|
205
|
+
switch (source._tag) {
|
|
206
|
+
case 'InlineBase64':
|
|
207
|
+
return Option.some(source.data)
|
|
208
|
+
case 'Url':
|
|
209
|
+
case 'Ref':
|
|
210
|
+
return Option.none<string>()
|
|
211
|
+
}
|
|
212
|
+
}
|
package/src/protocol/index.ts
CHANGED
|
@@ -7,6 +7,12 @@ export {
|
|
|
7
7
|
} from './capability.ts'
|
|
8
8
|
export {
|
|
9
9
|
appendTextToContent,
|
|
10
|
+
attachmentSourceBase64,
|
|
11
|
+
attachmentSourceDataUrl,
|
|
12
|
+
AttachmentSource,
|
|
13
|
+
type AttachmentContentPart,
|
|
14
|
+
type AttachmentSourceResolver,
|
|
15
|
+
attachmentSourcePreview,
|
|
10
16
|
AudioPart,
|
|
11
17
|
Content,
|
|
12
18
|
ContentPart,
|
|
@@ -17,7 +23,15 @@ export {
|
|
|
17
23
|
contentText,
|
|
18
24
|
DocumentPart,
|
|
19
25
|
ImagePart,
|
|
26
|
+
InlineBase64AttachmentSource,
|
|
27
|
+
inlineBase64AttachmentSource,
|
|
28
|
+
inlineBase64Source,
|
|
20
29
|
isContentEmpty,
|
|
30
|
+
refAttachmentSource,
|
|
31
|
+
RefAttachmentSource,
|
|
32
|
+
resolveContentAttachmentSources,
|
|
33
|
+
urlAttachmentSource,
|
|
34
|
+
UrlAttachmentSource,
|
|
21
35
|
TextPart
|
|
22
36
|
} from './content.ts'
|
|
23
37
|
export {
|