{"version":3,"file":"codec.test.mjs","names":[],"sources":["../src/codec.test.ts"],"sourcesContent":["import { fileBase64, fileUrl } from \"@effect-uai/core/File\"\nimport { imageBytes } from \"@effect-uai/core/Image\"\nimport * as Items from \"@effect-uai/core/Items\"\nimport { Option, Result } from \"effect\"\nimport { describe, expect, it } from \"vitest\"\nimport { buildRequestBody } from \"./codec.js\"\n\nconst toolResultFor = (output: Items.ToolCallOutput) => {\n  const body = Result.getOrThrow(\n    buildRequestBody({\n      model: \"claude-sonnet-4-5\",\n      history: [\n        Items.userText(\"go\"),\n        { type: \"function_call\", call_id: \"c1\", name: \"shot\", arguments: \"{}\" },\n        output,\n      ],\n      maxTokens: 1024,\n      temperature: Option.none(),\n      topP: Option.none(),\n      topK: Option.none(),\n      stopSequences: Option.none(),\n      thinking: Option.none(),\n      tools: Option.none(),\n      toolChoice: Option.none(),\n      userId: Option.none(),\n      outputConfig: Option.none(),\n      cacheControl: Option.none(),\n    }),\n  )\n  return body.messages.at(-1)?.content\n}\n\nconst outputOf = (output: Items.ToolCallOutput[\"output\"], isError?: boolean) =>\n  toolResultFor({\n    type: \"function_call_output\",\n    call_id: \"c1\",\n    output,\n    ...(isError !== undefined && { isError }),\n  })\n\ndescribe(\"tool_result\", () => {\n  it(\"sends text and JSON as one string and flags failures with is_error\", () => {\n    expect(outputOf([Items.json({ _tag: \"CityNotFound\", city: \"Atlantis\" })], true)).toEqual([\n      {\n        type: \"tool_result\",\n        tool_use_id: \"c1\",\n        content: '{\"_tag\":\"CityNotFound\",\"city\":\"Atlantis\"}',\n        is_error: true,\n      },\n    ])\n  })\n\n  it(\"sends media as image and document blocks, the filename as the document title\", () => {\n    expect(\n      outputOf([\n        Items.text(\"Home\"),\n        Items.image(imageBytes(new Uint8Array([1, 2, 3]), \"image/png\")),\n        Items.file(fileBase64(\"JVBE\", \"application/pdf\"), \"report.pdf\"),\n        Items.file(fileUrl(\"https://x/a.pdf\")),\n      ]),\n    ).toEqual([\n      {\n        type: \"tool_result\",\n        tool_use_id: \"c1\",\n        content: [\n          { type: \"text\", text: \"Home\" },\n          { type: \"image\", source: { type: \"base64\", media_type: \"image/png\", data: \"AQID\" } },\n          {\n            type: \"document\",\n            source: { type: \"base64\", media_type: \"application/pdf\", data: \"JVBE\" },\n            title: \"report.pdf\",\n          },\n          { type: \"document\", source: { type: \"url\", url: \"https://x/a.pdf\" } },\n        ],\n      },\n    ])\n  })\n})\n"],"mappings":";;;;;;;AAOA,MAAM,iBAAiB,WAAiC;CAsBtD,OArBa,OAAO,WAClB,iBAAiB;EACf,OAAO;EACP,SAAS;GACP,MAAM,SAAS,IAAI;GACnB;IAAE,MAAM;IAAiB,SAAS;IAAM,MAAM;IAAQ,WAAW;GAAK;GACtE;EACF;EACA,WAAW;EACX,aAAa,OAAO,KAAK;EACzB,MAAM,OAAO,KAAK;EAClB,MAAM,OAAO,KAAK;EAClB,eAAe,OAAO,KAAK;EAC3B,UAAU,OAAO,KAAK;EACtB,OAAO,OAAO,KAAK;EACnB,YAAY,OAAO,KAAK;EACxB,QAAQ,OAAO,KAAK;EACpB,cAAc,OAAO,KAAK;EAC1B,cAAc,OAAO,KAAK;CAC5B,CAAC,CAEO,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,EAAE;AAC/B;AAEA,MAAM,YAAY,QAAwC,YACxD,cAAc;CACZ,MAAM;CACN,SAAS;CACT;CACA,GAAI,YAAY,KAAA,KAAa,EAAE,QAAQ;AACzC,CAAC;AAEH,SAAS,qBAAqB;CAC5B,GAAG,4EAA4E;EAC7E,aAAO,SAAS,CAAC,MAAM,KAAK;GAAE,MAAM;GAAgB,MAAM;EAAW,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CACvF;GACE,MAAM;GACN,aAAa;GACb,SAAS;GACT,UAAU;EACZ,CACF,CAAC;CACH,CAAC;CAED,GAAG,sFAAsF;EACvF,aACE,SAAS;GACP,MAAM,KAAK,MAAM;GACjB,MAAM,MAAM,WAAW,IAAI,WAAW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