@zyro-sec/ai 1.0.0 → 1.0.2
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/AGENTS.md +23 -0
- package/example/tutorial.ts +284 -0
- package/package.json +11 -13
- package/script/pack.ts +5 -0
- package/script/recording-cost-report.ts +250 -0
- package/script/setup-recording-env.ts +602 -0
- package/src/ai-client.ts +28 -0
- package/src/cache-policy.ts +249 -0
- package/src/decision-client.ts +88 -0
- package/src/decision.ts +335 -0
- package/src/effect.ts +44 -0
- package/src/effort-updates.ts +25 -0
- package/src/embedding-client.ts +46 -0
- package/src/embedding.ts +167 -0
- package/src/experimental/cloudflare-run-extraction.ts +112 -0
- package/src/experimental/extraction.ts +190 -0
- package/src/experimental/realtime.ts +211 -0
- package/src/experimental.ts +51 -0
- package/src/generation.ts +210 -0
- package/src/image-client.ts +89 -0
- package/src/image.ts +236 -0
- package/src/index.ts +363 -0
- package/src/llm.ts +364 -0
- package/src/loop.ts +214 -0
- package/src/media-client.ts +94 -0
- package/src/media-model.ts +129 -0
- package/src/media.ts +408 -0
- package/src/protocols/alibaba-chat.ts +95 -0
- package/src/protocols/alibaba-images.ts +126 -0
- package/src/protocols/alibaba-messages.ts +49 -0
- package/src/protocols/alibaba-responses.ts +86 -0
- package/src/protocols/anthropic-messages.ts +1664 -0
- package/src/protocols/assemblyai-transcription.ts +209 -0
- package/src/protocols/bedrock-converse.ts +984 -0
- package/src/protocols/bedrock-event-stream.ts +147 -0
- package/src/protocols/cartesia-speech.ts +182 -0
- package/src/protocols/cloudflare-run-decisions.ts +55 -0
- package/src/protocols/cloudflare-workers-ai-images.ts +124 -0
- package/src/protocols/cohere-chat.ts +353 -0
- package/src/protocols/deepgram-speech.ts +148 -0
- package/src/protocols/deepgram-transcription.ts +179 -0
- package/src/protocols/elevenlabs-speech.ts +207 -0
- package/src/protocols/elevenlabs-transcription.ts +211 -0
- package/src/protocols/gemini.ts +908 -0
- package/src/protocols/google-decisions.ts +179 -0
- package/src/protocols/google-embed-content.ts +165 -0
- package/src/protocols/google-images.ts +255 -0
- package/src/protocols/google-interactions-video.ts +264 -0
- package/src/protocols/google-interactions.ts +904 -0
- package/src/protocols/google-speech.ts +157 -0
- package/src/protocols/google-transcription.ts +206 -0
- package/src/protocols/google-vertex-predict-embeddings.ts +104 -0
- package/src/protocols/index.ts +21 -0
- package/src/protocols/meta-images.ts +162 -0
- package/src/protocols/meta-messages.ts +67 -0
- package/src/protocols/meta-responses.ts +249 -0
- package/src/protocols/minimax-images.ts +215 -0
- package/src/protocols/minimax-video.ts +406 -0
- package/src/protocols/mistral-chat.ts +768 -0
- package/src/protocols/open-responses-channel.ts +198 -0
- package/src/protocols/open-responses-continuation.ts +218 -0
- package/src/protocols/open-responses.ts +1636 -0
- package/src/protocols/openai-chat.ts +1431 -0
- package/src/protocols/openai-compatible-chat.ts +22 -0
- package/src/protocols/openai-compatible-responses.ts +21 -0
- package/src/protocols/openai-decisions.ts +174 -0
- package/src/protocols/openai-embeddings.ts +105 -0
- package/src/protocols/openai-freeform.ts +287 -0
- package/src/protocols/openai-images.ts +442 -0
- package/src/protocols/openai-responses.ts +442 -0
- package/src/protocols/openai-speech.ts +164 -0
- package/src/protocols/openai-transcription.ts +295 -0
- package/src/protocols/openrouter-video.ts +215 -0
- package/src/protocols/seedance-video.ts +301 -0
- package/src/protocols/shared.ts +552 -0
- package/src/protocols/system-one.ts +335 -0
- package/src/protocols/utils/bedrock-auth.ts +147 -0
- package/src/protocols/utils/bedrock-cache.ts +56 -0
- package/src/protocols/utils/bedrock-media.ts +121 -0
- package/src/protocols/utils/cache.ts +44 -0
- package/src/protocols/utils/claude-model.ts +19 -0
- package/src/protocols/utils/gateway-protocol.ts +92 -0
- package/src/protocols/utils/gemini-generate-content.ts +172 -0
- package/src/protocols/utils/gemini-json-schema.ts +77 -0
- package/src/protocols/utils/image-sizing.ts +117 -0
- package/src/protocols/utils/lifecycle.ts +120 -0
- package/src/protocols/utils/media-input.ts +98 -0
- package/src/protocols/utils/mistral-tool-id.ts +34 -0
- package/src/protocols/utils/open-responses-options.ts +82 -0
- package/src/protocols/utils/partial-json-options.ts +62 -0
- package/src/protocols/utils/partial-json.ts +283 -0
- package/src/protocols/utils/responses-checkpoint.ts +115 -0
- package/src/protocols/utils/responses-compaction.ts +210 -0
- package/src/protocols/utils/responses-hosted-tools.ts +104 -0
- package/src/protocols/utils/speaker-turns.ts +10 -0
- package/src/protocols/utils/speech-stream.ts +111 -0
- package/src/protocols/utils/tool-schema.ts +115 -0
- package/src/protocols/utils/tool-stream.ts +240 -0
- package/src/protocols/venice-chat.ts +356 -0
- package/src/protocols/xai-images.ts +137 -0
- package/src/protocols/xai-responses.ts +106 -0
- package/src/protocols/xai-video.ts +232 -0
- package/src/protocols/zai-chat.ts +71 -0
- package/src/protocols/zai-images.ts +120 -0
- package/src/protocols/zai-messages.ts +34 -0
- package/src/protocols.ts +1 -0
- package/src/provider-error.ts +291 -0
- package/src/provider-package.ts +32 -0
- package/src/providers/alibaba/chat.ts +1 -0
- package/src/providers/alibaba/embeddings.ts +2 -0
- package/src/providers/alibaba/images.ts +2 -0
- package/src/providers/alibaba/messages.ts +3 -0
- package/src/providers/alibaba/responses.ts +3 -0
- package/src/providers/alibaba.ts +177 -0
- package/src/providers/amazon-bedrock/mantle/chat.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/messages.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/responses.ts +2 -0
- package/src/providers/amazon-bedrock/mantle.ts +2 -0
- package/src/providers/amazon-bedrock-mantle.ts +192 -0
- package/src/providers/amazon-bedrock.ts +81 -0
- package/src/providers/anthropic-compatible.ts +80 -0
- package/src/providers/anthropic.ts +66 -0
- package/src/providers/assemblyai.ts +32 -0
- package/src/providers/azure/chat.ts +2 -0
- package/src/providers/azure/embeddings.ts +2 -0
- package/src/providers/azure/images.ts +2 -0
- package/src/providers/azure/messages.ts +2 -0
- package/src/providers/azure/responses.ts +2 -0
- package/src/providers/azure.ts +240 -0
- package/src/providers/baseten/decisions.ts +2 -0
- package/src/providers/baseten.ts +88 -0
- package/src/providers/byteplus/videos.ts +2 -0
- package/src/providers/byteplus.ts +39 -0
- package/src/providers/cartesia.ts +28 -0
- package/src/providers/cerebras.ts +56 -0
- package/src/providers/cloudflare-ai-gateway/decisions.ts +2 -0
- package/src/providers/cloudflare-ai-gateway.ts +199 -0
- package/src/providers/cloudflare-shared.ts +29 -0
- package/src/providers/cloudflare-workers-ai/decisions.ts +2 -0
- package/src/providers/cloudflare-workers-ai/images.ts +2 -0
- package/src/providers/cloudflare-workers-ai.ts +104 -0
- package/src/providers/cohere/chat.ts +8 -0
- package/src/providers/cohere/embeddings.ts +2 -0
- package/src/providers/cohere.ts +72 -0
- package/src/providers/deepgram.ts +33 -0
- package/src/providers/deepinfra/embeddings.ts +2 -0
- package/src/providers/deepinfra.ts +76 -0
- package/src/providers/deepseek.ts +54 -0
- package/src/providers/digitalocean/decisions.ts +2 -0
- package/src/providers/digitalocean/embeddings.ts +2 -0
- package/src/providers/digitalocean/images.ts +2 -0
- package/src/providers/digitalocean/responses.ts +4 -0
- package/src/providers/digitalocean.ts +144 -0
- package/src/providers/elevenlabs.ts +35 -0
- package/src/providers/fireworks/embeddings.ts +2 -0
- package/src/providers/fireworks.ts +66 -0
- package/src/providers/google/decisions.ts +2 -0
- package/src/providers/google/embeddings.ts +2 -0
- package/src/providers/google/images.ts +2 -0
- package/src/providers/google/interactions.ts +13 -0
- package/src/providers/google/videos.ts +2 -0
- package/src/providers/google-vertex/chat.ts +2 -0
- package/src/providers/google-vertex/embeddings.ts +2 -0
- package/src/providers/google-vertex/gemini.ts +2 -0
- package/src/providers/google-vertex/images.ts +2 -0
- package/src/providers/google-vertex/interactions.ts +2 -0
- package/src/providers/google-vertex/messages.ts +2 -0
- package/src/providers/google-vertex/mistral.ts +2 -0
- package/src/providers/google-vertex/responses.ts +2 -0
- package/src/providers/google-vertex-chat.ts +63 -0
- package/src/providers/google-vertex-interactions.ts +104 -0
- package/src/providers/google-vertex-messages.ts +99 -0
- package/src/providers/google-vertex-mistral.ts +79 -0
- package/src/providers/google-vertex-responses.ts +64 -0
- package/src/providers/google-vertex-shared.ts +176 -0
- package/src/providers/google-vertex.ts +228 -0
- package/src/providers/google.ts +121 -0
- package/src/providers/groq.ts +98 -0
- package/src/providers/index.ts +45 -0
- package/src/providers/meta/chat.ts +2 -0
- package/src/providers/meta/images.ts +2 -0
- package/src/providers/meta/messages.ts +2 -0
- package/src/providers/meta/responses.ts +2 -0
- package/src/providers/meta.ts +161 -0
- package/src/providers/minimax/chat.ts +8 -0
- package/src/providers/minimax/images.ts +4 -0
- package/src/providers/minimax/messages.ts +1 -0
- package/src/providers/minimax/responses.ts +8 -0
- package/src/providers/minimax/videos.ts +4 -0
- package/src/providers/minimax.ts +162 -0
- package/src/providers/mistral.ts +40 -0
- package/src/providers/moonshot/chat.ts +1 -0
- package/src/providers/moonshot/messages.ts +8 -0
- package/src/providers/moonshot/responses.ts +8 -0
- package/src/providers/moonshot.ts +134 -0
- package/src/providers/open-responses-options.ts +4 -0
- package/src/providers/openai/chat.ts +2 -0
- package/src/providers/openai/embeddings.ts +2 -0
- package/src/providers/openai/images.ts +2 -0
- package/src/providers/openai/responses.ts +2 -0
- package/src/providers/openai-compatible/decisions.ts +2 -0
- package/src/providers/openai-compatible/embeddings.ts +2 -0
- package/src/providers/openai-compatible/images.ts +2 -0
- package/src/providers/openai-compatible/responses.ts +1 -0
- package/src/providers/openai-compatible-responses.ts +52 -0
- package/src/providers/openai-compatible.ts +108 -0
- package/src/providers/openai-options.ts +66 -0
- package/src/providers/openai.ts +207 -0
- package/src/providers/opencode/decisions.ts +2 -0
- package/src/providers/opencode.ts +45 -0
- package/src/providers/openrouter/decisions.ts +2 -0
- package/src/providers/openrouter/embeddings.ts +2 -0
- package/src/providers/openrouter/images.ts +2 -0
- package/src/providers/openrouter/responses.ts +3 -0
- package/src/providers/openrouter/videos.ts +2 -0
- package/src/providers/openrouter.ts +347 -0
- package/src/providers/settings.ts +54 -0
- package/src/providers/togetherai.ts +53 -0
- package/src/providers/typesafe-ai/decisions.ts +2 -0
- package/src/providers/typesafe-ai.ts +45 -0
- package/src/providers/venice/responses.ts +4 -0
- package/src/providers/venice.ts +93 -0
- package/src/providers/vercel-ai-gateway/chat.ts +2 -0
- package/src/providers/vercel-ai-gateway/decisions.ts +2 -0
- package/src/providers/vercel-ai-gateway/embeddings.ts +2 -0
- package/src/providers/vercel-ai-gateway/images.ts +2 -0
- package/src/providers/vercel-ai-gateway/messages.ts +2 -0
- package/src/providers/vercel-ai-gateway/responses.ts +2 -0
- package/src/providers/vercel-ai-gateway.ts +300 -0
- package/src/providers/volcengine/videos.ts +2 -0
- package/src/providers/volcengine.ts +39 -0
- package/src/providers/xai/images.ts +2 -0
- package/src/providers/xai/videos.ts +2 -0
- package/src/providers/xai.ts +125 -0
- package/src/providers/zai/chat.ts +1 -0
- package/src/providers/zai/images.ts +2 -0
- package/src/providers/zai-coding-plan/chat.ts +1 -0
- package/src/providers/zai-coding-plan/messages.ts +8 -0
- package/src/providers/zai-coding-plan/responses.ts +8 -0
- package/src/providers/zai-coding-plan.ts +86 -0
- package/src/providers/zai.ts +73 -0
- package/src/providers.ts +1 -0
- package/src/public.ts +204 -0
- package/src/route/auth-options.ts +62 -0
- package/src/route/auth.ts +164 -0
- package/src/route/client.ts +700 -0
- package/src/route/decision.ts +150 -0
- package/src/route/embedding.ts +175 -0
- package/src/route/endpoint.ts +63 -0
- package/src/route/executor-service.ts +191 -0
- package/src/route/executor.ts +361 -0
- package/src/route/framing.ts +112 -0
- package/src/route/index.ts +47 -0
- package/src/route/media-protocol.ts +321 -0
- package/src/route/media.ts +507 -0
- package/src/route/protocol.ts +97 -0
- package/src/route/transport/http.ts +103 -0
- package/src/route/transport/index.ts +59 -0
- package/src/route/transport/websocket-channel.ts +51 -0
- package/src/route/transport/websocket.ts +443 -0
- package/src/route.ts +1 -0
- package/src/schema/errors.ts +246 -0
- package/src/schema/events.ts +744 -0
- package/src/schema/ids.ts +24 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/messages.ts +529 -0
- package/src/schema/options.ts +445 -0
- package/src/speech-client.ts +25 -0
- package/src/speech.ts +211 -0
- package/src/testing.ts +218 -0
- package/src/tool-history.ts +91 -0
- package/src/tool-runtime.ts +107 -0
- package/src/tool-updates.ts +139 -0
- package/src/tool.ts +281 -0
- package/src/transcription-client.ts +19 -0
- package/src/transcription.ts +234 -0
- package/src/utils/bytes.ts +9 -0
- package/src/utils/json.ts +5 -0
- package/src/utils/media-type.ts +93 -0
- package/src/utils/provider-codes.ts +43 -0
- package/src/utils/record.ts +3 -0
- package/src/utils/sanitize.ts +33 -0
- package/src/video-client.ts +66 -0
- package/src/video.ts +181 -0
- package/test/adapter.test.ts +180 -0
- package/test/auth-options.types.ts +283 -0
- package/test/auth.test.ts +112 -0
- package/test/cache-policy.test.ts +578 -0
- package/test/compaction-http.test.ts +96 -0
- package/test/compaction.test.ts +107 -0
- package/test/compile.test.ts +600 -0
- package/test/continuation-scenarios.ts +115 -0
- package/test/decision.test.ts +983 -0
- package/test/decision.types.ts +117 -0
- package/test/effort-updates.test.ts +574 -0
- package/test/embedding.test.ts +455 -0
- package/test/endpoint.test.ts +58 -0
- package/test/error-partial.test.ts +140 -0
- package/test/executor.test.ts +1095 -0
- package/test/exports.test.ts +222 -0
- package/test/extraction.test.ts +227 -0
- package/test/fixtures/audio/dialog.mp3 +0 -0
- package/test/fixtures/audio/hello.mp3 +0 -0
- package/test/fixtures/images/edit-source.jpg +0 -0
- package/test/fixtures/media/restroom.png +0 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-returns-a-json-object.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-images/edits-an-image.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-qwen-image-images.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-wan-images.json +33 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-follows-a-json-schema.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-continues-a-stored-response.json +53 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-code-interpreter.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-web-search-and-extraction.json +36 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-text.json +40 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-call.json +41 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-loop.json +60 -0
- package/test/fixtures/recordings/anthropic-messages/anthropic-opus-4-7-image-tool-result.json +43 -0
- package/test/fixtures/recordings/anthropic-messages-cache/keeps-a-long-tool-turn-inside-the-cache-lookback.json +48 -0
- package/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/assemblyai-transcription/uploads-submits-and-polls-a-transcript.json +98 -0
- package/test/fixtures/recordings/azure/chat-streams-text-from-a-foundry-models-url.json +31 -0
- package/test/fixtures/recordings/azure/chat-streams-text.json +28 -0
- package/test/fixtures/recordings/azure/messages-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/messages-streams-text.json +31 -0
- package/test/fixtures/recordings/azure/responses-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/responses-continues-after-a-tool-result.json +31 -0
- package/test/fixtures/recordings/azure/responses-streams-text.json +31 -0
- package/test/fixtures/recordings/baseten-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/bedrock-converse/continues-after-parallel-tool-results.json +36 -0
- package/test/fixtures/recordings/bedrock-converse/drives-a-tool-loop.json +55 -0
- package/test/fixtures/recordings/bedrock-converse/streams-a-tool-call.json +29 -0
- package/test/fixtures/recordings/bedrock-converse/streams-text.json +29 -0
- package/test/fixtures/recordings/bedrock-converse-cache/writes-then-reads-cachepoint-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/bedrock-converse-options/constrains-claude-output-to-a-json-schema.json +33 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-claude-effort-with-adaptive-thinking-service-tier-and-request-metadata.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-gpt-oss-reasoning-effort-with-the-priority-tier.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-nova-2-reasoning-effort.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/accepts-the-default-binding-with-no-thinking-configured.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/keeps-a-session-working-after-the-system-prompt-changes.json +71 -0
- package/test/fixtures/recordings/bedrock-mantle/streams-text.json +33 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/applies-mid-conversation-effort-updates-and-thinking-block-binding-on-opus-5-5.json +57 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/lowers-system-updates-to-wrapped-user-text-on-haiku-4-5-with-budget-thinking.json +37 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/replays-signed-thinking-through-a-tool-loop-and-native-system-update.json +59 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/strips-unsupported-mid-conversation-effort-updates-on-opus-5-0.json +37 -0
- package/test/fixtures/recordings/cartesia-speech/generates-speech.json +34 -0
- package/test/fixtures/recordings/cartesia-speech/streams-speech-with-timestamps.json +33 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-text.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-call.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-loop.json +50 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-text.json +38 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-tool-loop.json +58 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-text.json +37 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-tool-loop.json +56 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-extraction/extracts-invoice-fields.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-flux-2-image-from-multipart-fields.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-raw-binary-image.json +33 -0
- package/test/fixtures/recordings/cohere/continues-a-native-tool-call.json +49 -0
- package/test/fixtures/recordings/cohere/streams-compatible-chat-reasoning.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-text-and-usage.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-thinking-with-a-budget.json +31 -0
- package/test/fixtures/recordings/cohere-embedding/embeds-text-through-the-compatibility-api.json +33 -0
- package/test/fixtures/recordings/deepgram-speech/generates-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-speech/streams-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-transcription/splits-utterances-at-speaker-changes.json +32 -0
- package/test/fixtures/recordings/deepgram-transcription/transcribes-raw-audio-with-speakers-and-word-timestamps.json +50 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-text.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-call.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-loop.json +50 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/digitalocean-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/digitalocean-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/digitalocean-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/generates-speech.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/streams-speech-with-timestamps.json +34 -0
- package/test/fixtures/recordings/elevenlabs-transcription/groups-diarized-words-into-speaker-turns.json +32 -0
- package/test/fixtures/recordings/elevenlabs-transcription/transcribes-audio-with-word-timestamps.json +50 -0
- package/test/fixtures/recordings/gemini/gemini-2-5-flash-image.json +32 -0
- package/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json +46 -0
- package/test/fixtures/recordings/google-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/google-embedding/embeds-an-image-and-text-into-one-vector-each.json +32 -0
- package/test/fixtures/recordings/google-embedding/embeds-text-through-batchembedcontents.json +32 -0
- package/test/fixtures/recordings/google-embedding/maps-inputtype-to-a-task-type-for-gemini-embedding-001.json +50 -0
- package/test/fixtures/recordings/google-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/google-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/google-interactions/continues-tool-results-with-previous-interaction-id.json +66 -0
- package/test/fixtures/recordings/google-interactions/replays-native-tool-results-and-signatures-statelessly.json +50 -0
- package/test/fixtures/recordings/google-interactions/streams-reasoning-and-retains-thought-signatures.json +32 -0
- package/test/fixtures/recordings/google-interactions/streams-text-and-reports-usage.json +32 -0
- package/test/fixtures/recordings/google-interactions-video/generates-a-video.json +96 -0
- package/test/fixtures/recordings/google-speech/generates-speech.json +32 -0
- package/test/fixtures/recordings/google-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/google-transcription/streams-speaker-turns.json +32 -0
- package/test/fixtures/recordings/google-transcription/transcribes-with-speakers-and-word-timestamps.json +32 -0
- package/test/fixtures/recordings/google-vertex/calls-a-tool.json +32 -0
- package/test/fixtures/recordings/google-vertex/continues-after-a-tool-result.json +32 -0
- package/test/fixtures/recordings/google-vertex/streams-text.json +32 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-gemini-embedding-001-one-text-per-predict-request.json +50 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-text-through-predict.json +32 -0
- package/test/fixtures/recordings/groq-chat/continues-qwen-parallel-tool-calls.json +47 -0
- package/test/fixtures/recordings/groq-chat/replays-gpt-oss-reasoning-through-a-tool-loop.json +47 -0
- package/test/fixtures/recordings/groq-chat/streams-qwen-parsed-reasoning.json +29 -0
- package/test/fixtures/recordings/groq-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/meta-chat/continues-a-generated-tool-call.json +56 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-high-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-low-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-max-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-xhigh-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-images/edits-image-bytes-and-returns-png.json +29 -0
- package/test/fixtures/recordings/meta-images/generates-default-webp-bytes.json +29 -0
- package/test/fixtures/recordings/meta-images/replays-a-signed-image-handle-for-a-responses-edit.json +55 -0
- package/test/fixtures/recordings/meta-messages/replays-encrypted-thinking-through-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-enabled-thinking.json +36 -0
- package/test/fixtures/recordings/meta-responses/replays-encrypted-reasoning-through-a-tool-loop.json +56 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-high-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-low-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-max-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-xhigh-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-messages.json +56 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-responses.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-continues-a-tool-loop-with-default-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/minimax-images/generates-from-a-subject-reference.json +32 -0
- package/test/fixtures/recordings/minimax-messages/m2-7-streams-default-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-continues-a-tool-loop-with-adaptive-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-messages/m3-generates-a-named-tool-call-with-default-thinking-off.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-responses/m3-continues-a-tool-loop-with-effort-minimal.json +56 -0
- package/test/fixtures/recordings/minimax-responses/m3-streams-text-with-effort-none.json +36 -0
- package/test/fixtures/recordings/minimax-video/generates-a-hailuo-video-from-a-first-frame.json +176 -0
- package/test/fixtures/recordings/minimax-video/generates-an-h3-video.json +96 -0
- package/test/fixtures/recordings/mistral-chat/drives-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/mistral-chat/replays-native-reasoning.json +47 -0
- package/test/fixtures/recordings/mistral-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/mistral-chat-glm/streams-an-indexed-tool-call.json +36 -0
- package/test/fixtures/recordings/moonshot-chat/k3-reads-image-bytes.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-none.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-required.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-returns-native-structured-output.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-default-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-high-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-low-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-max-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-disabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-enabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-messages/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-responses/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/openai-compatible-chat/gemini-parallel-tool-signatures.json +54 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-text.json +28 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-tool-call.json +28 -0
- package/test/fixtures/recordings/openai-decision/decides-choice-score-and-predicate-questions-about-json-state.json +33 -0
- package/test/fixtures/recordings/openai-embedding/embeds-text-with-requested-dimensions.json +33 -0
- package/test/fixtures/recordings/openai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/streams-a-partial-image-before-the-final-image.json +32 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-image-tool-result.json +42 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning-continuation.json +58 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning.json +38 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-tool-loop.json +57 -0
- package/test/fixtures/recordings/openai-responses-cache/caches-the-system-prompt-on-gpt-6-2-sol.json +51 -0
- package/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json +51 -0
- package/test/fixtures/recordings/openai-responses-images/generates-and-edits-an-image-with-the-hosted-tool.json +50 -0
- package/test/fixtures/recordings/openai-responses-websocket/continues-a-tool-call-over-one-socket.json +588 -0
- package/test/fixtures/recordings/openai-responses-websocket/reconstructs-full-context-after-reconnect.json +167 -0
- package/test/fixtures/recordings/openai-responses-websocket/recovers-from-explicit-continuation-rejection.json +167 -0
- package/test/fixtures/recordings/openai-speech/generates-speech.json +33 -0
- package/test/fixtures/recordings/openai-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/openai-transcription/diarizes-speakers-into-segments.json +32 -0
- package/test/fixtures/recordings/openai-transcription/returns-whisper-word-timestamps.json +32 -0
- package/test/fixtures/recordings/openai-transcription/streams-text-deltas.json +32 -0
- package/test/fixtures/recordings/openai-transcription/transcribes-with-a-language-hint.json +32 -0
- package/test/fixtures/recordings/opencode-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-images/edits-an-image-through-input-references.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-flux-3-from-an-aspect-ratio-and-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-gemini-at-the-requested-2k-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/openrouter-reasoning.json +29 -0
- package/test/fixtures/recordings/openrouter-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/openrouter-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/openrouter-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/openrouter-video/generates-a-video.json +113 -0
- package/test/fixtures/recordings/pdf/anthropic-tool-result.json +28 -0
- package/test/fixtures/recordings/pdf/anthropic-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/bedrock-tool-result.json +29 -0
- package/test/fixtures/recordings/pdf/bedrock-user-input.json +29 -0
- package/test/fixtures/recordings/pdf/gemini-tool-result.json +53 -0
- package/test/fixtures/recordings/pdf/gemini-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/openai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/openai-user-input.json +34 -0
- package/test/fixtures/recordings/pdf/xai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/xai-user-input.json +34 -0
- package/test/fixtures/recordings/typesafe-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/venice-chat/claude-opus-4-8-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/deepseek-v4-flash-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-3-1-pro-preview-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-preserves-per-call-signatures-through-parallel-tools.json +71 -0
- package/test/fixtures/recordings/venice-chat/openai-gpt-54-mini-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/qwen-disables-reasoning.json +35 -0
- package/test/fixtures/recordings/venice-chat/surfaces-venice-model-errors.json +33 -0
- package/test/fixtures/recordings/venice-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/venice-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/venice-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/sizes-grok-through-xai-provider-options.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning.json +29 -0
- package/test/fixtures/recordings/vercel-native/automatically-caches-distinct-claude-system-blocks.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-muse-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-deepseek-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-gemini-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-gpt-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-grok-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/rejects-invalid-credentials-without-retryable-classification.json +31 -0
- package/test/fixtures/recordings/xai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/xai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/xai-video/generates-a-video.json +129 -0
- package/test/fixtures/recordings/zai-chat/glm-4-5-calls-a-tool-without-streaming-arguments.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-medium-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-minimal-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-none-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-xhigh-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-flash-reads-image-bytes.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +64 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-rejects-disabled-thinking.json +27 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-returns-a-json-object.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-default-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-images/generates-an-image.json +28 -0
- package/test/generate-object.test.ts +281 -0
- package/test/generation.test.ts +191 -0
- package/test/google-interactions-video.test.ts +351 -0
- package/test/http-hooks.test.ts +137 -0
- package/test/http-timeout.test.ts +287 -0
- package/test/image-job.test.ts +199 -0
- package/test/image-sizing.test.ts +47 -0
- package/test/image.test.ts +1114 -0
- package/test/image.types.ts +203 -0
- package/test/keyless-auth.test.ts +85 -0
- package/test/lib/effect.ts +50 -0
- package/test/lib/env.ts +30 -0
- package/test/lib/http.ts +141 -0
- package/test/lib/image.ts +29 -0
- package/test/lib/openai-chunks.ts +27 -0
- package/test/lib/sse.ts +20 -0
- package/test/lib/tool-runtime.ts +152 -0
- package/test/llm-option-types.types.ts +153 -0
- package/test/llm.test.ts +286 -0
- package/test/loop-steps.test.ts +77 -0
- package/test/loop-tools.types.ts +79 -0
- package/test/loop.test.ts +425 -0
- package/test/media-input.test.ts +98 -0
- package/test/media-usage.test.ts +13 -0
- package/test/media.test.ts +340 -0
- package/test/minimax-video.test.ts +553 -0
- package/test/openai-freeform.test.ts +252 -0
- package/test/openrouter-video.test.ts +294 -0
- package/test/partial-json.test.ts +58 -0
- package/test/promise-parity.types.ts +83 -0
- package/test/promise.test.ts +632 -0
- package/test/provider/alibaba-capabilities.recorded.test.ts +253 -0
- package/test/provider/alibaba-images.recorded.test.ts +71 -0
- package/test/provider/alibaba-images.test.ts +199 -0
- package/test/provider/alibaba.recorded.test.ts +165 -0
- package/test/provider/alibaba.test.ts +419 -0
- package/test/provider/anthropic-compaction.test.ts +171 -0
- package/test/provider/anthropic-messages-cache.recorded.test.ts +111 -0
- package/test/provider/anthropic-messages.recorded.test.ts +45 -0
- package/test/provider/anthropic-messages.test.ts +2609 -0
- package/test/provider/anthropic-thinking-binding.test.ts +65 -0
- package/test/provider/assemblyai-transcription.recorded.test.ts +39 -0
- package/test/provider/azure.recorded.test.ts +139 -0
- package/test/provider/azure.test.ts +48 -0
- package/test/provider/bedrock-converse-cache.recorded.test.ts +61 -0
- package/test/provider/bedrock-converse-cache.test.ts +168 -0
- package/test/provider/bedrock-converse-options.recorded.test.ts +119 -0
- package/test/provider/bedrock-converse-options.test.ts +149 -0
- package/test/provider/bedrock-converse-thinking-binding.recorded.test.ts +103 -0
- package/test/provider/bedrock-converse-thinking-binding.test.ts +107 -0
- package/test/provider/bedrock-converse.test.ts +2548 -0
- package/test/provider/bedrock-mantle.test.ts +444 -0
- package/test/provider/bedrock-mistral-ids.test.ts +86 -0
- package/test/provider/cartesia-speech.recorded.test.ts +47 -0
- package/test/provider/checkpoint.test.ts +324 -0
- package/test/provider/cloudflare-workers-ai-images.recorded.test.ts +57 -0
- package/test/provider/cloudflare-workers-ai-images.test.ts +155 -0
- package/test/provider/cloudflare.test.ts +330 -0
- package/test/provider/cohere.recorded.test.ts +94 -0
- package/test/provider/cohere.test.ts +301 -0
- package/test/provider/compaction-websocket.test.ts +50 -0
- package/test/provider/compaction.recorded.test.ts +89 -0
- package/test/provider/compaction.test.ts +178 -0
- package/test/provider/conversation-lowering.test.ts +31 -0
- package/test/provider/decision.recorded.test.ts +211 -0
- package/test/provider/deepgram-speech.recorded.test.ts +41 -0
- package/test/provider/deepgram-transcription.recorded.test.ts +47 -0
- package/test/provider/digitalocean.recorded.test.ts +78 -0
- package/test/provider/digitalocean.test.ts +123 -0
- package/test/provider/elevenlabs-speech.recorded.test.ts +54 -0
- package/test/provider/elevenlabs-transcription.recorded.test.ts +50 -0
- package/test/provider/embedding.recorded.test.ts +109 -0
- package/test/provider/empty-tool-choice.test.ts +80 -0
- package/test/provider/error-retention.test.ts +158 -0
- package/test/provider/explicit-compaction.test.ts +503 -0
- package/test/provider/extraction.recorded.test.ts +46 -0
- package/test/provider/freeform-tools.test.ts +446 -0
- package/test/provider/gemini-cache.recorded.test.ts +49 -0
- package/test/provider/gemini-openai-chat.recorded.test.ts +69 -0
- package/test/provider/gemini.test.ts +2336 -0
- package/test/provider/golden.recorded.test.ts +287 -0
- package/test/provider/google-images.recorded.test.ts +53 -0
- package/test/provider/google-interactions-video.recorded.test.ts +48 -0
- package/test/provider/google-interactions.recorded.test.ts +169 -0
- package/test/provider/google-interactions.test.ts +593 -0
- package/test/provider/google-speech.recorded.test.ts +45 -0
- package/test/provider/google-transcription.recorded.test.ts +54 -0
- package/test/provider/google-vertex-interactions.test.ts +307 -0
- package/test/provider/google-vertex.recorded.test.ts +75 -0
- package/test/provider/google-vertex.test.ts +595 -0
- package/test/provider/groq.recorded.test.ts +187 -0
- package/test/provider/groq.test.ts +134 -0
- package/test/provider/image-detail.test.ts +58 -0
- package/test/provider/media-entrypoints.test.ts +618 -0
- package/test/provider/meta-capabilities.test.ts +216 -0
- package/test/provider/meta-images.recorded.test.ts +119 -0
- package/test/provider/meta-messages.recorded.test.ts +121 -0
- package/test/provider/meta-search.recorded.test.ts +97 -0
- package/test/provider/meta.recorded.test.ts +182 -0
- package/test/provider/meta.test.ts +140 -0
- package/test/provider/minimax-images.recorded.test.ts +52 -0
- package/test/provider/minimax-images.test.ts +236 -0
- package/test/provider/minimax-video.recorded.test.ts +83 -0
- package/test/provider/minimax.recorded.test.ts +257 -0
- package/test/provider/minimax.test.ts +110 -0
- package/test/provider/missing-tool-input.test.ts +73 -0
- package/test/provider/mistral-chat.test.ts +757 -0
- package/test/provider/mistral.recorded.test.ts +170 -0
- package/test/provider/moonshot-capabilities.recorded.test.ts +131 -0
- package/test/provider/moonshot.recorded.test.ts +191 -0
- package/test/provider/moonshot.test.ts +218 -0
- package/test/provider/native-providers.test.ts +299 -0
- package/test/provider/open-responses-errors.test.ts +141 -0
- package/test/provider/open-responses-finals.test.ts +209 -0
- package/test/provider/open-responses-lifecycle.test.ts +526 -0
- package/test/provider/open-responses-replay.test.ts +120 -0
- package/test/provider/openai-chat-reasoning.recorded.test.ts +154 -0
- package/test/provider/openai-chat.test.ts +2505 -0
- package/test/provider/openai-compatible-chat.test.ts +819 -0
- package/test/provider/openai-compatible-responses.test.ts +1139 -0
- package/test/provider/openai-images.recorded.test.ts +91 -0
- package/test/provider/openai-responses-cache.recorded.test.ts +68 -0
- package/test/provider/openai-responses-images.recorded.test.ts +66 -0
- package/test/provider/openai-responses-websocket.recorded.test.ts +221 -0
- package/test/provider/openai-responses.test.ts +5414 -0
- package/test/provider/openai-speech.recorded.test.ts +38 -0
- package/test/provider/openai-transcription.recorded.test.ts +91 -0
- package/test/provider/openrouter-images.recorded.test.ts +76 -0
- package/test/provider/openrouter-video.recorded.test.ts +53 -0
- package/test/provider/openrouter.test.ts +656 -0
- package/test/provider/pdf.recorded.test.ts +211 -0
- package/test/provider/queued-recording.ts +10 -0
- package/test/provider/responses-routes.recorded.test.ts +91 -0
- package/test/provider/seedance-video.recorded.test.ts +52 -0
- package/test/provider/speech-recording.ts +19 -0
- package/test/provider/transcription-recording.ts +41 -0
- package/test/provider/venice.recorded.test.ts +237 -0
- package/test/provider/venice.test.ts +373 -0
- package/test/provider/vercel-ai-gateway-images.recorded.test.ts +55 -0
- package/test/provider/vercel-ai-gateway.recorded.test.ts +125 -0
- package/test/provider/vercel-ai-gateway.test.ts +303 -0
- package/test/provider/xai-images.recorded.test.ts +54 -0
- package/test/provider/xai-images.test.ts +109 -0
- package/test/provider/xai-responses.test.ts +339 -0
- package/test/provider/xai-video.recorded.test.ts +54 -0
- package/test/provider/zai-capabilities.recorded.test.ts +156 -0
- package/test/provider/zai-images.recorded.test.ts +33 -0
- package/test/provider/zai-images.test.ts +163 -0
- package/test/provider/zai.recorded.test.ts +115 -0
- package/test/provider/zai.test.ts +374 -0
- package/test/provider-api-methods.types.ts +8 -0
- package/test/provider-error.test.ts +800 -0
- package/test/provider-model.types.ts +37 -0
- package/test/provider-options/alibaba.types.ts +46 -0
- package/test/provider-options/amazon-bedrock.types.ts +33 -0
- package/test/provider-options/anthropic-compatible.types.ts +13 -0
- package/test/provider-options/anthropic.types.ts +30 -0
- package/test/provider-options/azure.types.ts +13 -0
- package/test/provider-options/checkpoint.types.ts +150 -0
- package/test/provider-options/cloudflare.types.ts +13 -0
- package/test/provider-options/compaction.types.ts +146 -0
- package/test/provider-options/google-vertex-chat.types.ts +7 -0
- package/test/provider-options/google-vertex-interactions.types.ts +29 -0
- package/test/provider-options/google-vertex-messages.types.ts +13 -0
- package/test/provider-options/google-vertex-responses.types.ts +14 -0
- package/test/provider-options/google-vertex.types.ts +17 -0
- package/test/provider-options/google.types.ts +43 -0
- package/test/provider-options/minimax.types.ts +33 -0
- package/test/provider-options/mistral.types.ts +24 -0
- package/test/provider-options/moonshot.types.ts +45 -0
- package/test/provider-options/openai-compatible-responses.types.ts +17 -0
- package/test/provider-options/openai-compatible.types.ts +13 -0
- package/test/provider-options/openai.types.ts +27 -0
- package/test/provider-options/openrouter.types.ts +55 -0
- package/test/provider-options/venice.types.ts +39 -0
- package/test/provider-options/vercel-ai-gateway.types.ts +30 -0
- package/test/provider-options/xai.types.ts +14 -0
- package/test/provider-options/zai.types.ts +42 -0
- package/test/provider-package.test.ts +586 -0
- package/test/raw-events.test.ts +75 -0
- package/test/realtime.test.ts +172 -0
- package/test/recorded-golden.ts +104 -0
- package/test/recorded-runner.ts +101 -0
- package/test/recorded-scenarios.ts +468 -0
- package/test/recorded-test.ts +127 -0
- package/test/recorded-utils.ts +56 -0
- package/test/request-encoding.test.ts +57 -0
- package/test/request-transport.test.ts +74 -0
- package/test/response.test.ts +203 -0
- package/test/route.test.ts +225 -0
- package/test/sanitize.test.ts +80 -0
- package/test/schema.test.ts +412 -0
- package/test/seedance-video.test.ts +418 -0
- package/test/speech.test.ts +297 -0
- package/test/speech.types.ts +33 -0
- package/test/testing.test.ts +372 -0
- package/test/tool-history.test.ts +162 -0
- package/test/tool-runtime.test.ts +926 -0
- package/test/tool-schema-projection.test.ts +427 -0
- package/test/tool-stream.test.ts +252 -0
- package/test/tool-updates.test.ts +849 -0
- package/test/tool.types.ts +131 -0
- package/test/transcription.test.ts +618 -0
- package/test/transcription.types.ts +44 -0
- package/test/video.test.ts +447 -0
- package/test/video.types.ts +110 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +16 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# AI Package Guide
|
|
2
|
+
|
|
3
|
+
## Principles
|
|
4
|
+
|
|
5
|
+
- **Forward compatibility.** Providers ship new models, options, and values constantly. Accept unknown pass-through values (`Known | (string & {})` for string options); use closed literals only when OpenCode branches on the value.
|
|
6
|
+
- **Tolerate unknowns.** Unknown provider events, statuses, and enum values must not fail a request; ignore them or pass them through. Fail only on errors in the provider's documented shape, malformed known types, or a missing terminal event.
|
|
7
|
+
- **One canonical model.** The Schema classes in `src/schema/` are the data model. Do not add a parallel shape or a second construction path.
|
|
8
|
+
- **Independent of Session.** Auth, permissions, plugins, and orchestration belong in Core. `ai.stream`/`ai.generate` run exactly one model call.
|
|
9
|
+
- **Reuse protocols.** Providers compose existing protocols with `Route.make(...)` instead of cloning them.
|
|
10
|
+
- **One API, two runtimes.** `ai` from `@zyro-sec/ai` and `ai` from `@zyro-sec/ai/effect` have the same namespaces and operations, with the same names, overloads, input and options (plus `RunOptions`, `signal` and `http`, on the Promise side); keep `test/promise-parity.types.ts` passing.
|
|
11
|
+
- **One way to hook HTTP.** Every request goes through `RequestExecutor`, which applies executor-wide middleware (`RequestExecutor.middleware`) and the caller's scoped middleware (`RequestExecutor.withMiddleware`, Promise `{ http }`). Don't add a per-method hook option or send HTTP any other way. A `url` asset downloads with its own `middleware`, which a route sets only for URLs on the provider's origin. Types already require every route to send through the executor it is given, and lint rejects `fetch` and the `HttpClient` import outside `route/executor.ts`. Keep `test/http-hooks.test.ts` passing; it lists every Promise method.
|
|
12
|
+
|
|
13
|
+
## Code style
|
|
14
|
+
|
|
15
|
+
- Use `HttpClient`, `Stream`, and Schema codecs instead of `fetch`, async generators, and `JSON.parse`/`JSON.stringify`.
|
|
16
|
+
- `return yield* new MyError(...)` instead of `Effect.fail(...)`; `Effect.void` instead of `Effect.succeed(undefined)`.
|
|
17
|
+
- Only `src/index.ts` (the Promise entry) may use Promises.
|
|
18
|
+
|
|
19
|
+
## Tests
|
|
20
|
+
|
|
21
|
+
- Use `testEffect(...)` from `test/lib/effect.ts` for tests that need Effect layers.
|
|
22
|
+
- Provider tests replay cassettes: recorded HTTP exchanges stored as JSON in `test/fixtures/recordings/`, one file per scenario. Replay is the default and needs no API keys.
|
|
23
|
+
- To record, unset `CI` and run with `RECORD=true` plus the provider's API key. Re-record only the cassette you are changing; recordings contain volatile IDs that create noisy diffs.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { Config, Effect, Formatter, Schema, Stream } from "effect"
|
|
2
|
+
import { HttpClientResponse } from "effect/http"
|
|
3
|
+
import { NodeFileSystem } from "@effect/platform-node"
|
|
4
|
+
import { ai, AIClient, Media, Message, ProviderID, ToolRuntime } from "@zyro-sec/ai/effect"
|
|
5
|
+
import { tool } from "@zyro-sec/ai/effect"
|
|
6
|
+
import { Route, Auth, Endpoint, Framing, Protocol, RequestExecutor } from "@zyro-sec/ai/route"
|
|
7
|
+
import { OpenAI } from "@zyro-sec/ai/providers"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A runnable walkthrough of the LLM package use-site API.
|
|
11
|
+
*
|
|
12
|
+
* Run from `packages/ai` with an OpenAI key in the environment:
|
|
13
|
+
*
|
|
14
|
+
* OPENAI_API_KEY=... bun example/tutorial.ts [example]
|
|
15
|
+
*
|
|
16
|
+
* where `example` is one of the keys of `examples` at the bottom (default
|
|
17
|
+
* `tools`). The `fake` example runs offline and needs no key.
|
|
18
|
+
*
|
|
19
|
+
* The file is intentionally written as a normal TypeScript program. You can
|
|
20
|
+
* hover imports and local values to see how the public API is typed.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const apiKey = Config.Redacted("OPENAI_API_KEY")
|
|
24
|
+
|
|
25
|
+
// 1. Configure a provider. The configured facade records provider identity,
|
|
26
|
+
// deployment options, authentication, and defaults. Per-modality selectors pick
|
|
27
|
+
// the API: `.responses(...)` / `.chat(...)` for LLM calls and `.image(...)` for
|
|
28
|
+
// image generation.
|
|
29
|
+
const openai = OpenAI.configure({
|
|
30
|
+
apiKey,
|
|
31
|
+
maxTokens: 160,
|
|
32
|
+
providerOptions: {
|
|
33
|
+
store: false,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
const model = openai.responses("gpt-4o-mini")
|
|
37
|
+
|
|
38
|
+
// 2. Build a provider-neutral request. This is useful when reusing one request
|
|
39
|
+
// across generate and stream examples.
|
|
40
|
+
//
|
|
41
|
+
// Options can live on both the configured route/provider facade and the request:
|
|
42
|
+
//
|
|
43
|
+
// - `maxTokens`, `temperature`, `topP`, `topK`, penalties, `seed` and `stop`:
|
|
44
|
+
// common controls set at the top level.
|
|
45
|
+
// - `promptCacheKey`: stable cache affinity for protocols that support it.
|
|
46
|
+
// - `providerOptions`: model-typed provider-native behavior. For example,
|
|
47
|
+
// OpenAI store behavior, Anthropic thinking, Gemini thinking config, or
|
|
48
|
+
// OpenRouter routing/reasoning.
|
|
49
|
+
// - `http`: last-resort serializable overlays for final request body, headers,
|
|
50
|
+
// and query params. Prefer typed `providerOptions` when a field is stable.
|
|
51
|
+
//
|
|
52
|
+
// Route/provider options are defaults. Request options override them for this call.
|
|
53
|
+
const request = ai.request({
|
|
54
|
+
model,
|
|
55
|
+
system: "You are concise and practical.",
|
|
56
|
+
prompt: "Tell me a joke",
|
|
57
|
+
maxTokens: 80,
|
|
58
|
+
temperature: 0.7,
|
|
59
|
+
promptCacheKey: "tutorial-joke",
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// 3. `generate` sends the request and collects the event stream into one
|
|
63
|
+
// response object. `response.text` is the collected text output.
|
|
64
|
+
const generateOnce = Effect.gen(function* () {
|
|
65
|
+
const response = yield* ai.generate(request)
|
|
66
|
+
|
|
67
|
+
console.log("\n== generate ==")
|
|
68
|
+
console.log("generated text:", response.text)
|
|
69
|
+
console.log("usage", Formatter.formatJson(response.usage, { space: 2 }))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// 4. `stream` exposes provider output as common `LLMEvent`s for UIs that want
|
|
73
|
+
// incremental text, reasoning, tool input, usage, or finish events.
|
|
74
|
+
const streamText = ai.stream(request).pipe(
|
|
75
|
+
Stream.tap((event) =>
|
|
76
|
+
Effect.sync(() => {
|
|
77
|
+
if (event.type === "text-delta") process.stdout.write(`\ntext: ${event.text}`)
|
|
78
|
+
if (event.type === "finish")
|
|
79
|
+
process.stdout.write(
|
|
80
|
+
`\nfinish: ${event.reason.normalized}${event.reason.raw ? ` (${event.reason.raw})` : ""}\n`,
|
|
81
|
+
)
|
|
82
|
+
}),
|
|
83
|
+
),
|
|
84
|
+
Stream.runDrain,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
// 5. Tools are typed with Effect Schema. Provider turns remain explicit:
|
|
88
|
+
// advertise definitions on the request, stream one turn, dispatch local calls,
|
|
89
|
+
// then persist/build follow-up history in the enclosing product flow.
|
|
90
|
+
const tools = [
|
|
91
|
+
tool({
|
|
92
|
+
name: "get_weather",
|
|
93
|
+
description: "Get current weather for a city.",
|
|
94
|
+
input: Schema.Struct({ city: Schema.String }),
|
|
95
|
+
success: Schema.Struct({ forecast: Schema.String }),
|
|
96
|
+
execute: (input) => Effect.succeed({ forecast: `${input.city}: sunny, 72F` }),
|
|
97
|
+
}),
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
const streamWithTools = Effect.gen(function* () {
|
|
101
|
+
const request = ai.request({
|
|
102
|
+
model,
|
|
103
|
+
prompt: "Use get_weather for San Francisco, then answer in one sentence.",
|
|
104
|
+
maxTokens: 80,
|
|
105
|
+
temperature: 0,
|
|
106
|
+
tools,
|
|
107
|
+
})
|
|
108
|
+
const events = Array.from(yield* ai.stream(request).pipe(Stream.runCollect))
|
|
109
|
+
for (const event of events) {
|
|
110
|
+
if (event.type === "tool-call") console.log("tool call", event.name, event.input)
|
|
111
|
+
if (event.type === "text-delta") process.stdout.write(event.text)
|
|
112
|
+
if (event.type !== "tool-call" || event.providerExecuted) continue
|
|
113
|
+
const dispatched = yield* ToolRuntime.dispatch(tools, event)
|
|
114
|
+
console.log("tool result", event.name, dispatched.result)
|
|
115
|
+
|
|
116
|
+
// A durable agent would persist these messages before starting another
|
|
117
|
+
// raw model turn. This tutorial keeps the boundary visible instead.
|
|
118
|
+
const followUp = {
|
|
119
|
+
...request,
|
|
120
|
+
messages: [
|
|
121
|
+
...request.messages,
|
|
122
|
+
Message.assistant([event]),
|
|
123
|
+
Message.tool({ ...event, result: dispatched.result }),
|
|
124
|
+
],
|
|
125
|
+
}
|
|
126
|
+
console.log("follow-up history messages:", followUp.messages.length)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// 6. `schema` asks for structured output. It forces a hidden tool call, so the
|
|
131
|
+
// same call site works across providers, and decodes its input into `object`.
|
|
132
|
+
const WeatherReport = Schema.Struct({
|
|
133
|
+
city: Schema.String,
|
|
134
|
+
forecast: Schema.String,
|
|
135
|
+
highFahrenheit: Schema.Number,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const generateStructuredObject = Effect.gen(function* () {
|
|
139
|
+
const response = yield* ai.generate({
|
|
140
|
+
model,
|
|
141
|
+
system: "Return only structured weather data.",
|
|
142
|
+
prompt: "Give me today's weather for San Francisco.",
|
|
143
|
+
schema: WeatherReport,
|
|
144
|
+
maxTokens: 120,
|
|
145
|
+
temperature: 0,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
console.log("\n== structured output ==")
|
|
149
|
+
console.log(Formatter.formatJson(response.object, { space: 2 }))
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
// If the shape is only known at runtime, pass raw JSON Schema instead. The
|
|
153
|
+
// `.object` type is `unknown`; callers that need static types should validate it.
|
|
154
|
+
const generateDynamicObject = ai.generate({
|
|
155
|
+
model,
|
|
156
|
+
prompt: "Extract the city and forecast from: San Francisco is sunny.",
|
|
157
|
+
schema: {
|
|
158
|
+
type: "object",
|
|
159
|
+
properties: {
|
|
160
|
+
city: { type: "string" },
|
|
161
|
+
forecast: { type: "string" },
|
|
162
|
+
},
|
|
163
|
+
required: ["city", "forecast"],
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
// -----------------------------------------------------------------------------
|
|
168
|
+
// Part 2: provider composition with a fake provider
|
|
169
|
+
// -----------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
// A protocol is the provider-native API shape: common request -> body, response
|
|
172
|
+
// frames -> common events. This fake one turns text prompts into a JSON body
|
|
173
|
+
// and treats every SSE frame as output text.
|
|
174
|
+
const FakeBody = Schema.Struct({
|
|
175
|
+
model: Schema.String,
|
|
176
|
+
input: Schema.String,
|
|
177
|
+
})
|
|
178
|
+
type FakeBody = Schema.Schema.Type<typeof FakeBody>
|
|
179
|
+
|
|
180
|
+
const FakeProtocol = Protocol.make<FakeBody, string, string, void>({
|
|
181
|
+
// Protocol ids are open strings, so external packages can define their own
|
|
182
|
+
// protocols without changing this package.
|
|
183
|
+
id: "fake-echo",
|
|
184
|
+
body: {
|
|
185
|
+
schema: FakeBody,
|
|
186
|
+
from: (request) =>
|
|
187
|
+
Effect.succeed({
|
|
188
|
+
model: request.model.id,
|
|
189
|
+
input: request.messages
|
|
190
|
+
.flatMap((message) => [...message.content])
|
|
191
|
+
.filter((part) => part.type === "text")
|
|
192
|
+
.map((part) => part.text)
|
|
193
|
+
.join("\n"),
|
|
194
|
+
}),
|
|
195
|
+
},
|
|
196
|
+
stream: {
|
|
197
|
+
event: Schema.String,
|
|
198
|
+
initial: () => undefined,
|
|
199
|
+
step: (_, frame) => Effect.succeed([undefined, [{ type: "text-delta", id: "text-0", text: frame }]] as const),
|
|
200
|
+
onHalt: () => Effect.succeed([{ type: "finish", reason: { normalized: "stop" } }]),
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// A route is the runnable binding for that protocol. It adds the deployment
|
|
205
|
+
// axes that the protocol deliberately does not know: URL, auth, and framing.
|
|
206
|
+
const FakeAdapter = Route.make({
|
|
207
|
+
id: "fake-echo",
|
|
208
|
+
provider: "fake-echo",
|
|
209
|
+
protocol: FakeProtocol,
|
|
210
|
+
endpoint: Endpoint.path("/v1/echo", { baseURL: "https://fake.local" }),
|
|
211
|
+
auth: Auth.passthrough,
|
|
212
|
+
framing: Framing.sse,
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
// A provider module exports a configured facade. Configuration happens before
|
|
216
|
+
// model selection; model selectors accept ids only.
|
|
217
|
+
const FakeEcho = {
|
|
218
|
+
id: ProviderID.make("fake-echo"),
|
|
219
|
+
configure: () => ({
|
|
220
|
+
id: ProviderID.make("fake-echo"),
|
|
221
|
+
model: (id: string) => FakeAdapter.model({ id }),
|
|
222
|
+
}),
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 7. Run the fake provider offline. `RequestExecutor.middleware` sees every HTTP
|
|
226
|
+
// request before it is sent; here it answers with two SSE frames instead of
|
|
227
|
+
// calling the network.
|
|
228
|
+
const fakeExecutor = RequestExecutor.middleware((request) =>
|
|
229
|
+
Effect.succeed(
|
|
230
|
+
HttpClientResponse.fromWeb(
|
|
231
|
+
request,
|
|
232
|
+
new Response("data: hello\n\ndata: from fake-echo\n\n", { headers: { "content-type": "text/event-stream" } }),
|
|
233
|
+
),
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
const generateFake = Effect.gen(function* () {
|
|
238
|
+
const response = yield* ai.generate({ model: FakeEcho.configure().model("echo-1"), prompt: "Say hello." })
|
|
239
|
+
console.log("\n== fake provider ==")
|
|
240
|
+
console.log("generated text:", response.text)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// 8. Image generation uses the same facade and the same request/generate shape.
|
|
244
|
+
// `response.images[0]` is a `Media.Asset`: bytes decode lazily and are cached, and
|
|
245
|
+
// `Media.write` persists them through the Effect `FileSystem`.
|
|
246
|
+
const generateImage = Effect.gen(function* () {
|
|
247
|
+
const response = yield* ai.image.generate({
|
|
248
|
+
model: openai.image("gpt-image-1-mini"),
|
|
249
|
+
prompt: "A flat black circle centered on a plain white background.",
|
|
250
|
+
aspect: "1:1",
|
|
251
|
+
// Exact pixel sizes and output formats are provider options.
|
|
252
|
+
providerOptions: { quality: "low", outputFormat: "jpeg" },
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
console.log("\n== image ==")
|
|
256
|
+
console.log("media type:", response.images[0].mediaType)
|
|
257
|
+
console.log("bytes:", (yield* response.images[0].bytes()).byteLength)
|
|
258
|
+
console.log("usage", Formatter.formatJson(response.usage, { space: 2 }))
|
|
259
|
+
yield* Media.write(response.images[0], "tutorial-image.jpg").pipe(Effect.provide(NodeFileSystem.layer))
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Provide every modality client and the HTTP request executor once with
|
|
263
|
+
// `AIClient.layer`; `AIClient.layerWith(executor)` swaps the executor, as the
|
|
264
|
+
// fake example does. One example runs at a time so the tutorial does not spend
|
|
265
|
+
// tokens on every path.
|
|
266
|
+
const examples: Record<string, Effect.Effect<void, unknown, AIClient.Services>> = {
|
|
267
|
+
generate: generateOnce,
|
|
268
|
+
stream: streamText,
|
|
269
|
+
tools: streamWithTools,
|
|
270
|
+
object: generateStructuredObject,
|
|
271
|
+
"dynamic-object": generateDynamicObject.pipe(
|
|
272
|
+
Effect.andThen((response) => Effect.sync(() => console.log(response.object))),
|
|
273
|
+
),
|
|
274
|
+
image: generateImage,
|
|
275
|
+
fake: generateFake,
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const name = process.argv[2] ?? "tools"
|
|
279
|
+
if (!Object.hasOwn(examples, name))
|
|
280
|
+
throw new Error(`Unknown example ${name}; pick one of ${Object.keys(examples).join(", ")}`)
|
|
281
|
+
|
|
282
|
+
Effect.runPromise(
|
|
283
|
+
examples[name].pipe(Effect.provide(name === "fake" ? AIClient.layerWith(fakeExecutor) : AIClient.layer)),
|
|
284
|
+
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"name": "@zyro-sec/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,9 +12,6 @@
|
|
|
12
12
|
"build": "tsc -p tsconfig.build.json",
|
|
13
13
|
"pack": "bun run script/pack.ts"
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
15
|
"exports": {
|
|
19
16
|
".": "./src/index.ts",
|
|
20
17
|
"./effect": "./src/effect.ts",
|
|
@@ -170,20 +167,20 @@
|
|
|
170
167
|
},
|
|
171
168
|
"devDependencies": {
|
|
172
169
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
173
|
-
"@effect/platform-node": "
|
|
174
|
-
"@zyro-sec/http-recorder": "^1.0.
|
|
175
|
-
"@tsconfig/bun": "
|
|
176
|
-
"@types/bun": "
|
|
177
|
-
"@typescript/native": "
|
|
178
|
-
"typescript": "
|
|
170
|
+
"@effect/platform-node": "4.1.0",
|
|
171
|
+
"@zyro-sec/http-recorder": "^1.0.2",
|
|
172
|
+
"@tsconfig/bun": "1.0.9",
|
|
173
|
+
"@types/bun": "1.4.3",
|
|
174
|
+
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
175
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
179
176
|
},
|
|
180
177
|
"dependencies": {
|
|
181
178
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
182
179
|
"@smithy/eventstream-codec": "4.2.14",
|
|
183
180
|
"@smithy/util-utf8": "4.2.2",
|
|
184
|
-
"@zyro-sec/schema": "^1.0.
|
|
181
|
+
"@zyro-sec/schema": "^1.0.2",
|
|
185
182
|
"aws4fetch": "1.0.20",
|
|
186
|
-
"effect": "
|
|
183
|
+
"effect": "4.1.0",
|
|
187
184
|
"google-auth-library": "10.5.0"
|
|
188
185
|
},
|
|
189
186
|
"repository": {
|
|
@@ -193,5 +190,6 @@
|
|
|
193
190
|
},
|
|
194
191
|
"publishConfig": {
|
|
195
192
|
"access": "public"
|
|
196
|
-
}
|
|
193
|
+
},
|
|
194
|
+
"main": "src/index.ts"
|
|
197
195
|
}
|
package/script/pack.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises"
|
|
2
|
+
import * as path from "node:path"
|
|
3
|
+
|
|
4
|
+
const RECORDINGS_DIR = path.resolve(import.meta.dir, "..", "test", "fixtures", "recordings")
|
|
5
|
+
const MODELS_DEV_URL = "https://models.opencode.ai/api.json"
|
|
6
|
+
|
|
7
|
+
type JsonRecord = Record<string, unknown>
|
|
8
|
+
|
|
9
|
+
type Pricing = {
|
|
10
|
+
readonly input?: number
|
|
11
|
+
readonly output?: number
|
|
12
|
+
readonly cache_read?: number
|
|
13
|
+
readonly cache_write?: number
|
|
14
|
+
readonly reasoning?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Usage = {
|
|
18
|
+
readonly inputTokens: number
|
|
19
|
+
readonly outputTokens: number
|
|
20
|
+
readonly cacheReadTokens: number
|
|
21
|
+
readonly cacheWriteTokens: number
|
|
22
|
+
readonly reasoningTokens: number
|
|
23
|
+
readonly reportedCost: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Row = Usage & {
|
|
27
|
+
readonly cassette: string
|
|
28
|
+
readonly provider: string
|
|
29
|
+
readonly model: string
|
|
30
|
+
readonly estimatedCost: number
|
|
31
|
+
readonly pricingSource: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isRecord = (value: unknown): value is JsonRecord =>
|
|
35
|
+
value !== null && typeof value === "object" && !Array.isArray(value)
|
|
36
|
+
|
|
37
|
+
const asNumber = (value: unknown) => (typeof value === "number" && Number.isFinite(value) ? value : 0)
|
|
38
|
+
|
|
39
|
+
const asString = (value: unknown) => (typeof value === "string" ? value : undefined)
|
|
40
|
+
|
|
41
|
+
const readJson = async (file: string) => JSON.parse(await Bun.file(file).text()) as unknown
|
|
42
|
+
|
|
43
|
+
const walk = async (dir: string): Promise<ReadonlyArray<string>> =>
|
|
44
|
+
(await fs.readdir(dir, { withFileTypes: true }))
|
|
45
|
+
.flatMap((entry) => {
|
|
46
|
+
const file = path.join(dir, entry.name)
|
|
47
|
+
return entry.isDirectory() ? [] : [file]
|
|
48
|
+
})
|
|
49
|
+
.concat(
|
|
50
|
+
...(await Promise.all(
|
|
51
|
+
(await fs.readdir(dir, { withFileTypes: true }))
|
|
52
|
+
.filter((entry) => entry.isDirectory())
|
|
53
|
+
.map((entry) => walk(path.join(dir, entry.name))),
|
|
54
|
+
)),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const providerFromUrl = (url: string) => {
|
|
58
|
+
if (url.includes("api.openai.com")) return "openai"
|
|
59
|
+
if (url.includes("api.anthropic.com")) return "anthropic"
|
|
60
|
+
if (url.includes("generativelanguage.googleapis.com")) return "google"
|
|
61
|
+
if (url.includes("bedrock")) return "amazon-bedrock"
|
|
62
|
+
if (url.includes("openrouter.ai")) return "openrouter"
|
|
63
|
+
if (url.includes("api.x.ai")) return "xai"
|
|
64
|
+
if (url.includes("api.groq.com")) return "groq"
|
|
65
|
+
if (url.includes("api.deepseek.com")) return "deepseek"
|
|
66
|
+
if (url.includes("api.together.xyz")) return "togetherai"
|
|
67
|
+
return "unknown"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const providerAliases: Record<string, ReadonlyArray<string>> = {
|
|
71
|
+
openai: ["openai"],
|
|
72
|
+
anthropic: ["anthropic"],
|
|
73
|
+
google: ["google"],
|
|
74
|
+
"amazon-bedrock": ["amazon-bedrock"],
|
|
75
|
+
openrouter: ["openrouter", "openai", "anthropic", "google"],
|
|
76
|
+
xai: ["xai"],
|
|
77
|
+
groq: ["groq"],
|
|
78
|
+
deepseek: ["deepseek"],
|
|
79
|
+
togetherai: ["togetherai"],
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const modelAliases = (model: string) => [
|
|
83
|
+
model,
|
|
84
|
+
model.replace(/^models\//, ""),
|
|
85
|
+
model.replace(/-\d{8}$/, ""),
|
|
86
|
+
model.replace(/-\d{4}-\d{2}-\d{2}$/, ""),
|
|
87
|
+
model.replace(/-\d{4}-\d{2}-\d{2}$/, "").replace(/-\d{8}$/, ""),
|
|
88
|
+
model.replace(/^openai\//, ""),
|
|
89
|
+
model.replace(/^anthropic\//, ""),
|
|
90
|
+
model.replace(/^google\//, ""),
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
const pricingFor = (models: JsonRecord, provider: string, model: string) => {
|
|
94
|
+
for (const providerID of providerAliases[provider] ?? [provider]) {
|
|
95
|
+
const providerEntry = models[providerID]
|
|
96
|
+
if (!isRecord(providerEntry) || !isRecord(providerEntry.models)) continue
|
|
97
|
+
for (const modelID of modelAliases(model)) {
|
|
98
|
+
const modelEntry = providerEntry.models[modelID]
|
|
99
|
+
if (isRecord(modelEntry) && isRecord(modelEntry.cost))
|
|
100
|
+
return { pricing: modelEntry.cost as Pricing, source: `${providerID}/${modelID}` }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { pricing: undefined, source: "missing" }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const estimateCost = (usage: Usage, pricing: Pricing | undefined) => {
|
|
107
|
+
if (!pricing) return 0
|
|
108
|
+
return (
|
|
109
|
+
(usage.inputTokens * (pricing.input ?? 0) +
|
|
110
|
+
usage.outputTokens * (pricing.output ?? 0) +
|
|
111
|
+
usage.cacheReadTokens * (pricing.cache_read ?? 0) +
|
|
112
|
+
usage.cacheWriteTokens * (pricing.cache_write ?? 0) +
|
|
113
|
+
usage.reasoningTokens * (pricing.reasoning ?? 0)) /
|
|
114
|
+
1_000_000
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const emptyUsage = (): Usage => ({
|
|
119
|
+
inputTokens: 0,
|
|
120
|
+
outputTokens: 0,
|
|
121
|
+
cacheReadTokens: 0,
|
|
122
|
+
cacheWriteTokens: 0,
|
|
123
|
+
reasoningTokens: 0,
|
|
124
|
+
reportedCost: 0,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const addUsage = (a: Usage, b: Usage): Usage => ({
|
|
128
|
+
inputTokens: a.inputTokens + b.inputTokens,
|
|
129
|
+
outputTokens: a.outputTokens + b.outputTokens,
|
|
130
|
+
cacheReadTokens: a.cacheReadTokens + b.cacheReadTokens,
|
|
131
|
+
cacheWriteTokens: a.cacheWriteTokens + b.cacheWriteTokens,
|
|
132
|
+
reasoningTokens: a.reasoningTokens + b.reasoningTokens,
|
|
133
|
+
reportedCost: a.reportedCost + b.reportedCost,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const usageFromObject = (usage: unknown): Usage => {
|
|
137
|
+
if (!isRecord(usage)) return emptyUsage()
|
|
138
|
+
const promptDetails = isRecord(usage.prompt_tokens_details) ? usage.prompt_tokens_details : {}
|
|
139
|
+
const completionDetails = isRecord(usage.completion_tokens_details) ? usage.completion_tokens_details : {}
|
|
140
|
+
const inputDetails = isRecord(usage.input_tokens_details) ? usage.input_tokens_details : {}
|
|
141
|
+
const outputDetails = isRecord(usage.output_tokens_details) ? usage.output_tokens_details : {}
|
|
142
|
+
const cacheWriteTokens = asNumber(promptDetails.cache_write_tokens) + asNumber(inputDetails.cache_write_tokens)
|
|
143
|
+
return {
|
|
144
|
+
inputTokens: asNumber(usage.prompt_tokens) + asNumber(usage.input_tokens),
|
|
145
|
+
outputTokens: asNumber(usage.completion_tokens) + asNumber(usage.output_tokens),
|
|
146
|
+
cacheReadTokens: asNumber(promptDetails.cached_tokens) + asNumber(inputDetails.cached_tokens),
|
|
147
|
+
cacheWriteTokens,
|
|
148
|
+
reasoningTokens: asNumber(completionDetails.reasoning_tokens) + asNumber(outputDetails.reasoning_tokens),
|
|
149
|
+
reportedCost: asNumber(usage.cost),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const jsonPayloads = (body: string) =>
|
|
154
|
+
body
|
|
155
|
+
.split("\n")
|
|
156
|
+
.map((line) => line.trim())
|
|
157
|
+
.filter((line) => line.startsWith("data:"))
|
|
158
|
+
.map((line) => line.slice("data:".length).trim())
|
|
159
|
+
.filter((line) => line !== "" && line !== "[DONE]")
|
|
160
|
+
.flatMap((line) => {
|
|
161
|
+
try {
|
|
162
|
+
return [JSON.parse(line) as unknown]
|
|
163
|
+
} catch {
|
|
164
|
+
return []
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const usageFromResponseBody = (body: string) =>
|
|
169
|
+
jsonPayloads(body).reduce<Usage>((usage, payload) => {
|
|
170
|
+
if (!isRecord(payload)) return usage
|
|
171
|
+
return addUsage(
|
|
172
|
+
usage,
|
|
173
|
+
addUsage(
|
|
174
|
+
usageFromObject(payload.usage),
|
|
175
|
+
usageFromObject(isRecord(payload.response) ? payload.response.usage : undefined),
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
}, emptyUsage())
|
|
179
|
+
|
|
180
|
+
const modelFromRequest = (request: unknown) => {
|
|
181
|
+
if (!isRecord(request)) return "unknown"
|
|
182
|
+
const requestBody = asString(request.body)
|
|
183
|
+
if (!requestBody) return "unknown"
|
|
184
|
+
try {
|
|
185
|
+
const body = JSON.parse(requestBody) as unknown
|
|
186
|
+
if (!isRecord(body)) return "unknown"
|
|
187
|
+
return asString(body.model) ?? "unknown"
|
|
188
|
+
} catch {
|
|
189
|
+
return "unknown"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const rowFor = (models: JsonRecord, file: string, cassette: unknown): Row | undefined => {
|
|
194
|
+
if (!isRecord(cassette) || !Array.isArray(cassette.interactions)) return undefined
|
|
195
|
+
const first = cassette.interactions.find(isRecord)
|
|
196
|
+
if (!first || !isRecord(first.request)) return undefined
|
|
197
|
+
const provider = providerFromUrl(asString(first.request.url) ?? "")
|
|
198
|
+
const model = modelFromRequest(first.request)
|
|
199
|
+
const usage = cassette.interactions.filter(isRecord).reduce<Usage>((total, interaction) => {
|
|
200
|
+
if (!isRecord(interaction.response)) return total
|
|
201
|
+
const responseBody = asString(interaction.response.body)
|
|
202
|
+
if (!responseBody) return total
|
|
203
|
+
return addUsage(total, usageFromResponseBody(responseBody))
|
|
204
|
+
}, emptyUsage())
|
|
205
|
+
const priced = pricingFor(models, provider, model)
|
|
206
|
+
return {
|
|
207
|
+
cassette: path.relative(RECORDINGS_DIR, file),
|
|
208
|
+
provider,
|
|
209
|
+
model,
|
|
210
|
+
...usage,
|
|
211
|
+
estimatedCost: estimateCost(usage, priced.pricing),
|
|
212
|
+
pricingSource: priced.source,
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const money = (value: number) => (value === 0 ? "$0.000000" : `$${value.toFixed(6)}`)
|
|
217
|
+
const tokens = (value: number) => value.toLocaleString("en-US")
|
|
218
|
+
|
|
219
|
+
const models = (await (await fetch(MODELS_DEV_URL)).json()) as JsonRecord
|
|
220
|
+
const rows = (
|
|
221
|
+
await Promise.all(
|
|
222
|
+
(await walk(RECORDINGS_DIR))
|
|
223
|
+
.filter((file) => file.endsWith(".json"))
|
|
224
|
+
.map(async (file) => rowFor(models, file, await readJson(file))),
|
|
225
|
+
)
|
|
226
|
+
).filter((row): row is Row => row !== undefined)
|
|
227
|
+
|
|
228
|
+
const totals = rows.reduce(
|
|
229
|
+
(total, row) => ({
|
|
230
|
+
...addUsage(total, row),
|
|
231
|
+
estimatedCost: total.estimatedCost + row.estimatedCost,
|
|
232
|
+
}),
|
|
233
|
+
{ ...emptyUsage(), estimatedCost: 0 },
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
console.log("# Recording Cost Report")
|
|
237
|
+
console.log("")
|
|
238
|
+
console.log(`Pricing: ${MODELS_DEV_URL}`)
|
|
239
|
+
console.log(`Cassettes: ${rows.length}`)
|
|
240
|
+
console.log(`Reported cost: ${money(totals.reportedCost)}`)
|
|
241
|
+
console.log(`Estimated cost: ${money(totals.estimatedCost)}`)
|
|
242
|
+
console.log("")
|
|
243
|
+
console.log("| Provider | Model | Input | Output | Reasoning | Reported | Estimated | Pricing | Cassette |")
|
|
244
|
+
console.log("|---|---:|---:|---:|---:|---:|---:|---|---|")
|
|
245
|
+
for (const row of rows.toSorted((a, b) => b.reportedCost + b.estimatedCost - (a.reportedCost + a.estimatedCost))) {
|
|
246
|
+
if (row.inputTokens + row.outputTokens + row.reasoningTokens + row.reportedCost + row.estimatedCost === 0) continue
|
|
247
|
+
console.log(
|
|
248
|
+
`| ${row.provider} | ${row.model} | ${tokens(row.inputTokens)} | ${tokens(row.outputTokens)} | ${tokens(row.reasoningTokens)} | ${money(row.reportedCost)} | ${money(row.estimatedCost)} | ${row.pricingSource} | ${row.cassette} |`,
|
|
249
|
+
)
|
|
250
|
+
}
|