@yolk-sdk/agent 0.1.0-canary.33 → 0.1.0-canary.36
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 +2 -1
- package/dist/protocol/content.d.mts +14 -1
- package/dist/protocol/content.d.mts.map +1 -1
- package/dist/protocol/content.mjs +26 -7
- 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.map +1 -1
- package/dist/providers/anthropic/claude-provider.mjs +3 -3
- 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.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +2 -2
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/openai/realtime/client-codec.d.mts.map +1 -1
- package/dist/providers/openai/realtime/client-codec.mjs +4 -3
- package/dist/providers/openai/realtime/client-codec.mjs.map +1 -1
- package/dist/providers/openai/realtime/index.d.mts +2 -2
- package/dist/providers/openai/realtime/index.mjs +2 -2
- package/dist/providers/openai/realtime/session-config.d.mts +10 -1
- package/dist/providers/openai/realtime/session-config.d.mts.map +1 -1
- package/dist/providers/openai/realtime/session-config.mjs +54 -2
- package/dist/providers/openai/realtime/session-config.mjs.map +1 -1
- package/dist/voice/index.d.mts +4 -2
- package/dist/voice/index.mjs +3 -1
- package/dist/voice/outbox.d.mts +36 -0
- package/dist/voice/outbox.d.mts.map +1 -0
- package/dist/voice/outbox.mjs +80 -0
- package/dist/voice/outbox.mjs.map +1 -0
- package/dist/voice/projection.d.mts +12 -2
- package/dist/voice/projection.d.mts.map +1 -1
- package/dist/voice/projection.mjs +9 -3
- package/dist/voice/projection.mjs.map +1 -1
- package/dist/voice/react.d.mts +11 -2
- package/dist/voice/react.d.mts.map +1 -1
- package/dist/voice/react.mjs +21 -16
- package/dist/voice/react.mjs.map +1 -1
- package/dist/voice/session-log.d.mts +77 -0
- package/dist/voice/session-log.d.mts.map +1 -0
- package/dist/voice/session-log.mjs +144 -0
- package/dist/voice/session-log.mjs.map +1 -0
- package/package.json +1 -1
- package/src/protocol/content.ts +30 -0
- package/src/protocol/index.ts +2 -0
- package/src/providers/anthropic/claude-provider.ts +4 -1
- package/src/providers/openai/codex-provider.ts +7 -1
- package/src/providers/openai/provider.ts +7 -1
- package/src/providers/openai/realtime/client-codec.ts +11 -3
- package/src/providers/openai/realtime/index.ts +1 -0
- package/src/providers/openai/realtime/session-config.ts +106 -1
- package/src/voice/index.ts +19 -1
- package/src/voice/outbox.ts +155 -0
- package/src/voice/projection.ts +37 -3
- package/src/voice/react.ts +24 -5
- package/src/voice/session-log.ts +196 -0
package/README.md
CHANGED
|
@@ -322,7 +322,8 @@ handler, approval HITL, transcript projection, and one-shot TTS/STT contracts.
|
|
|
322
322
|
back-to-back responses, multi-item responses, and duplicate final transcript event families
|
|
323
323
|
never concatenate, wipe, or duplicate messages. `sequenceVoiceEvent`/`dedupeStoredVoiceEvents`
|
|
324
324
|
give replay-safe durable event ids; `voiceSeedTextsFromMessages` seeds new provider sessions
|
|
325
|
-
after reconnect
|
|
325
|
+
after reconnect, optionally prefixing user seeds with author display names via
|
|
326
|
+
`{ includeAuthors: true }` for multi-user transcripts.
|
|
326
327
|
- `makeWebSocketVoiceTransport` covers Node/server realtime sessions;
|
|
327
328
|
`@yolk-sdk/agent/providers/openai/speech` provides `VoiceSpeechSynthesizer` /
|
|
328
329
|
`VoiceTranscriber` layers. `VoiceSpeechRequest.instructions` steers delivery style only, and
|
|
@@ -52,6 +52,19 @@ type AttachmentSourceResolver<E = never, R = never> = (part: AttachmentContentPa
|
|
|
52
52
|
declare const resolveContentAttachmentSources: <E, R>(content: Content, resolver: AttachmentSourceResolver<E, R>) => Effect.Effect<Content, E, R>;
|
|
53
53
|
declare const contentPartText: (part: ContentPart) => string;
|
|
54
54
|
declare const contentPartPreview: (part: ContentPart) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Replace lone UTF-16 surrogates with U+FFFD. Models emit them in transcripts
|
|
57
|
+
* and tool arguments; they are valid JS strings but unencodable as UTF-8, so
|
|
58
|
+
* provider APIs and storage backends can reject payloads containing them.
|
|
59
|
+
*/
|
|
60
|
+
declare const replaceLoneSurrogates: (text: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Deep-apply `replaceLoneSurrogates` to every string (keys included) in a
|
|
63
|
+
* JSON-shaped value. Providers harden lowered request bodies with this before
|
|
64
|
+
* serialization so junk in replayed transcripts cannot poison model calls;
|
|
65
|
+
* hosts may also use it when persisting model-produced JSON.
|
|
66
|
+
*/
|
|
67
|
+
declare const replaceLoneSurrogatesDeep: (value: unknown) => unknown;
|
|
55
68
|
declare const contentText: (content: Content) => string;
|
|
56
69
|
declare const contentPreview: (content: Content) => string;
|
|
57
70
|
declare const contentParts: (content: Content) => ReadonlyArray<ContentPart>;
|
|
@@ -80,5 +93,5 @@ declare const documentPartFromText: (input: {
|
|
|
80
93
|
declare const attachmentSourceText: (source: AttachmentSource) => Effect.Effect<Option.Option<string>, unknown, never>;
|
|
81
94
|
declare const attachmentSourceBase64: (source: AttachmentSource) => Option.Option<string>;
|
|
82
95
|
//#endregion
|
|
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 };
|
|
96
|
+
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, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
84
97
|
//# 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;;;;;;cAEQ,SAAA,SAAkB,cAK7B;AAAA,cAEW,WAAA,EAAW,MAAA,CAAA,KAAA,kBAAA,QAAA,SAAA,SAAA,SAAA,YAAA,SAAA,SAAA;AAAA,KACZ,WAAA,UAAqB,WAAA,CAAY,IAAI;AAAA,cAE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K;AAAA,cAEjD,uBAAA,GAA2B,MAAwB,EAAhB,gBAAgB;AAAA,cAWnD,uBAAA,GAA2B,MAAA,EAAQ,gBAAA,EAAkB,QAAA,aAAgB,MAAA,CAAA,MAAA;AAAA,cAUrE,mBAAA,GAAuB,MAAA,EAAQ,gBAAA,EAAkB,QAAA,aAAgB,MAAA,CAAA,MAAA;AAAA,cAyCjE,sBAAA,GAA0B,QAAgB;AAAA,cAyB1C,gCAAA,GAAoC,QAAgB;AAAA,cASpD,yBAAA,GAA6B,KAAA;EAAA,SAC/B,QAAA;EAAA,SACA,QAAA;AAAA;AAAA,cAUE,gBAAA,GAAoB,IAAY;AAAA,cAWhC,oBAAA,GAAwB,KAAA;EAAA,SAC1B,IAAA;EAAA,SACA,QAAA;EAAA,SACA,QAAA;EAAA,SACA,KAAA;AAAA,MACV,YAAA;AAAA,cA4BY,oBAAA,GAAwB,MAAA,EAAQ,gBAAA,KAAgB,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA;AAAA,cAahD,sBAAA,GAA0B,MAAA,EAAQ,gBAAA,KAAgB,MAAA,CAAA,MAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Effect, Option } from "effect";
|
|
1
|
+
import { Array as Array$1, 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 }) {};
|
|
@@ -79,15 +79,34 @@ const contentPartPreview = (part) => {
|
|
|
79
79
|
case "Audio": return "Audio";
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
82
|
+
const loneSurrogates = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
83
|
+
/**
|
|
84
|
+
* Replace lone UTF-16 surrogates with U+FFFD. Models emit them in transcripts
|
|
85
|
+
* and tool arguments; they are valid JS strings but unencodable as UTF-8, so
|
|
86
|
+
* provider APIs and storage backends can reject payloads containing them.
|
|
87
|
+
*/
|
|
88
|
+
const replaceLoneSurrogates = (text) => text.replace(loneSurrogates, "�");
|
|
89
|
+
/**
|
|
90
|
+
* Deep-apply `replaceLoneSurrogates` to every string (keys included) in a
|
|
91
|
+
* JSON-shaped value. Providers harden lowered request bodies with this before
|
|
92
|
+
* serialization so junk in replayed transcripts cannot poison model calls;
|
|
93
|
+
* hosts may also use it when persisting model-produced JSON.
|
|
94
|
+
*/
|
|
95
|
+
const replaceLoneSurrogatesDeep = (value) => {
|
|
96
|
+
if (typeof value === "string") return replaceLoneSurrogates(value);
|
|
97
|
+
if (Array.isArray(value)) return value.map(replaceLoneSurrogatesDeep);
|
|
98
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [replaceLoneSurrogates(key), replaceLoneSurrogatesDeep(entry)]));
|
|
99
|
+
return value;
|
|
100
|
+
};
|
|
101
|
+
const contentText = (content) => typeof content === "string" ? content : Array$1.map(content, contentPartText).join("");
|
|
102
|
+
const contentPreview = (content) => typeof content === "string" ? content : Array$1.map(content, contentPartPreview).join(", ");
|
|
84
103
|
const contentParts = (content) => typeof content === "string" ? [TextPart.make({ text: content })] : content;
|
|
85
|
-
const isContentEmpty = (content) => typeof content === "string" ? content.length === 0 : content.length === 0 || Array.every(content, (part) => part._tag === "Text" && part.text.length === 0);
|
|
104
|
+
const isContentEmpty = (content) => typeof content === "string" ? content.length === 0 : content.length === 0 || Array$1.every(content, (part) => part._tag === "Text" && part.text.length === 0);
|
|
86
105
|
const appendTextToContent = (content, text) => {
|
|
87
106
|
if (typeof content === "string") return `${content}${text}`;
|
|
88
|
-
return Option.match(Array.last(content), {
|
|
107
|
+
return Option.match(Array$1.last(content), {
|
|
89
108
|
onNone: () => [TextPart.make({ text })],
|
|
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)
|
|
109
|
+
onSome: (last) => last._tag !== "Text" ? [...content, TextPart.make({ text })] : Array$1.map(content, (part, index) => index === content.length - 1 && part._tag === "Text" ? TextPart.make({ text: `${part.text}${text}` }) : part)
|
|
91
110
|
});
|
|
92
111
|
};
|
|
93
112
|
const inlineBase64AttachmentSource = (data) => InlineBase64AttachmentSource.make({ data });
|
|
@@ -198,6 +217,6 @@ const attachmentSourceBase64 = (source) => {
|
|
|
198
217
|
}
|
|
199
218
|
};
|
|
200
219
|
//#endregion
|
|
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 };
|
|
220
|
+
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, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource };
|
|
202
221
|
|
|
203
222
|
//# 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) =>\n 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) =>\n 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 ||\n mimeType === 'application/octet-stream' ||\n 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 =\n 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,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,QAAQ,OAAO,SAA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AEA,MAAM,oBAAoB,SAAiB;CACzC,MAAM,SAAS,WAAW,KAAK,IAAI;CACnC,MAAM,QAAQ,WAAW,KAAK,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\nconst loneSurrogates = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g\n\n/**\n * Replace lone UTF-16 surrogates with U+FFFD. Models emit them in transcripts\n * and tool arguments; they are valid JS strings but unencodable as UTF-8, so\n * provider APIs and storage backends can reject payloads containing them.\n */\nexport const replaceLoneSurrogates = (text: string) => text.replace(loneSurrogates, '\\uFFFD')\n\n/**\n * Deep-apply `replaceLoneSurrogates` to every string (keys included) in a\n * JSON-shaped value. Providers harden lowered request bodies with this before\n * serialization so junk in replayed transcripts cannot poison model calls;\n * hosts may also use it when persisting model-produced JSON.\n */\nexport const replaceLoneSurrogatesDeep = (value: unknown): unknown => {\n if (typeof value === 'string') return replaceLoneSurrogates(value)\n if (Array.isArray(value)) return value.map(replaceLoneSurrogatesDeep)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [\n replaceLoneSurrogates(key),\n replaceLoneSurrogatesDeep(entry)\n ])\n )\n }\n\n return value\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) =>\n 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) =>\n 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 ||\n mimeType === 'application/octet-stream' ||\n 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 =\n 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,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,OAAO,OAAO,SAAS,O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aAAa,IAAI;CAGpC,OAAO,WAAW,KAAK,MAAM;AAC/B;AAEA,MAAa,wBAAwB,UAK/B;CACJ,MAAM,aAAa,kBAAkB,MAAM,QAAQ;CACnD,MAAM,WACJ,0BAA0B;EACxB,UAAU,MAAM;EAChB,UAAU,MAAM;CAClB,CAAC,MAAM,0BAA0B,UAAU,IAAI,eAAe,KAAA;CAEhE,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAEnC,MAAM,OAAO;EACX,QAAQ,6BAA6B,iBAAiB,MAAM,IAAI,CAAC;EACjE;EACA,UAAU,MAAM;CAClB;CAEA,OAAO,MAAM,UAAU,KAAA,IACnB,aAAa,KAAK,IAAI,IACtB,aAAa,KAAK;EAAE,GAAG;EAAM,OAAO,MAAM;CAAM,CAAC;AACvD;AAEA,MAAM,oBAAoB,SAAiB;CACzC,MAAM,SAAS,WAAW,KAAK,IAAI;CACnC,MAAM,QAAQ,WAAW,KAAK,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,5 +1,5 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.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";
|
|
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, replaceLoneSurrogates, replaceLoneSurrogatesDeep, 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, type TerminalAgentEvent, 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, isTerminalAgentEvent, 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, type TerminalAgentEvent, 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, isTerminalAgentEvent, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, 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":";;;;;;;;;;KAsKY,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, attachmentSourceUrl, 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, replaceLoneSurrogates, replaceLoneSurrogatesDeep, 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, isTerminalAgentEvent, 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, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTerminalAgentEvent, 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, isTerminalAgentEvent, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
@@ -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":[],"sources":["../../../src/providers/anthropic/claude-provider.ts"],"mappings":";;;;;;KAoDY,6BAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,WAAA;EAAA,SACA,SAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA;AAAA;AAAA,KAG9B,kBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AA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,CAAO,oBAAA,EAAsB,QAAA;AAAA,cAoiB1B,6BAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cA2Fd,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, attachmentSourceText, isTextDocumentMimeType, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
|
|
4
|
+
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceText, isTextDocumentMimeType, messageContextText, prependMessageContextToContent, replaceLoneSurrogatesDeep } 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";
|
|
@@ -797,10 +797,10 @@ const streamAnthropicClaudeResponse = (response) => Stream.unwrap(Ref.make(initi
|
|
|
797
797
|
return chunks.pipe(Stream.concat(finalEvents));
|
|
798
798
|
})));
|
|
799
799
|
const sendAnthropicClaudeRequest = (config, request, client, sessionId) => Effect.gen(function* () {
|
|
800
|
-
const serializedBody = yield* encodeJsonString(yield* toAnthropicClaudeRequestBody(request, {
|
|
800
|
+
const serializedBody = yield* encodeJsonString(replaceLoneSurrogatesDeep(yield* toAnthropicClaudeRequestBody(request, {
|
|
801
801
|
...config,
|
|
802
802
|
stream: true
|
|
803
|
-
}), "Could not serialize Anthropic Claude request");
|
|
803
|
+
})), "Could not serialize Anthropic Claude request");
|
|
804
804
|
const httpRequest = HttpClientRequest.post(config.messagesUrl ?? anthropicClaudeMessagesUrl).pipe(HttpClientRequest.setHeaders({
|
|
805
805
|
accept: "text/event-stream",
|
|
806
806
|
...anthropicClaudeAuthorizationHeaders(config.token),
|