@effect-uai/core 0.3.0 → 0.5.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/{AiError-CBuPHVKA.d.mts → AiError-CAX_48RU.d.mts} +27 -5
- package/dist/{AiError-CBuPHVKA.d.mts.map → AiError-CAX_48RU.d.mts.map} +1 -1
- package/dist/Audio-BfCTGnH3.d.mts +61 -0
- package/dist/Audio-BfCTGnH3.d.mts.map +1 -0
- package/dist/{Image-BZmKfIdq.d.mts → Image-HNmMpMTh.d.mts} +1 -1
- package/dist/{Image-BZmKfIdq.d.mts.map → Image-HNmMpMTh.d.mts.map} +1 -1
- package/dist/{Items-CB8Bo3FI.d.mts → Items-DqbaJoz7.d.mts} +5 -5
- package/dist/{Items-CB8Bo3FI.d.mts.map → Items-DqbaJoz7.d.mts.map} +1 -1
- package/dist/{StructuredFormat-BWq5Hd1O.d.mts → StructuredFormat-BbN4dosH.d.mts} +11 -4
- package/dist/StructuredFormat-BbN4dosH.d.mts.map +1 -0
- package/dist/{Tool-DjVufH7i.d.mts → Tool-Y0__Py1H.d.mts} +20 -4
- package/dist/Tool-Y0__Py1H.d.mts.map +1 -0
- package/dist/Turn-ChbL2foc.d.mts +388 -0
- package/dist/Turn-ChbL2foc.d.mts.map +1 -0
- package/dist/domain/AiError.d.mts +2 -2
- package/dist/domain/AiError.mjs +19 -3
- package/dist/domain/AiError.mjs.map +1 -1
- package/dist/domain/Audio.d.mts +2 -0
- package/dist/domain/Audio.mjs +14 -0
- package/dist/domain/Audio.mjs.map +1 -0
- package/dist/domain/Image.d.mts +1 -1
- package/dist/domain/Items.d.mts +1 -1
- package/dist/domain/Items.mjs +1 -1
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Music.d.mts +116 -0
- package/dist/domain/Music.d.mts.map +1 -0
- package/dist/domain/Music.mjs +29 -0
- package/dist/domain/Music.mjs.map +1 -0
- package/dist/domain/Transcript.d.mts +95 -0
- package/dist/domain/Transcript.d.mts.map +1 -0
- package/dist/domain/Transcript.mjs +22 -0
- package/dist/domain/Transcript.mjs.map +1 -0
- package/dist/domain/Turn.d.mts +2 -2
- package/dist/domain/Turn.mjs +22 -4
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/domain/Turn.test.d.mts +1 -0
- package/dist/domain/Turn.test.mjs +136 -0
- package/dist/domain/Turn.test.mjs.map +1 -0
- package/dist/embedding-model/Embedding.d.mts +15 -3
- package/dist/embedding-model/Embedding.d.mts.map +1 -1
- package/dist/embedding-model/Embedding.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.d.mts +33 -17
- package/dist/embedding-model/EmbeddingModel.d.mts.map +1 -1
- package/dist/embedding-model/EmbeddingModel.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.test.d.mts +1 -0
- package/dist/embedding-model/EmbeddingModel.test.mjs +59 -0
- package/dist/embedding-model/EmbeddingModel.test.mjs.map +1 -0
- package/dist/index.d.mts +13 -7
- package/dist/index.mjs +7 -1
- package/dist/language-model/LanguageModel.d.mts +30 -8
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs +33 -3
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/language-model/LanguageModel.test.d.mts +1 -0
- package/dist/language-model/LanguageModel.test.mjs +143 -0
- package/dist/language-model/LanguageModel.test.mjs.map +1 -0
- package/dist/loop/Loop.d.mts +94 -11
- package/dist/loop/Loop.d.mts.map +1 -1
- package/dist/loop/Loop.mjs +92 -26
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.mjs +171 -3
- package/dist/loop/Loop.test.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.d.mts +77 -0
- package/dist/music-generator/MusicGenerator.d.mts.map +1 -0
- package/dist/music-generator/MusicGenerator.mjs +51 -0
- package/dist/music-generator/MusicGenerator.mjs.map +1 -0
- package/dist/music-generator/MusicGenerator.test.d.mts +1 -0
- package/dist/music-generator/MusicGenerator.test.mjs +154 -0
- package/dist/music-generator/MusicGenerator.test.mjs.map +1 -0
- package/dist/observability/Metrics.d.mts +1 -1
- package/dist/observability/Metrics.mjs +1 -1
- package/dist/observability/Metrics.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +96 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts.map +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs +48 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs.map +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.test.d.mts +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +112 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs.map +1 -0
- package/dist/streaming/JSONL.d.mts +10 -3
- package/dist/streaming/JSONL.d.mts.map +1 -1
- package/dist/streaming/JSONL.mjs +15 -9
- package/dist/streaming/JSONL.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.d.mts +2 -2
- package/dist/structured-format/StructuredFormat.mjs +9 -1
- package/dist/structured-format/StructuredFormat.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.test.d.mts +1 -0
- package/dist/structured-format/StructuredFormat.test.mjs +70 -0
- package/dist/structured-format/StructuredFormat.test.mjs.map +1 -0
- package/dist/testing/MockMusicGenerator.d.mts +39 -0
- package/dist/testing/MockMusicGenerator.d.mts.map +1 -0
- package/dist/testing/MockMusicGenerator.mjs +96 -0
- package/dist/testing/MockMusicGenerator.mjs.map +1 -0
- package/dist/testing/MockProvider.d.mts +23 -18
- package/dist/testing/MockProvider.d.mts.map +1 -1
- package/dist/testing/MockProvider.mjs +56 -72
- package/dist/testing/MockProvider.mjs.map +1 -1
- package/dist/testing/MockSpeechSynthesizer.d.mts +37 -0
- package/dist/testing/MockSpeechSynthesizer.d.mts.map +1 -0
- package/dist/testing/MockSpeechSynthesizer.mjs +95 -0
- package/dist/testing/MockSpeechSynthesizer.mjs.map +1 -0
- package/dist/testing/MockTranscriber.d.mts +37 -0
- package/dist/testing/MockTranscriber.d.mts.map +1 -0
- package/dist/testing/MockTranscriber.mjs +77 -0
- package/dist/testing/MockTranscriber.mjs.map +1 -0
- package/dist/tool/HistoryCheck.d.mts +1 -1
- package/dist/tool/Outcome.d.mts +1 -1
- package/dist/tool/Resolvers.d.mts +65 -8
- package/dist/tool/Resolvers.d.mts.map +1 -1
- package/dist/tool/Resolvers.mjs +8 -12
- package/dist/tool/Resolvers.mjs.map +1 -1
- package/dist/tool/Resolvers.test.mjs +6 -5
- package/dist/tool/Resolvers.test.mjs.map +1 -1
- package/dist/tool/Tool.d.mts +2 -2
- package/dist/tool/Tool.mjs +18 -1
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/Tool.test.d.mts +1 -0
- package/dist/tool/Tool.test.mjs +66 -0
- package/dist/tool/Tool.test.mjs.map +1 -0
- package/dist/tool/Toolkit.d.mts +4 -6
- package/dist/tool/Toolkit.d.mts.map +1 -1
- package/dist/tool/Toolkit.mjs +14 -43
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/transcriber/Transcriber.d.mts +101 -0
- package/dist/transcriber/Transcriber.d.mts.map +1 -0
- package/dist/transcriber/Transcriber.mjs +49 -0
- package/dist/transcriber/Transcriber.mjs.map +1 -0
- package/dist/transcriber/Transcriber.test.d.mts +1 -0
- package/dist/transcriber/Transcriber.test.mjs +130 -0
- package/dist/transcriber/Transcriber.test.mjs.map +1 -0
- package/package.json +37 -1
- package/src/domain/AiError.ts +22 -1
- package/src/domain/Audio.ts +88 -0
- package/src/domain/Items.ts +1 -1
- package/src/domain/Music.ts +121 -0
- package/src/domain/Transcript.ts +83 -0
- package/src/domain/Turn.test.ts +141 -0
- package/src/domain/Turn.ts +50 -43
- package/src/embedding-model/Embedding.ts +23 -0
- package/src/embedding-model/EmbeddingModel.test.ts +92 -0
- package/src/embedding-model/EmbeddingModel.ts +30 -20
- package/src/index.ts +6 -0
- package/src/language-model/LanguageModel.test.ts +170 -0
- package/src/language-model/LanguageModel.ts +64 -1
- package/src/loop/Loop.test.ts +256 -3
- package/src/loop/Loop.ts +225 -49
- package/src/music-generator/MusicGenerator.test.ts +170 -0
- package/src/music-generator/MusicGenerator.ts +123 -0
- package/src/observability/Metrics.ts +1 -1
- package/src/speech-synthesizer/SpeechSynthesizer.test.ts +141 -0
- package/src/speech-synthesizer/SpeechSynthesizer.ts +131 -0
- package/src/streaming/JSONL.ts +16 -13
- package/src/structured-format/StructuredFormat.test.ts +105 -0
- package/src/structured-format/StructuredFormat.ts +14 -1
- package/src/testing/MockMusicGenerator.ts +168 -0
- package/src/testing/MockProvider.ts +126 -105
- package/src/testing/MockSpeechSynthesizer.ts +163 -0
- package/src/testing/MockTranscriber.ts +137 -0
- package/src/tool/Resolvers.test.ts +8 -5
- package/src/tool/Resolvers.ts +17 -19
- package/src/tool/Tool.test.ts +105 -0
- package/src/tool/Tool.ts +20 -0
- package/src/tool/Toolkit.ts +49 -50
- package/src/transcriber/Transcriber.test.ts +125 -0
- package/src/transcriber/Transcriber.ts +127 -0
- package/dist/StructuredFormat-BWq5Hd1O.d.mts.map +0 -1
- package/dist/Tool-DjVufH7i.d.mts.map +0 -1
- package/dist/Turn-OPaILVIB.d.mts +0 -194
- package/dist/Turn-OPaILVIB.d.mts.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { r as AudioFormat, t as AudioBlob } from "../Audio-BfCTGnH3.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/domain/Music.d.ts
|
|
4
|
+
declare namespace Music_d_exports {
|
|
5
|
+
export { CommonGenerateMusicRequest, CommonStreamGenerateMusicRequest, MusicResult, MusicSessionInput, WeightedPrompt, configInput, controlInput, isConfigInput, isControlInput, isPromptsInput, promptsInput };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Prompt fragment with a relative weight. Native to Lyria RealTime
|
|
9
|
+
* (`{ text, weight }` pairs blended in the model). Single-prompt
|
|
10
|
+
* providers (Suno, Mureka, MiniMax) flatten to text at the adapter
|
|
11
|
+
* layer.
|
|
12
|
+
*/
|
|
13
|
+
type WeightedPrompt = {
|
|
14
|
+
readonly text: string; /** Default `1.0`. Range typically `[0, 1]`; provider-dependent. */
|
|
15
|
+
readonly weight?: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Cross-provider music-generation request. Provider-specific extras
|
|
19
|
+
* (Lyria `mode`, ElevenLabs `composition_plan`, Suno custom-mode `title`,
|
|
20
|
+
* MiniMax `lyrics_optimizer`) live on each provider's typed request
|
|
21
|
+
* which extends this and narrows `model`.
|
|
22
|
+
*/
|
|
23
|
+
type CommonGenerateMusicRequest = {
|
|
24
|
+
/** Model identifier. Each provider narrows. */readonly model: string; /** Single prompt string or weighted-prompt list (blended where supported). */
|
|
25
|
+
readonly prompts: string | ReadonlyArray<WeightedPrompt>;
|
|
26
|
+
/**
|
|
27
|
+
* Lyrics text, optionally with section tags like `[Verse]` / `[Chorus]` /
|
|
28
|
+
* `[Bridge]` / `[Outro]`. Ignored for instrumental-only providers or
|
|
29
|
+
* when `instrumental: true`.
|
|
30
|
+
*/
|
|
31
|
+
readonly lyrics?: string; /** Target duration in seconds. Provider may treat as a hint or hard limit. */
|
|
32
|
+
readonly durationSeconds?: number; /** Beats per minute (60–200 typical). */
|
|
33
|
+
readonly bpm?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Musical key/mode hint. Provider-specific vocabulary (e.g. Lyria
|
|
36
|
+
* RealTime uses enum values like `"C_MAJOR"`, `"A_MINOR"`).
|
|
37
|
+
*/
|
|
38
|
+
readonly scale?: string; /** Skip vocals / lyrics. */
|
|
39
|
+
readonly instrumental?: boolean; /** Preferred output format. Provider may override. */
|
|
40
|
+
readonly outputFormat?: AudioFormat;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Streamed-output request. Same shape as the sync request — the
|
|
44
|
+
* streaming variant only differs in how the response is delivered.
|
|
45
|
+
*/
|
|
46
|
+
type CommonStreamGenerateMusicRequest = CommonGenerateMusicRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Bidirectional-session input. The user pushes one of these per
|
|
49
|
+
* change: a new prompt blend, a config delta, or a playback control.
|
|
50
|
+
* Lyria RealTime is the only provider currently surfacing these.
|
|
51
|
+
*/
|
|
52
|
+
type MusicSessionInput = {
|
|
53
|
+
readonly _tag: "prompts";
|
|
54
|
+
readonly prompts: ReadonlyArray<WeightedPrompt>;
|
|
55
|
+
} | {
|
|
56
|
+
readonly _tag: "config";
|
|
57
|
+
readonly config: {
|
|
58
|
+
readonly bpm?: number;
|
|
59
|
+
readonly scale?: string;
|
|
60
|
+
readonly density?: number;
|
|
61
|
+
readonly brightness?: number;
|
|
62
|
+
readonly guidance?: number;
|
|
63
|
+
readonly temperature?: number;
|
|
64
|
+
readonly topK?: number;
|
|
65
|
+
readonly seed?: number;
|
|
66
|
+
readonly muteBass?: boolean;
|
|
67
|
+
readonly muteDrums?: boolean;
|
|
68
|
+
readonly onlyBassAndDrums?: boolean;
|
|
69
|
+
};
|
|
70
|
+
} | {
|
|
71
|
+
readonly _tag: "control";
|
|
72
|
+
readonly action: "play" | "pause" | "stop" | "reset_context";
|
|
73
|
+
};
|
|
74
|
+
declare const promptsInput: (prompts: ReadonlyArray<WeightedPrompt>) => MusicSessionInput;
|
|
75
|
+
declare const configInput: (config: (MusicSessionInput & {
|
|
76
|
+
_tag: "config";
|
|
77
|
+
})["config"]) => MusicSessionInput;
|
|
78
|
+
declare const controlInput: (action: (MusicSessionInput & {
|
|
79
|
+
_tag: "control";
|
|
80
|
+
})["action"]) => MusicSessionInput;
|
|
81
|
+
/**
|
|
82
|
+
* Sync-generation result. Extends `AudioBlob` with provider-side
|
|
83
|
+
* metadata that's common across music providers:
|
|
84
|
+
*
|
|
85
|
+
* - `songId` — Suno task id, ElevenLabs `song_id`, etc. Used for
|
|
86
|
+
* back-reference (re-download, stem export, follow-up edits).
|
|
87
|
+
* - `lyrics` — generated lyrics when the model returned them (Lyria
|
|
88
|
+
* text part, Mureka, Suno).
|
|
89
|
+
* - `sections` — structured section markers (Lyria optional JSON
|
|
90
|
+
* structure response).
|
|
91
|
+
* - `watermark` — presence marker (Lyria SynthID is always set).
|
|
92
|
+
*/
|
|
93
|
+
type MusicResult = AudioBlob & {
|
|
94
|
+
readonly songId?: string;
|
|
95
|
+
readonly lyrics?: string;
|
|
96
|
+
readonly sections?: ReadonlyArray<{
|
|
97
|
+
readonly label: string;
|
|
98
|
+
readonly startSeconds: number;
|
|
99
|
+
readonly endSeconds: number;
|
|
100
|
+
}>;
|
|
101
|
+
readonly watermark?: {
|
|
102
|
+
readonly kind: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
declare const isPromptsInput: (i: MusicSessionInput) => i is MusicSessionInput & {
|
|
106
|
+
_tag: "prompts";
|
|
107
|
+
};
|
|
108
|
+
declare const isConfigInput: (i: MusicSessionInput) => i is MusicSessionInput & {
|
|
109
|
+
_tag: "config";
|
|
110
|
+
};
|
|
111
|
+
declare const isControlInput: (i: MusicSessionInput) => i is MusicSessionInput & {
|
|
112
|
+
_tag: "control";
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { CommonGenerateMusicRequest, CommonStreamGenerateMusicRequest, MusicResult, MusicSessionInput, WeightedPrompt, configInput, controlInput, isConfigInput, isControlInput, isPromptsInput, promptsInput, Music_d_exports as t };
|
|
116
|
+
//# sourceMappingURL=Music.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Music.d.mts","names":[],"sources":["../../src/domain/Music.ts"],"mappings":";;;;;;;;;;;;KAQY,cAAA;EAAA,SACD,IAAA;WAEA,MAAA;AAAA;;;;;;AAHX;KAYY,0BAAA;0DAED,KAAA,UAXM;EAAA,SAaN,OAAA,WAAkB,aAAA,CAAc,cAAA;EAJL;;;;;EAAA,SAU3B,MAAA,WAa0B;EAAA,SAX1B,eAAA,WARA;EAAA,SAUA,GAAA;EAVgC;;;;EAAA,SAehC,KAAA,WAEA;EAAA,SAAA,YAAA,YAEe;EAAA,SAAf,YAAA,GAAe,WAAA;AAAA;AAO1B;;;;AAAA,KAAY,gCAAA,GAAmC,0BAAA;AAO/C;;;;;AAAA,KAAY,iBAAA;EAAA,SACG,IAAA;EAAA,SAA0B,OAAA,EAAS,aAAA,CAAc,cAAA;AAAA;EAAA,SAEjD,IAAA;EAAA,SACA,MAAA;IAAA,SACE,GAAA;IAAA,SACA,KAAA;IAAA,SACA,OAAA;IAAA,SACA,UAAA;IAAA,SACA,QAAA;IAAA,SACA,WAAA;IAAA,SACA,IAAA;IAAA,SACA,IAAA;IAAA,SACA,QAAA;IAAA,SACA,SAAA;IAAA,SACA,gBAAA;EAAA;AAAA;EAAA,SAGF,IAAA;EAAA,SAA0B,MAAA;AAAA;AAAA,cAE5B,YAAA,GAAgB,OAAA,EAAS,aAAA,CAAc,cAAA,MAAkB,iBAAA;AAAA,cAKzD,WAAA,GACX,MAAA,GAAS,iBAAA;EAAsB,IAAA;AAAA,iBAC9B,iBAAA;AAAA,cAEU,YAAA,GACX,MAAA,GAAS,iBAAA;EAAsB,IAAA;AAAA,iBAC9B,iBAAA;;;;;;AANH;;;;;;;KAoBY,WAAA,GAAc,SAAA;EAAA,SACf,MAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,GAAW,aAAA;IAAA,SACT,KAAA;IAAA,SACA,YAAA;IAAA,SACA,UAAA;EAAA;EAAA,SAEF,SAAA;IAAA,SAAuB,IAAA;EAAA;AAAA;AAAA,cAGrB,cAAA,GACX,CAAA,EAAG,iBAAA,KACF,CAAA,IAAK,iBAAA;EAAsB,IAAA;AAAA;AAAA,cACjB,aAAA,GAAiB,CAAA,EAAG,iBAAA,KAAoB,CAAA,IAAK,iBAAA;EAAsB,IAAA;AAAA;AAAA,cAEnE,cAAA,GACX,CAAA,EAAG,iBAAA,KACF,CAAA,IAAK,iBAAA;EAAsB,IAAA;AAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
//#region src/domain/Music.ts
|
|
3
|
+
var Music_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
configInput: () => configInput,
|
|
5
|
+
controlInput: () => controlInput,
|
|
6
|
+
isConfigInput: () => isConfigInput,
|
|
7
|
+
isControlInput: () => isControlInput,
|
|
8
|
+
isPromptsInput: () => isPromptsInput,
|
|
9
|
+
promptsInput: () => promptsInput
|
|
10
|
+
});
|
|
11
|
+
const promptsInput = (prompts) => ({
|
|
12
|
+
_tag: "prompts",
|
|
13
|
+
prompts
|
|
14
|
+
});
|
|
15
|
+
const configInput = (config) => ({
|
|
16
|
+
_tag: "config",
|
|
17
|
+
config
|
|
18
|
+
});
|
|
19
|
+
const controlInput = (action) => ({
|
|
20
|
+
_tag: "control",
|
|
21
|
+
action
|
|
22
|
+
});
|
|
23
|
+
const isPromptsInput = (i) => i._tag === "prompts";
|
|
24
|
+
const isConfigInput = (i) => i._tag === "config";
|
|
25
|
+
const isControlInput = (i) => i._tag === "control";
|
|
26
|
+
//#endregion
|
|
27
|
+
export { configInput, controlInput, isConfigInput, isControlInput, isPromptsInput, promptsInput, Music_exports as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=Music.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Music.mjs","names":[],"sources":["../../src/domain/Music.ts"],"sourcesContent":["import type { AudioBlob, AudioFormat } from \"./Audio.js\"\n\n/**\n * Prompt fragment with a relative weight. Native to Lyria RealTime\n * (`{ text, weight }` pairs blended in the model). Single-prompt\n * providers (Suno, Mureka, MiniMax) flatten to text at the adapter\n * layer.\n */\nexport type WeightedPrompt = {\n readonly text: string\n /** Default `1.0`. Range typically `[0, 1]`; provider-dependent. */\n readonly weight?: number\n}\n\n/**\n * Cross-provider music-generation request. Provider-specific extras\n * (Lyria `mode`, ElevenLabs `composition_plan`, Suno custom-mode `title`,\n * MiniMax `lyrics_optimizer`) live on each provider's typed request\n * which extends this and narrows `model`.\n */\nexport type CommonGenerateMusicRequest = {\n /** Model identifier. Each provider narrows. */\n readonly model: string\n /** Single prompt string or weighted-prompt list (blended where supported). */\n readonly prompts: string | ReadonlyArray<WeightedPrompt>\n /**\n * Lyrics text, optionally with section tags like `[Verse]` / `[Chorus]` /\n * `[Bridge]` / `[Outro]`. Ignored for instrumental-only providers or\n * when `instrumental: true`.\n */\n readonly lyrics?: string\n /** Target duration in seconds. Provider may treat as a hint or hard limit. */\n readonly durationSeconds?: number\n /** Beats per minute (60–200 typical). */\n readonly bpm?: number\n /**\n * Musical key/mode hint. Provider-specific vocabulary (e.g. Lyria\n * RealTime uses enum values like `\"C_MAJOR\"`, `\"A_MINOR\"`).\n */\n readonly scale?: string\n /** Skip vocals / lyrics. */\n readonly instrumental?: boolean\n /** Preferred output format. Provider may override. */\n readonly outputFormat?: AudioFormat\n}\n\n/**\n * Streamed-output request. Same shape as the sync request — the\n * streaming variant only differs in how the response is delivered.\n */\nexport type CommonStreamGenerateMusicRequest = CommonGenerateMusicRequest\n\n/**\n * Bidirectional-session input. The user pushes one of these per\n * change: a new prompt blend, a config delta, or a playback control.\n * Lyria RealTime is the only provider currently surfacing these.\n */\nexport type MusicSessionInput =\n | { readonly _tag: \"prompts\"; readonly prompts: ReadonlyArray<WeightedPrompt> }\n | {\n readonly _tag: \"config\"\n readonly config: {\n readonly bpm?: number\n readonly scale?: string\n readonly density?: number\n readonly brightness?: number\n readonly guidance?: number\n readonly temperature?: number\n readonly topK?: number\n readonly seed?: number\n readonly muteBass?: boolean\n readonly muteDrums?: boolean\n readonly onlyBassAndDrums?: boolean\n }\n }\n | { readonly _tag: \"control\"; readonly action: \"play\" | \"pause\" | \"stop\" | \"reset_context\" }\n\nexport const promptsInput = (prompts: ReadonlyArray<WeightedPrompt>): MusicSessionInput => ({\n _tag: \"prompts\",\n prompts,\n})\n\nexport const configInput = (\n config: (MusicSessionInput & { _tag: \"config\" })[\"config\"],\n): MusicSessionInput => ({ _tag: \"config\", config })\n\nexport const controlInput = (\n action: (MusicSessionInput & { _tag: \"control\" })[\"action\"],\n): MusicSessionInput => ({ _tag: \"control\", action })\n\n/**\n * Sync-generation result. Extends `AudioBlob` with provider-side\n * metadata that's common across music providers:\n *\n * - `songId` — Suno task id, ElevenLabs `song_id`, etc. Used for\n * back-reference (re-download, stem export, follow-up edits).\n * - `lyrics` — generated lyrics when the model returned them (Lyria\n * text part, Mureka, Suno).\n * - `sections` — structured section markers (Lyria optional JSON\n * structure response).\n * - `watermark` — presence marker (Lyria SynthID is always set).\n */\nexport type MusicResult = AudioBlob & {\n readonly songId?: string\n readonly lyrics?: string\n readonly sections?: ReadonlyArray<{\n readonly label: string\n readonly startSeconds: number\n readonly endSeconds: number\n }>\n readonly watermark?: { readonly kind: string }\n}\n\nexport const isPromptsInput = (\n i: MusicSessionInput,\n): i is MusicSessionInput & { _tag: \"prompts\" } => i._tag === \"prompts\"\nexport const isConfigInput = (i: MusicSessionInput): i is MusicSessionInput & { _tag: \"config\" } =>\n i._tag === \"config\"\nexport const isControlInput = (\n i: MusicSessionInput,\n): i is MusicSessionInput & { _tag: \"control\" } => i._tag === \"control\"\n"],"mappings":";;;;;;;;;;AA6EA,MAAa,gBAAgB,aAA+D;CAC1F,MAAM;CACN;CACD;AAED,MAAa,eACX,YACuB;CAAE,MAAM;CAAU;CAAQ;AAEnD,MAAa,gBACX,YACuB;CAAE,MAAM;CAAW;CAAQ;AAyBpD,MAAa,kBACX,MACiD,EAAE,SAAS;AAC9D,MAAa,iBAAiB,MAC5B,EAAE,SAAS;AACb,MAAa,kBACX,MACiD,EAAE,SAAS"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
declare namespace Transcript_d_exports {
|
|
2
|
+
export { TranscriptEvent, TranscriptResult, WordTimestamp, isAudioEvent, isError, isFinal, isMetadata, isPartial, isSpeechStarted, isUtteranceEnded };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Per-word timing + metadata. `confidence` and `speakerId` are optional
|
|
6
|
+
* because providers vary widely in what they emit and when (some only on
|
|
7
|
+
* final, some only with diarization enabled, some not at all).
|
|
8
|
+
*/
|
|
9
|
+
type WordTimestamp = {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly startSeconds: number;
|
|
12
|
+
readonly endSeconds: number;
|
|
13
|
+
readonly confidence?: number;
|
|
14
|
+
readonly speakerId?: string;
|
|
15
|
+
readonly languageCode?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Sync STT result. `raw` preserves the provider-specific response for
|
|
19
|
+
* consumers that need fields the common shape doesn't expose
|
|
20
|
+
* (alternatives, segments, NBest, audio events, etc.).
|
|
21
|
+
*/
|
|
22
|
+
type TranscriptResult = {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly languageCode?: string;
|
|
25
|
+
readonly durationSeconds?: number;
|
|
26
|
+
readonly words?: ReadonlyArray<WordTimestamp>;
|
|
27
|
+
readonly raw?: unknown;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Streaming STT event union. Collapses every provider's vocabulary into
|
|
31
|
+
* a small set; provider-specific shapes survive on `metadata.raw`.
|
|
32
|
+
*
|
|
33
|
+
* - `partial`: interim hypothesis. `stability` is Google-only.
|
|
34
|
+
* - `final`: committed transcript for the current utterance / segment.
|
|
35
|
+
* - `speech-started` / `utterance-ended`: VAD-derived boundaries. Not
|
|
36
|
+
* all providers emit them (OpenAI Realtime, Google with
|
|
37
|
+
* `voice_activity_events`, Deepgram with `vad_events`, AssemblyAI).
|
|
38
|
+
* - `audio-event`: non-speech label (`(laughter)`, `(music)`) — ElevenLabs only.
|
|
39
|
+
* - `metadata`: opaque server-side bookkeeping (request_id, model info).
|
|
40
|
+
* - `error`: non-fatal provider error mid-stream. Fatal errors surface
|
|
41
|
+
* on the `Stream`'s error channel as `AiError.AiError`.
|
|
42
|
+
*/
|
|
43
|
+
type TranscriptEvent = {
|
|
44
|
+
readonly _tag: "partial";
|
|
45
|
+
readonly text: string;
|
|
46
|
+
readonly words?: ReadonlyArray<WordTimestamp>;
|
|
47
|
+
readonly stability?: number;
|
|
48
|
+
} | {
|
|
49
|
+
readonly _tag: "final";
|
|
50
|
+
readonly text: string;
|
|
51
|
+
readonly words?: ReadonlyArray<WordTimestamp>;
|
|
52
|
+
readonly languageCode?: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly _tag: "speech-started";
|
|
55
|
+
readonly atSeconds: number;
|
|
56
|
+
} | {
|
|
57
|
+
readonly _tag: "utterance-ended";
|
|
58
|
+
readonly atSeconds: number;
|
|
59
|
+
} | {
|
|
60
|
+
readonly _tag: "audio-event";
|
|
61
|
+
readonly label: string;
|
|
62
|
+
readonly startSeconds: number;
|
|
63
|
+
readonly endSeconds: number;
|
|
64
|
+
} | {
|
|
65
|
+
readonly _tag: "metadata";
|
|
66
|
+
readonly raw: unknown;
|
|
67
|
+
} | {
|
|
68
|
+
readonly _tag: "error";
|
|
69
|
+
readonly code?: string;
|
|
70
|
+
readonly message: string;
|
|
71
|
+
};
|
|
72
|
+
declare const isPartial: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
73
|
+
_tag: "partial";
|
|
74
|
+
}>;
|
|
75
|
+
declare const isFinal: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
76
|
+
_tag: "final";
|
|
77
|
+
}>;
|
|
78
|
+
declare const isSpeechStarted: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
79
|
+
_tag: "speech-started";
|
|
80
|
+
}>;
|
|
81
|
+
declare const isUtteranceEnded: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
82
|
+
_tag: "utterance-ended";
|
|
83
|
+
}>;
|
|
84
|
+
declare const isAudioEvent: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
85
|
+
_tag: "audio-event";
|
|
86
|
+
}>;
|
|
87
|
+
declare const isMetadata: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
88
|
+
_tag: "metadata";
|
|
89
|
+
}>;
|
|
90
|
+
declare const isError: (e: TranscriptEvent) => e is Extract<TranscriptEvent, {
|
|
91
|
+
_tag: "error";
|
|
92
|
+
}>;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { TranscriptEvent, TranscriptResult, WordTimestamp, isAudioEvent, isError, isFinal, isMetadata, isPartial, isSpeechStarted, isUtteranceEnded, Transcript_d_exports as t };
|
|
95
|
+
//# sourceMappingURL=Transcript.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transcript.d.mts","names":[],"sources":["../../src/domain/Transcript.ts"],"mappings":";;;;;;;;KAKY,aAAA;EAAA,SACD,IAAA;EAAA,SACA,YAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA;EAAA,SACA,SAAA;EAAA,SACA,YAAA;AAAA;;;AANX;;;KAcY,gBAAA;EAAA,SACD,IAAA;EAAA,SACA,YAAA;EAAA,SACA,eAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;EAAA,SACtB,GAAA;AAAA;;;AALX;;;;;;;;;;;;KAsBY,eAAA;EAAA,SAEG,IAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;EAAA,SACtB,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;EAAA,SACtB,YAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAAiC,SAAA;AAAA;EAAA,SACjC,IAAA;EAAA,SAAkC,SAAA;AAAA;EAAA,SAElC,IAAA;EAAA,SACA,KAAA;EAAA,SACA,YAAA;EAAA,SACA,UAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAA2B,GAAA;AAAA;EAAA,SAC3B,IAAA;EAAA,SAAwB,IAAA;EAAA,SAAwB,OAAA;AAAA;AAAA,cAElD,SAAA,GAAa,CAAA,EAAG,eAAA,KAAkB,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cAElE,OAAA,GAAW,CAAA,EAAG,eAAA,KAAkB,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cAEhE,eAAA,GACX,CAAA,EAAG,eAAA,KACF,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cACtB,gBAAA,GACX,CAAA,EAAG,eAAA,KACF,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cACtB,YAAA,GACX,CAAA,EAAG,eAAA,KACF,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cACtB,UAAA,GACX,CAAA,EAAG,eAAA,KACF,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA;AAAA,cACtB,OAAA,GAAW,CAAA,EAAG,eAAA,KAAkB,CAAA,IAAK,OAAA,CAAQ,eAAA;EAAmB,IAAA;AAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
//#region src/domain/Transcript.ts
|
|
3
|
+
var Transcript_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
isAudioEvent: () => isAudioEvent,
|
|
5
|
+
isError: () => isError,
|
|
6
|
+
isFinal: () => isFinal,
|
|
7
|
+
isMetadata: () => isMetadata,
|
|
8
|
+
isPartial: () => isPartial,
|
|
9
|
+
isSpeechStarted: () => isSpeechStarted,
|
|
10
|
+
isUtteranceEnded: () => isUtteranceEnded
|
|
11
|
+
});
|
|
12
|
+
const isPartial = (e) => e._tag === "partial";
|
|
13
|
+
const isFinal = (e) => e._tag === "final";
|
|
14
|
+
const isSpeechStarted = (e) => e._tag === "speech-started";
|
|
15
|
+
const isUtteranceEnded = (e) => e._tag === "utterance-ended";
|
|
16
|
+
const isAudioEvent = (e) => e._tag === "audio-event";
|
|
17
|
+
const isMetadata = (e) => e._tag === "metadata";
|
|
18
|
+
const isError = (e) => e._tag === "error";
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isAudioEvent, isError, isFinal, isMetadata, isPartial, isSpeechStarted, isUtteranceEnded, Transcript_exports as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=Transcript.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transcript.mjs","names":[],"sources":["../../src/domain/Transcript.ts"],"sourcesContent":["/**\n * Per-word timing + metadata. `confidence` and `speakerId` are optional\n * because providers vary widely in what they emit and when (some only on\n * final, some only with diarization enabled, some not at all).\n */\nexport type WordTimestamp = {\n readonly text: string\n readonly startSeconds: number\n readonly endSeconds: number\n readonly confidence?: number\n readonly speakerId?: string\n readonly languageCode?: string\n}\n\n/**\n * Sync STT result. `raw` preserves the provider-specific response for\n * consumers that need fields the common shape doesn't expose\n * (alternatives, segments, NBest, audio events, etc.).\n */\nexport type TranscriptResult = {\n readonly text: string\n readonly languageCode?: string\n readonly durationSeconds?: number\n readonly words?: ReadonlyArray<WordTimestamp>\n readonly raw?: unknown\n}\n\n/**\n * Streaming STT event union. Collapses every provider's vocabulary into\n * a small set; provider-specific shapes survive on `metadata.raw`.\n *\n * - `partial`: interim hypothesis. `stability` is Google-only.\n * - `final`: committed transcript for the current utterance / segment.\n * - `speech-started` / `utterance-ended`: VAD-derived boundaries. Not\n * all providers emit them (OpenAI Realtime, Google with\n * `voice_activity_events`, Deepgram with `vad_events`, AssemblyAI).\n * - `audio-event`: non-speech label (`(laughter)`, `(music)`) — ElevenLabs only.\n * - `metadata`: opaque server-side bookkeeping (request_id, model info).\n * - `error`: non-fatal provider error mid-stream. Fatal errors surface\n * on the `Stream`'s error channel as `AiError.AiError`.\n */\nexport type TranscriptEvent =\n | {\n readonly _tag: \"partial\"\n readonly text: string\n readonly words?: ReadonlyArray<WordTimestamp>\n readonly stability?: number\n }\n | {\n readonly _tag: \"final\"\n readonly text: string\n readonly words?: ReadonlyArray<WordTimestamp>\n readonly languageCode?: string\n }\n | { readonly _tag: \"speech-started\"; readonly atSeconds: number }\n | { readonly _tag: \"utterance-ended\"; readonly atSeconds: number }\n | {\n readonly _tag: \"audio-event\"\n readonly label: string\n readonly startSeconds: number\n readonly endSeconds: number\n }\n | { readonly _tag: \"metadata\"; readonly raw: unknown }\n | { readonly _tag: \"error\"; readonly code?: string; readonly message: string }\n\nexport const isPartial = (e: TranscriptEvent): e is Extract<TranscriptEvent, { _tag: \"partial\" }> =>\n e._tag === \"partial\"\nexport const isFinal = (e: TranscriptEvent): e is Extract<TranscriptEvent, { _tag: \"final\" }> =>\n e._tag === \"final\"\nexport const isSpeechStarted = (\n e: TranscriptEvent,\n): e is Extract<TranscriptEvent, { _tag: \"speech-started\" }> => e._tag === \"speech-started\"\nexport const isUtteranceEnded = (\n e: TranscriptEvent,\n): e is Extract<TranscriptEvent, { _tag: \"utterance-ended\" }> => e._tag === \"utterance-ended\"\nexport const isAudioEvent = (\n e: TranscriptEvent,\n): e is Extract<TranscriptEvent, { _tag: \"audio-event\" }> => e._tag === \"audio-event\"\nexport const isMetadata = (\n e: TranscriptEvent,\n): e is Extract<TranscriptEvent, { _tag: \"metadata\" }> => e._tag === \"metadata\"\nexport const isError = (e: TranscriptEvent): e is Extract<TranscriptEvent, { _tag: \"error\" }> =>\n e._tag === \"error\"\n"],"mappings":";;;;;;;;;;;AAiEA,MAAa,aAAa,MACxB,EAAE,SAAS;AACb,MAAa,WAAW,MACtB,EAAE,SAAS;AACb,MAAa,mBACX,MAC8D,EAAE,SAAS;AAC3E,MAAa,oBACX,MAC+D,EAAE,SAAS;AAC5E,MAAa,gBACX,MAC2D,EAAE,SAAS;AACxE,MAAa,cACX,MACwD,EAAE,SAAS;AACrE,MAAa,WAAW,MACtB,EAAE,SAAS"}
|
package/dist/domain/Turn.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
export { InteractionEvent, RefusalRejected, Turn, TurnEvent, appendTurn, assistantMessages, functionCalls, isTurnComplete, reasonings, textDeltas, toStructured };
|
|
1
|
+
import { c as assistantText, d as isTurnComplete, f as reasonings, i as TurnEvent, l as assistantTexts, m as toStructured, n as RefusalRejected, o as appendTurn, p as textDeltas, r as Turn, s as assistantMessages, t as InteractionEvent, u as functionCalls } from "../Turn-ChbL2foc.mjs";
|
|
2
|
+
export { InteractionEvent, RefusalRejected, Turn, TurnEvent, appendTurn, assistantMessages, assistantText, assistantTexts, functionCalls, isTurnComplete, reasonings, textDeltas, toStructured };
|
package/dist/domain/Turn.mjs
CHANGED
|
@@ -6,8 +6,11 @@ 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
|
+
TurnEvent: () => TurnEvent,
|
|
9
10
|
appendTurn: () => appendTurn,
|
|
10
11
|
assistantMessages: () => assistantMessages,
|
|
12
|
+
assistantText: () => assistantText,
|
|
13
|
+
assistantTexts: () => assistantTexts,
|
|
11
14
|
functionCalls: () => functionCalls,
|
|
12
15
|
isTurnComplete: () => isTurnComplete,
|
|
13
16
|
reasonings: () => reasonings,
|
|
@@ -24,11 +27,26 @@ const Turn = Schema.Struct({
|
|
|
24
27
|
usage: Usage,
|
|
25
28
|
stop_reason: StopReason
|
|
26
29
|
});
|
|
27
|
-
const
|
|
30
|
+
const TurnEvent = Data.taggedEnum();
|
|
31
|
+
const isTurnComplete = TurnEvent.$is("TurnComplete");
|
|
28
32
|
const functionCalls = (turn) => turn.items.filter((i) => i.type === "function_call");
|
|
29
33
|
const reasonings = (turn) => turn.items.filter((i) => i.type === "reasoning");
|
|
30
34
|
const assistantMessages = (turn) => turn.items.filter((i) => i.type === "message" && i.role === "assistant");
|
|
31
35
|
/**
|
|
36
|
+
* Every `output_text` payload across every assistant message in the turn,
|
|
37
|
+
* preserving order. Refusals and other content blocks are dropped — use
|
|
38
|
+
* `assistantMessages` if you need to inspect them. The primitive for
|
|
39
|
+
* "give me the assistant's text"; callers decide how to combine
|
|
40
|
+
* (typically `.join("")` for prose or `.join(" ")` for log strings).
|
|
41
|
+
*/
|
|
42
|
+
const assistantTexts = (turn) => assistantMessages(turn).flatMap((m) => m.content).filter(isOutputText).map((b) => b.text);
|
|
43
|
+
/**
|
|
44
|
+
* Sugar over `assistantTexts(turn).join("")` — the common case for
|
|
45
|
+
* summarizers, classifiers, judge calls, and structured-output backstops
|
|
46
|
+
* that want one concatenated string.
|
|
47
|
+
*/
|
|
48
|
+
const assistantText = (turn) => assistantTexts(turn).join("");
|
|
49
|
+
/**
|
|
32
50
|
* Append a completed turn and optional follow-up items to a state record's
|
|
33
51
|
* history. Recipes use this at the point where structured tool results are
|
|
34
52
|
* converted to model-facing `FunctionCallOutput`s.
|
|
@@ -42,11 +60,11 @@ const appendTurn = (state, turn, items = []) => ({
|
|
|
42
60
|
]
|
|
43
61
|
});
|
|
44
62
|
/**
|
|
45
|
-
* Project a `TurnEvent` stream onto its `
|
|
63
|
+
* Project a `TurnEvent` stream onto its `TextDelta` payloads. Other
|
|
46
64
|
* variants are dropped. Composes with `Lines.lines` +
|
|
47
65
|
* `decodeJsonLines` for prompted-JSONL streaming.
|
|
48
66
|
*/
|
|
49
|
-
const textDeltas = (self) => self.pipe(Stream.filterMap((ev) => ev.
|
|
67
|
+
const textDeltas = (self) => self.pipe(Stream.filterMap((ev) => ev._tag === "TextDelta" ? Result.succeed(ev.text) : Result.failVoid));
|
|
50
68
|
/**
|
|
51
69
|
* The assistant message on the just-completed turn was a refusal block,
|
|
52
70
|
* not an `output_text` payload. Returned by `toStructured` to short-circuit
|
|
@@ -81,6 +99,6 @@ const lastAssistantContent = (turn) => {
|
|
|
81
99
|
*/
|
|
82
100
|
const toStructured = (turn, format) => pipe(lastAssistantContent(turn), ({ text, refused }) => refused ? Effect.fail(new RefusalRejected({ turn })) : parseJson(format)(text));
|
|
83
101
|
//#endregion
|
|
84
|
-
export { RefusalRejected, Turn, appendTurn, assistantMessages, functionCalls, isTurnComplete, reasonings, Turn_exports as t, textDeltas, toStructured };
|
|
102
|
+
export { RefusalRejected, Turn, TurnEvent, appendTurn, assistantMessages, assistantText, assistantTexts, functionCalls, isTurnComplete, reasonings, Turn_exports as t, textDeltas, toStructured };
|
|
85
103
|
|
|
86
104
|
//# 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 `
|
|
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 `TurnComplete` carries the assembled `Turn`. Lifecycle members\n * aren't deltas, hence the union name.\n *\n * `ReasoningDelta.kind`: `trace` is the model's raw chain-of-thought;\n * `summary` is a model-written summary intended for display. OpenAI\n * Responses emits both; Anthropic and Gemini only emit `trace`.\n *\n * `RefusalDelta`: the model declined to answer. OpenAI Responses emits\n * this as its own event; Anthropic surfaces refusals via `stop_reason`\n * and Gemini collapses them into `finishReason: SAFETY` — both go\n * without a `RefusalDelta`.\n *\n * `UsageUpdate`: mid-stream cumulative usage. Anthropic emits this on\n * `message_start` and `message_delta`; other providers may only deliver\n * usage via `TurnComplete.turn.usage`.\n */\nexport type TurnEvent = Data.TaggedEnum<{\n TextDelta: { readonly text: string }\n ReasoningDelta: { readonly text: string; readonly kind: \"trace\" | \"summary\" }\n RefusalDelta: { readonly text: string }\n ToolCallStart: { readonly call_id: string; readonly name: string }\n ToolCallArgsDelta: { readonly call_id: string; readonly delta: string }\n UsageUpdate: { readonly usage: Usage }\n TurnComplete: { readonly turn: Turn }\n}>\n\nexport const TurnEvent = Data.taggedEnum<TurnEvent>()\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 `TurnComplete`\n * carrying the assembled `Turn`), plus the output of any tool the loop ran.\n * Both variants carry a `_tag` discriminator.\n */\nexport type InteractionEvent = TurnEvent | FunctionCallOutput\n\nexport const isTurnComplete = TurnEvent.$is(\"TurnComplete\")\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 * Every `output_text` payload across every assistant message in the turn,\n * preserving order. Refusals and other content blocks are dropped — use\n * `assistantMessages` if you need to inspect them. The primitive for\n * \"give me the assistant's text\"; callers decide how to combine\n * (typically `.join(\"\")` for prose or `.join(\" \")` for log strings).\n */\nexport const assistantTexts = (turn: Turn): ReadonlyArray<string> =>\n assistantMessages(turn)\n .flatMap((m) => m.content)\n .filter(isOutputText)\n .map((b) => b.text)\n\n/**\n * Sugar over `assistantTexts(turn).join(\"\")` — the common case for\n * summarizers, classifiers, judge calls, and structured-output backstops\n * that want one concatenated string.\n */\nexport const assistantText = (turn: Turn): string => assistantTexts(turn).join(\"\")\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 `TextDelta` 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) => (ev._tag === \"TextDelta\" ? Result.succeed(ev.text) : Result.failVoid)),\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;AAgCF,MAAa,YAAY,KAAK,YAAuB;AAUrD,MAAa,iBAAiB,UAAU,IAAI,eAAe;AAE3D,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;;;;;;;;AASxF,MAAa,kBAAkB,SAC7B,kBAAkB,KAAK,CACpB,SAAS,MAAM,EAAE,QAAQ,CACzB,OAAO,aAAa,CACpB,KAAK,MAAM,EAAE,KAAK;;;;;;AAOvB,MAAa,iBAAiB,SAAuB,eAAe,KAAK,CAAC,KAAK,GAAG;;;;;;AAOlF,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,OAAQ,GAAG,SAAS,cAAc,OAAO,QAAQ,GAAG,KAAK,GAAG,OAAO,SAAU,CAChG;;;;;;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 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { assistantText, systemText, userText } from "./Items.mjs";
|
|
2
|
+
import { assistantText as assistantText$1, assistantTexts } from "./Turn.mjs";
|
|
3
|
+
import { i as it, n as globalExpect, r as describe } from "../dist-DV5ISja1.mjs";
|
|
4
|
+
//#region src/domain/Turn.test.ts
|
|
5
|
+
const turnOf = (items) => ({
|
|
6
|
+
items,
|
|
7
|
+
usage: {
|
|
8
|
+
input_tokens: 0,
|
|
9
|
+
output_tokens: 0
|
|
10
|
+
},
|
|
11
|
+
stop_reason: "stop"
|
|
12
|
+
});
|
|
13
|
+
describe("Turn.assistantTexts", () => {
|
|
14
|
+
it("returns each output_text block in order across a single assistant message", () => {
|
|
15
|
+
globalExpect(assistantTexts(turnOf([{
|
|
16
|
+
type: "message",
|
|
17
|
+
role: "assistant",
|
|
18
|
+
content: [{
|
|
19
|
+
type: "output_text",
|
|
20
|
+
text: "first"
|
|
21
|
+
}, {
|
|
22
|
+
type: "output_text",
|
|
23
|
+
text: "second"
|
|
24
|
+
}]
|
|
25
|
+
}]))).toEqual(["first", "second"]);
|
|
26
|
+
});
|
|
27
|
+
it("preserves order across multiple assistant messages", () => {
|
|
28
|
+
globalExpect(assistantTexts(turnOf([
|
|
29
|
+
assistantText("alpha"),
|
|
30
|
+
assistantText("beta"),
|
|
31
|
+
assistantText("gamma")
|
|
32
|
+
]))).toEqual([
|
|
33
|
+
"alpha",
|
|
34
|
+
"beta",
|
|
35
|
+
"gamma"
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
it("drops refusal blocks and non-assistant messages", () => {
|
|
39
|
+
globalExpect(assistantTexts(turnOf([userText("ignored"), {
|
|
40
|
+
type: "message",
|
|
41
|
+
role: "assistant",
|
|
42
|
+
content: [{
|
|
43
|
+
type: "output_text",
|
|
44
|
+
text: "kept"
|
|
45
|
+
}, {
|
|
46
|
+
type: "refusal",
|
|
47
|
+
text: "I can't help with that."
|
|
48
|
+
}]
|
|
49
|
+
}]))).toEqual(["kept"]);
|
|
50
|
+
});
|
|
51
|
+
it("returns an empty array when there's nothing to extract", () => {
|
|
52
|
+
globalExpect(assistantTexts(turnOf([]))).toEqual([]);
|
|
53
|
+
globalExpect(assistantTexts(turnOf([userText("only user")]))).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
it("composes with caller-chosen separators", () => {
|
|
56
|
+
const turn = turnOf([assistantText("hello"), assistantText("world")]);
|
|
57
|
+
globalExpect(assistantTexts(turn).join("")).toBe("helloworld");
|
|
58
|
+
globalExpect(assistantTexts(turn).join(" ")).toBe("hello world");
|
|
59
|
+
globalExpect(assistantTexts(turn).join("\n")).toBe("hello\nworld");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("Turn.assistantText", () => {
|
|
63
|
+
it("concatenates output_text across a single assistant message's content blocks", () => {
|
|
64
|
+
globalExpect(assistantText$1(turnOf([{
|
|
65
|
+
type: "message",
|
|
66
|
+
role: "assistant",
|
|
67
|
+
content: [{
|
|
68
|
+
type: "output_text",
|
|
69
|
+
text: "hello "
|
|
70
|
+
}, {
|
|
71
|
+
type: "output_text",
|
|
72
|
+
text: "world"
|
|
73
|
+
}]
|
|
74
|
+
}]))).toBe("hello world");
|
|
75
|
+
});
|
|
76
|
+
it("concatenates output_text across multiple assistant messages", () => {
|
|
77
|
+
globalExpect(assistantText$1(turnOf([assistantText("first "), assistantText("second")]))).toBe("first second");
|
|
78
|
+
});
|
|
79
|
+
it("ignores non-assistant messages", () => {
|
|
80
|
+
globalExpect(assistantText$1(turnOf([
|
|
81
|
+
userText("ignored"),
|
|
82
|
+
systemText("also ignored"),
|
|
83
|
+
assistantText("kept")
|
|
84
|
+
]))).toBe("kept");
|
|
85
|
+
});
|
|
86
|
+
it("ignores non-output_text content blocks (refusals, etc.)", () => {
|
|
87
|
+
globalExpect(assistantText$1(turnOf([{
|
|
88
|
+
type: "message",
|
|
89
|
+
role: "assistant",
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: "output_text",
|
|
93
|
+
text: "before "
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: "refusal",
|
|
97
|
+
text: "I can't help with that."
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: "output_text",
|
|
101
|
+
text: "after"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}]))).toBe("before after");
|
|
105
|
+
});
|
|
106
|
+
it("ignores function_call items even when interleaved with messages", () => {
|
|
107
|
+
globalExpect(assistantText$1(turnOf([
|
|
108
|
+
assistantText("text "),
|
|
109
|
+
{
|
|
110
|
+
type: "function_call",
|
|
111
|
+
call_id: "c1",
|
|
112
|
+
name: "search",
|
|
113
|
+
arguments: "{}"
|
|
114
|
+
},
|
|
115
|
+
assistantText("more text")
|
|
116
|
+
]))).toBe("text more text");
|
|
117
|
+
});
|
|
118
|
+
it("returns the empty string when no assistant messages exist", () => {
|
|
119
|
+
globalExpect(assistantText$1(turnOf([]))).toBe("");
|
|
120
|
+
globalExpect(assistantText$1(turnOf([userText("only user")]))).toBe("");
|
|
121
|
+
});
|
|
122
|
+
it("returns the empty string when the assistant message has no output_text blocks", () => {
|
|
123
|
+
globalExpect(assistantText$1(turnOf([{
|
|
124
|
+
type: "message",
|
|
125
|
+
role: "assistant",
|
|
126
|
+
content: [{
|
|
127
|
+
type: "refusal",
|
|
128
|
+
text: "I can't help."
|
|
129
|
+
}]
|
|
130
|
+
}]))).toBe("");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
//#endregion
|
|
134
|
+
export {};
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=Turn.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Turn.test.mjs","names":["Turn.assistantTexts","Items.assistantText","Items.userText","Turn.assistantText","Items.systemText"],"sources":["../../src/domain/Turn.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\"\nimport * as Items from \"./Items.js\"\nimport * as Turn from \"./Turn.js\"\n\nconst turnOf = (items: Turn.Turn[\"items\"]): Turn.Turn => ({\n items,\n usage: { input_tokens: 0, output_tokens: 0 },\n stop_reason: \"stop\",\n})\n\ndescribe(\"Turn.assistantTexts\", () => {\n it(\"returns each output_text block in order across a single assistant message\", () => {\n const turn = turnOf([\n {\n type: \"message\",\n role: \"assistant\",\n content: [\n { type: \"output_text\", text: \"first\" },\n { type: \"output_text\", text: \"second\" },\n ],\n },\n ])\n\n expect(Turn.assistantTexts(turn)).toEqual([\"first\", \"second\"])\n })\n\n it(\"preserves order across multiple assistant messages\", () => {\n const turn = turnOf([\n Items.assistantText(\"alpha\"),\n Items.assistantText(\"beta\"),\n Items.assistantText(\"gamma\"),\n ])\n\n expect(Turn.assistantTexts(turn)).toEqual([\"alpha\", \"beta\", \"gamma\"])\n })\n\n it(\"drops refusal blocks and non-assistant messages\", () => {\n const turn = turnOf([\n Items.userText(\"ignored\"),\n {\n type: \"message\",\n role: \"assistant\",\n content: [\n { type: \"output_text\", text: \"kept\" },\n { type: \"refusal\", text: \"I can't help with that.\" },\n ],\n },\n ])\n\n expect(Turn.assistantTexts(turn)).toEqual([\"kept\"])\n })\n\n it(\"returns an empty array when there's nothing to extract\", () => {\n expect(Turn.assistantTexts(turnOf([]))).toEqual([])\n expect(Turn.assistantTexts(turnOf([Items.userText(\"only user\")]))).toEqual([])\n })\n\n it(\"composes with caller-chosen separators\", () => {\n const turn = turnOf([Items.assistantText(\"hello\"), Items.assistantText(\"world\")])\n\n expect(Turn.assistantTexts(turn).join(\"\")).toBe(\"helloworld\")\n expect(Turn.assistantTexts(turn).join(\" \")).toBe(\"hello world\")\n expect(Turn.assistantTexts(turn).join(\"\\n\")).toBe(\"hello\\nworld\")\n })\n})\n\ndescribe(\"Turn.assistantText\", () => {\n it(\"concatenates output_text across a single assistant message's content blocks\", () => {\n const turn = turnOf([\n {\n type: \"message\",\n role: \"assistant\",\n content: [\n { type: \"output_text\", text: \"hello \" },\n { type: \"output_text\", text: \"world\" },\n ],\n },\n ])\n\n expect(Turn.assistantText(turn)).toBe(\"hello world\")\n })\n\n it(\"concatenates output_text across multiple assistant messages\", () => {\n const turn = turnOf([Items.assistantText(\"first \"), Items.assistantText(\"second\")])\n\n expect(Turn.assistantText(turn)).toBe(\"first second\")\n })\n\n it(\"ignores non-assistant messages\", () => {\n const turn = turnOf([\n Items.userText(\"ignored\"),\n Items.systemText(\"also ignored\"),\n Items.assistantText(\"kept\"),\n ])\n\n expect(Turn.assistantText(turn)).toBe(\"kept\")\n })\n\n it(\"ignores non-output_text content blocks (refusals, etc.)\", () => {\n const turn = turnOf([\n {\n type: \"message\",\n role: \"assistant\",\n content: [\n { type: \"output_text\", text: \"before \" },\n { type: \"refusal\", text: \"I can't help with that.\" },\n { type: \"output_text\", text: \"after\" },\n ],\n },\n ])\n\n expect(Turn.assistantText(turn)).toBe(\"before after\")\n })\n\n it(\"ignores function_call items even when interleaved with messages\", () => {\n const turn = turnOf([\n Items.assistantText(\"text \"),\n { type: \"function_call\", call_id: \"c1\", name: \"search\", arguments: \"{}\" },\n Items.assistantText(\"more text\"),\n ])\n\n expect(Turn.assistantText(turn)).toBe(\"text more text\")\n })\n\n it(\"returns the empty string when no assistant messages exist\", () => {\n expect(Turn.assistantText(turnOf([]))).toBe(\"\")\n expect(Turn.assistantText(turnOf([Items.userText(\"only user\")]))).toBe(\"\")\n })\n\n it(\"returns the empty string when the assistant message has no output_text blocks\", () => {\n const turn = turnOf([\n {\n type: \"message\",\n role: \"assistant\",\n content: [{ type: \"refusal\", text: \"I can't help.\" }],\n },\n ])\n\n expect(Turn.assistantText(turn)).toBe(\"\")\n })\n})\n"],"mappings":";;;;AAIA,MAAM,UAAU,WAA0C;CACxD;CACA,OAAO;EAAE,cAAc;EAAG,eAAe;EAAG;CAC5C,aAAa;CACd;AAED,SAAS,6BAA6B;AACpC,IAAG,mFAAmF;AAYpF,eAAOA,eAXM,OAAO,CAClB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CACP;IAAE,MAAM;IAAe,MAAM;IAAS,EACtC;IAAE,MAAM;IAAe,MAAM;IAAU,CACxC;GACF,CACF,CAE0B,CAAK,CAAC,CAAC,QAAQ,CAAC,SAAS,SAAS,CAAC;GAC9D;AAEF,IAAG,4DAA4D;AAO7D,eAAOA,eANM,OAAO;GAClBC,cAAoB,QAAQ;GAC5BA,cAAoB,OAAO;GAC3BA,cAAoB,QAAQ;GAC7B,CAE0B,CAAK,CAAC,CAAC,QAAQ;GAAC;GAAS;GAAQ;GAAQ,CAAC;GACrE;AAEF,IAAG,yDAAyD;AAa1D,eAAOD,eAZM,OAAO,CAClBE,SAAe,UAAU,EACzB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CACP;IAAE,MAAM;IAAe,MAAM;IAAQ,EACrC;IAAE,MAAM;IAAW,MAAM;IAA2B,CACrD;GACF,CACF,CAE0B,CAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;GACnD;AAEF,IAAG,gEAAgE;AACjE,eAAOF,eAAoB,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AACnD,eAAOA,eAAoB,OAAO,CAACE,SAAe,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;GAC9E;AAEF,IAAG,gDAAgD;EACjD,MAAM,OAAO,OAAO,CAACD,cAAoB,QAAQ,EAAEA,cAAoB,QAAQ,CAAC,CAAC;AAEjF,eAAOD,eAAoB,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,aAAa;AAC7D,eAAOA,eAAoB,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,cAAc;AAC/D,eAAOA,eAAoB,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,eAAe;GACjE;EACF;AAEF,SAAS,4BAA4B;AACnC,IAAG,qFAAqF;AAYtF,eAAOG,gBAXM,OAAO,CAClB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CACP;IAAE,MAAM;IAAe,MAAM;IAAU,EACvC;IAAE,MAAM;IAAe,MAAM;IAAS,CACvC;GACF,CACF,CAEyB,CAAK,CAAC,CAAC,KAAK,cAAc;GACpD;AAEF,IAAG,qEAAqE;AAGtE,eAAOA,gBAFM,OAAO,CAACF,cAAoB,SAAS,EAAEA,cAAoB,SAAS,CAAC,CAExD,CAAK,CAAC,CAAC,KAAK,eAAe;GACrD;AAEF,IAAG,wCAAwC;AAOzC,eAAOE,gBANM,OAAO;GAClBD,SAAe,UAAU;GACzBE,WAAiB,eAAe;GAChCH,cAAoB,OAAO;GAC5B,CAEyB,CAAK,CAAC,CAAC,KAAK,OAAO;GAC7C;AAEF,IAAG,iEAAiE;AAalE,eAAOE,gBAZM,OAAO,CAClB;GACE,MAAM;GACN,MAAM;GACN,SAAS;IACP;KAAE,MAAM;KAAe,MAAM;KAAW;IACxC;KAAE,MAAM;KAAW,MAAM;KAA2B;IACpD;KAAE,MAAM;KAAe,MAAM;KAAS;IACvC;GACF,CACF,CAEyB,CAAK,CAAC,CAAC,KAAK,eAAe;GACrD;AAEF,IAAG,yEAAyE;AAO1E,eAAOA,gBANM,OAAO;GAClBF,cAAoB,QAAQ;GAC5B;IAAE,MAAM;IAAiB,SAAS;IAAM,MAAM;IAAU,WAAW;IAAM;GACzEA,cAAoB,YAAY;GACjC,CAEyB,CAAK,CAAC,CAAC,KAAK,iBAAiB;GACvD;AAEF,IAAG,mEAAmE;AACpE,eAAOE,gBAAmB,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;AAC/C,eAAOA,gBAAmB,OAAO,CAACD,SAAe,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;GAC1E;AAEF,IAAG,uFAAuF;AASxF,eAAOC,gBARM,OAAO,CAClB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CAAC;IAAE,MAAM;IAAW,MAAM;IAAiB,CAAC;GACtD,CACF,CAEyB,CAAK,CAAC,CAAC,KAAK,GAAG;GACzC;EACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { i as ImageSource } from "../Image-
|
|
1
|
+
import { i as ImageSource } from "../Image-HNmMpMTh.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/embedding-model/Embedding.d.ts
|
|
4
4
|
declare namespace Embedding_d_exports {
|
|
5
|
-
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse };
|
|
5
|
+
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, EmbeddingFor, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse };
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* One part of a mixed text+image input. Used inside `EmbedInput.content[]`
|
|
@@ -94,6 +94,18 @@ declare const isInt8: (e: Embedding) => e is Int8Embedding;
|
|
|
94
94
|
declare const isBinary: (e: Embedding) => e is BinaryEmbedding;
|
|
95
95
|
declare const isSparse: (e: Embedding) => e is SparseEmbedding;
|
|
96
96
|
declare const isMultivector: (e: Embedding) => e is MultivectorEmbedding;
|
|
97
|
+
/**
|
|
98
|
+
* Maps an `encoding` request field to the corresponding response embedding
|
|
99
|
+
* variant. `undefined` (no encoding requested) defaults to `Float32Embedding`,
|
|
100
|
+
* which is what every provider returns when the caller doesn't ask for
|
|
101
|
+
* anything else. Widened `E` falls back to the full `Embedding` union — the
|
|
102
|
+
* caller has to narrow at use site, which honestly reflects what they know
|
|
103
|
+
* at compile time.
|
|
104
|
+
*
|
|
105
|
+
* Used by `EmbedResponse<E>` / `EmbedManyResponse<E>` to give callers a
|
|
106
|
+
* precise embedding type without a runtime narrowing helper.
|
|
107
|
+
*/
|
|
108
|
+
type EmbeddingFor<E> = [E] extends [undefined | "float32"] ? Float32Embedding : [E] extends ["int8"] ? Int8Embedding : [E] extends ["binary"] ? BinaryEmbedding : [E] extends ["sparse"] ? SparseEmbedding : [E] extends ["multivector"] ? MultivectorEmbedding : Embedding;
|
|
97
109
|
/**
|
|
98
110
|
* Token usage for one embed / embedMany call. One value per HTTP request,
|
|
99
111
|
* not per input vector. Most providers populate `inputTokens`; the field
|
|
@@ -103,5 +115,5 @@ type Usage = {
|
|
|
103
115
|
readonly inputTokens?: number;
|
|
104
116
|
};
|
|
105
117
|
//#endregion
|
|
106
|
-
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse, Embedding_d_exports as t };
|
|
118
|
+
export { BinaryEmbedding, EmbedContentPart, EmbedInput, Embedding, EmbeddingFor, Float32Embedding, Int8Embedding, MultivectorEmbedding, SparseEmbedding, Usage, isBinary, isFloat32, isInt8, isMultivector, isSparse, Embedding_d_exports as t };
|
|
107
119
|
//# sourceMappingURL=Embedding.d.mts.map
|
|
@@ -1 +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
|
|
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;;;;;;;;;KAwBY,YAAA,OAAmB,CAAA,oCAC3B,gBAAA,IACC,CAAA,qBACC,aAAA,IACC,CAAA,uBACC,eAAA,IACC,CAAA,uBACC,eAAA,IACC,CAAA,4BACC,oBAAA,GACA,SAAA;;;;;;KAOA,KAAA;EAAA,SACD,WAAA;AAAA"}
|