@effect-uai/core 0.12.1 → 0.13.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/chunker/Chunker.d.mts +32 -0
- package/dist/chunker/Chunker.d.mts.map +1 -0
- package/dist/chunker/Chunker.mjs +14 -0
- package/dist/chunker/Chunker.mjs.map +1 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +4 -1
- package/dist/reranker/Reranker.d.mts +46 -0
- package/dist/reranker/Reranker.d.mts.map +1 -0
- package/dist/reranker/Reranker.mjs +14 -0
- package/dist/reranker/Reranker.mjs.map +1 -0
- package/dist/tokenizer/Tokenizer.d.mts +22 -0
- package/dist/tokenizer/Tokenizer.d.mts.map +1 -0
- package/dist/tokenizer/Tokenizer.mjs +9 -0
- package/dist/tokenizer/Tokenizer.mjs.map +1 -0
- package/package.json +13 -1
- package/src/chunker/Chunker.ts +34 -0
- package/src/index.ts +3 -0
- package/src/reranker/Reranker.ts +51 -0
- package/src/tokenizer/Tokenizer.ts +19 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
declare namespace Chunker_d_exports {
|
|
4
|
+
export { Chunk, Chunker, ChunkerService, chunk };
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A passage of a document, with the character offsets it came from.
|
|
8
|
+
*
|
|
9
|
+
* Implementor contract: `text` is the input's `[start, end)` slice verbatim,
|
|
10
|
+
* so a retrieved passage can be traced back to its source and enriched with
|
|
11
|
+
* what surrounds it. Chunks may overlap.
|
|
12
|
+
*/
|
|
13
|
+
type Chunk = {
|
|
14
|
+
readonly text: string;
|
|
15
|
+
readonly start: number;
|
|
16
|
+
readonly end: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Splitting a document into retrievable passages. Strategy and sizing are
|
|
20
|
+
* fixed when the layer is built, so callers stay portable across a local
|
|
21
|
+
* splitter and a hosted chunking service.
|
|
22
|
+
*/
|
|
23
|
+
type ChunkerService = {
|
|
24
|
+
readonly chunk: (text: string) => Effect.Effect<ReadonlyArray<Chunk>, AiError>;
|
|
25
|
+
};
|
|
26
|
+
declare const Chunker_base: Context.ServiceClass<Chunker, "@betalyra/effect-uai/Chunker", ChunkerService>;
|
|
27
|
+
declare class Chunker extends Chunker_base {}
|
|
28
|
+
/** Split a document into passages. */
|
|
29
|
+
declare const chunk: (text: string) => Effect.Effect<ReadonlyArray<Chunk>, AiError, Chunker>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Chunk, Chunker, ChunkerService, chunk, Chunker_d_exports as t };
|
|
32
|
+
//# sourceMappingURL=Chunker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chunker.d.mts","names":[],"sources":["../../src/chunker/Chunker.ts"],"mappings":";;;;;;;;;;;;KAUY;WACD;WACA;WACA;;;;;;;KAQC;WACD,QAAQ,iBAAiB,OAAO,OAAO,cAAc,QAAQ;;;cAG3D,gBAAgB;;cAKhB,QAAK,iBAEf,OAAO,OAAO,cAAc,QAAQ,SAAiB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
//#region src/chunker/Chunker.ts
|
|
4
|
+
var Chunker_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
Chunker: () => Chunker,
|
|
6
|
+
chunk: () => chunk
|
|
7
|
+
});
|
|
8
|
+
var Chunker = class extends Context.Service()("@betalyra/effect-uai/Chunker") {};
|
|
9
|
+
/** Split a document into passages. */
|
|
10
|
+
const chunk = (text) => Effect.flatMap(Chunker, (chunker) => chunker.chunk(text));
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Chunker, chunk, Chunker_exports as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=Chunker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chunker.mjs","names":[],"sources":["../../src/chunker/Chunker.ts"],"sourcesContent":["import { Context, Effect } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n/**\n * A passage of a document, with the character offsets it came from.\n *\n * Implementor contract: `text` is the input's `[start, end)` slice verbatim,\n * so a retrieved passage can be traced back to its source and enriched with\n * what surrounds it. Chunks may overlap.\n */\nexport type Chunk = {\n readonly text: string\n readonly start: number\n readonly end: number\n}\n\n/**\n * Splitting a document into retrievable passages. Strategy and sizing are\n * fixed when the layer is built, so callers stay portable across a local\n * splitter and a hosted chunking service.\n */\nexport type ChunkerService = {\n readonly chunk: (text: string) => Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError>\n}\n\nexport class Chunker extends Context.Service<Chunker, ChunkerService>()(\n \"@betalyra/effect-uai/Chunker\",\n) {}\n\n/** Split a document into passages. */\nexport const chunk = (\n text: string,\n): Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError, Chunker> =>\n Effect.flatMap(Chunker, (chunker) => chunker.chunk(text))\n"],"mappings":";;;;;;;AAyBA,IAAa,UAAb,cAA6B,QAAQ,QAAiC,CAAC,CACrE,8BACF,CAAC,CAAC,CAAC;;AAGH,MAAa,SACX,SAEA,OAAO,QAAQ,UAAU,YAAY,QAAQ,MAAM,IAAI,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ import { _ as Tool_d_exports } from "./Tool-DE-rnvkw.mjs";
|
|
|
7
7
|
import { t as BrowserTool_d_exports } from "./browser/BrowserTool.mjs";
|
|
8
8
|
import { t as Capabilities_d_exports } from "./capabilities/Capabilities.mjs";
|
|
9
9
|
import { n as AiError_d_exports } from "./AiError-eLV9t1lU.mjs";
|
|
10
|
+
import { t as Chunker_d_exports } from "./chunker/Chunker.mjs";
|
|
10
11
|
import { o as Audio_d_exports } from "./Audio-60lKKHxS.mjs";
|
|
11
12
|
import { t as Citation_d_exports } from "./domain/Citation.mjs";
|
|
12
13
|
import { t as Music_d_exports } from "./domain/Music.mjs";
|
|
@@ -24,6 +25,7 @@ import { n as ToolEvent_d_exports } from "./ToolEvent-D99MGQYH.mjs";
|
|
|
24
25
|
import { l as Toolkit_d_exports } from "./Toolkit-BEZrNPTI.mjs";
|
|
25
26
|
import { t as LanguageModel_d_exports } from "./language-model/LanguageModel.mjs";
|
|
26
27
|
import { t as MusicGenerator_d_exports } from "./music-generator/MusicGenerator.mjs";
|
|
28
|
+
import { t as Reranker_d_exports } from "./reranker/Reranker.mjs";
|
|
27
29
|
import { t as Memory_d_exports } from "./sandbox/Memory.mjs";
|
|
28
30
|
import { o as SandboxError_d_exports } from "./SandboxError-BN8b28Bh.mjs";
|
|
29
31
|
import { t as Sandbox_d_exports } from "./sandbox/Sandbox.mjs";
|
|
@@ -36,6 +38,7 @@ import { t as WebReadTool_d_exports } from "./web-read/WebReadTool.mjs";
|
|
|
36
38
|
import { t as WebSearch_d_exports } from "./web-search/WebSearch.mjs";
|
|
37
39
|
import { t as WebSearchTool_d_exports } from "./web-search/WebSearchTool.mjs";
|
|
38
40
|
import { t as Vector_d_exports } from "./math/Vector.mjs";
|
|
41
|
+
import { t as Tokenizer_d_exports } from "./tokenizer/Tokenizer.mjs";
|
|
39
42
|
import { t as Retry_d_exports } from "./retry/Retry.mjs";
|
|
40
43
|
import { t as Approval_d_exports } from "./tool/Approval.mjs";
|
|
41
44
|
import { t as HistoryCheck_d_exports } from "./tool/HistoryCheck.mjs";
|
|
@@ -44,4 +47,4 @@ import { t as Lines_d_exports } from "./streaming/Lines.mjs";
|
|
|
44
47
|
import { t as SSE_d_exports } from "./streaming/SSE.mjs";
|
|
45
48
|
import { t as Metrics_d_exports } from "./observability/Metrics.mjs";
|
|
46
49
|
import { t as Telemetry_d_exports } from "./observability/Telemetry.mjs";
|
|
47
|
-
export { AiError_d_exports as AiError, Approval_d_exports as Approval, Audio_d_exports as Audio, Browser_d_exports as Browser, BrowserError_d_exports as BrowserError, BrowserTool_d_exports as BrowserTool, Capabilities_d_exports as Capabilities, Citation_d_exports as Citation, DeepResearch_d_exports as DeepResearch, Embedding_d_exports as Embedding, EmbeddingModel_d_exports as EmbeddingModel, HistoryCheck_d_exports as HistoryCheck, Image_d_exports as Image, Items_d_exports as Items, JSONL_d_exports as JSONL, Job_d_exports as Job, LanguageModel_d_exports as LanguageModel, Lines_d_exports as Lines, Loop_d_exports as Loop, Media_d_exports as Media, Memory_d_exports as Memory, Metrics_d_exports as Metrics, Music_d_exports as Music, MusicGenerator_d_exports as MusicGenerator, Research_d_exports as Research, Retry_d_exports as Retry, SSE_d_exports as SSE, Sandbox_d_exports as Sandbox, SandboxError_d_exports as SandboxError, SandboxImage_d_exports as SandboxImage, SandboxNetwork_d_exports as SandboxNetwork, SpeechSynthesizer_d_exports as SpeechSynthesizer, StructuredFormat_d_exports as StructuredFormat, Telemetry_d_exports as Telemetry, Tool_d_exports as Tool, ToolEvent_d_exports as ToolEvent, ToolResult_d_exports as ToolResult, Toolkit_d_exports as Toolkit, Transcriber_d_exports as Transcriber, Transcript_d_exports as Transcript, Turn_d_exports as Turn, Vector_d_exports as Vector, WebRead_d_exports as WebRead, WebReadTool_d_exports as WebReadTool, WebSearch_d_exports as WebSearch, WebSearchTool_d_exports as WebSearchTool };
|
|
50
|
+
export { AiError_d_exports as AiError, Approval_d_exports as Approval, Audio_d_exports as Audio, Browser_d_exports as Browser, BrowserError_d_exports as BrowserError, BrowserTool_d_exports as BrowserTool, Capabilities_d_exports as Capabilities, Chunker_d_exports as Chunker, Citation_d_exports as Citation, DeepResearch_d_exports as DeepResearch, Embedding_d_exports as Embedding, EmbeddingModel_d_exports as EmbeddingModel, HistoryCheck_d_exports as HistoryCheck, Image_d_exports as Image, Items_d_exports as Items, JSONL_d_exports as JSONL, Job_d_exports as Job, LanguageModel_d_exports as LanguageModel, Lines_d_exports as Lines, Loop_d_exports as Loop, Media_d_exports as Media, Memory_d_exports as Memory, Metrics_d_exports as Metrics, Music_d_exports as Music, MusicGenerator_d_exports as MusicGenerator, Reranker_d_exports as Reranker, Research_d_exports as Research, Retry_d_exports as Retry, SSE_d_exports as SSE, Sandbox_d_exports as Sandbox, SandboxError_d_exports as SandboxError, SandboxImage_d_exports as SandboxImage, SandboxNetwork_d_exports as SandboxNetwork, SpeechSynthesizer_d_exports as SpeechSynthesizer, StructuredFormat_d_exports as StructuredFormat, Telemetry_d_exports as Telemetry, Tokenizer_d_exports as Tokenizer, Tool_d_exports as Tool, ToolEvent_d_exports as ToolEvent, ToolResult_d_exports as ToolResult, Toolkit_d_exports as Toolkit, Transcriber_d_exports as Transcriber, Transcript_d_exports as Transcript, Turn_d_exports as Turn, Vector_d_exports as Vector, WebRead_d_exports as WebRead, WebReadTool_d_exports as WebReadTool, WebSearch_d_exports as WebSearch, WebSearchTool_d_exports as WebSearchTool };
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { t as ToolEvent_exports } from "./tool/ToolEvent.mjs";
|
|
|
13
13
|
import { t as Toolkit_exports } from "./tool/Toolkit.mjs";
|
|
14
14
|
import { t as BrowserTool_exports } from "./browser/BrowserTool.mjs";
|
|
15
15
|
import { t as Capabilities_exports } from "./capabilities/Capabilities.mjs";
|
|
16
|
+
import { t as Chunker_exports } from "./chunker/Chunker.mjs";
|
|
16
17
|
import { t as Citation_exports } from "./domain/Citation.mjs";
|
|
17
18
|
import { t as Job_exports } from "./job/Job.mjs";
|
|
18
19
|
import { t as DeepResearch_exports } from "./research/DeepResearch.mjs";
|
|
@@ -24,6 +25,7 @@ import { t as Embedding_exports } from "./embedding-model/Embedding.mjs";
|
|
|
24
25
|
import { t as EmbeddingModel_exports } from "./embedding-model/EmbeddingModel.mjs";
|
|
25
26
|
import { t as LanguageModel_exports } from "./language-model/LanguageModel.mjs";
|
|
26
27
|
import { t as MusicGenerator_exports } from "./music-generator/MusicGenerator.mjs";
|
|
28
|
+
import { t as Reranker_exports } from "./reranker/Reranker.mjs";
|
|
27
29
|
import { t as Memory_exports } from "./sandbox/Memory.mjs";
|
|
28
30
|
import { t as Sandbox_exports } from "./sandbox/Sandbox.mjs";
|
|
29
31
|
import { t as SandboxError_exports } from "./sandbox/SandboxError.mjs";
|
|
@@ -36,6 +38,7 @@ import { t as WebReadTool_exports } from "./web-read/WebReadTool.mjs";
|
|
|
36
38
|
import { t as WebSearch_exports } from "./web-search/WebSearch.mjs";
|
|
37
39
|
import { t as WebSearchTool_exports } from "./web-search/WebSearchTool.mjs";
|
|
38
40
|
import { t as Vector_exports } from "./math/Vector.mjs";
|
|
41
|
+
import { t as Tokenizer_exports } from "./tokenizer/Tokenizer.mjs";
|
|
39
42
|
import { t as Retry_exports } from "./retry/Retry.mjs";
|
|
40
43
|
import { t as Approval_exports } from "./tool/Approval.mjs";
|
|
41
44
|
import { t as HistoryCheck_exports } from "./tool/HistoryCheck.mjs";
|
|
@@ -44,4 +47,4 @@ import { t as Lines_exports } from "./streaming/Lines.mjs";
|
|
|
44
47
|
import { t as SSE_exports } from "./streaming/SSE.mjs";
|
|
45
48
|
import { t as Metrics_exports } from "./observability/Metrics.mjs";
|
|
46
49
|
import { t as Telemetry_exports } from "./observability/Telemetry.mjs";
|
|
47
|
-
export { AiError_exports as AiError, Approval_exports as Approval, Audio_exports as Audio, Browser_exports as Browser, BrowserError_exports as BrowserError, BrowserTool_exports as BrowserTool, Capabilities_exports as Capabilities, Citation_exports as Citation, DeepResearch_exports as DeepResearch, Embedding_exports as Embedding, EmbeddingModel_exports as EmbeddingModel, HistoryCheck_exports as HistoryCheck, Image_exports as Image, Items_exports as Items, JSONL_exports as JSONL, Job_exports as Job, LanguageModel_exports as LanguageModel, Lines_exports as Lines, Loop_exports as Loop, Media_exports as Media, Memory_exports as Memory, Metrics_exports as Metrics, Music_exports as Music, MusicGenerator_exports as MusicGenerator, Research_exports as Research, Retry_exports as Retry, SSE_exports as SSE, Sandbox_exports as Sandbox, SandboxError_exports as SandboxError, SandboxImage_exports as SandboxImage, SandboxNetwork_exports as SandboxNetwork, SpeechSynthesizer_exports as SpeechSynthesizer, StructuredFormat_exports as StructuredFormat, Telemetry_exports as Telemetry, Tool_exports as Tool, ToolEvent_exports as ToolEvent, ToolResult_exports as ToolResult, Toolkit_exports as Toolkit, Transcriber_exports as Transcriber, Transcript_exports as Transcript, Turn_exports as Turn, Vector_exports as Vector, WebRead_exports as WebRead, WebReadTool_exports as WebReadTool, WebSearch_exports as WebSearch, WebSearchTool_exports as WebSearchTool };
|
|
50
|
+
export { AiError_exports as AiError, Approval_exports as Approval, Audio_exports as Audio, Browser_exports as Browser, BrowserError_exports as BrowserError, BrowserTool_exports as BrowserTool, Capabilities_exports as Capabilities, Chunker_exports as Chunker, Citation_exports as Citation, DeepResearch_exports as DeepResearch, Embedding_exports as Embedding, EmbeddingModel_exports as EmbeddingModel, HistoryCheck_exports as HistoryCheck, Image_exports as Image, Items_exports as Items, JSONL_exports as JSONL, Job_exports as Job, LanguageModel_exports as LanguageModel, Lines_exports as Lines, Loop_exports as Loop, Media_exports as Media, Memory_exports as Memory, Metrics_exports as Metrics, Music_exports as Music, MusicGenerator_exports as MusicGenerator, Reranker_exports as Reranker, Research_exports as Research, Retry_exports as Retry, SSE_exports as SSE, Sandbox_exports as Sandbox, SandboxError_exports as SandboxError, SandboxImage_exports as SandboxImage, SandboxNetwork_exports as SandboxNetwork, SpeechSynthesizer_exports as SpeechSynthesizer, StructuredFormat_exports as StructuredFormat, Telemetry_exports as Telemetry, Tokenizer_exports as Tokenizer, Tool_exports as Tool, ToolEvent_exports as ToolEvent, ToolResult_exports as ToolResult, Toolkit_exports as Toolkit, Transcriber_exports as Transcriber, Transcript_exports as Transcript, Turn_exports as Turn, Vector_exports as Vector, WebRead_exports as WebRead, WebReadTool_exports as WebReadTool, WebSearch_exports as WebSearch, WebSearchTool_exports as WebSearchTool };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
declare namespace Reranker_d_exports {
|
|
4
|
+
export { CommonRerankRequest, RerankResponse, RerankResult, RerankUsage, Reranker, RerankerService, rerank };
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Cross-provider rerank request. Vendor knobs (multimodal documents,
|
|
8
|
+
* instruction fields, truncation) live on the provider's typed request.
|
|
9
|
+
*/
|
|
10
|
+
type CommonRerankRequest = {
|
|
11
|
+
readonly query: string;
|
|
12
|
+
readonly documents: ReadonlyArray<string>;
|
|
13
|
+
/** Each provider narrows this to its typed literal union. */
|
|
14
|
+
readonly model: string;
|
|
15
|
+
/** Keep only the top N results. Default: all documents. */
|
|
16
|
+
readonly topN?: number;
|
|
17
|
+
};
|
|
18
|
+
type RerankResult = {
|
|
19
|
+
/** Position in the request's `documents`. */
|
|
20
|
+
readonly index: number;
|
|
21
|
+
readonly score: number;
|
|
22
|
+
};
|
|
23
|
+
/** Optional throughout: some providers bill per search unit, not per token. */
|
|
24
|
+
type RerankUsage = {
|
|
25
|
+
readonly totalTokens?: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Score contract: `results` is sorted descending, higher is better. Scores
|
|
29
|
+
* order candidates within one call; no range or calibration is promised and
|
|
30
|
+
* they are not comparable across requests. Implementors must sort descending
|
|
31
|
+
* if the wire does not.
|
|
32
|
+
*/
|
|
33
|
+
type RerankResponse = {
|
|
34
|
+
readonly results: ReadonlyArray<RerankResult>;
|
|
35
|
+
readonly usage: RerankUsage;
|
|
36
|
+
};
|
|
37
|
+
type RerankerService = {
|
|
38
|
+
readonly rerank: (request: CommonRerankRequest) => Effect.Effect<RerankResponse, AiError>;
|
|
39
|
+
};
|
|
40
|
+
declare const Reranker_base: Context.ServiceClass<Reranker, "@betalyra/effect-uai/Reranker", RerankerService>;
|
|
41
|
+
declare class Reranker extends Reranker_base {}
|
|
42
|
+
/** Score a candidate set against a query, best first. */
|
|
43
|
+
declare const rerank: (request: CommonRerankRequest) => Effect.Effect<RerankResponse, AiError, Reranker>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CommonRerankRequest, RerankResponse, RerankResult, RerankUsage, Reranker, RerankerService, rerank, Reranker_d_exports as t };
|
|
46
|
+
//# sourceMappingURL=Reranker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reranker.d.mts","names":[],"sources":["../../src/reranker/Reranker.ts"],"mappings":";;;;;;;;;KAOY;WACD;WACA,WAAW;;WAEX;;WAEA;;KAGC;;WAED;WACA;;;KAIC;WACD;;;;;;;;KASC;WACD,SAAS,cAAc;WACvB,OAAO;;KAGN;WACD,SAAS,SAAS,wBAAwB,OAAO,OAAO,gBAAgB;;;cAGtE,iBAAiB;;cAKjB,SAAM,SACR,wBACR,OAAO,OAAO,gBAAgB,SAAiB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
//#region src/reranker/Reranker.ts
|
|
4
|
+
var Reranker_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
Reranker: () => Reranker,
|
|
6
|
+
rerank: () => rerank
|
|
7
|
+
});
|
|
8
|
+
var Reranker = class extends Context.Service()("@betalyra/effect-uai/Reranker") {};
|
|
9
|
+
/** Score a candidate set against a query, best first. */
|
|
10
|
+
const rerank = (request) => Effect.flatMap(Reranker, (r) => r.rerank(request));
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Reranker, rerank, Reranker_exports as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=Reranker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reranker.mjs","names":[],"sources":["../../src/reranker/Reranker.ts"],"sourcesContent":["import { Context, Effect } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n/**\n * Cross-provider rerank request. Vendor knobs (multimodal documents,\n * instruction fields, truncation) live on the provider's typed request.\n */\nexport type CommonRerankRequest = {\n readonly query: string\n readonly documents: ReadonlyArray<string>\n /** Each provider narrows this to its typed literal union. */\n readonly model: string\n /** Keep only the top N results. Default: all documents. */\n readonly topN?: number\n}\n\nexport type RerankResult = {\n /** Position in the request's `documents`. */\n readonly index: number\n readonly score: number\n}\n\n/** Optional throughout: some providers bill per search unit, not per token. */\nexport type RerankUsage = {\n readonly totalTokens?: number\n}\n\n/**\n * Score contract: `results` is sorted descending, higher is better. Scores\n * order candidates within one call; no range or calibration is promised and\n * they are not comparable across requests. Implementors must sort descending\n * if the wire does not.\n */\nexport type RerankResponse = {\n readonly results: ReadonlyArray<RerankResult>\n readonly usage: RerankUsage\n}\n\nexport type RerankerService = {\n readonly rerank: (request: CommonRerankRequest) => Effect.Effect<RerankResponse, AiError.AiError>\n}\n\nexport class Reranker extends Context.Service<Reranker, RerankerService>()(\n \"@betalyra/effect-uai/Reranker\",\n) {}\n\n/** Score a candidate set against a query, best first. */\nexport const rerank = (\n request: CommonRerankRequest,\n): Effect.Effect<RerankResponse, AiError.AiError, Reranker> =>\n Effect.flatMap(Reranker, (r) => r.rerank(request))\n"],"mappings":";;;;;;;AA0CA,IAAa,WAAb,cAA8B,QAAQ,QAAmC,CAAC,CACxE,+BACF,CAAC,CAAC,CAAC;;AAGH,MAAa,UACX,YAEA,OAAO,QAAQ,WAAW,MAAM,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
declare namespace Tokenizer_d_exports {
|
|
3
|
+
export { Tokenizer, TokenizerService };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Turning text into tokens, for sizing chunks, budgeting context, and
|
|
7
|
+
* estimating usage a provider does not report. Count with `encode(text).length`.
|
|
8
|
+
*
|
|
9
|
+
* Implementor contract: both methods are synchronous, so counting inside a loop
|
|
10
|
+
* never awaits; loading a vocabulary is the layer's job. `decode` inverts
|
|
11
|
+
* `encode`. Implement this only over a real vocabulary, never a heuristic:
|
|
12
|
+
* a character-count estimate is a plain function, not a service.
|
|
13
|
+
*/
|
|
14
|
+
type TokenizerService = {
|
|
15
|
+
readonly encode: (text: string) => ReadonlyArray<number>;
|
|
16
|
+
readonly decode: (tokens: ReadonlyArray<number>) => string;
|
|
17
|
+
};
|
|
18
|
+
declare const Tokenizer_base: Context.ServiceClass<Tokenizer, "@betalyra/effect-uai/Tokenizer", TokenizerService>;
|
|
19
|
+
declare class Tokenizer extends Tokenizer_base {}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Tokenizer, TokenizerService, Tokenizer_d_exports as t };
|
|
22
|
+
//# sourceMappingURL=Tokenizer.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tokenizer.d.mts","names":[],"sources":["../../src/tokenizer/Tokenizer.ts"],"mappings":";;;;;;;;;;;;;KAWY;WACD,SAAS,iBAAiB;WAC1B,SAAS,QAAQ;;;cAGf,kBAAkB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
|
+
import { Context } from "effect";
|
|
3
|
+
//#region src/tokenizer/Tokenizer.ts
|
|
4
|
+
var Tokenizer_exports = /* @__PURE__ */ __exportAll({ Tokenizer: () => Tokenizer });
|
|
5
|
+
var Tokenizer = class extends Context.Service()("@betalyra/effect-uai/Tokenizer") {};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { Tokenizer, Tokenizer_exports as t };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=Tokenizer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tokenizer.mjs","names":[],"sources":["../../src/tokenizer/Tokenizer.ts"],"sourcesContent":["import { Context } from \"effect\"\n\n/**\n * Turning text into tokens, for sizing chunks, budgeting context, and\n * estimating usage a provider does not report. Count with `encode(text).length`.\n *\n * Implementor contract: both methods are synchronous, so counting inside a loop\n * never awaits; loading a vocabulary is the layer's job. `decode` inverts\n * `encode`. Implement this only over a real vocabulary, never a heuristic:\n * a character-count estimate is a plain function, not a service.\n */\nexport type TokenizerService = {\n readonly encode: (text: string) => ReadonlyArray<number>\n readonly decode: (tokens: ReadonlyArray<number>) => string\n}\n\nexport class Tokenizer extends Context.Service<Tokenizer, TokenizerService>()(\n \"@betalyra/effect-uai/Tokenizer\",\n) {}\n"],"mappings":";;;;AAgBA,IAAa,YAAb,cAA+B,QAAQ,QAAqC,CAAC,CAC3E,gCACF,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-uai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Low-level primitives (loop, conversation, items, tools, streaming codecs) for building AI agents with Effect.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
"types": "./dist/domain/Audio.d.mts",
|
|
43
43
|
"import": "./dist/domain/Audio.mjs"
|
|
44
44
|
},
|
|
45
|
+
"./Chunker": {
|
|
46
|
+
"types": "./dist/chunker/Chunker.d.mts",
|
|
47
|
+
"import": "./dist/chunker/Chunker.mjs"
|
|
48
|
+
},
|
|
45
49
|
"./Citation": {
|
|
46
50
|
"types": "./dist/domain/Citation.d.mts",
|
|
47
51
|
"import": "./dist/domain/Citation.mjs"
|
|
@@ -110,6 +114,10 @@
|
|
|
110
114
|
"types": "./dist/music-generator/MusicGenerator.d.mts",
|
|
111
115
|
"import": "./dist/music-generator/MusicGenerator.mjs"
|
|
112
116
|
},
|
|
117
|
+
"./Reranker": {
|
|
118
|
+
"types": "./dist/reranker/Reranker.d.mts",
|
|
119
|
+
"import": "./dist/reranker/Reranker.mjs"
|
|
120
|
+
},
|
|
113
121
|
"./Memory": {
|
|
114
122
|
"types": "./dist/sandbox/Memory.d.mts",
|
|
115
123
|
"import": "./dist/sandbox/Memory.mjs"
|
|
@@ -166,6 +174,10 @@
|
|
|
166
174
|
"types": "./dist/math/Vector.d.mts",
|
|
167
175
|
"import": "./dist/math/Vector.mjs"
|
|
168
176
|
},
|
|
177
|
+
"./Tokenizer": {
|
|
178
|
+
"types": "./dist/tokenizer/Tokenizer.d.mts",
|
|
179
|
+
"import": "./dist/tokenizer/Tokenizer.mjs"
|
|
180
|
+
},
|
|
169
181
|
"./Tool": {
|
|
170
182
|
"types": "./dist/tool/Tool.d.mts",
|
|
171
183
|
"import": "./dist/tool/Tool.mjs"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context, Effect } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A passage of a document, with the character offsets it came from.
|
|
6
|
+
*
|
|
7
|
+
* Implementor contract: `text` is the input's `[start, end)` slice verbatim,
|
|
8
|
+
* so a retrieved passage can be traced back to its source and enriched with
|
|
9
|
+
* what surrounds it. Chunks may overlap.
|
|
10
|
+
*/
|
|
11
|
+
export type Chunk = {
|
|
12
|
+
readonly text: string
|
|
13
|
+
readonly start: number
|
|
14
|
+
readonly end: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Splitting a document into retrievable passages. Strategy and sizing are
|
|
19
|
+
* fixed when the layer is built, so callers stay portable across a local
|
|
20
|
+
* splitter and a hosted chunking service.
|
|
21
|
+
*/
|
|
22
|
+
export type ChunkerService = {
|
|
23
|
+
readonly chunk: (text: string) => Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Chunker extends Context.Service<Chunker, ChunkerService>()(
|
|
27
|
+
"@betalyra/effect-uai/Chunker",
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
/** Split a document into passages. */
|
|
31
|
+
export const chunk = (
|
|
32
|
+
text: string,
|
|
33
|
+
): Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError, Chunker> =>
|
|
34
|
+
Effect.flatMap(Chunker, (chunker) => chunker.chunk(text))
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as Browser from "./browser/Browser.js"
|
|
|
4
4
|
export * as BrowserError from "./browser/BrowserError.js"
|
|
5
5
|
export * as BrowserTool from "./browser/BrowserTool.js"
|
|
6
6
|
export * as Capabilities from "./capabilities/Capabilities.js"
|
|
7
|
+
export * as Chunker from "./chunker/Chunker.js"
|
|
7
8
|
export * as Citation from "./domain/Citation.js"
|
|
8
9
|
export * as DeepResearch from "./research/DeepResearch.js"
|
|
9
10
|
export * as Image from "./domain/Image.js"
|
|
@@ -18,6 +19,7 @@ export * as Embedding from "./embedding-model/Embedding.js"
|
|
|
18
19
|
export * as EmbeddingModel from "./embedding-model/EmbeddingModel.js"
|
|
19
20
|
export * as LanguageModel from "./language-model/LanguageModel.js"
|
|
20
21
|
export * as MusicGenerator from "./music-generator/MusicGenerator.js"
|
|
22
|
+
export * as Reranker from "./reranker/Reranker.js"
|
|
21
23
|
export * as Memory from "./sandbox/Memory.js"
|
|
22
24
|
export * as Sandbox from "./sandbox/Sandbox.js"
|
|
23
25
|
export * as SandboxError from "./sandbox/SandboxError.js"
|
|
@@ -30,6 +32,7 @@ export * as WebReadTool from "./web-read/WebReadTool.js"
|
|
|
30
32
|
export * as WebSearch from "./web-search/WebSearch.js"
|
|
31
33
|
export * as WebSearchTool from "./web-search/WebSearchTool.js"
|
|
32
34
|
export * as Vector from "./math/Vector.js"
|
|
35
|
+
export * as Tokenizer from "./tokenizer/Tokenizer.js"
|
|
33
36
|
export * as Loop from "./loop/Loop.js"
|
|
34
37
|
export * as Retry from "./retry/Retry.js"
|
|
35
38
|
export * as Tool from "./tool/Tool.js"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Context, Effect } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cross-provider rerank request. Vendor knobs (multimodal documents,
|
|
6
|
+
* instruction fields, truncation) live on the provider's typed request.
|
|
7
|
+
*/
|
|
8
|
+
export type CommonRerankRequest = {
|
|
9
|
+
readonly query: string
|
|
10
|
+
readonly documents: ReadonlyArray<string>
|
|
11
|
+
/** Each provider narrows this to its typed literal union. */
|
|
12
|
+
readonly model: string
|
|
13
|
+
/** Keep only the top N results. Default: all documents. */
|
|
14
|
+
readonly topN?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type RerankResult = {
|
|
18
|
+
/** Position in the request's `documents`. */
|
|
19
|
+
readonly index: number
|
|
20
|
+
readonly score: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Optional throughout: some providers bill per search unit, not per token. */
|
|
24
|
+
export type RerankUsage = {
|
|
25
|
+
readonly totalTokens?: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Score contract: `results` is sorted descending, higher is better. Scores
|
|
30
|
+
* order candidates within one call; no range or calibration is promised and
|
|
31
|
+
* they are not comparable across requests. Implementors must sort descending
|
|
32
|
+
* if the wire does not.
|
|
33
|
+
*/
|
|
34
|
+
export type RerankResponse = {
|
|
35
|
+
readonly results: ReadonlyArray<RerankResult>
|
|
36
|
+
readonly usage: RerankUsage
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type RerankerService = {
|
|
40
|
+
readonly rerank: (request: CommonRerankRequest) => Effect.Effect<RerankResponse, AiError.AiError>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Reranker extends Context.Service<Reranker, RerankerService>()(
|
|
44
|
+
"@betalyra/effect-uai/Reranker",
|
|
45
|
+
) {}
|
|
46
|
+
|
|
47
|
+
/** Score a candidate set against a query, best first. */
|
|
48
|
+
export const rerank = (
|
|
49
|
+
request: CommonRerankRequest,
|
|
50
|
+
): Effect.Effect<RerankResponse, AiError.AiError, Reranker> =>
|
|
51
|
+
Effect.flatMap(Reranker, (r) => r.rerank(request))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context } from "effect"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Turning text into tokens, for sizing chunks, budgeting context, and
|
|
5
|
+
* estimating usage a provider does not report. Count with `encode(text).length`.
|
|
6
|
+
*
|
|
7
|
+
* Implementor contract: both methods are synchronous, so counting inside a loop
|
|
8
|
+
* never awaits; loading a vocabulary is the layer's job. `decode` inverts
|
|
9
|
+
* `encode`. Implement this only over a real vocabulary, never a heuristic:
|
|
10
|
+
* a character-count estimate is a plain function, not a service.
|
|
11
|
+
*/
|
|
12
|
+
export type TokenizerService = {
|
|
13
|
+
readonly encode: (text: string) => ReadonlyArray<number>
|
|
14
|
+
readonly decode: (tokens: ReadonlyArray<number>) => string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Tokenizer extends Context.Service<Tokenizer, TokenizerService>()(
|
|
18
|
+
"@betalyra/effect-uai/Tokenizer",
|
|
19
|
+
) {}
|