@effect-uai/google 0.18.0 → 0.19.0-dev-20261110065930
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/codec.d.mts +28 -7
- package/dist/codec.d.mts.map +1 -1
- package/dist/codec.mjs +52 -10
- package/dist/codec.mjs.map +1 -1
- package/dist/codec.test.d.mts +1 -0
- package/dist/codec.test.mjs +61 -0
- package/dist/codec.test.mjs.map +1 -0
- package/dist/geminiTools.test.mjs +1 -0
- package/dist/geminiTools.test.mjs.map +1 -1
- package/dist/realtimeSession.mjs +2 -2
- package/dist/realtimeSession.mjs.map +1 -1
- package/dist/realtimeSession.test.mjs +67 -36
- package/dist/realtimeSession.test.mjs.map +1 -1
- package/package.json +4 -4
- package/src/codec.test.ts +54 -0
- package/src/codec.ts +90 -21
- package/src/geminiTools.test.ts +1 -0
- package/src/realtimeSession.test.ts +5 -5
- package/src/realtimeSession.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtimeSession.test.mjs","names":["Effect","Cause","Duration","pipe","Layer","Scope","V.describe","it","V.it","internal.it"],"sources":["../../../../node_modules/.pnpm/@effect+vitest@4.0.1_effect@4.0.1_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_65816e3353e20bfeb9b2e1494bdddeef/node_modules/@effect/vitest/dist/internal/internal.js","../../../../node_modules/.pnpm/@effect+vitest@4.0.1_effect@4.0.1_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_65816e3353e20bfeb9b2e1494bdddeef/node_modules/@effect/vitest/dist/index.js","../src/realtimeSession.test.ts"],"sourcesContent":["/**\n * @since 4.0.0\n */\nimport * as Arbitrary from \"effect/Arbitrary\";\nimport * as Cause from \"effect/Cause\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport { constVoid, flow, pipe } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as Scope from \"effect/Scope\";\nimport * as TestClock from \"effect/testing/TestClock\";\nimport * as TestConsole from \"effect/testing/TestConsole\";\nimport * as V from \"vitest\";\nconst getCurrentSuite = V.TestRunner.getCurrentSuite;\nconst runPromise = /*#__PURE__*/Effect.fnUntraced(function* (effect, _ctx) {\n const exit = yield* Effect.exit(effect);\n if (Exit.isFailure(exit)) {\n const errors = Cause.prettyErrors(exit.cause);\n for (let i = 0; i < errors.length; i++) {\n yield* Effect.logError(errors[i]);\n }\n }\n return yield* exit;\n}, (effect, _, ctx) => Effect.runPromise(effect, {\n signal: ctx?.signal\n}));\n/** @internal */\nconst runTest = ctx => effect => {\n const promise = runPromise(effect, ctx);\n if (ctx) {\n // Vitest stops awaiting the test promise once the signal aborts (timeout or\n // cancellation), so only then add a hook that waits for the finalizers.\n // Registering it unconditionally would change the teardown of every test.\n const onAbort = () => ctx.onTestFinished(() => promise.then(constVoid, constVoid));\n ctx.signal.addEventListener(\"abort\", onAbort, {\n once: true\n });\n const cleanup = () => ctx.signal.removeEventListener(\"abort\", onAbort);\n promise.then(cleanup, cleanup);\n // A retry after a timed-out attempt reuses the aborted signal, so no event fires.\n if (ctx.signal.aborted) onAbort();\n }\n return promise;\n};\nconst TestEnv = /*#__PURE__*/Layer.mergeAll(TestConsole.layer, /*#__PURE__*/TestClock.layer());\n/** @internal */\nexport const addEqualityTesters = () => {\n V.expect.addEqualityTesters([]);\n};\n/** @internal */\nconst testOptions = timeout => typeof timeout === \"number\" ? {\n timeout\n} : timeout ?? {};\nconst hookTimeout = timeout => timeout === undefined ? undefined : Duration.toMillis(Duration.fromInputUnsafe(timeout));\nconst propertyTestOptions = timeout => typeof timeout === \"number\" ? undefined : timeout;\nconst checkOptions = timeout => propertyTestOptions(timeout)?.arbitrary;\nconst compileArbitraryInput = input => Arbitrary.isArbitrary(input) ? input : Arbitrary.schema(input);\nconst makeArbitrary = arbitraries => Arbitrary.all(Array.isArray(arbitraries) ? arbitraries.map(compileArbitraryInput) : Object.fromEntries(Object.entries(arbitraries).map(([key, input]) => [key, compileArbitraryInput(input)])));\nconst normalizeProperty = (property, value) => Effect.catchCause(Effect.suspend(() => {\n const output = property(value);\n return Effect.isEffect(output) ? output : Effect.succeed(output);\n}), cause => Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Effect.fail(cause));\nconst runCheck = (ctx, arbitrary, property, options) => runTest(ctx)(Effect.flatMapEager(Arbitrary.checkEffect(arbitrary, value => normalizeProperty(property, value), options), result => {\n const failure = Arbitrary.formatCheckFailure(result);\n return failure === undefined ? Effect.void : Effect.die(new Error(failure));\n}));\n// Vitest decides which fixtures to set up by parsing the source of a test\n// function's context parameter, and there is no public API to supply the names\n// for a wrapper, so wrappers expose the source of the function they call.\nconst withFixturesOf = (source, f) => Object.defineProperty(f, \"toString\", {\n value: () => source.toString()\n});\nconst makeItProxy = (it, overrides) => new Proxy(it, {\n apply(target, thisArg, argArray) {\n return Reflect.apply(target, thisArg, argArray);\n },\n get(target, property, receiver) {\n if (Object.hasOwn(overrides, property)) {\n return Reflect.get(overrides, property);\n }\n // do not bind: binding would strip vitest's static helpers (e.g. `describe.each`)\n return Reflect.get(target, property, receiver);\n }\n});\nconst collectTasks = (tasks, acc = []) => {\n for (let i = 0; i < tasks.length; i++) {\n const task = tasks[i];\n if (task.type === \"test\" && task.mode !== \"skip\" && task.mode !== \"todo\") {\n acc.push(task);\n } else if (task.tasks !== undefined) {\n collectTasks(task.tasks, acc);\n }\n }\n return acc;\n};\nconst registerProp = (it, name, arbitraries, property, timeout) => {\n const arbitrary = makeArbitrary(arbitraries);\n // Property callbacks receive only the base context; the empty source requests no fixtures.\n it(name, testOptions(timeout), withFixturesOf(() => {}, ctx => runCheck(ctx, arbitrary, values => property(values, ctx), checkOptions(timeout))));\n};\nconst makeTester = (mapEffect, it) => {\n const run = (ctx, args, self) => pipe(Effect.suspend(() => self(...args)), mapEffect, runTest(ctx));\n const register = test => (name, self, timeout) => test(name, testOptions(timeout), withFixturesOf(self, ctx => run(ctx, [ctx], self)));\n const each = cases => (name, self, timeout) => it.for(cases)(name, testOptions(timeout), withFixturesOf(self, (args, ctx) => run(ctx, [args, ctx], self).then(constVoid)));\n const prop = (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => Effect.mapEager(mapEffect(Effect.suspend(() => self(values, ctx))), value => value !== false), timeout);\n return Object.assign(register(it), {\n skip: register(it.skip),\n skipIf: condition => register(it.skipIf(condition)),\n runIf: condition => register(it.runIf(condition)),\n only: register(it.only),\n each,\n fails: register(it.fails),\n prop\n });\n};\nconst makeProp = it => (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => self(values, ctx) !== false, timeout);\nconst makeLayer = it => (layer_, options) => (...args) => {\n const excludeTestServices = options?.excludeTestServices ?? false;\n const withTestEnv = excludeTestServices ? layer_ : Layer.provideMerge(layer_, TestEnv);\n const memoMap = options?.memoMap ?? Effect.runSync(Layer.makeMemoMap);\n const scope = Effect.runSync(Scope.make());\n const contextEffect = Layer.buildWithMemoMap(withTestEnv, memoMap, scope).pipe(Effect.orDie, Effect.cached, Effect.runSync);\n let closed = false;\n const closeScope = () => {\n if (closed) {\n return Promise.resolve();\n }\n closed = true;\n // Layer cleanup must outlive the last test's already-aborted signal.\n return runPromise(Scope.close(scope, Exit.void));\n };\n const methods = makeItProxy(it, {\n effect: makeTester(effect => Effect.flatMap(contextEffect, context => effect.pipe(Effect.scoped, Effect.provide(context))), it),\n prop: makeProp(it),\n flakyTest,\n layer(nestedLayer, options) {\n return makeLayer(it)(Layer.provideMerge(nestedLayer, withTestEnv), {\n ...options,\n memoMap: Layer.forkMemoMapUnsafe(memoMap),\n excludeTestServices\n });\n }\n });\n if (args.length === 1) {\n const currentSuite = getCurrentSuite();\n const previousTasks = new Set(currentSuite.tasks);\n args[0](methods);\n const blockTasks = collectTasks(currentSuite.tasks.filter(task => !previousTasks.has(task)));\n if (blockTasks.length === 0) {\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n const blockTaskSet = new Set(blockTasks);\n let remaining = blockTasks.length;\n V.beforeEach(\n // Destructured so Vitest can parse the hook once the suite defines fixtures.\n ({\n onTestFinished,\n signal,\n task\n }) => {\n if (!blockTaskSet.has(task)) {\n return;\n }\n onTestFinished(() => {\n remaining--;\n if (remaining === 0) {\n return closeScope();\n }\n });\n return runPromise(Effect.asVoid(contextEffect), {\n signal\n });\n }, hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n const suiteOptions = options?.concurrent === undefined ? {} : {\n concurrent: options.concurrent\n };\n return V.describe(args[0], suiteOptions, () => {\n V.beforeAll(() => runPromise(Effect.asVoid(contextEffect)), hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return args[1](methods);\n });\n};\n/** @internal */\nexport const flakyTest = (self, timeout = Duration.seconds(30)) => pipe(self, Effect.scoped, Effect.sandbox, Effect.retry(pipe(Schedule.recurs(10), Schedule.while(_ => Effect.succeed(Duration.isLessThanOrEqualTo(Duration.fromInputUnsafe(_.elapsed), Duration.fromInputUnsafe(timeout)))))), Effect.orDie);\n/** @internal */\nexport const makeMethods = it => makeItProxy(it, {\n effect: makeTester(flow(Effect.scoped, Effect.provide(TestEnv)), it),\n live: makeTester(Effect.scoped, it),\n flakyTest,\n layer: makeLayer(it),\n prop: makeProp(it)\n});\n/** @internal */\nexport const it = /*#__PURE__*/makeMethods(V.it);\n/** @internal */\nexport const {\n /** @internal */\n effect,\n /** @internal */\n layer,\n /** @internal */\n live,\n /** @internal */\n prop\n} = it;\n/** @internal */\nexport const describeWrapped = (name, f) => V.describe(name, () => f(it));\n//# sourceMappingURL=internal.js.map","import * as internal from \"./internal/internal.js\";\n/**\n * Re-exports the `vitest` API unchanged.\n *\n * @stability unstable\n * @since 4.0.0\n */\nexport * from \"vitest\";\n/**\n * @since 4.0.0\n */\nexport const addEqualityTesters = internal.addEqualityTesters;\n/**\n * @since 4.0.0\n */\nexport const effect = internal.effect;\n/**\n * @since 4.0.0\n */\nexport const live = internal.live;\n/**\n * Share a `Layer` between multiple tests, optionally wrapping\n * the tests in a `describe` block if a name is provided.\n *\n * Named layers accept `concurrent` to override inherited suite concurrency.\n * Anonymous layers always inherit the enclosing suite's concurrency.\n * Use `ctx.expect` in concurrent tests for test-local snapshots and assertion counts.\n *\n * @since 4.0.0\n *\n * ```ts\n * import { assert, layer } from \"@effect/vitest\"\n * import { Effect, Layer, Context } from \"effect\"\n *\n * class Foo extends Context.Service<Foo, \"foo\">()(\"Foo\") {\n * static layer = Layer.succeed(Foo, \"foo\")\n * }\n *\n * class Bar extends Context.Service<Bar, \"bar\">()(\"Bar\") {\n * static layer = Layer.effect(\n * Bar,\n * Effect.map(Foo, () => \"bar\" as const)\n * )\n * }\n *\n * layer(Foo.layer)(\"layer\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * assert.strictEqual(foo, \"foo\")\n * }))\n *\n * it.layer(Bar.layer)(\"nested\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * const bar = yield* Bar\n * assert.strictEqual(foo, \"foo\")\n * assert.strictEqual(bar, \"bar\")\n * }))\n * })\n * })\n * ```\n */\nexport const layer = internal.layer;\n/**\n * @since 4.0.0\n */\nexport const flakyTest = internal.flakyTest;\n/**\n * @since 4.0.0\n */\nexport const prop = internal.prop;\n/**\n * @since 4.0.0\n */\n/**\n * @since 4.0.0\n */\nexport const it = internal.it;\n/**\n * Creates the Effect test helpers for a Vitest test API, such as one extended with fixtures.\n *\n * **Details**\n *\n * Tests receive the fixtures they destructure from their context. Vitest sets them up before the test and tears\n * them down after the test's scope closes, as it does for its own tests. `it.effect.each` passes the context\n * after the test case, and named and anonymous `it.layer` blocks keep the fixtures.\n *\n * **Gotchas**\n *\n * Vitest reads the destructured names to decide which fixtures to set up. Once any fixture is defined, a test that\n * takes the whole context as a plain parameter, such as `(ctx) =>`, fails with a `FixtureParseError`. Property\n * tests receive only the base test context and cannot request fixtures; auto fixtures still run.\n *\n * **Example** (Using a Vitest fixture in an Effect test)\n *\n * ```ts\n * import { assert, makeMethods, test } from \"@effect/vitest\"\n * import { Effect } from \"effect\"\n *\n * const it = makeMethods(\n * test.extend(\"config\", { scope: \"file\" }, () => ({ port: 3000 }))\n * )\n *\n * it.effect(\"reads the config fixture\", ({ config }) =>\n * Effect.sync(() => {\n * assert.strictEqual(config.port, 3000)\n * }))\n * ```\n *\n * @since 4.0.0\n */\nexport const makeMethods = internal.makeMethods;\n/**\n * @since 4.0.0\n */\nexport const describeWrapped = internal.describeWrapped;\n//# sourceMappingURL=index.js.map","import { describe, it } from \"@effect/vitest\"\nimport { Duration, Effect, Fiber, Logger, Redacted, Ref, Stream } from \"effect\"\nimport { Base64 } from \"effect/encoding\"\nimport { expect } from \"vitest\"\nimport type { RealtimeEvent } from \"@effect-uai/core/Realtime\"\nimport { RealtimeInput } from \"@effect-uai/core/Realtime\"\nimport type { RealtimeSessionHandle } from \"@effect-uai/core/RealtimeSession\"\nimport * as FakeWebSocket from \"@effect-uai/core/testing/FakeWebSocket\"\nimport { type GeminiLiveRequest, openSession } from \"./realtimeSession.js\"\n\nconst request: GeminiLiveRequest = {\n model: \"gemini-3.1-flash-live-preview\",\n instructions: \"be terse\",\n voiceId: \"Kore\",\n inputFormat: { container: \"raw\", encoding: \"pcm_s16le\", sampleRate: 16000, channels: 1 },\n outputFormat: { container: \"raw\", encoding: \"pcm_s16le\", sampleRate: 24000, channels: 1 },\n}\n\nconst cfg = { apiKey: Redacted.make(\"test-key\") }\n\n/** The client speaks first here, so the handshake answers `setup`. */\nconst gemini = FakeWebSocket.make({\n reply: (frame) =>\n Effect.succeed(Object.hasOwn(frame as object, \"setup\") ? [{ setupComplete: {} }] : []),\n})\n\n/** Let the socket's own turn and the adapter's fibers run. */\nconst tick = Effect.sleep(\"5 millis\")\n\n/**\n * Events are recorded as they arrive rather than collected at the end, so a\n * run that ends in a failure still says what the caller saw before it.\n */\nconst transcript = (\n server: FakeWebSocket.FakeWebSocketServer,\n script: (handle: RealtimeSessionHandle) => Effect.Effect<void, unknown>,\n options?: { readonly closeCode?: number; readonly request?: GeminiLiveRequest },\n) =>\n Effect.gen(function* () {\n const handle = yield* openSession({ ...cfg, webSocket: server.connect })(\n options?.request ?? request,\n )\n const seen = yield* Ref.make<ReadonlyArray<RealtimeEvent>>([])\n const collector = yield* Effect.forkChild(\n Effect.exit(Stream.runForEach(handle.events, (e) => Ref.update(seen, (xs) => [...xs, e]))),\n )\n yield* script(handle)\n yield* tick\n yield* server.close(options?.closeCode ?? 1000)\n const exit = yield* Fiber.join(collector)\n return { exit, events: yield* Ref.get(seen) }\n })\n\nconst tags = (events: ReadonlyArray<RealtimeEvent>) => events.map((e) => e._tag)\n\nconst audioPart = (bytes: ReadonlyArray<number>) => ({\n inlineData: {\n mimeType: \"audio/pcm;rate=24000\",\n data: Base64.encode(new Uint8Array(bytes)),\n },\n})\n\ndescribe(\"Gemini live session turns\", () => {\n it.live(\"mints one turn id for a whole answer, and reports its usage at the end\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n // 3.1 packs several parts, and their transcription, into one message.\n yield* server.push({\n serverContent: {\n modelTurn: { parts: [audioPart([1, 2, 3]), { thought: true, text: \"planning\" }] },\n outputTranscription: { text: \"hi\" },\n },\n })\n yield* server.push({\n serverContent: { modelTurn: { parts: [audioPart([4, 5])] } },\n usageMetadata: { promptTokenCount: 10, responseTokenCount: 20, totalTokenCount: 30 },\n })\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n // The thought part is the model reasoning, not something to speak.\n expect(tags(events)).toEqual([\n \"ResponseStarted\",\n \"AudioDelta\",\n \"OutputTranscriptDelta\",\n \"AudioDelta\",\n \"ResponseDone\",\n ])\n // The wire carries no response id, so every event of the turn shares one.\n expect(new Set(events.map((e) => (\"responseId\" in e ? e.responseId : \"\")))).toEqual(\n new Set([\"turn_1\"]),\n )\n const done = events[4]\n expect(done?._tag === \"ResponseDone\" && done.reason).toBe(\"complete\")\n expect(done?._tag === \"ResponseDone\" && done.usage?.total_tokens).toBe(30)\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends an interrupted turn once, and numbers the next one after it\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n yield* server.push({ serverContent: { modelTurn: { parts: [audioPart([1])] } } })\n yield* server.push({ serverContent: { interrupted: true } })\n // The server follows an interruption with `turnComplete`, which\n // would otherwise end the same turn a second time.\n yield* server.push({ serverContent: { turnComplete: true } })\n yield* server.push({ serverContent: { modelTurn: { parts: [audioPart([2])] } } })\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n expect(tags(events)).toEqual([\n \"ResponseStarted\",\n \"AudioDelta\",\n \"Interrupted\",\n \"ResponseDone\",\n \"ResponseStarted\",\n \"AudioDelta\",\n \"ResponseDone\",\n ])\n const interrupted = events[3]\n expect(interrupted?._tag === \"ResponseDone\" && interrupted.reason).toBe(\"interrupted\")\n const next = events[4]\n expect(next?._tag === \"ResponseStarted\" && next.responseId).toBe(\"turn_2\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"marks the user's words interim until the utterance is transcribed\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n yield* server.push({ serverContent: { interimInputTranscription: { text: \"weather\" } } })\n yield* server.push({\n serverContent: { inputTranscription: { text: \"weather in Lisbon\" } },\n })\n }),\n )\n\n // A transcript belongs to no turn, so none is started for it.\n expect(events).toEqual([\n { _tag: \"InputTranscript\", text: \"weather\", final: false },\n { _tag: \"InputTranscript\", text: \"weather in Lisbon\", final: true },\n ])\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends the stream as an incomplete turn when a turn is still running\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { exit } = yield* transcript(server, () =>\n server.push({ serverContent: { modelTurn: { parts: [audioPart([1])] } } }),\n )\n\n // A close must never look like a finished turn.\n expect(exit._tag).toBe(\"Failure\")\n expect(JSON.stringify(exit)).toContain(\"IncompleteTurn\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"fails when the socket closes before the configuration is accepted\", () =>\n Effect.gen(function* () {\n const mute = yield* FakeWebSocket.make()\n const opened = yield* Effect.forkChild(\n Effect.exit(openSession({ ...cfg, webSocket: mute.connect })(request)),\n )\n yield* tick\n yield* mute.close(1000)\n\n const exit = yield* Fiber.join(opened)\n expect(exit._tag).toBe(\"Failure\")\n expect(JSON.stringify(exit)).toContain(\"Unavailable\")\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session tools\", () => {\n it.live(\"answers a call with the name the server gave it\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, (handle) =>\n Effect.gen(function* () {\n yield* server.push({\n toolCall: {\n functionCalls: [{ id: \"fc_1\", name: \"get_weather\", args: { city: \"Lisbon\" } }],\n },\n })\n yield* tick\n yield* handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: '{\"celsius\":32}',\n providerData: undefined,\n },\n }),\n )\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n const call = events.find((e) => e._tag === \"ToolCall\")\n expect(call?._tag === \"ToolCall\" && call.call.arguments).toBe('{\"city\":\"Lisbon\"}')\n // A call arrives with no turn open, so it gets one of its own.\n expect(call?._tag === \"ToolCall\" && call.responseId).toBe(\"turn_1\")\n\n const sent = yield* server.sent\n const response = sent.find((f: any) => f.toolResponse !== undefined) as any\n // The name comes from the call, and the payload has to be an object.\n // `WHEN_IDLE` by default: a model that kept talking while the tool ran\n // finishes the sentence rather than cutting itself off to report.\n expect(response.toolResponse.functionResponses).toEqual([\n {\n id: \"fc_1\",\n name: \"get_weather\",\n response: { celsius: 32 },\n scheduling: \"WHEN_IDLE\",\n },\n ])\n }).pipe(Effect.scoped),\n )\n\n it.live(\"reports a result at once when the caller asks it to interrupt\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n yield* transcript(\n server,\n (handle) =>\n Effect.gen(function* () {\n yield* server.push({\n toolCall: { functionCalls: [{ id: \"fc_1\", name: \"get_weather\", args: {} }] },\n })\n yield* tick\n yield* handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: \"{}\",\n providerData: undefined,\n },\n }),\n )\n }),\n { request: { ...request, toolScheduling: \"interrupt\" } },\n )\n\n const sent = yield* server.sent\n const response = sent.find((f: any) => f.toolResponse !== undefined) as any\n expect(response.toolResponse.functionResponses[0].scheduling).toBe(\"INTERRUPT\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"rejects a result for a call this session never made\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const handle = yield* openSession({ ...cfg, webSocket: server.connect })(request)\n const failure = yield* Effect.exit(\n handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_unknown\",\n output: \"{}\",\n providerData: undefined,\n },\n }),\n ),\n )\n\n expect(failure._tag).toBe(\"Failure\")\n expect(JSON.stringify(failure)).toContain(\"InvalidRequest\")\n expect((yield* server.sent).some((f: any) => f.toolResponse !== undefined)).toBe(false)\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session lifetime\", () => {\n it.live(\"keeps only a resumable handle, and reads the closing warning as a duration\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events, exit } = yield* transcript(server, () =>\n Effect.gen(function* () {\n // Sent while a tool runs: no handle, and the stored one must stand.\n yield* server.push({ sessionResumptionUpdate: { newHandle: \"\", resumable: false } })\n yield* server.push({ sessionResumptionUpdate: { newHandle: \"h1\", resumable: true } })\n yield* server.push({ goAway: { timeLeft: \"60s\" } })\n }),\n )\n\n expect(tags(events)).toEqual([\"ResumptionHandle\", \"SessionEnding\"])\n const handle = events[0]\n expect(handle?._tag === \"ResumptionHandle\" && handle.handle).toBe(\"h1\")\n const ending = events[1]\n // A proto duration string, not a number.\n expect(ending?._tag === \"SessionEnding\" && ending.timeLeft).toEqual(Duration.seconds(60))\n // The close `goAway` announced is the lifetime cap, not a clean end, so\n // a caller can tell \"reconnect\" from \"we are done here\".\n expect(JSON.stringify(exit)).toContain(\"SessionExpired\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends cleanly when the close was not announced\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { exit } = yield* transcript(server, () =>\n server.push({ serverContent: { turnComplete: true } }),\n )\n\n expect(exit._tag).toBe(\"Success\")\n }).pipe(Effect.scoped),\n )\n})\n\n/** The `CapabilityWarning` payloads a run produced, in order. */\nconst warningCollector = () => {\n const seen: Array<{ readonly field: string; readonly value?: unknown }> = []\n const logger = Logger.make((options) => {\n const [label, warning] = options.message as ReadonlyArray<any>\n if (label === \"Capability dropped\") seen.push(warning)\n })\n return { seen, layer: Logger.layer([logger]) }\n}\n\nconst userText = (text: string) =>\n ({\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text, providerData: undefined }],\n providerData: undefined,\n }) as const\n\nconst call = (id: string) =>\n ({\n type: \"function_call\",\n call_id: id,\n name: \"get_time\",\n arguments: \"{}\",\n providerData: undefined,\n }) as const\n\ndescribe(\"Gemini live session history\", () => {\n it.live(\"names each kind of item the text-only seed cannot carry, once\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const warnings = warningCollector()\n\n yield* openSession({ ...cfg, webSocket: server.connect })({\n ...request,\n history: [\n userText(\"what time is it\"),\n call(\"fc_1\"),\n call(\"fc_2\"),\n {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: '{\"now\":\"12:00\"}',\n providerData: undefined,\n },\n ],\n }).pipe(Effect.provide(warnings.layer))\n yield* tick\n\n // Two calls, one kind: a long tool history is not a wall of warnings.\n expect(warnings.seen.map((w) => w.value)).toEqual([\"function_call\", \"function_call_output\"])\n expect(warnings.seen.every((w) => w.field === \"history\")).toBe(true)\n\n const sent = yield* server.sent\n const seed = sent.find((f: any) => f.clientContent !== undefined) as any\n expect(seed.clientContent.turns).toEqual([\n { role: \"user\", parts: [{ text: \"what time is it\" }] },\n ])\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session video\", () => {\n it.live(\"sends frame bytes inline, and refuses a frame it would have to fetch\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n yield* transcript(server, (handle) =>\n Effect.gen(function* () {\n yield* handle.send(\n RealtimeInput.VideoFrame({\n frame: { _tag: \"bytes\", bytes: new Uint8Array([1, 2]), mimeType: \"image/jpeg\" },\n }),\n )\n // A URL would need an upload through the Files API first.\n const exit = yield* Effect.exit(\n handle.send(\n RealtimeInput.VideoFrame({\n frame: { _tag: \"url\", url: \"https://example.com/frame.jpg\" },\n }),\n ),\n )\n expect(JSON.stringify(exit)).toContain(\"Unsupported\")\n }),\n )\n\n const sent = yield* server.sent\n expect(sent.filter((f: any) => f.realtimeInput?.video !== undefined)).toEqual([\n {\n realtimeInput: {\n video: { data: Base64.encode(new Uint8Array([1, 2])), mimeType: \"image/jpeg\" },\n },\n },\n ])\n }).pipe(Effect.scoped),\n )\n})\n"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,kBAAA,WAA+B;AACrC,MAAM,aAA0B,uBAAO,WAAW,WAAW,QAAQ,MAAM;CACzE,MAAM,OAAO,OAAOA,SAAO,KAAK,MAAM;CACtC,IAAI,KAAK,UAAU,IAAI,GAAG;EACxB,MAAM,SAASC,QAAM,aAAa,KAAK,KAAK;EAC5C,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,OAAOD,SAAO,SAAS,OAAO,EAAE;CAEpC;CACA,OAAO,OAAO;AAChB,IAAI,QAAQ,GAAG,QAA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UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI;EAGnE,MAAM,QAAO,OADO,OAAO,KAAA,CACT,MAAM,MAAW,EAAE,kBAAkB,KAAA,CAAS;EAChE,aAAO,KAAK,cAAc,KAAK,CAAC,CAAC,QAAQ,CACvC;GAAE,MAAM;GAAQ,OAAO,CAAC,EAAE,MAAM,kBAAkB,CAAC;EAAE,CACvD,CAAC;CACH,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,CACvB;AACF,CAAC;AAED,SAAS,mCAAmC;CAC1C,GAAG,KAAK,8EACN,OAAO,IAAI,aAAa;EACtB,MAAM,SAAS,OAAO;EACtB,OAAO,WAAW,SAAS,WACzB,OAAO,IAAI,aAAa;GACtB,OAAO,OAAO,KACZ,cAAc,WAAW,EACvB,OAAO;IAAE,MAAM;IAAS,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;IAAG,UAAU;GAAa,EAChF,CAAC,CACH;GAEA,MAAM,OAAO,OAAO,OAAO,KACzB,OAAO,KACL,cAAc,WAAW,EACvB,OAAO;IAAE,MAAM;IAAO,KAAK;GAAgC,EAC7D,CAAC,CACH,CACF;GACA,aAAO,KAAK,UAAU,IAAI,CAAC,CAAC,CAAC,UAAU,aAAa;EACtD,CAAC,CACH;EAEA,MAAM,OAAO,OAAO,OAAO;EAC3B,aAAO,KAAK,QAAQ,MAAW,EAAE,eAAe,UAAU,KAAA,CAAS,CAAC,CAAC,CAAC,QAAQ,CAC5E,EACE,eAAe,EACb,OAAO;GAAE,MAAM,OAAO,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;GAAG,UAAU;EAAa,EAC/E,EACF,CACF,CAAC;CACH,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,CACvB;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"realtimeSession.test.mjs","names":["Effect","Cause","Duration","pipe","Layer","V.describe","Scope","it","V.it","internal.it"],"sources":["../../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/internal/internal.js","../../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/index.js","../src/realtimeSession.test.ts"],"sourcesContent":["/**\n * @since 4.0.0\n */\nimport * as Arbitrary from \"effect/Arbitrary\";\nimport * as Cause from \"effect/Cause\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Fiber from \"effect/Fiber\";\nimport { constVoid, flow, pipe } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as Scope from \"effect/Scope\";\nimport * as TestClock from \"effect/testing/TestClock\";\nimport * as TestConsole from \"effect/testing/TestConsole\";\nimport * as V from \"vitest\";\nconst getCurrentSuite = V.TestRunner.getCurrentSuite;\nconst runPromise = (effect, ctx) => Effect.runPromise(\n// Only the test is interruptible: once the signal aborts, the fiber stops\n// at its next interruptible step, which would skip reporting the defects\n// raised by finalizers.\nEffect.uninterruptibleMask(restore => Effect.gen(function* () {\n const exit = yield* Effect.exit(restore(effect));\n if (Exit.isFailure(exit)) {\n const errors = Cause.prettyErrors(exit.cause);\n for (let i = 0; i < errors.length; i++) {\n yield* Effect.logError(errors[i]);\n }\n }\n return yield* exit;\n})), {\n signal: ctx?.signal\n});\nconst settleOnAbort = (ctx, promise) => {\n // Vitest stops awaiting the promise once the signal aborts (timeout or\n // cancellation), so only then add a hook that waits for the finalizers.\n // Registering it unconditionally would change the teardown of every test.\n const onAbort = () => ctx.onTestFinished(() => promise.then(constVoid, constVoid));\n ctx.signal.addEventListener(\"abort\", onAbort, {\n once: true\n });\n const cleanup = () => ctx.signal.removeEventListener(\"abort\", onAbort);\n promise.then(cleanup, cleanup);\n // A retry after a timed-out attempt reuses the aborted signal, so no event fires.\n if (ctx.signal.aborted) onAbort();\n return promise;\n};\n/** @internal */\nconst runTest = ctx => effect => {\n const promise = runPromise(effect, ctx);\n return ctx ? settleOnAbort(ctx, promise) : promise;\n};\nconst TestEnv = /*#__PURE__*/Layer.mergeAll(TestConsole.layer, /*#__PURE__*/TestClock.layer());\n/** @internal */\nexport const addEqualityTesters = () => {\n V.expect.addEqualityTesters([]);\n};\n/** @internal */\nconst testOptions = timeout => typeof timeout === \"number\" ? {\n timeout\n} : timeout ?? {};\nconst hookTimeout = timeout => timeout === undefined ? undefined : Duration.toMillis(Duration.fromInputUnsafe(timeout));\nconst propertyTestOptions = timeout => typeof timeout === \"number\" ? undefined : timeout;\nconst checkOptions = timeout => propertyTestOptions(timeout)?.arbitrary;\nconst compileArbitraryInput = input => Arbitrary.isArbitrary(input) ? input : Arbitrary.schema(input);\nconst makeArbitrary = arbitraries => Arbitrary.all(Array.isArray(arbitraries) ? arbitraries.map(compileArbitraryInput) : Object.fromEntries(Object.entries(arbitraries).map(([key, input]) => [key, compileArbitraryInput(input)])));\nconst normalizeProperty = (property, value) => Effect.catchCause(Effect.suspend(() => {\n const output = property(value);\n return Effect.isEffect(output) ? output : Effect.succeed(output);\n}), cause => Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Effect.fail(cause));\nconst runCheck = (ctx, arbitrary, property, options) => runTest(ctx)(Effect.flatMapEager(Arbitrary.checkEffect(arbitrary, value => normalizeProperty(property, value), options), result => {\n const failure = Arbitrary.formatCheckFailure(result);\n return failure === undefined ? Effect.void : Effect.die(new Error(failure));\n}));\n// Vitest decides which fixtures to set up by parsing the source of a test\n// function's context parameter, and there is no public API to supply the names\n// for a wrapper, so wrappers expose the source of the function they call.\nconst withFixturesOf = (source, f) => Object.defineProperty(f, \"toString\", {\n value: () => source.toString()\n});\nconst runHook = (fn, run) => withFixturesOf(fn, (...args) => {\n const result = fn(...args);\n if (!Effect.isEffect(result)) {\n return result;\n }\n const scope = Scope.makeUnsafe();\n // Everything the hook leaves behind lives in the scope: the resources it\n // acquired and, ahead of them, a cleanup function it returned. On failure\n // the scope closes inside the fiber, so interrupting it awaits the release.\n const effect = Scope.provide(result, scope).pipe(Effect.flatMap(cleanup => typeof cleanup === \"function\" ? Scope.addFinalizer(scope, Effect.promise(async () => await cleanup())) : Effect.void), Effect.onError(cause => Scope.close(scope, Exit.failCause(cause))));\n return run(args, effect, scope);\n});\n// Closing must outlive an already-aborted signal, so it runs without one.\nconst closeHookScope = scope => runPromise(Scope.close(scope, Exit.void));\n/** @internal */\nexport const beforeAll = (fn, timeout) => {\n let dispose = () => Promise.resolve();\n // Vitest drops the cleanup of a setup that outlives its timeout, so the\n // scope is disposed by the cleanup of a hook registered just before this\n // one. It runs in the same cleanup phase, in the slot next to this hook's,\n // with this hook's timeout.\n V.beforeAll(() => () => dispose(), timeout);\n V.beforeAll(runHook(fn, (_, effect, scope) => {\n const fiber = Effect.runFork(effect);\n // Interrupting a setup that Vitest stopped waiting for awaits its release.\n dispose = () => runPromise(Effect.andThen(Fiber.interrupt(fiber), Scope.close(scope, Exit.void)));\n return runPromise(Fiber.join(fiber));\n }), timeout);\n};\n/** @internal */\nexport const beforeEach = (fn, timeout) => V.beforeEach(runHook(fn, ([ctx], effect, scope) =>\n// The scope closes when Vitest runs the hook's cleanup after the test,\n// and the next test waits for it even if that cleanup times out.\nrunTest(ctx)(effect).then(() => () => settleOnAbort(ctx, closeHookScope(scope)))), timeout);\nconst makeItProxy = (it, overrides) => new Proxy(it, {\n apply(target, thisArg, argArray) {\n return Reflect.apply(target, thisArg, argArray);\n },\n get(target, property, receiver) {\n if (Object.hasOwn(overrides, property)) {\n return Reflect.get(overrides, property);\n }\n // do not bind: binding would strip vitest's static helpers (e.g. `describe.each`)\n return Reflect.get(target, property, receiver);\n }\n});\nconst collectTasks = (tasks, acc = []) => {\n for (let i = 0; i < tasks.length; i++) {\n const task = tasks[i];\n if (task.type === \"test\" && task.mode !== \"skip\" && task.mode !== \"todo\") {\n acc.push(task);\n } else if (task.tasks !== undefined) {\n collectTasks(task.tasks, acc);\n }\n }\n return acc;\n};\nconst runsMoreThanOnce = task => {\n const retry = typeof task.retry === \"number\" ? task.retry : task.retry?.count;\n return (retry ?? 0) > 0 || (task.repeats ?? 0) > 0;\n};\nconst registerProp = (it, name, arbitraries, property, timeout) => {\n const arbitrary = makeArbitrary(arbitraries);\n // Property callbacks receive only the base context; the empty source requests no fixtures.\n it(name, testOptions(timeout), withFixturesOf(() => {}, ctx => runCheck(ctx, arbitrary, values => property(values, ctx), checkOptions(timeout))));\n};\nconst makeTester = (mapEffect, it) => {\n const run = (ctx, args, self) => pipe(Effect.suspend(() => self(...args)), mapEffect, runTest(ctx));\n const register = test => (name, self, timeout) => test(name, testOptions(timeout), withFixturesOf(self, ctx => run(ctx, [ctx], self)));\n const each = cases => (name, self, timeout) => it.for(cases)(name, testOptions(timeout), withFixturesOf(self, (args, ctx) => run(ctx, [args, ctx], self).then(constVoid)));\n const prop = (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => Effect.mapEager(mapEffect(Effect.suspend(() => self(values, ctx))), value => value !== false), timeout);\n return Object.assign(register(it), {\n skip: register(it.skip),\n skipIf: condition => register(it.skipIf(condition)),\n runIf: condition => register(it.runIf(condition)),\n only: register(it.only),\n each,\n fails: register(it.fails),\n prop\n });\n};\nconst makeProp = it => (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => {\n const result = self(values, ctx);\n if (result !== undefined && typeof result !== \"boolean\") {\n throw new TypeError(\"it.prop callbacks must return boolean or void. Use it.effect.prop for Effect callbacks.\");\n }\n return result !== false;\n}, timeout);\nconst makeLayer = it => (layer_, options) => (...args) => {\n const excludeTestServices = options?.excludeTestServices ?? false;\n const withTestEnv = excludeTestServices ? layer_ : Layer.provideMerge(layer_, TestEnv);\n const memoMap = options?.memoMap ?? Effect.runSync(Layer.makeMemoMap);\n const buildPerTest = options?.buildPerTest ?? false;\n const suiteOptions = options?.concurrent === undefined ? {} : {\n concurrent: options.concurrent\n };\n const makeBlockMethods = provide => makeItProxy(it, {\n effect: makeTester(effect => provide(Effect.scoped(effect)), it),\n prop: makeProp(it),\n flakyTest,\n layer(nestedLayer, nestedOptions) {\n return makeLayer(it)(Layer.provideMerge(nestedLayer, withTestEnv), {\n ...nestedOptions,\n memoMap: Layer.forkMemoMapUnsafe(memoMap),\n excludeTestServices,\n // The services of a per-test block only exist during a test, so\n // blocks nested in it are built per test as well.\n buildPerTest: buildPerTest || nestedOptions?.buildPerTest === true\n });\n }\n });\n if (buildPerTest) {\n // Each test builds into its own fork of the memo map, so it reuses the\n // services of enclosing blocks and releases the rest when it finishes.\n const methods = makeBlockMethods(effect => Effect.scopedWith(scope => Layer.buildWithMemoMap(withTestEnv, Layer.forkMemoMapUnsafe(memoMap), scope).pipe(Effect.orDie, Effect.flatMap(context => Effect.provide(effect, context)))));\n if (args.length === 1) {\n return args[0](methods);\n }\n return V.describe(args[0], suiteOptions, () => args[1](methods));\n }\n const scope = Effect.runSync(Scope.make());\n const contextEffect = Layer.buildWithMemoMap(withTestEnv, memoMap, scope).pipe(Effect.orDie, Effect.cached, Effect.runSync);\n let closed = false;\n const closeScope = () => {\n if (closed) {\n return Promise.resolve();\n }\n closed = true;\n // Layer cleanup must outlive the last test's already-aborted signal.\n return runPromise(Scope.close(scope, Exit.void));\n };\n const methods = makeBlockMethods(effect => Effect.flatMap(contextEffect, context => Effect.provide(effect, context)));\n if (args.length === 1) {\n const currentSuite = getCurrentSuite();\n const previousTasks = new Set(currentSuite.tasks);\n args[0](methods);\n const blockTasks = collectTasks(currentSuite.tasks.filter(task => !previousTasks.has(task)));\n if (blockTasks.length === 0) {\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n const blockTaskSet = new Set(blockTasks);\n // Vitest runs hooks once per retry and repeat attempt, so a test's last\n // attempt cannot be counted. Blocks with such tests are released by `afterAll`.\n const releaseAfterLastTest = !blockTasks.some(runsMoreThanOnce);\n let remaining = blockTasks.length;\n V.beforeEach(\n // Destructured so Vitest can parse the hook once the suite defines fixtures.\n ({\n onTestFinished,\n signal,\n task\n }) => {\n if (!blockTaskSet.has(task)) {\n return;\n }\n if (releaseAfterLastTest) {\n onTestFinished(() => {\n remaining--;\n if (remaining === 0) {\n return closeScope();\n }\n });\n }\n return runPromise(Effect.asVoid(contextEffect), {\n signal\n });\n }, hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n return V.describe(args[0], suiteOptions, () => {\n V.beforeAll(() => runPromise(Effect.asVoid(contextEffect)), hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return args[1](methods);\n });\n};\n/** @internal */\nexport const flakyTest = (self, timeout = Duration.seconds(30)) => pipe(self, Effect.scoped, Effect.sandbox, Effect.retry(pipe(Schedule.recurs(10), Schedule.while(_ => Effect.succeed(Duration.isLessThanOrEqualTo(Duration.fromInputUnsafe(_.elapsed), Duration.fromInputUnsafe(timeout)))))), Effect.orDie);\n/** @internal */\nexport const makeMethods = it => makeItProxy(it, {\n effect: makeTester(flow(Effect.scoped, Effect.provide(TestEnv)), it),\n live: makeTester(Effect.scoped, it),\n flakyTest,\n layer: makeLayer(it),\n prop: makeProp(it)\n});\n/** @internal */\nexport const it = /*#__PURE__*/makeMethods(V.it);\n/** @internal */\nexport const {\n /** @internal */\n effect,\n /** @internal */\n layer,\n /** @internal */\n live,\n /** @internal */\n prop\n} = it;\n/** @internal */\nexport const describeWrapped = (name, f) => V.describe(name, () => f(it));\n//# sourceMappingURL=internal.js.map","import * as internal from \"./internal/internal.js\";\n/**\n * Re-exports the `vitest` API unchanged.\n *\n * @stability unstable\n * @since 4.0.0\n */\nexport * from \"vitest\";\n/**\n * Invokes the Effect Vitest equality-tester registration hook.\n *\n * @stability unstable\n * @category utils\n * @since 4.0.0\n */\nexport const addEqualityTesters = internal.addEqualityTesters;\n/**\n * Registers a callback to run once before all tests in the current suite. If\n * the callback returns an `Effect`, it is run and awaited with a `Scope` that\n * closes in a cleanup after the suite's `afterAll` hooks, within the hook's\n * timeout. The `Effect` must not require any other services.\n *\n * **Details**\n *\n * If Vitest stops waiting for the setup, the setup is interrupted before the\n * `Scope` closes. As with any `beforeAll` cleanup, Vitest reports a closing\n * that exceeds the hook's timeout and does not wait for it.\n *\n * @stability unstable\n * @category hooks\n * @since 4.0.0\n */\nexport const beforeAll = internal.beforeAll;\n/**\n * Registers a callback to run before each test in the current suite. If the\n * callback returns an `Effect`, it is run and awaited with a `Scope` that\n * closes when the test finishes, and interrupted if the hook times out. The\n * `Effect` must not require any other services.\n *\n * @stability unstable\n * @category hooks\n * @since 4.0.0\n */\nexport const beforeEach = internal.beforeEach;\n/**\n * Runs a scoped Effect test with test clock and console services.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const effect = internal.effect;\n/**\n * Runs a scoped Effect test with live services.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const live = internal.live;\n/**\n * Share a `Layer` between multiple tests, optionally wrapping\n * the tests in a `describe` block if a name is provided.\n *\n * **Details**\n *\n * Named layers accept `concurrent` to override inherited suite concurrency.\n * Anonymous layers always inherit the enclosing suite's concurrency.\n * Use `ctx.expect` in concurrent tests for test-local snapshots and assertion counts.\n *\n * Pass `buildPerTest: true` to build the layer once per test instead of once\n * per block. Each test gets new services, released when the test finishes,\n * while services from an enclosing `layer` block stay shared. A build failure\n * fails only that test. Blocks nested inside a per-test block are built per\n * test as well. `timeout` has no effect on a per-test block, since the test's\n * own timeout covers the build.\n *\n * **Example** (Sharing layers between tests)\n *\n * ```ts\n * import { assert, layer } from \"@effect/vitest\"\n * import { Effect, Layer, Context } from \"effect\"\n *\n * class Foo extends Context.Service<Foo, \"foo\">()(\"Foo\") {\n * static layer = Layer.succeed(Foo, \"foo\")\n * }\n *\n * class Bar extends Context.Service<Bar, \"bar\">()(\"Bar\") {\n * static layer = Layer.effect(\n * Bar,\n * Effect.map(Foo, () => \"bar\" as const)\n * )\n * }\n *\n * layer(Foo.layer)(\"layer\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * assert.strictEqual(foo, \"foo\")\n * }))\n *\n * it.layer(Bar.layer)(\"nested\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * const bar = yield* Bar\n * assert.strictEqual(foo, \"foo\")\n * assert.strictEqual(bar, \"bar\")\n * }))\n * })\n * })\n * ```\n *\n * **Example** (Building a layer for each test)\n *\n * ```ts\n * import { assert, layer } from \"@effect/vitest\"\n * import { Effect, Layer, Context, Ref } from \"effect\"\n *\n * class Database extends Context.Service<Database, \"database\">()(\"Database\") {\n * static layer = Layer.succeed(Database, \"database\")\n * }\n *\n * class Cache extends Context.Service<Cache, Ref.Ref<Array<string>>>()(\"Cache\") {\n * static layer = Layer.effect(\n * Cache,\n * Effect.andThen(Database, Ref.make<Array<string>>([]))\n * )\n * }\n *\n * layer(Database.layer)(\"repository\", (it) => {\n * // Database is shared, Cache is built for each test\n * it.layer(Cache.layer, { buildPerTest: true })((it) => {\n * it.effect(\"writes to the cache\", () =>\n * Effect.gen(function*() {\n * const cache = yield* Cache\n * yield* Ref.update(cache, (keys) => [...keys, \"a\"])\n * assert.deepStrictEqual(yield* Ref.get(cache), [\"a\"])\n * }))\n *\n * it.effect(\"starts with an empty cache\", () =>\n * Effect.gen(function*() {\n * const cache = yield* Cache\n * assert.deepStrictEqual(yield* Ref.get(cache), [])\n * }))\n * })\n * })\n * ```\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const layer = internal.layer;\n/**\n * Retries a scoped Effect to tolerate intermittent test failures, dying on exhausted retries.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const flakyTest = internal.flakyTest;\n/**\n * Runs a synchronous property test using schemas or arbitraries.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const prop = internal.prop;\n/**\n * Vitest test API extended with Effect test helpers.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const it = internal.it;\n/**\n * Creates the Effect test helpers for a Vitest test API, such as one extended with fixtures.\n *\n * **Details**\n *\n * Tests receive the fixtures they destructure from their context. Vitest sets them up before the test and tears\n * them down after the test's scope closes, as it does for its own tests. `it.effect.each` passes the context\n * after the test case, and named and anonymous `it.layer` blocks keep the fixtures.\n *\n * **Gotchas**\n *\n * Vitest reads the destructured names to decide which fixtures to set up. Once any fixture is defined, a test that\n * takes the whole context as a plain parameter, such as `(ctx) =>`, fails with a `FixtureParseError`. Property\n * tests receive only the base test context and cannot request fixtures; auto fixtures still run.\n *\n * **Example** (Using a Vitest fixture in an Effect test)\n *\n * ```ts\n * import { assert, makeMethods, test } from \"@effect/vitest\"\n * import { Effect } from \"effect\"\n *\n * const it = makeMethods(\n * test.extend(\"config\", { scope: \"file\" }, () => ({ port: 3000 }))\n * )\n *\n * it.effect(\"reads the config fixture\", ({ config }) =>\n * Effect.sync(() => {\n * assert.strictEqual(config.port, 3000)\n * }))\n * ```\n *\n * @stability unstable\n * @category constructors\n * @since 4.0.0\n */\nexport const makeMethods = internal.makeMethods;\n/**\n * Creates a named Vitest suite whose callback receives Effect test helpers.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const describeWrapped = internal.describeWrapped;\n//# sourceMappingURL=index.js.map","import { describe, it } from \"@effect/vitest\"\nimport { Duration, Effect, Fiber, Logger, Redacted, Ref, Stream } from \"effect\"\nimport { Base64 } from \"effect/encoding\"\nimport { expect } from \"vitest\"\nimport type { RealtimeEvent } from \"@effect-uai/core/Realtime\"\nimport { RealtimeInput } from \"@effect-uai/core/Realtime\"\nimport type { RealtimeSessionHandle } from \"@effect-uai/core/RealtimeSession\"\nimport * as FakeWebSocket from \"@effect-uai/core/testing/FakeWebSocket\"\nimport { type GeminiLiveRequest, openSession } from \"./realtimeSession.js\"\n\nconst request: GeminiLiveRequest = {\n model: \"gemini-3.1-flash-live-preview\",\n instructions: \"be terse\",\n voiceId: \"Kore\",\n inputFormat: { container: \"raw\", encoding: \"pcm_s16le\", sampleRate: 16000, channels: 1 },\n outputFormat: { container: \"raw\", encoding: \"pcm_s16le\", sampleRate: 24000, channels: 1 },\n}\n\nconst cfg = { apiKey: Redacted.make(\"test-key\") }\n\n/** The client speaks first here, so the handshake answers `setup`. */\nconst gemini = FakeWebSocket.make({\n reply: (frame) =>\n Effect.succeed(Object.hasOwn(frame as object, \"setup\") ? [{ setupComplete: {} }] : []),\n})\n\n/** Let the socket's own turn and the adapter's fibers run. */\nconst tick = Effect.sleep(\"5 millis\")\n\n/**\n * Events are recorded as they arrive rather than collected at the end, so a\n * run that ends in a failure still says what the caller saw before it.\n */\nconst transcript = (\n server: FakeWebSocket.FakeWebSocketServer,\n script: (handle: RealtimeSessionHandle) => Effect.Effect<void, unknown>,\n options?: { readonly closeCode?: number; readonly request?: GeminiLiveRequest },\n) =>\n Effect.gen(function* () {\n const handle = yield* openSession({ ...cfg, webSocket: server.connect })(\n options?.request ?? request,\n )\n const seen = yield* Ref.make<ReadonlyArray<RealtimeEvent>>([])\n const collector = yield* Effect.forkChild(\n Effect.exit(Stream.runForEach(handle.events, (e) => Ref.update(seen, (xs) => [...xs, e]))),\n )\n yield* script(handle)\n yield* tick\n yield* server.close(options?.closeCode ?? 1000)\n const exit = yield* Fiber.join(collector)\n return { exit, events: yield* Ref.get(seen) }\n })\n\nconst tags = (events: ReadonlyArray<RealtimeEvent>) => events.map((e) => e._tag)\n\nconst audioPart = (bytes: ReadonlyArray<number>) => ({\n inlineData: {\n mimeType: \"audio/pcm;rate=24000\",\n data: Base64.encode(new Uint8Array(bytes)),\n },\n})\n\ndescribe(\"Gemini live session turns\", () => {\n it.live(\"mints one turn id for a whole answer, and reports its usage at the end\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n // 3.1 packs several parts, and their transcription, into one message.\n yield* server.push({\n serverContent: {\n modelTurn: { parts: [audioPart([1, 2, 3]), { thought: true, text: \"planning\" }] },\n outputTranscription: { text: \"hi\" },\n },\n })\n yield* server.push({\n serverContent: { modelTurn: { parts: [audioPart([4, 5])] } },\n usageMetadata: { promptTokenCount: 10, responseTokenCount: 20, totalTokenCount: 30 },\n })\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n // The thought part is the model reasoning, not something to speak.\n expect(tags(events)).toEqual([\n \"ResponseStarted\",\n \"AudioDelta\",\n \"OutputTranscriptDelta\",\n \"AudioDelta\",\n \"ResponseDone\",\n ])\n // The wire carries no response id, so every event of the turn shares one.\n expect(new Set(events.map((e) => (\"responseId\" in e ? e.responseId : \"\")))).toEqual(\n new Set([\"turn_1\"]),\n )\n const done = events[4]\n expect(done?._tag === \"ResponseDone\" && done.reason).toBe(\"complete\")\n expect(done?._tag === \"ResponseDone\" && done.usage?.total_tokens).toBe(30)\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends an interrupted turn once, and numbers the next one after it\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n yield* server.push({ serverContent: { modelTurn: { parts: [audioPart([1])] } } })\n yield* server.push({ serverContent: { interrupted: true } })\n // The server follows an interruption with `turnComplete`, which\n // would otherwise end the same turn a second time.\n yield* server.push({ serverContent: { turnComplete: true } })\n yield* server.push({ serverContent: { modelTurn: { parts: [audioPart([2])] } } })\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n expect(tags(events)).toEqual([\n \"ResponseStarted\",\n \"AudioDelta\",\n \"Interrupted\",\n \"ResponseDone\",\n \"ResponseStarted\",\n \"AudioDelta\",\n \"ResponseDone\",\n ])\n const interrupted = events[3]\n expect(interrupted?._tag === \"ResponseDone\" && interrupted.reason).toBe(\"interrupted\")\n const next = events[4]\n expect(next?._tag === \"ResponseStarted\" && next.responseId).toBe(\"turn_2\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"marks the user's words interim until the utterance is transcribed\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, () =>\n Effect.gen(function* () {\n yield* server.push({ serverContent: { interimInputTranscription: { text: \"weather\" } } })\n yield* server.push({\n serverContent: { inputTranscription: { text: \"weather in Lisbon\" } },\n })\n }),\n )\n\n // A transcript belongs to no turn, so none is started for it.\n expect(events).toEqual([\n { _tag: \"InputTranscript\", text: \"weather\", final: false },\n { _tag: \"InputTranscript\", text: \"weather in Lisbon\", final: true },\n ])\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends the stream as an incomplete turn when a turn is still running\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { exit } = yield* transcript(server, () =>\n server.push({ serverContent: { modelTurn: { parts: [audioPart([1])] } } }),\n )\n\n // A close must never look like a finished turn.\n expect(exit._tag).toBe(\"Failure\")\n expect(JSON.stringify(exit)).toContain(\"IncompleteTurn\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"fails when the socket closes before the configuration is accepted\", () =>\n Effect.gen(function* () {\n const mute = yield* FakeWebSocket.make()\n const opened = yield* Effect.forkChild(\n Effect.exit(openSession({ ...cfg, webSocket: mute.connect })(request)),\n )\n yield* tick\n yield* mute.close(1000)\n\n const exit = yield* Fiber.join(opened)\n expect(exit._tag).toBe(\"Failure\")\n expect(JSON.stringify(exit)).toContain(\"Unavailable\")\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session tools\", () => {\n it.live(\"answers a call with the name the server gave it\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events } = yield* transcript(server, (handle) =>\n Effect.gen(function* () {\n yield* server.push({\n toolCall: {\n functionCalls: [{ id: \"fc_1\", name: \"get_weather\", args: { city: \"Lisbon\" } }],\n },\n })\n yield* tick\n yield* handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: [{ type: \"input_json\", value: { celsius: 32 } }],\n providerData: undefined,\n },\n }),\n )\n yield* server.push({ serverContent: { turnComplete: true } })\n }),\n )\n\n const call = events.find((e) => e._tag === \"ToolCall\")\n expect(call?._tag === \"ToolCall\" && call.call.arguments).toBe('{\"city\":\"Lisbon\"}')\n // A call arrives with no turn open, so it gets one of its own.\n expect(call?._tag === \"ToolCall\" && call.responseId).toBe(\"turn_1\")\n\n const sent = yield* server.sent\n const response = sent.find((f: any) => f.toolResponse !== undefined) as any\n // The name comes from the call, and the payload has to be an object.\n // `WHEN_IDLE` by default: a model that kept talking while the tool ran\n // finishes the sentence rather than cutting itself off to report.\n expect(response.toolResponse.functionResponses).toEqual([\n {\n id: \"fc_1\",\n name: \"get_weather\",\n response: { output: { celsius: 32 } },\n scheduling: \"WHEN_IDLE\",\n },\n ])\n }).pipe(Effect.scoped),\n )\n\n it.live(\"reports a result at once when the caller asks it to interrupt\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n yield* transcript(\n server,\n (handle) =>\n Effect.gen(function* () {\n yield* server.push({\n toolCall: { functionCalls: [{ id: \"fc_1\", name: \"get_weather\", args: {} }] },\n })\n yield* tick\n yield* handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: [{ type: \"input_json\", value: {} }],\n providerData: undefined,\n },\n }),\n )\n }),\n { request: { ...request, toolScheduling: \"interrupt\" } },\n )\n\n const sent = yield* server.sent\n const response = sent.find((f: any) => f.toolResponse !== undefined) as any\n expect(response.toolResponse.functionResponses[0].scheduling).toBe(\"INTERRUPT\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"rejects a result for a call this session never made\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const handle = yield* openSession({ ...cfg, webSocket: server.connect })(request)\n const failure = yield* Effect.exit(\n handle.send(\n RealtimeInput.ToolResult({\n output: {\n type: \"function_call_output\",\n call_id: \"fc_unknown\",\n output: [{ type: \"input_json\", value: {} }],\n providerData: undefined,\n },\n }),\n ),\n )\n\n expect(failure._tag).toBe(\"Failure\")\n expect(JSON.stringify(failure)).toContain(\"InvalidRequest\")\n expect((yield* server.sent).some((f: any) => f.toolResponse !== undefined)).toBe(false)\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session lifetime\", () => {\n it.live(\"keeps only a resumable handle, and reads the closing warning as a duration\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { events, exit } = yield* transcript(server, () =>\n Effect.gen(function* () {\n // Sent while a tool runs: no handle, and the stored one must stand.\n yield* server.push({ sessionResumptionUpdate: { newHandle: \"\", resumable: false } })\n yield* server.push({ sessionResumptionUpdate: { newHandle: \"h1\", resumable: true } })\n yield* server.push({ goAway: { timeLeft: \"60s\" } })\n }),\n )\n\n expect(tags(events)).toEqual([\"ResumptionHandle\", \"SessionEnding\"])\n const handle = events[0]\n expect(handle?._tag === \"ResumptionHandle\" && handle.handle).toBe(\"h1\")\n const ending = events[1]\n // A proto duration string, not a number.\n expect(ending?._tag === \"SessionEnding\" && ending.timeLeft).toEqual(Duration.seconds(60))\n // The close `goAway` announced is the lifetime cap, not a clean end, so\n // a caller can tell \"reconnect\" from \"we are done here\".\n expect(JSON.stringify(exit)).toContain(\"SessionExpired\")\n }).pipe(Effect.scoped),\n )\n\n it.live(\"ends cleanly when the close was not announced\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const { exit } = yield* transcript(server, () =>\n server.push({ serverContent: { turnComplete: true } }),\n )\n\n expect(exit._tag).toBe(\"Success\")\n }).pipe(Effect.scoped),\n )\n})\n\n/** The `CapabilityWarning` payloads a run produced, in order. */\nconst warningCollector = () => {\n const seen: Array<{ readonly field: string; readonly value?: unknown }> = []\n const logger = Logger.make((options) => {\n const [label, warning] = options.message as ReadonlyArray<any>\n if (label === \"Capability dropped\") seen.push(warning)\n })\n return { seen, layer: Logger.layer([logger]) }\n}\n\nconst userText = (text: string) =>\n ({\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text, providerData: undefined }],\n providerData: undefined,\n }) as const\n\nconst call = (id: string) =>\n ({\n type: \"function_call\",\n call_id: id,\n name: \"get_time\",\n arguments: \"{}\",\n providerData: undefined,\n }) as const\n\ndescribe(\"Gemini live session history\", () => {\n it.live(\"names each kind of item the text-only seed cannot carry, once\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n const warnings = warningCollector()\n\n yield* openSession({ ...cfg, webSocket: server.connect })({\n ...request,\n history: [\n userText(\"what time is it\"),\n call(\"fc_1\"),\n call(\"fc_2\"),\n {\n type: \"function_call_output\",\n call_id: \"fc_1\",\n output: [{ type: \"input_json\", value: { now: \"12:00\" } }],\n providerData: undefined,\n },\n ],\n }).pipe(Effect.provide(warnings.layer))\n yield* tick\n\n // Two calls, one kind: a long tool history is not a wall of warnings.\n expect(warnings.seen.map((w) => w.value)).toEqual([\"function_call\", \"function_call_output\"])\n expect(warnings.seen.every((w) => w.field === \"history\")).toBe(true)\n\n const sent = yield* server.sent\n const seed = sent.find((f: any) => f.clientContent !== undefined) as any\n expect(seed.clientContent.turns).toEqual([\n { role: \"user\", parts: [{ text: \"what time is it\" }] },\n ])\n }).pipe(Effect.scoped),\n )\n})\n\ndescribe(\"Gemini live session video\", () => {\n it.live(\"sends frame bytes inline, and refuses a frame it would have to fetch\", () =>\n Effect.gen(function* () {\n const server = yield* gemini\n yield* transcript(server, (handle) =>\n Effect.gen(function* () {\n yield* handle.send(\n RealtimeInput.VideoFrame({\n frame: { _tag: \"bytes\", bytes: new Uint8Array([1, 2]), mimeType: \"image/jpeg\" },\n }),\n )\n // A URL would need an upload through the Files API first.\n const exit = yield* Effect.exit(\n handle.send(\n RealtimeInput.VideoFrame({\n frame: { _tag: \"url\", url: \"https://example.com/frame.jpg\" },\n }),\n ),\n )\n expect(JSON.stringify(exit)).toContain(\"Unsupported\")\n }),\n )\n\n const sent = yield* server.sent\n expect(sent.filter((f: any) => f.realtimeInput?.video !== undefined)).toEqual([\n {\n realtimeInput: {\n video: { data: Base64.encode(new Uint8Array([1, 2])), mimeType: \"image/jpeg\" },\n },\n },\n ])\n }).pipe(Effect.scoped),\n )\n})\n"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,kBAAA,WAA+B;AACrC,MAAM,cAAc,QAAQ,QAAQA,SAAO,WAI3CA,SAAO,qBAAoB,YAAWA,SAAO,IAAI,aAAa;CAC5D,MAAM,OAAO,OAAOA,SAAO,KAAK,QAAQ,MAAM,CAAC;CAC/C,IAAI,KAAK,UAAU,IAAI,GAAG;EACxB,MAAM,SAASC,QAAM,aAAa,KAAK,KAAK;EAC5C,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,OAAOD,SAAO,SAAS,OAAO,EAAE;CAEpC;CACA,OAAO,OAAO;AAChB,CAAC,CAAC,GAAG,EACH,QAAQ,KAAK,OACf,CAAC;AACD,MAAM,iBAAiB,KAAK,YAAY;CAItC,MAAM,gBAAgB,IAAI,qBAAqB,QAAQ,KAAK,WAAW,SAAS,CAAC;CACjF,IAAI,OAAO,iBAAiB,SAAS,SAAS,EAC5C,MAAM,KACR,CAAC;CACD,MAAM,gBAAgB,IAAI,OAAO,oBAAoB,SAAS,OAAO;CACrE,QAAQ,KAAK,SAAS,OAAO;CAE7B,IAAI,IAAI,OAAO,SAAS,QAAQ;CAChC,OAAO;AACT;;AAEA,MAAM,WAAU,SAAO,WAAU;CAC/B,MAAM,UAAU,WAAW,QAAQ,GAAG;CACtC,OAAO,MAAM,cAAc,KAAK,OAAO,IAAI;AAC7C;AACA,MAAM,UAAuB,sBAAM,SAAS,YAAY,OAAoB,wBAAU,MAAM,CAAC;;AAM7F,MAAM,eAAc,YAAW,OAAO,YAAY,WAAW,EAC3D,QACF,IAAI,WAAW,CAAC;AAChB,MAAM,eAAc,YAAW,YAAY,KAAA,IAAY,KAAA,IAAYE,WAAS,SAASA,WAAS,gBAAgB,OAAO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,QAAQ,MAAW,EAAE,eAAe,UAAU,KAAA,CAAS,CAAC,CAAC,CAAC,QAAQ,CAC5E,EACE,eAAe,EACb,OAAO;GAAE,MAAM,OAAO,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;GAAG,UAAU;EAAa,EAC/E,EACF,CACF,CAAC;CACH,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,CACvB;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-uai/google",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-dev-20261110065930",
|
|
4
4
|
"description": "Google Gemini provider for @effect-uai/core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
"access": "public"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"effect": "4.
|
|
70
|
+
"effect": "4.1.2",
|
|
71
71
|
"typescript": "^7.0.2",
|
|
72
|
-
"@effect-uai/core": "0.
|
|
72
|
+
"@effect-uai/core": "0.19.0-dev-20261110065930"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@effect-uai/core": "
|
|
75
|
+
"@effect-uai/core": "0.19.0-dev-20261110065930",
|
|
76
76
|
"effect": ">=4.0.1 <5.0.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { fileUrl } from "@effect-uai/core/File"
|
|
2
|
+
import { imageBytes } from "@effect-uai/core/Image"
|
|
3
|
+
import * as Items from "@effect-uai/core/Items"
|
|
4
|
+
import { describe, expect, it } from "vitest"
|
|
5
|
+
import { functionResponseBody } from "./codec.js"
|
|
6
|
+
|
|
7
|
+
const body = (output: Items.ToolCallOutput["output"], isError?: boolean) =>
|
|
8
|
+
functionResponseBody({
|
|
9
|
+
type: "function_call_output",
|
|
10
|
+
call_id: "c1",
|
|
11
|
+
output,
|
|
12
|
+
...(isError !== undefined && { isError }),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe("functionResponseBody", () => {
|
|
16
|
+
it("puts one JSON value under output as an object, never a string", () => {
|
|
17
|
+
expect(body([Items.json({ city: "Lisbon", temp: 18 })])).toEqual({
|
|
18
|
+
response: { output: { city: "Lisbon", temp: 18 } },
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it("puts a failure under error", () => {
|
|
23
|
+
expect(body([Items.json({ _tag: "CityNotFound", city: "Atlantis" })], true)).toEqual({
|
|
24
|
+
response: { error: { _tag: "CityNotFound", city: "Atlantis" } },
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("keeps several values as an array and moves media to parts", () => {
|
|
29
|
+
expect(
|
|
30
|
+
body([
|
|
31
|
+
Items.text("Home"),
|
|
32
|
+
Items.json({ hits: 2 }),
|
|
33
|
+
Items.image(imageBytes(new Uint8Array([1, 2, 3]), "image/png")),
|
|
34
|
+
Items.file(fileUrl("gs://bucket/a.pdf", "application/pdf"), "a.pdf"),
|
|
35
|
+
]),
|
|
36
|
+
).toEqual({
|
|
37
|
+
response: { output: ["Home", { hits: 2 }] },
|
|
38
|
+
parts: [
|
|
39
|
+
{ inlineData: { mimeType: "image/png", data: "AQID" } },
|
|
40
|
+
{
|
|
41
|
+
fileData: {
|
|
42
|
+
fileUri: "gs://bucket/a.pdf",
|
|
43
|
+
mimeType: "application/pdf",
|
|
44
|
+
displayName: "a.pdf",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it("sends an empty response for media-only output", () => {
|
|
52
|
+
expect(body([Items.image(imageBytes(new Uint8Array([1]), "image/png"))]).response).toEqual({})
|
|
53
|
+
})
|
|
54
|
+
})
|
package/src/codec.ts
CHANGED
|
@@ -3,9 +3,12 @@ import { Base64 } from "effect/encoding"
|
|
|
3
3
|
import * as AiError from "@effect-uai/core/AiError"
|
|
4
4
|
import type { ImageSource } from "@effect-uai/core/Image"
|
|
5
5
|
import { imageBase64 } from "@effect-uai/core/Image"
|
|
6
|
+
import type { FileSource } from "@effect-uai/core/File"
|
|
6
7
|
import type {
|
|
7
8
|
ContentBlock,
|
|
8
9
|
ToolCall,
|
|
10
|
+
ToolCallOutput,
|
|
11
|
+
ToolOutputContent,
|
|
9
12
|
InputImage,
|
|
10
13
|
HistoryItem,
|
|
11
14
|
Message,
|
|
@@ -153,10 +156,9 @@ type RequestPart =
|
|
|
153
156
|
readonly thoughtSignature?: string
|
|
154
157
|
}
|
|
155
158
|
| {
|
|
156
|
-
readonly functionResponse: {
|
|
159
|
+
readonly functionResponse: FunctionResponseBody & {
|
|
157
160
|
readonly id?: string
|
|
158
161
|
readonly name: string
|
|
159
|
-
readonly response: Record<string, unknown>
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -295,31 +297,98 @@ const allMessages = (history: ReadonlyArray<HistoryItem>): ReadonlyArray<Message
|
|
|
295
297
|
// ---------------------------------------------------------------------------
|
|
296
298
|
// Function-call round-trip
|
|
297
299
|
//
|
|
298
|
-
// `ToolCall.arguments`
|
|
299
|
-
//
|
|
300
|
-
// expect parsed JSON *objects*. Decode via Schema:
|
|
301
|
-
// - object payload → use as-is
|
|
302
|
-
// - scalar / array / malformed → wrap as `{ output: <raw string> }` so the
|
|
303
|
-
// model still sees *some* response without crashing the request.
|
|
300
|
+
// `ToolCall.arguments` is a JSON string; Gemini's `functionCall.args` wants
|
|
301
|
+
// an object (malformed or non-object arguments become `{}`).
|
|
304
302
|
// ---------------------------------------------------------------------------
|
|
305
303
|
|
|
306
304
|
const JsonObject = Schema.Record(Schema.String, Schema.Unknown)
|
|
307
305
|
const decodeJsonObject = Schema.decodeResult(Schema.fromJsonString(JsonObject))
|
|
308
306
|
|
|
309
|
-
const
|
|
310
|
-
(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
307
|
+
const parsedArgs = (encoded: string): Record<string, unknown> =>
|
|
308
|
+
pipe(
|
|
309
|
+
decodeJsonObject(encoded),
|
|
310
|
+
Result.getOrElse(() => ({})),
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
type MediaPart =
|
|
314
|
+
| {
|
|
315
|
+
readonly inlineData: {
|
|
316
|
+
readonly mimeType: string
|
|
317
|
+
readonly data: string
|
|
318
|
+
readonly displayName?: string
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
| {
|
|
322
|
+
readonly fileData: {
|
|
323
|
+
readonly fileUri: string
|
|
324
|
+
readonly mimeType?: string
|
|
325
|
+
readonly displayName?: string
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const mediaPart = (
|
|
330
|
+
source: ImageSource | FileSource,
|
|
331
|
+
displayName: string | undefined,
|
|
332
|
+
): MediaPart => {
|
|
333
|
+
const named = displayName === undefined ? {} : { displayName }
|
|
334
|
+
return Match.value(source).pipe(
|
|
335
|
+
Match.tagsExhaustive({
|
|
336
|
+
url: (s) => ({
|
|
337
|
+
fileData: {
|
|
338
|
+
fileUri: s.url,
|
|
339
|
+
...(s.mimeType !== undefined && { mimeType: s.mimeType }),
|
|
340
|
+
...named,
|
|
341
|
+
},
|
|
317
342
|
}),
|
|
318
|
-
|
|
343
|
+
base64: (s) => ({ inlineData: { mimeType: s.mimeType, data: s.base64, ...named } }),
|
|
344
|
+
bytes: (s) => ({
|
|
345
|
+
inlineData: { mimeType: s.mimeType, data: Base64.encode(s.bytes), ...named },
|
|
346
|
+
}),
|
|
347
|
+
}),
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Gemini's `functionResponse` body for a tool output, without `id` / `name`. */
|
|
352
|
+
export type FunctionResponseBody = {
|
|
353
|
+
readonly response: Record<string, unknown>
|
|
354
|
+
readonly parts?: ReadonlyArray<MediaPart>
|
|
355
|
+
}
|
|
319
356
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
357
|
+
/**
|
|
358
|
+
* Text and JSON go into `response.output` (or `response.error` when the call
|
|
359
|
+
* failed) as values, never stringified: one value as itself, several as an
|
|
360
|
+
* array. Media goes into `parts`.
|
|
361
|
+
*/
|
|
362
|
+
export const functionResponseBody = (output: ToolCallOutput): FunctionResponseBody => {
|
|
363
|
+
const values = Arr.filterMap(
|
|
364
|
+
output.output,
|
|
365
|
+
Match.type<ToolOutputContent>().pipe(
|
|
366
|
+
Match.discriminatorsExhaustive("type")({
|
|
367
|
+
input_text: (p) => Result.succeed<unknown>(p.text),
|
|
368
|
+
input_json: (p) => Result.succeed<unknown>(p.value),
|
|
369
|
+
input_image: () => Result.failVoid,
|
|
370
|
+
input_file: () => Result.failVoid,
|
|
371
|
+
}),
|
|
372
|
+
),
|
|
373
|
+
)
|
|
374
|
+
const media = Arr.filterMap(
|
|
375
|
+
output.output,
|
|
376
|
+
Match.type<ToolOutputContent>().pipe(
|
|
377
|
+
Match.discriminatorsExhaustive("type")({
|
|
378
|
+
input_text: () => Result.failVoid,
|
|
379
|
+
input_json: () => Result.failVoid,
|
|
380
|
+
input_image: (p) => Result.succeed(mediaPart(p.source, undefined)),
|
|
381
|
+
input_file: (p) => Result.succeed(mediaPart(p.source, p.filename)),
|
|
382
|
+
}),
|
|
383
|
+
),
|
|
384
|
+
)
|
|
385
|
+
const key = output.isError === true ? "error" : "output"
|
|
386
|
+
const response = Arr.match(values, {
|
|
387
|
+
onEmpty: () => ({}),
|
|
388
|
+
onNonEmpty: (all) => ({ [key]: all.length === 1 ? Arr.headNonEmpty(all) : all }),
|
|
389
|
+
})
|
|
390
|
+
return media.length === 0 ? { response } : { response, parts: media }
|
|
391
|
+
}
|
|
323
392
|
|
|
324
393
|
/**
|
|
325
394
|
* `ToolCallOutput` only carries `call_id`; Gemini's `functionResponse`
|
|
@@ -423,7 +492,7 @@ const itemToContent =
|
|
|
423
492
|
onNone: () => ({}),
|
|
424
493
|
}),
|
|
425
494
|
name: Option.getOrElse(nameForCallId(history, o.call_id), () => o.call_id),
|
|
426
|
-
|
|
495
|
+
...functionResponseBody(o),
|
|
427
496
|
},
|
|
428
497
|
},
|
|
429
498
|
],
|
package/src/geminiTools.test.ts
CHANGED
|
@@ -16,6 +16,7 @@ const localTool = Tool.make({
|
|
|
16
16
|
name: "get_weather",
|
|
17
17
|
description: "Look up the weather.",
|
|
18
18
|
inputSchema: Tool.fromEffectSchema(Schema.Struct({ city: Schema.String })),
|
|
19
|
+
outputSchema: Schema.String,
|
|
19
20
|
run: ({ city }) => Effect.succeed(`sunny in ${city}`),
|
|
20
21
|
})
|
|
21
22
|
|
|
@@ -196,7 +196,7 @@ describe("Gemini live session tools", () => {
|
|
|
196
196
|
output: {
|
|
197
197
|
type: "function_call_output",
|
|
198
198
|
call_id: "fc_1",
|
|
199
|
-
output:
|
|
199
|
+
output: [{ type: "input_json", value: { celsius: 32 } }],
|
|
200
200
|
providerData: undefined,
|
|
201
201
|
},
|
|
202
202
|
}),
|
|
@@ -219,7 +219,7 @@ describe("Gemini live session tools", () => {
|
|
|
219
219
|
{
|
|
220
220
|
id: "fc_1",
|
|
221
221
|
name: "get_weather",
|
|
222
|
-
response: { celsius: 32 },
|
|
222
|
+
response: { output: { celsius: 32 } },
|
|
223
223
|
scheduling: "WHEN_IDLE",
|
|
224
224
|
},
|
|
225
225
|
])
|
|
@@ -242,7 +242,7 @@ describe("Gemini live session tools", () => {
|
|
|
242
242
|
output: {
|
|
243
243
|
type: "function_call_output",
|
|
244
244
|
call_id: "fc_1",
|
|
245
|
-
output: "{}
|
|
245
|
+
output: [{ type: "input_json", value: {} }],
|
|
246
246
|
providerData: undefined,
|
|
247
247
|
},
|
|
248
248
|
}),
|
|
@@ -267,7 +267,7 @@ describe("Gemini live session tools", () => {
|
|
|
267
267
|
output: {
|
|
268
268
|
type: "function_call_output",
|
|
269
269
|
call_id: "fc_unknown",
|
|
270
|
-
output: "{}
|
|
270
|
+
output: [{ type: "input_json", value: {} }],
|
|
271
271
|
providerData: undefined,
|
|
272
272
|
},
|
|
273
273
|
}),
|
|
@@ -360,7 +360,7 @@ describe("Gemini live session history", () => {
|
|
|
360
360
|
{
|
|
361
361
|
type: "function_call_output",
|
|
362
362
|
call_id: "fc_1",
|
|
363
|
-
output:
|
|
363
|
+
output: [{ type: "input_json", value: { now: "12:00" } }],
|
|
364
364
|
providerData: undefined,
|
|
365
365
|
},
|
|
366
366
|
],
|
package/src/realtimeSession.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
} from "@effect-uai/core/Realtime"
|
|
37
37
|
import type { RealtimeSessionHandle } from "@effect-uai/core/RealtimeSession"
|
|
38
38
|
import * as WebSocketSession from "@effect-uai/core/WebSocketSession"
|
|
39
|
-
import {
|
|
39
|
+
import { functionResponseBody, toolDescriptorsToTools } from "./codec.js"
|
|
40
40
|
import type { GeminiLiveModel } from "./models.js"
|
|
41
41
|
|
|
42
42
|
const PROVIDER = "gemini-live"
|
|
@@ -635,7 +635,7 @@ const handleInput = (
|
|
|
635
635
|
{
|
|
636
636
|
id: i.output.call_id,
|
|
637
637
|
name,
|
|
638
|
-
|
|
638
|
+
...functionResponseBody(i.output),
|
|
639
639
|
scheduling: options.scheduling,
|
|
640
640
|
},
|
|
641
641
|
],
|