@effect-uai/core 0.12.1 → 0.14.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/dist/{Audio-60lKKHxS.d.mts → Audio-_nGR4V0X.d.mts} +2 -2
- package/dist/{Audio-60lKKHxS.d.mts.map → Audio-_nGR4V0X.d.mts.map} +1 -1
- package/dist/Image-Cv6iBLTy.d.mts +99 -0
- package/dist/Image-Cv6iBLTy.d.mts.map +1 -0
- package/dist/{Items-SfUabNuB.d.mts → Items-C7MyrYPX.d.mts} +35 -4
- package/dist/Items-C7MyrYPX.d.mts.map +1 -0
- package/dist/Media-BbX7BAaO.d.mts +60 -0
- package/dist/Media-BbX7BAaO.d.mts.map +1 -0
- package/dist/{Tool-DE-rnvkw.d.mts → Tool-BF78QWtn.d.mts} +2 -2
- package/dist/{Tool-DE-rnvkw.d.mts.map → Tool-BF78QWtn.d.mts.map} +1 -1
- package/dist/{ToolEvent-D99MGQYH.d.mts → ToolEvent-Di4a723B.d.mts} +2 -2
- package/dist/{ToolEvent-D99MGQYH.d.mts.map → ToolEvent-Di4a723B.d.mts.map} +1 -1
- package/dist/{ToolResult-Cj8ChodL.d.mts → ToolResult-BsYQRjmW.d.mts} +2 -2
- package/dist/{ToolResult-Cj8ChodL.d.mts.map → ToolResult-BsYQRjmW.d.mts.map} +1 -1
- package/dist/{Toolkit-BEZrNPTI.d.mts → Toolkit-DAjJ9Tvl.d.mts} +5 -5
- package/dist/{Toolkit-BEZrNPTI.d.mts.map → Toolkit-DAjJ9Tvl.d.mts.map} +1 -1
- package/dist/browser/BrowserTool.d.mts +1 -1
- package/dist/capabilities/Capabilities.d.mts +26 -2
- package/dist/capabilities/Capabilities.d.mts.map +1 -1
- package/dist/capabilities/Capabilities.mjs +32 -1
- package/dist/capabilities/Capabilities.mjs.map +1 -1
- package/dist/chunker/Chunker.d.mts +32 -0
- package/dist/chunker/Chunker.d.mts.map +1 -0
- package/dist/chunker/Chunker.mjs +14 -0
- package/dist/chunker/Chunker.mjs.map +1 -0
- package/dist/domain/Audio.d.mts +1 -1
- package/dist/domain/Image.d.mts +3 -2
- package/dist/domain/Image.mjs +29 -3
- package/dist/domain/Image.mjs.map +1 -1
- package/dist/domain/Items.d.mts +2 -2
- package/dist/domain/Items.mjs +19 -1
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Media.d.mts +2 -2
- package/dist/domain/Media.mjs +51 -2
- package/dist/domain/Media.mjs.map +1 -1
- package/dist/domain/Music.d.mts +3 -8
- package/dist/domain/Music.d.mts.map +1 -1
- package/dist/domain/Music.mjs.map +1 -1
- package/dist/domain/Research.d.mts +1 -1
- package/dist/domain/Turn.d.mts +73 -9
- package/dist/domain/Turn.d.mts.map +1 -1
- package/dist/domain/Turn.mjs +38 -2
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/embedding-model/Embedding.d.mts +1 -1
- package/dist/image-generator/ImageGenerator.d.mts +188 -0
- package/dist/image-generator/ImageGenerator.d.mts.map +1 -0
- package/dist/image-generator/ImageGenerator.mjs +50 -0
- package/dist/image-generator/ImageGenerator.mjs.map +1 -0
- package/dist/index.d.mts +14 -9
- package/dist/index.mjs +7 -2
- package/dist/language-model/LanguageModel.d.mts +2 -2
- package/dist/music-generator/MusicGenerator.d.mts +3 -2
- package/dist/music-generator/MusicGenerator.d.mts.map +1 -1
- package/dist/observability/Metrics.d.mts +1 -1
- package/dist/reranker/Reranker.d.mts +46 -0
- package/dist/reranker/Reranker.d.mts.map +1 -0
- package/dist/reranker/Reranker.mjs +14 -0
- package/dist/reranker/Reranker.mjs.map +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +1 -1
- package/dist/streaming/Multipart.d.mts +21 -0
- package/dist/streaming/Multipart.d.mts.map +1 -0
- package/dist/streaming/Multipart.mjs +26 -0
- package/dist/streaming/Multipart.mjs.map +1 -0
- package/dist/testing/MockMusicGenerator.d.mts +1 -1
- package/dist/testing/MockProvider.d.mts +1 -1
- package/dist/testing/MockSpeechSynthesizer.d.mts +1 -1
- package/dist/tokenizer/Tokenizer.d.mts +22 -0
- package/dist/tokenizer/Tokenizer.d.mts.map +1 -0
- package/dist/tokenizer/Tokenizer.mjs +9 -0
- package/dist/tokenizer/Tokenizer.mjs.map +1 -0
- package/dist/tool/Approval.d.mts +3 -3
- package/dist/tool/HistoryCheck.d.mts +2 -2
- package/dist/tool/Tool.d.mts +1 -1
- package/dist/tool/ToolEvent.d.mts +1 -1
- package/dist/tool/ToolResult.d.mts +1 -1
- package/dist/tool/Toolkit.d.mts +1 -1
- package/dist/transcriber/Transcriber.d.mts +1 -1
- package/dist/web-read/WebReadTool.d.mts +1 -1
- package/dist/web-search/WebSearchTool.d.mts +1 -1
- package/package.json +21 -1
- package/src/capabilities/Capabilities.ts +38 -0
- package/src/chunker/Chunker.ts +34 -0
- package/src/domain/Image.ts +68 -2
- package/src/domain/Items.ts +18 -1
- package/src/domain/Media.ts +66 -0
- package/src/domain/Music.ts +4 -3
- package/src/domain/Turn.ts +56 -0
- package/src/image-generator/ImageGenerator.ts +165 -0
- package/src/index.ts +5 -0
- package/src/reranker/Reranker.ts +51 -0
- package/src/streaming/Multipart.ts +29 -0
- package/src/tokenizer/Tokenizer.ts +19 -0
- package/dist/Image-BK8-4H6s.d.mts +0 -59
- package/dist/Image-BK8-4H6s.d.mts.map +0 -1
- package/dist/Items-SfUabNuB.d.mts.map +0 -1
- package/dist/Media-DwgpifPD.d.mts +0 -57
- package/dist/Media-DwgpifPD.d.mts.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Context, Data, Effect, Stream } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
import type {
|
|
4
|
+
AspectRatio,
|
|
5
|
+
GeneratedImage,
|
|
6
|
+
ImageResolution,
|
|
7
|
+
ImageSource,
|
|
8
|
+
ProviderData,
|
|
9
|
+
} from "../domain/Image.js"
|
|
10
|
+
|
|
11
|
+
export type { AspectRatio, GeneratedImage, ImageResolution, ProviderData } from "../domain/Image.js"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Cross-provider text-to-image request. Shape and resolution are given
|
|
15
|
+
* as a ratio plus a tier rather than exact pixels: every provider takes
|
|
16
|
+
* one or derives the other. Exact dimensions, quality tiers, output
|
|
17
|
+
* encodings, and moderation knobs are vendor-specific and live on each
|
|
18
|
+
* provider's typed request.
|
|
19
|
+
*/
|
|
20
|
+
export type CommonImageGenerateRequest = {
|
|
21
|
+
readonly prompt: string
|
|
22
|
+
/** Each provider narrows this to its typed literal union. */
|
|
23
|
+
readonly model: string
|
|
24
|
+
readonly aspectRatio?: AspectRatio
|
|
25
|
+
readonly resolution?: ImageResolution
|
|
26
|
+
/** Default 1. Implementors without multi-image output fail `Unsupported` for more. */
|
|
27
|
+
readonly n?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Edit request: the same prompt-driven generation, conditioned on
|
|
32
|
+
* reference images. Separate from `generate` because the reference set
|
|
33
|
+
* is required here and absent there, and providers expose the two as
|
|
34
|
+
* distinct wire shapes. Per-provider caps on the array length apply.
|
|
35
|
+
*/
|
|
36
|
+
export type CommonImageEditRequest = CommonImageGenerateRequest & {
|
|
37
|
+
readonly images: ReadonlyArray<ImageSource>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Gated by {@link ImageStreaming}; `partialImages` is the preview-frame count. */
|
|
41
|
+
export type CommonStreamImageRequest = CommonImageGenerateRequest & {
|
|
42
|
+
readonly partialImages: 1 | 2 | 3
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The same previews, for an edit. Gated by {@link ImageStreaming}. */
|
|
46
|
+
export type CommonStreamImageEditRequest = CommonImageEditRequest & {
|
|
47
|
+
readonly partialImages: 1 | 2 | 3
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Optional throughout: not every provider bills or reports per token. */
|
|
51
|
+
export type ImageUsage = {
|
|
52
|
+
readonly inputTokens?: number
|
|
53
|
+
readonly outputTokens?: number
|
|
54
|
+
readonly totalTokens?: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ImageResponse = {
|
|
58
|
+
readonly images: ReadonlyArray<GeneratedImage>
|
|
59
|
+
readonly usage: ImageUsage
|
|
60
|
+
/**
|
|
61
|
+
* Response-level extras, keyed by provider name: the seed a request
|
|
62
|
+
* resolved to, timings, safety flags. Per-image extras live on each
|
|
63
|
+
* {@link GeneratedImage} instead. See `Image.ProviderData`.
|
|
64
|
+
*/
|
|
65
|
+
readonly providerData?: ProviderData
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Zero or more `PartialImage` previews, then exactly one `Complete`.
|
|
70
|
+
* `Complete` carries the `ImageResponse` fields flat, so it is
|
|
71
|
+
* assignable to `ImageResponse` and needs no unwrapping.
|
|
72
|
+
*/
|
|
73
|
+
export type ImageStreamEvent = Data.TaggedEnum<{
|
|
74
|
+
PartialImage: {
|
|
75
|
+
readonly image: ImageSource
|
|
76
|
+
/** Counts from 0 in emission order. */
|
|
77
|
+
readonly index: number
|
|
78
|
+
}
|
|
79
|
+
Complete: {
|
|
80
|
+
readonly images: ReadonlyArray<GeneratedImage>
|
|
81
|
+
readonly usage: ImageUsage
|
|
82
|
+
}
|
|
83
|
+
}>
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Namespace of constructors, type guards, and matchers for
|
|
87
|
+
* `ImageStreamEvent`, provided by `Data.taggedEnum`.
|
|
88
|
+
*/
|
|
89
|
+
export const ImageStreamEvent = Data.taggedEnum<ImageStreamEvent>()
|
|
90
|
+
|
|
91
|
+
export const isPartialImage = ImageStreamEvent.$is("PartialImage")
|
|
92
|
+
export const isComplete = ImageStreamEvent.$is("Complete")
|
|
93
|
+
|
|
94
|
+
export type ImageGeneratorService = {
|
|
95
|
+
/** Prompt in, images out. Universally supported. */
|
|
96
|
+
readonly generate: (
|
|
97
|
+
request: CommonImageGenerateRequest,
|
|
98
|
+
) => Effect.Effect<ImageResponse, AiError.AiError>
|
|
99
|
+
/** Prompt plus reference images in, images out. Universally supported. */
|
|
100
|
+
readonly edit: (request: CommonImageEditRequest) => Effect.Effect<ImageResponse, AiError.AiError>
|
|
101
|
+
/**
|
|
102
|
+
* Preview frames as the image resolves, then the final response.
|
|
103
|
+
* Implementors without a partial-image wire return `Unsupported` and
|
|
104
|
+
* do NOT register {@link ImageStreaming}, so the top-level helper is
|
|
105
|
+
* a compile-time error against their Layer.
|
|
106
|
+
*/
|
|
107
|
+
readonly streamGeneration: (
|
|
108
|
+
request: CommonStreamImageRequest,
|
|
109
|
+
) => Stream.Stream<ImageStreamEvent, AiError.AiError>
|
|
110
|
+
/** {@link streamGeneration} conditioned on reference images. */
|
|
111
|
+
readonly streamEdit: (
|
|
112
|
+
request: CommonStreamImageEditRequest,
|
|
113
|
+
) => Stream.Stream<ImageStreamEvent, AiError.AiError>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class ImageGenerator extends Context.Service<ImageGenerator, ImageGeneratorService>()(
|
|
117
|
+
"@betalyra/effect-uai/ImageGenerator",
|
|
118
|
+
) {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Capability marker for partial-image streaming. Phantom: the value is
|
|
122
|
+
* `void`, providers register with
|
|
123
|
+
* `Layer.succeed(ImageStreaming, undefined)`. Calling
|
|
124
|
+
* {@link streamGeneration} while only a non-streaming Layer is in scope
|
|
125
|
+
* fails at `Effect.provide` with a type error.
|
|
126
|
+
*/
|
|
127
|
+
export class ImageStreaming extends Context.Service<ImageStreaming, void>()(
|
|
128
|
+
"@betalyra/effect-uai/capability/ImageStreaming",
|
|
129
|
+
) {}
|
|
130
|
+
|
|
131
|
+
/** Text to image. */
|
|
132
|
+
export const generate = (
|
|
133
|
+
request: CommonImageGenerateRequest,
|
|
134
|
+
): Effect.Effect<ImageResponse, AiError.AiError, ImageGenerator> =>
|
|
135
|
+
Effect.flatMap(ImageGenerator, (g) => g.generate(request))
|
|
136
|
+
|
|
137
|
+
/** Text plus reference images to image. */
|
|
138
|
+
export const edit = (
|
|
139
|
+
request: CommonImageEditRequest,
|
|
140
|
+
): Effect.Effect<ImageResponse, AiError.AiError, ImageGenerator> =>
|
|
141
|
+
Effect.flatMap(ImageGenerator, (g) => g.edit(request))
|
|
142
|
+
|
|
143
|
+
/** Preview frames then the final response. Requires {@link ImageStreaming} in R. */
|
|
144
|
+
export const streamGeneration = (
|
|
145
|
+
request: CommonStreamImageRequest,
|
|
146
|
+
): Stream.Stream<ImageStreamEvent, AiError.AiError, ImageGenerator | ImageStreaming> =>
|
|
147
|
+
Stream.unwrap(
|
|
148
|
+
Effect.gen(function* () {
|
|
149
|
+
const g = yield* ImageGenerator
|
|
150
|
+
yield* ImageStreaming
|
|
151
|
+
return g.streamGeneration(request)
|
|
152
|
+
}),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
/** The same, conditioned on reference images. Requires {@link ImageStreaming} in R. */
|
|
156
|
+
export const streamEdit = (
|
|
157
|
+
request: CommonStreamImageEditRequest,
|
|
158
|
+
): Stream.Stream<ImageStreamEvent, AiError.AiError, ImageGenerator | ImageStreaming> =>
|
|
159
|
+
Stream.unwrap(
|
|
160
|
+
Effect.gen(function* () {
|
|
161
|
+
const g = yield* ImageGenerator
|
|
162
|
+
yield* ImageStreaming
|
|
163
|
+
return g.streamEdit(request)
|
|
164
|
+
}),
|
|
165
|
+
)
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as Browser from "./browser/Browser.js"
|
|
|
4
4
|
export * as BrowserError from "./browser/BrowserError.js"
|
|
5
5
|
export * as BrowserTool from "./browser/BrowserTool.js"
|
|
6
6
|
export * as Capabilities from "./capabilities/Capabilities.js"
|
|
7
|
+
export * as Chunker from "./chunker/Chunker.js"
|
|
7
8
|
export * as Citation from "./domain/Citation.js"
|
|
8
9
|
export * as DeepResearch from "./research/DeepResearch.js"
|
|
9
10
|
export * as Image from "./domain/Image.js"
|
|
@@ -16,8 +17,10 @@ export * as Transcript from "./domain/Transcript.js"
|
|
|
16
17
|
export * as Turn from "./domain/Turn.js"
|
|
17
18
|
export * as Embedding from "./embedding-model/Embedding.js"
|
|
18
19
|
export * as EmbeddingModel from "./embedding-model/EmbeddingModel.js"
|
|
20
|
+
export * as ImageGenerator from "./image-generator/ImageGenerator.js"
|
|
19
21
|
export * as LanguageModel from "./language-model/LanguageModel.js"
|
|
20
22
|
export * as MusicGenerator from "./music-generator/MusicGenerator.js"
|
|
23
|
+
export * as Reranker from "./reranker/Reranker.js"
|
|
21
24
|
export * as Memory from "./sandbox/Memory.js"
|
|
22
25
|
export * as Sandbox from "./sandbox/Sandbox.js"
|
|
23
26
|
export * as SandboxError from "./sandbox/SandboxError.js"
|
|
@@ -30,6 +33,7 @@ export * as WebReadTool from "./web-read/WebReadTool.js"
|
|
|
30
33
|
export * as WebSearch from "./web-search/WebSearch.js"
|
|
31
34
|
export * as WebSearchTool from "./web-search/WebSearchTool.js"
|
|
32
35
|
export * as Vector from "./math/Vector.js"
|
|
36
|
+
export * as Tokenizer from "./tokenizer/Tokenizer.js"
|
|
33
37
|
export * as Loop from "./loop/Loop.js"
|
|
34
38
|
export * as Retry from "./retry/Retry.js"
|
|
35
39
|
export * as Tool from "./tool/Tool.js"
|
|
@@ -40,6 +44,7 @@ export * as Approval from "./tool/Approval.js"
|
|
|
40
44
|
export * as HistoryCheck from "./tool/HistoryCheck.js"
|
|
41
45
|
export * as JSONL from "./streaming/JSONL.js"
|
|
42
46
|
export * as Lines from "./streaming/Lines.js"
|
|
47
|
+
export * as Multipart from "./streaming/Multipart.js"
|
|
43
48
|
export * as SSE from "./streaming/SSE.js"
|
|
44
49
|
export * as StructuredFormat from "./structured-format/StructuredFormat.js"
|
|
45
50
|
export * as Metrics from "./observability/Metrics.js"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Context, Effect } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cross-provider rerank request. Vendor knobs (multimodal documents,
|
|
6
|
+
* instruction fields, truncation) live on the provider's typed request.
|
|
7
|
+
*/
|
|
8
|
+
export type CommonRerankRequest = {
|
|
9
|
+
readonly query: string
|
|
10
|
+
readonly documents: ReadonlyArray<string>
|
|
11
|
+
/** Each provider narrows this to its typed literal union. */
|
|
12
|
+
readonly model: string
|
|
13
|
+
/** Keep only the top N results. Default: all documents. */
|
|
14
|
+
readonly topN?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type RerankResult = {
|
|
18
|
+
/** Position in the request's `documents`. */
|
|
19
|
+
readonly index: number
|
|
20
|
+
readonly score: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Optional throughout: some providers bill per search unit, not per token. */
|
|
24
|
+
export type RerankUsage = {
|
|
25
|
+
readonly totalTokens?: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Score contract: `results` is sorted descending, higher is better. Scores
|
|
30
|
+
* order candidates within one call; no range or calibration is promised and
|
|
31
|
+
* they are not comparable across requests. Implementors must sort descending
|
|
32
|
+
* if the wire does not.
|
|
33
|
+
*/
|
|
34
|
+
export type RerankResponse = {
|
|
35
|
+
readonly results: ReadonlyArray<RerankResult>
|
|
36
|
+
readonly usage: RerankUsage
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type RerankerService = {
|
|
40
|
+
readonly rerank: (request: CommonRerankRequest) => Effect.Effect<RerankResponse, AiError.AiError>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Reranker extends Context.Service<Reranker, RerankerService>()(
|
|
44
|
+
"@betalyra/effect-uai/Reranker",
|
|
45
|
+
) {}
|
|
46
|
+
|
|
47
|
+
/** Score a candidate set against a query, best first. */
|
|
48
|
+
export const rerank = (
|
|
49
|
+
request: CommonRerankRequest,
|
|
50
|
+
): Effect.Effect<RerankResponse, AiError.AiError, Reranker> =>
|
|
51
|
+
Effect.flatMap(Reranker, (r) => r.rerank(request))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { HttpClientRequest } from "effect/unstable/http"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Multipart body for an `HttpClientRequest`, encoded to bytes.
|
|
6
|
+
*
|
|
7
|
+
* Use this over `HttpClientRequest.bodyFormData`: the Undici client
|
|
8
|
+
* passes the `FormData` object straight to `dispatcher.request`, which
|
|
9
|
+
* cannot serialise it, so the request is never sent and the effect
|
|
10
|
+
* hangs with no error. Encoding here produces the same bytes every
|
|
11
|
+
* other client derives internally, so it works on all of them.
|
|
12
|
+
*
|
|
13
|
+
* The failure is whatever `Response.arrayBuffer` rejects with; map it
|
|
14
|
+
* to your provider's transport error at the call site.
|
|
15
|
+
*/
|
|
16
|
+
export const bodyMultipart = (
|
|
17
|
+
form: FormData,
|
|
18
|
+
): Effect.Effect<
|
|
19
|
+
(request: HttpClientRequest.HttpClientRequest) => HttpClientRequest.HttpClientRequest,
|
|
20
|
+
unknown
|
|
21
|
+
> =>
|
|
22
|
+
Effect.gen(function* () {
|
|
23
|
+
const encoded = new Response(form)
|
|
24
|
+
const buffer = yield* Effect.tryPromise(() => encoded.arrayBuffer())
|
|
25
|
+
return HttpClientRequest.bodyUint8Array(
|
|
26
|
+
new Uint8Array(buffer),
|
|
27
|
+
encoded.headers.get("content-type") ?? "multipart/form-data",
|
|
28
|
+
)
|
|
29
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context } from "effect"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Turning text into tokens, for sizing chunks, budgeting context, and
|
|
5
|
+
* estimating usage a provider does not report. Count with `encode(text).length`.
|
|
6
|
+
*
|
|
7
|
+
* Implementor contract: both methods are synchronous, so counting inside a loop
|
|
8
|
+
* never awaits; loading a vocabulary is the layer's job. `decode` inverts
|
|
9
|
+
* `encode`. Implement this only over a real vocabulary, never a heuristic:
|
|
10
|
+
* a character-count estimate is a plain function, not a service.
|
|
11
|
+
*/
|
|
12
|
+
export type TokenizerService = {
|
|
13
|
+
readonly encode: (text: string) => ReadonlyArray<number>
|
|
14
|
+
readonly decode: (tokens: ReadonlyArray<number>) => string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Tokenizer extends Context.Service<Tokenizer, TokenizerService>()(
|
|
18
|
+
"@betalyra/effect-uai/Tokenizer",
|
|
19
|
+
) {}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { i as MediaUrl, n as MediaBytes, r as MediaSource, t as MediaBase64 } from "./Media-DwgpifPD.mjs";
|
|
2
|
-
import { Schema } from "effect";
|
|
3
|
-
declare namespace Image_d_exports {
|
|
4
|
-
export { ImageBase64Source, ImageBytesSource, ImageMimeType, ImageSource, ImageUrlSource, imageBase64, imageBytes, imageUrl, isImageBase64, isImageBytes, isImageUrl };
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Image MIME types AI providers typically accept. The first four are the
|
|
8
|
-
* universal subset (Cohere v4, Voyage multimodal, Jina v4, Google
|
|
9
|
-
* `gemini-embedding-2`); HEIC / HEIF are Google-specific. The
|
|
10
|
-
* `(string & {})` tail keeps autocomplete on the literals while still
|
|
11
|
-
* accepting any string, so a newly-supported format works without an
|
|
12
|
-
* SDK update.
|
|
13
|
-
*/
|
|
14
|
-
type ImageMimeType = "image/png" | "image/jpeg" | "image/webp" | "image/gif" | "image/heic" | "image/heif" | (string & {});
|
|
15
|
-
type ImageUrlSource = MediaUrl<ImageMimeType>;
|
|
16
|
-
type ImageBase64Source = MediaBase64<ImageMimeType>;
|
|
17
|
-
type ImageBytesSource = MediaBytes<ImageMimeType>;
|
|
18
|
-
/**
|
|
19
|
-
* Where an image lives. Provider layers normalize across these:
|
|
20
|
-
* `bytes` becomes a base64 data URI for OpenAI / Anthropic, an
|
|
21
|
-
* `inlineData` part for Gemini, and a separate field for Cohere /
|
|
22
|
-
* Voyage. URL constraints (must be HTTPS, must be public, …) are
|
|
23
|
-
* provider-specific and validated at the layer, not in the type.
|
|
24
|
-
*/
|
|
25
|
-
type ImageSource = MediaSource<ImageMimeType>;
|
|
26
|
-
declare const ImageUrlSource: Schema.TaggedStruct<"url", {
|
|
27
|
-
readonly url: Schema.String;
|
|
28
|
-
readonly mimeType: Schema.optional<Schema.Schema<ImageMimeType>>;
|
|
29
|
-
}>;
|
|
30
|
-
declare const ImageBase64Source: Schema.TaggedStruct<"base64", {
|
|
31
|
-
readonly base64: Schema.String;
|
|
32
|
-
readonly mimeType: Schema.Schema<ImageMimeType>;
|
|
33
|
-
}>;
|
|
34
|
-
declare const ImageBytesSource: Schema.TaggedStruct<"bytes", {
|
|
35
|
-
readonly bytes: Schema.Uint8Array;
|
|
36
|
-
readonly mimeType: Schema.Schema<ImageMimeType>;
|
|
37
|
-
}>;
|
|
38
|
-
declare const ImageSource: Schema.Schema<ImageSource>;
|
|
39
|
-
declare const imageUrl: (url: string, mimeType?: ImageMimeType) => ImageUrlSource;
|
|
40
|
-
declare const imageBase64: (base64: string, mimeType: ImageMimeType) => ImageBase64Source;
|
|
41
|
-
declare const imageBytes: (bytes: Uint8Array, mimeType: ImageMimeType) => ImageBytesSource;
|
|
42
|
-
declare const isImageUrl: <I>(input: I) => input is I & {
|
|
43
|
-
readonly _tag: "url";
|
|
44
|
-
readonly url: string;
|
|
45
|
-
readonly mimeType?: ImageMimeType | undefined;
|
|
46
|
-
};
|
|
47
|
-
declare const isImageBase64: <I>(input: I) => input is I & {
|
|
48
|
-
readonly _tag: "base64";
|
|
49
|
-
readonly base64: string;
|
|
50
|
-
readonly mimeType: ImageMimeType;
|
|
51
|
-
};
|
|
52
|
-
declare const isImageBytes: <I>(input: I) => input is I & {
|
|
53
|
-
readonly _tag: "bytes";
|
|
54
|
-
readonly bytes: Uint8Array<ArrayBufferLike>;
|
|
55
|
-
readonly mimeType: ImageMimeType;
|
|
56
|
-
};
|
|
57
|
-
//#endregion
|
|
58
|
-
export { ImageUrlSource as a, imageBytes as c, isImageBytes as d, isImageUrl as f, ImageSource as i, imageUrl as l, ImageBytesSource as n, Image_d_exports as o, ImageMimeType as r, imageBase64 as s, ImageBase64Source as t, isImageBase64 as u };
|
|
59
|
-
//# sourceMappingURL=Image-BK8-4H6s.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Image-BK8-4H6s.d.mts","names":[],"sources":["../src/domain/Image.ts"],"mappings":";;;;;;;;;;;;;KAWY;KAYA,iBAAiB,SAAS;KAC1B,oBAAoB,YAAY;KAChC,mBAAmB,WAAW;;;;;;;;KAS9B,cAAc,YAAY;cAEzB,gBAAc,OAAA;;;;cAKd,mBAAiB,OAAA;;;;cAKjB,kBAAgB,OAAA;;;;cAKhB,aAAa,OAAO,OAAO;cAM3B,WAAQ,aAAe,WAAa,kBAAgB;cAGpD,cAAW,gBAAkB,UAAY,kBAAgB;cAMzD,aAAU,OAAW,YAAU,UAAY,kBAAgB;cAM3D,aAAU,GAAA,OAAA,MAAA,SAAA;;;;;cACV,gBAAa,GAAA,OAAA,MAAA,SAAA;;;;;cACb,eAAY,GAAA,OAAA,MAAA,SAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Items-SfUabNuB.d.mts","names":[],"sources":["../src/domain/Items.ts"],"mappings":";;;;;cAOa,WAAS,OAAA;;;;KAIV,mBAAmB,UAAU;;;;;;;;;cAU5B,YAAU,OAAA;;;;KAIX,oBAAoB,WAAW;;;;;;;;;cAgB9B,aAAW,OAAA;;;;;;;;;KASZ,qBAAqB,YAAY;cAEhC,cAAY,OAAA;;;;;KAKb,sBAAsB,aAAa;cAElC,uBAAqB,OAAA;;;;;;;KAOtB,+BAA+B,sBAAsB;cAEpD,UAAQ,OAAA;;;;;KAKT,kBAAkB,SAAS;cAE1B,YAAU,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;KACX,oBAAoB,WAAW;cAE9B,gBAAa,GAAA,OAAA,MAAA,SAAA;;;;;;;;;cACb,iBAAc,GAAA,OAAA,MAAA,SAAA;;;;;cACd,0BAAuB,GAAA,OAAA,MAAA,SAAA;;;;;;;cACvB,aAAU,GAAA,OAAA,MAAA,SAAA;;;;;cAEV,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKX,oBAAoB,WAAW;;;;;;;cAQ9B,SAAO,OAAA;;;;KAIR,iBAAiB,QAAQ;cAExB,cAAY,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACb,sBAAsB,aAAa;cAElC,MAAI,OAAA;KACL,cAAc,KAAK;cAqBlB,SAAO,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAMR,iBAAiB,QAAQ;cAExB,UAAQ,OAAA;;;;;;;KAQT,kBAAkB,SAAS;cAE1B,gBAAc,OAAA;;;;;;KAMf,wBAAwB,eAAe;;;;;;;cAQtC,WAAS,OAAA;;;;;;;KAOV,mBAAmB,UAAU;cAE5B,aAAW,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACZ,qBAAqB,YAAY;cAMhC,cAAW,GAAA,OAAA,MAAA,SAAA;;;;cACX,eAAY,GAAA,OAAA,MAAA,SAAA;;;;cACZ,eAAY,GAAA,OAAA,MAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cACZ,YAAS,GAAA,OAAA,MAAA,SAAA;;;;cAET,YAAS,GAAA,OAAA,MAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cACT,aAAU,GAAA,OAAA,MAAA,SAAA;;;;;;;cACV,mBAAgB,GAAA,OAAA,MAAA,SAAA;;;;;;cAChB,cAAW,GAAA,OAAA,MAAA,SAAA;;;;;;;;;;;;;;;;;;cAiBX,oBAAkB,OAAA;;;;KAInB,4BAA4B,mBAAmB;cAE9C,qBAAmB,OAAA;;;KAGpB,6BAA6B,oBAAoB;cAEhD,OAAK,OAAA;;;;;;;;;;;;KAON,eAAe,MAAM;cAEpB,YAAU,OAAA;KAUX,oBAAoB,WAAW;cAM9B,WAAQ,iBAAmB;cAM3B,aAAU,iBAAmB;cAM7B,gBAAa,iBAAmB;cAMhC,iBAAc,iBAAmB,mBAAmB"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
declare namespace Media_d_exports {
|
|
2
|
-
export { MediaBase64, MediaBytes, MediaSource, MediaUrl, isMediaBase64, isMediaBytes, isMediaUrl };
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Cross-modality media reference shape.
|
|
6
|
-
*
|
|
7
|
-
* Every "media at rest" reference - image, audio, video, document - is one
|
|
8
|
-
* of three variants:
|
|
9
|
-
*
|
|
10
|
-
* - `url` : a remote address (HTTP, GCS, etc.). The model fetches it.
|
|
11
|
-
* `mimeType` is optional - servers usually set Content-Type.
|
|
12
|
-
* Some providers (Gemini `fileData`) want it explicit.
|
|
13
|
-
*
|
|
14
|
-
* - `base64` : an inline base64-encoded payload. Always carries a
|
|
15
|
-
* `mimeType` so the consumer knows how to decode.
|
|
16
|
-
*
|
|
17
|
-
* - `bytes` : raw `Uint8Array`. Provider layers normalize to base64 or
|
|
18
|
-
* multipart upload at the wire boundary - users don't need
|
|
19
|
-
* to encode themselves.
|
|
20
|
-
*
|
|
21
|
-
* Per-modality files (`Image.ts`, future `Audio.ts` / `Video.ts` /
|
|
22
|
-
* `Document.ts`) instantiate this shape with their typed MIME union to
|
|
23
|
-
* get autocomplete on common formats while keeping the structural type
|
|
24
|
-
* uniform across modalities.
|
|
25
|
-
*
|
|
26
|
-
* Streaming media (live mic feed, streaming TTS playback) is *not*
|
|
27
|
-
* modeled here. Streams carry effect parameters (`Stream<A, E, R>`) and
|
|
28
|
-
* lifecycle (Scope, cancellation) that don't apply to media at rest. The
|
|
29
|
-
* complementary type lives alongside this one as `*Stream` in each
|
|
30
|
-
* per-modality file when those modalities land.
|
|
31
|
-
*
|
|
32
|
-
* Provider-uploaded asset references (OpenAI Files `file_id`, Gemini
|
|
33
|
-
* Files API URIs, Anthropic file IDs) are also out of scope here -
|
|
34
|
-
* they're a separate union (`FileRef`) added when needed.
|
|
35
|
-
*/
|
|
36
|
-
type MediaUrl<M extends string = string> = {
|
|
37
|
-
readonly _tag: "url";
|
|
38
|
-
readonly url: string;
|
|
39
|
-
readonly mimeType?: M;
|
|
40
|
-
};
|
|
41
|
-
type MediaBase64<M extends string = string> = {
|
|
42
|
-
readonly _tag: "base64";
|
|
43
|
-
readonly base64: string;
|
|
44
|
-
readonly mimeType: M;
|
|
45
|
-
};
|
|
46
|
-
type MediaBytes<M extends string = string> = {
|
|
47
|
-
readonly _tag: "bytes";
|
|
48
|
-
readonly bytes: Uint8Array;
|
|
49
|
-
readonly mimeType: M;
|
|
50
|
-
};
|
|
51
|
-
type MediaSource<M extends string = string> = MediaUrl<M> | MediaBase64<M> | MediaBytes<M>;
|
|
52
|
-
declare const isMediaUrl: <M extends string>(s: MediaSource<M>) => s is MediaUrl<M>;
|
|
53
|
-
declare const isMediaBase64: <M extends string>(s: MediaSource<M>) => s is MediaBase64<M>;
|
|
54
|
-
declare const isMediaBytes: <M extends string>(s: MediaSource<M>) => s is MediaBytes<M>;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { Media_d_exports as a, isMediaUrl as c, MediaUrl as i, MediaBytes as n, isMediaBase64 as o, MediaSource as r, isMediaBytes as s, MediaBase64 as t };
|
|
57
|
-
//# sourceMappingURL=Media-DwgpifPD.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Media-DwgpifPD.d.mts","names":[],"sources":["../src/domain/Media.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiCY,SAAS;WACV;WACA;WACA,WAAW;;KAGV,YAAY;WACb;WACA;WACA,UAAU;;KAGT,WAAW;WACZ;WACA,OAAO;WACP,UAAU;;KAGT,YAAY,6BAA6B,SAAS,KAAK,YAAY,KAAK,WAAW;cAElF,aAAc,kBAAgB,GAAK,YAAY,OAAK,KAAK,SAAS;cAGlE,gBAAiB,kBAAgB,GAAK,YAAY,OAAK,KAAK,YAAY;cAGxE,eAAgB,kBAAgB,GAAK,YAAY,OAAK,KAAK,WAAW"}
|