@effect-uai/core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{AiError-CqmYjXyx.d.mts → AiError-CBuPHVKA.d.mts} +1 -1
- package/dist/{AiError-CqmYjXyx.d.mts.map → AiError-CBuPHVKA.d.mts.map} +1 -1
- package/dist/Image-BZmKfIdq.d.mts +61 -0
- package/dist/Image-BZmKfIdq.d.mts.map +1 -0
- package/dist/{Items-D1C2686t.d.mts → Items-CB8Bo3FI.d.mts} +132 -80
- package/dist/Items-CB8Bo3FI.d.mts.map +1 -0
- package/dist/Media-D_CpcM1Z.d.mts +57 -0
- package/dist/Media-D_CpcM1Z.d.mts.map +1 -0
- package/dist/{StructuredFormat-B5ueioNr.d.mts → StructuredFormat-BWq5Hd1O.d.mts} +5 -5
- package/dist/StructuredFormat-BWq5Hd1O.d.mts.map +1 -0
- package/dist/{Tool-5wxOCuOh.d.mts → Tool-DjVufH7i.d.mts} +13 -13
- package/dist/Tool-DjVufH7i.d.mts.map +1 -0
- package/dist/{Turn-rlTfuHaQ.d.mts → Turn-OPaILVIB.d.mts} +12 -29
- package/dist/Turn-OPaILVIB.d.mts.map +1 -0
- package/dist/{chunk-CfYAbeIz.mjs → chunk-uyGKjUfl.mjs} +2 -1
- package/dist/dist-DV5ISja1.mjs +13782 -0
- package/dist/dist-DV5ISja1.mjs.map +1 -0
- package/dist/domain/AiError.d.mts +1 -1
- package/dist/domain/AiError.mjs +1 -1
- package/dist/domain/Image.d.mts +2 -0
- package/dist/domain/Image.mjs +58 -0
- package/dist/domain/Image.mjs.map +1 -0
- package/dist/domain/Items.d.mts +2 -2
- package/dist/domain/Items.mjs +19 -42
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Media.d.mts +2 -0
- package/dist/domain/Media.mjs +14 -0
- package/dist/domain/Media.mjs.map +1 -0
- package/dist/domain/Turn.d.mts +2 -2
- package/dist/domain/Turn.mjs +12 -8
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/embedding-model/Embedding.d.mts +107 -0
- package/dist/embedding-model/Embedding.d.mts.map +1 -0
- package/dist/embedding-model/Embedding.mjs +18 -0
- package/dist/embedding-model/Embedding.mjs.map +1 -0
- package/dist/embedding-model/EmbeddingModel.d.mts +97 -0
- package/dist/embedding-model/EmbeddingModel.d.mts.map +1 -0
- package/dist/embedding-model/EmbeddingModel.mjs +17 -0
- package/dist/embedding-model/EmbeddingModel.mjs.map +1 -0
- package/dist/index.d.mts +16 -8
- package/dist/index.mjs +10 -2
- package/dist/language-model/LanguageModel.d.mts +12 -20
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs +3 -20
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/loop/Loop.d.mts +111 -2
- package/dist/loop/Loop.d.mts.map +1 -0
- package/dist/loop/Loop.mjs +39 -6
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.d.mts +1 -0
- package/dist/loop/Loop.test.mjs +411 -0
- package/dist/loop/Loop.test.mjs.map +1 -0
- package/dist/magic-string.es-BgIV5Mu3.mjs +1013 -0
- package/dist/magic-string.es-BgIV5Mu3.mjs.map +1 -0
- package/dist/math/Vector.d.mts +47 -0
- package/dist/math/Vector.d.mts.map +1 -0
- package/dist/math/Vector.mjs +117 -0
- package/dist/math/Vector.mjs.map +1 -0
- package/dist/observability/Metrics.d.mts +2 -2
- package/dist/observability/Metrics.d.mts.map +1 -1
- package/dist/observability/Metrics.mjs +1 -1
- package/dist/observability/Metrics.mjs.map +1 -1
- package/dist/streaming/JSONL.mjs +1 -1
- package/dist/streaming/JSONL.test.d.mts +1 -0
- package/dist/streaming/JSONL.test.mjs +70 -0
- package/dist/streaming/JSONL.test.mjs.map +1 -0
- package/dist/streaming/Lines.mjs +1 -1
- package/dist/streaming/SSE.d.mts +2 -2
- package/dist/streaming/SSE.d.mts.map +1 -1
- package/dist/streaming/SSE.mjs +1 -1
- package/dist/streaming/SSE.mjs.map +1 -1
- package/dist/streaming/SSE.test.d.mts +1 -0
- package/dist/streaming/SSE.test.mjs +72 -0
- package/dist/streaming/SSE.test.mjs.map +1 -0
- package/dist/structured-format/StructuredFormat.d.mts +1 -1
- package/dist/structured-format/StructuredFormat.mjs +1 -1
- package/dist/structured-format/StructuredFormat.mjs.map +1 -1
- package/dist/testing/MockProvider.d.mts +6 -6
- package/dist/testing/MockProvider.d.mts.map +1 -1
- package/dist/testing/MockProvider.mjs.map +1 -1
- package/dist/tool/HistoryCheck.d.mts +6 -3
- package/dist/tool/HistoryCheck.d.mts.map +1 -1
- package/dist/tool/HistoryCheck.mjs +7 -1
- package/dist/tool/HistoryCheck.mjs.map +1 -1
- package/dist/tool/Outcome.d.mts +138 -2
- package/dist/tool/Outcome.d.mts.map +1 -0
- package/dist/tool/Outcome.mjs +34 -18
- package/dist/tool/Outcome.mjs.map +1 -1
- package/dist/tool/Resolvers.d.mts +30 -25
- package/dist/tool/Resolvers.d.mts.map +1 -1
- package/dist/tool/Resolvers.mjs +54 -44
- package/dist/tool/Resolvers.mjs.map +1 -1
- package/dist/tool/Resolvers.test.d.mts +1 -0
- package/dist/tool/Resolvers.test.mjs +317 -0
- package/dist/tool/Resolvers.test.mjs.map +1 -0
- package/dist/tool/Tool.d.mts +1 -1
- package/dist/tool/Tool.mjs +1 -1
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +151 -2
- package/dist/tool/ToolEvent.d.mts.map +1 -0
- package/dist/tool/ToolEvent.mjs +30 -4
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/Toolkit.d.mts +24 -15
- package/dist/tool/Toolkit.d.mts.map +1 -1
- package/dist/tool/Toolkit.mjs +14 -13
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.d.mts +1 -0
- package/dist/tool/Toolkit.test.mjs +113 -0
- package/dist/tool/Toolkit.test.mjs.map +1 -0
- package/package.json +29 -13
- package/src/domain/Image.ts +75 -0
- package/src/domain/Items.ts +18 -47
- package/src/domain/Media.ts +61 -0
- package/src/domain/Turn.ts +7 -17
- package/src/embedding-model/Embedding.ts +117 -0
- package/src/embedding-model/EmbeddingModel.ts +107 -0
- package/src/index.ts +9 -1
- package/src/language-model/LanguageModel.ts +2 -22
- package/src/loop/Loop.test.ts +114 -2
- package/src/loop/Loop.ts +69 -5
- package/src/math/Vector.ts +138 -0
- package/src/observability/Metrics.ts +1 -1
- package/src/streaming/SSE.ts +1 -1
- package/src/structured-format/StructuredFormat.ts +2 -2
- package/src/testing/MockProvider.ts +2 -2
- package/src/tool/HistoryCheck.ts +2 -5
- package/src/tool/Outcome.ts +39 -53
- package/src/tool/Resolvers.test.ts +46 -117
- package/src/tool/Resolvers.ts +74 -102
- package/src/tool/Tool.ts +9 -9
- package/src/tool/ToolEvent.ts +30 -26
- package/src/tool/Toolkit.test.ts +97 -2
- package/src/tool/Toolkit.ts +65 -67
- package/dist/Items-D1C2686t.d.mts.map +0 -1
- package/dist/Loop-CzSJo1h8.d.mts +0 -87
- package/dist/Loop-CzSJo1h8.d.mts.map +0 -1
- package/dist/Outcome-C2JYknCu.d.mts +0 -40
- package/dist/Outcome-C2JYknCu.d.mts.map +0 -1
- package/dist/StructuredFormat-B5ueioNr.d.mts.map +0 -1
- package/dist/Tool-5wxOCuOh.d.mts.map +0 -1
- package/dist/ToolEvent-B2N10hr3.d.mts +0 -29
- package/dist/ToolEvent-B2N10hr3.d.mts.map +0 -1
- package/dist/Turn-rlTfuHaQ.d.mts.map +0 -1
- package/dist/match/Match.d.mts +0 -16
- package/dist/match/Match.d.mts.map +0 -1
- package/dist/match/Match.mjs +0 -15
- package/dist/match/Match.mjs.map +0 -1
- package/src/match/Match.ts +0 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as Cancelled, c as GenerationFailed, d as RateLimited, f as Scope, i as AuthSubtype, l as IncompleteTurn, m as Unavailable, o as ContentFiltered, p as Timeout, r as AuthFailed, s as ContextLengthExceeded, t as AiError, u as InvalidRequest } from "../AiError-
|
|
1
|
+
import { a as Cancelled, c as GenerationFailed, d as RateLimited, f as Scope, i as AuthSubtype, l as IncompleteTurn, m as Unavailable, o as ContentFiltered, p as Timeout, r as AuthFailed, s as ContextLengthExceeded, t as AiError, u as InvalidRequest } from "../AiError-CBuPHVKA.mjs";
|
|
2
2
|
export { AiError, AuthFailed, AuthSubtype, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, Scope, Timeout, Unavailable };
|
package/dist/domain/AiError.mjs
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ImageUrlSource, c as imageBytes, d as isImageBytes, f as isImageUrl, i as ImageSource, l as imageUrl, n as ImageBytesSource, r as ImageMimeType, s as imageBase64, t as ImageBase64Source, u as isImageBase64 } from "../Image-BZmKfIdq.mjs";
|
|
2
|
+
export { ImageBase64Source, ImageBytesSource, ImageMimeType, ImageSource, ImageUrlSource, imageBase64, imageBytes, imageUrl, isImageBase64, isImageBytes, isImageUrl };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
//#region src/domain/Image.ts
|
|
4
|
+
var Image_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
ImageBase64Source: () => ImageBase64Source,
|
|
6
|
+
ImageBytesSource: () => ImageBytesSource,
|
|
7
|
+
ImageSource: () => ImageSource,
|
|
8
|
+
ImageUrlSource: () => ImageUrlSource,
|
|
9
|
+
imageBase64: () => imageBase64,
|
|
10
|
+
imageBytes: () => imageBytes,
|
|
11
|
+
imageUrl: () => imageUrl,
|
|
12
|
+
isImageBase64: () => isImageBase64,
|
|
13
|
+
isImageBytes: () => isImageBytes,
|
|
14
|
+
isImageUrl: () => isImageUrl
|
|
15
|
+
});
|
|
16
|
+
const ImageMimeTypeSchema = Schema.String;
|
|
17
|
+
const ImageUrlSource = Schema.TaggedStruct("url", {
|
|
18
|
+
url: Schema.String,
|
|
19
|
+
mimeType: Schema.optional(ImageMimeTypeSchema)
|
|
20
|
+
});
|
|
21
|
+
const ImageBase64Source = Schema.TaggedStruct("base64", {
|
|
22
|
+
base64: Schema.String,
|
|
23
|
+
mimeType: ImageMimeTypeSchema
|
|
24
|
+
});
|
|
25
|
+
const ImageBytesSource = Schema.TaggedStruct("bytes", {
|
|
26
|
+
bytes: Schema.Uint8Array,
|
|
27
|
+
mimeType: ImageMimeTypeSchema
|
|
28
|
+
});
|
|
29
|
+
const ImageSource = Schema.Union([
|
|
30
|
+
ImageUrlSource,
|
|
31
|
+
ImageBase64Source,
|
|
32
|
+
ImageBytesSource
|
|
33
|
+
]);
|
|
34
|
+
const imageUrl = (url, mimeType) => mimeType !== void 0 ? {
|
|
35
|
+
_tag: "url",
|
|
36
|
+
url,
|
|
37
|
+
mimeType
|
|
38
|
+
} : {
|
|
39
|
+
_tag: "url",
|
|
40
|
+
url
|
|
41
|
+
};
|
|
42
|
+
const imageBase64 = (base64, mimeType) => ({
|
|
43
|
+
_tag: "base64",
|
|
44
|
+
base64,
|
|
45
|
+
mimeType
|
|
46
|
+
});
|
|
47
|
+
const imageBytes = (bytes, mimeType) => ({
|
|
48
|
+
_tag: "bytes",
|
|
49
|
+
bytes,
|
|
50
|
+
mimeType
|
|
51
|
+
});
|
|
52
|
+
const isImageUrl = Schema.is(ImageUrlSource);
|
|
53
|
+
const isImageBase64 = Schema.is(ImageBase64Source);
|
|
54
|
+
const isImageBytes = Schema.is(ImageBytesSource);
|
|
55
|
+
//#endregion
|
|
56
|
+
export { ImageBase64Source, ImageBytesSource, ImageSource, ImageUrlSource, imageBase64, imageBytes, imageUrl, isImageBase64, isImageBytes, isImageUrl, Image_exports as t };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=Image.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.mjs","names":[],"sources":["../../src/domain/Image.ts"],"sourcesContent":["import { Schema } from \"effect\"\nimport type { MediaBase64, MediaBytes, MediaSource, MediaUrl } from \"./Media.js\"\n\n/**\n * Image MIME types AI providers typically accept. The first four are the\n * universal subset (Cohere v4, Voyage multimodal, Jina v4, Google\n * `gemini-embedding-2`); HEIC / HEIF are Google-specific. The\n * `(string & {})` tail keeps autocomplete on the literals while still\n * accepting any string, so a newly-supported format works without an\n * SDK update.\n */\nexport type ImageMimeType =\n | \"image/png\"\n | \"image/jpeg\"\n | \"image/webp\"\n | \"image/gif\"\n | \"image/heic\"\n | \"image/heif\"\n // eslint-disable-next-line @typescript-eslint/ban-types\n | (string & {})\n\nconst ImageMimeTypeSchema = Schema.String as unknown as Schema.Schema<ImageMimeType>\n\nexport type ImageUrlSource = MediaUrl<ImageMimeType>\nexport type ImageBase64Source = MediaBase64<ImageMimeType>\nexport type ImageBytesSource = MediaBytes<ImageMimeType>\n\n/**\n * Where an image lives. Provider layers normalize across these:\n * `bytes` becomes a base64 data URI for OpenAI / Anthropic, an\n * `inlineData` part for Gemini, and a separate field for Cohere /\n * Voyage. URL constraints (must be HTTPS, must be public, …) are\n * provider-specific and validated at the layer, not in the type.\n */\nexport type ImageSource = MediaSource<ImageMimeType>\n\nexport const ImageUrlSource = Schema.TaggedStruct(\"url\", {\n url: Schema.String,\n mimeType: Schema.optional(ImageMimeTypeSchema),\n})\n\nexport const ImageBase64Source = Schema.TaggedStruct(\"base64\", {\n base64: Schema.String,\n mimeType: ImageMimeTypeSchema,\n})\n\nexport const ImageBytesSource = Schema.TaggedStruct(\"bytes\", {\n bytes: Schema.Uint8Array,\n mimeType: ImageMimeTypeSchema,\n})\n\nexport const ImageSource: Schema.Schema<ImageSource> = Schema.Union([\n ImageUrlSource,\n ImageBase64Source,\n ImageBytesSource,\n]) as unknown as Schema.Schema<ImageSource>\n\nexport const imageUrl = (url: string, mimeType?: ImageMimeType): ImageUrlSource =>\n mimeType !== undefined ? { _tag: \"url\", url, mimeType } : { _tag: \"url\", url }\n\nexport const imageBase64 = (base64: string, mimeType: ImageMimeType): ImageBase64Source => ({\n _tag: \"base64\",\n base64,\n mimeType,\n})\n\nexport const imageBytes = (bytes: Uint8Array, mimeType: ImageMimeType): ImageBytesSource => ({\n _tag: \"bytes\",\n bytes,\n mimeType,\n})\n\nexport const isImageUrl = Schema.is(ImageUrlSource)\nexport const isImageBase64 = Schema.is(ImageBase64Source)\nexport const isImageBytes = Schema.is(ImageBytesSource)\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,sBAAsB,OAAO;AAenC,MAAa,iBAAiB,OAAO,aAAa,OAAO;CACvD,KAAK,OAAO;CACZ,UAAU,OAAO,SAAS,oBAAoB;CAC/C,CAAC;AAEF,MAAa,oBAAoB,OAAO,aAAa,UAAU;CAC7D,QAAQ,OAAO;CACf,UAAU;CACX,CAAC;AAEF,MAAa,mBAAmB,OAAO,aAAa,SAAS;CAC3D,OAAO,OAAO;CACd,UAAU;CACX,CAAC;AAEF,MAAa,cAA0C,OAAO,MAAM;CAClE;CACA;CACA;CACD,CAAC;AAEF,MAAa,YAAY,KAAa,aACpC,aAAa,KAAA,IAAY;CAAE,MAAM;CAAO;CAAK;CAAU,GAAG;CAAE,MAAM;CAAO;CAAK;AAEhF,MAAa,eAAe,QAAgB,cAAgD;CAC1F,MAAM;CACN;CACA;CACD;AAED,MAAa,cAAc,OAAmB,cAA+C;CAC3F,MAAM;CACN;CACA;CACD;AAED,MAAa,aAAa,OAAO,GAAG,eAAe;AACnD,MAAa,gBAAgB,OAAO,GAAG,kBAAkB;AACzD,MAAa,eAAe,OAAO,GAAG,iBAAiB"}
|
package/dist/domain/Items.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { Annotation, ContainerFileCitation, ContentBlock, FileCitation, FilePath, FunctionCall, FunctionCallOutput,
|
|
1
|
+
import { A as isInputText, C as functionCallOutput, D as isFunctionCall, E as isFilePath, F as isUrlCitation, I as systemText, L as userText, M as isOutputText, N as isReasoning, O as isFunctionCallOutput, P as isRefusal, S as assistantText, T as isFileCitation, _ as Refusal, a as FilePath, b as UrlCitation, c as InputImage, d as Item, g as Reasoning, h as OutputTokensDetails, i as FileCitation, j as isMessage, k as isInputImage, l as InputText, m as OutputText, n as ContainerFileCitation, o as FunctionCall, p as Message, r as ContentBlock, s as FunctionCallOutput, t as Annotation, u as InputTokensDetails, v as Role, w as isContainerFileCitation, x as Usage, y as StopReason } from "../Items-CB8Bo3FI.mjs";
|
|
2
|
+
export { Annotation, ContainerFileCitation, ContentBlock, FileCitation, FilePath, FunctionCall, FunctionCallOutput, InputImage, InputText, InputTokensDetails, Item, Message, OutputText, OutputTokensDetails, Reasoning, Refusal, Role, StopReason, UrlCitation, Usage, assistantText, functionCallOutput, isContainerFileCitation, isFileCitation, isFilePath, isFunctionCall, isFunctionCallOutput, isInputImage, isInputText, isMessage, isOutputText, isReasoning, isRefusal, isUrlCitation, systemText, userText };
|
package/dist/domain/Items.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
import { ImageSource } from "./Image.mjs";
|
|
2
3
|
import { Schema } from "effect";
|
|
3
4
|
//#region src/domain/Items.ts
|
|
4
5
|
var Items_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -9,9 +10,6 @@ var Items_exports = /* @__PURE__ */ __exportAll({
|
|
|
9
10
|
FilePath: () => FilePath,
|
|
10
11
|
FunctionCall: () => FunctionCall,
|
|
11
12
|
FunctionCallOutput: () => FunctionCallOutput,
|
|
12
|
-
ImageBase64Source: () => ImageBase64Source,
|
|
13
|
-
ImageSource: () => ImageSource,
|
|
14
|
-
ImageUrlSource: () => ImageUrlSource,
|
|
15
13
|
InputImage: () => InputImage,
|
|
16
14
|
InputText: () => InputText,
|
|
17
15
|
InputTokensDetails: () => InputTokensDetails,
|
|
@@ -32,8 +30,6 @@ var Items_exports = /* @__PURE__ */ __exportAll({
|
|
|
32
30
|
isFilePath: () => isFilePath,
|
|
33
31
|
isFunctionCall: () => isFunctionCall,
|
|
34
32
|
isFunctionCallOutput: () => isFunctionCallOutput,
|
|
35
|
-
isImageBase64Source: () => isImageBase64Source,
|
|
36
|
-
isImageUrlSource: () => isImageUrlSource,
|
|
37
33
|
isInputImage: () => isInputImage,
|
|
38
34
|
isInputText: () => isInputText,
|
|
39
35
|
isMessage: () => isMessage,
|
|
@@ -49,31 +45,12 @@ const InputText = Schema.Struct({
|
|
|
49
45
|
text: Schema.String
|
|
50
46
|
});
|
|
51
47
|
/**
|
|
52
|
-
* Where an image lives. `url` covers HTTP(S) URLs (the model fetches
|
|
53
|
-
* them); `base64` covers inline bytes embedded in the request. Provider
|
|
54
|
-
* encoders dispatch on `_tag`. File-id / uploaded-asset references are
|
|
55
|
-
* provider-specific and stay out of this union for now.
|
|
56
|
-
*/
|
|
57
|
-
const ImageUrlSource = Schema.Struct({
|
|
58
|
-
_tag: Schema.Literal("url"),
|
|
59
|
-
url: Schema.String
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* Inline image bytes. `data` is **already base64-encoded** (matches what
|
|
63
|
-
* the wire formats expect; no double-encoding needed downstream).
|
|
64
|
-
* `media_type` is the MIME type, e.g. `"image/png"`.
|
|
65
|
-
*/
|
|
66
|
-
const ImageBase64Source = Schema.Struct({
|
|
67
|
-
_tag: Schema.Literal("base64"),
|
|
68
|
-
media_type: Schema.String,
|
|
69
|
-
data: Schema.String
|
|
70
|
-
});
|
|
71
|
-
const ImageSource = Schema.Union([ImageUrlSource, ImageBase64Source]);
|
|
72
|
-
const isImageUrlSource = (s) => s._tag === "url";
|
|
73
|
-
const isImageBase64Source = (s) => s._tag === "base64";
|
|
74
|
-
/**
|
|
75
48
|
* User-provided image content block. Pair with `InputText` inside a
|
|
76
49
|
* `Message.content` array to ask "what's in this image?" style questions.
|
|
50
|
+
*
|
|
51
|
+
* `source` is the cross-modality `ImageSource` from `domain/Image.ts` -
|
|
52
|
+
* url, base64, or raw bytes. Provider codecs encode bytes to whatever
|
|
53
|
+
* wire format the provider wants.
|
|
77
54
|
*/
|
|
78
55
|
const InputImage = Schema.Struct({
|
|
79
56
|
type: Schema.Literal("input_image"),
|
|
@@ -109,10 +86,10 @@ const Annotation = Schema.Union([
|
|
|
109
86
|
ContainerFileCitation,
|
|
110
87
|
FilePath
|
|
111
88
|
]);
|
|
112
|
-
const isUrlCitation = (
|
|
113
|
-
const isFileCitation = (
|
|
114
|
-
const isContainerFileCitation = (
|
|
115
|
-
const isFilePath = (
|
|
89
|
+
const isUrlCitation = Schema.is(UrlCitation);
|
|
90
|
+
const isFileCitation = Schema.is(FileCitation);
|
|
91
|
+
const isContainerFileCitation = Schema.is(ContainerFileCitation);
|
|
92
|
+
const isFilePath = Schema.is(FilePath);
|
|
116
93
|
const OutputText = Schema.Struct({
|
|
117
94
|
type: Schema.Literal("output_text"),
|
|
118
95
|
text: Schema.String,
|
|
@@ -178,14 +155,14 @@ const Item = Schema.Union([
|
|
|
178
155
|
FunctionCallOutput,
|
|
179
156
|
Reasoning
|
|
180
157
|
]);
|
|
181
|
-
const isInputText = (
|
|
182
|
-
const isInputImage = (
|
|
183
|
-
const isOutputText = (
|
|
184
|
-
const isRefusal = (
|
|
185
|
-
const isMessage = (
|
|
186
|
-
const isFunctionCall = (
|
|
187
|
-
const isFunctionCallOutput = (
|
|
188
|
-
const isReasoning = (
|
|
158
|
+
const isInputText = Schema.is(InputText);
|
|
159
|
+
const isInputImage = Schema.is(InputImage);
|
|
160
|
+
const isOutputText = Schema.is(OutputText);
|
|
161
|
+
const isRefusal = Schema.is(Refusal);
|
|
162
|
+
const isMessage = Schema.is(Message);
|
|
163
|
+
const isFunctionCall = Schema.is(FunctionCall);
|
|
164
|
+
const isFunctionCallOutput = Schema.is(FunctionCallOutput);
|
|
165
|
+
const isReasoning = Schema.is(Reasoning);
|
|
189
166
|
const InputTokensDetails = Schema.Struct({ cached_tokens: Schema.optional(Schema.Number) });
|
|
190
167
|
const OutputTokensDetails = Schema.Struct({ reasoning_tokens: Schema.optional(Schema.Number) });
|
|
191
168
|
const Usage = Schema.Struct({
|
|
@@ -233,6 +210,6 @@ const functionCallOutput = (call_id, output) => ({
|
|
|
233
210
|
output
|
|
234
211
|
});
|
|
235
212
|
//#endregion
|
|
236
|
-
export { Annotation, ContainerFileCitation, ContentBlock, FileCitation, FilePath, FunctionCall, FunctionCallOutput,
|
|
213
|
+
export { Annotation, ContainerFileCitation, ContentBlock, FileCitation, FilePath, FunctionCall, FunctionCallOutput, InputImage, InputText, InputTokensDetails, Item, Message, OutputText, OutputTokensDetails, Reasoning, Refusal, Role, StopReason, UrlCitation, Usage, assistantText, functionCallOutput, isContainerFileCitation, isFileCitation, isFilePath, isFunctionCall, isFunctionCallOutput, isInputImage, isInputText, isMessage, isOutputText, isReasoning, isRefusal, isUrlCitation, systemText, Items_exports as t, userText };
|
|
237
214
|
|
|
238
215
|
//# sourceMappingURL=Items.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Items.mjs","names":[],"sources":["../../src/domain/Items.ts"],"sourcesContent":["import { Schema } from \"effect\"\n\n// ---------------------------------------------------------------------------\n// Content blocks (inside Message.content)\n// ---------------------------------------------------------------------------\n\nexport const InputText = Schema.Struct({\n type: Schema.Literal(\"input_text\"),\n text: Schema.String,\n})\nexport type InputText = typeof InputText.Type\n\n/**\n * Where an image lives. `url` covers HTTP(S) URLs (the model fetches\n * them); `base64` covers inline bytes embedded in the request. Provider\n * encoders dispatch on `_tag`. File-id / uploaded-asset references are\n * provider-specific and stay out of this union for now.\n */\nexport const ImageUrlSource = Schema.Struct({\n _tag: Schema.Literal(\"url\"),\n url: Schema.String,\n})\nexport type ImageUrlSource = typeof ImageUrlSource.Type\n\n/**\n * Inline image bytes. `data` is **already base64-encoded** (matches what\n * the wire formats expect; no double-encoding needed downstream).\n * `media_type` is the MIME type, e.g. `\"image/png\"`.\n */\nexport const ImageBase64Source = Schema.Struct({\n _tag: Schema.Literal(\"base64\"),\n media_type: Schema.String,\n data: Schema.String,\n})\nexport type ImageBase64Source = typeof ImageBase64Source.Type\n\nexport const ImageSource = Schema.Union([ImageUrlSource, ImageBase64Source])\nexport type ImageSource = typeof ImageSource.Type\n\nexport const isImageUrlSource = (s: ImageSource): s is ImageUrlSource => s._tag === \"url\"\nexport const isImageBase64Source = (s: ImageSource): s is ImageBase64Source => s._tag === \"base64\"\n\n/**\n * User-provided image content block. Pair with `InputText` inside a\n * `Message.content` array to ask \"what's in this image?\" style questions.\n */\nexport const InputImage = Schema.Struct({\n type: Schema.Literal(\"input_image\"),\n source: ImageSource,\n})\nexport type InputImage = typeof InputImage.Type\n\n// ---------------------------------------------------------------------------\n// Annotations - source / citation pointers attached to `output_text` blocks.\n// Mirrors OpenAI Responses API; other providers can omit or map onto these\n// shapes.\n// ---------------------------------------------------------------------------\n\nexport const UrlCitation = Schema.Struct({\n type: Schema.Literal(\"url_citation\"),\n url: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n title: Schema.String,\n})\nexport type UrlCitation = typeof UrlCitation.Type\n\nexport const FileCitation = Schema.Struct({\n type: Schema.Literal(\"file_citation\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\nexport type FileCitation = typeof FileCitation.Type\n\nexport const ContainerFileCitation = Schema.Struct({\n type: Schema.Literal(\"container_file_citation\"),\n container_id: Schema.String,\n file_id: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n})\nexport type ContainerFileCitation = typeof ContainerFileCitation.Type\n\nexport const FilePath = Schema.Struct({\n type: Schema.Literal(\"file_path\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\nexport type FilePath = typeof FilePath.Type\n\nexport const Annotation = Schema.Union([UrlCitation, FileCitation, ContainerFileCitation, FilePath])\nexport type Annotation = typeof Annotation.Type\n\nexport const isUrlCitation = (a: Annotation): a is UrlCitation => a.type === \"url_citation\"\nexport const isFileCitation = (a: Annotation): a is FileCitation => a.type === \"file_citation\"\nexport const isContainerFileCitation = (a: Annotation): a is ContainerFileCitation =>\n a.type === \"container_file_citation\"\nexport const isFilePath = (a: Annotation): a is FilePath => a.type === \"file_path\"\n\nexport const OutputText = Schema.Struct({\n type: Schema.Literal(\"output_text\"),\n text: Schema.String,\n annotations: Schema.optional(Schema.Array(Annotation)),\n})\nexport type OutputText = typeof OutputText.Type\n\n/**\n * Model-emitted refusal. Distinct from `output_text`: the model declined\n * to answer rather than producing normal output. Pair with\n * `stop_reason: \"refusal\"` on the surrounding `Turn`. Streamed via the\n * `refusal_delta` `TurnEvent`.\n */\nexport const Refusal = Schema.Struct({\n type: Schema.Literal(\"refusal\"),\n text: Schema.String,\n})\nexport type Refusal = typeof Refusal.Type\n\nexport const ContentBlock = Schema.Union([InputText, InputImage, OutputText, Refusal])\nexport type ContentBlock = typeof ContentBlock.Type\n\nexport const Role = Schema.Literals([\"user\", \"assistant\", \"system\"])\nexport type Role = typeof Role.Type\n\n// ---------------------------------------------------------------------------\n// Provider passthrough - every Item type carries this opaque slot.\n// The framework never reads or interprets it; provider modules decode\n// their own data via their own typed readers (see e.g.\n// the `@effect-uai/responses` package).\n// ---------------------------------------------------------------------------\n\nconst ProviderData = Schema.optional(Schema.Unknown)\n\n// ---------------------------------------------------------------------------\n// Items\n// ---------------------------------------------------------------------------\n\nexport const Message = Schema.Struct({\n type: Schema.Literal(\"message\"),\n role: Role,\n content: Schema.Array(ContentBlock),\n providerData: ProviderData,\n})\nexport type Message = typeof Message.Type\n\nexport const FunctionCall = Schema.Struct({\n type: Schema.Literal(\"function_call\"),\n call_id: Schema.String,\n name: Schema.String,\n // JSON-encoded arguments string, mirroring OpenAI Responses API\n arguments: Schema.String,\n providerData: ProviderData,\n})\nexport type FunctionCall = typeof FunctionCall.Type\n\nexport const FunctionCallOutput = Schema.Struct({\n type: Schema.Literal(\"function_call_output\"),\n call_id: Schema.String,\n output: Schema.String,\n providerData: ProviderData,\n})\nexport type FunctionCallOutput = typeof FunctionCallOutput.Type\n\n/**\n * Reasoning item - top-level, mirrors OpenAI Responses API. Common shape\n * across providers covers `summary` (human-readable text) and `signature`\n * (opaque round-trip blob - Anthropic's signed thinking, OpenAI's\n * encrypted_content, etc.). Provider-specific fields go in `providerData`.\n */\nexport const Reasoning = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.optional(Schema.String),\n summary: Schema.optional(Schema.String),\n signature: Schema.optional(Schema.String),\n providerData: ProviderData,\n})\nexport type Reasoning = typeof Reasoning.Type\n\nexport const Item = Schema.Union([Message, FunctionCall, FunctionCallOutput, Reasoning])\nexport type Item = typeof Item.Type\n\n// ---------------------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------------------\n\nexport const isInputText = (block: ContentBlock): block is InputText => block.type === \"input_text\"\nexport const isInputImage = (block: ContentBlock): block is InputImage =>\n block.type === \"input_image\"\nexport const isOutputText = (block: ContentBlock): block is OutputText =>\n block.type === \"output_text\"\nexport const isRefusal = (block: ContentBlock): block is Refusal => block.type === \"refusal\"\n\nexport const isMessage = (item: Item): item is Message => item.type === \"message\"\nexport const isFunctionCall = (item: Item): item is FunctionCall => item.type === \"function_call\"\nexport const isFunctionCallOutput = (item: Item): item is FunctionCallOutput =>\n item.type === \"function_call_output\"\nexport const isReasoning = (item: Item): item is Reasoning => item.type === \"reasoning\"\n\n// ---------------------------------------------------------------------------\n// Usage and stop reason\n// ---------------------------------------------------------------------------\n\nexport const InputTokensDetails = Schema.Struct({\n cached_tokens: Schema.optional(Schema.Number),\n})\nexport type InputTokensDetails = typeof InputTokensDetails.Type\n\nexport const OutputTokensDetails = Schema.Struct({\n reasoning_tokens: Schema.optional(Schema.Number),\n})\nexport type OutputTokensDetails = typeof OutputTokensDetails.Type\n\nexport const Usage = Schema.Struct({\n input_tokens: Schema.optional(Schema.Number),\n output_tokens: Schema.optional(Schema.Number),\n total_tokens: Schema.optional(Schema.Number),\n input_tokens_details: Schema.optional(InputTokensDetails),\n output_tokens_details: Schema.optional(OutputTokensDetails),\n})\nexport type Usage = typeof Usage.Type\n\nexport const StopReason = Schema.Literals([\n \"stop\",\n \"tool_calls\",\n \"max_tokens\",\n \"refusal\",\n /** Provider-side safety classifier flagged the output. */\n \"content_filter\",\n /** Server-enforced cap on tool calls per turn was hit. */\n \"max_tool_calls\",\n])\nexport type StopReason = typeof StopReason.Type\n\n// ---------------------------------------------------------------------------\n// Helper constructors\n// ---------------------------------------------------------------------------\n\nexport const userText = (text: string): Message => ({\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text }],\n})\n\nexport const systemText = (text: string): Message => ({\n type: \"message\",\n role: \"system\",\n content: [{ type: \"input_text\", text }],\n})\n\nexport const assistantText = (text: string): Message => ({\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"output_text\", text }],\n})\n\nexport const functionCallOutput = (call_id: string, output: string): FunctionCallOutput => ({\n type: \"function_call_output\",\n call_id,\n output,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,YAAY,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,aAAa;CAClC,MAAM,OAAO;CACd,CAAC;;;;;;;AASF,MAAa,iBAAiB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,MAAM;CAC3B,KAAK,OAAO;CACb,CAAC;;;;;;AAQF,MAAa,oBAAoB,OAAO,OAAO;CAC7C,MAAM,OAAO,QAAQ,SAAS;CAC9B,YAAY,OAAO;CACnB,MAAM,OAAO;CACd,CAAC;AAGF,MAAa,cAAc,OAAO,MAAM,CAAC,gBAAgB,kBAAkB,CAAC;AAG5E,MAAa,oBAAoB,MAAwC,EAAE,SAAS;AACpF,MAAa,uBAAuB,MAA2C,EAAE,SAAS;;;;;AAM1F,MAAa,aAAa,OAAO,OAAO;CACtC,MAAM,OAAO,QAA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;CAC5C,sBAAsB,OAAO,SAAS,mBAAmB;CACzD,uBAAuB,OAAO,SAAS,oBAAoB;CAC5D,CAAC;AAGF,MAAa,aAAa,OAAO,SAAS;CACxC;CACA;CACA;CACA;CAEA;CAEA;CACD,CAAC;AAOF,MAAa,YAAY,UAA2B;CAClD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAc;EAAM,CAAC;CACxC;AAED,MAAa,cAAc,UAA2B;CACpD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAc;EAAM,CAAC;CACxC;AAED,MAAa,iBAAiB,UAA2B;CACvD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAe;EAAM,CAAC;CACzC;AAED,MAAa,sBAAsB,SAAiB,YAAwC;CAC1F,MAAM;CACN;CACA;CACD"}
|
|
1
|
+
{"version":3,"file":"Items.mjs","names":[],"sources":["../../src/domain/Items.ts"],"sourcesContent":["import { Schema } from \"effect\"\nimport { ImageSource } from \"./Image.js\"\n\n// ---------------------------------------------------------------------------\n// Content blocks (inside Message.content)\n// ---------------------------------------------------------------------------\n\nexport const InputText = Schema.Struct({\n type: Schema.Literal(\"input_text\"),\n text: Schema.String,\n})\nexport type InputText = typeof InputText.Type\n\n/**\n * User-provided image content block. Pair with `InputText` inside a\n * `Message.content` array to ask \"what's in this image?\" style questions.\n *\n * `source` is the cross-modality `ImageSource` from `domain/Image.ts` -\n * url, base64, or raw bytes. Provider codecs encode bytes to whatever\n * wire format the provider wants.\n */\nexport const InputImage = Schema.Struct({\n type: Schema.Literal(\"input_image\"),\n source: ImageSource,\n})\nexport type InputImage = typeof InputImage.Type\n\n// ---------------------------------------------------------------------------\n// Annotations - source / citation pointers attached to `output_text` blocks.\n// Mirrors OpenAI Responses API; other providers can omit or map onto these\n// shapes.\n// ---------------------------------------------------------------------------\n\nexport const UrlCitation = Schema.Struct({\n type: Schema.Literal(\"url_citation\"),\n url: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n title: Schema.String,\n})\nexport type UrlCitation = typeof UrlCitation.Type\n\nexport const FileCitation = Schema.Struct({\n type: Schema.Literal(\"file_citation\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\nexport type FileCitation = typeof FileCitation.Type\n\nexport const ContainerFileCitation = Schema.Struct({\n type: Schema.Literal(\"container_file_citation\"),\n container_id: Schema.String,\n file_id: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n})\nexport type ContainerFileCitation = typeof ContainerFileCitation.Type\n\nexport const FilePath = Schema.Struct({\n type: Schema.Literal(\"file_path\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\nexport type FilePath = typeof FilePath.Type\n\nexport const Annotation = Schema.Union([UrlCitation, FileCitation, ContainerFileCitation, FilePath])\nexport type Annotation = typeof Annotation.Type\n\nexport const isUrlCitation = Schema.is(UrlCitation)\nexport const isFileCitation = Schema.is(FileCitation)\nexport const isContainerFileCitation = Schema.is(ContainerFileCitation)\nexport const isFilePath = Schema.is(FilePath)\n\nexport const OutputText = Schema.Struct({\n type: Schema.Literal(\"output_text\"),\n text: Schema.String,\n annotations: Schema.optional(Schema.Array(Annotation)),\n})\nexport type OutputText = typeof OutputText.Type\n\n/**\n * Model-emitted refusal. Distinct from `output_text`: the model declined\n * to answer rather than producing normal output. Pair with\n * `stop_reason: \"refusal\"` on the surrounding `Turn`. Streamed via the\n * `refusal_delta` `TurnEvent`.\n */\nexport const Refusal = Schema.Struct({\n type: Schema.Literal(\"refusal\"),\n text: Schema.String,\n})\nexport type Refusal = typeof Refusal.Type\n\nexport const ContentBlock = Schema.Union([InputText, InputImage, OutputText, Refusal])\nexport type ContentBlock = typeof ContentBlock.Type\n\nexport const Role = Schema.Literals([\"user\", \"assistant\", \"system\"])\nexport type Role = typeof Role.Type\n\n// ---------------------------------------------------------------------------\n// Provider passthrough - every Item type carries this opaque slot.\n// The framework never reads or interprets it; provider modules decode\n// their own data via their own typed readers (see e.g.\n// the `@effect-uai/responses` package).\n// ---------------------------------------------------------------------------\n\nconst ProviderData = Schema.optional(Schema.Unknown)\n\n// ---------------------------------------------------------------------------\n// Items\n// ---------------------------------------------------------------------------\n\nexport const Message = Schema.Struct({\n type: Schema.Literal(\"message\"),\n role: Role,\n content: Schema.Array(ContentBlock),\n providerData: ProviderData,\n})\nexport type Message = typeof Message.Type\n\nexport const FunctionCall = Schema.Struct({\n type: Schema.Literal(\"function_call\"),\n call_id: Schema.String,\n name: Schema.String,\n // JSON-encoded arguments string, mirroring OpenAI Responses API\n arguments: Schema.String,\n providerData: ProviderData,\n})\nexport type FunctionCall = typeof FunctionCall.Type\n\nexport const FunctionCallOutput = Schema.Struct({\n type: Schema.Literal(\"function_call_output\"),\n call_id: Schema.String,\n output: Schema.String,\n providerData: ProviderData,\n})\nexport type FunctionCallOutput = typeof FunctionCallOutput.Type\n\n/**\n * Reasoning item - top-level, mirrors OpenAI Responses API. Common shape\n * across providers covers `summary` (human-readable text) and `signature`\n * (opaque round-trip blob - Anthropic's signed thinking, OpenAI's\n * encrypted_content, etc.). Provider-specific fields go in `providerData`.\n */\nexport const Reasoning = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.optional(Schema.String),\n summary: Schema.optional(Schema.String),\n signature: Schema.optional(Schema.String),\n providerData: ProviderData,\n})\nexport type Reasoning = typeof Reasoning.Type\n\nexport const Item = Schema.Union([Message, FunctionCall, FunctionCallOutput, Reasoning])\nexport type Item = typeof Item.Type\n\n// ---------------------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------------------\n\nexport const isInputText = Schema.is(InputText)\nexport const isInputImage = Schema.is(InputImage)\nexport const isOutputText = Schema.is(OutputText)\nexport const isRefusal = Schema.is(Refusal)\n\nexport const isMessage = Schema.is(Message)\nexport const isFunctionCall = Schema.is(FunctionCall)\nexport const isFunctionCallOutput = Schema.is(FunctionCallOutput)\nexport const isReasoning = Schema.is(Reasoning)\n\n// ---------------------------------------------------------------------------\n// Usage and stop reason\n// ---------------------------------------------------------------------------\n\nexport const InputTokensDetails = Schema.Struct({\n cached_tokens: Schema.optional(Schema.Number),\n})\nexport type InputTokensDetails = typeof InputTokensDetails.Type\n\nexport const OutputTokensDetails = Schema.Struct({\n reasoning_tokens: Schema.optional(Schema.Number),\n})\nexport type OutputTokensDetails = typeof OutputTokensDetails.Type\n\nexport const Usage = Schema.Struct({\n input_tokens: Schema.optional(Schema.Number),\n output_tokens: Schema.optional(Schema.Number),\n total_tokens: Schema.optional(Schema.Number),\n input_tokens_details: Schema.optional(InputTokensDetails),\n output_tokens_details: Schema.optional(OutputTokensDetails),\n})\nexport type Usage = typeof Usage.Type\n\nexport const StopReason = Schema.Literals([\n \"stop\",\n \"tool_calls\",\n \"max_tokens\",\n \"refusal\",\n /** Provider-side safety classifier flagged the output. */\n \"content_filter\",\n /** Server-enforced cap on tool calls per turn was hit. */\n \"max_tool_calls\",\n])\nexport type StopReason = typeof StopReason.Type\n\n// ---------------------------------------------------------------------------\n// Helper constructors\n// ---------------------------------------------------------------------------\n\nexport const userText = (text: string): Message => ({\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text }],\n})\n\nexport const systemText = (text: string): Message => ({\n type: \"message\",\n role: \"system\",\n content: [{ type: \"input_text\", text }],\n})\n\nexport const assistantText = (text: string): Message => ({\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"output_text\", text }],\n})\n\nexport const functionCallOutput = (call_id: string, output: string): FunctionCallOutput => ({\n type: \"function_call_output\",\n call_id,\n output,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAa,YAAY,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,aAAa;CAClC,MAAM,OAAO;CACd,CAAC;;;;;;;;;AAWF,MAAa,aAAa,OAAO,OAAO;CACtC,MAAM,OAAO,QAAQ,cAAc;CACnC,QAAQ;CACT,CAAC;AASF,MAAa,cAAc,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ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a,aAAa,OAAO,SAAS;CACxC;CACA;CACA;CACA;CAEA;CAEA;CACD,CAAC;AAOF,MAAa,YAAY,UAA2B;CAClD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAc;EAAM,CAAC;CACxC;AAED,MAAa,cAAc,UAA2B;CACpD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAc;EAAM,CAAC;CACxC;AAED,MAAa,iBAAiB,UAA2B;CACvD,MAAM;CACN,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAe;EAAM,CAAC;CACzC;AAED,MAAa,sBAAsB,SAAiB,YAAwC;CAC1F,MAAM;CACN;CACA;CACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
//#region src/domain/Media.ts
|
|
3
|
+
var Media_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
isMediaBase64: () => isMediaBase64,
|
|
5
|
+
isMediaBytes: () => isMediaBytes,
|
|
6
|
+
isMediaUrl: () => isMediaUrl
|
|
7
|
+
});
|
|
8
|
+
const isMediaUrl = (s) => s._tag === "url";
|
|
9
|
+
const isMediaBase64 = (s) => s._tag === "base64";
|
|
10
|
+
const isMediaBytes = (s) => s._tag === "bytes";
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isMediaBase64, isMediaBytes, isMediaUrl, Media_exports as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=Media.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Media.mjs","names":[],"sources":["../../src/domain/Media.ts"],"sourcesContent":["/**\n * Cross-modality media reference shape.\n *\n * Every \"media at rest\" reference - image, audio, video, document - is one\n * of three variants:\n *\n * - `url` : a remote address (HTTP, GCS, etc.). The model fetches it.\n * `mimeType` is optional - servers usually set Content-Type.\n * Some providers (Gemini `fileData`) want it explicit.\n *\n * - `base64` : an inline base64-encoded payload. Always carries a\n * `mimeType` so the consumer knows how to decode.\n *\n * - `bytes` : raw `Uint8Array`. Provider layers normalize to base64 or\n * multipart upload at the wire boundary - users don't need\n * to encode themselves.\n *\n * Per-modality files (`Image.ts`, future `Audio.ts` / `Video.ts` /\n * `Document.ts`) instantiate this shape with their typed MIME union to\n * get autocomplete on common formats while keeping the structural type\n * uniform across modalities.\n *\n * Streaming media (live mic feed, streaming TTS playback) is *not*\n * modeled here. Streams carry effect parameters (`Stream<A, E, R>`) and\n * lifecycle (Scope, cancellation) that don't apply to media at rest. The\n * complementary type lives alongside this one as `*Stream` in each\n * per-modality file when those modalities land.\n *\n * Provider-uploaded asset references (OpenAI Files `file_id`, Gemini\n * Files API URIs, Anthropic file IDs) are also out of scope here -\n * they're a separate union (`FileRef`) added when needed.\n */\n\nexport type MediaUrl<M extends string = string> = {\n readonly _tag: \"url\"\n readonly url: string\n readonly mimeType?: M\n}\n\nexport type MediaBase64<M extends string = string> = {\n readonly _tag: \"base64\"\n readonly base64: string\n readonly mimeType: M\n}\n\nexport type MediaBytes<M extends string = string> = {\n readonly _tag: \"bytes\"\n readonly bytes: Uint8Array\n readonly mimeType: M\n}\n\nexport type MediaSource<M extends string = string> = MediaUrl<M> | MediaBase64<M> | MediaBytes<M>\n\nexport const isMediaUrl = <M extends string>(s: MediaSource<M>): s is MediaUrl<M> =>\n s._tag === \"url\"\n\nexport const isMediaBase64 = <M extends string>(s: MediaSource<M>): s is MediaBase64<M> =>\n s._tag === \"base64\"\n\nexport const isMediaBytes = <M extends string>(s: MediaSource<M>): s is MediaBytes<M> =>\n s._tag === \"bytes\"\n"],"mappings":";;;;;;;AAqDA,MAAa,cAAgC,MAC3C,EAAE,SAAS;AAEb,MAAa,iBAAmC,MAC9C,EAAE,SAAS;AAEb,MAAa,gBAAkC,MAC7C,EAAE,SAAS"}
|
package/dist/domain/Turn.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { c as functionCalls, d as textDeltas, f as toStructured, i as TurnEvent, l as isTurnComplete, n as RefusalRejected, o as appendTurn, r as Turn, s as assistantMessages, t as InteractionEvent, u as reasonings } from "../Turn-OPaILVIB.mjs";
|
|
2
|
+
export { InteractionEvent, RefusalRejected, Turn, TurnEvent, appendTurn, assistantMessages, functionCalls, isTurnComplete, reasonings, textDeltas, toStructured };
|
package/dist/domain/Turn.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
2
|
import { Item, StopReason, Usage, isOutputText, isRefusal } from "./Items.mjs";
|
|
3
3
|
import { parseJson } from "../structured-format/StructuredFormat.mjs";
|
|
4
4
|
import { Data, Effect, Result, Schema, Stream, pipe } from "effect";
|
|
@@ -6,8 +6,8 @@ import { Data, Effect, Result, Schema, Stream, pipe } from "effect";
|
|
|
6
6
|
var Turn_exports = /* @__PURE__ */ __exportAll({
|
|
7
7
|
RefusalRejected: () => RefusalRejected,
|
|
8
8
|
Turn: () => Turn,
|
|
9
|
+
appendTurn: () => appendTurn,
|
|
9
10
|
assistantMessages: () => assistantMessages,
|
|
10
|
-
cursor: () => cursor,
|
|
11
11
|
functionCalls: () => functionCalls,
|
|
12
12
|
isTurnComplete: () => isTurnComplete,
|
|
13
13
|
reasonings: () => reasonings,
|
|
@@ -29,13 +29,17 @@ const functionCalls = (turn) => turn.items.filter((i) => i.type === "function_ca
|
|
|
29
29
|
const reasonings = (turn) => turn.items.filter((i) => i.type === "reasoning");
|
|
30
30
|
const assistantMessages = (turn) => turn.items.filter((i) => i.type === "message" && i.role === "assistant");
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Append a completed turn and optional follow-up items to a state record's
|
|
33
|
+
* history. Recipes use this at the point where structured tool results are
|
|
34
|
+
* converted to model-facing `FunctionCallOutput`s.
|
|
34
35
|
*/
|
|
35
|
-
const
|
|
36
|
+
const appendTurn = (state, turn, items = []) => ({
|
|
36
37
|
...state,
|
|
37
|
-
history: [
|
|
38
|
-
|
|
38
|
+
history: [
|
|
39
|
+
...state.history,
|
|
40
|
+
...turn.items,
|
|
41
|
+
...items
|
|
42
|
+
]
|
|
39
43
|
});
|
|
40
44
|
/**
|
|
41
45
|
* Project a `TurnEvent` stream onto its `text_delta` payloads. Other
|
|
@@ -77,6 +81,6 @@ const lastAssistantContent = (turn) => {
|
|
|
77
81
|
*/
|
|
78
82
|
const toStructured = (turn, format) => pipe(lastAssistantContent(turn), ({ text, refused }) => refused ? Effect.fail(new RefusalRejected({ turn })) : parseJson(format)(text));
|
|
79
83
|
//#endregion
|
|
80
|
-
export { RefusalRejected, Turn,
|
|
84
|
+
export { RefusalRejected, Turn, appendTurn, assistantMessages, functionCalls, isTurnComplete, reasonings, Turn_exports as t, textDeltas, toStructured };
|
|
81
85
|
|
|
82
86
|
//# sourceMappingURL=Turn.mjs.map
|
package/dist/domain/Turn.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Turn.mjs","names":["StructuredFormat.parseJson"],"sources":["../../src/domain/Turn.ts"],"sourcesContent":["import { Data, Effect, Result, Schema, Stream, pipe } from \"effect\"\nimport * as StructuredFormat from \"../structured-format/StructuredFormat.js\"\nimport {\n FunctionCall,\n FunctionCallOutput,\n Item,\n isOutputText,\n isRefusal,\n Message,\n Reasoning,\n StopReason,\n Usage,\n} from \"./Items.js\"\n\n/**\n * The result of a single LLM generation. A turn produces zero or more items\n * (typically one assistant message and zero or more function_call items)\n * and reports usage + a stop reason.\n */\nexport const Turn = Schema.Struct({\n items: Schema.Array(Item),\n usage: Usage,\n stop_reason: StopReason,\n})\nexport type Turn = typeof Turn.Type\n\n/**\n * Canonical events emitted while a single turn is being generated. Most\n * variants are streaming deltas (text, reasoning, tool-call args); the\n * terminal `turn_complete` carries the assembled `Turn`. Lifecycle members\n * aren't deltas, hence the union name.\n */\nexport type TurnEvent =\n | { readonly type: \"text_delta\"; readonly text: string }\n | {\n readonly type: \"reasoning_delta\"\n readonly text: string\n /**\n * `trace` is the model's raw chain-of-thought; `summary` is a\n * model-written summary intended for display. OpenAI Responses emits\n * both as separate wire events; Anthropic and Gemini only emit\n * `trace`. Consumers who just want any reasoning text match once;\n * those who want only summaries filter `kind === \"summary\"`.\n */\n readonly kind: \"trace\" | \"summary\"\n }\n /**\n * The model declined to answer. `text` is the (streamed) explanation.\n * Distinct from the failure channel: a refusal is normal model output and\n * the stream still completes with `turn_complete`. OpenAI Responses emits\n * this; Anthropic surfaces refusals via `stop_reason`, and Gemini collapses\n * them into `finishReason: SAFETY` - both go without a `refusal_delta`.\n */\n | { readonly type: \"refusal_delta\"; readonly text: string }\n | { readonly type: \"tool_call_start\"; readonly call_id: string; readonly name: string }\n | { readonly type: \"tool_call_args_delta\"; readonly call_id: string; readonly delta: string }\n /**\n * Mid-stream cumulative usage. Carries the full `Usage` (including cache\n * token fields when the provider surfaces them) so consumers can drive\n * live budget / cost tracking without waiting for `turn_complete`.\n * Anthropic emits this on `message_start` and `message_delta`; other\n * providers may not emit any `usage_update` and only deliver usage via\n * `turn_complete.turn.usage`.\n */\n | { readonly type: \"usage_update\"; readonly usage: Usage }\n | { readonly type: \"turn_complete\"; readonly turn: Turn }\n\n/**\n * What flows out of an agent loop body to its consumer per turn: every\n * `TurnEvent` the provider emits (including the terminal `turn_complete`\n * carrying the assembled `Turn`), plus the output of any tool the loop ran.\n * Both variants carry a `type` discriminator.\n */\nexport type InteractionEvent = TurnEvent | FunctionCallOutput\n\nexport const isTurnComplete = (d: TurnEvent): d is Extract<TurnEvent, { type: \"turn_complete\" }> =>\n d.type === \"turn_complete\"\n\nexport const functionCalls = (turn: Turn): ReadonlyArray<FunctionCall> =>\n turn.items.filter((i): i is FunctionCall => i.type === \"function_call\")\n\nexport const reasonings = (turn: Turn): ReadonlyArray<Reasoning> =>\n turn.items.filter((i): i is Reasoning => i.type === \"reasoning\")\n\nexport const assistantMessages = (turn: Turn): ReadonlyArray<Message> =>\n turn.items.filter((i): i is Message => i.type === \"message\" && i.role === \"assistant\")\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"Turn.mjs","names":["StructuredFormat.parseJson"],"sources":["../../src/domain/Turn.ts"],"sourcesContent":["import { Data, Effect, Result, Schema, Stream, pipe } from \"effect\"\nimport * as StructuredFormat from \"../structured-format/StructuredFormat.js\"\nimport {\n FunctionCall,\n FunctionCallOutput,\n Item,\n isOutputText,\n isRefusal,\n Message,\n Reasoning,\n StopReason,\n Usage,\n} from \"./Items.js\"\n\n/**\n * The result of a single LLM generation. A turn produces zero or more items\n * (typically one assistant message and zero or more function_call items)\n * and reports usage + a stop reason.\n */\nexport const Turn = Schema.Struct({\n items: Schema.Array(Item),\n usage: Usage,\n stop_reason: StopReason,\n})\nexport type Turn = typeof Turn.Type\n\n/**\n * Canonical events emitted while a single turn is being generated. Most\n * variants are streaming deltas (text, reasoning, tool-call args); the\n * terminal `turn_complete` carries the assembled `Turn`. Lifecycle members\n * aren't deltas, hence the union name.\n */\nexport type TurnEvent =\n | { readonly type: \"text_delta\"; readonly text: string }\n | {\n readonly type: \"reasoning_delta\"\n readonly text: string\n /**\n * `trace` is the model's raw chain-of-thought; `summary` is a\n * model-written summary intended for display. OpenAI Responses emits\n * both as separate wire events; Anthropic and Gemini only emit\n * `trace`. Consumers who just want any reasoning text match once;\n * those who want only summaries filter `kind === \"summary\"`.\n */\n readonly kind: \"trace\" | \"summary\"\n }\n /**\n * The model declined to answer. `text` is the (streamed) explanation.\n * Distinct from the failure channel: a refusal is normal model output and\n * the stream still completes with `turn_complete`. OpenAI Responses emits\n * this; Anthropic surfaces refusals via `stop_reason`, and Gemini collapses\n * them into `finishReason: SAFETY` - both go without a `refusal_delta`.\n */\n | { readonly type: \"refusal_delta\"; readonly text: string }\n | { readonly type: \"tool_call_start\"; readonly call_id: string; readonly name: string }\n | { readonly type: \"tool_call_args_delta\"; readonly call_id: string; readonly delta: string }\n /**\n * Mid-stream cumulative usage. Carries the full `Usage` (including cache\n * token fields when the provider surfaces them) so consumers can drive\n * live budget / cost tracking without waiting for `turn_complete`.\n * Anthropic emits this on `message_start` and `message_delta`; other\n * providers may not emit any `usage_update` and only deliver usage via\n * `turn_complete.turn.usage`.\n */\n | { readonly type: \"usage_update\"; readonly usage: Usage }\n | { readonly type: \"turn_complete\"; readonly turn: Turn }\n\n/**\n * What flows out of an agent loop body to its consumer per turn: every\n * `TurnEvent` the provider emits (including the terminal `turn_complete`\n * carrying the assembled `Turn`), plus the output of any tool the loop ran.\n * Both variants carry a `type` discriminator.\n */\nexport type InteractionEvent = TurnEvent | FunctionCallOutput\n\nexport const isTurnComplete = (d: TurnEvent): d is Extract<TurnEvent, { type: \"turn_complete\" }> =>\n d.type === \"turn_complete\"\n\nexport const functionCalls = (turn: Turn): ReadonlyArray<FunctionCall> =>\n turn.items.filter((i): i is FunctionCall => i.type === \"function_call\")\n\nexport const reasonings = (turn: Turn): ReadonlyArray<Reasoning> =>\n turn.items.filter((i): i is Reasoning => i.type === \"reasoning\")\n\nexport const assistantMessages = (turn: Turn): ReadonlyArray<Message> =>\n turn.items.filter((i): i is Message => i.type === \"message\" && i.role === \"assistant\")\n\n/**\n * Append a completed turn and optional follow-up items to a state record's\n * history. Recipes use this at the point where structured tool results are\n * converted to model-facing `FunctionCallOutput`s.\n */\nexport const appendTurn = <S extends { readonly history: ReadonlyArray<Item> }>(\n state: S,\n turn: Turn,\n items: ReadonlyArray<Item> = [],\n): S => ({\n ...state,\n history: [...state.history, ...turn.items, ...items],\n})\n\n// ---------------------------------------------------------------------------\n// Stream operators\n// ---------------------------------------------------------------------------\n\n/**\n * Project a `TurnEvent` stream onto its `text_delta` payloads. Other\n * variants are dropped. Composes with `Lines.lines` +\n * `decodeJsonLines` for prompted-JSONL streaming.\n */\nexport const textDeltas = <E, R>(\n self: Stream.Stream<TurnEvent, E, R>,\n): Stream.Stream<string, E, R> =>\n self.pipe(\n Stream.filterMap((ev) =>\n ev.type === \"text_delta\" ? Result.succeed(ev.text) : Result.failVoid,\n ),\n )\n\n// ---------------------------------------------------------------------------\n// Structured-output integration\n// ---------------------------------------------------------------------------\n\n/**\n * The assistant message on the just-completed turn was a refusal block,\n * not an `output_text` payload. Returned by `toStructured` to short-circuit\n * decoding before `JSON.parse` / schema validation runs.\n */\nexport class RefusalRejected extends Data.TaggedError(\"RefusalRejected\")<{\n readonly turn: Turn\n}> {}\n\nconst lastAssistantContent = (turn: Turn): { readonly text: string; readonly refused: boolean } => {\n const assistants = assistantMessages(turn)\n const last = assistants[assistants.length - 1]\n if (last === undefined) return { text: \"\", refused: false }\n if (last.content.some(isRefusal)) return { text: \"\", refused: true }\n const text = last.content\n .filter(isOutputText)\n .map((b) => b.text)\n .join(\"\")\n return { text, refused: false }\n}\n\n/**\n * Validate a completed `Turn` against a `StructuredFormat`. Concatenates\n * `output_text` blocks on the last assistant message, then runs\n * `JSON.parse` + the format's schema validation.\n *\n * Three failure modes:\n * - `RefusalRejected` — the assistant emitted a refusal block.\n * - `JsonParseError` — the assembled text wasn't valid JSON.\n * - `StructuredDecodeError` — the JSON didn't match the schema.\n */\nexport const toStructured = <A>(\n turn: Turn,\n format: StructuredFormat.StructuredFormat<A>,\n): Effect.Effect<\n A,\n RefusalRejected | StructuredFormat.JsonParseError | StructuredFormat.StructuredDecodeError\n> =>\n pipe(lastAssistantContent(turn), ({ text, refused }) =>\n refused ? Effect.fail(new RefusalRejected({ turn })) : StructuredFormat.parseJson(format)(text),\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,OAAO,OAAO,OAAO;CAChC,OAAO,OAAO,MAAM,KAAK;CACzB,OAAO;CACP,aAAa;CACd,CAAC;AAoDF,MAAa,kBAAkB,MAC7B,EAAE,SAAS;AAEb,MAAa,iBAAiB,SAC5B,KAAK,MAAM,QAAQ,MAAyB,EAAE,SAAS,gBAAgB;AAEzE,MAAa,cAAc,SACzB,KAAK,MAAM,QAAQ,MAAsB,EAAE,SAAS,YAAY;AAElE,MAAa,qBAAqB,SAChC,KAAK,MAAM,QAAQ,MAAoB,EAAE,SAAS,aAAa,EAAE,SAAS,YAAY;;;;;;AAOxF,MAAa,cACX,OACA,MACA,QAA6B,EAAE,MACxB;CACP,GAAG;CACH,SAAS;EAAC,GAAG,MAAM;EAAS,GAAG,KAAK;EAAO,GAAG;EAAM;CACrD;;;;;;AAWD,MAAa,cACX,SAEA,KAAK,KACH,OAAO,WAAW,OAChB,GAAG,SAAS,eAAe,OAAO,QAAQ,GAAG,KAAK,GAAG,OAAO,SAC7D,CACF;;;;;;AAWH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAErE;AAEH,MAAM,wBAAwB,SAAqE;CACjG,MAAM,aAAa,kBAAkB,KAAK;CAC1C,MAAM,OAAO,WAAW,WAAW,SAAS;AAC5C,KAAI,SAAS,KAAA,EAAW,QAAO;EAAE,MAAM;EAAI,SAAS;EAAO;AAC3D,KAAI,KAAK,QAAQ,KAAK,UAAU,CAAE,QAAO;EAAE,MAAM;EAAI,SAAS;EAAM;AAKpE,QAAO;EAAE,MAJI,KAAK,QACf,OAAO,aAAa,CACpB,KAAK,MAAM,EAAE,KAAK,CAClB,KAAK,GACK;EAAE,SAAS;EAAO;;;;;;;;;;;;AAajC,MAAa,gBACX,MACA,WAKA,KAAK,qBAAqB,KAAK,GAAG,EAAE,MAAM,cACxC,UAAU,OAAO,KAAK,IAAI,gBAAgB,EAAE,MAAM,CAAC,CAAC,GAAGA,UAA2B,OAAO,CAAC,KAAK,CAChG"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { i as ImageSource } from "../Image-BZmKfIdq.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/embedding-model/Embedding.d.ts
|
|
4
|
+
declare namespace Embedding_d_exports {
|
|
5
|
+
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* One part of a mixed text+image input. Used inside `EmbedInput.content[]`
|
|
9
|
+
* for providers that accept interleaved modalities in a single embed call
|
|
10
|
+
* (Cohere v4, Voyage multimodal, Jina v4, Google `gemini-embedding-2`).
|
|
11
|
+
*/
|
|
12
|
+
type EmbedContentPart = {
|
|
13
|
+
readonly text: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly image: ImageSource;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* What you embed. The `string` shorthand covers the common text-only case;
|
|
19
|
+
* structured variants exist for image-only and mixed-modality inputs.
|
|
20
|
+
*
|
|
21
|
+
* Not every provider accepts every variant: text-only providers (OpenAI,
|
|
22
|
+
* Mixedbread today) handle `string` and `{ text }`; multimodal providers
|
|
23
|
+
* (Google, Jina v4, Voyage multimodal, Cohere v4) handle all four. A
|
|
24
|
+
* provider layer rejects shapes it can't encode as `AiError.InvalidRequest`.
|
|
25
|
+
*/
|
|
26
|
+
type EmbedInput = string | {
|
|
27
|
+
readonly text: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly image: ImageSource;
|
|
30
|
+
} | {
|
|
31
|
+
readonly content: ReadonlyArray<EmbedContentPart>;
|
|
32
|
+
};
|
|
33
|
+
/** Dense float32 vector. The default representation across all providers. */
|
|
34
|
+
type Float32Embedding = {
|
|
35
|
+
readonly _tag: "float32";
|
|
36
|
+
readonly vector: Float32Array;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Dense int8-quantized vector. ~4x smaller than float32 with minimal
|
|
40
|
+
* recall loss on most benchmarks.
|
|
41
|
+
*/
|
|
42
|
+
type Int8Embedding = {
|
|
43
|
+
readonly _tag: "int8";
|
|
44
|
+
readonly vector: Int8Array;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Dense binary-quantized vector. One bit per dimension, packed into bytes.
|
|
48
|
+
* ~32x smaller than float32; meaningful recall loss but useful for hot
|
|
49
|
+
* indexes paired with a float32 reranker pass.
|
|
50
|
+
*/
|
|
51
|
+
type BinaryEmbedding = {
|
|
52
|
+
readonly _tag: "binary";
|
|
53
|
+
readonly vector: Uint8Array;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Sparse vector. Token-keyed weights for hybrid search (dense + lexical-
|
|
57
|
+
* style sparse). The single hosted producer today is Jina's `elser-v2`
|
|
58
|
+
* model, which returns subword tokens (e.g. `"bread"`, `"##ing"`) with
|
|
59
|
+
* their relevance weights.
|
|
60
|
+
*
|
|
61
|
+
* The shape is `Record<string, number>` rather than `(indices, values)`
|
|
62
|
+
* because real hosted learned-sparse encoders (ELSER, SPLADE) emit token
|
|
63
|
+
* strings with no shared vocabulary index. Converting to integer indices
|
|
64
|
+
* would either need a vocabulary table the model doesn't expose, or
|
|
65
|
+
* lose the cross-vector matching semantics. If a provider ever exposes
|
|
66
|
+
* index-valued sparse vectors (Pinecone-style, where you bring your own
|
|
67
|
+
* vocab), add an `IndexSparseEmbedding` sibling arm with `_tag:
|
|
68
|
+
* "sparse-indexed"`.
|
|
69
|
+
*
|
|
70
|
+
* Score with `Vector.sparseCosine` — dot product over the intersection
|
|
71
|
+
* of keys, normalized by the L2 norms of both maps.
|
|
72
|
+
*/
|
|
73
|
+
type SparseEmbedding = {
|
|
74
|
+
readonly _tag: "sparse";
|
|
75
|
+
readonly weights: Readonly<Record<string, number>>;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Multivector / late-interaction output: one float32 vector per token.
|
|
79
|
+
* Score documents with `Vector.maxSim` (ColBERT-style: per query vector,
|
|
80
|
+
* max dot product across doc vectors, summed). Typically ~50-500 vectors
|
|
81
|
+
* per document, each shorter than a single-vector embedding (~128 dim
|
|
82
|
+
* vs ~1024).
|
|
83
|
+
*
|
|
84
|
+
* Quantized multivector forms aren't modeled for the same reason as
|
|
85
|
+
* sparse - nothing on hosted APIs ships them yet.
|
|
86
|
+
*/
|
|
87
|
+
type MultivectorEmbedding = {
|
|
88
|
+
readonly _tag: "multivector";
|
|
89
|
+
readonly vectors: ReadonlyArray<Float32Array>;
|
|
90
|
+
};
|
|
91
|
+
type Embedding = Float32Embedding | Int8Embedding | BinaryEmbedding | SparseEmbedding | MultivectorEmbedding;
|
|
92
|
+
declare const isFloat32: (e: Embedding) => e is Float32Embedding;
|
|
93
|
+
declare const isInt8: (e: Embedding) => e is Int8Embedding;
|
|
94
|
+
declare const isBinary: (e: Embedding) => e is BinaryEmbedding;
|
|
95
|
+
declare const isSparse: (e: Embedding) => e is SparseEmbedding;
|
|
96
|
+
declare const isMultivector: (e: Embedding) => e is MultivectorEmbedding;
|
|
97
|
+
/**
|
|
98
|
+
* Token usage for one embed / embedMany call. One value per HTTP request,
|
|
99
|
+
* not per input vector. Most providers populate `inputTokens`; the field
|
|
100
|
+
* is optional for those that don't (or for mock layers in tests).
|
|
101
|
+
*/
|
|
102
|
+
type Usage = {
|
|
103
|
+
readonly inputTokens?: number;
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse, Embedding_d_exports as t };
|
|
107
|
+
//# sourceMappingURL=Embedding.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Embedding.d.mts","names":[],"sources":["../../src/embedding-model/Embedding.ts"],"mappings":";;;;;;;;;;;KAOY,gBAAA;EAAA,SAA8B,IAAA;AAAA;EAAA,SAA4B,KAAA,EAAO,WAAA;AAAA;;;;;;;;;;KAWjE,UAAA;EAAA,SAEG,IAAA;AAAA;EAAA,SACA,KAAA,EAAO,WAAA;AAAA;EAAA,SACP,OAAA,EAAS,aAAA,CAAc,gBAAA;AAAA;;KAY1B,gBAAA;EAAA,SACD,IAAA;EAAA,SACA,MAAA,EAAQ,YAAA;AAAA;;;;;KAOP,aAAA;EAAA,SACD,IAAA;EAAA,SACA,MAAA,EAAQ,SAAA;AAAA;;;;;;KAQP,eAAA;EAAA,SACD,IAAA;EAAA,SACA,MAAA,EAAQ,UAAA;AAAA;;;;;;AAZnB;;;;;;;;;AAUA;;;;KAuBY,eAAA;EAAA,SACD,IAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA;AAAA;;AAF7B;;;;;;;;;KAeY,oBAAA;EAAA,SACD,IAAA;EAAA,SACA,OAAA,EAAS,aAAA,CAAc,YAAA;AAAA;AAAA,KAGtB,SAAA,GACR,gBAAA,GACA,aAAA,GACA,eAAA,GACA,eAAA,GACA,oBAAA;AAAA,cAES,SAAA,GAAa,CAAA,EAAG,SAAA,KAAY,CAAA,IAAK,gBAAA;AAAA,cACjC,MAAA,GAAU,CAAA,EAAG,SAAA,KAAY,CAAA,IAAK,aAAA;AAAA,cAC9B,QAAA,GAAY,CAAA,EAAG,SAAA,KAAY,CAAA,IAAK,eAAA;AAAA,cAChC,QAAA,GAAY,CAAA,EAAG,SAAA,KAAY,CAAA,IAAK,eAAA;AAAA,cAChC,aAAA,GAAiB,CAAA,EAAG,SAAA,KAAY,CAAA,IAAK,oBAAA;;AAXlD;;;;KAkBY,KAAA;EAAA,SACD,WAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
//#region src/embedding-model/Embedding.ts
|
|
3
|
+
var Embedding_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
isBinary: () => isBinary,
|
|
5
|
+
isFloat32: () => isFloat32,
|
|
6
|
+
isInt8: () => isInt8,
|
|
7
|
+
isMultivector: () => isMultivector,
|
|
8
|
+
isSparse: () => isSparse
|
|
9
|
+
});
|
|
10
|
+
const isFloat32 = (e) => e._tag === "float32";
|
|
11
|
+
const isInt8 = (e) => e._tag === "int8";
|
|
12
|
+
const isBinary = (e) => e._tag === "binary";
|
|
13
|
+
const isSparse = (e) => e._tag === "sparse";
|
|
14
|
+
const isMultivector = (e) => e._tag === "multivector";
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isBinary, isFloat32, isInt8, isMultivector, isSparse, Embedding_exports as t };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=Embedding.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Embedding.mjs","names":[],"sources":["../../src/embedding-model/Embedding.ts"],"sourcesContent":["import type { ImageSource } from \"../domain/Image.js\"\n\n/**\n * One part of a mixed text+image input. Used inside `EmbedInput.content[]`\n * for providers that accept interleaved modalities in a single embed call\n * (Cohere v4, Voyage multimodal, Jina v4, Google `gemini-embedding-2`).\n */\nexport type EmbedContentPart = { readonly text: string } | { readonly image: ImageSource }\n\n/**\n * What you embed. The `string` shorthand covers the common text-only case;\n * structured variants exist for image-only and mixed-modality inputs.\n *\n * Not every provider accepts every variant: text-only providers (OpenAI,\n * Mixedbread today) handle `string` and `{ text }`; multimodal providers\n * (Google, Jina v4, Voyage multimodal, Cohere v4) handle all four. A\n * provider layer rejects shapes it can't encode as `AiError.InvalidRequest`.\n */\nexport type EmbedInput =\n | string\n | { readonly text: string }\n | { readonly image: ImageSource }\n | { readonly content: ReadonlyArray<EmbedContentPart> }\n\n// ---------------------------------------------------------------------------\n// Embedding representations\n//\n// The `_tag` reflects the wire form the provider returned, *not* what the\n// consumer asked for - request `encoding: \"int8\"` and you get back an\n// `Int8Embedding`. Math primitives are typed against the named interfaces\n// (see `Vector.ts`) so e.g. `sparseCosine` only accepts `SparseEmbedding`.\n// ---------------------------------------------------------------------------\n\n/** Dense float32 vector. The default representation across all providers. */\nexport type Float32Embedding = {\n readonly _tag: \"float32\"\n readonly vector: Float32Array\n}\n\n/**\n * Dense int8-quantized vector. ~4x smaller than float32 with minimal\n * recall loss on most benchmarks.\n */\nexport type Int8Embedding = {\n readonly _tag: \"int8\"\n readonly vector: Int8Array\n}\n\n/**\n * Dense binary-quantized vector. One bit per dimension, packed into bytes.\n * ~32x smaller than float32; meaningful recall loss but useful for hot\n * indexes paired with a float32 reranker pass.\n */\nexport type BinaryEmbedding = {\n readonly _tag: \"binary\"\n readonly vector: Uint8Array\n}\n\n/**\n * Sparse vector. Token-keyed weights for hybrid search (dense + lexical-\n * style sparse). The single hosted producer today is Jina's `elser-v2`\n * model, which returns subword tokens (e.g. `\"bread\"`, `\"##ing\"`) with\n * their relevance weights.\n *\n * The shape is `Record<string, number>` rather than `(indices, values)`\n * because real hosted learned-sparse encoders (ELSER, SPLADE) emit token\n * strings with no shared vocabulary index. Converting to integer indices\n * would either need a vocabulary table the model doesn't expose, or\n * lose the cross-vector matching semantics. If a provider ever exposes\n * index-valued sparse vectors (Pinecone-style, where you bring your own\n * vocab), add an `IndexSparseEmbedding` sibling arm with `_tag:\n * \"sparse-indexed\"`.\n *\n * Score with `Vector.sparseCosine` — dot product over the intersection\n * of keys, normalized by the L2 norms of both maps.\n */\nexport type SparseEmbedding = {\n readonly _tag: \"sparse\"\n readonly weights: Readonly<Record<string, number>>\n}\n\n/**\n * Multivector / late-interaction output: one float32 vector per token.\n * Score documents with `Vector.maxSim` (ColBERT-style: per query vector,\n * max dot product across doc vectors, summed). Typically ~50-500 vectors\n * per document, each shorter than a single-vector embedding (~128 dim\n * vs ~1024).\n *\n * Quantized multivector forms aren't modeled for the same reason as\n * sparse - nothing on hosted APIs ships them yet.\n */\nexport type MultivectorEmbedding = {\n readonly _tag: \"multivector\"\n readonly vectors: ReadonlyArray<Float32Array>\n}\n\nexport type Embedding =\n | Float32Embedding\n | Int8Embedding\n | BinaryEmbedding\n | SparseEmbedding\n | MultivectorEmbedding\n\nexport const isFloat32 = (e: Embedding): e is Float32Embedding => e._tag === \"float32\"\nexport const isInt8 = (e: Embedding): e is Int8Embedding => e._tag === \"int8\"\nexport const isBinary = (e: Embedding): e is BinaryEmbedding => e._tag === \"binary\"\nexport const isSparse = (e: Embedding): e is SparseEmbedding => e._tag === \"sparse\"\nexport const isMultivector = (e: Embedding): e is MultivectorEmbedding => e._tag === \"multivector\"\n\n/**\n * Token usage for one embed / embedMany call. One value per HTTP request,\n * not per input vector. Most providers populate `inputTokens`; the field\n * is optional for those that don't (or for mock layers in tests).\n */\nexport type Usage = {\n readonly inputTokens?: number\n}\n"],"mappings":";;;;;;;;;AAuGA,MAAa,aAAa,MAAwC,EAAE,SAAS;AAC7E,MAAa,UAAU,MAAqC,EAAE,SAAS;AACvE,MAAa,YAAY,MAAuC,EAAE,SAAS;AAC3E,MAAa,YAAY,MAAuC,EAAE,SAAS;AAC3E,MAAa,iBAAiB,MAA4C,EAAE,SAAS"}
|