innocode 1.0.0 → 1.0.229
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/LICENSE +21 -0
- package/package.json +17 -118
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -18
- package/README.md +0 -15
- package/bunfig.toml +0 -5
- package/parsers-config.ts +0 -253
- package/script/build.ts +0 -198
- package/script/publish.ts +0 -186
- package/script/schema.ts +0 -47
- package/script/seed-e2e.ts +0 -50
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -1676
- package/src/acp/session.ts +0 -117
- package/src/acp/types.ts +0 -23
- package/src/agent/agent.ts +0 -338
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -14
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -44
- package/src/auth/index.ts +0 -70
- package/src/bun/index.ts +0 -137
- package/src/bun/registry.ts +0 -48
- package/src/bus/bus-event.ts +0 -43
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -105
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -70
- package/src/cli/cmd/agent.ts +0 -257
- package/src/cli/cmd/auth.ts +0 -400
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/agent.ts +0 -167
- package/src/cli/cmd/debug/config.ts +0 -16
- package/src/cli/cmd/debug/file.ts +0 -97
- package/src/cli/cmd/debug/index.ts +0 -48
- package/src/cli/cmd/debug/lsp.ts +0 -52
- package/src/cli/cmd/debug/ripgrep.ts +0 -87
- package/src/cli/cmd/debug/scrap.ts +0 -16
- package/src/cli/cmd/debug/skill.ts +0 -16
- package/src/cli/cmd/debug/snapshot.ts +0 -52
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -1540
- package/src/cli/cmd/import.ts +0 -147
- package/src/cli/cmd/mcp.ts +0 -765
- package/src/cli/cmd/models.ts +0 -77
- package/src/cli/cmd/pr.ts +0 -113
- package/src/cli/cmd/run.ts +0 -598
- package/src/cli/cmd/serve.ts +0 -20
- package/src/cli/cmd/session.ts +0 -135
- package/src/cli/cmd/stats.ts +0 -426
- package/src/cli/cmd/tui/app.tsx +0 -812
- package/src/cli/cmd/tui/attach.ts +0 -60
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -165
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -243
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -108
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-skill.tsx +0 -36
- package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -167
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/logo.tsx +0 -85
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -666
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1153
- package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
- package/src/cli/cmd/tui/component/spinner.tsx +0 -24
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
- package/src/cli/cmd/tui/component/tips.tsx +0 -153
- package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
- package/src/cli/cmd/tui/context/args.tsx +0 -15
- package/src/cli/cmd/tui/context/directory.ts +0 -13
- package/src/cli/cmd/tui/context/exit.tsx +0 -54
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -100
- package/src/cli/cmd/tui/context/kv.tsx +0 -52
- package/src/cli/cmd/tui/context/local.tsx +0 -409
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -46
- package/src/cli/cmd/tui/context/sdk.tsx +0 -101
- package/src/cli/cmd/tui/context/sync.tsx +0 -470
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -242
- package/src/cli/cmd/tui/context/theme/innocode.json +0 -245
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -249
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1154
- package/src/cli/cmd/tui/event.ts +0 -48
- package/src/cli/cmd/tui/routes/home.tsx +0 -145
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -135
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -2139
- package/src/cli/cmd/tui/routes/session/permission.tsx +0 -508
- package/src/cli/cmd/tui/routes/session/question.tsx +0 -466
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -313
- package/src/cli/cmd/tui/thread.ts +0 -188
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -59
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -85
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -207
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -40
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -80
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -401
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
- package/src/cli/cmd/tui/ui/link.tsx +0 -28
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -159
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/signal.ts +0 -7
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/util/transcript.ts +0 -98
- package/src/cli/cmd/tui/win32.ts +0 -129
- package/src/cli/cmd/tui/worker.ts +0 -152
- package/src/cli/cmd/uninstall.ts +0 -363
- package/src/cli/cmd/upgrade.ts +0 -73
- package/src/cli/cmd/web.ts +0 -81
- package/src/cli/error.ts +0 -57
- package/src/cli/logo.ts +0 -6
- package/src/cli/network.ts +0 -60
- package/src/cli/ui.ts +0 -113
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -150
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -101
- package/src/config/config.ts +0 -1517
- package/src/config/markdown.ts +0 -98
- package/src/env/index.ts +0 -28
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -583
- package/src/file/ripgrep.ts +0 -375
- package/src/file/time.ts +0 -69
- package/src/file/watcher.ts +0 -127
- package/src/flag/flag.ts +0 -148
- package/src/format/formatter.ts +0 -366
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -80
- package/src/id/id.ts +0 -83
- package/src/ide/index.ts +0 -76
- package/src/index.ts +0 -160
- package/src/installation/index.ts +0 -268
- package/src/lsp/client.ts +0 -252
- package/src/lsp/index.ts +0 -485
- package/src/lsp/language.ts +0 -119
- package/src/lsp/server.ts +0 -2046
- package/src/mcp/auth.ts +0 -132
- package/src/mcp/index.ts +0 -937
- package/src/mcp/oauth-callback.ts +0 -200
- package/src/mcp/oauth-provider.ts +0 -154
- package/src/patch/index.ts +0 -680
- package/src/permission/arity.ts +0 -163
- package/src/permission/index.ts +0 -210
- package/src/permission/next.ts +0 -280
- package/src/plugin/codex.ts +0 -624
- package/src/plugin/copilot.ts +0 -327
- package/src/plugin/index.ts +0 -138
- package/src/project/bootstrap.ts +0 -35
- package/src/project/instance.ts +0 -114
- package/src/project/project.ts +0 -371
- package/src/project/state.ts +0 -70
- package/src/project/vcs.ts +0 -76
- package/src/provider/auth.ts +0 -147
- package/src/provider/error.ts +0 -189
- package/src/provider/models.ts +0 -133
- package/src/provider/provider.ts +0 -1370
- package/src/provider/sdk/copilot/README.md +0 -5
- package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -164
- package/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
- package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -17
- package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -780
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
- package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
- package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -87
- package/src/provider/sdk/copilot/copilot-provider.ts +0 -100
- package/src/provider/sdk/copilot/index.ts +0 -2
- package/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
- package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -303
- package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
- package/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
- package/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
- package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -207
- package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1732
- package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -177
- package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
- package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -88
- package/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -128
- package/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -115
- package/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -65
- package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -104
- package/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -103
- package/src/provider/transform.ts +0 -806
- package/src/pty/index.ts +0 -286
- package/src/question/index.ts +0 -171
- package/src/scheduler/index.ts +0 -61
- package/src/server/error.ts +0 -36
- package/src/server/event.ts +0 -7
- package/src/server/mdns.ts +0 -60
- package/src/server/routes/config.ts +0 -92
- package/src/server/routes/experimental.ts +0 -208
- package/src/server/routes/file.ts +0 -197
- package/src/server/routes/global.ts +0 -183
- package/src/server/routes/mcp.ts +0 -225
- package/src/server/routes/permission.ts +0 -68
- package/src/server/routes/project.ts +0 -82
- package/src/server/routes/provider.ts +0 -179
- package/src/server/routes/pty.ts +0 -176
- package/src/server/routes/question.ts +0 -98
- package/src/server/routes/session.ts +0 -939
- package/src/server/routes/tui.ts +0 -379
- package/src/server/server.ts +0 -621
- package/src/session/compaction.ts +0 -261
- package/src/session/index.ts +0 -543
- package/src/session/instruction.ts +0 -197
- package/src/session/llm.ts +0 -283
- package/src/session/message-v2.ts +0 -841
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -410
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex_header.txt +0 -79
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt/trinity.txt +0 -97
- package/src/session/prompt.ts +0 -1964
- package/src/session/retry.ts +0 -101
- package/src/session/revert.ts +0 -121
- package/src/session/status.ts +0 -76
- package/src/session/summary.ts +0 -203
- package/src/session/system.ts +0 -54
- package/src/session/todo.ts +0 -37
- package/src/share/share-next.ts +0 -200
- package/src/share/share.ts +0 -92
- package/src/shell/shell.ts +0 -67
- package/src/skill/discovery.ts +0 -97
- package/src/skill/index.ts +0 -1
- package/src/skill/skill.ts +0 -188
- package/src/snapshot/index.ts +0 -255
- package/src/storage/storage.ts +0 -227
- package/src/tool/apply_patch.ts +0 -281
- package/src/tool/apply_patch.txt +0 -33
- package/src/tool/bash.ts +0 -269
- package/src/tool/bash.txt +0 -115
- package/src/tool/batch.ts +0 -175
- package/src/tool/batch.txt +0 -24
- package/src/tool/codesearch.ts +0 -132
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -655
- package/src/tool/edit.txt +0 -10
- package/src/tool/external-directory.ts +0 -32
- package/src/tool/glob.ts +0 -80
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -150
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -121
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp.ts +0 -96
- package/src/tool/lsp.txt +0 -19
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/plan-enter.txt +0 -14
- package/src/tool/plan-exit.txt +0 -13
- package/src/tool/plan.ts +0 -130
- package/src/tool/question.ts +0 -33
- package/src/tool/question.txt +0 -10
- package/src/tool/read.ts +0 -261
- package/src/tool/read.txt +0 -14
- package/src/tool/registry.ts +0 -160
- package/src/tool/skill.ts +0 -123
- package/src/tool/task.ts +0 -165
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -53
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -89
- package/src/tool/truncation.ts +0 -106
- package/src/tool/webfetch.ts +0 -186
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -150
- package/src/tool/websearch.txt +0 -14
- package/src/tool/write.ts +0 -85
- package/src/tool/write.txt +0 -8
- package/src/util/abort.ts +0 -35
- package/src/util/archive.ts +0 -16
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -93
- package/src/util/fn.ts +0 -11
- package/src/util/format.ts +0 -20
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -103
- package/src/util/lazy.ts +0 -18
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -180
- package/src/util/proxied.ts +0 -3
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -66
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -56
- package/src/worktree/index.ts +0 -612
- package/sst-env.d.ts +0 -9
- package/test/acp/agent-interface.test.ts +0 -51
- package/test/acp/event-subscription.test.ts +0 -436
- package/test/agent/agent.test.ts +0 -675
- package/test/bun.test.ts +0 -53
- package/test/cli/github-action.test.ts +0 -161
- package/test/cli/github-remote.test.ts +0 -80
- package/test/cli/import.test.ts +0 -38
- package/test/cli/tui/transcript.test.ts +0 -322
- package/test/config/agent-color.test.ts +0 -71
- package/test/config/config.test.ts +0 -1802
- package/test/config/fixtures/empty-frontmatter.md +0 -4
- package/test/config/fixtures/frontmatter.md +0 -28
- package/test/config/fixtures/markdown-header.md +0 -11
- package/test/config/fixtures/no-frontmatter.md +0 -1
- package/test/config/fixtures/weird-model-id.md +0 -13
- package/test/config/markdown.test.ts +0 -228
- package/test/file/ignore.test.ts +0 -10
- package/test/file/path-traversal.test.ts +0 -198
- package/test/file/ripgrep.test.ts +0 -39
- package/test/fixture/fixture.ts +0 -45
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -421
- package/test/lsp/client.test.ts +0 -95
- package/test/mcp/headers.test.ts +0 -153
- package/test/mcp/oauth-browser.test.ts +0 -249
- package/test/memory/abort-leak.test.ts +0 -136
- package/test/patch/patch.test.ts +0 -348
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -690
- package/test/permission-task.test.ts +0 -319
- package/test/plugin/auth-override.test.ts +0 -44
- package/test/plugin/codex.test.ts +0 -123
- package/test/preload.ts +0 -63
- package/test/project/project.test.ts +0 -120
- package/test/provider/amazon-bedrock.test.ts +0 -445
- package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
- package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
- package/test/provider/gitlab-duo.test.ts +0 -262
- package/test/provider/provider.test.ts +0 -2129
- package/test/provider/transform.test.ts +0 -1928
- package/test/question/question.test.ts +0 -300
- package/test/scheduler.test.ts +0 -73
- package/test/server/session-list.test.ts +0 -39
- package/test/server/session-select.test.ts +0 -78
- package/test/session/compaction.test.ts +0 -423
- package/test/session/instruction.test.ts +0 -170
- package/test/session/llm.test.ts +0 -667
- package/test/session/message-v2.test.ts +0 -924
- package/test/session/prompt-missing-file.test.ts +0 -53
- package/test/session/prompt-special-chars.test.ts +0 -56
- package/test/session/prompt-variant.test.ts +0 -68
- package/test/session/retry.test.ts +0 -188
- package/test/session/revert-compact.test.ts +0 -285
- package/test/session/session.test.ts +0 -71
- package/test/session/structured-output-integration.test.ts +0 -233
- package/test/session/structured-output.test.ts +0 -385
- package/test/skill/discovery.test.ts +0 -60
- package/test/skill/skill.test.ts +0 -388
- package/test/snapshot/snapshot.test.ts +0 -1040
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/apply_patch.test.ts +0 -559
- package/test/tool/bash.test.ts +0 -399
- package/test/tool/external-directory.test.ts +0 -127
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +0 -38413
- package/test/tool/grep.test.ts +0 -110
- package/test/tool/question.test.ts +0 -107
- package/test/tool/read.test.ts +0 -421
- package/test/tool/registry.test.ts +0 -122
- package/test/tool/skill.test.ts +0 -112
- package/test/tool/truncation.test.ts +0 -159
- package/test/util/filesystem.test.ts +0 -39
- package/test/util/format.test.ts +0 -59
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/lock.test.ts +0 -72
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -75
- package/tsconfig.json +0 -16
- /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
package/test/session/llm.test.ts
DELETED
|
@@ -1,667 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"
|
|
2
|
-
import path from "path"
|
|
3
|
-
import type { ModelMessage } from "ai"
|
|
4
|
-
import { LLM } from "../../src/session/llm"
|
|
5
|
-
import { Global } from "../../src/global"
|
|
6
|
-
import { Instance } from "../../src/project/instance"
|
|
7
|
-
import { Provider } from "../../src/provider/provider"
|
|
8
|
-
import { ProviderTransform } from "../../src/provider/transform"
|
|
9
|
-
import { ModelsDev } from "../../src/provider/models"
|
|
10
|
-
import { tmpdir } from "../fixture/fixture"
|
|
11
|
-
import type { Agent } from "../../src/agent/agent"
|
|
12
|
-
import type { MessageV2 } from "../../src/session/message-v2"
|
|
13
|
-
|
|
14
|
-
describe("session.llm.hasToolCalls", () => {
|
|
15
|
-
test("returns false for empty messages array", () => {
|
|
16
|
-
expect(LLM.hasToolCalls([])).toBe(false)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test("returns false for messages with only text content", () => {
|
|
20
|
-
const messages: ModelMessage[] = [
|
|
21
|
-
{
|
|
22
|
-
role: "user",
|
|
23
|
-
content: [{ type: "text", text: "Hello" }],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
role: "assistant",
|
|
27
|
-
content: [{ type: "text", text: "Hi there" }],
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
expect(LLM.hasToolCalls(messages)).toBe(false)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
test("returns true when messages contain tool-call", () => {
|
|
34
|
-
const messages = [
|
|
35
|
-
{
|
|
36
|
-
role: "user",
|
|
37
|
-
content: [{ type: "text", text: "Run a command" }],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
role: "assistant",
|
|
41
|
-
content: [
|
|
42
|
-
{
|
|
43
|
-
type: "tool-call",
|
|
44
|
-
toolCallId: "call-123",
|
|
45
|
-
toolName: "bash",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
] as ModelMessage[]
|
|
50
|
-
expect(LLM.hasToolCalls(messages)).toBe(true)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test("returns true when messages contain tool-result", () => {
|
|
54
|
-
const messages = [
|
|
55
|
-
{
|
|
56
|
-
role: "tool",
|
|
57
|
-
content: [
|
|
58
|
-
{
|
|
59
|
-
type: "tool-result",
|
|
60
|
-
toolCallId: "call-123",
|
|
61
|
-
toolName: "bash",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
] as ModelMessage[]
|
|
66
|
-
expect(LLM.hasToolCalls(messages)).toBe(true)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test("returns false for messages with string content", () => {
|
|
70
|
-
const messages: ModelMessage[] = [
|
|
71
|
-
{
|
|
72
|
-
role: "user",
|
|
73
|
-
content: "Hello world",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
role: "assistant",
|
|
77
|
-
content: "Hi there",
|
|
78
|
-
},
|
|
79
|
-
]
|
|
80
|
-
expect(LLM.hasToolCalls(messages)).toBe(false)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test("returns true when tool-call is mixed with text content", () => {
|
|
84
|
-
const messages = [
|
|
85
|
-
{
|
|
86
|
-
role: "assistant",
|
|
87
|
-
content: [
|
|
88
|
-
{ type: "text", text: "Let me run that command" },
|
|
89
|
-
{
|
|
90
|
-
type: "tool-call",
|
|
91
|
-
toolCallId: "call-456",
|
|
92
|
-
toolName: "read",
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
] as ModelMessage[]
|
|
97
|
-
expect(LLM.hasToolCalls(messages)).toBe(true)
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
type Capture = {
|
|
102
|
-
url: URL
|
|
103
|
-
headers: Headers
|
|
104
|
-
body: Record<string, unknown>
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const state = {
|
|
108
|
-
server: null as ReturnType<typeof Bun.serve> | null,
|
|
109
|
-
queue: [] as Array<{ path: string; response: Response; resolve: (value: Capture) => void }>,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function deferred<T>() {
|
|
113
|
-
const result = {} as { promise: Promise<T>; resolve: (value: T) => void }
|
|
114
|
-
result.promise = new Promise((resolve) => {
|
|
115
|
-
result.resolve = resolve
|
|
116
|
-
})
|
|
117
|
-
return result
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function waitRequest(pathname: string, response: Response) {
|
|
121
|
-
const pending = deferred<Capture>()
|
|
122
|
-
state.queue.push({ path: pathname, response, resolve: pending.resolve })
|
|
123
|
-
return pending.promise
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
beforeAll(() => {
|
|
127
|
-
state.server = Bun.serve({
|
|
128
|
-
port: 0,
|
|
129
|
-
async fetch(req) {
|
|
130
|
-
const next = state.queue.shift()
|
|
131
|
-
if (!next) {
|
|
132
|
-
return new Response("unexpected request", { status: 500 })
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const url = new URL(req.url)
|
|
136
|
-
const body = (await req.json()) as Record<string, unknown>
|
|
137
|
-
next.resolve({ url, headers: req.headers, body })
|
|
138
|
-
|
|
139
|
-
if (!url.pathname.endsWith(next.path)) {
|
|
140
|
-
return new Response("not found", { status: 404 })
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return next.response
|
|
144
|
-
},
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
beforeEach(() => {
|
|
149
|
-
state.queue.length = 0
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
afterAll(() => {
|
|
153
|
-
state.server?.stop()
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
function createChatStream(text: string) {
|
|
157
|
-
const payload =
|
|
158
|
-
[
|
|
159
|
-
`data: ${JSON.stringify({
|
|
160
|
-
id: "chatcmpl-1",
|
|
161
|
-
object: "chat.completion.chunk",
|
|
162
|
-
choices: [{ delta: { role: "assistant" } }],
|
|
163
|
-
})}`,
|
|
164
|
-
`data: ${JSON.stringify({
|
|
165
|
-
id: "chatcmpl-1",
|
|
166
|
-
object: "chat.completion.chunk",
|
|
167
|
-
choices: [{ delta: { content: text } }],
|
|
168
|
-
})}`,
|
|
169
|
-
`data: ${JSON.stringify({
|
|
170
|
-
id: "chatcmpl-1",
|
|
171
|
-
object: "chat.completion.chunk",
|
|
172
|
-
choices: [{ delta: {}, finish_reason: "stop" }],
|
|
173
|
-
})}`,
|
|
174
|
-
"data: [DONE]",
|
|
175
|
-
].join("\n\n") + "\n\n"
|
|
176
|
-
|
|
177
|
-
const encoder = new TextEncoder()
|
|
178
|
-
return new ReadableStream<Uint8Array>({
|
|
179
|
-
start(controller) {
|
|
180
|
-
controller.enqueue(encoder.encode(payload))
|
|
181
|
-
controller.close()
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async function loadFixture(providerID: string, modelID: string) {
|
|
187
|
-
const fixturePath = path.join(import.meta.dir, "../tool/fixtures/models-api.json")
|
|
188
|
-
const data = (await Bun.file(fixturePath).json()) as Record<string, ModelsDev.Provider>
|
|
189
|
-
const provider = data[providerID]
|
|
190
|
-
if (!provider) {
|
|
191
|
-
throw new Error(`Missing provider in fixture: ${providerID}`)
|
|
192
|
-
}
|
|
193
|
-
const model = provider.models[modelID]
|
|
194
|
-
if (!model) {
|
|
195
|
-
throw new Error(`Missing model in fixture: ${modelID}`)
|
|
196
|
-
}
|
|
197
|
-
return { provider, model }
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function createEventStream(chunks: unknown[], includeDone = false) {
|
|
201
|
-
const lines = chunks.map((chunk) => `data: ${typeof chunk === "string" ? chunk : JSON.stringify(chunk)}`)
|
|
202
|
-
if (includeDone) {
|
|
203
|
-
lines.push("data: [DONE]")
|
|
204
|
-
}
|
|
205
|
-
const payload = lines.join("\n\n") + "\n\n"
|
|
206
|
-
const encoder = new TextEncoder()
|
|
207
|
-
return new ReadableStream<Uint8Array>({
|
|
208
|
-
start(controller) {
|
|
209
|
-
controller.enqueue(encoder.encode(payload))
|
|
210
|
-
controller.close()
|
|
211
|
-
},
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function createEventResponse(chunks: unknown[], includeDone = false) {
|
|
216
|
-
return new Response(createEventStream(chunks, includeDone), {
|
|
217
|
-
status: 200,
|
|
218
|
-
headers: { "Content-Type": "text/event-stream" },
|
|
219
|
-
})
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
describe("session.llm.stream", () => {
|
|
223
|
-
test("sends temperature, tokens, and reasoning options for openai-compatible models", async () => {
|
|
224
|
-
const server = state.server
|
|
225
|
-
if (!server) {
|
|
226
|
-
throw new Error("Server not initialized")
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const providerID = "alibaba"
|
|
230
|
-
const modelID = "qwen-plus"
|
|
231
|
-
const fixture = await loadFixture(providerID, modelID)
|
|
232
|
-
const provider = fixture.provider
|
|
233
|
-
const model = fixture.model
|
|
234
|
-
|
|
235
|
-
const request = waitRequest(
|
|
236
|
-
"/chat/completions",
|
|
237
|
-
new Response(createChatStream("Hello"), {
|
|
238
|
-
status: 200,
|
|
239
|
-
headers: { "Content-Type": "text/event-stream" },
|
|
240
|
-
}),
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
await using tmp = await tmpdir({
|
|
244
|
-
init: async (dir) => {
|
|
245
|
-
await Bun.write(
|
|
246
|
-
path.join(dir, "opencode.json"),
|
|
247
|
-
JSON.stringify({
|
|
248
|
-
$schema: "https://opencode.ai/config.json",
|
|
249
|
-
enabled_providers: [providerID],
|
|
250
|
-
provider: {
|
|
251
|
-
[providerID]: {
|
|
252
|
-
options: {
|
|
253
|
-
apiKey: "test-key",
|
|
254
|
-
baseURL: `${server.url.origin}/v1`,
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
}),
|
|
259
|
-
)
|
|
260
|
-
},
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
await Instance.provide({
|
|
264
|
-
directory: tmp.path,
|
|
265
|
-
fn: async () => {
|
|
266
|
-
const resolved = await Provider.getModel(providerID, model.id)
|
|
267
|
-
const sessionID = "session-test-1"
|
|
268
|
-
const agent = {
|
|
269
|
-
name: "test",
|
|
270
|
-
mode: "primary",
|
|
271
|
-
options: {},
|
|
272
|
-
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
273
|
-
temperature: 0.4,
|
|
274
|
-
topP: 0.8,
|
|
275
|
-
} satisfies Agent.Info
|
|
276
|
-
|
|
277
|
-
const user = {
|
|
278
|
-
id: "user-1",
|
|
279
|
-
sessionID,
|
|
280
|
-
role: "user",
|
|
281
|
-
time: { created: Date.now() },
|
|
282
|
-
agent: agent.name,
|
|
283
|
-
model: { providerID, modelID: resolved.id },
|
|
284
|
-
variant: "high",
|
|
285
|
-
} satisfies MessageV2.User
|
|
286
|
-
|
|
287
|
-
const stream = await LLM.stream({
|
|
288
|
-
user,
|
|
289
|
-
sessionID,
|
|
290
|
-
model: resolved,
|
|
291
|
-
agent,
|
|
292
|
-
system: ["You are a helpful assistant."],
|
|
293
|
-
abort: new AbortController().signal,
|
|
294
|
-
messages: [{ role: "user", content: "Hello" }],
|
|
295
|
-
tools: {},
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
for await (const _ of stream.fullStream) {
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const capture = await request
|
|
302
|
-
const body = capture.body
|
|
303
|
-
const headers = capture.headers
|
|
304
|
-
const url = capture.url
|
|
305
|
-
|
|
306
|
-
expect(url.pathname.startsWith("/v1/")).toBe(true)
|
|
307
|
-
expect(url.pathname.endsWith("/chat/completions")).toBe(true)
|
|
308
|
-
expect(headers.get("Authorization")).toBe("Bearer test-key")
|
|
309
|
-
expect(headers.get("User-Agent") ?? "").toMatch(/^opencode\//)
|
|
310
|
-
|
|
311
|
-
expect(body.model).toBe(resolved.api.id)
|
|
312
|
-
expect(body.temperature).toBe(0.4)
|
|
313
|
-
expect(body.top_p).toBe(0.8)
|
|
314
|
-
expect(body.stream).toBe(true)
|
|
315
|
-
|
|
316
|
-
const maxTokens = (body.max_tokens as number | undefined) ?? (body.max_output_tokens as number | undefined)
|
|
317
|
-
const expectedMaxTokens = ProviderTransform.maxOutputTokens(resolved)
|
|
318
|
-
expect(maxTokens).toBe(expectedMaxTokens)
|
|
319
|
-
|
|
320
|
-
const reasoning = (body.reasoningEffort as string | undefined) ?? (body.reasoning_effort as string | undefined)
|
|
321
|
-
expect(reasoning).toBe("high")
|
|
322
|
-
},
|
|
323
|
-
})
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
test("sends responses API payload for OpenAI models", async () => {
|
|
327
|
-
const server = state.server
|
|
328
|
-
if (!server) {
|
|
329
|
-
throw new Error("Server not initialized")
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const source = await loadFixture("openai", "gpt-5.2")
|
|
333
|
-
const model = source.model
|
|
334
|
-
|
|
335
|
-
const responseChunks = [
|
|
336
|
-
{
|
|
337
|
-
type: "response.created",
|
|
338
|
-
response: {
|
|
339
|
-
id: "resp-1",
|
|
340
|
-
created_at: Math.floor(Date.now() / 1000),
|
|
341
|
-
model: model.id,
|
|
342
|
-
service_tier: null,
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
type: "response.output_text.delta",
|
|
347
|
-
item_id: "item-1",
|
|
348
|
-
delta: "Hello",
|
|
349
|
-
logprobs: null,
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
type: "response.completed",
|
|
353
|
-
response: {
|
|
354
|
-
incomplete_details: null,
|
|
355
|
-
usage: {
|
|
356
|
-
input_tokens: 1,
|
|
357
|
-
input_tokens_details: null,
|
|
358
|
-
output_tokens: 1,
|
|
359
|
-
output_tokens_details: null,
|
|
360
|
-
},
|
|
361
|
-
service_tier: null,
|
|
362
|
-
},
|
|
363
|
-
},
|
|
364
|
-
]
|
|
365
|
-
const request = waitRequest("/responses", createEventResponse(responseChunks, true))
|
|
366
|
-
|
|
367
|
-
await using tmp = await tmpdir({
|
|
368
|
-
init: async (dir) => {
|
|
369
|
-
await Bun.write(
|
|
370
|
-
path.join(dir, "opencode.json"),
|
|
371
|
-
JSON.stringify({
|
|
372
|
-
$schema: "https://opencode.ai/config.json",
|
|
373
|
-
enabled_providers: ["openai"],
|
|
374
|
-
provider: {
|
|
375
|
-
openai: {
|
|
376
|
-
name: "OpenAI",
|
|
377
|
-
env: ["OPENAI_API_KEY"],
|
|
378
|
-
npm: "@ai-sdk/openai",
|
|
379
|
-
api: "https://api.openai.com/v1",
|
|
380
|
-
models: {
|
|
381
|
-
[model.id]: model,
|
|
382
|
-
},
|
|
383
|
-
options: {
|
|
384
|
-
apiKey: "test-openai-key",
|
|
385
|
-
baseURL: `${server.url.origin}/v1`,
|
|
386
|
-
},
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
}),
|
|
390
|
-
)
|
|
391
|
-
},
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
await Instance.provide({
|
|
395
|
-
directory: tmp.path,
|
|
396
|
-
fn: async () => {
|
|
397
|
-
const resolved = await Provider.getModel("openai", model.id)
|
|
398
|
-
const sessionID = "session-test-2"
|
|
399
|
-
const agent = {
|
|
400
|
-
name: "test",
|
|
401
|
-
mode: "primary",
|
|
402
|
-
options: {},
|
|
403
|
-
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
404
|
-
temperature: 0.2,
|
|
405
|
-
} satisfies Agent.Info
|
|
406
|
-
|
|
407
|
-
const user = {
|
|
408
|
-
id: "user-2",
|
|
409
|
-
sessionID,
|
|
410
|
-
role: "user",
|
|
411
|
-
time: { created: Date.now() },
|
|
412
|
-
agent: agent.name,
|
|
413
|
-
model: { providerID: "openai", modelID: resolved.id },
|
|
414
|
-
variant: "high",
|
|
415
|
-
} satisfies MessageV2.User
|
|
416
|
-
|
|
417
|
-
const stream = await LLM.stream({
|
|
418
|
-
user,
|
|
419
|
-
sessionID,
|
|
420
|
-
model: resolved,
|
|
421
|
-
agent,
|
|
422
|
-
system: ["You are a helpful assistant."],
|
|
423
|
-
abort: new AbortController().signal,
|
|
424
|
-
messages: [{ role: "user", content: "Hello" }],
|
|
425
|
-
tools: {},
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
for await (const _ of stream.fullStream) {
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const capture = await request
|
|
432
|
-
const body = capture.body
|
|
433
|
-
|
|
434
|
-
expect(capture.url.pathname.endsWith("/responses")).toBe(true)
|
|
435
|
-
expect(body.model).toBe(resolved.api.id)
|
|
436
|
-
expect(body.stream).toBe(true)
|
|
437
|
-
expect((body.reasoning as { effort?: string } | undefined)?.effort).toBe("high")
|
|
438
|
-
|
|
439
|
-
const maxTokens = body.max_output_tokens as number | undefined
|
|
440
|
-
const expectedMaxTokens = ProviderTransform.maxOutputTokens(resolved)
|
|
441
|
-
expect(maxTokens).toBe(expectedMaxTokens)
|
|
442
|
-
},
|
|
443
|
-
})
|
|
444
|
-
})
|
|
445
|
-
|
|
446
|
-
test("sends messages API payload for Anthropic models", async () => {
|
|
447
|
-
const server = state.server
|
|
448
|
-
if (!server) {
|
|
449
|
-
throw new Error("Server not initialized")
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const providerID = "anthropic"
|
|
453
|
-
const modelID = "claude-3-5-sonnet-20241022"
|
|
454
|
-
const fixture = await loadFixture(providerID, modelID)
|
|
455
|
-
const provider = fixture.provider
|
|
456
|
-
const model = fixture.model
|
|
457
|
-
|
|
458
|
-
const chunks = [
|
|
459
|
-
{
|
|
460
|
-
type: "message_start",
|
|
461
|
-
message: {
|
|
462
|
-
id: "msg-1",
|
|
463
|
-
model: model.id,
|
|
464
|
-
usage: {
|
|
465
|
-
input_tokens: 3,
|
|
466
|
-
cache_creation_input_tokens: null,
|
|
467
|
-
cache_read_input_tokens: null,
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
type: "content_block_start",
|
|
473
|
-
index: 0,
|
|
474
|
-
content_block: { type: "text", text: "" },
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
type: "content_block_delta",
|
|
478
|
-
index: 0,
|
|
479
|
-
delta: { type: "text_delta", text: "Hello" },
|
|
480
|
-
},
|
|
481
|
-
{ type: "content_block_stop", index: 0 },
|
|
482
|
-
{
|
|
483
|
-
type: "message_delta",
|
|
484
|
-
delta: { stop_reason: "end_turn", stop_sequence: null, container: null },
|
|
485
|
-
usage: {
|
|
486
|
-
input_tokens: 3,
|
|
487
|
-
output_tokens: 2,
|
|
488
|
-
cache_creation_input_tokens: null,
|
|
489
|
-
cache_read_input_tokens: null,
|
|
490
|
-
},
|
|
491
|
-
},
|
|
492
|
-
{ type: "message_stop" },
|
|
493
|
-
]
|
|
494
|
-
const request = waitRequest("/messages", createEventResponse(chunks))
|
|
495
|
-
|
|
496
|
-
await using tmp = await tmpdir({
|
|
497
|
-
init: async (dir) => {
|
|
498
|
-
await Bun.write(
|
|
499
|
-
path.join(dir, "opencode.json"),
|
|
500
|
-
JSON.stringify({
|
|
501
|
-
$schema: "https://opencode.ai/config.json",
|
|
502
|
-
enabled_providers: [providerID],
|
|
503
|
-
provider: {
|
|
504
|
-
[providerID]: {
|
|
505
|
-
options: {
|
|
506
|
-
apiKey: "test-anthropic-key",
|
|
507
|
-
baseURL: `${server.url.origin}/v1`,
|
|
508
|
-
},
|
|
509
|
-
},
|
|
510
|
-
},
|
|
511
|
-
}),
|
|
512
|
-
)
|
|
513
|
-
},
|
|
514
|
-
})
|
|
515
|
-
|
|
516
|
-
await Instance.provide({
|
|
517
|
-
directory: tmp.path,
|
|
518
|
-
fn: async () => {
|
|
519
|
-
const resolved = await Provider.getModel(providerID, model.id)
|
|
520
|
-
const sessionID = "session-test-3"
|
|
521
|
-
const agent = {
|
|
522
|
-
name: "test",
|
|
523
|
-
mode: "primary",
|
|
524
|
-
options: {},
|
|
525
|
-
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
526
|
-
temperature: 0.4,
|
|
527
|
-
topP: 0.9,
|
|
528
|
-
} satisfies Agent.Info
|
|
529
|
-
|
|
530
|
-
const user = {
|
|
531
|
-
id: "user-3",
|
|
532
|
-
sessionID,
|
|
533
|
-
role: "user",
|
|
534
|
-
time: { created: Date.now() },
|
|
535
|
-
agent: agent.name,
|
|
536
|
-
model: { providerID, modelID: resolved.id },
|
|
537
|
-
} satisfies MessageV2.User
|
|
538
|
-
|
|
539
|
-
const stream = await LLM.stream({
|
|
540
|
-
user,
|
|
541
|
-
sessionID,
|
|
542
|
-
model: resolved,
|
|
543
|
-
agent,
|
|
544
|
-
system: ["You are a helpful assistant."],
|
|
545
|
-
abort: new AbortController().signal,
|
|
546
|
-
messages: [{ role: "user", content: "Hello" }],
|
|
547
|
-
tools: {},
|
|
548
|
-
})
|
|
549
|
-
|
|
550
|
-
for await (const _ of stream.fullStream) {
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const capture = await request
|
|
554
|
-
const body = capture.body
|
|
555
|
-
|
|
556
|
-
expect(capture.url.pathname.endsWith("/messages")).toBe(true)
|
|
557
|
-
expect(body.model).toBe(resolved.api.id)
|
|
558
|
-
expect(body.max_tokens).toBe(ProviderTransform.maxOutputTokens(resolved))
|
|
559
|
-
expect(body.temperature).toBe(0.4)
|
|
560
|
-
expect(body.top_p).toBe(0.9)
|
|
561
|
-
},
|
|
562
|
-
})
|
|
563
|
-
})
|
|
564
|
-
|
|
565
|
-
test("sends Google API payload for Gemini models", async () => {
|
|
566
|
-
const server = state.server
|
|
567
|
-
if (!server) {
|
|
568
|
-
throw new Error("Server not initialized")
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
const providerID = "google"
|
|
572
|
-
const modelID = "gemini-2.5-flash"
|
|
573
|
-
const fixture = await loadFixture(providerID, modelID)
|
|
574
|
-
const provider = fixture.provider
|
|
575
|
-
const model = fixture.model
|
|
576
|
-
const pathSuffix = `/v1beta/models/${model.id}:streamGenerateContent`
|
|
577
|
-
|
|
578
|
-
const chunks = [
|
|
579
|
-
{
|
|
580
|
-
candidates: [
|
|
581
|
-
{
|
|
582
|
-
content: {
|
|
583
|
-
parts: [{ text: "Hello" }],
|
|
584
|
-
},
|
|
585
|
-
finishReason: "STOP",
|
|
586
|
-
},
|
|
587
|
-
],
|
|
588
|
-
usageMetadata: {
|
|
589
|
-
promptTokenCount: 1,
|
|
590
|
-
candidatesTokenCount: 1,
|
|
591
|
-
totalTokenCount: 2,
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
]
|
|
595
|
-
const request = waitRequest(pathSuffix, createEventResponse(chunks))
|
|
596
|
-
|
|
597
|
-
await using tmp = await tmpdir({
|
|
598
|
-
init: async (dir) => {
|
|
599
|
-
await Bun.write(
|
|
600
|
-
path.join(dir, "opencode.json"),
|
|
601
|
-
JSON.stringify({
|
|
602
|
-
$schema: "https://opencode.ai/config.json",
|
|
603
|
-
enabled_providers: [providerID],
|
|
604
|
-
provider: {
|
|
605
|
-
[providerID]: {
|
|
606
|
-
options: {
|
|
607
|
-
apiKey: "test-google-key",
|
|
608
|
-
baseURL: `${server.url.origin}/v1beta`,
|
|
609
|
-
},
|
|
610
|
-
},
|
|
611
|
-
},
|
|
612
|
-
}),
|
|
613
|
-
)
|
|
614
|
-
},
|
|
615
|
-
})
|
|
616
|
-
|
|
617
|
-
await Instance.provide({
|
|
618
|
-
directory: tmp.path,
|
|
619
|
-
fn: async () => {
|
|
620
|
-
const resolved = await Provider.getModel(providerID, model.id)
|
|
621
|
-
const sessionID = "session-test-4"
|
|
622
|
-
const agent = {
|
|
623
|
-
name: "test",
|
|
624
|
-
mode: "primary",
|
|
625
|
-
options: {},
|
|
626
|
-
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
627
|
-
temperature: 0.3,
|
|
628
|
-
topP: 0.8,
|
|
629
|
-
} satisfies Agent.Info
|
|
630
|
-
|
|
631
|
-
const user = {
|
|
632
|
-
id: "user-4",
|
|
633
|
-
sessionID,
|
|
634
|
-
role: "user",
|
|
635
|
-
time: { created: Date.now() },
|
|
636
|
-
agent: agent.name,
|
|
637
|
-
model: { providerID, modelID: resolved.id },
|
|
638
|
-
} satisfies MessageV2.User
|
|
639
|
-
|
|
640
|
-
const stream = await LLM.stream({
|
|
641
|
-
user,
|
|
642
|
-
sessionID,
|
|
643
|
-
model: resolved,
|
|
644
|
-
agent,
|
|
645
|
-
system: ["You are a helpful assistant."],
|
|
646
|
-
abort: new AbortController().signal,
|
|
647
|
-
messages: [{ role: "user", content: "Hello" }],
|
|
648
|
-
tools: {},
|
|
649
|
-
})
|
|
650
|
-
|
|
651
|
-
for await (const _ of stream.fullStream) {
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
const capture = await request
|
|
655
|
-
const body = capture.body
|
|
656
|
-
const config = body.generationConfig as
|
|
657
|
-
| { temperature?: number; topP?: number; maxOutputTokens?: number }
|
|
658
|
-
| undefined
|
|
659
|
-
|
|
660
|
-
expect(capture.url.pathname).toBe(pathSuffix)
|
|
661
|
-
expect(config?.temperature).toBe(0.3)
|
|
662
|
-
expect(config?.topP).toBe(0.8)
|
|
663
|
-
expect(config?.maxOutputTokens).toBe(ProviderTransform.maxOutputTokens(resolved))
|
|
664
|
-
},
|
|
665
|
-
})
|
|
666
|
-
})
|
|
667
|
-
})
|