@effect-uai/core 0.15.0 → 0.17.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 +30 -16
- package/dist/{AiError-eLV9t1lU.d.mts → AiError-DvhLIbmd.d.mts} +15 -4
- package/dist/{AiError-eLV9t1lU.d.mts.map → AiError-DvhLIbmd.d.mts.map} +1 -1
- package/dist/{Loop-B54AB1ME.d.mts → Loop-ChpaO-ya.d.mts} +2 -2
- package/dist/{Loop-B54AB1ME.d.mts.map → Loop-ChpaO-ya.d.mts.map} +1 -1
- package/dist/{Toolkit-DAjJ9Tvl.d.mts → Toolkit-tlL0F2YR.d.mts} +2 -2
- package/dist/{Toolkit-DAjJ9Tvl.d.mts.map → Toolkit-tlL0F2YR.d.mts.map} +1 -1
- package/dist/chunker/Chunker.d.mts +1 -1
- package/dist/decision-model/Decision.d.mts +155 -0
- package/dist/decision-model/Decision.d.mts.map +1 -0
- package/dist/decision-model/Decision.mjs +118 -0
- package/dist/decision-model/Decision.mjs.map +1 -0
- package/dist/decision-model/Decision.test.mjs +164 -0
- package/dist/decision-model/Decision.test.mjs.map +1 -0
- package/dist/decision-model/DecisionModel.d.mts +45 -0
- package/dist/decision-model/DecisionModel.d.mts.map +1 -0
- package/dist/decision-model/DecisionModel.mjs +25 -0
- package/dist/decision-model/DecisionModel.mjs.map +1 -0
- package/dist/domain/AiError.d.mts +2 -2
- package/dist/domain/AiError.mjs +9 -2
- package/dist/domain/AiError.mjs.map +1 -1
- package/dist/domain/Realtime.d.mts +616 -0
- package/dist/domain/Realtime.d.mts.map +1 -0
- package/dist/domain/Realtime.mjs +21 -0
- package/dist/domain/Realtime.mjs.map +1 -0
- package/dist/domain/Transcript.d.mts +17 -3
- package/dist/domain/Transcript.d.mts.map +1 -1
- package/dist/domain/Transcript.mjs +30 -1
- package/dist/domain/Transcript.mjs.map +1 -1
- package/dist/domain/Transcript.test.d.mts +1 -0
- package/dist/domain/Transcript.test.mjs +110 -0
- package/dist/domain/Transcript.test.mjs.map +1 -0
- package/dist/embedding-model/EmbeddingModel.d.mts +1 -1
- package/dist/image-generator/ImageGenerator.d.mts +1 -1
- package/dist/index.d.mts +11 -5
- package/dist/index.mjs +9 -3
- package/dist/job/Job.d.mts +1 -1
- package/dist/language-model/LanguageModel.d.mts +2 -2
- package/dist/loop/Loop.d.mts +1 -1
- package/dist/math/Probability.d.mts +21 -0
- package/dist/math/Probability.d.mts.map +1 -0
- package/dist/math/Probability.mjs +31 -0
- package/dist/math/Probability.mjs.map +1 -0
- package/dist/math/Probability.test.d.mts +1 -0
- package/dist/math/Probability.test.mjs +95 -0
- package/dist/math/Probability.test.mjs.map +1 -0
- package/dist/music-generator/MusicGenerator.d.mts +1 -1
- package/dist/realtime/RealtimeSession.d.mts +50 -0
- package/dist/realtime/RealtimeSession.d.mts.map +1 -0
- package/dist/realtime/RealtimeSession.mjs +45 -0
- package/dist/realtime/RealtimeSession.mjs.map +1 -0
- package/dist/realtime/RealtimeSession.test.d.mts +1 -0
- package/dist/realtime/RealtimeSession.test.mjs +95 -0
- package/dist/realtime/RealtimeSession.test.mjs.map +1 -0
- package/dist/reranker/Reranker.d.mts +1 -1
- package/dist/research/DeepResearch.d.mts +1 -1
- package/dist/retry/Retry.d.mts +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +1 -1
- package/dist/streaming/Settle.d.mts +45 -0
- package/dist/streaming/Settle.d.mts.map +1 -0
- package/dist/streaming/Settle.mjs +95 -0
- package/dist/streaming/Settle.mjs.map +1 -0
- package/dist/streaming/Settle.test.d.mts +1 -0
- package/dist/streaming/Settle.test.mjs +252 -0
- package/dist/streaming/Settle.test.mjs.map +1 -0
- package/dist/streaming/WebSocketSession.d.mts +36 -0
- package/dist/streaming/WebSocketSession.d.mts.map +1 -0
- package/dist/streaming/WebSocketSession.mjs +89 -0
- package/dist/streaming/WebSocketSession.mjs.map +1 -0
- package/dist/streaming/WebSocketSession.test.d.mts +1 -0
- package/dist/streaming/WebSocketSession.test.mjs +51 -0
- package/dist/streaming/WebSocketSession.test.mjs.map +1 -0
- package/dist/testing/FakeWebSocket.d.mts +25 -0
- package/dist/testing/FakeWebSocket.d.mts.map +1 -0
- package/dist/testing/FakeWebSocket.mjs +79 -0
- package/dist/testing/FakeWebSocket.mjs.map +1 -0
- package/dist/testing/MockRealtimeSession.d.mts +30 -0
- package/dist/testing/MockRealtimeSession.d.mts.map +1 -0
- package/dist/testing/MockRealtimeSession.mjs +52 -0
- package/dist/testing/MockRealtimeSession.mjs.map +1 -0
- package/dist/tool/Toolkit.d.mts +1 -1
- package/dist/transcriber/Transcriber.d.mts +1 -1
- package/dist/web-read/WebRead.d.mts +1 -1
- package/dist/web-read/WebReadTool.d.mts +1 -1
- package/dist/web-search/WebSearch.d.mts +1 -1
- package/dist/web-search/WebSearchTool.d.mts +1 -1
- package/package.json +36 -4
- package/src/decision-model/Decision.test.ts +146 -0
- package/src/decision-model/Decision.ts +273 -0
- package/src/decision-model/DecisionModel.ts +53 -0
- package/src/domain/AiError.ts +11 -0
- package/src/domain/Realtime.ts +101 -0
- package/src/domain/Transcript.test.ts +98 -0
- package/src/domain/Transcript.ts +53 -1
- package/src/index.ts +7 -1
- package/src/math/Probability.test.ts +61 -0
- package/src/math/Probability.ts +44 -0
- package/src/realtime/RealtimeSession.test.ts +100 -0
- package/src/realtime/RealtimeSession.ts +77 -0
- package/src/streaming/Settle.test.ts +344 -0
- package/src/streaming/Settle.ts +196 -0
- package/src/streaming/WebSocketSession.test.ts +52 -0
- package/src/streaming/WebSocketSession.ts +132 -0
- package/src/testing/FakeWebSocket.ts +120 -0
- package/src/testing/MockRealtimeSession.ts +92 -0
- package/dist/inbox/Inbox.d.mts +0 -16
- package/dist/inbox/Inbox.d.mts.map +0 -1
- package/dist/inbox/Inbox.mjs +0 -28
- package/dist/inbox/Inbox.mjs.map +0 -1
- package/dist/inbox/Inbox.test.mjs +0 -42
- package/dist/inbox/Inbox.test.mjs.map +0 -1
- package/src/inbox/Inbox.test.ts +0 -52
- package/src/inbox/Inbox.ts +0 -33
- /package/dist/{inbox/Inbox.test.d.mts → decision-model/Decision.test.d.mts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Decision.test.mjs","names":["Decision.make","Decision.classify","Decision.rate","Decision.probability","Decision.probabilitiesOf","Decision.ranked","Decision.winner","Decision.topLevel","Decision.expectedLevel","Decision.confidence","Decision.margin","Decision.assertKinds","AiError.Unsupported"],"sources":["../../src/decision-model/Decision.test.ts"],"sourcesContent":["import { describe, it } from \"@effect/vitest\"\nimport { Effect, Layer, Option, Ref, Schema } from \"effect\"\nimport { expect, expectTypeOf } from \"vitest\"\nimport * as AiError from \"../domain/AiError.js\"\nimport * as Decision from \"./Decision.js\"\nimport { decide, DecisionModel, type DecisionModelService } from \"./DecisionModel.js\"\n\nconst triage = Decision.make({\n inputSchema: Schema.Struct({ message: Schema.String }),\n decisions: {\n department: Decision.classify({\n instructions: \"Which team should handle this?\",\n criteria: { billing: \"Payments, invoicing\", technical: \"Bugs, outages\" },\n }),\n severity: Decision.rate({\n instructions: \"How severe is it?\",\n criteria: [\"Cosmetic\", \"Degraded\", \"Blocking\"],\n }),\n urgent: Decision.probability({ instructions: \"Does this convey urgency?\" }),\n },\n})\n\nconst fixture = {\n department: { _tag: \"Classify\", labels: { billing: 0.62, technical: 0.38 } },\n severity: { _tag: \"Rate\", levels: [0, 0.7, 0.3], legend: [\"Cosmetic\", \"Degraded\", \"Blocking\"] },\n urgent: { _tag: \"Probability\", probability: 0.94 },\n} as const\n\n/**\n * A fixed fixture cannot prove it satisfies the caller's `Answers<D>`. This is\n * the boundary a provider casts at too, once it has decoded the wire.\n */\nconst fixed = <D extends Decision.Decisions>(\n answers: Readonly<Record<string, Decision.Answer>>,\n): Decision.Answers<D> => answers as Decision.Answers<D>\n\ntype Call = { readonly input: unknown; readonly model: string }\n\n/** A `DecisionModel` layer that records what reached it. */\nconst recording = Effect.gen(function* () {\n const calls = yield* Ref.make<ReadonlyArray<Call>>([])\n const service: DecisionModelService = {\n decide: (_definition, request) =>\n Effect.as(\n Ref.update(calls, (seen) => [...seen, { input: request.input, model: request.model }]),\n { answers: fixed(fixture), usage: {} },\n ),\n }\n return { calls, layer: Layer.succeed(DecisionModel, service) }\n})\n\ndescribe(\"the answer map is derived from the definition\", () => {\n it.effect(\"keeps each decision's label keys and rejects labels it never had\", () =>\n Effect.gen(function* () {\n const { calls, layer } = yield* recording\n const result = yield* decide(triage, {\n model: \"jev-latest\",\n input: { message: \"hi\" },\n }).pipe(Effect.provide(layer))\n\n expectTypeOf(result.answers.department.labels).toEqualTypeOf<{\n readonly billing: number\n readonly technical: number\n }>()\n // @ts-expect-error shipping is not a label of this decision\n result.answers.department.labels.shipping\n // @ts-expect-error a Probability answer has no labels\n result.answers.urgent.labels\n\n // `decide` forwards both arguments rather than dropping either.\n expect(yield* Ref.get(calls)).toEqual([{ input: { message: \"hi\" }, model: \"jev-latest\" }])\n }),\n )\n\n it(\"keeps the rubric as a tuple, so levels are positional rather than parsed\", () => {\n type Severity = (typeof triage)[\"decisions\"][\"severity\"]\n expectTypeOf<Decision.AnswerFor<Severity>[\"levels\"]>().toEqualTypeOf<\n readonly [number, number, number]\n >()\n expectTypeOf<Decision.AnswerFor<Severity>[\"legend\"]>().toEqualTypeOf<\n readonly [\"Cosmetic\", \"Degraded\", \"Blocking\"]\n >()\n })\n})\n\ndescribe(\"reading an answer\", () => {\n it(\"derives a Probability answer's distribution as [p, 1 - p]\", () => {\n const [yes, no] = Decision.probabilitiesOf(fixture.urgent)\n expect(yes).toBeCloseTo(0.94, 10)\n expect(no).toBeCloseTo(0.06, 10)\n })\n\n it(\"ranks labels best first and names the winner\", () => {\n expect(Decision.ranked(fixture.department)).toEqual([\n { label: \"billing\", probability: 0.62 },\n { label: \"technical\", probability: 0.38 },\n ])\n expect(Decision.winner(fixture.department)).toStrictEqual(Option.some(\"billing\"))\n })\n\n it(\"has no winner for an empty label set\", () => {\n expect(Decision.winner({ _tag: \"Classify\", labels: {} })).toStrictEqual(Option.none())\n })\n\n it(\"reads a rubric by index and by expected value\", () => {\n expect(Decision.topLevel(fixture.severity)).toBe(1)\n expect(Decision.expectedLevel(fixture.severity)).toBeCloseTo(1.3, 10)\n expect(fixture.severity.legend[Decision.topLevel(fixture.severity)]).toBe(\"Degraded\")\n })\n\n it(\"resolves a level tie to the lowest index\", () => {\n expect(Decision.topLevel({ _tag: \"Rate\", levels: [0.5, 0.5], legend: [\"a\", \"b\"] })).toBe(0)\n })\n\n it(\"computes certainty for every kind, including Probability\", () => {\n expect(Decision.confidence(fixture.urgent)).toBeCloseTo(0.67, 2)\n expect(Decision.margin(fixture.urgent)).toBeCloseTo(0.88, 10)\n expect(Decision.margin(fixture.department)).toBeCloseTo(0.24, 10)\n })\n})\n\ndescribe(\"assertKinds\", () => {\n const supported = [\"Classify\", \"Probability\"] as const\n\n it.effect(\"passes when every kind is supported\", () => {\n const { department, urgent } = triage.decisions\n return Decision.assertKinds({ department, urgent }, supported, \"nli\")\n })\n\n it.effect(\"fails Unsupported and names every offender at once\", () =>\n Effect.gen(function* () {\n const decisions = {\n ...triage.decisions,\n impact: Decision.rate({ instructions: \"How bad?\", criteria: [\"low\", \"high\"] }),\n }\n const error = yield* Effect.flip(Decision.assertKinds(decisions, supported, \"nli\"))\n\n expect(error).toBeInstanceOf(AiError.Unsupported)\n if (error._tag !== \"Unsupported\") return\n\n expect(error.reason).toContain('\"severity\" is a Rate')\n expect(error.reason).toContain('\"impact\" is a Rate')\n expect(error.reason).not.toContain(\"department\")\n }),\n )\n})\n"],"mappings":";;;;;;;;;AAOA,MAAM,SAASA,KAAc;CAC3B,aAAa,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,CAAC;CACrD,WAAW;EACT,YAAYC,SAAkB;GAC5B,cAAc;GACd,UAAU;IAAE,SAAS;IAAuB,WAAW;GAAgB;EACzE,CAAC;EACD,UAAUC,KAAc;GACtB,cAAc;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EACnE,aAAOE,WAAoB,QAAQ,MAAM,CAAC,CAAC,CAAC,YAAY,KAAM,CAAC;EAC/D,aAAOC,OAAgB,QAAQ,MAAM,CAAC,CAAC,CAAC,YAAY,KAAM,EAAE;EAC5D,aAAOA,OAAgB,QAAQ,UAAU,CAAC,CAAC,CAAC,YAAY,KAAM,EAAE;CAClE,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB;CAC5B,MAAM,YAAY,CAAC,YAAY,aAAa;CAE5C,GAAG,OAAO,6CAA6C;EACrD,MAAM,EAAE,YAAY,WAAW,OAAO;EACtC,OAAOC,YAAqB;GAAE;GAAY;EAAO,GAAG,WAAW,KAAK;CACtE,CAAC;CAED,GAAG,OAAO,4DACR,OAAO,IAAI,aAAa;EACtB,MAAM,YAAY;GAChB,GAAG,OAAO;GACV,QAAQT,KAAc;IAAE,cAAc;IAAY,UAAU,CAAC,OAAO,MAAM;GAAE,CAAC;EAC/E;EACA,MAAM,QAAQ,OAAO,OAAO,KAAKS,YAAqB,WAAW,WAAW,KAAK,CAAC;EAElF,aAAO,KAAK,CAAC,CAAC,eAAeC,WAAmB;EAChD,IAAI,MAAM,SAAS,eAAe;EAElC,aAAO,MAAM,MAAM,CAAC,CAAC,UAAU,wBAAsB;EACrD,aAAO,MAAM,MAAM,CAAC,CAAC,UAAU,sBAAoB;EACnD,aAAO,MAAM,MAAM,CAAC,CAAC,IAAI,UAAU,YAAY;CACjD,CAAC,CACH;AACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as AiError } from "../AiError-DvhLIbmd.mjs";
|
|
2
|
+
import { Answers, Decisions, Definition } from "./Decision.mjs";
|
|
3
|
+
import { Context, Effect } from "effect";
|
|
4
|
+
declare namespace DecisionModel_d_exports {
|
|
5
|
+
export { CommonDecideRequest, DecideResponse, DecideUsage, DecisionModel, DecisionModelService, decide };
|
|
6
|
+
}
|
|
7
|
+
/** Optional throughout: not every backing reports token counts. */
|
|
8
|
+
type DecideUsage = {
|
|
9
|
+
readonly inputTokens?: number;
|
|
10
|
+
readonly outputTokens?: number;
|
|
11
|
+
};
|
|
12
|
+
type DecideResponse<D extends Decisions = Decisions> = {
|
|
13
|
+
readonly answers: Answers<D>;
|
|
14
|
+
readonly usage: DecideUsage;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Cross-provider decide request. The input is billed once for the whole
|
|
18
|
+
* definition, so batching decisions is cheaper than repeating the input.
|
|
19
|
+
*/
|
|
20
|
+
type CommonDecideRequest<A> = {
|
|
21
|
+
readonly input: A;
|
|
22
|
+
/** Each provider narrows this to its typed literal union. */
|
|
23
|
+
readonly model: string;
|
|
24
|
+
};
|
|
25
|
+
type DecisionModelService = {
|
|
26
|
+
readonly decide: <A, D extends Decisions>(definition: Definition<A, D>, request: CommonDecideRequest<A>) => Effect.Effect<DecideResponse<D>, AiError>;
|
|
27
|
+
};
|
|
28
|
+
declare const DecisionModel_base: Context.ServiceClass<DecisionModel, "@betalyra/effect-uai/DecisionModel", DecisionModelService>;
|
|
29
|
+
/**
|
|
30
|
+
* Answering typed questions about an input with probabilities instead of
|
|
31
|
+
* generating text. The model reports beliefs; the decision stays in the
|
|
32
|
+
* caller's code.
|
|
33
|
+
*
|
|
34
|
+
* Implementor contract: answer every decision or fail. Omitting one leaves a
|
|
35
|
+
* hole where {@link DecideResponse} promises a key, so a kind the backing
|
|
36
|
+
* cannot express is rejected up front with `Decision.assertKinds`.
|
|
37
|
+
*
|
|
38
|
+
* @experimental The model class this abstracts is new and the shape may change.
|
|
39
|
+
*/
|
|
40
|
+
declare class DecisionModel extends DecisionModel_base {}
|
|
41
|
+
/** Answer a definition's decisions about one input in one call. */
|
|
42
|
+
declare const decide: <A, D extends Decisions>(definition: Definition<A, D>, request: CommonDecideRequest<A>) => Effect.Effect<DecideResponse<D>, AiError, DecisionModel>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { CommonDecideRequest, DecideResponse, DecideUsage, DecisionModel, DecisionModelService, decide, DecisionModel_d_exports as t };
|
|
45
|
+
//# sourceMappingURL=DecisionModel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionModel.d.mts","names":[],"sources":["../../src/decision-model/DecisionModel.ts"],"mappings":";;;;;;;KAKY;WACD;WACA;;KAGC,eAAe,UAAU,YAAqB;WAC/C,SAAS,QAAiB;WAC1B,OAAO;;;;;;KAON,oBAAoB;WACrB,OAAO;;WAEP;;KAGC;WACD,SAAS,GAAG,UAAU,WAC7B,YAAY,WAAoB,GAAG,IACnC,SAAS,oBAAoB,OAC1B,OAAO,OAAO,eAAe,IAAI;;;;;;;;;;;;;;cAc3B,sBAAsB;;cAKtB,SAAU,GAAG,UAAU,WAAkB,YACxC,WAAoB,GAAG,IAAE,SAC5B,oBAAoB,OAC5B,OAAO,OAAO,eAAe,IAAI,SAAiB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
//#region src/decision-model/DecisionModel.ts
|
|
4
|
+
var DecisionModel_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
DecisionModel: () => DecisionModel,
|
|
6
|
+
decide: () => decide
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Answering typed questions about an input with probabilities instead of
|
|
10
|
+
* generating text. The model reports beliefs; the decision stays in the
|
|
11
|
+
* caller's code.
|
|
12
|
+
*
|
|
13
|
+
* Implementor contract: answer every decision or fail. Omitting one leaves a
|
|
14
|
+
* hole where {@link DecideResponse} promises a key, so a kind the backing
|
|
15
|
+
* cannot express is rejected up front with `Decision.assertKinds`.
|
|
16
|
+
*
|
|
17
|
+
* @experimental The model class this abstracts is new and the shape may change.
|
|
18
|
+
*/
|
|
19
|
+
var DecisionModel = class extends Context.Service()("@betalyra/effect-uai/DecisionModel") {};
|
|
20
|
+
/** Answer a definition's decisions about one input in one call. */
|
|
21
|
+
const decide = (definition, request) => Effect.flatMap(DecisionModel, (m) => m.decide(definition, request));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DecisionModel, decide, DecisionModel_exports as t };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=DecisionModel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionModel.mjs","names":[],"sources":["../../src/decision-model/DecisionModel.ts"],"sourcesContent":["import { Context, Effect } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\nimport type * as Decision from \"./Decision.js\"\n\n/** Optional throughout: not every backing reports token counts. */\nexport type DecideUsage = {\n readonly inputTokens?: number\n readonly outputTokens?: number\n}\n\nexport type DecideResponse<D extends Decision.Decisions = Decision.Decisions> = {\n readonly answers: Decision.Answers<D>\n readonly usage: DecideUsage\n}\n\n/**\n * Cross-provider decide request. The input is billed once for the whole\n * definition, so batching decisions is cheaper than repeating the input.\n */\nexport type CommonDecideRequest<A> = {\n readonly input: A\n /** Each provider narrows this to its typed literal union. */\n readonly model: string\n}\n\nexport type DecisionModelService = {\n readonly decide: <A, D extends Decision.Decisions>(\n definition: Decision.Definition<A, D>,\n request: CommonDecideRequest<A>,\n ) => Effect.Effect<DecideResponse<D>, AiError.AiError>\n}\n\n/**\n * Answering typed questions about an input with probabilities instead of\n * generating text. The model reports beliefs; the decision stays in the\n * caller's code.\n *\n * Implementor contract: answer every decision or fail. Omitting one leaves a\n * hole where {@link DecideResponse} promises a key, so a kind the backing\n * cannot express is rejected up front with `Decision.assertKinds`.\n *\n * @experimental The model class this abstracts is new and the shape may change.\n */\nexport class DecisionModel extends Context.Service<DecisionModel, DecisionModelService>()(\n \"@betalyra/effect-uai/DecisionModel\",\n) {}\n\n/** Answer a definition's decisions about one input in one call. */\nexport const decide = <A, D extends Decision.Decisions>(\n definition: Decision.Definition<A, D>,\n request: CommonDecideRequest<A>,\n): Effect.Effect<DecideResponse<D>, AiError.AiError, DecisionModel> =>\n Effect.flatMap(DecisionModel, (m) => m.decide(definition, request))\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,IAAa,gBAAb,cAAmC,QAAQ,QAA6C,CAAC,CACvF,oCACF,CAAC,CAAC,CAAC;;AAGH,MAAa,UACX,YACA,YAEA,OAAO,QAAQ,gBAAgB,MAAM,EAAE,OAAO,YAAY,OAAO,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as Cancelled, c as GenerationFailed, d as RateLimited, f as Scope, g as
|
|
2
|
-
export { AiError, AuthFailed, AuthSubtype, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, Scope, Timeout, Unavailable, Unsupported, describe };
|
|
1
|
+
import { _ as describe, a as Cancelled, c as GenerationFailed, d as RateLimited, f as Scope, g as Unsupported, h as Unavailable, i as AuthSubtype, l as IncompleteTurn, m as Timeout, o as ContentFiltered, p as SessionExpired, r as AuthFailed, s as ContextLengthExceeded, t as AiError, u as InvalidRequest } from "../AiError-DvhLIbmd.mjs";
|
|
2
|
+
export { AiError, AuthFailed, AuthSubtype, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, Scope, SessionExpired, Timeout, Unavailable, Unsupported, describe };
|
package/dist/domain/AiError.mjs
CHANGED
|
@@ -10,6 +10,7 @@ var AiError_exports = /* @__PURE__ */ __exportAll({
|
|
|
10
10
|
IncompleteTurn: () => IncompleteTurn,
|
|
11
11
|
InvalidRequest: () => InvalidRequest,
|
|
12
12
|
RateLimited: () => RateLimited,
|
|
13
|
+
SessionExpired: () => SessionExpired,
|
|
13
14
|
Timeout: () => Timeout,
|
|
14
15
|
Unavailable: () => Unavailable,
|
|
15
16
|
Unsupported: () => Unsupported,
|
|
@@ -51,6 +52,11 @@ var IncompleteTurn = class extends Data.TaggedError("IncompleteTurn") {};
|
|
|
51
52
|
* (`TtsIncrementalText`, `SttStreaming`) on the R channel instead.
|
|
52
53
|
*/
|
|
53
54
|
var Unsupported = class extends Data.TaggedError("Unsupported") {};
|
|
55
|
+
/**
|
|
56
|
+
* A long-lived session hit the provider's lifetime cap. Distinct from
|
|
57
|
+
* `Unavailable`: reconnecting works, retrying the same session does not.
|
|
58
|
+
*/
|
|
59
|
+
var SessionExpired = class extends Data.TaggedError("SessionExpired") {};
|
|
54
60
|
const withReason = (base, reason) => reason === void 0 ? base : `${base}: ${reason}`;
|
|
55
61
|
/**
|
|
56
62
|
* Short human-readable description of an error, for logs and model-facing
|
|
@@ -67,9 +73,10 @@ const describe = Match.type().pipe(Match.discriminatorsExhaustive("_tag")({
|
|
|
67
73
|
Cancelled: (e) => `the ${e.provider} request was cancelled`,
|
|
68
74
|
IncompleteTurn: () => "the provider stream ended without completing",
|
|
69
75
|
GenerationFailed: (e) => e.message ?? `${e.provider} failed mid-generation`,
|
|
70
|
-
Unsupported: (e) => withReason(`${e.provider} does not support ${e.capability}`, e.reason)
|
|
76
|
+
Unsupported: (e) => withReason(`${e.provider} does not support ${e.capability}`, e.reason),
|
|
77
|
+
SessionExpired: (e) => `the ${e.provider} session reached its lifetime limit`
|
|
71
78
|
}));
|
|
72
79
|
//#endregion
|
|
73
|
-
export { AuthFailed, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, Timeout, Unavailable, Unsupported, describe, AiError_exports as t };
|
|
80
|
+
export { AuthFailed, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, SessionExpired, Timeout, Unavailable, Unsupported, describe, AiError_exports as t };
|
|
74
81
|
|
|
75
82
|
//# sourceMappingURL=AiError.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiError.mjs","names":[],"sources":["../../src/domain/AiError.ts"],"sourcesContent":["import { Data, Duration, Match } from \"effect\"\n\nexport type Scope = \"rpm\" | \"tpm\" | \"rpd\" | \"tpd\"\n\nexport class RateLimited extends Data.TaggedError(\"RateLimited\")<{\n provider: string\n retryAfter?: Duration.Duration\n scope?: Scope\n requestId?: string\n raw: unknown\n}> {}\n\nexport class Unavailable extends Data.TaggedError(\"Unavailable\")<{\n provider: string\n retryAfter?: Duration.Duration\n status?: number\n requestId?: string\n raw: unknown\n}> {}\n\nexport class Timeout extends Data.TaggedError(\"Timeout\")<{\n provider: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport class ContentFiltered extends Data.TaggedError(\"ContentFiltered\")<{\n provider: string\n reason?: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport class ContextLengthExceeded extends Data.TaggedError(\"ContextLengthExceeded\")<{\n provider: string\n modelLimit?: number\n requested?: number\n raw: unknown\n}> {}\n\nexport class InvalidRequest extends Data.TaggedError(\"InvalidRequest\")<{\n provider: string\n param?: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport type AuthSubtype = \"auth\" | \"permission\" | \"billing\" | \"quota\"\n\nexport class AuthFailed extends Data.TaggedError(\"AuthFailed\")<{\n provider: string\n subtype: AuthSubtype\n raw: unknown\n}> {}\n\nexport class Cancelled extends Data.TaggedError(\"Cancelled\")<{\n provider: string\n}> {}\n\n/**\n * The model errored mid-generation. Distinct from `Unavailable` (transport\n * problem before generation started) and from `IncompleteTurn` (provider\n * stream ended without a terminal event). The provider's own error message,\n * if any, is on `message`.\n */\nexport class GenerationFailed extends Data.TaggedError(\"GenerationFailed\")<{\n provider: string\n code?: string\n message?: string\n requestId?: string\n raw: unknown\n}> {}\n\n/**\n * The provider's delta stream ended without a terminal `TurnComplete`.\n * Indicates a misbehaving provider or a connection that dropped mid-flight.\n * Non-terminal deltas seen so far have already been emitted downstream.\n */\nexport class IncompleteTurn extends Data.TaggedError(\"IncompleteTurn\")<{\n raw?: unknown\n}> {}\n\n/**\n * The provider does not implement the requested capability for this\n * specific request. Distinct from `InvalidRequest` (the request shape is\n * malformed) and `AuthFailed` (the request was rejected).\n *\n * Reserved for request-data-dependent gaps where the provider supports\n * the method in general but not for these inputs — e.g. Google's\n * `streamSynthesisFrom` works only for Chirp 3 HD voices; calling it\n * with a Neural2 voice ID fails `Unsupported`.\n *\n * Blanket provider-level gaps (e.g. OpenAI has no incremental-text-in\n * TTS at all) are gated at compile time via capability marker tags\n * (`TtsIncrementalText`, `SttStreaming`) on the R channel instead.\n */\nexport class Unsupported extends Data.TaggedError(\"Unsupported\")<{\n provider: string\n capability: string\n reason?: string\n}> {}\n\nexport type AiError =\n | RateLimited\n | Unavailable\n | Timeout\n | ContentFiltered\n | ContextLengthExceeded\n | InvalidRequest\n | AuthFailed\n | Cancelled\n | IncompleteTurn\n | GenerationFailed\n | Unsupported\n\nconst withReason = (base: string, reason: string | undefined): string =>\n reason === undefined ? base : `${base}: ${reason}`\n\n/**\n * Short human-readable description of an error, for logs and model-facing\n * failure messages. Prose, not a contract; branch on `_tag` instead.\n */\nexport const describe: (e: AiError) => string = Match.type<AiError>().pipe(\n Match.discriminatorsExhaustive(\"_tag\")({\n RateLimited: (e) => `rate limited by ${e.provider}; try again later`,\n Unavailable: (e) => `${e.provider} is temporarily unavailable`,\n Timeout: (e) => `the ${e.provider} request timed out`,\n ContentFiltered: (e) => withReason(`blocked by ${e.provider}'s content filter`, e.reason),\n ContextLengthExceeded: (e) => `the request exceeded ${e.provider}'s context limit`,\n InvalidRequest: (e) =>\n e.param === undefined\n ? `${e.provider} rejected the request`\n : `${e.provider} rejected the request (param: ${e.param})`,\n AuthFailed: (e) => `authentication against ${e.provider} failed (${e.subtype})`,\n Cancelled: (e) => `the ${e.provider} request was cancelled`,\n IncompleteTurn: () => \"the provider stream ended without completing\",\n GenerationFailed: (e) => e.message ?? `${e.provider} failed mid-generation`,\n Unsupported: (e) => withReason(`${e.provider} does not support ${e.capability}`, e.reason),\n }),\n)\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiError.mjs","names":[],"sources":["../../src/domain/AiError.ts"],"sourcesContent":["import { Data, Duration, Match } from \"effect\"\n\nexport type Scope = \"rpm\" | \"tpm\" | \"rpd\" | \"tpd\"\n\nexport class RateLimited extends Data.TaggedError(\"RateLimited\")<{\n provider: string\n retryAfter?: Duration.Duration\n scope?: Scope\n requestId?: string\n raw: unknown\n}> {}\n\nexport class Unavailable extends Data.TaggedError(\"Unavailable\")<{\n provider: string\n retryAfter?: Duration.Duration\n status?: number\n requestId?: string\n raw: unknown\n}> {}\n\nexport class Timeout extends Data.TaggedError(\"Timeout\")<{\n provider: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport class ContentFiltered extends Data.TaggedError(\"ContentFiltered\")<{\n provider: string\n reason?: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport class ContextLengthExceeded extends Data.TaggedError(\"ContextLengthExceeded\")<{\n provider: string\n modelLimit?: number\n requested?: number\n raw: unknown\n}> {}\n\nexport class InvalidRequest extends Data.TaggedError(\"InvalidRequest\")<{\n provider: string\n param?: string\n requestId?: string\n raw: unknown\n}> {}\n\nexport type AuthSubtype = \"auth\" | \"permission\" | \"billing\" | \"quota\"\n\nexport class AuthFailed extends Data.TaggedError(\"AuthFailed\")<{\n provider: string\n subtype: AuthSubtype\n raw: unknown\n}> {}\n\nexport class Cancelled extends Data.TaggedError(\"Cancelled\")<{\n provider: string\n}> {}\n\n/**\n * The model errored mid-generation. Distinct from `Unavailable` (transport\n * problem before generation started) and from `IncompleteTurn` (provider\n * stream ended without a terminal event). The provider's own error message,\n * if any, is on `message`.\n */\nexport class GenerationFailed extends Data.TaggedError(\"GenerationFailed\")<{\n provider: string\n code?: string\n message?: string\n requestId?: string\n raw: unknown\n}> {}\n\n/**\n * The provider's delta stream ended without a terminal `TurnComplete`.\n * Indicates a misbehaving provider or a connection that dropped mid-flight.\n * Non-terminal deltas seen so far have already been emitted downstream.\n */\nexport class IncompleteTurn extends Data.TaggedError(\"IncompleteTurn\")<{\n raw?: unknown\n}> {}\n\n/**\n * The provider does not implement the requested capability for this\n * specific request. Distinct from `InvalidRequest` (the request shape is\n * malformed) and `AuthFailed` (the request was rejected).\n *\n * Reserved for request-data-dependent gaps where the provider supports\n * the method in general but not for these inputs — e.g. Google's\n * `streamSynthesisFrom` works only for Chirp 3 HD voices; calling it\n * with a Neural2 voice ID fails `Unsupported`.\n *\n * Blanket provider-level gaps (e.g. OpenAI has no incremental-text-in\n * TTS at all) are gated at compile time via capability marker tags\n * (`TtsIncrementalText`, `SttStreaming`) on the R channel instead.\n */\nexport class Unsupported extends Data.TaggedError(\"Unsupported\")<{\n provider: string\n capability: string\n reason?: string\n}> {}\n\n/**\n * A long-lived session hit the provider's lifetime cap. Distinct from\n * `Unavailable`: reconnecting works, retrying the same session does not.\n */\nexport class SessionExpired extends Data.TaggedError(\"SessionExpired\")<{\n provider: string\n raw?: unknown\n}> {}\n\nexport type AiError =\n | RateLimited\n | Unavailable\n | Timeout\n | ContentFiltered\n | ContextLengthExceeded\n | InvalidRequest\n | AuthFailed\n | Cancelled\n | IncompleteTurn\n | GenerationFailed\n | Unsupported\n | SessionExpired\n\nconst withReason = (base: string, reason: string | undefined): string =>\n reason === undefined ? base : `${base}: ${reason}`\n\n/**\n * Short human-readable description of an error, for logs and model-facing\n * failure messages. Prose, not a contract; branch on `_tag` instead.\n */\nexport const describe: (e: AiError) => string = Match.type<AiError>().pipe(\n Match.discriminatorsExhaustive(\"_tag\")({\n RateLimited: (e) => `rate limited by ${e.provider}; try again later`,\n Unavailable: (e) => `${e.provider} is temporarily unavailable`,\n Timeout: (e) => `the ${e.provider} request timed out`,\n ContentFiltered: (e) => withReason(`blocked by ${e.provider}'s content filter`, e.reason),\n ContextLengthExceeded: (e) => `the request exceeded ${e.provider}'s context limit`,\n InvalidRequest: (e) =>\n e.param === undefined\n ? `${e.provider} rejected the request`\n : `${e.provider} rejected the request (param: ${e.param})`,\n AuthFailed: (e) => `authentication against ${e.provider} failed (${e.subtype})`,\n Cancelled: (e) => `the ${e.provider} request was cancelled`,\n IncompleteTurn: () => \"the provider stream ended without completing\",\n GenerationFailed: (e) => e.message ?? `${e.provider} failed mid-generation`,\n Unsupported: (e) => withReason(`${e.provider} does not support ${e.capability}`, e.reason),\n SessionExpired: (e) => `the ${e.provider} session reached its lifetime limit`,\n }),\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAIA,IAAa,cAAb,cAAiC,KAAK,YAAY,aAAa,CAAC,CAM7D,CAAC;AAEJ,IAAa,cAAb,cAAiC,KAAK,YAAY,aAAa,CAAC,CAM7D,CAAC;AAEJ,IAAa,UAAb,cAA6B,KAAK,YAAY,SAAS,CAAC,CAIrD,CAAC;AAEJ,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAKrE,CAAC;AAEJ,IAAa,wBAAb,cAA2C,KAAK,YAAY,uBAAuB,CAAC,CAKjF,CAAC;AAEJ,IAAa,iBAAb,cAAoC,KAAK,YAAY,gBAAgB,CAAC,CAKnE,CAAC;AAIJ,IAAa,aAAb,cAAgC,KAAK,YAAY,YAAY,CAAC,CAI3D,CAAC;AAEJ,IAAa,YAAb,cAA+B,KAAK,YAAY,WAAW,CAAC,CAEzD,CAAC;;;;;;;AAQJ,IAAa,mBAAb,cAAsC,KAAK,YAAY,kBAAkB,CAAC,CAMvE,CAAC;;;;;;AAOJ,IAAa,iBAAb,cAAoC,KAAK,YAAY,gBAAgB,CAAC,CAEnE,CAAC;;;;;;;;;;;;;;;AAgBJ,IAAa,cAAb,cAAiC,KAAK,YAAY,aAAa,CAAC,CAI7D,CAAC;;;;;AAMJ,IAAa,iBAAb,cAAoC,KAAK,YAAY,gBAAgB,CAAC,CAGnE,CAAC;AAgBJ,MAAM,cAAc,MAAc,WAChC,WAAW,KAAA,IAAY,OAAO,GAAG,KAAK,IAAI;;;;;AAM5C,MAAa,WAAmC,MAAM,KAAc,CAAC,CAAC,KACpE,MAAM,yBAAyB,MAAM,CAAC,CAAC;CACrC,cAAc,MAAM,mBAAmB,EAAE,SAAS;CAClD,cAAc,MAAM,GAAG,EAAE,SAAS;CAClC,UAAU,MAAM,OAAO,EAAE,SAAS;CAClC,k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