@effect-uai/core 0.17.0 → 0.19.0-dev-20261109183959
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 +5 -5
- package/dist/Content-D_Qfn8Ja.d.mts +48 -0
- package/dist/Content-D_Qfn8Ja.d.mts.map +1 -0
- package/dist/File-B923KvZ9.d.mts +46 -0
- package/dist/File-B923KvZ9.d.mts.map +1 -0
- package/dist/{Image-Cv6iBLTy.d.mts → Image-Bzc1H_UK.d.mts} +19 -8
- package/dist/Image-Bzc1H_UK.d.mts.map +1 -0
- package/dist/{Items-C7MyrYPX.d.mts → Items-Bvx8s9QH.d.mts} +109 -16
- package/dist/Items-Bvx8s9QH.d.mts.map +1 -0
- package/dist/{Loop-ChpaO-ya.d.mts → Loop-CeA0AelN.d.mts} +7 -6
- package/dist/Loop-CeA0AelN.d.mts.map +1 -0
- package/dist/Tool-Bkryw6-h.d.mts +206 -0
- package/dist/Tool-Bkryw6-h.d.mts.map +1 -0
- package/dist/ToolEvent-9inLx5cI.d.mts +22 -0
- package/dist/ToolEvent-9inLx5cI.d.mts.map +1 -0
- package/dist/ToolOutput-BNTIQgGB.d.mts +151 -0
- package/dist/ToolOutput-BNTIQgGB.d.mts.map +1 -0
- package/dist/Toolkit-D2VGeD5R.d.mts +212 -0
- package/dist/Toolkit-D2VGeD5R.d.mts.map +1 -0
- package/dist/browser/BrowserTool.d.mts +84 -22
- package/dist/browser/BrowserTool.d.mts.map +1 -1
- package/dist/browser/BrowserTool.mjs +5 -0
- package/dist/browser/BrowserTool.mjs.map +1 -1
- package/dist/capabilities/Capabilities.d.mts +1 -1
- package/dist/decision-model/Decision.test.mjs +4 -4
- package/dist/dist-B5K-y4Be.mjs +191 -0
- package/dist/dist-B5K-y4Be.mjs.map +1 -0
- package/dist/dist-CorQTQL-.mjs +1533 -0
- package/dist/dist-CorQTQL-.mjs.map +1 -0
- package/dist/dist-DNeuh84d.mjs +7 -0
- package/dist/dist-DNeuh84d.mjs.map +1 -0
- package/dist/dist-DzeSyeYF.mjs +10253 -0
- package/dist/dist-DzeSyeYF.mjs.map +1 -0
- package/dist/domain/File.d.mts +2 -0
- package/dist/domain/File.mjs +51 -0
- package/dist/domain/File.mjs.map +1 -0
- package/dist/domain/Image.d.mts +2 -2
- package/dist/domain/Image.mjs +12 -2
- package/dist/domain/Image.mjs.map +1 -1
- package/dist/domain/Items.d.mts +2 -2
- package/dist/domain/Items.mjs +65 -4
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Realtime.d.mts +72 -490
- package/dist/domain/Realtime.d.mts.map +1 -1
- package/dist/domain/Research.d.mts +1 -1
- package/dist/domain/Transcript.test.mjs +3 -3
- package/dist/domain/Turn.d.mts +57 -262
- package/dist/domain/Turn.d.mts.map +1 -1
- package/dist/domain/Turn.mjs +1 -1
- package/dist/domain/Turn.test.mjs +2 -2
- package/dist/embedding-model/Embedding.d.mts +1 -1
- package/dist/embedding-model/EmbeddingModel.test.mjs +2 -2
- package/dist/embedding-model/EmbeddingModel.test.mjs.map +1 -1
- package/dist/image-generator/ImageGenerator.d.mts +10 -66
- package/dist/image-generator/ImageGenerator.d.mts.map +1 -1
- package/dist/index.C4tKZ0yW-LuFnBtmu.mjs +7042 -0
- package/dist/index.C4tKZ0yW-LuFnBtmu.mjs.map +1 -0
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +7 -6
- package/dist/language-model/LanguageModel.d.mts +2 -2
- package/dist/language-model/LanguageModel.test.mjs +2 -2
- package/dist/loop/Loop.d.mts +1 -1
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.mjs +3 -3
- package/dist/math/Probability.test.mjs +2 -2
- package/dist/messenger/Messenger.d.mts +43 -289
- package/dist/messenger/Messenger.d.mts.map +1 -1
- package/dist/messenger/MessengerAdapter.test.mjs +3 -3
- package/dist/music-generator/MusicGenerator.test.mjs +3 -3
- package/dist/observability/Metrics.d.mts +1 -1
- package/dist/observability/Metrics.test.mjs +3 -3
- package/dist/observability/Telemetry.d.mts +1 -1
- package/dist/observability/Telemetry.mjs +1 -1
- package/dist/observability/Telemetry.mjs.map +1 -1
- package/dist/observability/Telemetry.test.mjs +4 -4
- package/dist/observability/Telemetry.test.mjs.map +1 -1
- package/dist/realtime/RealtimeSession.d.mts +1 -1
- package/dist/realtime/RealtimeSession.test.mjs +4 -4
- package/dist/retry/Retry.test.mjs +2 -2
- package/dist/sandbox/Sandbox.d.mts +32 -237
- package/dist/sandbox/Sandbox.d.mts.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +3 -3
- package/dist/streaming/JSONL.test.mjs +2 -2
- package/dist/streaming/Multipart.d.mts +1 -1
- package/dist/streaming/Multipart.mjs +3 -2
- package/dist/streaming/Multipart.mjs.map +1 -1
- package/dist/streaming/Multipart.test.mjs +28 -0
- package/dist/streaming/Multipart.test.mjs.map +1 -0
- package/dist/streaming/SSE.d.mts +1 -1
- package/dist/streaming/SSE.mjs +2 -2
- package/dist/streaming/SSE.mjs.map +1 -1
- package/dist/streaming/SSE.test.mjs +2 -2
- package/dist/streaming/Settle.test.mjs +3 -3
- package/dist/streaming/WebSocketSession.d.mts +5 -3
- package/dist/streaming/WebSocketSession.d.mts.map +1 -1
- package/dist/streaming/WebSocketSession.mjs +22 -10
- package/dist/streaming/WebSocketSession.mjs.map +1 -1
- package/dist/streaming/WebSocketSession.test.mjs +41 -5
- package/dist/streaming/WebSocketSession.test.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.test.mjs +2 -2
- package/dist/testing/FakeWebSocket.d.mts +5 -1
- package/dist/testing/FakeWebSocket.d.mts.map +1 -1
- package/dist/testing/FakeWebSocket.mjs +12 -6
- package/dist/testing/FakeWebSocket.mjs.map +1 -1
- package/dist/testing/MockMessenger.d.mts +19 -134
- package/dist/testing/MockMessenger.d.mts.map +1 -1
- package/dist/testing/MockProvider.d.mts +1 -1
- package/dist/testing/MockSandbox.d.mts +65 -446
- package/dist/testing/MockSandbox.d.mts.map +1 -1
- package/dist/tool/Content.d.mts +2 -0
- package/dist/tool/Content.mjs +46 -0
- package/dist/tool/Content.mjs.map +1 -0
- package/dist/tool/Content.test.d.mts +1 -0
- package/dist/tool/Content.test.mjs +48 -0
- package/dist/tool/Content.test.mjs.map +1 -0
- package/dist/tool/HistoryCheck.d.mts +6 -15
- package/dist/tool/HistoryCheck.d.mts.map +1 -1
- package/dist/tool/HistoryCheck.mjs +10 -24
- package/dist/tool/HistoryCheck.mjs.map +1 -1
- package/dist/tool/Tool.d.mts +2 -2
- package/dist/tool/Tool.mjs +55 -130
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/Tool.test.mjs +222 -178
- package/dist/tool/Tool.test.mjs.map +1 -1
- package/dist/tool/ToolDecision.d.mts +164 -0
- package/dist/tool/ToolDecision.d.mts.map +1 -0
- package/dist/tool/ToolDecision.mjs +146 -0
- package/dist/tool/ToolDecision.mjs.map +1 -0
- package/dist/tool/ToolDecision.test.d.mts +1 -0
- package/dist/tool/ToolDecision.test.mjs +330 -0
- package/dist/tool/ToolDecision.test.mjs.map +1 -0
- package/dist/tool/ToolEvent.d.mts +2 -2
- package/dist/tool/ToolEvent.mjs +2 -34
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/ToolOutput.d.mts +2 -0
- package/dist/tool/ToolOutput.mjs +128 -0
- package/dist/tool/ToolOutput.mjs.map +1 -0
- package/dist/tool/ToolOutput.test.d.mts +1 -0
- package/dist/tool/ToolOutput.test.mjs +153 -0
- package/dist/tool/ToolOutput.test.mjs.map +1 -0
- package/dist/tool/Toolkit.d.mts +2 -2
- package/dist/tool/Toolkit.mjs +230 -165
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.mjs +433 -391
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/dist/transcriber/Transcriber.test.mjs +3 -3
- package/dist/web-read/WebReadTool.d.mts +2 -2
- package/dist/web-read/WebReadTool.mjs +1 -0
- package/dist/web-read/WebReadTool.mjs.map +1 -1
- package/dist/web-search/WebSearchTool.d.mts +2 -2
- package/dist/web-search/WebSearchTool.mjs +1 -0
- package/dist/web-search/WebSearchTool.mjs.map +1 -1
- package/package.json +18 -10
- package/src/browser/BrowserTool.ts +5 -0
- package/src/domain/File.ts +79 -0
- package/src/domain/Image.ts +14 -4
- package/src/domain/Items.ts +39 -3
- package/src/embedding-model/EmbeddingModel.test.ts +2 -2
- package/src/index.ts +3 -2
- package/src/loop/Loop.ts +25 -14
- package/src/observability/Telemetry.test.ts +1 -1
- package/src/observability/Telemetry.ts +2 -2
- package/src/streaming/Multipart.test.ts +26 -0
- package/src/streaming/Multipart.ts +6 -5
- package/src/streaming/SSE.ts +2 -2
- package/src/streaming/WebSocketSession.test.ts +54 -2
- package/src/streaming/WebSocketSession.ts +27 -6
- package/src/structured-format/StructuredFormat.ts +1 -1
- package/src/testing/FakeWebSocket.ts +21 -6
- package/src/tool/Content.test.ts +40 -0
- package/src/tool/Content.ts +38 -0
- package/src/tool/HistoryCheck.ts +21 -26
- package/src/tool/Tool.test.ts +240 -241
- package/src/tool/Tool.ts +204 -309
- package/src/tool/ToolDecision.test.ts +301 -0
- package/src/tool/ToolDecision.ts +360 -0
- package/src/tool/ToolEvent.ts +21 -41
- package/src/tool/ToolOutput.test.ts +132 -0
- package/src/tool/ToolOutput.ts +198 -0
- package/src/tool/Toolkit.test.ts +594 -454
- package/src/tool/Toolkit.ts +631 -356
- package/src/web-read/WebReadTool.ts +2 -1
- package/src/web-search/WebSearchTool.ts +2 -1
- package/dist/Image-Cv6iBLTy.d.mts.map +0 -1
- package/dist/Items-C7MyrYPX.d.mts.map +0 -1
- package/dist/Loop-ChpaO-ya.d.mts.map +0 -1
- package/dist/Tool-BF78QWtn.d.mts +0 -314
- package/dist/Tool-BF78QWtn.d.mts.map +0 -1
- package/dist/ToolEvent-Di4a723B.d.mts +0 -144
- package/dist/ToolEvent-Di4a723B.d.mts.map +0 -1
- package/dist/ToolResult-BsYQRjmW.d.mts +0 -152
- package/dist/ToolResult-BsYQRjmW.d.mts.map +0 -1
- package/dist/Toolkit-tlL0F2YR.d.mts +0 -193
- package/dist/Toolkit-tlL0F2YR.d.mts.map +0 -1
- package/dist/dist-BaenoU1A.mjs +0 -145
- package/dist/dist-BaenoU1A.mjs.map +0 -1
- package/dist/dist-nohcnkD6.mjs +0 -182
- package/dist/dist-nohcnkD6.mjs.map +0 -1
- package/dist/magic-string.es-CB2hOw9v.mjs +0 -1014
- package/dist/magic-string.es-CB2hOw9v.mjs.map +0 -1
- package/dist/test.DNmyFkvJ-YPzDR0Co.mjs +0 -10254
- package/dist/test.DNmyFkvJ-YPzDR0Co.mjs.map +0 -1
- package/dist/tool/Approval.d.mts +0 -113
- package/dist/tool/Approval.d.mts.map +0 -1
- package/dist/tool/Approval.mjs +0 -80
- package/dist/tool/Approval.mjs.map +0 -1
- package/dist/tool/Approval.test.mjs +0 -371
- package/dist/tool/Approval.test.mjs.map +0 -1
- package/dist/tool/ToolResult.d.mts +0 -2
- package/dist/tool/ToolResult.mjs +0 -85
- package/dist/tool/ToolResult.mjs.map +0 -1
- package/dist/utils-CiH_DjFW.mjs +0 -3918
- package/dist/utils-CiH_DjFW.mjs.map +0 -1
- package/src/tool/Approval.test.ts +0 -400
- package/src/tool/Approval.ts +0 -181
- package/src/tool/ToolResult.ts +0 -114
- /package/dist/{tool/Approval.test.d.mts → streaming/Multipart.test.d.mts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { audioEvent, controlInput, promptsInput, singleVariant } from "../domain/Music.mjs";
|
|
2
2
|
import { generate, streamGeneration, streamGenerationFrom } from "./MusicGenerator.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { n as globalExpect } from "../
|
|
5
|
-
import { t as import_dist } from "../dist-
|
|
3
|
+
import { b as it, m as describe } from "../dist-DzeSyeYF.mjs";
|
|
4
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
5
|
+
import { t as import_dist } from "../dist-DNeuh84d.mjs";
|
|
6
6
|
import { layer, layerWithoutInteractive } from "../testing/MockMusicGenerator.mjs";
|
|
7
7
|
import { Duration, Effect, Stream } from "effect";
|
|
8
8
|
//#region src/music-generator/MusicGenerator.test.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TurnEvent } from "../domain/Turn.mjs";
|
|
2
2
|
import { computeThroughputTick, isMetricEvent, makeEvent, metricEvents, throughput, timeToCompletion, timeToFirstToken, tokenTotals } from "./Metrics.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { n as globalExpect } from "../
|
|
5
|
-
import { t as it } from "../dist-
|
|
3
|
+
import { m as describe } from "../dist-DzeSyeYF.mjs";
|
|
4
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
5
|
+
import { t as it } from "../dist-B5K-y4Be.mjs";
|
|
6
6
|
import { Array, Duration, Effect, Fiber, Option, Stream } from "effect";
|
|
7
7
|
import * as TestClock from "effect/testing/TestClock";
|
|
8
8
|
//#region src/observability/Metrics.test.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { isMetricEvent } from "./Metrics.mjs";
|
|
3
3
|
import { Effect, Layer, Match, Metric, Stream } from "effect";
|
|
4
|
-
import { OtlpMetrics, OtlpSerialization } from "effect/
|
|
4
|
+
import { OtlpMetrics, OtlpSerialization } from "effect/observability";
|
|
5
5
|
//#region src/observability/Telemetry.ts
|
|
6
6
|
var Telemetry_exports = /* @__PURE__ */ __exportAll({
|
|
7
7
|
layerOtlp: () => layerOtlp,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Telemetry.mjs","names":[],"sources":["../../src/observability/Telemetry.ts"],"sourcesContent":["import { Duration, Effect, Layer, Match, Metric, Stream } from \"effect\"\nimport type { HttpClient } from \"effect/
|
|
1
|
+
{"version":3,"file":"Telemetry.mjs","names":[],"sources":["../../src/observability/Telemetry.ts"],"sourcesContent":["import { Duration, Effect, Layer, Match, Metric, Stream } from \"effect\"\nimport type { HttpClient } from \"effect/http\"\nimport { OtlpMetrics, OtlpSerialization } from \"effect/observability\"\nimport { isMetricEvent, type Measurement, type MetricEvent } from \"./Metrics.js\"\n\n// ---------------------------------------------------------------------------\n// The agnostic recorder\n// ---------------------------------------------------------------------------\n\n/**\n * Histogram bucket boundaries used for every histogram measurement (the only\n * built-in one is throughput). Custom histogram metrics share these; a metric\n * that needs bespoke boundaries can update its own instrument directly instead\n * of routing through `record`.\n */\nconst histogramBoundaries = Metric.exponentialBoundaries({ start: 1, factor: 2, count: 16 })\n\n/**\n * Build the effect `Metric` instrument a measurement maps to. Dispatches on\n * `kind`, never on the event `_tag`, so a new built-in or custom metric needs\n * no change here. Instruments dedupe by name in the global registry, so a fresh\n * instance per call accumulates onto the same series (no cache needed).\n */\nconst buildInstrument = (m: Measurement): Metric.Metric<any, any> =>\n Match.value(m.kind).pipe(\n Match.when(\"counter\", () => Metric.counter(m.name, { incremental: true })),\n Match.when(\"histogram\", () => Metric.histogram(m.name, { boundaries: histogramBoundaries })),\n Match.when(\"timer\", () => Metric.timer(m.name)),\n Match.when(\"gauge\", () => Metric.gauge(m.name)),\n Match.exhaustive,\n )\n\nconst mergeAttributes = (\n base: Readonly<Record<string, string>> | undefined,\n extra: Readonly<Record<string, string>> | undefined,\n): Readonly<Record<string, string>> | undefined =>\n base === undefined ? extra : extra === undefined ? base : { ...base, ...extra }\n\nconst recordEvent = (\n ev: MetricEvent,\n baseAttributes: Readonly<Record<string, string>> | undefined,\n): Effect.Effect<void> =>\n Effect.forEach(\n ev.measurements,\n (m) => {\n const attributes = mergeAttributes(baseAttributes, m.attributes)\n const base = buildInstrument(m)\n const instrument = attributes === undefined ? base : Metric.withAttributes(base, attributes)\n return Metric.update(instrument, m.value)\n },\n { discard: true },\n )\n\nexport type RecordOptions = {\n /** Attributes applied to every recorded metric, e.g. `{ model, provider }`. */\n readonly attributes?: Readonly<Record<string, string>>\n}\n\n/**\n * Record every measurement on every metric event into effect `Metric`\n * instruments, then pass events through unchanged. Matches events structurally\n * (`isMetricEvent`), so it records built-in and custom metrics alike, and\n * dispatches on `measurement.kind`, never on the event tag. Sits mid-pipeline\n * before the transport. Provide an OTLP (or Prometheus) layer to export the\n * instruments it populates.\n */\nexport const record =\n (options?: RecordOptions) =>\n <A, E, R>(self: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>\n self.pipe(\n Stream.tap((ev) => (isMetricEvent(ev) ? recordEvent(ev, options?.attributes) : Effect.void)),\n )\n\n// ---------------------------------------------------------------------------\n// OTLP wiring\n// ---------------------------------------------------------------------------\n\nexport type LayerOtlpOptions = {\n readonly url: string\n readonly resource?: {\n readonly serviceName?: string\n readonly serviceVersion?: string\n }\n readonly exportInterval?: Duration.Input\n}\n\n/**\n * Convenience layer that exports recorded metrics over OTLP. Provides the JSON\n * serializer and leaves `HttpClient` as a requirement, so the platform's client\n * (FetchHttpClient, NodeHttpClient, ...) is provided at the edge. This keeps\n * the library platform-independent.\n */\nexport const layerOtlp = (\n options: LayerOtlpOptions,\n): Layer.Layer<never, never, HttpClient.HttpClient> =>\n OtlpMetrics.layer(options).pipe(Layer.provide(OtlpSerialization.layerJson))\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,sBAAsB,OAAO,sBAAsB;CAAE,OAAO;CAAG,QAAQ;CAAG,OAAO;AAAG,CAAC;;;;;;;AAQ3F,MAAM,mBAAmB,MACvB,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,KAClB,MAAM,KAAK,iBAAiB,OAAO,QAAQ,EAAE,MAAM,EAAE,aAAa,KAAK,CAAC,CAAC,GACzE,MAAM,KAAK,mBAAmB,OAAO,UAAU,EAAE,MAAM,EAAE,YAAY,oBAAoB,CAAC,CAAC,GAC3F,MAAM,KAAK,eAAe,OAAO,MAAM,EAAE,IAAI,CAAC,GAC9C,MAAM,KAAK,eAAe,OAAO,MAAM,EAAE,IAAI,CAAC,GAC9C,MAAM,UACR;AAEF,MAAM,mBACJ,MACA,UAEA,SAAS,KAAA,IAAY,QAAQ,UAAU,KAAA,IAAY,OAAO;CAAE,GAAG;CAAM,GAAG;AAAM;AAEhF,MAAM,eACJ,IACA,mBAEA,OAAO,QACL,GAAG,eACF,MAAM;CACL,MAAM,aAAa,gBAAgB,gBAAgB,EAAE,UAAU;CAC/D,MAAM,OAAO,gBAAgB,CAAC;CAC9B,MAAM,aAAa,eAAe,KAAA,IAAY,OAAO,OAAO,eAAe,MAAM,UAAU;CAC3F,OAAO,OAAO,OAAO,YAAY,EAAE,KAAK;AAC1C,GACA,EAAE,SAAS,KAAK,CAClB;;;;;;;;;AAeF,MAAa,UACV,aACS,SACR,KAAK,KACH,OAAO,KAAK,OAAQ,cAAc,EAAE,IAAI,YAAY,IAAI,SAAS,UAAU,IAAI,OAAO,IAAK,CAC7F;;;;;;;AAqBJ,MAAa,aACX,YAEA,YAAY,MAAM,OAAO,CAAC,CAAC,KAAK,MAAM,QAAQ,kBAAkB,SAAS,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { makeEvent } from "./Metrics.mjs";
|
|
2
2
|
import { layerOtlp, record } from "./Telemetry.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { n as globalExpect } from "../
|
|
5
|
-
import { t as it } from "../dist-
|
|
3
|
+
import { m as describe } from "../dist-DzeSyeYF.mjs";
|
|
4
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
5
|
+
import { t as it } from "../dist-B5K-y4Be.mjs";
|
|
6
6
|
import { Array, Duration, Effect, Layer, Metric, Option, Ref, Stream } from "effect";
|
|
7
|
-
import { HttpClient, HttpClientResponse } from "effect/
|
|
7
|
+
import { HttpClient, HttpClientResponse } from "effect/http";
|
|
8
8
|
//#region src/observability/Telemetry.test.ts
|
|
9
9
|
const event = (measurements) => makeEvent({
|
|
10
10
|
_tag: "Test",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Telemetry.test.mjs","names":["Arr"],"sources":["../../src/observability/Telemetry.test.ts"],"sourcesContent":["import { describe, it } from \"@effect/vitest\"\nimport { Array as Arr, Duration, Effect, Layer, Metric, Option, Ref, Stream } from \"effect\"\nimport { type HttpBody, HttpClient, HttpClientResponse } from \"effect/
|
|
1
|
+
{"version":3,"file":"Telemetry.test.mjs","names":["Arr"],"sources":["../../src/observability/Telemetry.test.ts"],"sourcesContent":["import { describe, it } from \"@effect/vitest\"\nimport { Array as Arr, Duration, Effect, Layer, Metric, Option, Ref, Stream } from \"effect\"\nimport { type HttpBody, HttpClient, HttpClientResponse } from \"effect/http\"\nimport { expect } from \"vitest\"\nimport { type Measurement, makeEvent } from \"./Metrics.js\"\nimport { layerOtlp, record } from \"./Telemetry.js\"\n\nconst event = (measurements: ReadonlyArray<Measurement>) =>\n makeEvent({ _tag: \"Test\", turnIndex: 0, measurements })\n\n// Each test gets a fresh registry so instruments do not leak across tests.\nconst isolated = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n Effect.provideService(self, Metric.MetricRegistry, new Map())\n\nconst findById = (snap: ReadonlyArray<Metric.Metric.Snapshot>, id: string) =>\n Option.getOrThrow(Arr.findFirst(snap, (s) => s.id === id))\n\ndescribe(\"record\", () => {\n it.effect(\"accumulates a counter measurement across events\", () =>\n isolated(\n Effect.gen(function* () {\n const ev = event([{ name: \"rec_counter\", kind: \"counter\", value: 5 }])\n yield* Stream.make(ev, ev).pipe(record(), Stream.runDrain)\n const snap = yield* Metric.snapshot\n const c = findById(snap, \"rec_counter\")\n expect(c.type).toBe(\"Counter\")\n expect((c.state as { readonly count: number }).count).toBe(10)\n }),\n ),\n )\n\n it.effect(\"records a timer measurement as a histogram observation\", () =>\n isolated(\n Effect.gen(function* () {\n const ev = event([{ name: \"rec_timer\", kind: \"timer\", value: Duration.millis(100) }])\n yield* Stream.make(ev).pipe(record(), Stream.runDrain)\n const snap = yield* Metric.snapshot\n const h = findById(snap, \"rec_timer\")\n expect(h.type).toBe(\"Histogram\")\n expect((h.state as { readonly count: number }).count).toBe(1)\n }),\n ),\n )\n\n it.effect(\"applies base attributes to every recorded metric\", () =>\n isolated(\n Effect.gen(function* () {\n const ev = event([{ name: \"rec_attr\", kind: \"counter\", value: 1 }])\n yield* Stream.make(ev).pipe(\n record({ attributes: { model: \"test-model\" } }),\n Stream.runDrain,\n )\n const snap = yield* Metric.snapshot\n const c = findById(snap, \"rec_attr\")\n expect(c.attributes).toMatchObject({ model: \"test-model\" })\n }),\n ),\n )\n\n it.effect(\"records a custom metric with a novel name, unchanged recorder\", () =>\n isolated(\n Effect.gen(function* () {\n // A user-defined event the recorder has never seen: still exported.\n const custom = makeEvent({\n _tag: \"ToolLatency\",\n turnIndex: 0,\n measurements: [{ name: \"myapp_tool_latency_total\", kind: \"counter\", value: 3 }],\n })\n yield* Stream.make(custom).pipe(record(), Stream.runDrain)\n const snap = yield* Metric.snapshot\n const c = findById(snap, \"myapp_tool_latency_total\")\n expect((c.state as { readonly count: number }).count).toBe(3)\n }),\n ),\n )\n\n it.effect(\"passes non-metric elements through untouched\", () =>\n isolated(\n Effect.gen(function* () {\n const out = yield* Stream.make(\"a\", \"b\", \"c\").pipe(record(), Stream.runCollect)\n expect(out).toEqual([\"a\", \"b\", \"c\"])\n }),\n ),\n )\n})\n\nconst bodyToString = (body: HttpBody.HttpBody): string =>\n body._tag === \"Uint8Array\" ? new TextDecoder().decode(body.body) : \"\"\n\ndescribe(\"layerOtlp\", () => {\n it.effect(\"exports recorded metrics over OTLP via a mock HttpClient\", () =>\n isolated(\n Effect.gen(function* () {\n const bodies = yield* Ref.make<ReadonlyArray<string>>([])\n const mockClient = HttpClient.make((request) =>\n Ref.update(bodies, (b) => [...b, bodyToString(request.body)]).pipe(\n Effect.as(HttpClientResponse.fromWeb(request, new Response(\"{}\", { status: 200 }))),\n ),\n )\n const clientLayer = Layer.succeed(HttpClient.HttpClient, mockClient)\n const ev = event([{ name: \"otlp_export_counter\", kind: \"counter\", value: 3 }])\n\n // Provide the OTLP layer scoped to the recording program. The exporter\n // flushes on scope close (interval is long, so we rely on the flush).\n yield* Stream.make(ev).pipe(\n record(),\n Stream.runDrain,\n Effect.provide(\n layerOtlp({\n url: \"http://localhost:4318/v1/metrics\",\n resource: { serviceName: \"test-service\" },\n exportInterval: \"10 minutes\",\n }).pipe(Layer.provide(clientLayer)),\n ),\n )\n\n const captured = yield* Ref.get(bodies)\n expect(captured.length).toBeGreaterThanOrEqual(1)\n expect(captured.join(\"\\n\")).toContain(\"otlp_export_counter\")\n }),\n ),\n )\n})\n"],"mappings":";;;;;;;;AAOA,MAAM,SAAS,iBACb,UAAU;CAAE,MAAM;CAAQ,WAAW;CAAG;AAAa,CAAC;AAGxD,MAAM,YAAqB,SACzB,OAAO,eAAe,MAAM,OAAO,gCAAgB,IAAI,IAAI,CAAC;AAE9D,MAAM,YAAY,MAA6C,OAC7D,OAAO,WAAWA,MAAI,UAAU,OAAO,MAAM,EAAE,OAAO,EAAE,CAAC;AAE3D,SAAS,gBAAgB;CACvB,GAAG,OAAO,yDACR,SACE,OAAO,IAAI,aAAa;EACtB,MAAM,KAAK,MAAM,CAAC;GAAE,MAAM;GAAe,MAAM;GAAW,OAAO;EAAE,CAAC,CAAC;EACrE,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC,CAAC,KAAK,OAAO,GAAG,OAAO,QAAQ;EACzD,MAAM,OAAO,OAAO,OAAO;EAC3B,MAAM,IAAI,SAAS,MAAM,aAAa;EACtC,aAAO,EAAE,IAAI,CAAC,CAAC,KAAK,SAAS;EAC7B,aAAQ,EAAE,MAAqC,KAAK,CAAC,CAAC,KAAK,EAAE;CAC/D,CAAC,CACH,CACF;CAEA,GAAG,OAAO,gEACR,SACE,OAAO,IAAI,aAAa;EACtB,MAAM,KAAK,MAAM,CAA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
|
2
2
|
import { t as AiError } from "../AiError-DvhLIbmd.mjs";
|
|
3
3
|
import { CommonSessionRequest, RealtimeEvent, RealtimeInput } from "../domain/Realtime.mjs";
|
|
4
4
|
import { Context, Effect, Scope, Stream } from "effect";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { imageBase64 } from "../domain/Image.mjs";
|
|
2
2
|
import { RealtimeEvent, RealtimeInput } from "../domain/Realtime.mjs";
|
|
3
3
|
import { open, sendVideoFrame, toolCalls } from "./RealtimeSession.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { n as globalExpect } from "../
|
|
6
|
-
import { t as import_dist } from "../dist-
|
|
7
|
-
import { t as it } from "../dist-
|
|
4
|
+
import { m as describe } from "../dist-DzeSyeYF.mjs";
|
|
5
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
6
|
+
import { t as import_dist } from "../dist-DNeuh84d.mjs";
|
|
7
|
+
import { t as it } from "../dist-B5K-y4Be.mjs";
|
|
8
8
|
import { layer, layerAudioOnly } from "../testing/MockRealtimeSession.mjs";
|
|
9
9
|
import { Effect, Stream } from "effect";
|
|
10
10
|
//#region src/realtime/RealtimeSession.test.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContentFiltered, RateLimited, Timeout, Unavailable } from "../domain/AiError.mjs";
|
|
2
2
|
import { effect, stream } from "./Retry.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { n as globalExpect } from "../
|
|
3
|
+
import { b as it, m as describe } from "../dist-DzeSyeYF.mjs";
|
|
4
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
5
5
|
import { Cause, Effect, Exit, Option, Ref, Schedule, Stream } from "effect";
|
|
6
6
|
//#region src/retry/Retry.test.ts
|
|
7
7
|
const planned = (attempts, plan) => Stream.unwrap(Ref.getAndUpdate(attempts, (n) => n + 1).pipe(Effect.map((n) => plan[Math.min(n, plan.length - 1)])));
|
|
@@ -54,95 +54,18 @@ type ImageRef = Data.TaggedEnum<{
|
|
|
54
54
|
readonly contents: string;
|
|
55
55
|
};
|
|
56
56
|
}>;
|
|
57
|
-
declare const ImageRef: {
|
|
58
|
-
readonly
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly ref: string;
|
|
70
|
-
}, {
|
|
71
|
-
readonly _tag: Tag;
|
|
72
|
-
}> | Extract<{
|
|
73
|
-
readonly _tag: "Snapshot";
|
|
74
|
-
readonly id: SnapshotId;
|
|
75
|
-
}, {
|
|
76
|
-
readonly _tag: Tag;
|
|
77
|
-
}>;
|
|
78
|
-
readonly $match: {
|
|
79
|
-
<Cases extends { readonly [Tag in "Default" | "Dockerfile" | "Registry" | "Snapshot"]: (args: Extract<{
|
|
80
|
-
readonly _tag: "Default";
|
|
81
|
-
} | {
|
|
82
|
-
readonly _tag: "Dockerfile";
|
|
83
|
-
readonly contents: string;
|
|
84
|
-
} | {
|
|
85
|
-
readonly _tag: "Registry";
|
|
86
|
-
readonly ref: string;
|
|
87
|
-
} | {
|
|
88
|
-
readonly _tag: "Snapshot";
|
|
89
|
-
readonly id: SnapshotId;
|
|
90
|
-
}, {
|
|
91
|
-
readonly _tag: Tag;
|
|
92
|
-
}>) => any; }>(cases: Cases): (value: {
|
|
93
|
-
readonly _tag: "Default";
|
|
94
|
-
} | {
|
|
95
|
-
readonly _tag: "Dockerfile";
|
|
96
|
-
readonly contents: string;
|
|
97
|
-
} | {
|
|
98
|
-
readonly _tag: "Registry";
|
|
99
|
-
readonly ref: string;
|
|
100
|
-
} | {
|
|
101
|
-
readonly _tag: "Snapshot";
|
|
102
|
-
readonly id: SnapshotId;
|
|
103
|
-
}) => import("effect/Unify").Unify<ReturnType<Cases["Default" | "Dockerfile" | "Registry" | "Snapshot"]>>;
|
|
104
|
-
<Cases extends { readonly [Tag in "Default" | "Dockerfile" | "Registry" | "Snapshot"]: (args: Extract<{
|
|
105
|
-
readonly _tag: "Default";
|
|
106
|
-
} | {
|
|
107
|
-
readonly _tag: "Dockerfile";
|
|
108
|
-
readonly contents: string;
|
|
109
|
-
} | {
|
|
110
|
-
readonly _tag: "Registry";
|
|
111
|
-
readonly ref: string;
|
|
112
|
-
} | {
|
|
113
|
-
readonly _tag: "Snapshot";
|
|
114
|
-
readonly id: SnapshotId;
|
|
115
|
-
}, {
|
|
116
|
-
readonly _tag: Tag;
|
|
117
|
-
}>) => any; }>(value: {
|
|
118
|
-
readonly _tag: "Default";
|
|
119
|
-
} | {
|
|
120
|
-
readonly _tag: "Dockerfile";
|
|
121
|
-
readonly contents: string;
|
|
122
|
-
} | {
|
|
123
|
-
readonly _tag: "Registry";
|
|
124
|
-
readonly ref: string;
|
|
125
|
-
} | {
|
|
126
|
-
readonly _tag: "Snapshot";
|
|
127
|
-
readonly id: SnapshotId;
|
|
128
|
-
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Default" | "Dockerfile" | "Registry" | "Snapshot"]>>;
|
|
129
|
-
};
|
|
130
|
-
readonly Default: Data.TaggedEnum.ConstructorFrom<{
|
|
131
|
-
readonly _tag: "Default";
|
|
132
|
-
}, "_tag">;
|
|
133
|
-
readonly Dockerfile: Data.TaggedEnum.ConstructorFrom<{
|
|
134
|
-
readonly _tag: "Dockerfile";
|
|
135
|
-
readonly contents: string;
|
|
136
|
-
}, "_tag">;
|
|
137
|
-
readonly Registry: Data.TaggedEnum.ConstructorFrom<{
|
|
138
|
-
readonly _tag: "Registry";
|
|
139
|
-
readonly ref: string;
|
|
140
|
-
}, "_tag">;
|
|
141
|
-
readonly Snapshot: Data.TaggedEnum.ConstructorFrom<{
|
|
142
|
-
readonly _tag: "Snapshot";
|
|
143
|
-
readonly id: SnapshotId;
|
|
144
|
-
}, "_tag">;
|
|
145
|
-
};
|
|
57
|
+
declare const ImageRef: Data.TaggedEnum.Constructor<{
|
|
58
|
+
readonly _tag: "Default";
|
|
59
|
+
} | {
|
|
60
|
+
readonly _tag: "Dockerfile";
|
|
61
|
+
readonly contents: string;
|
|
62
|
+
} | {
|
|
63
|
+
readonly _tag: "Registry";
|
|
64
|
+
readonly ref: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly _tag: "Snapshot";
|
|
67
|
+
readonly id: SnapshotId;
|
|
68
|
+
}>;
|
|
146
69
|
/**
|
|
147
70
|
* Outbound network policy for a sandbox.
|
|
148
71
|
*
|
|
@@ -163,74 +86,15 @@ type NetworkPolicy = Data.TaggedEnum<{
|
|
|
163
86
|
readonly cidrs?: ReadonlyArray<string>;
|
|
164
87
|
};
|
|
165
88
|
}>;
|
|
166
|
-
declare const NetworkPolicy: {
|
|
167
|
-
readonly
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}, {
|
|
176
|
-
readonly _tag: Tag;
|
|
177
|
-
}> | Extract<{
|
|
178
|
-
readonly _tag: "Open";
|
|
179
|
-
}, {
|
|
180
|
-
readonly _tag: Tag;
|
|
181
|
-
}>;
|
|
182
|
-
readonly $match: {
|
|
183
|
-
<Cases extends { readonly [Tag in "Allowlist" | "Blocked" | "Open"]: (args: Extract<{
|
|
184
|
-
readonly _tag: "Allowlist";
|
|
185
|
-
readonly hosts?: ReadonlyArray<string>;
|
|
186
|
-
readonly cidrs?: ReadonlyArray<string>;
|
|
187
|
-
} | {
|
|
188
|
-
readonly _tag: "Blocked";
|
|
189
|
-
} | {
|
|
190
|
-
readonly _tag: "Open";
|
|
191
|
-
}, {
|
|
192
|
-
readonly _tag: Tag;
|
|
193
|
-
}>) => any; }>(cases: Cases): (value: {
|
|
194
|
-
readonly _tag: "Allowlist";
|
|
195
|
-
readonly hosts?: ReadonlyArray<string>;
|
|
196
|
-
readonly cidrs?: ReadonlyArray<string>;
|
|
197
|
-
} | {
|
|
198
|
-
readonly _tag: "Blocked";
|
|
199
|
-
} | {
|
|
200
|
-
readonly _tag: "Open";
|
|
201
|
-
}) => import("effect/Unify").Unify<ReturnType<Cases["Allowlist" | "Blocked" | "Open"]>>;
|
|
202
|
-
<Cases extends { readonly [Tag in "Allowlist" | "Blocked" | "Open"]: (args: Extract<{
|
|
203
|
-
readonly _tag: "Allowlist";
|
|
204
|
-
readonly hosts?: ReadonlyArray<string>;
|
|
205
|
-
readonly cidrs?: ReadonlyArray<string>;
|
|
206
|
-
} | {
|
|
207
|
-
readonly _tag: "Blocked";
|
|
208
|
-
} | {
|
|
209
|
-
readonly _tag: "Open";
|
|
210
|
-
}, {
|
|
211
|
-
readonly _tag: Tag;
|
|
212
|
-
}>) => any; }>(value: {
|
|
213
|
-
readonly _tag: "Allowlist";
|
|
214
|
-
readonly hosts?: ReadonlyArray<string>;
|
|
215
|
-
readonly cidrs?: ReadonlyArray<string>;
|
|
216
|
-
} | {
|
|
217
|
-
readonly _tag: "Blocked";
|
|
218
|
-
} | {
|
|
219
|
-
readonly _tag: "Open";
|
|
220
|
-
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Allowlist" | "Blocked" | "Open"]>>;
|
|
221
|
-
};
|
|
222
|
-
readonly Allowlist: Data.TaggedEnum.ConstructorFrom<{
|
|
223
|
-
readonly _tag: "Allowlist";
|
|
224
|
-
readonly hosts?: ReadonlyArray<string>;
|
|
225
|
-
readonly cidrs?: ReadonlyArray<string>;
|
|
226
|
-
}, "_tag">;
|
|
227
|
-
readonly Blocked: Data.TaggedEnum.ConstructorFrom<{
|
|
228
|
-
readonly _tag: "Blocked";
|
|
229
|
-
}, "_tag">;
|
|
230
|
-
readonly Open: Data.TaggedEnum.ConstructorFrom<{
|
|
231
|
-
readonly _tag: "Open";
|
|
232
|
-
}, "_tag">;
|
|
233
|
-
};
|
|
89
|
+
declare const NetworkPolicy: Data.TaggedEnum.Constructor<{
|
|
90
|
+
readonly _tag: "Allowlist";
|
|
91
|
+
readonly hosts?: ReadonlyArray<string>;
|
|
92
|
+
readonly cidrs?: ReadonlyArray<string>;
|
|
93
|
+
} | {
|
|
94
|
+
readonly _tag: "Blocked";
|
|
95
|
+
} | {
|
|
96
|
+
readonly _tag: "Open";
|
|
97
|
+
}>;
|
|
234
98
|
/**
|
|
235
99
|
* A secret bound to a sandbox at create time. The code inside the
|
|
236
100
|
* sandbox sees only a placeholder (`$MSB_<NAME>` for Microsandbox,
|
|
@@ -352,86 +216,17 @@ type ExecEvent = Data.TaggedEnum<{
|
|
|
352
216
|
readonly durationMs: number;
|
|
353
217
|
};
|
|
354
218
|
}>;
|
|
355
|
-
declare const ExecEvent: {
|
|
356
|
-
readonly
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
readonly _tag: Tag;
|
|
367
|
-
}> | Extract<{
|
|
368
|
-
readonly _tag: "Stdout";
|
|
369
|
-
readonly chunk: Uint8Array;
|
|
370
|
-
}, {
|
|
371
|
-
readonly _tag: Tag;
|
|
372
|
-
}>;
|
|
373
|
-
readonly $match: {
|
|
374
|
-
<Cases extends { readonly [Tag in "Complete" | "Stderr" | "Stdout"]: (args: Extract<{
|
|
375
|
-
readonly _tag: "Complete";
|
|
376
|
-
readonly exitCode: number;
|
|
377
|
-
readonly durationMs: number;
|
|
378
|
-
} | {
|
|
379
|
-
readonly _tag: "Stderr";
|
|
380
|
-
readonly chunk: Uint8Array;
|
|
381
|
-
} | {
|
|
382
|
-
readonly _tag: "Stdout";
|
|
383
|
-
readonly chunk: Uint8Array;
|
|
384
|
-
}, {
|
|
385
|
-
readonly _tag: Tag;
|
|
386
|
-
}>) => any; }>(cases: Cases): (value: {
|
|
387
|
-
readonly _tag: "Complete";
|
|
388
|
-
readonly exitCode: number;
|
|
389
|
-
readonly durationMs: number;
|
|
390
|
-
} | {
|
|
391
|
-
readonly _tag: "Stderr";
|
|
392
|
-
readonly chunk: Uint8Array;
|
|
393
|
-
} | {
|
|
394
|
-
readonly _tag: "Stdout";
|
|
395
|
-
readonly chunk: Uint8Array;
|
|
396
|
-
}) => import("effect/Unify").Unify<ReturnType<Cases["Complete" | "Stderr" | "Stdout"]>>;
|
|
397
|
-
<Cases extends { readonly [Tag in "Complete" | "Stderr" | "Stdout"]: (args: Extract<{
|
|
398
|
-
readonly _tag: "Complete";
|
|
399
|
-
readonly exitCode: number;
|
|
400
|
-
readonly durationMs: number;
|
|
401
|
-
} | {
|
|
402
|
-
readonly _tag: "Stderr";
|
|
403
|
-
readonly chunk: Uint8Array;
|
|
404
|
-
} | {
|
|
405
|
-
readonly _tag: "Stdout";
|
|
406
|
-
readonly chunk: Uint8Array;
|
|
407
|
-
}, {
|
|
408
|
-
readonly _tag: Tag;
|
|
409
|
-
}>) => any; }>(value: {
|
|
410
|
-
readonly _tag: "Complete";
|
|
411
|
-
readonly exitCode: number;
|
|
412
|
-
readonly durationMs: number;
|
|
413
|
-
} | {
|
|
414
|
-
readonly _tag: "Stderr";
|
|
415
|
-
readonly chunk: Uint8Array;
|
|
416
|
-
} | {
|
|
417
|
-
readonly _tag: "Stdout";
|
|
418
|
-
readonly chunk: Uint8Array;
|
|
419
|
-
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Complete" | "Stderr" | "Stdout"]>>;
|
|
420
|
-
};
|
|
421
|
-
readonly Complete: Data.TaggedEnum.ConstructorFrom<{
|
|
422
|
-
readonly _tag: "Complete";
|
|
423
|
-
readonly exitCode: number;
|
|
424
|
-
readonly durationMs: number;
|
|
425
|
-
}, "_tag">;
|
|
426
|
-
readonly Stderr: Data.TaggedEnum.ConstructorFrom<{
|
|
427
|
-
readonly _tag: "Stderr";
|
|
428
|
-
readonly chunk: Uint8Array;
|
|
429
|
-
}, "_tag">;
|
|
430
|
-
readonly Stdout: Data.TaggedEnum.ConstructorFrom<{
|
|
431
|
-
readonly _tag: "Stdout";
|
|
432
|
-
readonly chunk: Uint8Array;
|
|
433
|
-
}, "_tag">;
|
|
434
|
-
};
|
|
219
|
+
declare const ExecEvent: Data.TaggedEnum.Constructor<{
|
|
220
|
+
readonly _tag: "Complete";
|
|
221
|
+
readonly exitCode: number;
|
|
222
|
+
readonly durationMs: number;
|
|
223
|
+
} | {
|
|
224
|
+
readonly _tag: "Stderr";
|
|
225
|
+
readonly chunk: Uint8Array;
|
|
226
|
+
} | {
|
|
227
|
+
readonly _tag: "Stdout";
|
|
228
|
+
readonly chunk: Uint8Array;
|
|
229
|
+
}>;
|
|
435
230
|
type FileEntryKind = "file" | "directory" | "symlink" | "other";
|
|
436
231
|
type FileEntry = {
|
|
437
232
|
readonly path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sandbox.d.mts","names":[],"sources":["../../src/sandbox/Sandbox.ts"],"mappings":";;;;;;;;;;;;;;KAgBY,YAAY,MAAM;cACjB,WAAS,MAAA,YAAA;;;;;;KAOV;WACD,IAAI;WACJ;;KAGC,WAAW,MAAM;cAChB,UAAQ,MAAA,YAAA;KAET,aAAa,MAAM;cAClB,YAAU,MAAA,YAAA;;;;;;;;;;;;;;;;KAqBX,WAAW,KAAK;EAC1B;EACA;aAAqB;;EACrB;aAAqB,IAAI;;EACzB;aAAuB;;;cAGZ
|
|
1
|
+
{"version":3,"file":"Sandbox.d.mts","names":[],"sources":["../../src/sandbox/Sandbox.ts"],"mappings":";;;;;;;;;;;;;;KAgBY,YAAY,MAAM;cACjB,WAAS,MAAA,YAAA;;;;;;KAOV;WACD,IAAI;WACJ;;KAGC,WAAW,MAAM;cAChB,UAAQ,MAAA,YAAA;KAET,aAAa,MAAM;cAClB,YAAU,MAAA,YAAA;;;;;;;;;;;;;;;;KAqBX,WAAW,KAAK;EAC1B;EACA;aAAqB;;EACrB;aAAqB,IAAI;;EACzB;aAAuB;;;cAGZ,UAAQ,KAAA,WAAA;;;;WAHc;;;WAFP;;;WACD,IAAA;;;;;;;;;;;;;;KAsBf,gBAAgB,KAAK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2B,UAAU;;cAQnD,gBAAa,IACpB,aACH,OAAO,aAAa,cAA2B,UAAU;;cAQ/C,aAAa,OAAO,OAC/B;WAAyB,IAAI;WAAmB;IAChD,cACA,UAAU;;cAQC,kBAAe,IACtB,eACH,OAAO,aAAa,cAA2B,UAAU;;cAQ/C,eAAe,OAAO,OACjC;WAAyB,IAAI;WAAqB;IAClD,cACA,UAAU;;;;;;;;cAcC,aAAU,UACX,iBAAe,iBAExB,OAAO;WACG;GACX,cACA,UAAU"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { streamSynthesis, streamSynthesisFrom, streamSynthesizeDialogue, synthesize, synthesizeDialogue } from "./SpeechSynthesizer.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { n as globalExpect } from "../
|
|
4
|
-
import { t as import_dist } from "../dist-
|
|
2
|
+
import { b as it, m as describe } from "../dist-DzeSyeYF.mjs";
|
|
3
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
4
|
+
import { t as import_dist } from "../dist-DNeuh84d.mjs";
|
|
5
5
|
import { layer, layerWithoutIncremental, layerWithoutMultiSpeaker } from "../testing/MockSpeechSynthesizer.mjs";
|
|
6
6
|
import { Duration, Effect, Stream } from "effect";
|
|
7
7
|
//#region src/speech-synthesizer/SpeechSynthesizer.test.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromBytes, parse, toBytes } from "./JSONL.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { n as globalExpect } from "../
|
|
2
|
+
import { b as it, m as describe } from "../dist-DzeSyeYF.mjs";
|
|
3
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
4
4
|
import { Effect, Result, Schema, Stream } from "effect";
|
|
5
5
|
//#region src/streaming/JSONL.test.ts
|
|
6
6
|
const enc = new TextEncoder();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
import { HttpClientRequest } from "effect/
|
|
3
|
+
import { HttpClientRequest } from "effect/http";
|
|
4
4
|
//#region src/streaming/Multipart.ts
|
|
5
5
|
var Multipart_exports = /* @__PURE__ */ __exportAll({ bodyMultipart: () => bodyMultipart });
|
|
6
6
|
/**
|
|
@@ -17,8 +17,9 @@ var Multipart_exports = /* @__PURE__ */ __exportAll({ bodyMultipart: () => bodyM
|
|
|
17
17
|
*/
|
|
18
18
|
const bodyMultipart = (form) => Effect.gen(function* () {
|
|
19
19
|
const encoded = new Response(form);
|
|
20
|
+
const contentType = encoded.headers.get("content-type") ?? "multipart/form-data";
|
|
20
21
|
const buffer = yield* Effect.tryPromise(() => encoded.arrayBuffer());
|
|
21
|
-
return HttpClientRequest.bodyUint8Array(new Uint8Array(buffer),
|
|
22
|
+
return HttpClientRequest.bodyUint8Array(new Uint8Array(buffer), contentType);
|
|
22
23
|
});
|
|
23
24
|
//#endregion
|
|
24
25
|
export { bodyMultipart, Multipart_exports as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Multipart.mjs","names":[],"sources":["../../src/streaming/Multipart.ts"],"sourcesContent":["import { Effect } from \"effect\"\nimport { HttpClientRequest } from \"effect/
|
|
1
|
+
{"version":3,"file":"Multipart.mjs","names":[],"sources":["../../src/streaming/Multipart.ts"],"sourcesContent":["import { Effect } from \"effect\"\nimport { HttpClientRequest } from \"effect/http\"\n\n/**\n * Multipart body for an `HttpClientRequest`, encoded to bytes.\n *\n * Use this over `HttpClientRequest.bodyFormData`: the Undici client\n * passes the `FormData` object straight to `dispatcher.request`, which\n * cannot serialise it, so the request is never sent and the effect\n * hangs with no error. Encoding here produces the same bytes every\n * other client derives internally, so it works on all of them.\n *\n * The failure is whatever `Response.arrayBuffer` rejects with; map it\n * to your provider's transport error at the call site.\n */\nexport const bodyMultipart = (\n form: FormData,\n): Effect.Effect<\n (request: HttpClientRequest.HttpClientRequest) => HttpClientRequest.HttpClientRequest,\n unknown\n> =>\n Effect.gen(function* () {\n const encoded = new Response(form)\n // Read before the body: once it is consumed, Bun answers `null` for this\n // header (Node keeps it), which would drop the boundary and leave the\n // server unable to parse the parts.\n const contentType = encoded.headers.get(\"content-type\") ?? \"multipart/form-data\"\n const buffer = yield* Effect.tryPromise(() => encoded.arrayBuffer())\n return HttpClientRequest.bodyUint8Array(new Uint8Array(buffer), contentType)\n })\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,MAAa,iBACX,SAKA,OAAO,IAAI,aAAa;CACtB,MAAM,UAAU,IAAI,SAAS,IAAI;CAIjC,MAAM,cAAc,QAAQ,QAAQ,IAAI,cAAc,KAAK;CAC3D,MAAM,SAAS,OAAO,OAAO,iBAAiB,QAAQ,YAAY,CAAC;CACnE,OAAO,kBAAkB,eAAe,IAAI,WAAW,MAAM,GAAG,WAAW;AAC7E,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { bodyMultipart } from "./Multipart.mjs";
|
|
2
|
+
import { m as describe } from "../dist-DzeSyeYF.mjs";
|
|
3
|
+
import { n as globalExpect } from "../index.C4tKZ0yW-LuFnBtmu.mjs";
|
|
4
|
+
import { t as it } from "../dist-B5K-y4Be.mjs";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { HttpClientRequest } from "effect/http";
|
|
7
|
+
//#region src/streaming/Multipart.test.ts
|
|
8
|
+
describe("bodyMultipart", () => {
|
|
9
|
+
it.effect("sends the boundary the encoded parts are delimited by", () => Effect.gen(function* () {
|
|
10
|
+
const form = new FormData();
|
|
11
|
+
form.set("file", new Blob([new Uint8Array([
|
|
12
|
+
1,
|
|
13
|
+
2,
|
|
14
|
+
3
|
|
15
|
+
])], { type: "audio/ogg" }), "audio.ogg");
|
|
16
|
+
form.set("model", "whisper-1");
|
|
17
|
+
const request = HttpClientRequest.post("https://example.test/upload").pipe(yield* bodyMultipart(form));
|
|
18
|
+
const contentType = request.headers["content-type"] ?? "";
|
|
19
|
+
const boundary = /boundary=(.+)$/.exec(contentType)?.[1];
|
|
20
|
+
globalExpect(boundary).toBeDefined();
|
|
21
|
+
const body = request.body._tag === "Uint8Array" ? new TextDecoder().decode(request.body.body) : "";
|
|
22
|
+
globalExpect(body.startsWith(`--${boundary}\r\n`)).toBe(true);
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export {};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=Multipart.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Multipart.test.mjs","names":[],"sources":["../../src/streaming/Multipart.test.ts"],"sourcesContent":["import { describe, it } from \"@effect/vitest\"\nimport { Effect } from \"effect\"\nimport { HttpClientRequest } from \"effect/http\"\nimport { expect } from \"vitest\"\nimport { bodyMultipart } from \"./Multipart.js\"\n\ndescribe(\"bodyMultipart\", () => {\n it.effect(\"sends the boundary the encoded parts are delimited by\", () =>\n Effect.gen(function* () {\n const form = new FormData()\n form.set(\"file\", new Blob([new Uint8Array([1, 2, 3])], { type: \"audio/ogg\" }), \"audio.ogg\")\n form.set(\"model\", \"whisper-1\")\n\n const request = HttpClientRequest.post(\"https://example.test/upload\").pipe(\n yield* bodyMultipart(form),\n )\n const contentType = request.headers[\"content-type\"] ?? \"\"\n const boundary = /boundary=(.+)$/.exec(contentType)?.[1]\n\n expect(boundary).toBeDefined()\n const body =\n request.body._tag === \"Uint8Array\" ? new TextDecoder().decode(request.body.body) : \"\"\n expect(body.startsWith(`--${boundary}\\r\\n`)).toBe(true)\n }),\n )\n})\n"],"mappings":";;;;;;;AAMA,SAAS,uBAAuB;CAC9B,GAAG,OAAO,+DACR,OAAO,IAAI,aAAa;EACtB,MAAM,OAAO,IAAI,SAAS;EAC1B,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC,IAAI,WAAW;GAAC;GAAG;GAAG;EAAC,CAAC,CAAC,GAAG,EAAE,MAAM,YAAY,CAAC,GAAG,WAAW;EAC1F,KAAK,IAAI,SAAS,WAAW;EAE7B,MAAM,UAAU,kBAAkB,KAAK,6BAA6B,CAAC,CAAC,KACpE,OAAO,cAAc,IAAI,CAC3B;EACA,MAAM,cAAc,QAAQ,QAAQ,mBAAmB;EACvD,MAAM,WAAW,iBAAiB,KAAK,WAAW,CAAC,GAAG;EAEtD,aAAO,QAAQ,CAAC,CAAC,YAAY;EAC7B,MAAM,OACJ,QAAQ,KAAK,SAAS,eAAe,IAAI,YAAY,CAAC,CAAC,OAAO,QAAQ,KAAK,IAAI,IAAI;EACrF,aAAO,KAAK,WAAW,KAAK,SAAS,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI;CACxD,CAAC,CACH;AACF,CAAC"}
|
package/dist/streaming/SSE.d.mts
CHANGED
|
@@ -15,7 +15,7 @@ type Event = {
|
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Decode a `Stream<Uint8Array>` (e.g. an HTTP response body) into a
|
|
18
|
-
* `Stream<SSE.Event>`, using the spec parser from `effect/
|
|
18
|
+
* `Stream<SSE.Event>`, using the spec parser from `effect/encoding`.
|
|
19
19
|
* An event is dispatched only once its terminating blank line arrives, so a
|
|
20
20
|
* partial event at stream end (clean or failed) is discarded per the spec
|
|
21
21
|
* rather than surfaced as a truncated frame.
|
package/dist/streaming/SSE.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { Stream } from "effect";
|
|
3
|
-
import { Sse } from "effect/
|
|
3
|
+
import { Sse } from "effect/encoding";
|
|
4
4
|
//#region src/streaming/SSE.ts
|
|
5
5
|
var SSE_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
fromBytes: () => fromBytes,
|
|
@@ -22,7 +22,7 @@ const makeParserState = () => {
|
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* Decode a `Stream<Uint8Array>` (e.g. an HTTP response body) into a
|
|
25
|
-
* `Stream<SSE.Event>`, using the spec parser from `effect/
|
|
25
|
+
* `Stream<SSE.Event>`, using the spec parser from `effect/encoding`.
|
|
26
26
|
* An event is dispatched only once its terminating blank line arrives, so a
|
|
27
27
|
* partial event at stream end (clean or failed) is discarded per the spec
|
|
28
28
|
* rather than surfaced as a truncated frame.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSE.mjs","names":[],"sources":["../../src/streaming/SSE.ts"],"sourcesContent":["import { Stream } from \"effect\"\nimport { Sse } from \"effect/
|
|
1
|
+
{"version":3,"file":"SSE.mjs","names":[],"sources":["../../src/streaming/SSE.ts"],"sourcesContent":["import { Stream } from \"effect\"\nimport { Sse } from \"effect/encoding\"\n\n/**\n * One Server-Sent Event. Fields per the WHATWG spec:\n * - `event`: optional event name (absent for the default \"message\")\n * - `data`: payload, with multiple `data:` lines joined by `\\n`\n * - `id`: optional last-event id\n */\nexport type Event = {\n readonly event?: string\n readonly data: string\n readonly id?: string\n}\n\nconst toEvent = (wire: Sse.Event): Event => ({\n data: wire.data,\n ...(wire.event !== \"message\" && { event: wire.event }),\n ...(wire.id !== undefined && { id: wire.id }),\n})\n\ntype ParserState = {\n readonly parser: Sse.Parser\n readonly out: Array<Event>\n}\n\nconst makeParserState = (): ParserState => {\n const out: Array<Event> = []\n const parser = Sse.makeParser((event) => {\n // `retry:` reconnection hints have no representation in `Event`\n if (event._tag === \"Event\") out.push(toEvent(event))\n })\n return { parser, out }\n}\n\n/**\n * Decode a `Stream<Uint8Array>` (e.g. an HTTP response body) into a\n * `Stream<SSE.Event>`, using the spec parser from `effect/encoding`.\n * An event is dispatched only once its terminating blank line arrives, so a\n * partial event at stream end (clean or failed) is discarded per the spec\n * rather than surfaced as a truncated frame.\n */\nexport const fromBytes = <E, R>(\n self: Stream.Stream<Uint8Array, E, R>,\n): Stream.Stream<Event, E, R> =>\n self.pipe(\n Stream.decodeText,\n Stream.mapAccum(makeParserState, (state, text: string) => {\n state.parser.feed(text)\n return [state, state.out.splice(0)] as const\n }),\n )\n\nconst encoder = new TextEncoder()\n\n/**\n * Encode a `Stream<Event>` as `Stream<Uint8Array>` ready to send on an\n * HTTP response with `Content-Type: text/event-stream`.\n */\nexport const toBytes = <E, R>(self: Stream.Stream<Event, E, R>): Stream.Stream<Uint8Array, E, R> =>\n Stream.map(self, (ev) =>\n encoder.encode(\n Sse.encoder.write({\n _tag: \"Event\",\n event: ev.event ?? \"message\",\n id: ev.id,\n data: ev.data,\n }),\n ),\n )\n"],"mappings":";;;;;;;;AAeA,MAAM,WAAW,UAA4B;CAC3C,MAAM,KAAK;CACX,GAAI,KAAK,UAAU,aAAa,EAAE,OAAO,KAAK,MAAM;CACpD,GAAI,KAAK,OAAO,KAAA,KAAa,EAAE,IAAI,KAAK,GAAG;AAC7C;AAOA,MAAM,wBAAqC;CACzC,MAAM,MAAoB,CAAC;CAK3B,OAAO;EAAE,QAJM,IAAI,YAAY,UAAU;GAEvC,IAAI,MAAM,SAAS,SAAS,IAAI,KAAK,QAAQ,KAAK,CAAC;EACrD,CACc;EAAG;CAAI;AACvB;;;;;;;;AASA,MAAa,aACX,SAEA,KAAK,KACH,OAAO,YACP,OAAO,SAAS,kBAAkB,OAAO,SAAiB;CACxD,MAAM,OAAO,KAAK,IAAI;CACtB,OAAO,CAAC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC;AACpC,CAAC,CACH;AAEF,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAa,WAAiB,SAC5B,OAAO,IAAI,OAAO,OAChB,QAAQ,OACN,IAAI,QAAQ,MAAM;CAChB,MAAM;CACN,OAAO,GAAG,SAAS;CACnB,IAAI,GAAG;CACP,MAAM,GAAG;AACX,CAAC,CACH,CACF"}
|