@neurocode-ai/core 1.18.8
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/bin/neurocode +199 -0
- package/bunfig.toml +2 -0
- package/drizzle.config.ts +10 -0
- package/package.json +131 -0
- package/schema.json +2071 -0
- package/script/fix-node-pty.ts +28 -0
- package/script/migration.ts +196 -0
- package/src/account/sql.ts +39 -0
- package/src/account.ts +101 -0
- package/src/agent.ts +111 -0
- package/src/aisdk.ts +235 -0
- package/src/background-job.ts +365 -0
- package/src/catalog.ts +301 -0
- package/src/command.ts +64 -0
- package/src/config/agent.ts +25 -0
- package/src/config/attachments.ts +15 -0
- package/src/config/command.ts +12 -0
- package/src/config/compaction.ts +15 -0
- package/src/config/experimental.ts +18 -0
- package/src/config/formatter.ts +12 -0
- package/src/config/lsp.ts +18 -0
- package/src/config/markdown.ts +36 -0
- package/src/config/mcp.ts +48 -0
- package/src/config/plugin/agent.ts +179 -0
- package/src/config/plugin/command.ts +83 -0
- package/src/config/plugin/external.ts +91 -0
- package/src/config/plugin/provider.ts +113 -0
- package/src/config/plugin/reference.ts +70 -0
- package/src/config/plugin/skill.ts +50 -0
- package/src/config/plugin.ts +13 -0
- package/src/config/provider.ts +71 -0
- package/src/config/reference.ts +22 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/watcher.ts +7 -0
- package/src/config.ts +227 -0
- package/src/control-plane/move-session.ts +148 -0
- package/src/control-plane/workspace.sql.ts +20 -0
- package/src/credential/sql.ts +14 -0
- package/src/credential.ts +138 -0
- package/src/cross-spawn-spawner.ts +507 -0
- package/src/data-migration.sql.ts +6 -0
- package/src/database/database.ts +57 -0
- package/src/database/migration/20260127222353_familiar_lady_ursula.ts +107 -0
- package/src/database/migration/20260211171708_add_project_commands.ts +11 -0
- package/src/database/migration/20260213144116_wakeful_the_professor.ts +23 -0
- package/src/database/migration/20260225215848_workspace.ts +19 -0
- package/src/database/migration/20260227213759_add_session_workspace_id.ts +12 -0
- package/src/database/migration/20260228203230_blue_harpoon.ts +30 -0
- package/src/database/migration/20260303231226_add_workspace_fields.ts +15 -0
- package/src/database/migration/20260309230000_move_org_to_state.ts +15 -0
- package/src/database/migration/20260312043431_session_message_cursor.ts +16 -0
- package/src/database/migration/20260323234822_events.ts +26 -0
- package/src/database/migration/20260410174513_workspace-name.ts +29 -0
- package/src/database/migration/20260413175956_chief_energizer.ts +24 -0
- package/src/database/migration/20260423070820_add_icon_url_override.ts +14 -0
- package/src/database/migration/20260427172553_slow_nightmare.ts +30 -0
- package/src/database/migration/20260428004200_add_session_path.ts +11 -0
- package/src/database/migration/20260501142318_next_venus.ts +12 -0
- package/src/database/migration/20260504145000_add_sync_owner.ts +11 -0
- package/src/database/migration/20260507164347_add_workspace_time.ts +11 -0
- package/src/database/migration/20260510033149_session_usage.ts +56 -0
- package/src/database/migration/20260511000411_data_migration_state.ts +16 -0
- package/src/database/migration/20260511173437_session-metadata.ts +16 -0
- package/src/database/migration/20260601010001_normalize_storage_paths.ts +22 -0
- package/src/database/migration/20260601202201_amazing_prowler.ts +11 -0
- package/src/database/migration/20260602002951_lowly_union_jack.ts +24 -0
- package/src/database/migration/20260602182828_add_project_directories.ts +20 -0
- package/src/database/migration/20260603001617_session_message_projection_indexes.ts +19 -0
- package/src/database/migration/20260603040000_session_message_projection_order.ts +19 -0
- package/src/database/migration/20260603141458_session_input_inbox.ts +25 -0
- package/src/database/migration/20260603160727_jittery_ezekiel_stane.ts +20 -0
- package/src/database/migration/20260604172448_event_sourced_session_input.ts +47 -0
- package/src/database/migration/20260605003541_add_session_context_snapshot.ts +21 -0
- package/src/database/migration/20260605042240_add_context_epoch_agent.ts +11 -0
- package/src/database/migration/20260611035744_credential.ts +25 -0
- package/src/database/migration/20260611192811_lush_chimera.ts +25 -0
- package/src/database/migration/20260612174303_project_dir_strategy.ts +29 -0
- package/src/database/migration/20260622142730_simplify_session_context_epoch.ts +13 -0
- package/src/database/migration/20260622170816_reset_v2_session_state.ts +17 -0
- package/src/database/migration/20260622202450_simplify_session_input.ts +17 -0
- package/src/database/migration.gen.ts +44 -0
- package/src/database/migration.ts +81 -0
- package/src/database/path.ts +91 -0
- package/src/database/schema.gen.ts +274 -0
- package/src/database/schema.sql.ts +10 -0
- package/src/database/sqlite.bun.ts +183 -0
- package/src/database/sqlite.node.ts +178 -0
- package/src/database/sqlite.ts +8 -0
- package/src/effect/app-node-builder.ts +23 -0
- package/src/effect/app-node-platform.ts +18 -0
- package/src/effect/app-node.ts +14 -0
- package/src/effect/dfdf +1 -0
- package/src/effect/keyed-mutex.ts +45 -0
- package/src/effect/layer-node.ts +333 -0
- package/src/effect/memo-map.ts +3 -0
- package/src/effect/runtime.ts +21 -0
- package/src/effect/service-use.ts +43 -0
- package/src/event/sql.ts +25 -0
- package/src/event.ts +638 -0
- package/src/file-mutation.ts +207 -0
- package/src/file.ts +6 -0
- package/src/filesystem/fff.bun.ts +140 -0
- package/src/filesystem/fff.node.ts +138 -0
- package/src/filesystem/ignore.ts +67 -0
- package/src/filesystem/protected.ts +53 -0
- package/src/filesystem/search.ts +239 -0
- package/src/filesystem/watcher.ts +140 -0
- package/src/filesystem.ts +118 -0
- package/src/flag/flag.ts +78 -0
- package/src/fs-util.ts +274 -0
- package/src/git.ts +987 -0
- package/src/github-copilot/README.md +5 -0
- package/src/github-copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
- package/src/github-copilot/chat/get-response-metadata.ts +15 -0
- package/src/github-copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/src/github-copilot/chat/openai-compatible-api-types.ts +64 -0
- package/src/github-copilot/chat/openai-compatible-chat-language-model.ts +815 -0
- package/src/github-copilot/chat/openai-compatible-chat-options.ts +28 -0
- package/src/github-copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
- package/src/github-copilot/chat/openai-compatible-prepare-tools.ts +83 -0
- package/src/github-copilot/copilot-provider.ts +100 -0
- package/src/github-copilot/openai-compatible-error.ts +27 -0
- package/src/github-copilot/responses/convert-to-openai-responses-input.ts +335 -0
- package/src/github-copilot/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/github-copilot/responses/openai-config.ts +18 -0
- package/src/github-copilot/responses/openai-error.ts +22 -0
- package/src/github-copilot/responses/openai-responses-api-types.ts +214 -0
- package/src/github-copilot/responses/openai-responses-language-model.ts +1770 -0
- package/src/github-copilot/responses/openai-responses-prepare-tools.ts +173 -0
- package/src/github-copilot/responses/openai-responses-settings.ts +1 -0
- package/src/github-copilot/responses/tool/code-interpreter.ts +87 -0
- package/src/github-copilot/responses/tool/file-search.ts +127 -0
- package/src/github-copilot/responses/tool/image-generation.ts +114 -0
- package/src/github-copilot/responses/tool/local-shell.ts +64 -0
- package/src/github-copilot/responses/tool/web-search-preview.ts +103 -0
- package/src/github-copilot/responses/tool/web-search.ts +102 -0
- package/src/global.ts +87 -0
- package/src/id/id.ts +47 -0
- package/src/image/photon.ts +94 -0
- package/src/image.ts +81 -0
- package/src/installation/version.ts +8 -0
- package/src/instruction-context.ts +101 -0
- package/src/integration/connection.ts +12 -0
- package/src/integration.ts +520 -0
- package/src/location-mutation.ts +162 -0
- package/src/location-service-map.ts +18 -0
- package/src/location-services.ts +115 -0
- package/src/location.ts +39 -0
- package/src/markdown.d.ts +4 -0
- package/src/model.ts +41 -0
- package/src/models-dev.ts +260 -0
- package/src/npm-config.ts +40 -0
- package/src/npm.ts +269 -0
- package/src/oauth/page.ts +276 -0
- package/src/observability/logging.ts +71 -0
- package/src/observability/otlp.ts +79 -0
- package/src/observability/shared.ts +1 -0
- package/src/observability.ts +24 -0
- package/src/patch.ts +197 -0
- package/src/permission/saved.ts +79 -0
- package/src/permission/sql.ts +20 -0
- package/src/permission.ts +310 -0
- package/src/plugin/agent.ts +206 -0
- package/src/plugin/command/initialize.txt +65 -0
- package/src/plugin/command/review.txt +100 -0
- package/src/plugin/command.ts +25 -0
- package/src/plugin/host.ts +219 -0
- package/src/plugin/internal.ts +153 -0
- package/src/plugin/layer-map.example.ts +94 -0
- package/src/plugin/models-dev.ts +183 -0
- package/src/plugin/promise.ts +93 -0
- package/src/plugin/provider/alibaba.ts +15 -0
- package/src/plugin/provider/amazon-bedrock.ts +126 -0
- package/src/plugin/provider/anthropic.ts +27 -0
- package/src/plugin/provider/azure.ts +82 -0
- package/src/plugin/provider/cerebras.ts +26 -0
- package/src/plugin/provider/cloudflare-ai-gateway.ts +81 -0
- package/src/plugin/provider/cloudflare-workers-ai.ts +81 -0
- package/src/plugin/provider/cohere.ts +15 -0
- package/src/plugin/provider/deepinfra.ts +15 -0
- package/src/plugin/provider/dynamic.ts +31 -0
- package/src/plugin/provider/gateway.ts +15 -0
- package/src/plugin/provider/github-copilot.ts +52 -0
- package/src/plugin/provider/gitlab.ts +65 -0
- package/src/plugin/provider/google-vertex.ts +173 -0
- package/src/plugin/provider/google.ts +15 -0
- package/src/plugin/provider/groq.ts +15 -0
- package/src/plugin/provider/kilo.ts +21 -0
- package/src/plugin/provider/llmgateway.ts +26 -0
- package/src/plugin/provider/mistral.ts +15 -0
- package/src/plugin/provider/nvidia.ts +22 -0
- package/src/plugin/provider/openai-compatible.ts +17 -0
- package/src/plugin/provider/openai.ts +292 -0
- package/src/plugin/provider/opencode.ts +311 -0
- package/src/plugin/provider/openrouter.ts +36 -0
- package/src/plugin/provider/perplexity.ts +15 -0
- package/src/plugin/provider/sap-ai-core.ts +46 -0
- package/src/plugin/provider/snowflake-cortex.ts +89 -0
- package/src/plugin/provider/togetherai.ts +15 -0
- package/src/plugin/provider/venice.ts +15 -0
- package/src/plugin/provider/vercel.ts +27 -0
- package/src/plugin/provider/xai.ts +22 -0
- package/src/plugin/provider/zenmux.ts +21 -0
- package/src/plugin/provider.ts +71 -0
- package/src/plugin/skill/customize-neurocode.md +452 -0
- package/src/plugin/skill.ts +31 -0
- package/src/plugin/variant.ts +39 -0
- package/src/plugin.ts +167 -0
- package/src/policy.ts +49 -0
- package/src/process.ts +261 -0
- package/src/project/copy-strategies.ts +35 -0
- package/src/project/copy.ts +292 -0
- package/src/project/directories.ts +158 -0
- package/src/project/schema.ts +16 -0
- package/src/project/sql.ts +35 -0
- package/src/project.ts +136 -0
- package/src/provider.ts +25 -0
- package/src/pty/protocol.ts +37 -0
- package/src/pty/pty.bun.ts +26 -0
- package/src/pty/pty.node.ts +29 -0
- package/src/pty/pty.ts +25 -0
- package/src/pty/schema.ts +1 -0
- package/src/pty/ticket.ts +56 -0
- package/src/pty.ts +318 -0
- package/src/public-event-manifest.ts +7 -0
- package/src/question.ts +153 -0
- package/src/reference/guidance.ts +69 -0
- package/src/reference.ts +125 -0
- package/src/repository-cache.ts +259 -0
- package/src/repository.ts +214 -0
- package/src/ripgrep/binary.ts +132 -0
- package/src/ripgrep.ts +281 -0
- package/src/schema.ts +79 -0
- package/src/session/compaction.ts +241 -0
- package/src/session/context-epoch.ts +174 -0
- package/src/session/error.ts +24 -0
- package/src/session/event.ts +2 -0
- package/src/session/execution/local.ts +46 -0
- package/src/session/execution.ts +34 -0
- package/src/session/history.ts +101 -0
- package/src/session/info.ts +50 -0
- package/src/session/input.ts +288 -0
- package/src/session/message-updater.ts +397 -0
- package/src/session/message.ts +2 -0
- package/src/session/projector.ts +458 -0
- package/src/session/prompt.ts +1 -0
- package/src/session/revert.ts +121 -0
- package/src/session/run-coordinator.ts +104 -0
- package/src/session/runner/index.ts +28 -0
- package/src/session/runner/llm.ts +432 -0
- package/src/session/runner/max-steps.ts +16 -0
- package/src/session/runner/model.ts +218 -0
- package/src/session/runner/publish-llm-event.ts +423 -0
- package/src/session/runner/to-llm-message.ts +171 -0
- package/src/session/schema.ts +9 -0
- package/src/session/sql.ts +176 -0
- package/src/session/store.ts +63 -0
- package/src/session/todo.ts +78 -0
- package/src/session.ts +486 -0
- package/src/share/sql.ts +13 -0
- package/src/shell.ts +226 -0
- package/src/skill/discovery.ts +213 -0
- package/src/skill/guidance.ts +76 -0
- package/src/skill.ts +132 -0
- package/src/snapshot.ts +266 -0
- package/src/state.ts +128 -0
- package/src/system-context/builtins.ts +50 -0
- package/src/system-context/index.ts +320 -0
- package/src/system-context/registry.ts +49 -0
- package/src/tool/AGENTS.md +59 -0
- package/src/tool/application-tools.ts +57 -0
- package/src/tool/apply-patch.ts +219 -0
- package/src/tool/bash.ts +207 -0
- package/src/tool/builtins.ts +48 -0
- package/src/tool/edit.ts +223 -0
- package/src/tool/glob.ts +105 -0
- package/src/tool/grep.ts +137 -0
- package/src/tool/http-body.ts +30 -0
- package/src/tool/question.ts +94 -0
- package/src/tool/read-filesystem.ts +366 -0
- package/src/tool/read.ts +117 -0
- package/src/tool/registry.ts +147 -0
- package/src/tool/skill.ts +109 -0
- package/src/tool/todowrite.ts +62 -0
- package/src/tool/tool.ts +162 -0
- package/src/tool/tools.ts +13 -0
- package/src/tool/webfetch.ts +218 -0
- package/src/tool/websearch.ts +260 -0
- package/src/tool/write.ts +101 -0
- package/src/tool-output-store.ts +211 -0
- package/src/util/array.ts +10 -0
- package/src/util/binary.ts +41 -0
- package/src/util/effect-flock.ts +284 -0
- package/src/util/encode.ts +51 -0
- package/src/util/error.ts +70 -0
- package/src/util/flock.ts +358 -0
- package/src/util/glob.ts +34 -0
- package/src/util/hash.ts +11 -0
- package/src/util/identifier.ts +1 -0
- package/src/util/iife.ts +3 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/module.ts +10 -0
- package/src/util/path.ts +37 -0
- package/src/util/retry.ts +42 -0
- package/src/util/slug.ts +74 -0
- package/src/util/token.ts +5 -0
- package/src/util/which.ts +14 -0
- package/src/util/wildcard.ts +14 -0
- package/src/v1/config/agent.ts +89 -0
- package/src/v1/config/attachment.ts +25 -0
- package/src/v1/config/command.ts +13 -0
- package/src/v1/config/config.ts +192 -0
- package/src/v1/config/console-state.ts +16 -0
- package/src/v1/config/error.ts +39 -0
- package/src/v1/config/formatter.ts +13 -0
- package/src/v1/config/layout.ts +6 -0
- package/src/v1/config/lsp.ts +80 -0
- package/src/v1/config/mcp.ts +63 -0
- package/src/v1/config/migrate.ts +254 -0
- package/src/v1/config/permission.ts +50 -0
- package/src/v1/config/plugin.ts +9 -0
- package/src/v1/config/provider-options.ts +227 -0
- package/src/v1/config/provider.ts +121 -0
- package/src/v1/config/server.ts +19 -0
- package/src/v1/config/skills.ts +13 -0
- package/src/v1/permission.ts +33 -0
- package/src/v1/session.ts +68 -0
- package/src/v2-schema.ts +3 -0
- package/src/workspace.ts +6 -0
- package/sst-env.d.ts +10 -0
- package/test/agent.test.ts +131 -0
- package/test/application-tools.test.ts +287 -0
- package/test/background-job.test.ts +106 -0
- package/test/catalog.test.ts +353 -0
- package/test/command.test.ts +56 -0
- package/test/config/agent.test.ts +349 -0
- package/test/config/command.test.ts +83 -0
- package/test/config/config.test.ts +798 -0
- package/test/config/fixtures/plugin/directory-plugin.ts +13 -0
- package/test/config/plugin.test.ts +248 -0
- package/test/config/provider-options.test.ts +224 -0
- package/test/config/provider.test.ts +269 -0
- package/test/config/skill.test.ts +80 -0
- package/test/credential.test.ts +36 -0
- package/test/database-migration.test.ts +644 -0
- package/test/effect/cross-spawn-spawner.test.ts +426 -0
- package/test/effect/keyed-mutex.test.ts +73 -0
- package/test/effect/layer-node/layer-node-types.test.ts +143 -0
- package/test/effect/layer-node/layer-node.test.ts +261 -0
- package/test/effect/layer-node/node-build.test.ts +125 -0
- package/test/effect/observability.test.ts +109 -0
- package/test/event.test.ts +1124 -0
- package/test/file-mutation.test.ts +368 -0
- package/test/filesystem/filesystem.test.ts +387 -0
- package/test/filesystem/ignore.test.ts +10 -0
- package/test/filesystem/search.test.ts +44 -0
- package/test/filesystem/watcher.test.ts +266 -0
- package/test/fixture/effect-flock-worker.ts +60 -0
- package/test/fixture/flock-worker.ts +72 -0
- package/test/fixture/git.ts +49 -0
- package/test/fixture/location.ts +26 -0
- package/test/fixture/tmpdir.ts +25 -0
- package/test/fixtures/recordings/session-runner/openai-chat-streams-text.json +27 -0
- package/test/git.test.ts +164 -0
- package/test/github-copilot/convert-to-copilot-messages.test.ts +523 -0
- package/test/github-copilot/copilot-chat-model.test.ts +592 -0
- package/test/github-copilot/openai-responses-language-model.test.ts +206 -0
- package/test/global.test.ts +16 -0
- package/test/instruction-context.test.ts +323 -0
- package/test/integration.test.ts +349 -0
- package/test/legacy-event-schema.test.ts +16 -0
- package/test/lib/effect.ts +53 -0
- package/test/lib/tool.ts +20 -0
- package/test/location-filesystem.test.ts +69 -0
- package/test/location-layer.test.ts +226 -0
- package/test/location-mutation.test.ts +178 -0
- package/test/location.test.ts +42 -0
- package/test/model.test.ts +23 -0
- package/test/models.test.ts +290 -0
- package/test/move-session.test.ts +235 -0
- package/test/npm-config.test.ts +51 -0
- package/test/npm.test.ts +84 -0
- package/test/oauth-page.test.ts +15 -0
- package/test/patch.test.ts +68 -0
- package/test/permission.test.ts +315 -0
- package/test/plugin/command.test.ts +47 -0
- package/test/plugin/fixture.ts +52 -0
- package/test/plugin/fixtures/config-effect-plugin.ts +15 -0
- package/test/plugin/fixtures/config-promise-plugin.ts +13 -0
- package/test/plugin/fixtures/invalid-plugin.ts +1 -0
- package/test/plugin/fixtures/models-dev.json +14 -0
- package/test/plugin/fixtures/provider-factory.ts +9 -0
- package/test/plugin/host.ts +303 -0
- package/test/plugin/models-dev.test.ts +170 -0
- package/test/plugin/promise.test.ts +67 -0
- package/test/plugin/provider-alibaba.test.ts +92 -0
- package/test/plugin/provider-amazon-bedrock.test.ts +622 -0
- package/test/plugin/provider-anthropic.test.ts +94 -0
- package/test/plugin/provider-azure-cognitive-services.test.ts +199 -0
- package/test/plugin/provider-azure.test.ts +293 -0
- package/test/plugin/provider-cerebras.test.ts +136 -0
- package/test/plugin/provider-cloudflare-ai-gateway.test.ts +426 -0
- package/test/plugin/provider-cloudflare-workers-ai.test.ts +279 -0
- package/test/plugin/provider-cohere.test.ts +123 -0
- package/test/plugin/provider-deepinfra.test.ts +159 -0
- package/test/plugin/provider-dynamic.test.ts +184 -0
- package/test/plugin/provider-gateway.test.ts +115 -0
- package/test/plugin/provider-github-copilot.test.ts +278 -0
- package/test/plugin/provider-gitlab.test.ts +308 -0
- package/test/plugin/provider-google-vertex-anthropic.test.ts +264 -0
- package/test/plugin/provider-google-vertex.test.ts +387 -0
- package/test/plugin/provider-google.test.ts +80 -0
- package/test/plugin/provider-groq.test.ts +121 -0
- package/test/plugin/provider-kilo.test.ts +99 -0
- package/test/plugin/provider-llmgateway.test.ts +80 -0
- package/test/plugin/provider-mistral.test.ts +129 -0
- package/test/plugin/provider-nvidia.test.ts +97 -0
- package/test/plugin/provider-openai-compatible.test.ts +107 -0
- package/test/plugin/provider-openai.test.ts +176 -0
- package/test/plugin/provider-opencode.test.ts +423 -0
- package/test/plugin/provider-openrouter.test.ts +113 -0
- package/test/plugin/provider-perplexity.test.ts +122 -0
- package/test/plugin/provider-sap-ai-core.test.ts +159 -0
- package/test/plugin/provider-snowflake-cortex.test.ts +261 -0
- package/test/plugin/provider-togetherai.test.ts +129 -0
- package/test/plugin/provider-venice.test.ts +115 -0
- package/test/plugin/provider-vercel.test.ts +83 -0
- package/test/plugin/provider-xai.test.ts +125 -0
- package/test/plugin/provider-zenmux.test.ts +110 -0
- package/test/plugin/skill.test.ts +25 -0
- package/test/plugin/variant.test.ts +67 -0
- package/test/plugin.test.ts +71 -0
- package/test/policy.test.ts +85 -0
- package/test/preload.ts +5 -0
- package/test/process/process.test.ts +368 -0
- package/test/project-copy.test.ts +400 -0
- package/test/project-directories.test.ts +61 -0
- package/test/project.test.ts +221 -0
- package/test/provider-mistral.test.ts +282 -0
- package/test/provider-xai-responses.test.ts +32 -0
- package/test/pty/info-schema.test.ts +32 -0
- package/test/pty/protocol.test.ts +27 -0
- package/test/pty/pty-session.test.ts +240 -0
- package/test/pty/ticket.test.ts +62 -0
- package/test/question.test.ts +114 -0
- package/test/reference-guidance.test.ts +76 -0
- package/test/reference.test.ts +78 -0
- package/test/repository-cache.test.ts +153 -0
- package/test/repository.test.ts +71 -0
- package/test/ripgrep.test.ts +65 -0
- package/test/session-compaction.test.ts +27 -0
- package/test/session-create.test.ts +425 -0
- package/test/session-history.test.ts +165 -0
- package/test/session-projector.test.ts +533 -0
- package/test/session-prompt.test.ts +584 -0
- package/test/session-run-coordinator.test.ts +418 -0
- package/test/session-runner-message.test.ts +501 -0
- package/test/session-runner-model.test.ts +347 -0
- package/test/session-runner-recorded.test.ts +193 -0
- package/test/session-runner-tool-events.test.ts +136 -0
- package/test/session-runner-tool-registry.test.ts +452 -0
- package/test/session-runner.test.ts +3365 -0
- package/test/session-todo.test.ts +94 -0
- package/test/session-tool-progress.test.ts +158 -0
- package/test/shared-schema.test.ts +206 -0
- package/test/shell.test.ts +108 -0
- package/test/skill/guidance.test.ts +144 -0
- package/test/skill-discovery.test.ts +165 -0
- package/test/skill.test.ts +125 -0
- package/test/snapshot.test.ts +178 -0
- package/test/state.test.ts +115 -0
- package/test/system-context/builtins.test.ts +129 -0
- package/test/system-context/index.test.ts +307 -0
- package/test/system-context/registry.test.ts +114 -0
- package/test/tool-apply-patch.test.ts +436 -0
- package/test/tool-bash.test.ts +437 -0
- package/test/tool-edit.test.ts +434 -0
- package/test/tool-output-store.test.ts +247 -0
- package/test/tool-question.test.ts +162 -0
- package/test/tool-read-filesystem.test.ts +118 -0
- package/test/tool-read.test.ts +674 -0
- package/test/tool-skill.test.ts +149 -0
- package/test/tool-todowrite.test.ts +125 -0
- package/test/tool-webfetch.test.ts +281 -0
- package/test/tool-websearch.test.ts +316 -0
- package/test/tool-write.test.ts +305 -0
- package/test/util/effect-flock.test.ts +392 -0
- package/test/util/flock.test.ts +428 -0
- package/test/util/which.test.ts +100 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { describe, expect } from "bun:test"
|
|
2
|
+
import { LLM } from "@neurocode-ai/llm"
|
|
3
|
+
import { LLMClient } from "@neurocode-ai/llm/route"
|
|
4
|
+
import { DateTime, Effect } from "effect"
|
|
5
|
+
import { Headers } from "effect/unstable/http"
|
|
6
|
+
import { Credential } from "@neurocode-ai/core/credential"
|
|
7
|
+
import { Integration } from "@neurocode-ai/core/integration"
|
|
8
|
+
import { ModelV2 } from "@neurocode-ai/core/model"
|
|
9
|
+
import { ProviderV2 } from "@neurocode-ai/core/provider"
|
|
10
|
+
import { ProjectV2 } from "@neurocode-ai/core/project"
|
|
11
|
+
import { SessionRunnerModel } from "@neurocode-ai/core/session/runner/model"
|
|
12
|
+
import { SessionV2 } from "@neurocode-ai/core/session"
|
|
13
|
+
import { AbsolutePath } from "@neurocode-ai/core/schema"
|
|
14
|
+
import { it } from "./lib/effect"
|
|
15
|
+
|
|
16
|
+
type Api =
|
|
17
|
+
| {
|
|
18
|
+
readonly type: "aisdk"
|
|
19
|
+
readonly package: string
|
|
20
|
+
readonly url?: string
|
|
21
|
+
readonly settings?: Record<string, unknown>
|
|
22
|
+
}
|
|
23
|
+
| { readonly type: "native"; readonly url?: string; readonly settings: Record<string, unknown> }
|
|
24
|
+
|
|
25
|
+
const model = (api: Api, variants: ModelV2.Info["variants"] = []) =>
|
|
26
|
+
ModelV2.Info.make({
|
|
27
|
+
id: ModelV2.ID.make("test-model"),
|
|
28
|
+
providerID: ProviderV2.ID.make("test-provider"),
|
|
29
|
+
name: "Test model",
|
|
30
|
+
api: { id: ModelV2.ID.make("api-test-model"), ...api },
|
|
31
|
+
capabilities: { tools: true, input: ["text"], output: ["text"] },
|
|
32
|
+
request: {
|
|
33
|
+
headers: { "x-test": "header" },
|
|
34
|
+
body: { apiKey: "secret", custom_extension: { enabled: true } },
|
|
35
|
+
},
|
|
36
|
+
variants,
|
|
37
|
+
time: { released: 0 },
|
|
38
|
+
cost: [],
|
|
39
|
+
status: "active",
|
|
40
|
+
enabled: true,
|
|
41
|
+
limit: { context: 100, output: 20 },
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe("SessionRunnerModel", () => {
|
|
45
|
+
it.effect("maps catalog OpenAI AI SDK models into native Responses routes", () =>
|
|
46
|
+
Effect.gen(function* () {
|
|
47
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
48
|
+
model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
expect(resolved).toMatchObject({ id: "api-test-model", provider: "test-provider" })
|
|
52
|
+
expect(resolved.route).toMatchObject({
|
|
53
|
+
id: "openai-responses",
|
|
54
|
+
endpoint: { baseURL: "https://openai.example/v1" },
|
|
55
|
+
defaults: {
|
|
56
|
+
headers: { "x-test": "header" },
|
|
57
|
+
limits: { context: 100, output: 20 },
|
|
58
|
+
http: { body: { custom_extension: { enabled: true } } },
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
it.effect("keeps catalog apiKey credentials out of provider JSON", () =>
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
67
|
+
model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
68
|
+
)
|
|
69
|
+
const prepared = yield* LLMClient.prepare(LLM.request({ model: resolved, prompt: "Hello" }))
|
|
70
|
+
|
|
71
|
+
expect(JSON.stringify(prepared.body)).not.toContain("apiKey")
|
|
72
|
+
expect(JSON.stringify(prepared.body)).not.toContain("secret")
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
it.effect("uses merged API settings for OpenAI-compatible auth and request defaults", () =>
|
|
77
|
+
Effect.gen(function* () {
|
|
78
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
79
|
+
ModelV2.Info.make({
|
|
80
|
+
...model({
|
|
81
|
+
type: "aisdk",
|
|
82
|
+
package: "@ai-sdk/openai-compatible",
|
|
83
|
+
url: "https://compatible.example/v1",
|
|
84
|
+
settings: { apiKey: "settings-secret", compatibility: "strict" },
|
|
85
|
+
}),
|
|
86
|
+
request: { headers: {}, body: {} },
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
89
|
+
const request = LLM.request({ model: resolved, prompt: "Hello" })
|
|
90
|
+
const headers = yield* resolved.route.auth.apply({
|
|
91
|
+
request,
|
|
92
|
+
method: "POST",
|
|
93
|
+
url: "https://compatible.example/v1/chat/completions",
|
|
94
|
+
body: "{}",
|
|
95
|
+
headers: Headers.empty,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
expect(headers.authorization).toBe("Bearer settings-secret")
|
|
99
|
+
expect(resolved.route.defaults.http?.body).toEqual({})
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
it.effect("overlays selected OpenAI Session variant bodies", () =>
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
const catalog = model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }, [
|
|
106
|
+
{
|
|
107
|
+
id: ModelV2.VariantID.make("high"),
|
|
108
|
+
headers: { "x-variant": "high" },
|
|
109
|
+
body: {
|
|
110
|
+
store: false,
|
|
111
|
+
service_tier: "priority",
|
|
112
|
+
temperature: 0.2,
|
|
113
|
+
reasoning: { effort: "high" },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
])
|
|
117
|
+
const session = SessionV2.Info.make({
|
|
118
|
+
id: SessionV2.ID.make("ses_model_variant"),
|
|
119
|
+
projectID: ProjectV2.ID.global,
|
|
120
|
+
title: "test",
|
|
121
|
+
model: {
|
|
122
|
+
id: catalog.id,
|
|
123
|
+
providerID: catalog.providerID,
|
|
124
|
+
variant: ModelV2.VariantID.make("high"),
|
|
125
|
+
},
|
|
126
|
+
cost: 0,
|
|
127
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
128
|
+
time: { created: DateTime.makeUnsafe(0), updated: DateTime.makeUnsafe(0) },
|
|
129
|
+
location: { directory: AbsolutePath.make("/project") },
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const resolved = yield* SessionRunnerModel.resolve(session, catalog)
|
|
133
|
+
|
|
134
|
+
expect(resolved.route.defaults.headers).toMatchObject({ "x-test": "header", "x-variant": "high" })
|
|
135
|
+
expect(resolved.route.defaults.http?.body).toEqual({
|
|
136
|
+
custom_extension: { enabled: true },
|
|
137
|
+
store: false,
|
|
138
|
+
service_tier: "priority",
|
|
139
|
+
temperature: 0.2,
|
|
140
|
+
reasoning: { effort: "high" },
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
it.effect("overlays selected OpenAI-compatible Session variant bodies", () =>
|
|
146
|
+
Effect.gen(function* () {
|
|
147
|
+
const catalog = model(
|
|
148
|
+
{ type: "aisdk", package: "@ai-sdk/openai-compatible", url: "https://compatible.example/v1" },
|
|
149
|
+
[
|
|
150
|
+
{
|
|
151
|
+
id: ModelV2.VariantID.make("high"),
|
|
152
|
+
headers: {},
|
|
153
|
+
body: { store: false, reasoning_effort: "high" },
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
)
|
|
157
|
+
const session = SessionV2.Info.make({
|
|
158
|
+
id: SessionV2.ID.make("ses_compatible_variant"),
|
|
159
|
+
projectID: ProjectV2.ID.global,
|
|
160
|
+
title: "test",
|
|
161
|
+
model: { id: catalog.id, providerID: catalog.providerID, variant: ModelV2.VariantID.make("high") },
|
|
162
|
+
cost: 0,
|
|
163
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
164
|
+
time: { created: DateTime.makeUnsafe(0), updated: DateTime.makeUnsafe(0) },
|
|
165
|
+
location: { directory: AbsolutePath.make("/project") },
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const resolved = yield* SessionRunnerModel.resolve(session, catalog)
|
|
169
|
+
|
|
170
|
+
expect(resolved.route.defaults.http?.body).toEqual({
|
|
171
|
+
custom_extension: { enabled: true },
|
|
172
|
+
store: false,
|
|
173
|
+
reasoning_effort: "high",
|
|
174
|
+
})
|
|
175
|
+
}),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
it.effect("rejects an explicit unavailable Session variant during model resolution", () =>
|
|
179
|
+
Effect.gen(function* () {
|
|
180
|
+
const catalog = model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" })
|
|
181
|
+
const session = SessionV2.Info.make({
|
|
182
|
+
id: SessionV2.ID.make("ses_model_variant_unavailable"),
|
|
183
|
+
projectID: ProjectV2.ID.global,
|
|
184
|
+
title: "test",
|
|
185
|
+
model: {
|
|
186
|
+
id: catalog.id,
|
|
187
|
+
providerID: catalog.providerID,
|
|
188
|
+
variant: ModelV2.VariantID.make("unknown"),
|
|
189
|
+
},
|
|
190
|
+
cost: 0,
|
|
191
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
192
|
+
time: { created: DateTime.makeUnsafe(0), updated: DateTime.makeUnsafe(0) },
|
|
193
|
+
location: { directory: AbsolutePath.make("/project") },
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
const failure = yield* SessionRunnerModel.resolve(session, catalog).pipe(Effect.flip)
|
|
197
|
+
|
|
198
|
+
expect(failure).toMatchObject({
|
|
199
|
+
_tag: "SessionRunnerModel.VariantUnavailableError",
|
|
200
|
+
providerID: "test-provider",
|
|
201
|
+
modelID: "test-model",
|
|
202
|
+
variant: "unknown",
|
|
203
|
+
})
|
|
204
|
+
expect(failure.message).toBe("Variant unavailable for test-provider/test-model: unknown")
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
it.effect("overlays selected Anthropic Session variant bodies", () =>
|
|
209
|
+
Effect.gen(function* () {
|
|
210
|
+
const catalog = model({ type: "aisdk", package: "@ai-sdk/anthropic", url: "https://anthropic.example/v1" }, [
|
|
211
|
+
{
|
|
212
|
+
id: ModelV2.VariantID.make("high"),
|
|
213
|
+
headers: {},
|
|
214
|
+
body: { thinking: { type: "enabled", budget_tokens: 12000 } },
|
|
215
|
+
},
|
|
216
|
+
])
|
|
217
|
+
const session = SessionV2.Info.make({
|
|
218
|
+
id: SessionV2.ID.make("ses_anthropic_variant"),
|
|
219
|
+
projectID: ProjectV2.ID.global,
|
|
220
|
+
title: "test",
|
|
221
|
+
model: { id: catalog.id, providerID: catalog.providerID, variant: ModelV2.VariantID.make("high") },
|
|
222
|
+
cost: 0,
|
|
223
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
224
|
+
time: { created: DateTime.makeUnsafe(0), updated: DateTime.makeUnsafe(0) },
|
|
225
|
+
location: { directory: AbsolutePath.make("/project") },
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const resolved = yield* SessionRunnerModel.resolve(session, catalog)
|
|
229
|
+
|
|
230
|
+
expect(resolved.route.defaults.http?.body).toEqual({
|
|
231
|
+
custom_extension: { enabled: true },
|
|
232
|
+
thinking: { type: "enabled", budget_tokens: 12000 },
|
|
233
|
+
})
|
|
234
|
+
}),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
it.effect("maps catalog Anthropic AI SDK models into native routes", () =>
|
|
238
|
+
Effect.gen(function* () {
|
|
239
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
240
|
+
model({ type: "aisdk", package: "@ai-sdk/anthropic", url: "https://anthropic.example/v1" }),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
expect(resolved.route).toMatchObject({
|
|
244
|
+
id: "anthropic-messages",
|
|
245
|
+
endpoint: { baseURL: "https://anthropic.example/v1" },
|
|
246
|
+
})
|
|
247
|
+
}),
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
it.effect("uses resolved credentials for bearer auth", () =>
|
|
251
|
+
Effect.gen(function* () {
|
|
252
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
253
|
+
ModelV2.Info.make({
|
|
254
|
+
...model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
255
|
+
request: { headers: {}, body: {} },
|
|
256
|
+
}),
|
|
257
|
+
Credential.Key.make({ type: "key", key: "secret" }),
|
|
258
|
+
)
|
|
259
|
+
const request = LLM.request({ model: resolved, prompt: "Hello" })
|
|
260
|
+
const headers = yield* resolved.route.auth.apply({
|
|
261
|
+
request,
|
|
262
|
+
method: "POST",
|
|
263
|
+
url: "https://openai.example/v1/responses",
|
|
264
|
+
body: "{}",
|
|
265
|
+
headers: Headers.empty,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
expect(headers.authorization).toBe("Bearer secret")
|
|
269
|
+
}),
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
it.effect("prefers stored credentials over configured auth", () =>
|
|
273
|
+
Effect.gen(function* () {
|
|
274
|
+
const credential = Credential.Key.make({ type: "key", key: "stored-secret", metadata: { tenant: "work" } })
|
|
275
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
276
|
+
ModelV2.Info.make({
|
|
277
|
+
...model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
278
|
+
request: { headers: {}, body: { apiKey: "configured-secret" } },
|
|
279
|
+
}),
|
|
280
|
+
credential,
|
|
281
|
+
)
|
|
282
|
+
const headers = yield* resolved.route.auth.apply({
|
|
283
|
+
request: LLM.request({ model: resolved, prompt: "Hello" }),
|
|
284
|
+
method: "POST",
|
|
285
|
+
url: "https://openai.example/v1/responses",
|
|
286
|
+
body: "{}",
|
|
287
|
+
headers: Headers.empty,
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
expect(headers.authorization).toBe("Bearer stored-secret")
|
|
291
|
+
expect(resolved.route.defaults.http?.body).toEqual({ tenant: "work" })
|
|
292
|
+
}),
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
it.effect("does not project OAuth account metadata into the request body", () =>
|
|
296
|
+
Effect.gen(function* () {
|
|
297
|
+
const resolved = yield* SessionRunnerModel.fromCatalogModel(
|
|
298
|
+
ModelV2.Info.make({
|
|
299
|
+
...model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
300
|
+
request: { headers: {}, body: {} },
|
|
301
|
+
}),
|
|
302
|
+
Credential.OAuth.make({
|
|
303
|
+
type: "oauth",
|
|
304
|
+
methodID: Integration.MethodID.make("device"),
|
|
305
|
+
access: "secret",
|
|
306
|
+
refresh: "refresh",
|
|
307
|
+
expires: Date.now() + 60_000,
|
|
308
|
+
metadata: { server: "https://console.example", orgID: "org_123" },
|
|
309
|
+
}),
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
expect(resolved.route.defaults.http?.body).toEqual({})
|
|
313
|
+
}),
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
it.effect("rejects catalog APIs without a native route", () =>
|
|
317
|
+
Effect.gen(function* () {
|
|
318
|
+
const failure = yield* SessionRunnerModel.fromCatalogModel(
|
|
319
|
+
model({ type: "aisdk", package: "@ai-sdk/google", url: "https://google.example/v1" }),
|
|
320
|
+
).pipe(Effect.flip)
|
|
321
|
+
|
|
322
|
+
expect(failure).toMatchObject({
|
|
323
|
+
_tag: "SessionRunnerModel.UnsupportedApiError",
|
|
324
|
+
providerID: "test-provider",
|
|
325
|
+
modelID: "test-model",
|
|
326
|
+
api: "aisdk:@ai-sdk/google",
|
|
327
|
+
})
|
|
328
|
+
expect(failure.message).toBe("Unsupported API for test-provider/test-model: aisdk:@ai-sdk/google")
|
|
329
|
+
}),
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
it.effect("reports whether a catalog model has a supported native route", () =>
|
|
333
|
+
Effect.sync(() => {
|
|
334
|
+
expect(
|
|
335
|
+
SessionRunnerModel.supported(
|
|
336
|
+
model({ type: "aisdk", package: "@ai-sdk/openai", url: "https://openai.example/v1" }),
|
|
337
|
+
),
|
|
338
|
+
).toBe(true)
|
|
339
|
+
expect(
|
|
340
|
+
SessionRunnerModel.supported(
|
|
341
|
+
model({ type: "aisdk", package: "@ai-sdk/google", url: "https://google.example/v1" }),
|
|
342
|
+
),
|
|
343
|
+
).toBe(false)
|
|
344
|
+
expect(SessionRunnerModel.supported(model({ type: "native", settings: {} }))).toBe(false)
|
|
345
|
+
}),
|
|
346
|
+
)
|
|
347
|
+
})
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { HttpRecorder } from "@neurocode-ai/http-recorder"
|
|
2
|
+
import { HttpRecorderInternal } from "@neurocode-ai/http-recorder/internal"
|
|
3
|
+
import * as OpenAIChat from "@neurocode-ai/llm/protocols/openai-chat"
|
|
4
|
+
import { Auth, LLMClient, RequestExecutor } from "@neurocode-ai/llm/route"
|
|
5
|
+
import { Database } from "@neurocode-ai/core/database/database"
|
|
6
|
+
import { AppNodeBuilder } from "@neurocode-ai/core/effect/app-node-builder"
|
|
7
|
+
import { LayerNodePlatform } from "@neurocode-ai/core/effect/app-node-platform"
|
|
8
|
+
import { LayerNode } from "@neurocode-ai/core/effect/layer-node"
|
|
9
|
+
import { EventV2 } from "@neurocode-ai/core/event"
|
|
10
|
+
import { EventTable } from "@neurocode-ai/core/event/sql"
|
|
11
|
+
import { PermissionV2 } from "@neurocode-ai/core/permission"
|
|
12
|
+
import { AgentV2 } from "@neurocode-ai/core/agent"
|
|
13
|
+
import { Config } from "@neurocode-ai/core/config"
|
|
14
|
+
import { Project } from "@neurocode-ai/core/project"
|
|
15
|
+
import { ProjectTable } from "@neurocode-ai/core/project/sql"
|
|
16
|
+
import { AbsolutePath } from "@neurocode-ai/core/schema"
|
|
17
|
+
import { SessionV2 } from "@neurocode-ai/core/session"
|
|
18
|
+
import { Snapshot } from "@neurocode-ai/core/snapshot"
|
|
19
|
+
import { Prompt } from "@neurocode-ai/core/session/prompt"
|
|
20
|
+
import { SessionProjector } from "@neurocode-ai/core/session/projector"
|
|
21
|
+
import { SessionExecution } from "@neurocode-ai/core/session/execution"
|
|
22
|
+
import { SessionRunCoordinator } from "@neurocode-ai/core/session/run-coordinator"
|
|
23
|
+
import { SessionRunner } from "@neurocode-ai/core/session/runner"
|
|
24
|
+
import * as SessionRunnerLLM from "@neurocode-ai/core/session/runner/llm"
|
|
25
|
+
import { SessionRunnerModel } from "@neurocode-ai/core/session/runner/model"
|
|
26
|
+
import { ToolRegistry } from "@neurocode-ai/core/tool/registry"
|
|
27
|
+
import { ToolOutputStore } from "@neurocode-ai/core/tool-output-store"
|
|
28
|
+
import { SessionTable } from "@neurocode-ai/core/session/sql"
|
|
29
|
+
import { SessionStore } from "@neurocode-ai/core/session/store"
|
|
30
|
+
import { Location } from "@neurocode-ai/core/location"
|
|
31
|
+
import { SystemContextRegistry } from "@neurocode-ai/core/system-context/registry"
|
|
32
|
+
import { SystemContext } from "@neurocode-ai/core/system-context"
|
|
33
|
+
import { SkillGuidance } from "@neurocode-ai/core/skill/guidance"
|
|
34
|
+
import { ReferenceGuidance } from "@neurocode-ai/core/reference/guidance"
|
|
35
|
+
import { describe, expect } from "bun:test"
|
|
36
|
+
import { eq } from "drizzle-orm"
|
|
37
|
+
import { Effect, Layer } from "effect"
|
|
38
|
+
import path from "node:path"
|
|
39
|
+
import { testEffect } from "./lib/effect"
|
|
40
|
+
|
|
41
|
+
const cassette =
|
|
42
|
+
process.env.RECORD === "true"
|
|
43
|
+
? HttpRecorderInternal.cassetteLayer("session-runner/openai-chat-streams-text", {
|
|
44
|
+
directory: path.resolve(import.meta.dir, "fixtures/recordings"),
|
|
45
|
+
mode: "record",
|
|
46
|
+
})
|
|
47
|
+
: HttpRecorder.http("session-runner/openai-chat-streams-text", {
|
|
48
|
+
directory: path.resolve(import.meta.dir, "fixtures/recordings"),
|
|
49
|
+
})
|
|
50
|
+
const executor = RequestExecutor.layer.pipe(Layer.provide(cassette))
|
|
51
|
+
const client = LLMClient.layer.pipe(Layer.provide(executor))
|
|
52
|
+
const permission = Layer.succeed(
|
|
53
|
+
PermissionV2.Service,
|
|
54
|
+
PermissionV2.Service.of({
|
|
55
|
+
assert: () => Effect.die("unused"),
|
|
56
|
+
ask: () => Effect.die("unused"),
|
|
57
|
+
reply: () => Effect.die("unused"),
|
|
58
|
+
get: () => Effect.die("unused"),
|
|
59
|
+
forSession: () => Effect.die("unused"),
|
|
60
|
+
list: () => Effect.die("unused"),
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
const model = OpenAIChat.route
|
|
64
|
+
.with({
|
|
65
|
+
endpoint: { baseURL: "https://api.openai.com/v1" },
|
|
66
|
+
auth: Auth.bearer(process.env.OPENAI_API_KEY ?? "fixture"),
|
|
67
|
+
generation: { maxTokens: 20, temperature: 0 },
|
|
68
|
+
})
|
|
69
|
+
.model({ id: "gpt-4o-mini" })
|
|
70
|
+
const models = SessionRunnerModel.layerWith(() => Effect.succeed(model))
|
|
71
|
+
const systemContext = AppNodeBuilder.build(SystemContextRegistry.node)
|
|
72
|
+
const skillGuidance = Layer.mock(SkillGuidance.Service, { load: () => Effect.succeed(SystemContext.empty) })
|
|
73
|
+
const referenceGuidance = Layer.mock(ReferenceGuidance.Service, { load: () => Effect.succeed(SystemContext.empty) })
|
|
74
|
+
const config = Layer.succeed(Config.Service, Config.Service.of({ entries: () => Effect.succeed([]) }))
|
|
75
|
+
const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [
|
|
76
|
+
[Snapshot.node, Snapshot.noopLayer],
|
|
77
|
+
[LayerNodePlatform.llmClient, client],
|
|
78
|
+
[SessionRunnerModel.node, models],
|
|
79
|
+
[SystemContextRegistry.node, systemContext],
|
|
80
|
+
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
|
81
|
+
[SkillGuidance.node, skillGuidance],
|
|
82
|
+
[ReferenceGuidance.node, referenceGuidance],
|
|
83
|
+
[Config.node, config],
|
|
84
|
+
[PermissionV2.node, permission],
|
|
85
|
+
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
86
|
+
])
|
|
87
|
+
const execution = Layer.effect(
|
|
88
|
+
SessionExecution.Service,
|
|
89
|
+
Effect.gen(function* () {
|
|
90
|
+
const sessionRunner = yield* SessionRunner.Service
|
|
91
|
+
const coordinator = yield* SessionRunCoordinator.make<SessionV2.ID, SessionRunner.RunError>({
|
|
92
|
+
drain: (sessionID, force) => sessionRunner.run({ sessionID, force }),
|
|
93
|
+
})
|
|
94
|
+
return SessionExecution.Service.of({
|
|
95
|
+
active: coordinator.active,
|
|
96
|
+
resume: coordinator.run,
|
|
97
|
+
wake: coordinator.wake,
|
|
98
|
+
interrupt: coordinator.interrupt,
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
101
|
+
).pipe(Layer.provide(runnerLayer))
|
|
102
|
+
const it = testEffect(
|
|
103
|
+
AppNodeBuilder.build(
|
|
104
|
+
LayerNode.group([
|
|
105
|
+
Database.node,
|
|
106
|
+
EventV2.node,
|
|
107
|
+
SessionProjector.node,
|
|
108
|
+
SessionStore.node,
|
|
109
|
+
AgentV2.node,
|
|
110
|
+
ToolRegistry.node,
|
|
111
|
+
SessionRunnerModel.node,
|
|
112
|
+
SystemContextRegistry.node,
|
|
113
|
+
SkillGuidance.node,
|
|
114
|
+
ReferenceGuidance.node,
|
|
115
|
+
Config.node,
|
|
116
|
+
Snapshot.node,
|
|
117
|
+
SessionRunnerLLM.node,
|
|
118
|
+
SessionV2.node,
|
|
119
|
+
]),
|
|
120
|
+
[
|
|
121
|
+
[LayerNodePlatform.llmClient, client],
|
|
122
|
+
[PermissionV2.node, permission],
|
|
123
|
+
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
124
|
+
[SessionRunnerModel.node, models],
|
|
125
|
+
[SystemContextRegistry.node, systemContext],
|
|
126
|
+
[Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
|
|
127
|
+
[SkillGuidance.node, skillGuidance],
|
|
128
|
+
[ReferenceGuidance.node, referenceGuidance],
|
|
129
|
+
[Config.node, config],
|
|
130
|
+
[Snapshot.node, Snapshot.noopLayer],
|
|
131
|
+
[SessionExecution.node, execution],
|
|
132
|
+
],
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
const sessionID = SessionV2.ID.make("ses_runner_recorded")
|
|
136
|
+
|
|
137
|
+
describe("SessionRunnerLLM recorded", () => {
|
|
138
|
+
it.effect("executes one recorded V2 prompt through the recorded HTTP transport", () =>
|
|
139
|
+
Effect.gen(function* () {
|
|
140
|
+
const { db } = yield* Database.Service
|
|
141
|
+
yield* db
|
|
142
|
+
.insert(ProjectTable)
|
|
143
|
+
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
|
144
|
+
.onConflictDoNothing()
|
|
145
|
+
.run()
|
|
146
|
+
.pipe(Effect.orDie)
|
|
147
|
+
yield* db
|
|
148
|
+
.insert(SessionTable)
|
|
149
|
+
.values({
|
|
150
|
+
id: sessionID,
|
|
151
|
+
project_id: Project.ID.global,
|
|
152
|
+
slug: "test",
|
|
153
|
+
directory: "/project",
|
|
154
|
+
title: "test",
|
|
155
|
+
version: "test",
|
|
156
|
+
})
|
|
157
|
+
.onConflictDoNothing()
|
|
158
|
+
.run()
|
|
159
|
+
.pipe(Effect.orDie)
|
|
160
|
+
const session = yield* SessionV2.Service
|
|
161
|
+
const prompt = yield* session.prompt({
|
|
162
|
+
sessionID,
|
|
163
|
+
prompt: Prompt.make({ text: "Say hello in one short sentence." }),
|
|
164
|
+
resume: false,
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
yield* session.resume(sessionID)
|
|
168
|
+
|
|
169
|
+
const messages = yield* session.context(sessionID)
|
|
170
|
+
expect(messages).toHaveLength(2)
|
|
171
|
+
expect(messages[0]).toMatchObject({ id: prompt.id, type: "user", text: "Say hello in one short sentence." })
|
|
172
|
+
expect(messages[1]).toMatchObject({ type: "assistant", agent: "build", finish: "stop" })
|
|
173
|
+
expect(messages[1]?.type === "assistant" ? messages[1].content : []).toMatchObject([
|
|
174
|
+
{ type: "text", text: "Hello!" },
|
|
175
|
+
])
|
|
176
|
+
expect(
|
|
177
|
+
(yield* db
|
|
178
|
+
.select({ type: EventTable.type })
|
|
179
|
+
.from(EventTable)
|
|
180
|
+
.where(eq(EventTable.aggregate_id, sessionID))
|
|
181
|
+
.orderBy(EventTable.seq)
|
|
182
|
+
.all()).map((event) => event.type),
|
|
183
|
+
).toEqual([
|
|
184
|
+
"session.next.prompt.admitted.1",
|
|
185
|
+
"session.next.prompted.1",
|
|
186
|
+
"session.next.step.started.1",
|
|
187
|
+
"session.next.text.started.1",
|
|
188
|
+
"session.next.text.ended.1",
|
|
189
|
+
"session.next.step.ended.2",
|
|
190
|
+
])
|
|
191
|
+
}),
|
|
192
|
+
)
|
|
193
|
+
})
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { Effect, Schema, Stream } from "effect"
|
|
3
|
+
import { LLMEvent } from "@neurocode-ai/llm"
|
|
4
|
+
import { EventV2 } from "@neurocode-ai/core/event"
|
|
5
|
+
import { SessionEvent } from "@neurocode-ai/core/session/event"
|
|
6
|
+
import { SessionMessage } from "@neurocode-ai/core/session/message"
|
|
7
|
+
import { SessionV2 } from "@neurocode-ai/core/session"
|
|
8
|
+
import { ModelV2 } from "@neurocode-ai/core/model"
|
|
9
|
+
import { ProviderV2 } from "@neurocode-ai/core/provider"
|
|
10
|
+
import { createLLMEventPublisher } from "@neurocode-ai/core/session/runner/publish-llm-event"
|
|
11
|
+
|
|
12
|
+
const sessionID = SessionV2.ID.make("ses_tool_event_test")
|
|
13
|
+
const base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB"
|
|
14
|
+
|
|
15
|
+
const capture = () => {
|
|
16
|
+
const published: Array<{ readonly type: string; readonly data: unknown }> = []
|
|
17
|
+
const events = EventV2.Service.of({
|
|
18
|
+
publish: (definition, data) =>
|
|
19
|
+
Effect.sync(() => {
|
|
20
|
+
const event = { id: EventV2.ID.create(), type: definition.type, data } as EventV2.Payload<typeof definition>
|
|
21
|
+
published.push({
|
|
22
|
+
type: definition.durable
|
|
23
|
+
? EventV2.versionedType(definition.type, definition.durable.version)
|
|
24
|
+
: definition.type,
|
|
25
|
+
data,
|
|
26
|
+
})
|
|
27
|
+
return event
|
|
28
|
+
}),
|
|
29
|
+
subscribe: () => Stream.empty,
|
|
30
|
+
all: () => Stream.empty,
|
|
31
|
+
durable: () => Stream.empty,
|
|
32
|
+
listen: () => Effect.succeed(Effect.void),
|
|
33
|
+
project: () => Effect.void,
|
|
34
|
+
replay: () => Effect.void,
|
|
35
|
+
replayAll: () => Effect.succeed(undefined),
|
|
36
|
+
remove: () => Effect.void,
|
|
37
|
+
claim: () => Effect.void,
|
|
38
|
+
})
|
|
39
|
+
return {
|
|
40
|
+
published,
|
|
41
|
+
publisher: createLLMEventPublisher(events, {
|
|
42
|
+
sessionID,
|
|
43
|
+
agent: "build",
|
|
44
|
+
model: {
|
|
45
|
+
id: ModelV2.ID.make("model"),
|
|
46
|
+
providerID: ProviderV2.ID.make("provider"),
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const call = LLMEvent.toolCall({ id: "call-image", name: "read", input: { path: "pixel.png" } })
|
|
53
|
+
const result = LLMEvent.toolResult({
|
|
54
|
+
id: "call-image",
|
|
55
|
+
name: "read",
|
|
56
|
+
result: {
|
|
57
|
+
type: "content",
|
|
58
|
+
value: [
|
|
59
|
+
{ type: "text", text: "Image read successfully" },
|
|
60
|
+
{ type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png", name: "pixel.png" },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
output: {
|
|
64
|
+
structured: { type: "media", mime: "image/png" },
|
|
65
|
+
content: [
|
|
66
|
+
{ type: "text", text: "Image read successfully" },
|
|
67
|
+
{ type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png", name: "pixel.png" },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test("local tool success serializes media base64 once and reconstructs from structured content", async () => {
|
|
73
|
+
const { published, publisher } = capture()
|
|
74
|
+
await Effect.runPromise(publisher.publish(call))
|
|
75
|
+
await Effect.runPromise(publisher.publish(result))
|
|
76
|
+
|
|
77
|
+
const success = published.find((event) => event.type === "session.next.tool.success.1")
|
|
78
|
+
expect(success).toBeDefined()
|
|
79
|
+
const serialized = JSON.stringify(success)
|
|
80
|
+
expect(serialized.split(base64)).toHaveLength(2)
|
|
81
|
+
expect(success?.data).not.toHaveProperty("result")
|
|
82
|
+
|
|
83
|
+
expect(success?.data).toMatchObject({
|
|
84
|
+
content: [
|
|
85
|
+
{ type: "text", text: "Image read successfully" },
|
|
86
|
+
{ type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png" },
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("provider-executed success retains its compatibility result", async () => {
|
|
92
|
+
const { published, publisher } = capture()
|
|
93
|
+
await Effect.runPromise(publisher.publish(LLMEvent.toolCall({ ...call, providerExecuted: true })))
|
|
94
|
+
await Effect.runPromise(publisher.publish(LLMEvent.toolResult({ ...result, providerExecuted: true })))
|
|
95
|
+
const success = published.find((event) => event.type === "session.next.tool.success.1")
|
|
96
|
+
expect(success?.data).toHaveProperty("result")
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test("binary failure emits no success event", async () => {
|
|
100
|
+
const { published, publisher } = capture()
|
|
101
|
+
await Effect.runPromise(publisher.publish(call))
|
|
102
|
+
await Effect.runPromise(
|
|
103
|
+
publisher.publish(
|
|
104
|
+
LLMEvent.toolResult({
|
|
105
|
+
id: call.id,
|
|
106
|
+
name: call.name,
|
|
107
|
+
result: { type: "error", value: "Cannot read binary file" },
|
|
108
|
+
}),
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
expect(published.some((event) => event.type === "session.next.tool.success.1")).toBe(false)
|
|
112
|
+
expect(published.some((event) => event.type === "session.next.tool.failed.1")).toBe(true)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test("old success event data containing result still decodes", () => {
|
|
116
|
+
const decoded = Schema.decodeUnknownSync(SessionEvent.Tool.Success.data)({
|
|
117
|
+
sessionID,
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
assistantMessageID: SessionMessage.ID.create(),
|
|
120
|
+
callID: "call-old",
|
|
121
|
+
structured: { type: "media", mime: "image/png" },
|
|
122
|
+
content: [{ type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png" }],
|
|
123
|
+
result: { type: "content", value: [{ type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png" }] },
|
|
124
|
+
provider: { executed: false },
|
|
125
|
+
})
|
|
126
|
+
expect(decoded.result).toMatchObject({ type: "content" })
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test("step finish records settlement without publishing step ended", async () => {
|
|
130
|
+
const { published, publisher } = capture()
|
|
131
|
+
await Effect.runPromise(publisher.publish(LLMEvent.stepStart({ index: 0 })))
|
|
132
|
+
await Effect.runPromise(publisher.publish(LLMEvent.stepFinish({ index: 0, reason: "stop" })))
|
|
133
|
+
|
|
134
|
+
expect(published.some((event) => event.type === "session.next.step.ended.2")).toBe(false)
|
|
135
|
+
expect(publisher.stepSettlement()).toMatchObject({ finish: "stop" })
|
|
136
|
+
})
|