@effect-uai/core 0.2.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 +1 -1
- 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-Bi83du4I.d.mts → Turn-OPaILVIB.d.mts} +5 -11
- 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 +1 -1
- package/dist/domain/Turn.mjs +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 +15 -7
- 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 +31 -7
- package/dist/loop/Loop.d.mts.map +1 -1
- 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 +32 -10
- package/dist/tool/Outcome.mjs.map +1 -1
- package/dist/tool/Resolvers.d.mts +11 -8
- package/dist/tool/Resolvers.d.mts.map +1 -1
- package/dist/tool/Resolvers.mjs +10 -1
- 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 +19 -10
- package/dist/tool/Toolkit.d.mts.map +1 -1
- package/dist/tool/Toolkit.mjs +5 -5
- 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/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 +36 -36
- package/src/tool/Resolvers.test.ts +11 -35
- package/src/tool/Resolvers.ts +5 -14
- package/src/tool/Tool.ts +9 -9
- package/src/tool/ToolEvent.ts +28 -24
- package/src/tool/Toolkit.test.ts +97 -2
- package/src/tool/Toolkit.ts +57 -33
- package/dist/Items-D1C2686t.d.mts.map +0 -1
- package/dist/Outcome-GiaNvt7i.d.mts +0 -32
- package/dist/Outcome-GiaNvt7i.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-wTMgb2GO.d.mts +0 -29
- package/dist/ToolEvent-wTMgb2GO.d.mts.map +0 -1
- package/dist/Turn-Bi83du4I.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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ImageSource } from "../domain/Image.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One part of a mixed text+image input. Used inside `EmbedInput.content[]`
|
|
5
|
+
* for providers that accept interleaved modalities in a single embed call
|
|
6
|
+
* (Cohere v4, Voyage multimodal, Jina v4, Google `gemini-embedding-2`).
|
|
7
|
+
*/
|
|
8
|
+
export type EmbedContentPart = { readonly text: string } | { readonly image: ImageSource }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What you embed. The `string` shorthand covers the common text-only case;
|
|
12
|
+
* structured variants exist for image-only and mixed-modality inputs.
|
|
13
|
+
*
|
|
14
|
+
* Not every provider accepts every variant: text-only providers (OpenAI,
|
|
15
|
+
* Mixedbread today) handle `string` and `{ text }`; multimodal providers
|
|
16
|
+
* (Google, Jina v4, Voyage multimodal, Cohere v4) handle all four. A
|
|
17
|
+
* provider layer rejects shapes it can't encode as `AiError.InvalidRequest`.
|
|
18
|
+
*/
|
|
19
|
+
export type EmbedInput =
|
|
20
|
+
| string
|
|
21
|
+
| { readonly text: string }
|
|
22
|
+
| { readonly image: ImageSource }
|
|
23
|
+
| { readonly content: ReadonlyArray<EmbedContentPart> }
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Embedding representations
|
|
27
|
+
//
|
|
28
|
+
// The `_tag` reflects the wire form the provider returned, *not* what the
|
|
29
|
+
// consumer asked for - request `encoding: "int8"` and you get back an
|
|
30
|
+
// `Int8Embedding`. Math primitives are typed against the named interfaces
|
|
31
|
+
// (see `Vector.ts`) so e.g. `sparseCosine` only accepts `SparseEmbedding`.
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/** Dense float32 vector. The default representation across all providers. */
|
|
35
|
+
export type Float32Embedding = {
|
|
36
|
+
readonly _tag: "float32"
|
|
37
|
+
readonly vector: Float32Array
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Dense int8-quantized vector. ~4x smaller than float32 with minimal
|
|
42
|
+
* recall loss on most benchmarks.
|
|
43
|
+
*/
|
|
44
|
+
export type Int8Embedding = {
|
|
45
|
+
readonly _tag: "int8"
|
|
46
|
+
readonly vector: Int8Array
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dense binary-quantized vector. One bit per dimension, packed into bytes.
|
|
51
|
+
* ~32x smaller than float32; meaningful recall loss but useful for hot
|
|
52
|
+
* indexes paired with a float32 reranker pass.
|
|
53
|
+
*/
|
|
54
|
+
export type BinaryEmbedding = {
|
|
55
|
+
readonly _tag: "binary"
|
|
56
|
+
readonly vector: Uint8Array
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Sparse vector. Token-keyed weights for hybrid search (dense + lexical-
|
|
61
|
+
* style sparse). The single hosted producer today is Jina's `elser-v2`
|
|
62
|
+
* model, which returns subword tokens (e.g. `"bread"`, `"##ing"`) with
|
|
63
|
+
* their relevance weights.
|
|
64
|
+
*
|
|
65
|
+
* The shape is `Record<string, number>` rather than `(indices, values)`
|
|
66
|
+
* because real hosted learned-sparse encoders (ELSER, SPLADE) emit token
|
|
67
|
+
* strings with no shared vocabulary index. Converting to integer indices
|
|
68
|
+
* would either need a vocabulary table the model doesn't expose, or
|
|
69
|
+
* lose the cross-vector matching semantics. If a provider ever exposes
|
|
70
|
+
* index-valued sparse vectors (Pinecone-style, where you bring your own
|
|
71
|
+
* vocab), add an `IndexSparseEmbedding` sibling arm with `_tag:
|
|
72
|
+
* "sparse-indexed"`.
|
|
73
|
+
*
|
|
74
|
+
* Score with `Vector.sparseCosine` — dot product over the intersection
|
|
75
|
+
* of keys, normalized by the L2 norms of both maps.
|
|
76
|
+
*/
|
|
77
|
+
export type SparseEmbedding = {
|
|
78
|
+
readonly _tag: "sparse"
|
|
79
|
+
readonly weights: Readonly<Record<string, number>>
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Multivector / late-interaction output: one float32 vector per token.
|
|
84
|
+
* Score documents with `Vector.maxSim` (ColBERT-style: per query vector,
|
|
85
|
+
* max dot product across doc vectors, summed). Typically ~50-500 vectors
|
|
86
|
+
* per document, each shorter than a single-vector embedding (~128 dim
|
|
87
|
+
* vs ~1024).
|
|
88
|
+
*
|
|
89
|
+
* Quantized multivector forms aren't modeled for the same reason as
|
|
90
|
+
* sparse - nothing on hosted APIs ships them yet.
|
|
91
|
+
*/
|
|
92
|
+
export type MultivectorEmbedding = {
|
|
93
|
+
readonly _tag: "multivector"
|
|
94
|
+
readonly vectors: ReadonlyArray<Float32Array>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type Embedding =
|
|
98
|
+
| Float32Embedding
|
|
99
|
+
| Int8Embedding
|
|
100
|
+
| BinaryEmbedding
|
|
101
|
+
| SparseEmbedding
|
|
102
|
+
| MultivectorEmbedding
|
|
103
|
+
|
|
104
|
+
export const isFloat32 = (e: Embedding): e is Float32Embedding => e._tag === "float32"
|
|
105
|
+
export const isInt8 = (e: Embedding): e is Int8Embedding => e._tag === "int8"
|
|
106
|
+
export const isBinary = (e: Embedding): e is BinaryEmbedding => e._tag === "binary"
|
|
107
|
+
export const isSparse = (e: Embedding): e is SparseEmbedding => e._tag === "sparse"
|
|
108
|
+
export const isMultivector = (e: Embedding): e is MultivectorEmbedding => e._tag === "multivector"
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Token usage for one embed / embedMany call. One value per HTTP request,
|
|
112
|
+
* not per input vector. Most providers populate `inputTokens`; the field
|
|
113
|
+
* is optional for those that don't (or for mock layers in tests).
|
|
114
|
+
*/
|
|
115
|
+
export type Usage = {
|
|
116
|
+
readonly inputTokens?: number
|
|
117
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Context, Effect } from "effect"
|
|
2
|
+
import * as AiError from "../domain/AiError.js"
|
|
3
|
+
import type { Embedding, EmbedInput, Usage } from "./Embedding.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Output representation requested from the provider.
|
|
7
|
+
*
|
|
8
|
+
* Dense quantizations - same vector at different storage cost:
|
|
9
|
+
* - `float32` — universal default.
|
|
10
|
+
* - `int8` — ~4x smaller; minimal recall loss on most benchmarks.
|
|
11
|
+
* - `binary` — ~32x smaller; meaningful recall loss but pairs well with
|
|
12
|
+
* a float32 reranker pass over a small candidate set.
|
|
13
|
+
*
|
|
14
|
+
* Non-dense representations:
|
|
15
|
+
* - `sparse` — learned sparse vector for hybrid (dense + lexical) search.
|
|
16
|
+
* Currently Jina ELSER only on hosted APIs.
|
|
17
|
+
* - `multivector` — one vector per token for late-interaction (ColBERT-
|
|
18
|
+
* style) scoring via `Vector.maxSim`. Currently Jina v4 only.
|
|
19
|
+
*
|
|
20
|
+
* Each provider's typed request narrows this to its supported set at
|
|
21
|
+
* compile time (e.g. `JinaEncoding = "float32" | "binary" | "sparse" |
|
|
22
|
+
* "multivector"`). On the generic `EmbeddingModel` path, callers can
|
|
23
|
+
* pass any `Encoding` and the provider's API will reject mismatches at
|
|
24
|
+
* runtime.
|
|
25
|
+
*/
|
|
26
|
+
export type Encoding = "float32" | "int8" | "binary" | "sparse" | "multivector"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cross-provider single-embed request. Mirrors the shape of
|
|
30
|
+
* `LanguageModel.CommonRequest`: cross-cutting fields here, vendor
|
|
31
|
+
* specifics in the provider's typed request.
|
|
32
|
+
*
|
|
33
|
+
* Provider-specific extensions (Cohere widened `task` enum, Jina LoRA
|
|
34
|
+
* tasks, Mixedbread free-form `prompt`, etc.) live in that provider's own
|
|
35
|
+
* request interface, which extends this and narrows `model` / widens
|
|
36
|
+
* `task`.
|
|
37
|
+
*/
|
|
38
|
+
export type CommonEmbedRequest = {
|
|
39
|
+
readonly input: EmbedInput
|
|
40
|
+
/**
|
|
41
|
+
* Model identifier. Each provider narrows this to its typed literal
|
|
42
|
+
* union, so code that yields a typed provider tag gets autocompletion.
|
|
43
|
+
*/
|
|
44
|
+
readonly model: string
|
|
45
|
+
/**
|
|
46
|
+
* Retrieval-task hint. Applies to the input. OpenAI ignores this;
|
|
47
|
+
* Mixedbread doesn't have it; Cohere v3+ requires it on the wire (typed
|
|
48
|
+
* as required in `CohereEmbedRequest`). Provider-specific task enums
|
|
49
|
+
* (classification, clustering, code retrieval, …) live on the
|
|
50
|
+
* provider's own request type.
|
|
51
|
+
*/
|
|
52
|
+
readonly task?: "query" | "document"
|
|
53
|
+
/**
|
|
54
|
+
* Matryoshka truncation. Default: provider's native dimension.
|
|
55
|
+
* Discrete-value providers (Cohere, Vertex `multimodalembedding@001`)
|
|
56
|
+
* narrow this to a literal union in their typed request.
|
|
57
|
+
*/
|
|
58
|
+
readonly dimensions?: number
|
|
59
|
+
/**
|
|
60
|
+
* Output representation - see {@link Encoding}. Dense float32 is the
|
|
61
|
+
* default; provider layers reject unsupported values up front with
|
|
62
|
+
* `InvalidRequest`.
|
|
63
|
+
*/
|
|
64
|
+
readonly encoding?: Encoding
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Cross-provider batch-embed request. One `task` for the whole batch -
|
|
69
|
+
* mixed-task batches aren't a real provider feature (rerankers exist for
|
|
70
|
+
* that).
|
|
71
|
+
*/
|
|
72
|
+
export type CommonEmbedManyRequest = Omit<CommonEmbedRequest, "input"> & {
|
|
73
|
+
readonly inputs: ReadonlyArray<EmbedInput>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type EmbedResponse = {
|
|
77
|
+
readonly embedding: Embedding
|
|
78
|
+
readonly usage: Usage
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type EmbedManyResponse = {
|
|
82
|
+
readonly embeddings: ReadonlyArray<Embedding>
|
|
83
|
+
readonly usage: Usage
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type EmbeddingModelService = {
|
|
87
|
+
readonly embed: (request: CommonEmbedRequest) => Effect.Effect<EmbedResponse, AiError.AiError>
|
|
88
|
+
readonly embedMany: (
|
|
89
|
+
request: CommonEmbedManyRequest,
|
|
90
|
+
) => Effect.Effect<EmbedManyResponse, AiError.AiError>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class EmbeddingModel extends Context.Service<EmbeddingModel, EmbeddingModelService>()(
|
|
94
|
+
"@betalyra/effect-uai/EmbeddingModel",
|
|
95
|
+
) {}
|
|
96
|
+
|
|
97
|
+
/** Embed a single input. */
|
|
98
|
+
export const embed = (
|
|
99
|
+
request: CommonEmbedRequest,
|
|
100
|
+
): Effect.Effect<EmbedResponse, AiError.AiError, EmbeddingModel> =>
|
|
101
|
+
Effect.flatMap(EmbeddingModel.asEffect(), (m) => m.embed(request))
|
|
102
|
+
|
|
103
|
+
/** Embed a batch in one provider call. Same `task` for every input. */
|
|
104
|
+
export const embedMany = (
|
|
105
|
+
request: CommonEmbedManyRequest,
|
|
106
|
+
): Effect.Effect<EmbedManyResponse, AiError.AiError, EmbeddingModel> =>
|
|
107
|
+
Effect.flatMap(EmbeddingModel.asEffect(), (m) => m.embedMany(request))
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
export * as AiError from "./domain/AiError.js"
|
|
2
|
+
export * as Image from "./domain/Image.js"
|
|
2
3
|
export * as Items from "./domain/Items.js"
|
|
4
|
+
export * as Media from "./domain/Media.js"
|
|
3
5
|
export * as Turn from "./domain/Turn.js"
|
|
6
|
+
export * as Embedding from "./embedding-model/Embedding.js"
|
|
7
|
+
export * as EmbeddingModel from "./embedding-model/EmbeddingModel.js"
|
|
4
8
|
export * as LanguageModel from "./language-model/LanguageModel.js"
|
|
9
|
+
export * as Vector from "./math/Vector.js"
|
|
5
10
|
export * as Loop from "./loop/Loop.js"
|
|
6
|
-
export * as Match from "./match/Match.js"
|
|
7
11
|
export * as Tool from "./tool/Tool.js"
|
|
8
12
|
export * as Toolkit from "./tool/Toolkit.js"
|
|
13
|
+
export * as Outcome from "./tool/Outcome.js"
|
|
14
|
+
export * as ToolEvent from "./tool/ToolEvent.js"
|
|
15
|
+
export * as Resolvers from "./tool/Resolvers.js"
|
|
16
|
+
export * as HistoryCheck from "./tool/HistoryCheck.js"
|
|
9
17
|
export * as JSONL from "./streaming/JSONL.js"
|
|
10
18
|
export * as Lines from "./streaming/Lines.js"
|
|
11
19
|
export * as SSE from "./streaming/SSE.js"
|
|
@@ -11,7 +11,7 @@ import { isTurnComplete, type Turn, type TurnEvent } from "../domain/Turn.js"
|
|
|
11
11
|
* to a single provider (reasoning effort, prompt caching, store flags,
|
|
12
12
|
* ...) lives in that provider's own request interface, which extends this.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export type CommonRequest = {
|
|
15
15
|
readonly history: ReadonlyArray<Item>
|
|
16
16
|
/**
|
|
17
17
|
* Model identifier. Each provider narrows this to its typed literal union,
|
|
@@ -36,7 +36,7 @@ export interface CommonRequest {
|
|
|
36
36
|
readonly structured?: StructuredFormat.StructuredFormat<unknown>
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export
|
|
39
|
+
export type LanguageModelService = {
|
|
40
40
|
readonly streamTurn: (request: CommonRequest) => Stream.Stream<TurnEvent, AiError.AiError>
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -51,23 +51,3 @@ export const streamTurn = (
|
|
|
51
51
|
request: CommonRequest,
|
|
52
52
|
): Stream.Stream<TurnEvent, AiError.AiError, LanguageModel> =>
|
|
53
53
|
Stream.unwrap(Effect.map(LanguageModel.asEffect(), (m) => m.streamTurn(request)))
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Run a single turn to completion and return the assembled `Turn`.
|
|
57
|
-
*
|
|
58
|
-
* Implementation: drain the delta stream and pluck the terminal
|
|
59
|
-
* `turn_complete` event. The provider is contractually required to emit
|
|
60
|
-
* exactly one such event as the last delta.
|
|
61
|
-
*/
|
|
62
|
-
export const turn = (request: CommonRequest): Effect.Effect<Turn, AiError.AiError, LanguageModel> =>
|
|
63
|
-
Effect.flatMap(Stream.runCollect(streamTurn(request)), (deltas) => {
|
|
64
|
-
const last = deltas[deltas.length - 1]
|
|
65
|
-
return last !== undefined && isTurnComplete(last)
|
|
66
|
-
? Effect.succeed(last.turn)
|
|
67
|
-
: Effect.fail(
|
|
68
|
-
new AiError.Unavailable({
|
|
69
|
-
provider: "unknown",
|
|
70
|
-
raw: "Provider stream ended without a turn_complete event",
|
|
71
|
-
}),
|
|
72
|
-
)
|
|
73
|
-
})
|
package/src/loop/Loop.test.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { Deferred, Effect, Fiber, Ref, Stream } from "effect"
|
|
1
|
+
import { Deferred, Effect, Fiber, Latch, Ref, Stream, SubscriptionRef } from "effect"
|
|
2
2
|
import { describe, expect, it } from "vitest"
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type Event,
|
|
5
|
+
loop,
|
|
6
|
+
loopWithState,
|
|
7
|
+
next,
|
|
8
|
+
nextAfter,
|
|
9
|
+
stopEvent,
|
|
10
|
+
stopAfter,
|
|
11
|
+
value,
|
|
12
|
+
} from "./Loop.js"
|
|
4
13
|
|
|
5
14
|
describe("Loop.loop", () => {
|
|
6
15
|
it("threads state across iterations and emits each iteration's substream in order", async () => {
|
|
@@ -410,3 +419,106 @@ describe("Loop.loop - pull-specific stream semantics", () => {
|
|
|
410
419
|
expect(result._tag).toBe("Failure")
|
|
411
420
|
})
|
|
412
421
|
})
|
|
422
|
+
|
|
423
|
+
describe("Loop.loopWithState", () => {
|
|
424
|
+
it("exposes the final state in the SubscriptionRef after the stream completes", async () => {
|
|
425
|
+
const program = Effect.gen(function* () {
|
|
426
|
+
const { stream, state } = yield* loopWithState(0, (n: number) =>
|
|
427
|
+
n >= 3 ? stopAfter(Stream.fromIterable([n])) : nextAfter(Stream.fromIterable([n]), n + 1),
|
|
428
|
+
)
|
|
429
|
+
const values = yield* Stream.runCollect(stream)
|
|
430
|
+
const finalState = yield* SubscriptionRef.get(state)
|
|
431
|
+
return { values: Array.from(values), finalState }
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
const { values, finalState } = await Effect.runPromise(program)
|
|
435
|
+
expect(values).toEqual([0, 1, 2, 3])
|
|
436
|
+
// Last `next(state)` was `next(3)` before the iteration that emitted Stop.
|
|
437
|
+
expect(finalState).toBe(3)
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
it("the state ref starts at `initial` and stays there if the loop stops without advancing", async () => {
|
|
441
|
+
const program = Effect.gen(function* () {
|
|
442
|
+
const { stream, state } = yield* loopWithState({ count: 7 }, () =>
|
|
443
|
+
Stream.fromIterable([stopEvent]),
|
|
444
|
+
)
|
|
445
|
+
yield* Stream.runDrain(stream)
|
|
446
|
+
return yield* SubscriptionRef.get(state)
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
expect(await Effect.runPromise(program)).toEqual({ count: 7 })
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
it("a downstream consumer can read the live state between emitted values", async () => {
|
|
453
|
+
// Body emits one value per iteration, then advances. A `Stream.runForEach`
|
|
454
|
+
// consumer reads the ref each time a value arrives — proving the ref
|
|
455
|
+
// tracks loop state without the body needing to surface it.
|
|
456
|
+
const program = Effect.gen(function* () {
|
|
457
|
+
const { stream, state } = yield* loopWithState(0, (n: number) =>
|
|
458
|
+
n >= 3 ? stopAfter(Stream.fromIterable([n])) : nextAfter(Stream.fromIterable([n]), n + 1),
|
|
459
|
+
)
|
|
460
|
+
const seen: Array<{ value: number; stateAfter: number }> = []
|
|
461
|
+
yield* Stream.runForEach(stream, (v) =>
|
|
462
|
+
Effect.gen(function* () {
|
|
463
|
+
seen.push({ value: v, stateAfter: yield* SubscriptionRef.get(state) })
|
|
464
|
+
}),
|
|
465
|
+
)
|
|
466
|
+
return seen
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
// For each iter `n`, the consumer reads the ref between values: it sees
|
|
470
|
+
// the iteration's input state. The terminal iter (n=3) stops without
|
|
471
|
+
// advancing, so its read still shows 3.
|
|
472
|
+
expect(await Effect.runPromise(program)).toEqual([
|
|
473
|
+
{ value: 0, stateAfter: 0 },
|
|
474
|
+
{ value: 1, stateAfter: 1 },
|
|
475
|
+
{ value: 2, stateAfter: 2 },
|
|
476
|
+
{ value: 3, stateAfter: 3 },
|
|
477
|
+
])
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
it("SubscriptionRef.changes emits every state transition to a concurrent observer", async () => {
|
|
481
|
+
const program = Effect.gen(function* () {
|
|
482
|
+
const start = yield* Latch.make(false)
|
|
483
|
+
|
|
484
|
+
// Body waits on the latch in iter 0 so the observer can subscribe first.
|
|
485
|
+
const { stream, state } = yield* loopWithState(0, (n: number) =>
|
|
486
|
+
Effect.gen(function* () {
|
|
487
|
+
if (n === 0) yield* Latch.await(start)
|
|
488
|
+
return n >= 3 ? stopAfter(Stream.empty) : nextAfter(Stream.empty, n + 1)
|
|
489
|
+
}),
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
// Fork the observer; take 4 distinct states (initial + 3 transitions).
|
|
493
|
+
const observerFiber = yield* Effect.forkChild(
|
|
494
|
+
SubscriptionRef.changes(state).pipe(Stream.take(4), Stream.runCollect),
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
// Give the observer fiber a chance to actually subscribe before the
|
|
498
|
+
// loop starts advancing the ref. Without this, the loop could finish
|
|
499
|
+
// before the observer's pubsub subscription is in place.
|
|
500
|
+
yield* Effect.sleep("10 millis")
|
|
501
|
+
|
|
502
|
+
yield* Latch.open(start)
|
|
503
|
+
yield* Stream.runDrain(stream)
|
|
504
|
+
|
|
505
|
+
return Array.from(yield* Fiber.join(observerFiber))
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
// initial 0, then next(1), next(2), next(3) — four distinct states.
|
|
509
|
+
expect(await Effect.runPromise(program)).toEqual([0, 1, 2, 3])
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
it("does not interfere with the body's value stream", async () => {
|
|
513
|
+
const program = Effect.gen(function* () {
|
|
514
|
+
const { stream } = yield* loopWithState(0, (n: number) =>
|
|
515
|
+
n >= 3
|
|
516
|
+
? stopAfter(Stream.fromIterable([n]))
|
|
517
|
+
: nextAfter(Stream.fromIterable([n, n + 0.5]), n + 1),
|
|
518
|
+
)
|
|
519
|
+
return Array.from(yield* Stream.runCollect(stream))
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
expect(await Effect.runPromise(program)).toEqual([0, 0.5, 1, 1.5, 2, 2.5, 3])
|
|
523
|
+
})
|
|
524
|
+
})
|
package/src/loop/Loop.ts
CHANGED
|
@@ -17,7 +17,19 @@
|
|
|
17
17
|
* (their producing side effects may already have run). Prefer the
|
|
18
18
|
* `Loop.nextAfter` / `Loop.stopAfter` helpers to terminate cleanly.
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
Cause,
|
|
22
|
+
Channel,
|
|
23
|
+
Data,
|
|
24
|
+
Effect,
|
|
25
|
+
Exit,
|
|
26
|
+
Function,
|
|
27
|
+
Option,
|
|
28
|
+
Ref,
|
|
29
|
+
Scope,
|
|
30
|
+
Stream,
|
|
31
|
+
SubscriptionRef,
|
|
32
|
+
} from "effect"
|
|
21
33
|
import { IncompleteTurn } from "../domain/AiError.js"
|
|
22
34
|
import { isTurnComplete, type Turn, type TurnEvent } from "../domain/Turn.js"
|
|
23
35
|
|
|
@@ -83,7 +95,7 @@ export const stopAfter = <A, E, R>(
|
|
|
83
95
|
* into an accumulator, and at end-of-stream emit one `next(build(finalAcc))`.
|
|
84
96
|
*
|
|
85
97
|
* Subsumes `nextAfter` when state is constant (`reduce: (s, _) => s`,
|
|
86
|
-
* `build: (s) => s`). Used by `Toolkit.
|
|
98
|
+
* `build: (s) => s`). Used by `Toolkit.continueWith` to collect tool
|
|
87
99
|
* results and build next state without exposing a Ref to recipes.
|
|
88
100
|
*/
|
|
89
101
|
export const nextAfterFold = <A, B, S, E, R>(
|
|
@@ -107,7 +119,7 @@ export const nextAfterFold = <A, B, S, E, R>(
|
|
|
107
119
|
)
|
|
108
120
|
|
|
109
121
|
// ---------------------------------------------------------------------------
|
|
110
|
-
//
|
|
122
|
+
// onTurnComplete - turn-aware stream operator for loop bodies
|
|
111
123
|
// ---------------------------------------------------------------------------
|
|
112
124
|
|
|
113
125
|
/**
|
|
@@ -125,7 +137,7 @@ export const nextAfterFold = <A, B, S, E, R>(
|
|
|
125
137
|
* fails with `AiError.IncompleteTurn`. Catch it via `Stream.catchTag` if
|
|
126
138
|
* you want to recover.
|
|
127
139
|
*/
|
|
128
|
-
export const
|
|
140
|
+
export const onTurnComplete =
|
|
129
141
|
<S, A, E2 = never, R2 = never>(
|
|
130
142
|
then: (turn: Turn) => Effect.Effect<Stream.Stream<Event<A, S>, E2, R2>, E2, R2>,
|
|
131
143
|
) =>
|
|
@@ -162,7 +174,7 @@ export const streamUntilComplete =
|
|
|
162
174
|
const isNonEmpty = <A>(array: ReadonlyArray<A>): array is readonly [A, ...Array<A>] =>
|
|
163
175
|
array.length > 0
|
|
164
176
|
|
|
165
|
-
|
|
177
|
+
type CurrentBody<S, A, E, R> = {
|
|
166
178
|
readonly scope: Scope.Closeable
|
|
167
179
|
readonly pull: Effect.Effect<ReadonlyArray<Event<A, S>>, E | Cause.Done<void>, R>
|
|
168
180
|
}
|
|
@@ -293,3 +305,55 @@ export const loop: {
|
|
|
293
305
|
),
|
|
294
306
|
),
|
|
295
307
|
)
|
|
308
|
+
|
|
309
|
+
// ---------------------------------------------------------------------------
|
|
310
|
+
// loopWithState - same body protocol, plus a live state observable.
|
|
311
|
+
// ---------------------------------------------------------------------------
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Like `loop`, but exposes the current loop state as a `SubscriptionRef`
|
|
315
|
+
* alongside the value stream.
|
|
316
|
+
*
|
|
317
|
+
* Allocates one `SubscriptionRef<S>` seeded with `initial`, then runs the
|
|
318
|
+
* loop with a wrapped body that taps every `Next(s)` event into the ref
|
|
319
|
+
* before forwarding it. The caller decides how to consume both channels:
|
|
320
|
+
*
|
|
321
|
+
* - **Final state**: drain the stream, then `SubscriptionRef.get(state)`
|
|
322
|
+
* - the ref holds the state from the last `Next` (or `initial` if the
|
|
323
|
+
* loop ended without advancing).
|
|
324
|
+
* - **Live transitions**: `SubscriptionRef.changes(state)` is a
|
|
325
|
+
* `Stream<S>` of every state observed; subscribe alongside the value
|
|
326
|
+
* stream.
|
|
327
|
+
* - **Mid-iteration peek**: `SubscriptionRef.get(state)` at any time.
|
|
328
|
+
*
|
|
329
|
+
* The returned stream and ref are independent of each other - the ref
|
|
330
|
+
* lives outside the stream's scope, so reading it after the stream
|
|
331
|
+
* completes is safe.
|
|
332
|
+
*/
|
|
333
|
+
export const loopWithState = <S, A, E, R>(
|
|
334
|
+
initial: S,
|
|
335
|
+
body: LoopBody<S, A, E, R>,
|
|
336
|
+
): Effect.Effect<{
|
|
337
|
+
readonly stream: Stream.Stream<A, E, R>
|
|
338
|
+
readonly state: SubscriptionRef.SubscriptionRef<S>
|
|
339
|
+
}> =>
|
|
340
|
+
Effect.gen(function* () {
|
|
341
|
+
const stateRef = yield* SubscriptionRef.make(initial)
|
|
342
|
+
|
|
343
|
+
const tap = (stream: Stream.Stream<Event<A, S>, E, R>): Stream.Stream<Event<A, S>, E, R> =>
|
|
344
|
+
stream.pipe(
|
|
345
|
+
Stream.tap((event) =>
|
|
346
|
+
event._tag === "Next" ? SubscriptionRef.set(stateRef, event.state) : Effect.void,
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
const wrappedBody: LoopBody<S, A, E, R> = (s) => {
|
|
351
|
+
const result = body(s)
|
|
352
|
+
return Effect.isEffect(result) ? Effect.map(result, tap) : tap(result)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
stream: loop(initial, wrappedBody),
|
|
357
|
+
state: stateRef,
|
|
358
|
+
}
|
|
359
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear-algebra primitives for embedding vectors:
|
|
3
|
+
*
|
|
4
|
+
* - **Dense float32**: `dot`, `l2Norm`, `normalize`, `cosine`,
|
|
5
|
+
* `euclidean`. Used for retrieval over single-vector embeddings.
|
|
6
|
+
* - **Sparse**: `sparseDot`, `sparseL2Norm`, `sparseCosine`. Used with
|
|
7
|
+
* `SparseEmbedding`, e.g. Jina ELSER outputs.
|
|
8
|
+
* - **Multivector** (late-interaction): `maxSim`. Used with
|
|
9
|
+
* `MultivectorEmbedding`, e.g. Jina v4 multivector / ColBERT.
|
|
10
|
+
*
|
|
11
|
+
* Hot loops are allocation-free; consumers can call these inside
|
|
12
|
+
* `.map()` over thousands of vectors without GC pressure. For
|
|
13
|
+
* GPU / SIMD / WASM-accelerated math at vector-DB scale, reach for a
|
|
14
|
+
* dedicated library - this module deliberately stays at the
|
|
15
|
+
* recipe-volume tier.
|
|
16
|
+
*/
|
|
17
|
+
import type { MultivectorEmbedding, SparseEmbedding } from "../embedding-model/Embedding.js"
|
|
18
|
+
|
|
19
|
+
/** Inner / dot product. */
|
|
20
|
+
export const dot = (a: Float32Array, b: Float32Array): number => {
|
|
21
|
+
let s = 0
|
|
22
|
+
const n = Math.min(a.length, b.length)
|
|
23
|
+
for (let i = 0; i < n; i++) s += a[i]! * b[i]!
|
|
24
|
+
return s
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** L2 norm (Euclidean magnitude). */
|
|
28
|
+
export const l2Norm = (v: Float32Array): number => {
|
|
29
|
+
let s = 0
|
|
30
|
+
for (let i = 0; i < v.length; i++) s += v[i]! * v[i]!
|
|
31
|
+
return Math.sqrt(s)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* L2-normalize to a unit vector. Allocates a new `Float32Array`. A zero
|
|
36
|
+
* vector returns zeros (no division-by-zero).
|
|
37
|
+
*/
|
|
38
|
+
export const normalize = (v: Float32Array): Float32Array => {
|
|
39
|
+
const n = l2Norm(v)
|
|
40
|
+
if (n === 0) return new Float32Array(v.length)
|
|
41
|
+
const out = new Float32Array(v.length)
|
|
42
|
+
for (let i = 0; i < v.length; i++) out[i] = v[i]! / n
|
|
43
|
+
return out
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Cosine similarity. Range `[-1, 1]`; higher = more similar. Returns
|
|
48
|
+
* `NaN` if either vector has zero magnitude.
|
|
49
|
+
*/
|
|
50
|
+
export const cosine = (a: Float32Array, b: Float32Array): number => {
|
|
51
|
+
let d = 0
|
|
52
|
+
let na = 0
|
|
53
|
+
let nb = 0
|
|
54
|
+
const n = Math.min(a.length, b.length)
|
|
55
|
+
for (let i = 0; i < n; i++) {
|
|
56
|
+
const ai = a[i]!
|
|
57
|
+
const bi = b[i]!
|
|
58
|
+
d += ai * bi
|
|
59
|
+
na += ai * ai
|
|
60
|
+
nb += bi * bi
|
|
61
|
+
}
|
|
62
|
+
return d / (Math.sqrt(na) * Math.sqrt(nb))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Euclidean (L2) distance. */
|
|
66
|
+
export const euclidean = (a: Float32Array, b: Float32Array): number => {
|
|
67
|
+
let s = 0
|
|
68
|
+
const n = Math.min(a.length, b.length)
|
|
69
|
+
for (let i = 0; i < n; i++) {
|
|
70
|
+
const d = a[i]! - b[i]!
|
|
71
|
+
s += d * d
|
|
72
|
+
}
|
|
73
|
+
return Math.sqrt(s)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Sparse vectors (Record<string, number>)
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
/** Inner product over the intersection of token keys. */
|
|
81
|
+
export const sparseDot = (a: SparseEmbedding, b: SparseEmbedding): number => {
|
|
82
|
+
// Iterate the smaller map; lookup against the larger one. O(min(|a|, |b|)).
|
|
83
|
+
const aSize = Object.keys(a.weights).length
|
|
84
|
+
const bSize = Object.keys(b.weights).length
|
|
85
|
+
const [smaller, larger] = aSize <= bSize ? [a.weights, b.weights] : [b.weights, a.weights]
|
|
86
|
+
let s = 0
|
|
87
|
+
for (const token in smaller) {
|
|
88
|
+
const other = larger[token]
|
|
89
|
+
if (other !== undefined) s += smaller[token]! * other
|
|
90
|
+
}
|
|
91
|
+
return s
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** L2 norm of a sparse vector. */
|
|
95
|
+
export const sparseL2Norm = (v: SparseEmbedding): number => {
|
|
96
|
+
let s = 0
|
|
97
|
+
for (const token in v.weights) {
|
|
98
|
+
const w = v.weights[token]!
|
|
99
|
+
s += w * w
|
|
100
|
+
}
|
|
101
|
+
return Math.sqrt(s)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sparse cosine similarity. Range `[-1, 1]` (typically `[0, 1]` for
|
|
106
|
+
* learned-sparse encoders since weights are non-negative). Returns
|
|
107
|
+
* `NaN` if either vector has zero magnitude.
|
|
108
|
+
*/
|
|
109
|
+
export const sparseCosine = (a: SparseEmbedding, b: SparseEmbedding): number =>
|
|
110
|
+
sparseDot(a, b) / (sparseL2Norm(a) * sparseL2Norm(b))
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Multivector / late-interaction (ColBERT-style)
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* MaxSim score for late-interaction retrieval. For each *query* vector,
|
|
118
|
+
* find the maximum dot product with any *document* vector, then sum.
|
|
119
|
+
*
|
|
120
|
+
* Captures fine-grained relevance that single-vector cosine smears out:
|
|
121
|
+
* each query token finds its own best-matching document token.
|
|
122
|
+
*
|
|
123
|
+
* Cost: O(|q| × |d| × dim). Fine at recipe volume; for production-scale
|
|
124
|
+
* retrieval use a vector store with native multivector indexing
|
|
125
|
+
* (Vespa, Qdrant, PLAID).
|
|
126
|
+
*/
|
|
127
|
+
export const maxSim = (q: MultivectorEmbedding, d: MultivectorEmbedding): number => {
|
|
128
|
+
let total = 0
|
|
129
|
+
for (const qv of q.vectors) {
|
|
130
|
+
let best = -Infinity
|
|
131
|
+
for (const dv of d.vectors) {
|
|
132
|
+
const s = dot(qv, dv)
|
|
133
|
+
if (s > best) best = s
|
|
134
|
+
}
|
|
135
|
+
total += best
|
|
136
|
+
}
|
|
137
|
+
return total
|
|
138
|
+
}
|
package/src/streaming/SSE.ts
CHANGED