anymous 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/bin/anymous.cjs +45 -0
- package/package.json +155 -0
- package/src/account/account.ts +473 -0
- package/src/account/repo.ts +171 -0
- package/src/account/schema.ts +99 -0
- package/src/account/url.ts +8 -0
- package/src/acp/agent.ts +95 -0
- package/src/acp/config-option.ts +203 -0
- package/src/acp/content.ts +269 -0
- package/src/acp/directory.ts +212 -0
- package/src/acp/error.ts +97 -0
- package/src/acp/event.ts +342 -0
- package/src/acp/permission.ts +254 -0
- package/src/acp/profile.ts +42 -0
- package/src/acp/service.ts +1097 -0
- package/src/acp/session.ts +232 -0
- package/src/acp/tool.ts +364 -0
- package/src/acp/usage.ts +239 -0
- package/src/agent/agent.ts +581 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +9 -0
- package/src/agent/prompt/debug-tools.txt +41 -0
- package/src/agent/prompt/exe-extractor.txt +37 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/memory-dump.txt +34 -0
- package/src/agent/prompt/reverser-automator.txt +24 -0
- package/src/agent/prompt/reverser-binary.txt +25 -0
- package/src/agent/prompt/reverser-dynamic.txt +29 -0
- package/src/agent/prompt/reverser-source.txt +22 -0
- package/src/agent/prompt/reverser-static.txt +28 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +44 -0
- package/src/agent/subagent-permissions.ts +27 -0
- package/src/audio.d.ts +14 -0
- package/src/auth/index.ts +97 -0
- package/src/background/job.ts +37 -0
- package/src/bus/global.ts +22 -0
- package/src/cli/bootstrap.ts +11 -0
- package/src/cli/cmd/account.ts +264 -0
- package/src/cli/cmd/acp.ts +73 -0
- package/src/cli/cmd/agent.ts +259 -0
- package/src/cli/cmd/attach.ts +148 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/db.ts +62 -0
- package/src/cli/cmd/debug/agent.handler.ts +193 -0
- package/src/cli/cmd/debug/agent.ts +27 -0
- package/src/cli/cmd/debug/config.ts +14 -0
- package/src/cli/cmd/debug/file.ts +73 -0
- package/src/cli/cmd/debug/index.ts +87 -0
- package/src/cli/cmd/debug/lsp.ts +50 -0
- package/src/cli/cmd/debug/ripgrep.ts +79 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +50 -0
- package/src/cli/cmd/debug/startup.ts +11 -0
- package/src/cli/cmd/debug/v2.ts +42 -0
- package/src/cli/cmd/export.ts +292 -0
- package/src/cli/cmd/generate.ts +54 -0
- package/src/cli/cmd/github.handler.ts +1593 -0
- package/src/cli/cmd/github.shared.ts +30 -0
- package/src/cli/cmd/github.ts +42 -0
- package/src/cli/cmd/import.ts +230 -0
- package/src/cli/cmd/mcp.ts +840 -0
- package/src/cli/cmd/models.ts +66 -0
- package/src/cli/cmd/plug.ts +230 -0
- package/src/cli/cmd/pr.ts +115 -0
- package/src/cli/cmd/prompt-display.ts +1 -0
- package/src/cli/cmd/providers.ts +534 -0
- package/src/cli/cmd/run/demo.ts +1274 -0
- package/src/cli/cmd/run/entry.body.ts +205 -0
- package/src/cli/cmd/run/footer.command.tsx +1070 -0
- package/src/cli/cmd/run/footer.menu.tsx +351 -0
- package/src/cli/cmd/run/footer.permission.tsx +472 -0
- package/src/cli/cmd/run/footer.prompt.tsx +1315 -0
- package/src/cli/cmd/run/footer.question.tsx +573 -0
- package/src/cli/cmd/run/footer.subagent.tsx +175 -0
- package/src/cli/cmd/run/footer.ts +1129 -0
- package/src/cli/cmd/run/footer.view.tsx +945 -0
- package/src/cli/cmd/run/footer.width.ts +27 -0
- package/src/cli/cmd/run/permission.shared.ts +256 -0
- package/src/cli/cmd/run/prompt.editor.ts +157 -0
- package/src/cli/cmd/run/prompt.shared.ts +153 -0
- package/src/cli/cmd/run/question.shared.ts +340 -0
- package/src/cli/cmd/run/runtime.boot.ts +202 -0
- package/src/cli/cmd/run/runtime.lifecycle.ts +406 -0
- package/src/cli/cmd/run/runtime.queue.ts +349 -0
- package/src/cli/cmd/run/runtime.shared.ts +17 -0
- package/src/cli/cmd/run/runtime.stdin.ts +37 -0
- package/src/cli/cmd/run/runtime.ts +814 -0
- package/src/cli/cmd/run/scrollback.shared.ts +92 -0
- package/src/cli/cmd/run/scrollback.surface.ts +431 -0
- package/src/cli/cmd/run/scrollback.writer.tsx +352 -0
- package/src/cli/cmd/run/session-data.ts +1113 -0
- package/src/cli/cmd/run/session-replay.ts +374 -0
- package/src/cli/cmd/run/session.shared.ts +196 -0
- package/src/cli/cmd/run/splash.ts +280 -0
- package/src/cli/cmd/run/stream.transport.ts +1462 -0
- package/src/cli/cmd/run/stream.ts +175 -0
- package/src/cli/cmd/run/subagent-data.ts +876 -0
- package/src/cli/cmd/run/theme.ts +690 -0
- package/src/cli/cmd/run/tool.ts +1486 -0
- package/src/cli/cmd/run/trace.ts +94 -0
- package/src/cli/cmd/run/turn-summary.ts +47 -0
- package/src/cli/cmd/run/types.ts +350 -0
- package/src/cli/cmd/run/variant.shared.ts +216 -0
- package/src/cli/cmd/run.ts +1011 -0
- package/src/cli/cmd/serve.ts +24 -0
- package/src/cli/cmd/session.ts +147 -0
- package/src/cli/cmd/stats.ts +393 -0
- package/src/cli/cmd/tui.ts +309 -0
- package/src/cli/cmd/uninstall.ts +353 -0
- package/src/cli/cmd/upgrade.ts +74 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/effect/prompt.ts +37 -0
- package/src/cli/effect-cmd.ts +96 -0
- package/src/cli/error.ts +130 -0
- package/src/cli/heap.ts +45 -0
- package/src/cli/logo.ts +1 -0
- package/src/cli/network.ts +80 -0
- package/src/cli/tui/layer.ts +8 -0
- package/src/cli/tui/validate-session.ts +29 -0
- package/src/cli/tui/worker.ts +80 -0
- package/src/cli/ui.ts +132 -0
- package/src/cli/upgrade.ts +53 -0
- package/src/command/index.ts +177 -0
- package/src/command/template/initialize.txt +66 -0
- package/src/command/template/review.txt +101 -0
- package/src/config/agent.ts +59 -0
- package/src/config/command.ts +39 -0
- package/src/config/config.ts +681 -0
- package/src/config/entry-name.ts +19 -0
- package/src/config/managed.ts +69 -0
- package/src/config/markdown.ts +36 -0
- package/src/config/parse.ts +79 -0
- package/src/config/paths.ts +45 -0
- package/src/config/plugin.ts +79 -0
- package/src/config/tui-cwd.ts +5 -0
- package/src/config/tui-host-attention.ts +21 -0
- package/src/config/tui-migrate.ts +132 -0
- package/src/config/tui.ts +276 -0
- package/src/config/variable.ts +91 -0
- package/src/control-plane/adapters/index.ts +41 -0
- package/src/control-plane/adapters/worktree.ts +96 -0
- package/src/control-plane/dev/README.md +19 -0
- package/src/control-plane/dev/debug-workspace-plugin.ts +73 -0
- package/src/control-plane/types.ts +59 -0
- package/src/control-plane/util.ts +39 -0
- package/src/control-plane/workspace-adapter-runtime.ts +51 -0
- package/src/control-plane/workspace-context.ts +26 -0
- package/src/control-plane/workspace.ts +964 -0
- package/src/effect/app-node-builder-v1.ts +12 -0
- package/src/effect/app-runtime.ts +135 -0
- package/src/effect/bootstrap-runtime.ts +19 -0
- package/src/effect/bridge.ts +84 -0
- package/src/effect/config-service.ts +67 -0
- package/src/effect/instance-ref.ts +11 -0
- package/src/effect/instance-registry.ts +12 -0
- package/src/effect/instance-state.ts +69 -0
- package/src/effect/promise.ts +17 -0
- package/src/effect/run-service.ts +47 -0
- package/src/effect/runner.ts +217 -0
- package/src/effect/runtime-flags.ts +78 -0
- package/src/env/index.ts +41 -0
- package/src/event-manifest.ts +3 -0
- package/src/event-v2-bridge.ts +71 -0
- package/src/format/formatter.ts +404 -0
- package/src/format/index.ts +203 -0
- package/src/git/index.ts +348 -0
- package/src/id/id.ts +80 -0
- package/src/ide/index.ts +54 -0
- package/src/image/image.ts +172 -0
- package/src/index.ts +142 -0
- package/src/installation/index.ts +336 -0
- package/src/lsp/client.ts +650 -0
- package/src/lsp/diagnostic.ts +29 -0
- package/src/lsp/language.ts +121 -0
- package/src/lsp/launch.ts +21 -0
- package/src/lsp/lsp.ts +507 -0
- package/src/lsp/server.ts +1983 -0
- package/src/markdown.d.ts +4 -0
- package/src/mcp/auth.ts +163 -0
- package/src/mcp/browser.ts +37 -0
- package/src/mcp/catalog.ts +170 -0
- package/src/mcp/index.ts +1004 -0
- package/src/mcp/oauth-callback.ts +194 -0
- package/src/mcp/oauth-provider.ts +259 -0
- package/src/node.ts +4 -0
- package/src/patch/index.ts +686 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/evaluate.ts +1 -0
- package/src/permission/index.ts +229 -0
- package/src/plugin/azure.ts +26 -0
- package/src/plugin/cloudflare.ts +76 -0
- package/src/plugin/digitalocean.ts +325 -0
- package/src/plugin/github-copilot/copilot.ts +414 -0
- package/src/plugin/github-copilot/models.ts +258 -0
- package/src/plugin/index.ts +314 -0
- package/src/plugin/install.ts +439 -0
- package/src/plugin/loader.ts +237 -0
- package/src/plugin/meta.ts +188 -0
- package/src/plugin/openai/README.md +31 -0
- package/src/plugin/openai/codex.ts +565 -0
- package/src/plugin/openai/ws-pool.ts +270 -0
- package/src/plugin/openai/ws.ts +381 -0
- package/src/plugin/pty-environment.ts +24 -0
- package/src/plugin/shared.ts +323 -0
- package/src/plugin/snowflake-cortex.ts +507 -0
- package/src/plugin/tui/internal.ts +10 -0
- package/src/plugin/tui/runtime.ts +1131 -0
- package/src/plugin/xai.ts +626 -0
- package/src/project/bootstrap-service.ts +9 -0
- package/src/project/bootstrap.ts +58 -0
- package/src/project/instance-context.ts +24 -0
- package/src/project/instance-runtime.ts +16 -0
- package/src/project/instance-store.ts +213 -0
- package/src/project/project.ts +483 -0
- package/src/project/vcs.ts +423 -0
- package/src/provider/auth.ts +229 -0
- package/src/provider/error.ts +188 -0
- package/src/provider/model-status.ts +8 -0
- package/src/provider/provider.ts +2006 -0
- package/src/provider/transform.ts +1832 -0
- package/src/question/index.ts +161 -0
- package/src/question/schema.ts +4 -0
- package/src/server/auth.ts +48 -0
- package/src/server/event.ts +10 -0
- package/src/server/global-lifecycle.ts +28 -0
- package/src/server/init-projectors.ts +3 -0
- package/src/server/mdns.ts +47 -0
- package/src/server/projectors.ts +1 -0
- package/src/server/proxy-util.ts +48 -0
- package/src/server/routes/instance/httpapi/AGENTS.md +39 -0
- package/src/server/routes/instance/httpapi/api.ts +97 -0
- package/src/server/routes/instance/httpapi/errors.ts +193 -0
- package/src/server/routes/instance/httpapi/groups/config.ts +65 -0
- package/src/server/routes/instance/httpapi/groups/control-plane.ts +35 -0
- package/src/server/routes/instance/httpapi/groups/control.ts +76 -0
- package/src/server/routes/instance/httpapi/groups/event.ts +29 -0
- package/src/server/routes/instance/httpapi/groups/experimental.ts +275 -0
- package/src/server/routes/instance/httpapi/groups/file.ts +185 -0
- package/src/server/routes/instance/httpapi/groups/global.ts +136 -0
- package/src/server/routes/instance/httpapi/groups/instance.ts +206 -0
- package/src/server/routes/instance/httpapi/groups/mcp.ts +156 -0
- package/src/server/routes/instance/httpapi/groups/metadata.ts +18 -0
- package/src/server/routes/instance/httpapi/groups/permission.ts +61 -0
- package/src/server/routes/instance/httpapi/groups/project-copy.ts +32 -0
- package/src/server/routes/instance/httpapi/groups/project.ts +93 -0
- package/src/server/routes/instance/httpapi/groups/provider.ts +101 -0
- package/src/server/routes/instance/httpapi/groups/pty.ts +172 -0
- package/src/server/routes/instance/httpapi/groups/query.ts +12 -0
- package/src/server/routes/instance/httpapi/groups/question.ts +74 -0
- package/src/server/routes/instance/httpapi/groups/session.ts +462 -0
- package/src/server/routes/instance/httpapi/groups/sync.ts +113 -0
- package/src/server/routes/instance/httpapi/groups/tui.ts +208 -0
- package/src/server/routes/instance/httpapi/groups/workspace.ts +141 -0
- package/src/server/routes/instance/httpapi/handlers/config.ts +34 -0
- package/src/server/routes/instance/httpapi/handlers/control-plane.ts +37 -0
- package/src/server/routes/instance/httpapi/handlers/control.ts +43 -0
- package/src/server/routes/instance/httpapi/handlers/event.ts +99 -0
- package/src/server/routes/instance/httpapi/handlers/experimental.ts +193 -0
- package/src/server/routes/instance/httpapi/handlers/file.ts +139 -0
- package/src/server/routes/instance/httpapi/handlers/global.ts +156 -0
- package/src/server/routes/instance/httpapi/handlers/instance.ts +110 -0
- package/src/server/routes/instance/httpapi/handlers/mcp.ts +111 -0
- package/src/server/routes/instance/httpapi/handlers/permission.ts +41 -0
- package/src/server/routes/instance/httpapi/handlers/project-copy.ts +83 -0
- package/src/server/routes/instance/httpapi/handlers/project.ts +63 -0
- package/src/server/routes/instance/httpapi/handlers/provider.ts +113 -0
- package/src/server/routes/instance/httpapi/handlers/pty.ts +273 -0
- package/src/server/routes/instance/httpapi/handlers/question.ts +54 -0
- package/src/server/routes/instance/httpapi/handlers/session-errors.ts +21 -0
- package/src/server/routes/instance/httpapi/handlers/session.ts +442 -0
- package/src/server/routes/instance/httpapi/handlers/sync.ts +89 -0
- package/src/server/routes/instance/httpapi/handlers/tui.ts +131 -0
- package/src/server/routes/instance/httpapi/handlers/workspace.ts +102 -0
- package/src/server/routes/instance/httpapi/lifecycle.ts +54 -0
- package/src/server/routes/instance/httpapi/middleware/authorization.ts +150 -0
- package/src/server/routes/instance/httpapi/middleware/compression.ts +64 -0
- package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +29 -0
- package/src/server/routes/instance/httpapi/middleware/error.ts +43 -0
- package/src/server/routes/instance/httpapi/middleware/fence.ts +25 -0
- package/src/server/routes/instance/httpapi/middleware/instance-context.ts +43 -0
- package/src/server/routes/instance/httpapi/middleware/proxy.ts +108 -0
- package/src/server/routes/instance/httpapi/middleware/schema-error.ts +41 -0
- package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +250 -0
- package/src/server/routes/instance/httpapi/public.ts +537 -0
- package/src/server/routes/instance/httpapi/server.ts +325 -0
- package/src/server/routes/instance/httpapi/websocket-tracker.ts +60 -0
- package/src/server/server.ts +226 -0
- package/src/server/shared/fence.ts +60 -0
- package/src/server/shared/pty-ticket.ts +15 -0
- package/src/server/shared/public-ui.ts +12 -0
- package/src/server/shared/tui-control.ts +28 -0
- package/src/server/shared/ui.ts +108 -0
- package/src/server/shared/workspace-routing.ts +38 -0
- package/src/server/tui-event.ts +1 -0
- package/src/session/compaction.ts +562 -0
- package/src/session/instruction.ts +237 -0
- package/src/session/llm/AGENTS.md +90 -0
- package/src/session/llm/ai-sdk.ts +288 -0
- package/src/session/llm/native-request.ts +196 -0
- package/src/session/llm/native-runtime.ts +195 -0
- package/src/session/llm/request.ts +226 -0
- package/src/session/llm.ts +404 -0
- package/src/session/message-error.ts +14 -0
- package/src/session/message-v2.ts +734 -0
- package/src/session/message.ts +148 -0
- package/src/session/overflow.ts +34 -0
- package/src/session/processor.ts +718 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/default.txt +95 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/gpt.txt +107 -0
- package/src/session/prompt/kimi.txt +95 -0
- package/src/session/prompt/meta.txt +65 -0
- package/src/session/prompt/plan-mode.txt +70 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/trinity.txt +97 -0
- package/src/session/prompt.ts +1631 -0
- package/src/session/reminders.ts +92 -0
- package/src/session/retry.ts +201 -0
- package/src/session/revert.ts +146 -0
- package/src/session/run-state.ts +151 -0
- package/src/session/schema.ts +26 -0
- package/src/session/session.ts +1018 -0
- package/src/session/status.ts +56 -0
- package/src/session/summary.ts +160 -0
- package/src/session/system.ts +145 -0
- package/src/session/todo.ts +74 -0
- package/src/session/tools.ts +590 -0
- package/src/share/session.ts +58 -0
- package/src/share/share-next.ts +371 -0
- package/src/skill/discovery.ts +140 -0
- package/src/skill/index.ts +354 -0
- package/src/snapshot/index.ts +807 -0
- package/src/sql.d.ts +4 -0
- package/src/storage/schema.ts +5 -0
- package/src/storage/storage.ts +327 -0
- package/src/sync/README.md +179 -0
- package/src/sync/schema.ts +11 -0
- package/src/temporary.ts +31 -0
- package/src/tool/apply_patch.ts +313 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/code-mode.ts +310 -0
- package/src/tool/edit.ts +737 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +49 -0
- package/src/tool/glob.ts +76 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +115 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +21 -0
- package/src/tool/json-schema.ts +164 -0
- package/src/tool/lsp.ts +113 -0
- package/src/tool/lsp.txt +24 -0
- package/src/tool/mcp-websearch.ts +96 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +79 -0
- package/src/tool/question.ts +44 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +386 -0
- package/src/tool/read.txt +14 -0
- package/src/tool/registry.ts +450 -0
- package/src/tool/schema.ts +14 -0
- package/src/tool/shell/id.ts +19 -0
- package/src/tool/shell/prompt.ts +293 -0
- package/src/tool/shell/shell.txt +21 -0
- package/src/tool/shell.ts +645 -0
- package/src/tool/skill.ts +70 -0
- package/src/tool/skill.txt +5 -0
- package/src/tool/task.ts +360 -0
- package/src/tool/task.txt +19 -0
- package/src/tool/todo.ts +46 -0
- package/src/tool/todowrite.txt +44 -0
- package/src/tool/tool.ts +183 -0
- package/src/tool/truncate.ts +156 -0
- package/src/tool/truncation-dir.ts +4 -0
- package/src/tool/webfetch.ts +192 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +143 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +104 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +17 -0
- package/src/util/bom.ts +27 -0
- package/src/util/data-url.ts +9 -0
- package/src/util/defer.ts +10 -0
- package/src/util/effect-http-client.ts +11 -0
- package/src/util/error.ts +1 -0
- package/src/util/filesystem.ts +251 -0
- package/src/util/html.ts +8 -0
- package/src/util/iife.ts +3 -0
- package/src/util/lazy.ts +20 -0
- package/src/util/local-context.ts +25 -0
- package/src/util/locale.ts +2 -0
- package/src/util/media.ts +26 -0
- package/src/util/process.ts +177 -0
- package/src/util/proxy-env.ts +72 -0
- package/src/util/queue.ts +32 -0
- package/src/util/record.ts +1 -0
- package/src/util/repository.ts +232 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +13 -0
- package/src/util/token.ts +1 -0
- package/src/util/wildcard.ts +59 -0
- package/src/worktree/index.ts +623 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { SessionID } from "./schema"
|
|
3
|
+
|
|
4
|
+
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
|
5
|
+
import { MessageError } from "./message-error"
|
|
6
|
+
import { AuthError, OutputLengthError } from "./message-error"
|
|
7
|
+
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
8
|
+
import { ModelV2 } from "@opencode-ai/core/model"
|
|
9
|
+
export { AuthError, OutputLengthError } from "./message-error"
|
|
10
|
+
|
|
11
|
+
export const ToolCall = Schema.Struct({
|
|
12
|
+
state: Schema.Literal("call"),
|
|
13
|
+
step: Schema.optional(NonNegativeInt),
|
|
14
|
+
toolCallId: Schema.String,
|
|
15
|
+
toolName: Schema.String,
|
|
16
|
+
args: Schema.Unknown,
|
|
17
|
+
}).annotate({ identifier: "ToolCall" })
|
|
18
|
+
export type ToolCall = Schema.Schema.Type<typeof ToolCall>
|
|
19
|
+
|
|
20
|
+
export const ToolPartialCall = Schema.Struct({
|
|
21
|
+
state: Schema.Literal("partial-call"),
|
|
22
|
+
step: Schema.optional(NonNegativeInt),
|
|
23
|
+
toolCallId: Schema.String,
|
|
24
|
+
toolName: Schema.String,
|
|
25
|
+
args: Schema.Unknown,
|
|
26
|
+
}).annotate({ identifier: "ToolPartialCall" })
|
|
27
|
+
export type ToolPartialCall = Schema.Schema.Type<typeof ToolPartialCall>
|
|
28
|
+
|
|
29
|
+
export const ToolResult = Schema.Struct({
|
|
30
|
+
state: Schema.Literal("result"),
|
|
31
|
+
step: Schema.optional(NonNegativeInt),
|
|
32
|
+
toolCallId: Schema.String,
|
|
33
|
+
toolName: Schema.String,
|
|
34
|
+
args: Schema.Unknown,
|
|
35
|
+
result: Schema.String,
|
|
36
|
+
}).annotate({ identifier: "ToolResult" })
|
|
37
|
+
export type ToolResult = Schema.Schema.Type<typeof ToolResult>
|
|
38
|
+
|
|
39
|
+
export const ToolInvocation = Schema.Union([ToolCall, ToolPartialCall, ToolResult]).annotate({
|
|
40
|
+
identifier: "ToolInvocation",
|
|
41
|
+
discriminator: "state",
|
|
42
|
+
})
|
|
43
|
+
export type ToolInvocation = Schema.Schema.Type<typeof ToolInvocation>
|
|
44
|
+
|
|
45
|
+
export const TextPart = Schema.Struct({
|
|
46
|
+
type: Schema.Literal("text"),
|
|
47
|
+
text: Schema.String,
|
|
48
|
+
}).annotate({ identifier: "TextPart" })
|
|
49
|
+
export type TextPart = Schema.Schema.Type<typeof TextPart>
|
|
50
|
+
|
|
51
|
+
export const ReasoningPart = Schema.Struct({
|
|
52
|
+
type: Schema.Literal("reasoning"),
|
|
53
|
+
text: Schema.String,
|
|
54
|
+
providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
55
|
+
}).annotate({ identifier: "ReasoningPart" })
|
|
56
|
+
export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>
|
|
57
|
+
|
|
58
|
+
export const ToolInvocationPart = Schema.Struct({
|
|
59
|
+
type: Schema.Literal("tool-invocation"),
|
|
60
|
+
toolInvocation: ToolInvocation,
|
|
61
|
+
}).annotate({ identifier: "ToolInvocationPart" })
|
|
62
|
+
export type ToolInvocationPart = Schema.Schema.Type<typeof ToolInvocationPart>
|
|
63
|
+
|
|
64
|
+
export const SourceUrlPart = Schema.Struct({
|
|
65
|
+
type: Schema.Literal("source-url"),
|
|
66
|
+
sourceId: Schema.String,
|
|
67
|
+
url: Schema.String,
|
|
68
|
+
title: Schema.optional(Schema.String),
|
|
69
|
+
providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
70
|
+
}).annotate({ identifier: "SourceUrlPart" })
|
|
71
|
+
export type SourceUrlPart = Schema.Schema.Type<typeof SourceUrlPart>
|
|
72
|
+
|
|
73
|
+
export const FilePart = Schema.Struct({
|
|
74
|
+
type: Schema.Literal("file"),
|
|
75
|
+
mediaType: Schema.String,
|
|
76
|
+
filename: Schema.optional(Schema.String),
|
|
77
|
+
url: Schema.String,
|
|
78
|
+
}).annotate({ identifier: "FilePart" })
|
|
79
|
+
export type FilePart = Schema.Schema.Type<typeof FilePart>
|
|
80
|
+
|
|
81
|
+
export const StepStartPart = Schema.Struct({
|
|
82
|
+
type: Schema.Literal("step-start"),
|
|
83
|
+
}).annotate({ identifier: "StepStartPart" })
|
|
84
|
+
export type StepStartPart = Schema.Schema.Type<typeof StepStartPart>
|
|
85
|
+
|
|
86
|
+
export const MessagePart = Schema.Union([
|
|
87
|
+
TextPart,
|
|
88
|
+
ReasoningPart,
|
|
89
|
+
ToolInvocationPart,
|
|
90
|
+
SourceUrlPart,
|
|
91
|
+
FilePart,
|
|
92
|
+
StepStartPart,
|
|
93
|
+
]).annotate({ identifier: "MessagePart", discriminator: "type" })
|
|
94
|
+
export type MessagePart = Schema.Schema.Type<typeof MessagePart>
|
|
95
|
+
|
|
96
|
+
export const Info = Schema.Struct({
|
|
97
|
+
id: Schema.String,
|
|
98
|
+
role: Schema.Literals(["user", "assistant"]),
|
|
99
|
+
parts: Schema.Array(MessagePart),
|
|
100
|
+
metadata: Schema.Struct({
|
|
101
|
+
time: Schema.Struct({
|
|
102
|
+
created: NonNegativeInt,
|
|
103
|
+
completed: Schema.optional(NonNegativeInt),
|
|
104
|
+
}),
|
|
105
|
+
error: Schema.optional(MessageError.SharedSchema),
|
|
106
|
+
sessionID: SessionID,
|
|
107
|
+
tool: Schema.Record(
|
|
108
|
+
Schema.String,
|
|
109
|
+
Schema.StructWithRest(
|
|
110
|
+
Schema.Struct({
|
|
111
|
+
title: Schema.String,
|
|
112
|
+
snapshot: Schema.optional(Schema.String),
|
|
113
|
+
time: Schema.Struct({
|
|
114
|
+
start: NonNegativeInt,
|
|
115
|
+
end: NonNegativeInt,
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
[Schema.Record(Schema.String, Schema.Unknown)],
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
assistant: Schema.optional(
|
|
122
|
+
Schema.Struct({
|
|
123
|
+
system: Schema.Array(Schema.String),
|
|
124
|
+
modelID: ModelV2.ID,
|
|
125
|
+
providerID: ProviderV2.ID,
|
|
126
|
+
path: Schema.Struct({
|
|
127
|
+
cwd: Schema.String,
|
|
128
|
+
root: Schema.String,
|
|
129
|
+
}),
|
|
130
|
+
cost: Schema.Finite,
|
|
131
|
+
summary: Schema.optional(Schema.Boolean),
|
|
132
|
+
tokens: Schema.Struct({
|
|
133
|
+
input: Schema.Finite,
|
|
134
|
+
output: Schema.Finite,
|
|
135
|
+
reasoning: Schema.Finite,
|
|
136
|
+
cache: Schema.Struct({
|
|
137
|
+
read: Schema.Finite,
|
|
138
|
+
write: Schema.Finite,
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
}),
|
|
142
|
+
),
|
|
143
|
+
snapshot: Schema.optional(Schema.String),
|
|
144
|
+
}).annotate({ identifier: "MessageMetadata" }),
|
|
145
|
+
}).annotate({ identifier: "Message" })
|
|
146
|
+
export type Info = Schema.Schema.Type<typeof Info>
|
|
147
|
+
|
|
148
|
+
export * as Message from "./message"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Config } from "@/config/config"
|
|
2
|
+
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
|
3
|
+
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
|
4
|
+
import type { Provider } from "@/provider/provider"
|
|
5
|
+
import { ProviderTransform } from "@/provider/transform"
|
|
6
|
+
import type { MessageV2 } from "./message-v2"
|
|
7
|
+
|
|
8
|
+
const COMPACTION_BUFFER = 20_000
|
|
9
|
+
|
|
10
|
+
export function usable(input: { cfg: ConfigV1.Info; model: Provider.Model; outputTokenMax?: number }) {
|
|
11
|
+
const context = input.model.limit.context
|
|
12
|
+
if (context === 0) return 0
|
|
13
|
+
|
|
14
|
+
const reserved =
|
|
15
|
+
input.cfg.compaction?.reserved ??
|
|
16
|
+
Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
|
|
17
|
+
return input.model.limit.input
|
|
18
|
+
? Math.max(0, input.model.limit.input - reserved)
|
|
19
|
+
: Math.max(0, context - ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isOverflow(input: {
|
|
23
|
+
cfg: ConfigV1.Info
|
|
24
|
+
tokens: SessionV1.Assistant["tokens"]
|
|
25
|
+
model: Provider.Model
|
|
26
|
+
outputTokenMax?: number
|
|
27
|
+
}) {
|
|
28
|
+
if (input.cfg.compaction?.auto === false) return false
|
|
29
|
+
if (input.model.limit.context === 0) return false
|
|
30
|
+
|
|
31
|
+
const count =
|
|
32
|
+
input.tokens.total || input.tokens.input + input.tokens.output + input.tokens.cache.read + input.tokens.cache.write
|
|
33
|
+
return count >= usable(input)
|
|
34
|
+
}
|