@zyro-sec/core 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +7 -7
- package/README.md +3 -3
- package/bunfig.toml +2 -2
- package/drizzle.config.ts +10 -10
- package/package.json +11 -8
- package/perf/location.bench.ts +44 -44
- package/perf/location.ts +140 -140
- package/perf/session.bench.ts +22 -22
- package/perf/snapshot.bench.ts +67 -67
- package/perf/snapshot.ts +423 -423
- package/schema.json +2763 -2763
- package/script/build.ts +44 -44
- package/script/fix-node-pty.ts +28 -28
- package/script/generate-api-skill.ts +361 -361
- package/script/migration.ts +216 -216
- package/script/models-snapshot.ts +82 -82
- package/script/pack.ts +5 -5
- package/script/snapshot-parity-compare.ts +22 -22
- package/script/snapshot-parity-run.sh +20 -20
- package/script/snapshot-parity.ts +710 -710
- package/script/test.ts +53 -53
- package/script/update-models-snapshot.ts +14 -14
- package/script/wellknown-server.ts +112 -112
- package/src/account/sql.ts +36 -36
- package/src/agent.ts +115 -115
- package/src/aisdk-native.ts +397 -397
- package/src/aisdk.ts +1063 -1063
- package/src/app.ts +31 -31
- package/src/artifact.ts +617 -617
- package/src/automation/author.ts +10 -10
- package/src/automation/code.ts +269 -269
- package/src/automation/event.ts +35 -35
- package/src/automation/shell.ts +82 -82
- package/src/automation/sql.ts +50 -50
- package/src/automation.ts +1293 -1293
- package/src/blob-store.ts +115 -115
- package/src/bus.ts +909 -909
- package/src/codemode/api.ts +44 -44
- package/src/codemode/bun.ts +550 -550
- package/src/codemode/catalog.ts +177 -177
- package/src/codemode/diffs.ts +134 -134
- package/src/codemode/execution.ts +9 -9
- package/src/codemode/fetch.ts +179 -179
- package/src/codemode/instructions.ts +169 -169
- package/src/codemode/job.ts +144 -144
- package/src/codemode/path.ts +45 -45
- package/src/codemode/tool.ts +564 -564
- package/src/command.ts +109 -109
- package/src/config/discovery.ts +183 -183
- package/src/config/integration.ts +134 -134
- package/src/config/managed.ts +6 -6
- package/src/config/markdown.ts +123 -123
- package/src/config/normalize.ts +870 -870
- package/src/config/plugin/agent.ts +192 -192
- package/src/config/plugin/command.ts +229 -229
- package/src/config/plugin/compaction.ts +27 -27
- package/src/config/plugin/compatibility.ts +94 -94
- package/src/config/plugin/entry-observer.ts +79 -79
- package/src/config/plugin/formatter.ts +76 -76
- package/src/config/plugin/image.ts +29 -29
- package/src/config/plugin/instruction.ts +260 -260
- package/src/config/plugin/location-watcher.ts +22 -22
- package/src/config/plugin/mcp.ts +57 -57
- package/src/config/plugin/policy.ts +117 -117
- package/src/config/plugin/provider.ts +274 -274
- package/src/config/plugin/reference.ts +67 -67
- package/src/config/plugin/session-search.ts +21 -21
- package/src/config/plugin/shell.ts +20 -20
- package/src/config/plugin/skill-file.ts +62 -62
- package/src/config/plugin/skill-scan.ts +46 -46
- package/src/config/plugin/skill.ts +202 -202
- package/src/config/plugin/snapshot.ts +21 -21
- package/src/config/plugin/source.ts +194 -194
- package/src/config/plugin/tool-output.ts +24 -24
- package/src/config/plugin/websearch.ts +19 -19
- package/src/config/plugin/worktree.ts +35 -35
- package/src/config/variable.ts +84 -84
- package/src/config/watch.ts +73 -73
- package/src/config.ts +574 -574
- package/src/console-access.ts +22 -22
- package/src/credential/sql.ts +14 -14
- package/src/credential.ts +350 -350
- package/src/database/batch.ts +21 -21
- package/src/database/database.ts +126 -126
- package/src/database/drizzle/README.md +35 -35
- package/src/database/drizzle/effect-sqlite/driver.ts +78 -78
- package/src/database/drizzle/effect-sqlite/index.ts +4 -4
- package/src/database/drizzle/effect-sqlite/session.ts +252 -252
- package/src/database/drizzle/index.ts +5 -5
- package/src/database/drizzle/internal/drizzle-utils.ts +147 -147
- package/src/database/drizzle/sqlite-core/effect/count.ts +58 -58
- package/src/database/drizzle/sqlite-core/effect/db.ts +243 -243
- package/src/database/drizzle/sqlite-core/effect/delete.ts +261 -261
- package/src/database/drizzle/sqlite-core/effect/index.ts +10 -10
- package/src/database/drizzle/sqlite-core/effect/insert.ts +340 -340
- package/src/database/drizzle/sqlite-core/effect/query.ts +198 -198
- package/src/database/drizzle/sqlite-core/effect/raw.ts +49 -49
- package/src/database/drizzle/sqlite-core/effect/select.ts +278 -278
- package/src/database/drizzle/sqlite-core/effect/session.ts +421 -421
- package/src/database/drizzle/sqlite-core/effect/update.ts +402 -402
- package/src/database/drizzle.ts +1 -1
- package/src/database/migration/20260127222353_familiar_lady_ursula.ts +109 -109
- package/src/database/migration/20260211171708_add_project_commands.ts +13 -13
- package/src/database/migration/20260213144116_wakeful_the_professor.ts +25 -25
- package/src/database/migration/20260225215848_workspace.ts +21 -21
- package/src/database/migration/20260227213759_add_session_workspace_id.ts +14 -14
- package/src/database/migration/20260228203230_blue_harpoon.ts +32 -32
- package/src/database/migration/20260303231226_add_workspace_fields.ts +17 -17
- package/src/database/migration/20260309230000_move_org_to_state.ts +17 -17
- package/src/database/migration/20260312043431_session_message_cursor.ts +18 -18
- package/src/database/migration/20260323234822_events.ts +28 -28
- package/src/database/migration/20260410174513_workspace-name.ts +34 -34
- package/src/database/migration/20260413175956_chief_energizer.ts +26 -26
- package/src/database/migration/20260423070820_add_icon_url_override.ts +16 -16
- package/src/database/migration/20260427172553_slow_nightmare.ts +32 -32
- package/src/database/migration/20260428004200_add_session_path.ts +13 -13
- package/src/database/migration/20260501142318_next_venus.ts +14 -14
- package/src/database/migration/20260504145000_add_sync_owner.ts +13 -13
- package/src/database/migration/20260507164347_add_workspace_time.ts +13 -13
- package/src/database/migration/20260510033149_session_usage.ts +58 -58
- package/src/database/migration/20260511000411_data_migration_state.ts +18 -18
- package/src/database/migration/20260511173437_session-metadata.ts +18 -18
- package/src/database/migration/20260601010001_normalize_storage_paths.ts +24 -24
- package/src/database/migration/20260601202201_amazing_prowler.ts +13 -13
- package/src/database/migration/20260602002951_lowly_union_jack.ts +26 -26
- package/src/database/migration/20260602182828_add_project_directories.ts +22 -22
- package/src/database/migration/20260603001617_session_message_projection_indexes.ts +21 -21
- package/src/database/migration/20260603040000_session_message_projection_order.ts +21 -21
- package/src/database/migration/20260603141458_session_input_inbox.ts +27 -27
- package/src/database/migration/20260603160727_jittery_ezekiel_stane.ts +22 -22
- package/src/database/migration/20260604172448_event_sourced_session_input.ts +49 -49
- package/src/database/migration/20260605003541_add_session_context_snapshot.ts +23 -23
- package/src/database/migration/20260605042240_add_context_epoch_agent.ts +13 -13
- package/src/database/migration/20260611035744_credential.ts +27 -27
- package/src/database/migration/20260611192811_lush_chimera.ts +27 -27
- package/src/database/migration/20260612174303_project_dir_strategy.ts +31 -31
- package/src/database/migration/20260622142730_simplify_session_context_epoch.ts +15 -15
- package/src/database/migration/20260622170816_reset_v2_session_state.ts +17 -17
- package/src/database/migration/20260622202450_simplify_session_input.ts +19 -19
- package/src/database/migration/20260804233008_loose_psylocke.ts +173 -173
- package/src/database/migration/20260805200742_import_legacy_credentials.ts +109 -109
- package/src/database/migration/20260808023530_workspace_domain.ts +22 -22
- package/src/database/migration/20260811161259_execution_claim_attempts.ts +13 -13
- package/src/database/migration/20260812181746_session_inbox.ts +30 -30
- package/src/database/migration/20260812213948_worktree.ts +35 -35
- package/src/database/migration/20260819222447_session_viewed_state.ts +15 -15
- package/src/database/migration/20260823191254_nullable_workspace_binding.ts +27 -27
- package/src/database/migration/20260910120000_clear_v1_session_permission.ts +13 -13
- package/src/database/migration/20260923013825_project_time_active.ts +14 -14
- package/src/database/migration/20261007190000_azure_cli_external_credential.ts +21 -21
- package/src/database/migration/20261010180456_project_time_archived.ts +13 -13
- package/src/database/migration/20261024002554_session_allowance.ts +13 -13
- package/src/database/migration/20261024175301_drop_session_allowance.ts +13 -13
- package/src/database/migration/20261025123711_blob.ts +36 -36
- package/src/database/migration/20261025154125_drop_session_pending.ts +16 -16
- package/src/database/migration/20261026223005_schedule.ts +38 -38
- package/src/database/migration/20261029002625_session_part.ts +30 -30
- package/src/database/migration/20261029073502_session_time_busy.ts +13 -13
- package/src/database/migration/20261029165540_schedule_checks.ts +16 -16
- package/src/database/migration/20261030054400_job.ts +60 -60
- package/src/database/migration/20261116043204_automation.ts +83 -83
- package/src/database/migration/20261116181958_automation_event_position.ts +13 -13
- package/src/database/migration/20261116213417_automation_active_index.ts +16 -16
- package/src/database/migration/20261119211416_machine.ts +18 -18
- package/src/database/migration/20261120004954_machine-key.ts +14 -14
- package/src/database/migration.gen.ts +132 -132
- package/src/database/migration.ts +155 -155
- package/src/database/path.ts +98 -98
- package/src/database/schema.gen.ts +363 -363
- package/src/database/schema.sql.ts +10 -10
- package/src/database/sqlite.bun.ts +17 -17
- package/src/database/sqlite.node.ts +25 -25
- package/src/database/sqlite.workerd.ts +227 -227
- package/src/database/storage-failure.ts +58 -58
- package/src/database/v1-migration.bun.ts +1234 -1234
- package/src/database/v1-migration.noop.ts +11 -11
- package/src/database/v1-migration.ts +2 -2
- package/src/effect/app-node-builder.ts +30 -30
- package/src/effect/app-node-platform.ts +71 -71
- package/src/effect/client-tls/client-tls.bun.ts +8 -8
- package/src/effect/client-tls/client-tls.node.ts +17 -17
- package/src/effect/client-tls/client-tls.ts +12 -12
- package/src/effect/client-tls/client-tls.workerd.ts +8 -8
- package/src/effect/keyed-mutex.ts +45 -45
- package/src/effect/websocket-constructor.ts +81 -81
- package/src/environment/driver.ts +68 -68
- package/src/environment/environment.ts +152 -152
- package/src/environment/environments.ts +78 -78
- package/src/environment/exec-defaults.ts +200 -200
- package/src/environment/files.ts +79 -79
- package/src/environment/index.ts +34 -34
- package/src/environment/local.ts +101 -101
- package/src/environment/memory.ts +186 -186
- package/src/environment/path.ts +68 -68
- package/src/environment/unavailable.ts +17 -17
- package/src/event/sql.ts +26 -26
- package/src/event-logger.ts +19 -19
- package/src/file-access.ts +352 -352
- package/src/file-mutation.ts +185 -185
- package/src/file-retention.ts +23 -23
- package/src/file-write.ts +110 -110
- package/src/filesystem/fff.bun.ts +15 -15
- package/src/filesystem/fff.node.ts +12 -12
- package/src/filesystem/fff.ts +67 -67
- package/src/filesystem/fff.workerd.ts +12 -12
- package/src/filesystem/file-watch.ts +164 -164
- package/src/filesystem/location-watcher-policy.ts +64 -64
- package/src/filesystem/location-watcher.ts +108 -108
- package/src/filesystem/protected.ts +31 -31
- package/src/filesystem/search.ts +251 -251
- package/src/filesystem/watcher-binding.ts +14 -14
- package/src/filesystem/watcher.ts +282 -282
- package/src/filesystem.ts +270 -270
- package/src/flag/resolve.ts +66 -66
- package/src/flag.ts +64 -64
- package/src/form.ts +370 -370
- package/src/formatter/builtins.ts +294 -294
- package/src/formatter.ts +108 -108
- package/src/generate.ts +397 -397
- package/src/git.ts +1609 -1609
- package/src/github-copilot/models.ts +289 -289
- package/src/image/notice.ts +8 -8
- package/src/image/photon-normalize.ts +148 -148
- package/src/image/photon-wasm.bun.ts +4 -4
- package/src/image/photon-wasm.node.ts +4 -4
- package/src/image/photon-wasm.workerd.ts +4 -4
- package/src/image/photon-worker.ts +26 -26
- package/src/image/photon.ts +156 -156
- package/src/image.ts +95 -95
- package/src/instance/service.ts +21 -21
- package/src/instance.ts +191 -191
- package/src/instruction-discovery.ts +165 -165
- package/src/instructions/agent.ts +50 -50
- package/src/instructions/builtins.ts +103 -103
- package/src/instructions/index.ts +287 -287
- package/src/integration/connection.ts +26 -26
- package/src/integration.ts +869 -869
- package/src/job/list.ts +160 -160
- package/src/job/recovery.ts +51 -51
- package/src/job/sql.ts +27 -27
- package/src/job.ts +766 -766
- package/src/kv/sql.ts +9 -9
- package/src/kv.ts +92 -92
- package/src/location-activity.ts +130 -130
- package/src/location-lifecycle.ts +97 -97
- package/src/location-service-map.ts +50 -50
- package/src/location-services.ts +125 -125
- package/src/location.ts +44 -44
- package/src/machine/driver.ts +487 -487
- package/src/machine/frames.ts +133 -133
- package/src/machine/identity.ts +187 -187
- package/src/machine/index.ts +4 -4
- package/src/machine/instructions.ts +61 -61
- package/src/machine/iroh-binding.ts +18 -18
- package/src/machine/iroh.ts +157 -157
- package/src/machine/join.ts +54 -54
- package/src/machine/link.ts +313 -313
- package/src/machine/machines.ts +280 -280
- package/src/machine/noise.ts +326 -326
- package/src/machine/sql.ts +13 -13
- package/src/machine/wire.ts +140 -140
- package/src/machine/worker-client.ts +276 -276
- package/src/managed-policy.ts +65 -65
- package/src/markdown.d.ts +4 -4
- package/src/mcp/client.ts +1198 -1198
- package/src/mcp/connection.ts +292 -292
- package/src/mcp/event-stream.ts +34 -34
- package/src/mcp/index.ts +1349 -1349
- package/src/mcp/instructions.ts +108 -108
- package/src/mcp/oauth.ts +665 -665
- package/src/mcp/pool.ts +386 -386
- package/src/mcp/socket-client.ts +86 -86
- package/src/mcp/stdio.ts +227 -227
- package/src/mime.ts +75 -75
- package/src/modal/models.ts +150 -150
- package/src/model-resolver.ts +639 -639
- package/src/model-retry.ts +134 -134
- package/src/model.ts +373 -373
- package/src/models-dev/v1.ts +203 -203
- package/src/models-dev.ts +899 -899
- package/src/node-ffi.d.ts +18 -18
- package/src/oauth/page.ts +260 -260
- package/src/oauth/redirect.ts +42 -42
- package/src/pentest/mcp-catalog.ts +175 -144
- package/src/permission/policy.ts +240 -240
- package/src/permission/saved.ts +140 -140
- package/src/permission/sql.ts +20 -20
- package/src/permission.ts +419 -419
- package/src/persistent-pty/binary.bun.ts +85 -85
- package/src/persistent-pty/binary.node.ts +5 -5
- package/src/persistent-pty/binary.workerd.ts +5 -5
- package/src/persistent-pty/daemon.ts +750 -750
- package/src/persistent-pty/index.ts +661 -661
- package/src/persistent-pty/pty-binding.ts +6 -6
- package/src/persistent-pty.ts +1 -1
- package/src/plugin/agent.ts +235 -235
- package/src/plugin/command/automation.txt +7 -7
- package/src/plugin/command/initialize.txt +65 -65
- package/src/plugin/command/review.txt +100 -100
- package/src/plugin/command.ts +113 -113
- package/src/plugin/fork-notice.ts +30 -30
- package/src/plugin/goal/continuation.txt +13 -13
- package/src/plugin/goal/judge.txt +20 -20
- package/src/plugin/goal/kickoff.txt +13 -13
- package/src/plugin/goal/reminder.txt +9 -9
- package/src/plugin/goal.ts +501 -501
- package/src/plugin/home-memory.ts +155 -155
- package/src/plugin/hooks.ts +108 -108
- package/src/plugin/host.ts +770 -770
- package/src/plugin/identity.ts +31 -31
- package/src/plugin/instance.ts +45 -45
- package/src/plugin/internal.ts +360 -360
- package/src/plugin/mcp-codemode-defaults.ts +41 -41
- package/src/plugin/mcp-skill.ts +171 -171
- package/src/plugin/models-dev.ts +128 -128
- package/src/plugin/module.ts +186 -186
- package/src/plugin/optimize.ts +97 -97
- package/src/plugin/plan.ts +52 -52
- package/src/plugin/promise.ts +3 -3
- package/src/plugin/provider/amazon-bedrock.ts +121 -121
- package/src/plugin/provider/azure.ts +568 -568
- package/src/plugin/provider/cerebras.ts +16 -16
- package/src/plugin/provider/chatgpt.ts +594 -594
- package/src/plugin/provider/claude-agent/aisdk.ts +36 -36
- package/src/plugin/provider/claude-agent/claude/accounts.ts +104 -104
- package/src/plugin/provider/claude-agent/claude/agent-sdk.ts +1 -1
- package/src/plugin/provider/claude-agent/claude/agent-sdk.workerd.ts +4 -4
- package/src/plugin/provider/claude-agent/claude/claude-folder-worker.ts +10 -10
- package/src/plugin/provider/claude-agent/claude/fork.ts +34 -34
- package/src/plugin/provider/claude-agent/claude/io.ts +88 -88
- package/src/plugin/provider/claude-agent/claude/probe.ts +124 -124
- package/src/plugin/provider/claude-agent/claude/query-options.ts +143 -143
- package/src/plugin/provider/claude-agent/claude/sdk.ts +17 -17
- package/src/plugin/provider/claude-agent/claude/session.ts +162 -162
- package/src/plugin/provider/claude-agent/claude/sessions.ts +508 -508
- package/src/plugin/provider/claude-agent/claude/status.ts +66 -66
- package/src/plugin/provider/claude-agent/claude/websearch.ts +96 -96
- package/src/plugin/provider/claude-agent/index.ts +63 -63
- package/src/plugin/provider/claude-agent/instructions.ts +54 -54
- package/src/plugin/provider/claude-agent/integration.ts +62 -62
- package/src/plugin/provider/claude-agent/language-model/claude-agent-error.ts +49 -49
- package/src/plugin/provider/claude-agent/language-model/claude-agent-language-model.ts +112 -112
- package/src/plugin/provider/claude-agent/language-model/convert-claude-stream.ts +139 -139
- package/src/plugin/provider/claude-agent/language-model/convert-to-claude-message.ts +55 -55
- package/src/plugin/provider/claude-agent/language-model/request-kind.ts +5 -5
- package/src/plugin/provider/claude-agent/language-model/system-prompt.ts +28 -28
- package/src/plugin/provider/claude-agent/language-model/usage.ts +58 -58
- package/src/plugin/provider/claude-agent/provider.ts +178 -178
- package/src/plugin/provider/claude-agent/session.ts +61 -61
- package/src/plugin/provider/claude-agent/sync/catch-up.ts +21 -21
- package/src/plugin/provider/claude-agent/sync/checkpoints.ts +41 -41
- package/src/plugin/provider/claude-agent/sync/decide.ts +58 -58
- package/src/plugin/provider/claude-agent/sync/fingerprint.ts +117 -117
- package/src/plugin/provider/claude-agent/sync/record.ts +42 -42
- package/src/plugin/provider/claude-agent/tools/hooks.ts +23 -23
- package/src/plugin/provider/claude-agent/tools/names.ts +30 -30
- package/src/plugin/provider/claude-agent/tools/pending.ts +72 -72
- package/src/plugin/provider/claude-agent/tools/result.ts +110 -110
- package/src/plugin/provider/claude-agent/tools/server.ts +34 -34
- package/src/plugin/provider/claude-agent/websearch.ts +57 -57
- package/src/plugin/provider/cloudflare-ai-gateway.ts +68 -68
- package/src/plugin/provider/cloudflare-workers-ai.ts +70 -70
- package/src/plugin/provider/configured.ts +18 -18
- package/src/plugin/provider/credential-settings.ts +77 -77
- package/src/plugin/provider/databricks.ts +31 -31
- package/src/plugin/provider/digitalocean.ts +197 -197
- package/src/plugin/provider/dynamic.ts +19 -19
- package/src/plugin/provider/github-copilot.ts +646 -646
- package/src/plugin/provider/gitlab.ts +496 -496
- package/src/plugin/provider/google-vertex.ts +231 -231
- package/src/plugin/provider/kilo.ts +17 -17
- package/src/plugin/provider/llmgateway.ts +27 -27
- package/src/plugin/provider/lmstudio.ts +52 -52
- package/src/plugin/provider/local.ts +240 -240
- package/src/plugin/provider/modal.ts +72 -72
- package/src/plugin/provider/neon.ts +12 -12
- package/src/plugin/provider/nvidia.ts +22 -22
- package/src/plugin/provider/ollama.ts +92 -92
- package/src/plugin/provider/openai-context-caps.ts +52 -52
- package/src/plugin/provider/openai-subscription-models.ts +59 -59
- package/src/plugin/provider/openai.ts +447 -447
- package/src/plugin/provider/opencode-artifacts.ts +216 -216
- package/src/plugin/provider/opencode-watches.ts +753 -753
- package/src/plugin/provider/opencode.ts +883 -883
- package/src/plugin/provider/openrouter.ts +30 -30
- package/src/plugin/provider/poe.ts +176 -176
- package/src/plugin/provider/prompt-cache-key.ts +37 -37
- package/src/plugin/provider/refresh.ts +80 -80
- package/src/plugin/provider/sap-ai-core.ts +39 -39
- package/src/plugin/provider/sdk-factory.ts +24 -24
- package/src/plugin/provider/snowflake-cortex.ts +266 -266
- package/src/plugin/provider/vllm.ts +34 -34
- package/src/plugin/provider/xai.ts +236 -236
- package/src/plugin/provider/zenmux.ts +21 -21
- package/src/plugin/provider.ts +64 -64
- package/src/plugin/sdk.ts +44 -44
- package/src/plugin/service.ts +42 -42
- package/src/plugin/skill/opencode/api/agent.md +18 -18
- package/src/plugin/skill/opencode/api/automation.md +63 -63
- package/src/plugin/skill/opencode/api/blob.md +10 -10
- package/src/plugin/skill/opencode/api/command.md +12 -12
- package/src/plugin/skill/opencode/api/form.md +22 -22
- package/src/plugin/skill/opencode/api/generate.md +96 -96
- package/src/plugin/skill/opencode/api/info.md +11 -11
- package/src/plugin/skill/opencode/api/location.md +17 -17
- package/src/plugin/skill/opencode/api/model.md +22 -22
- package/src/plugin/skill/opencode/api/permission.md +13 -13
- package/src/plugin/skill/opencode/api/project.md +29 -29
- package/src/plugin/skill/opencode/api/provider.md +18 -18
- package/src/plugin/skill/opencode/api/session.md +313 -313
- package/src/plugin/skill/opencode/api/skill.md +12 -12
- package/src/plugin/skill/opencode/api/vcs.md +60 -60
- package/src/plugin/skill/opencode/api/worktree.md +49 -49
- package/src/plugin/skill/opencode/api.md +119 -119
- package/src/plugin/skill/opencode/api.ts +40 -40
- package/src/plugin/skill/opencode-api.md +17 -17
- package/src/plugin/skill/opencode.md +154 -154
- package/src/plugin/skill/report.md +152 -152
- package/src/plugin/skill.ts +111 -111
- package/src/plugin/source-directory.ts +33 -33
- package/src/plugin/supervisor.ts +288 -288
- package/src/plugin/system-prompt/AGENTS.md +5 -5
- package/src/plugin/system-prompt/anthropic.txt +2 -2
- package/src/plugin/system-prompt/gpt-6.2.txt +71 -71
- package/src/plugin/system-prompt/gpt-astra.txt +46 -46
- package/src/plugin/system-prompt/gpt.txt +40 -40
- package/src/plugin/system-prompt/kimi.txt +96 -96
- package/src/plugin/system-prompt/meta.txt +56 -56
- package/src/plugin/system-prompt/trinity.txt +98 -98
- package/src/plugin/tool-input-repair.ts +232 -232
- package/src/plugin/update.ts +87 -87
- package/src/plugin/vcs/git.ts +802 -802
- package/src/plugin/vcs/hg.ts +234 -234
- package/src/plugin/verbosity.ts +58 -58
- package/src/plugin/warming.ts +224 -224
- package/src/plugin/websearch/exa.ts +69 -69
- package/src/plugin/websearch/firecrawl.ts +71 -71
- package/src/plugin/websearch/index.ts +13 -13
- package/src/plugin/websearch/mcp.ts +69 -69
- package/src/plugin/websearch/parallel.ts +90 -90
- package/src/plugin/websearch/provider.ts +44 -44
- package/src/plugin/websearch/tavily.ts +73 -73
- package/src/plugin/websearch/tinyfish.ts +131 -131
- package/src/plugin.ts +320 -320
- package/src/project/icon.ts +167 -167
- package/src/project/schema.ts +25 -25
- package/src/project/sql.ts +63 -63
- package/src/project.ts +536 -536
- package/src/provider.ts +553 -553
- package/src/pty/protocol.ts +37 -37
- package/src/pty/pty.bun.ts +44 -44
- package/src/pty/pty.node.ts +34 -34
- package/src/pty/pty.ts +25 -25
- package/src/pty/pty.workerd.ts +9 -9
- package/src/pty/ticket.ts +74 -74
- package/src/pty.ts +311 -311
- package/src/push/crypto.ts +39 -39
- package/src/push/list.ts +380 -380
- package/src/push/sender.ts +185 -185
- package/src/push/watcher.ts +169 -169
- package/src/reference/instructions.ts +82 -82
- package/src/reference.ts +129 -129
- package/src/repository-cache.ts +251 -251
- package/src/repository.ts +205 -205
- package/src/ripgrep/binary.ts +166 -166
- package/src/ripgrep.ts +311 -311
- package/src/rpc.ts +288 -288
- package/src/schema.ts +39 -39
- package/src/session/affinity.ts +8 -8
- package/src/session/background-result.ts +5 -5
- package/src/session/background.ts +125 -125
- package/src/session/blob.ts +503 -503
- package/src/session/command.ts +38 -38
- package/src/session/compaction-background.ts +55 -55
- package/src/session/compaction-subagents.ts +103 -103
- package/src/session/compaction.ts +1320 -1320
- package/src/session/context.ts +296 -296
- package/src/session/cwd-instructions.ts +147 -147
- package/src/session/cwd-store.ts +66 -66
- package/src/session/cwd.ts +75 -75
- package/src/session/diff.ts +149 -149
- package/src/session/environment.ts +33 -33
- package/src/session/error.ts +105 -105
- package/src/session/event.ts +2 -2
- package/src/session/execution/restart.ts +558 -558
- package/src/session/execution/subagent-report.ts +203 -203
- package/src/session/execution.ts +241 -241
- package/src/session/generate.ts +78 -78
- package/src/session/history.ts +405 -405
- package/src/session/inbox.ts +625 -625
- package/src/session/info.ts +62 -62
- package/src/session/instruction-entry.ts +171 -171
- package/src/session/instruction-state.ts +277 -277
- package/src/session/instructions.ts +126 -126
- package/src/session/message-updater.ts +497 -497
- package/src/session/message.ts +2 -2
- package/src/session/model-request.ts +474 -474
- package/src/session/model-transport.ts +571 -571
- package/src/session/move.ts +199 -199
- package/src/session/projector.ts +1197 -1197
- package/src/session/prompt.ts +253 -253
- package/src/session/recent-text.ts +93 -93
- package/src/session/revert.ts +112 -112
- package/src/session/run-coordinator.ts +198 -198
- package/src/session/runner/index.ts +46 -46
- package/src/session/runner/live-tool-metadata.ts +41 -41
- package/src/session/runner/llm.ts +481 -481
- package/src/session/runner/max-steps.ts +16 -16
- package/src/session/runner/model.ts +138 -138
- package/src/session/runner/prompt/system.txt +16 -16
- package/src/session/runner/publish-llm-event.ts +642 -642
- package/src/session/runner/retry.ts +78 -78
- package/src/session/runner/step.ts +401 -401
- package/src/session/runner/to-llm-message.ts +341 -341
- package/src/session/schema.ts +9 -9
- package/src/session/search-build.ts +116 -116
- package/src/session/search-index.ts +552 -552
- package/src/session/search.ts +672 -672
- package/src/session/session.ts +407 -407
- package/src/session/shell.ts +35 -35
- package/src/session/skill.ts +16 -16
- package/src/session/sql.ts +215 -215
- package/src/session/stats.ts +463 -463
- package/src/session/store.ts +323 -323
- package/src/session/stored.ts +44 -44
- package/src/session/subagent-completion.ts +95 -95
- package/src/session/subagent-depth.ts +21 -21
- package/src/session/subagent-job.ts +61 -61
- package/src/session/synthetic.ts +49 -49
- package/src/session/system-prompt.ts +28 -28
- package/src/session/title.ts +174 -174
- package/src/session/to-session-error.ts +179 -179
- package/src/session/transfer.ts +369 -369
- package/src/session/usage.ts +64 -64
- package/src/session.ts +602 -602
- package/src/shared-cache.ts +103 -103
- package/src/shell/parse.ts +645 -645
- package/src/shell/permissions.ts +60 -60
- package/src/shell/result.ts +115 -115
- package/src/shell/scan.ts +2585 -2585
- package/src/shell/select.ts +241 -241
- package/src/shell.ts +1274 -1274
- package/src/skill/discovery.ts +205 -205
- package/src/skill/instructions.ts +84 -84
- package/src/skill.ts +277 -277
- package/src/snapshot.ts +248 -248
- package/src/state.ts +271 -271
- package/src/tool/AGENTS.md +71 -71
- package/src/tool/html-markdown.ts +651 -651
- package/src/tool/http-body.ts +30 -30
- package/src/tool/mcp.ts +177 -177
- package/src/tool/model-policy.ts +38 -38
- package/src/tool/patch-grammar.txt +19 -19
- package/src/tool/patch.txt +33 -33
- package/src/tool/plugin/artifact.ts +171 -171
- package/src/tool/plugin/automation.ts +246 -246
- package/src/tool/plugin/cd.ts +103 -103
- package/src/tool/plugin/edit.ts +371 -371
- package/src/tool/plugin/file-diff.ts +42 -42
- package/src/tool/plugin/glob.ts +123 -123
- package/src/tool/plugin/grep.ts +152 -152
- package/src/tool/plugin/image-generate.ts +396 -396
- package/src/tool/plugin/machine.ts +36 -36
- package/src/tool/plugin/mcp-events.ts +72 -72
- package/src/tool/plugin/mcp-resource.ts +100 -100
- package/src/tool/plugin/opencode.ts +316 -316
- package/src/tool/plugin/patch.ts +358 -358
- package/src/tool/plugin/question.ts +130 -130
- package/src/tool/plugin/read.ts +413 -413
- package/src/tool/plugin/session-interrupt.ts +63 -63
- package/src/tool/plugin/session-search.ts +99 -99
- package/src/tool/plugin/shell.ts +594 -594
- package/src/tool/plugin/skill.ts +74 -74
- package/src/tool/plugin/subagent.ts +269 -269
- package/src/tool/plugin/todo.ts +83 -83
- package/src/tool/plugin/video-generate.ts +403 -403
- package/src/tool/plugin/webfetch.ts +214 -214
- package/src/tool/plugin/websearch.ts +196 -196
- package/src/tool/plugin/write.ts +72 -72
- package/src/tool/read-filesystem.ts +350 -350
- package/src/tool/runtime.ts +311 -311
- package/src/tool/search.ts +34 -34
- package/src/tool/todowrite.txt +7 -7
- package/src/tool-output.ts +220 -220
- package/src/tool.ts +579 -579
- package/src/usage-limits.ts +192 -192
- package/src/util/canonical-json.ts +11 -11
- package/src/util/error-summary.ts +33 -33
- package/src/util/git-executable.ts +59 -59
- package/src/util/lazy.ts +11 -11
- package/src/util/slug.ts +74 -74
- package/src/util/token.ts +5 -5
- package/src/util/which.ts +37 -37
- package/src/util/wildcard.ts +15 -15
- package/src/v1/config/agent.ts +69 -69
- package/src/v1/config/command.ts +13 -13
- package/src/v1/config/mcp.ts +69 -69
- package/src/v1/config/migrate.ts +269 -269
- package/src/v1/config/permission.ts +42 -42
- package/src/v1/config/plugin.ts +9 -9
- package/src/v1/config/provider-options.ts +59 -59
- package/src/v1/config/provider.ts +113 -113
- package/src/variant.ts +699 -699
- package/src/vcs/patch.ts +106 -106
- package/src/vcs.ts +262 -262
- package/src/video-generation.ts +344 -344
- package/src/voice.ts +194 -194
- package/src/websearch.ts +239 -239
- package/src/wellknown/plugin.ts +36 -36
- package/src/wellknown.ts +230 -230
- package/src/workspace/driver.ts +89 -89
- package/src/workspace/sql.ts +11 -11
- package/src/workspace.ts +566 -566
- package/src/worktree/directory.ts +16 -16
- package/src/worktree/git.ts +39 -39
- package/src/worktree/sql.ts +21 -21
- package/src/worktree/strategies.ts +74 -74
- package/src/worktree.ts +357 -357
- package/test/config/fixture/skills/first-source/first/SKILL.md +6 -6
- package/test/config/fixture/skills/second-source/second/SKILL.md +6 -6
- package/test/fixture/app-execution-alias.ts +17 -17
- package/test/fixture/codemode.ts +63 -63
- package/test/fixture/config-nodes.ts +40 -40
- package/test/fixture/durable-object-storage.ts +58 -58
- package/test/fixture/effect-flock-worker.ts +60 -60
- package/test/fixture/env.ts +22 -22
- package/test/fixture/environment.ts +52 -52
- package/test/fixture/event-server.ts +65 -65
- package/test/fixture/flock-worker.ts +72 -72
- package/test/fixture/git.ts +86 -86
- package/test/fixture/global.ts +26 -26
- package/test/fixture/held-stdio.cjs +36 -36
- package/test/fixture/html-markdown.ts +7 -7
- package/test/fixture/link-v1-transcript.json +27 -27
- package/test/fixture/location.ts +27 -27
- package/test/fixture/lock-worker.ts +53 -53
- package/test/fixture/machine-v2.json +66 -66
- package/test/fixture/machine-worker.ts +284 -284
- package/test/fixture/mcp-echo.ts +14 -14
- package/test/fixture/mcp-legacy-silent.ts +22 -22
- package/test/fixture/mcp-modern-stdio.ts +15 -15
- package/test/fixture/mcp-output-schema.ts +63 -63
- package/test/fixture/mcp-prompts.ts +29 -29
- package/test/fixture/mcp-timeout.ts +32 -32
- package/test/fixture/mcp-union-output-schema.ts +41 -41
- package/test/fixture/mcp.ts +44 -44
- package/test/fixture/models.ts +6 -6
- package/test/fixture/native/2.0.14-media.json +22 -22
- package/test/fixture/noise-xx-vectors.json +75 -75
- package/test/fixture/persistent-pty-daemon.ts +347 -347
- package/test/fixture/persistent-pty.ts +9 -9
- package/test/fixture/photon-crash-worker.ts +10 -10
- package/test/fixture/photon-exit.ts +29 -29
- package/test/fixture/photon-hang-worker.ts +2 -2
- package/test/fixture/policy.ts +98 -98
- package/test/fixture/prompt-location.ts +33 -33
- package/test/fixture/pty-windows.ts +69 -69
- package/test/fixture/selector.ts +12 -12
- package/test/fixture/shell-daemon.ts +122 -122
- package/test/fixture/spawn.ts +24 -24
- package/test/fixture/sqlite-node-client.ts +100 -100
- package/test/fixture/target-environment.ts +58 -58
- package/test/fixture/tmpdir.ts +44 -44
- package/test/fixture/v1-config/attachment.ts +25 -25
- package/test/fixture/v1-config/config.ts +182 -182
- package/test/fixture/v1-config/formatter.ts +13 -13
- package/test/fixture/v1-config/layout.ts +6 -6
- package/test/fixture/v1-config/lsp.ts +80 -80
- package/test/fixture/v1-config/server.ts +19 -19
- package/test/fixture/v1-config/skills.ts +13 -13
- package/test/fixtures/recordings/session-runner/openai-chat-streams-text.json +27 -27
- package/test/lib/clock.ts +43 -43
- package/test/lib/effect.ts +80 -80
- package/test/lib/environment-conformance.ts +204 -204
- package/test/lib/eventually.ts +20 -20
- package/test/lib/image.ts +7 -7
- package/test/lib/instructions.ts +47 -47
- package/test/lib/permission.ts +12 -12
- package/test/lib/project.ts +26 -26
- package/test/lib/session-message.ts +26 -26
- package/test/lib/tool.ts +102 -102
- package/test/lib/websearch.ts +63 -63
- package/test/lib/websocket-server.ts +73 -73
- package/test/plugin/fixture.ts +174 -174
- package/test/plugin/fixtures/greeting.ts +14 -14
- package/test/plugin/fixtures/models-dev-reasoning.json +811 -811
- package/test/plugin/fixtures/models-dev.json +92 -92
- package/test/plugin/fixtures/provider-factory.ts +9 -9
- package/test/plugin/host.ts +540 -540
- package/test/plugin/provider/claude-agent/fixtures/marker.pdf +68 -68
- package/test/plugin/provider/claude-agent/fixtures/recordings/api-error.jsonl +16 -16
- package/test/plugin/provider/claude-agent/fixtures/recordings/controls.jsonl +107 -107
- package/test/plugin/provider/claude-agent/fixtures/recordings/max-steps.jsonl +133 -133
- package/test/plugin/provider/claude-agent/fixtures/recordings/startup-logged-out.jsonl +4 -4
- package/test/plugin/provider/claude-agent/fixtures/recordings/startup.jsonl +52 -52
- package/test/plugin/provider/claude-agent/fixtures/recordings/sync.jsonl +73 -73
- package/test/plugin/provider/claude-agent/fixtures/recordings/text-cancel.jsonl +37 -37
- package/test/plugin/provider/claude-agent/fixtures/recordings/text-resume.jsonl +21 -21
- package/test/plugin/provider/claude-agent/fixtures/recordings/text.jsonl +35 -35
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-abort.jsonl +62 -62
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-cancel.jsonl +63 -63
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-continue.jsonl +58 -58
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-media.jsonl +80 -80
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-waiting-cancel.jsonl +58 -58
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools.jsonl +74 -74
- package/test/plugin/provider/claude-agent/fixtures/recordings/utility.jsonl +28 -28
- package/test/plugin/provider/claude-agent/fixtures/recordings/websearch.jsonl +13 -13
- package/test/plugin/provider/claude-agent/lib/fake-claude.ts +411 -411
- package/test/plugin/provider/claude-agent/lib/fake-io.ts +20 -20
- package/test/plugin/provider/claude-agent/lib/recorder.ts +61 -61
- package/test/plugin/provider/claude-agent/lib/sessions.ts +126 -126
- package/test/plugin/provider/claude-agent/lib/tools.ts +95 -95
- package/test/plugin/websearch-fixture.ts +63 -63
- package/test/preload.ts +2 -2
- package/test/session-sql.types.ts +25 -25
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +18 -18
- package/tsconfig.tests.json +13 -13
- package/test/agent.test.ts +0 -224
- package/test/aisdk-native.test.ts +0 -590
- package/test/aisdk.test.ts +0 -1259
- package/test/app.test.ts +0 -6
- package/test/artifact.test.ts +0 -216
- package/test/automation-event.test.ts +0 -688
- package/test/automation-shell.test.ts +0 -293
- package/test/automation.test.ts +0 -1950
- package/test/blob-store.test.ts +0 -37
- package/test/boot-work.test.ts +0 -215
- package/test/browser-attach.test.ts +0 -150
- package/test/browser-idle.test.ts +0 -107
- package/test/bus-session-routing.test.ts +0 -334
- package/test/bus-unpersisted.test.ts +0 -50
- package/test/bus.test.ts +0 -1347
- package/test/catalog.test.ts +0 -704
- package/test/codemode/catalog.test.ts +0 -339
- package/test/codemode/diffs.test.ts +0 -90
- package/test/codemode/instructions.test.ts +0 -123
- package/test/codemode-execute-options.test.ts +0 -172
- package/test/codemode-script-diffs.test.ts +0 -131
- package/test/codemode.test.ts +0 -132
- package/test/command.test.ts +0 -71
- package/test/config/agent.test.ts +0 -847
- package/test/config/command-subagent.test.ts +0 -165
- package/test/config/command.test.ts +0 -628
- package/test/config/compaction.test.ts +0 -184
- package/test/config/config.test.ts +0 -2113
- package/test/config/discovery.test.ts +0 -150
- package/test/config/entry-observer.test.ts +0 -51
- package/test/config/image.test.ts +0 -78
- package/test/config/markdown.test.ts +0 -129
- package/test/config/model.test.ts +0 -28
- package/test/config/normalization.test.ts +0 -854
- package/test/config/overlay.test.ts +0 -205
- package/test/config/policy.test.ts +0 -432
- package/test/config/provider-options.test.ts +0 -55
- package/test/config/provider.test.ts +0 -1338
- package/test/config/reload.test.ts +0 -526
- package/test/config/session-search.test.ts +0 -61
- package/test/config/shell.test.ts +0 -42
- package/test/config/skill.test.ts +0 -602
- package/test/config/snapshot.test.ts +0 -61
- package/test/config/tool-output.test.ts +0 -59
- package/test/config/watch.test.ts +0 -53
- package/test/config/websearch.test.ts +0 -45
- package/test/credential-refresh.test.ts +0 -113
- package/test/credential.test.ts +0 -271
- package/test/database-drizzle.test.ts +0 -228
- package/test/database-migration.test.ts +0 -783
- package/test/database.test.ts +0 -39
- package/test/effect/cross-spawn-spawner.test.ts +0 -522
- package/test/effect/keyed-mutex.test.ts +0 -73
- package/test/effect/layer-node/layer-node-types.test.ts +0 -230
- package/test/effect/layer-node/layer-node.test.ts +0 -467
- package/test/effect/layer-node/node-build.test.ts +0 -148
- package/test/effect/observability.test.ts +0 -141
- package/test/effect-app-node-platform.test.ts +0 -86
- package/test/effect-simplification-types.test.ts +0 -12
- package/test/environment.test.ts +0 -154
- package/test/environments.test.ts +0 -406
- package/test/event-logger.test.ts +0 -50
- package/test/file-access-path.test.ts +0 -336
- package/test/file-access.test.ts +0 -178
- package/test/file-mutation.test.ts +0 -244
- package/test/filesystem/file-watch.test.ts +0 -213
- package/test/filesystem/filesystem.test.ts +0 -383
- package/test/filesystem/location-watcher-policy.test.ts +0 -70
- package/test/filesystem/search.test.ts +0 -385
- package/test/filesystem/watcher.test.ts +0 -719
- package/test/flag.test.ts +0 -203
- package/test/form.test.ts +0 -357
- package/test/formatter-target-environment.test.ts +0 -138
- package/test/formatter.test.ts +0 -350
- package/test/generate.test.ts +0 -752
- package/test/git.test.ts +0 -666
- package/test/github-copilot/models.test.ts +0 -167
- package/test/image-photon.test.ts +0 -177
- package/test/instance-vanilla.test.ts +0 -124
- package/test/instruction-discovery.test.ts +0 -804
- package/test/instruction-state.test.ts +0 -537
- package/test/instructions/builtins.test.ts +0 -83
- package/test/instructions/index.test.ts +0 -248
- package/test/integration-refresh.test.ts +0 -118
- package/test/integration.test.ts +0 -716
- package/test/job.test.ts +0 -968
- package/test/kv.test.ts +0 -81
- package/test/location-activity.test.ts +0 -315
- package/test/location-filesystem.test.ts +0 -332
- package/test/location-layer.test.ts +0 -784
- package/test/location-missing-project.test.ts +0 -71
- package/test/location-retain.test.ts +0 -98
- package/test/location.test.ts +0 -46
- package/test/logging.test.ts +0 -14
- package/test/machine-frames.test.ts +0 -768
- package/test/machine-instructions.test.ts +0 -135
- package/test/machine-join.test.ts +0 -223
- package/test/machine-link.test.ts +0 -527
- package/test/machine-noise.test.ts +0 -429
- package/test/machine-path.test.ts +0 -1202
- package/test/machine.test.ts +0 -786
- package/test/machines.test.ts +0 -730
- package/test/mcp-attach.test.ts +0 -403
- package/test/mcp-events.test.ts +0 -299
- package/test/mcp-import-boundary.test.ts +0 -44
- package/test/mcp-instructions.test.ts +0 -221
- package/test/mcp-oauth.test.ts +0 -1289
- package/test/mcp-skills.test.ts +0 -274
- package/test/mcp-socket-client.test.ts +0 -210
- package/test/mcp-stdio.test.ts +0 -145
- package/test/mcp.test.ts +0 -4196
- package/test/mime.test.ts +0 -80
- package/test/modal/models.test.ts +0 -137
- package/test/model-free.test.ts +0 -120
- package/test/model-plugins.test.ts +0 -469
- package/test/model-resolver.test.ts +0 -1695
- package/test/model.test.ts +0 -16
- package/test/models.test.ts +0 -1404
- package/test/network-guard.test.ts +0 -56
- package/test/npm-config.test.ts +0 -42
- package/test/npm.test.ts +0 -545
- package/test/oauth-page.test.ts +0 -15
- package/test/opencode-api-skill.test.ts +0 -16
- package/test/patch.test.ts +0 -509
- package/test/permission.test.ts +0 -1179
- package/test/persistent-pty-daemon.test.ts +0 -337
- package/test/persistent-pty-session.test.ts +0 -295
- package/test/plugin/automation.test.ts +0 -124
- package/test/plugin/command.test.ts +0 -137
- package/test/plugin/goal-watchdog.test.ts +0 -212
- package/test/plugin/goal.test.ts +0 -609
- package/test/plugin/home-memory.test.ts +0 -131
- package/test/plugin/host-model.test.ts +0 -34
- package/test/plugin/identity.test.ts +0 -60
- package/test/plugin/internal-flag.test.ts +0 -101
- package/test/plugin/mcp-codemode-defaults.test.ts +0 -124
- package/test/plugin/models-dev.test.ts +0 -1406
- package/test/plugin/module.test.ts +0 -494
- package/test/plugin/optimize.test.ts +0 -343
- package/test/plugin/permission-assert.test.ts +0 -94
- package/test/plugin/plan.test.ts +0 -162
- package/test/plugin/promise-tool-cancel.test.ts +0 -279
- package/test/plugin/promise-tool.test.ts +0 -227
- package/test/plugin/provider/claude-agent/claude/accounts.test.ts +0 -326
- package/test/plugin/provider/claude-agent/claude/branches.test.ts +0 -300
- package/test/plugin/provider/claude-agent/claude/probe.test.ts +0 -99
- package/test/plugin/provider/claude-agent/claude/recorder.test.ts +0 -19
- package/test/plugin/provider/claude-agent/claude/session.test.ts +0 -30
- package/test/plugin/provider/claude-agent/claude/sessions.test.ts +0 -490
- package/test/plugin/provider/claude-agent/claude/status.test.ts +0 -67
- package/test/plugin/provider/claude-agent/claude/sync.test.ts +0 -70
- package/test/plugin/provider/claude-agent/claude/tools.test.ts +0 -382
- package/test/plugin/provider/claude-agent/language-model/convert.test.ts +0 -95
- package/test/plugin/provider/claude-agent/language-model/error.test.ts +0 -94
- package/test/plugin/provider/claude-agent/plugin.test.ts +0 -651
- package/test/plugin/provider/claude-agent/sync/sync.test.ts +0 -213
- package/test/plugin/provider/claude-agent/tools/tools.test.ts +0 -85
- package/test/plugin/provider/claude-agent/websearch.test.ts +0 -106
- package/test/plugin/provider-amazon-bedrock.test.ts +0 -225
- package/test/plugin/provider-azure.test.ts +0 -793
- package/test/plugin/provider-cerebras.test.ts +0 -62
- package/test/plugin/provider-chatgpt.test.ts +0 -1278
- package/test/plugin/provider-cloudflare-ai-gateway.test.ts +0 -160
- package/test/plugin/provider-cloudflare-workers-ai.test.ts +0 -158
- package/test/plugin/provider-databricks.test.ts +0 -45
- package/test/plugin/provider-digitalocean.test.ts +0 -322
- package/test/plugin/provider-dynamic.test.ts +0 -179
- package/test/plugin/provider-github-copilot.test.ts +0 -806
- package/test/plugin/provider-gitlab-oauth.test.ts +0 -407
- package/test/plugin/provider-gitlab.test.ts +0 -546
- package/test/plugin/provider-google-vertex.test.ts +0 -288
- package/test/plugin/provider-kilo.test.ts +0 -66
- package/test/plugin/provider-llmgateway.test.ts +0 -72
- package/test/plugin/provider-lmstudio.test.ts +0 -487
- package/test/plugin/provider-nvidia.test.ts +0 -84
- package/test/plugin/provider-ollama.test.ts +0 -312
- package/test/plugin/provider-openai-context-caps.test.ts +0 -80
- package/test/plugin/provider-openai.test.ts +0 -447
- package/test/plugin/provider-opencode-artifacts.test.ts +0 -236
- package/test/plugin/provider-opencode-watches.test.ts +0 -1103
- package/test/plugin/provider-opencode.test.ts +0 -2590
- package/test/plugin/provider-openrouter.test.ts +0 -83
- package/test/plugin/provider-poe.test.ts +0 -360
- package/test/plugin/provider-sap-ai-core.test.ts +0 -138
- package/test/plugin/provider-snowflake-cortex.test.ts +0 -294
- package/test/plugin/provider-vllm.test.ts +0 -382
- package/test/plugin/provider-xai.test.ts +0 -92
- package/test/plugin/provider-zenmux.test.ts +0 -100
- package/test/plugin/session-compact.test.ts +0 -52
- package/test/plugin/session-instructions.test.ts +0 -197
- package/test/plugin/session-list.test.ts +0 -52
- package/test/plugin/session-remove.test.ts +0 -61
- package/test/plugin/skill.test.ts +0 -81
- package/test/plugin/supervisor-reload.test.ts +0 -401
- package/test/plugin/supervisor.test.ts +0 -485
- package/test/plugin/tool-input-repair-integration.test.ts +0 -296
- package/test/plugin/tool-input-repair.test.ts +0 -457
- package/test/plugin/vcs-init.test.ts +0 -48
- package/test/plugin/verbosity.test.ts +0 -163
- package/test/plugin/warming.test.ts +0 -314
- package/test/plugin/websearch.test.ts +0 -368
- package/test/plugin/worktree.test.ts +0 -52
- package/test/plugin-failure.test.ts +0 -305
- package/test/plugin.test.ts +0 -756
- package/test/preload.test.ts +0 -32
- package/test/process/process.test.ts +0 -340
- package/test/project-activate.test.ts +0 -144
- package/test/project-icon.test.ts +0 -198
- package/test/project.test.ts +0 -754
- package/test/provider.test.ts +0 -92
- package/test/pty/info-schema.test.ts +0 -23
- package/test/pty/protocol.test.ts +0 -27
- package/test/pty/pty-session.test.ts +0 -224
- package/test/pty/pty-windows.test.ts +0 -41
- package/test/pty/ticket.test.ts +0 -76
- package/test/push-list.test.ts +0 -257
- package/test/push-sender.test.ts +0 -235
- package/test/push-watcher.test.ts +0 -359
- package/test/reference-instructions.test.ts +0 -112
- package/test/reference.test.ts +0 -209
- package/test/repository-cache.test.ts +0 -235
- package/test/repository.test.ts +0 -89
- package/test/ripgrep.test.ts +0 -253
- package/test/rpc-handler-errors.test.ts +0 -62
- package/test/session-activation.test.ts +0 -75
- package/test/session-archive.test.ts +0 -81
- package/test/session-background.test.ts +0 -97
- package/test/session-checkpoint-transport.test.ts +0 -168
- package/test/session-compact.test.ts +0 -171
- package/test/session-compaction-transport.test.ts +0 -131
- package/test/session-compaction.test.ts +0 -1871
- package/test/session-create.test.ts +0 -1643
- package/test/session-cwd-instructions.test.ts +0 -304
- package/test/session-cwd.test.ts +0 -484
- package/test/session-diff.test.ts +0 -207
- package/test/session-environment.test.ts +0 -30
- package/test/session-error.test.ts +0 -434
- package/test/session-execution.test.ts +0 -2298
- package/test/session-generate.test.ts +0 -502
- package/test/session-instructions.test.ts +0 -378
- package/test/session-list.test.ts +0 -72
- package/test/session-live-tool-metadata.test.ts +0 -43
- package/test/session-log.test.ts +0 -123
- package/test/session-model-request-hooks.test.ts +0 -270
- package/test/session-model-request.test.ts +0 -243
- package/test/session-model-transport-live.test.ts +0 -329
- package/test/session-model-transport.test.ts +0 -1109
- package/test/session-move.test.ts +0 -671
- package/test/session-native-compaction.test.ts +0 -425
- package/test/session-native.test.ts +0 -359
- package/test/session-owned.test.ts +0 -1073
- package/test/session-projector.test.ts +0 -2797
- package/test/session-prompt.test.ts +0 -1549
- package/test/session-remove.test.ts +0 -117
- package/test/session-revert.test.ts +0 -121
- package/test/session-run-coordinator.test.ts +0 -711
- package/test/session-runner-message.test.ts +0 -1574
- package/test/session-runner-recorded.test.ts +0 -288
- package/test/session-runner-retry.test.ts +0 -130
- package/test/session-runner-tool-events.test.ts +0 -662
- package/test/session-runner.test.ts +0 -7859
- package/test/session-search-build.test.ts +0 -214
- package/test/session-search-index.test.ts +0 -524
- package/test/session-search.test.ts +0 -375
- package/test/session-shell.test.ts +0 -437
- package/test/session-skill.test.ts +0 -228
- package/test/session-stats.test.ts +0 -429
- package/test/session-step.test.ts +0 -435
- package/test/session-store.test.ts +0 -543
- package/test/session-system-prompt.test.ts +0 -8
- package/test/session-title.test.ts +0 -767
- package/test/session-tool-progress.test.ts +0 -159
- package/test/session-usage.test.ts +0 -24
- package/test/session-view.test.ts +0 -218
- package/test/session-wait.test.ts +0 -41
- package/test/shared-cache.test.ts +0 -161
- package/test/shared-schema.test.ts +0 -187
- package/test/shell-cleanup.test.ts +0 -52
- package/test/shell-daemon.test.ts +0 -663
- package/test/shell-parse-compatibility.test.ts +0 -451
- package/test/shell-parse-parity.test.ts +0 -170
- package/test/shell-parse-syntax.test.ts +0 -201
- package/test/shell-parse.test.ts +0 -251
- package/test/shell-restart.test.ts +0 -268
- package/test/shell-result.test.ts +0 -65
- package/test/shell-retention.test.ts +0 -162
- package/test/shell-scan/adversarial.test.ts +0 -112
- package/test/shell-scan/arithmetic.test.ts +0 -143
- package/test/shell-scan/bash-safety.test.ts +0 -291
- package/test/shell-scan/bash-syntax.test.ts +0 -361
- package/test/shell-scan/closure.test.ts +0 -47
- package/test/shell-scan/compound-parity.test.ts +0 -131
- package/test/shell-scan/generated.test.ts +0 -201
- package/test/shell-scan/oracle.test.ts +0 -762
- package/test/shell-scan/parity-regressions.test.ts +0 -146
- package/test/shell-scan/powershell-runtime.test.ts +0 -604
- package/test/shell-scan/powershell-safety.test.ts +0 -470
- package/test/shell-scan/powershell-syntax.test.ts +0 -177
- package/test/shell-scan/redirect.test.ts +0 -168
- package/test/shell-scan/scan.test.ts +0 -496
- package/test/shell.test.ts +0 -140
- package/test/skill/instructions.test.ts +0 -216
- package/test/skill-discovery.test.ts +0 -154
- package/test/skill.test.ts +0 -297
- package/test/snapshot.test.ts +0 -488
- package/test/sqlite-bundle.test.ts +0 -53
- package/test/sqlite-interrupt.test.ts +0 -86
- package/test/sqlite-node.test.ts +0 -80
- package/test/sqlite-workerd.test.ts +0 -111
- package/test/state-group.test.ts +0 -138
- package/test/state-replay.test.ts +0 -207
- package/test/state.test.ts +0 -679
- package/test/storage-failure.test.ts +0 -88
- package/test/subagent-completion.test.ts +0 -170
- package/test/subagent-idle-e2e.test.ts +0 -825
- package/test/subagent-lifetime.test.ts +0 -146
- package/test/subagent-report.test.ts +0 -834
- package/test/tool/file-diff.test.ts +0 -45
- package/test/tool-automation.test.ts +0 -345
- package/test/tool-cd.test.ts +0 -372
- package/test/tool-edit.test.ts +0 -888
- package/test/tool-execute.test.ts +0 -1077
- package/test/tool-html-markdown-budget.test.ts +0 -68
- package/test/tool-image-generate.test.ts +0 -547
- package/test/tool-machine.test.ts +0 -84
- package/test/tool-mcp-events.test.ts +0 -90
- package/test/tool-media-target-environment.test.ts +0 -213
- package/test/tool-model-policy.test.ts +0 -289
- package/test/tool-opencode.test.ts +0 -303
- package/test/tool-output.test.ts +0 -334
- package/test/tool-patch-target-environment.test.ts +0 -239
- package/test/tool-patch.test.ts +0 -1265
- package/test/tool-question.test.ts +0 -260
- package/test/tool-read-filesystem.test.ts +0 -833
- package/test/tool-read.test.ts +0 -1341
- package/test/tool-registry.test.ts +0 -1662
- package/test/tool-schema.test.ts +0 -538
- package/test/tool-search-target-environment.test.ts +0 -103
- package/test/tool-search.test.ts +0 -411
- package/test/tool-session-search.test.ts +0 -178
- package/test/tool-shell-target-environment.test.ts +0 -193
- package/test/tool-shell.test.ts +0 -2650
- package/test/tool-skill.test.ts +0 -203
- package/test/tool-subagent.test.ts +0 -1046
- package/test/tool-target-environment.test.ts +0 -183
- package/test/tool-todo.test.ts +0 -75
- package/test/tool-video-generate.test.ts +0 -227
- package/test/tool-webfetch.test.ts +0 -737
- package/test/tool-websearch.test.ts +0 -482
- package/test/tool-write.test.ts +0 -440
- package/test/usage-limits.test.ts +0 -210
- package/test/util/effect-flock.test.ts +0 -331
- package/test/util/error-summary.test.ts +0 -19
- package/test/util/flock.test.ts +0 -326
- package/test/util/fs-util.test.ts +0 -50
- package/test/util/git-executable.test.ts +0 -80
- package/test/util/which.test.ts +0 -99
- package/test/v1-migration.test.ts +0 -1508
- package/test/variant.test.ts +0 -575
- package/test/vcs-hg.test.ts +0 -239
- package/test/vcs.test.ts +0 -1396
- package/test/video-generation.test.ts +0 -146
- package/test/voice.test.ts +0 -332
- package/test/websearch.test.ts +0 -593
- package/test/wellknown.test.ts +0 -132
- package/test/worker-client.test.ts +0 -529
- package/test/workspace.test.ts +0 -828
- package/test/worktree.test.ts +0 -944
|
@@ -1,2797 +0,0 @@
|
|
|
1
|
-
import { describe, expect } from "bun:test"
|
|
2
|
-
import { DateTime, Effect, Fiber, Layer, Option, Schema, Stream } from "effect"
|
|
3
|
-
import { TestClock } from "effect/testing"
|
|
4
|
-
import { and, asc, eq, sql } from "drizzle-orm"
|
|
5
|
-
import { Database } from "@zyro-sec/core/database/database"
|
|
6
|
-
import { sqliteLayer } from "@zyro-sec/core/database/sqlite.workerd"
|
|
7
|
-
import { Agent } from "@zyro-sec/core/agent"
|
|
8
|
-
import { LayerNode } from "@zyro-sec/util/effect/layer-node"
|
|
9
|
-
import { AppNodeBuilder } from "@zyro-sec/core/effect/app-node-builder"
|
|
10
|
-
import { Bus } from "@zyro-sec/core/bus"
|
|
11
|
-
import { Event } from "@zyro-sec/schema/event"
|
|
12
|
-
import { EventTable } from "@zyro-sec/core/event/sql"
|
|
13
|
-
import { Model } from "@zyro-sec/core/model"
|
|
14
|
-
import { Project } from "@zyro-sec/core/project"
|
|
15
|
-
import { ProjectTable } from "@zyro-sec/core/project/sql"
|
|
16
|
-
import { Provider } from "@zyro-sec/core/provider"
|
|
17
|
-
import { AbsolutePath, RelativePath } from "@zyro-sec/core/schema"
|
|
18
|
-
import { Session } from "@zyro-sec/core/session"
|
|
19
|
-
import { SessionEvent } from "@zyro-sec/core/session/event"
|
|
20
|
-
import { SessionMessage } from "@zyro-sec/core/session/message"
|
|
21
|
-
import { Money } from "@zyro-sec/schema/money"
|
|
22
|
-
import { SessionProjector } from "@zyro-sec/core/session/projector"
|
|
23
|
-
import { SessionExecution } from "@zyro-sec/core/session/execution"
|
|
24
|
-
import { fromRow } from "@zyro-sec/core/session/info"
|
|
25
|
-
import { SessionInbox } from "@zyro-sec/core/session/inbox"
|
|
26
|
-
import { SessionStore } from "@zyro-sec/core/session/store"
|
|
27
|
-
import { SessionStored } from "@zyro-sec/core/session/stored"
|
|
28
|
-
import { SessionBlob } from "@zyro-sec/core/session/blob"
|
|
29
|
-
import { Flag } from "@zyro-sec/core/flag"
|
|
30
|
-
import { Document, Info } from "@zyro-sec/schema/config"
|
|
31
|
-
import { ConfigExperimental } from "@zyro-sec/schema/config/experimental"
|
|
32
|
-
import { SessionHistory } from "@zyro-sec/core/session/history"
|
|
33
|
-
import { Shell } from "@zyro-sec/schema/shell"
|
|
34
|
-
import {
|
|
35
|
-
InstructionStateTable,
|
|
36
|
-
BlobRefTable,
|
|
37
|
-
BlobTable,
|
|
38
|
-
SessionInboxTable,
|
|
39
|
-
SessionMessageTable,
|
|
40
|
-
SessionPartTable,
|
|
41
|
-
SessionTable,
|
|
42
|
-
} from "@zyro-sec/core/session/sql"
|
|
43
|
-
import { testEffect } from "./lib/effect"
|
|
44
|
-
import { makeDurableObjectStorage } from "./fixture/durable-object-storage"
|
|
45
|
-
import { Snapshot } from "@zyro-sec/core/snapshot"
|
|
46
|
-
|
|
47
|
-
const it = testEffect(
|
|
48
|
-
AppNodeBuilder.build(
|
|
49
|
-
LayerNode.group([Database.node, Bus.node, SessionProjector.node, SessionInbox.node, SessionStore.node]),
|
|
50
|
-
[Bus.node.replace(Bus.configured({ persist: true }))],
|
|
51
|
-
),
|
|
52
|
-
)
|
|
53
|
-
// Durable Object SQLite, which rejects statements that bind more than 100 parameters.
|
|
54
|
-
const durableIt = testEffect(
|
|
55
|
-
AppNodeBuilder.build(
|
|
56
|
-
LayerNode.group([Database.node, Bus.node, SessionProjector.node, SessionInbox.node, SessionStore.node]),
|
|
57
|
-
[
|
|
58
|
-
Bus.node.replace(Bus.configured({ persist: true })),
|
|
59
|
-
Database.node.replace(
|
|
60
|
-
Database.configuredClient(Layer.suspend(() => sqliteLayer({ storage: makeDurableObjectStorage() }))),
|
|
61
|
-
),
|
|
62
|
-
],
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
const sessionsLayer = AppNodeBuilder.build(Session.node, [SessionExecution.node.replace(SessionExecution.noopLayer)])
|
|
66
|
-
const sessionID = Session.ID.make("ses_projector_test")
|
|
67
|
-
const created = DateTime.makeUnsafe(0)
|
|
68
|
-
const model = { id: Model.ID.make("model"), providerID: Provider.ID.make("provider") }
|
|
69
|
-
const previousModel = { ...model, variant: Model.VariantID.make("medium") }
|
|
70
|
-
const encodeMessage = Schema.encodeSync(SessionMessage.Info)
|
|
71
|
-
const experimental = (flags: ConstructorParameters<typeof ConfigExperimental.Info>[0]) =>
|
|
72
|
-
Flag.testLayer([
|
|
73
|
-
new Document({ type: "document", info: new Info({ experimental: new ConfigExperimental.Info(flags) }) }),
|
|
74
|
-
])
|
|
75
|
-
const mediaBlob = experimental({ media_blob: true })
|
|
76
|
-
const partRows = experimental({ part_rows: true })
|
|
77
|
-
const partRowsOff = experimental({ part_rows: false })
|
|
78
|
-
const mediaBlobPartRows = experimental({ media_blob: true, part_rows: true })
|
|
79
|
-
const png = Buffer.from(
|
|
80
|
-
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
|
|
81
|
-
"base64",
|
|
82
|
-
)
|
|
83
|
-
const attachment = (name: string, bytes = png, mime = "image/png") => ({
|
|
84
|
-
data: bytes.toString("base64"),
|
|
85
|
-
mime,
|
|
86
|
-
source: { type: "inline" as const },
|
|
87
|
-
name,
|
|
88
|
-
})
|
|
89
|
-
const build = Agent.defaultID
|
|
90
|
-
|
|
91
|
-
const assistantRow = (
|
|
92
|
-
id: SessionMessage.ID,
|
|
93
|
-
seq: number,
|
|
94
|
-
time: { created: DateTime.Utc; completed?: DateTime.Utc } = { created },
|
|
95
|
-
usage?: Pick<SessionMessage.Assistant, "cost" | "tokens">,
|
|
96
|
-
) => {
|
|
97
|
-
const {
|
|
98
|
-
id: _,
|
|
99
|
-
type,
|
|
100
|
-
...data
|
|
101
|
-
} = encodeMessage(
|
|
102
|
-
SessionMessage.Assistant.make({ id, type: "assistant", agent: build, model, content: [], time, ...usage }),
|
|
103
|
-
)
|
|
104
|
-
return { id, session_id: sessionID, type, seq, time_created: DateTime.toEpochMillis(time.created), data }
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const seedSession = (overrides?: Partial<typeof SessionTable.$inferInsert>) =>
|
|
108
|
-
Effect.gen(function* () {
|
|
109
|
-
const db = (yield* Database.Service).db
|
|
110
|
-
yield* db
|
|
111
|
-
.insert(ProjectTable)
|
|
112
|
-
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
|
113
|
-
.run()
|
|
114
|
-
yield* db
|
|
115
|
-
.insert(SessionTable)
|
|
116
|
-
.values({
|
|
117
|
-
id: sessionID,
|
|
118
|
-
project_id: Project.ID.global,
|
|
119
|
-
slug: "test",
|
|
120
|
-
directory: "/project",
|
|
121
|
-
title: "test",
|
|
122
|
-
version: "test",
|
|
123
|
-
...overrides,
|
|
124
|
-
})
|
|
125
|
-
.run()
|
|
126
|
-
return db
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
describe("SessionProjector", () => {
|
|
130
|
-
it.effect("does not settle a pending manual compaction on an auto failure", () =>
|
|
131
|
-
Effect.gen(function* () {
|
|
132
|
-
const db = yield* seedSession()
|
|
133
|
-
const bus = yield* Bus.Service
|
|
134
|
-
const inbox = yield* SessionInbox.Service
|
|
135
|
-
const inputID = SessionMessage.ID.make("msg_manual_compaction")
|
|
136
|
-
yield* inbox.admitCompaction({ id: inputID, sessionID, delivery: "queue" })
|
|
137
|
-
|
|
138
|
-
yield* bus.publish(SessionEvent.Compaction.Failed, {
|
|
139
|
-
sessionID,
|
|
140
|
-
reason: "auto",
|
|
141
|
-
error: { type: "compaction.failed", message: "Auto compaction failed" },
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
expect(yield* SessionInbox.find(db, inputID)).toMatchObject({ id: inputID })
|
|
145
|
-
}),
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
it.effect("loads legacy revert storage into canonical state", () =>
|
|
149
|
-
Effect.gen(function* () {
|
|
150
|
-
const db = yield* seedSession()
|
|
151
|
-
const legacy = JSON.stringify({
|
|
152
|
-
messageID: "msg_boundary",
|
|
153
|
-
snapshot: "tree",
|
|
154
|
-
diff: "legacy patch",
|
|
155
|
-
files: [{ path: "src/old.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" }],
|
|
156
|
-
})
|
|
157
|
-
yield* db.run(sql`update session_v2 set revert = ${legacy} where id = ${sessionID}`)
|
|
158
|
-
const stored = yield* db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get()
|
|
159
|
-
if (!stored) return yield* Effect.die("Session row missing")
|
|
160
|
-
const storedRevert = fromRow(stored).revert
|
|
161
|
-
expect(String(storedRevert?.messageID)).toBe("msg_boundary")
|
|
162
|
-
expect(String(storedRevert?.snapshot)).toBe("tree")
|
|
163
|
-
expect(storedRevert?.files).toEqual([
|
|
164
|
-
{ file: "src/old.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" },
|
|
165
|
-
])
|
|
166
|
-
}),
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
it.effect("projects staged, cleared, and committed reverts", () =>
|
|
170
|
-
Effect.gen(function* () {
|
|
171
|
-
const db = yield* seedSession({
|
|
172
|
-
cost: 1.25,
|
|
173
|
-
tokens_input: 10,
|
|
174
|
-
tokens_output: 4,
|
|
175
|
-
tokens_reasoning: 2,
|
|
176
|
-
tokens_cache_read: 3,
|
|
177
|
-
tokens_cache_write: 1,
|
|
178
|
-
})
|
|
179
|
-
const boundary = SessionMessage.ID.make("msg_boundary")
|
|
180
|
-
const earlier = SessionMessage.ID.make("msg_earlier")
|
|
181
|
-
yield* db
|
|
182
|
-
.insert(SessionMessageTable)
|
|
183
|
-
.values([
|
|
184
|
-
assistantRow(earlier, 0),
|
|
185
|
-
assistantRow(
|
|
186
|
-
boundary,
|
|
187
|
-
1,
|
|
188
|
-
{ created },
|
|
189
|
-
{
|
|
190
|
-
cost: Money.USD.make(0.5),
|
|
191
|
-
tokens: { input: 4, output: 1, reasoning: 1, cache: { read: 1, write: 0 } },
|
|
192
|
-
},
|
|
193
|
-
),
|
|
194
|
-
assistantRow(
|
|
195
|
-
SessionMessage.ID.make("msg_later"),
|
|
196
|
-
2,
|
|
197
|
-
{ created },
|
|
198
|
-
{
|
|
199
|
-
cost: Money.USD.make(0.75),
|
|
200
|
-
tokens: { input: 6, output: 3, reasoning: 1, cache: { read: 2, write: 1 } },
|
|
201
|
-
},
|
|
202
|
-
),
|
|
203
|
-
])
|
|
204
|
-
.run()
|
|
205
|
-
yield* db
|
|
206
|
-
.insert(InstructionStateTable)
|
|
207
|
-
.values({
|
|
208
|
-
session_id: sessionID,
|
|
209
|
-
epoch_start: 0,
|
|
210
|
-
through_seq: 0,
|
|
211
|
-
initial_values: {},
|
|
212
|
-
current_values: {},
|
|
213
|
-
})
|
|
214
|
-
.run()
|
|
215
|
-
const bus = yield* Bus.Service
|
|
216
|
-
yield* bus.publish(SessionEvent.RevertEvent.Staged, {
|
|
217
|
-
sessionID,
|
|
218
|
-
revert: { messageID: boundary, snapshot: Snapshot.ID.make("tree"), files: [] },
|
|
219
|
-
})
|
|
220
|
-
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toMatchObject({
|
|
221
|
-
messageID: boundary,
|
|
222
|
-
snapshot: "tree",
|
|
223
|
-
files: [],
|
|
224
|
-
})
|
|
225
|
-
yield* bus.publish(SessionEvent.RevertEvent.Cleared, { sessionID })
|
|
226
|
-
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toBeNull()
|
|
227
|
-
yield* bus.publish(SessionEvent.RevertEvent.Staged, {
|
|
228
|
-
sessionID,
|
|
229
|
-
revert: { messageID: boundary, files: [] },
|
|
230
|
-
})
|
|
231
|
-
yield* bus.publish(SessionEvent.RevertEvent.Committed, {
|
|
232
|
-
sessionID,
|
|
233
|
-
to: boundary,
|
|
234
|
-
})
|
|
235
|
-
expect(
|
|
236
|
-
(yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).all()).map((row) => row.id),
|
|
237
|
-
).toEqual([earlier])
|
|
238
|
-
expect(yield* db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get()).toMatchObject({
|
|
239
|
-
cost: Money.USD.make(1.25),
|
|
240
|
-
tokens_input: 10,
|
|
241
|
-
tokens_output: 4,
|
|
242
|
-
tokens_reasoning: 2,
|
|
243
|
-
tokens_cache_read: 3,
|
|
244
|
-
tokens_cache_write: 1,
|
|
245
|
-
})
|
|
246
|
-
// No instruction update followed the boundary, so the fold survives.
|
|
247
|
-
expect(yield* db.select().from(InstructionStateTable).get().pipe(Effect.orDie)).toMatchObject({ through_seq: 0 })
|
|
248
|
-
}),
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
it.effect("orders projected messages and context by durable aggregate sequence", () =>
|
|
252
|
-
Effect.gen(function* () {
|
|
253
|
-
yield* seedSession()
|
|
254
|
-
const bus = yield* Bus.Service
|
|
255
|
-
|
|
256
|
-
yield* bus.publish(SessionEvent.InboxEnqueued, {
|
|
257
|
-
sessionID,
|
|
258
|
-
inboxID: SessionMessage.ID.make("msg_first"),
|
|
259
|
-
item: { type: "user", payload: { text: "first" }, delivery: "steer" },
|
|
260
|
-
})
|
|
261
|
-
yield* bus.publish(
|
|
262
|
-
SessionEvent.InboxDelivered,
|
|
263
|
-
{
|
|
264
|
-
sessionID,
|
|
265
|
-
inboxID: SessionMessage.ID.make("msg_first"),
|
|
266
|
-
},
|
|
267
|
-
{ id: Event.ID.make("evt_z") },
|
|
268
|
-
)
|
|
269
|
-
yield* bus.publish(SessionEvent.InboxEnqueued, {
|
|
270
|
-
sessionID,
|
|
271
|
-
inboxID: SessionMessage.ID.make("msg_second"),
|
|
272
|
-
item: { type: "user", payload: { text: "second" }, delivery: "steer" },
|
|
273
|
-
})
|
|
274
|
-
yield* bus.publish(
|
|
275
|
-
SessionEvent.InboxDelivered,
|
|
276
|
-
{
|
|
277
|
-
sessionID,
|
|
278
|
-
inboxID: SessionMessage.ID.make("msg_second"),
|
|
279
|
-
},
|
|
280
|
-
{ id: Event.ID.make("evt_a") },
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
const sessions = yield* Session.Service
|
|
284
|
-
const firstPage = yield* sessions.messages({ sessionID, limit: 1, order: "asc" })
|
|
285
|
-
expect(firstPage.map((message) => (message.type === "user" ? message.text : message.type))).toEqual(["first"])
|
|
286
|
-
const secondPage = yield* sessions.messages({
|
|
287
|
-
sessionID,
|
|
288
|
-
limit: 1,
|
|
289
|
-
order: "asc",
|
|
290
|
-
cursor: { id: firstPage[0]!.id, direction: "next" },
|
|
291
|
-
})
|
|
292
|
-
expect(secondPage.map((message) => (message.type === "user" ? message.text : message.type))).toEqual(["second"])
|
|
293
|
-
expect(
|
|
294
|
-
(yield* sessions.messages({
|
|
295
|
-
sessionID,
|
|
296
|
-
limit: 1,
|
|
297
|
-
order: "asc",
|
|
298
|
-
cursor: { id: secondPage[0]!.id, direction: "previous" },
|
|
299
|
-
})).map((message) => (message.type === "user" ? message.text : message.type)),
|
|
300
|
-
).toEqual(["first"])
|
|
301
|
-
expect(
|
|
302
|
-
(yield* sessions.context(sessionID)).map((message) => (message.type === "user" ? message.text : message.type)),
|
|
303
|
-
).toEqual(["first", "second"])
|
|
304
|
-
}).pipe(Effect.provide(sessionsLayer)),
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
it.effect("maps malformed persisted rows consistently while single-message lookup defects", () =>
|
|
308
|
-
Effect.gen(function* () {
|
|
309
|
-
const db = yield* seedSession()
|
|
310
|
-
const messageID = SessionMessage.ID.make("msg_malformed")
|
|
311
|
-
yield* db
|
|
312
|
-
.insert(SessionMessageTable)
|
|
313
|
-
.values({
|
|
314
|
-
id: messageID,
|
|
315
|
-
session_id: sessionID,
|
|
316
|
-
type: "user",
|
|
317
|
-
seq: 0,
|
|
318
|
-
data: { text: "valid before corruption", time: { created: 0 } },
|
|
319
|
-
})
|
|
320
|
-
.run()
|
|
321
|
-
.pipe(Effect.orDie)
|
|
322
|
-
yield* db.run(sql`update session_message set data = '{"time":{"created":0}}' where id = ${messageID}`)
|
|
323
|
-
|
|
324
|
-
const sessions = yield* Session.Service
|
|
325
|
-
const store = yield* SessionStore.Service
|
|
326
|
-
const expected = { _tag: "Session.MessageDecodeError", sessionID, messageID }
|
|
327
|
-
expect(yield* store.messages({ sessionID }).pipe(Effect.flip)).toMatchObject(expected)
|
|
328
|
-
expect(yield* sessions.messages({ sessionID }).pipe(Effect.flip)).toMatchObject(expected)
|
|
329
|
-
expect(yield* sessions.context(sessionID).pipe(Effect.flip)).toMatchObject(expected)
|
|
330
|
-
expect(yield* sessions.message({ sessionID, messageID }).pipe(Effect.catchDefect(Effect.succeed))).toMatchObject(
|
|
331
|
-
expected,
|
|
332
|
-
)
|
|
333
|
-
}).pipe(Effect.provide(sessionsLayer)),
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
it.effect("checks session existence before resolving a missing message cursor", () =>
|
|
337
|
-
Effect.gen(function* () {
|
|
338
|
-
const sessions = yield* Session.Service
|
|
339
|
-
const missing = Session.ID.make("ses_missing")
|
|
340
|
-
expect(
|
|
341
|
-
yield* sessions
|
|
342
|
-
.messages({
|
|
343
|
-
sessionID: missing,
|
|
344
|
-
cursor: { id: SessionMessage.ID.make("msg_missing"), direction: "next" },
|
|
345
|
-
})
|
|
346
|
-
.pipe(Effect.flip),
|
|
347
|
-
).toEqual(new Session.NotFoundError({ sessionID: missing }))
|
|
348
|
-
}).pipe(Effect.provide(sessionsLayer)),
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
it.effect("consumes the pending row and projects the message at promotion", () =>
|
|
352
|
-
Effect.gen(function* () {
|
|
353
|
-
const db = yield* seedSession()
|
|
354
|
-
const bus = yield* Bus.Service
|
|
355
|
-
const inbox = yield* SessionInbox.Service
|
|
356
|
-
const id = SessionMessage.ID.make("msg_admitted")
|
|
357
|
-
const admitted = yield* inbox.admit({
|
|
358
|
-
id,
|
|
359
|
-
sessionID,
|
|
360
|
-
item: { type: "user", payload: { text: "promote me" }, delivery: "steer" },
|
|
361
|
-
})
|
|
362
|
-
if (!admitted) return yield* Effect.die("Prompt admission failed")
|
|
363
|
-
|
|
364
|
-
const event = yield* bus.publish(SessionEvent.InboxDelivered, {
|
|
365
|
-
sessionID,
|
|
366
|
-
inboxID: id,
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
expect(
|
|
370
|
-
yield* db.select().from(SessionInboxTable).where(eq(SessionInboxTable.id, id)).get().pipe(Effect.orDie),
|
|
371
|
-
).toBeUndefined()
|
|
372
|
-
expect(
|
|
373
|
-
yield* db.select().from(SessionMessageTable).where(eq(SessionMessageTable.id, id)).get().pipe(Effect.orDie),
|
|
374
|
-
).toMatchObject({ session_id: sessionID, type: "user", seq: event.durable?.seq })
|
|
375
|
-
}),
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
it.effect("projects durable context messages supported by the updater", () =>
|
|
379
|
-
Effect.gen(function* () {
|
|
380
|
-
const db = yield* seedSession({ agent: Agent.ID.make("plan"), model: previousModel })
|
|
381
|
-
const bus = yield* Bus.Service
|
|
382
|
-
|
|
383
|
-
yield* bus.publish(SessionEvent.AgentSelected, {
|
|
384
|
-
sessionID,
|
|
385
|
-
agent: build,
|
|
386
|
-
})
|
|
387
|
-
yield* bus.publish(SessionEvent.ModelSelected, {
|
|
388
|
-
sessionID,
|
|
389
|
-
model,
|
|
390
|
-
})
|
|
391
|
-
yield* bus.publish(SessionEvent.Synthetic, {
|
|
392
|
-
sessionID,
|
|
393
|
-
text: "synthetic context",
|
|
394
|
-
metadata: { source: "projector-test" },
|
|
395
|
-
})
|
|
396
|
-
// Serialized events have no transient envelope metadata to supply the background marker.
|
|
397
|
-
yield* bus.replay({
|
|
398
|
-
id: Event.ID.create(),
|
|
399
|
-
created: 0,
|
|
400
|
-
aggregateID: sessionID,
|
|
401
|
-
seq: 3,
|
|
402
|
-
type: Bus.versionedType(SessionEvent.Shell.Started.type, 1),
|
|
403
|
-
data: {
|
|
404
|
-
sessionID,
|
|
405
|
-
shell: Shell.Info.make({
|
|
406
|
-
id: Shell.ID.make("sh_projector"),
|
|
407
|
-
status: "running",
|
|
408
|
-
command: "pwd",
|
|
409
|
-
cwd: "/project",
|
|
410
|
-
shell: "/bin/sh",
|
|
411
|
-
file: "/tmp/sh_projector.out",
|
|
412
|
-
metadata: { background: true },
|
|
413
|
-
time: { started: 0 },
|
|
414
|
-
}),
|
|
415
|
-
},
|
|
416
|
-
})
|
|
417
|
-
yield* bus.publish(SessionEvent.Shell.Ended, {
|
|
418
|
-
sessionID,
|
|
419
|
-
shell: Shell.Info.make({
|
|
420
|
-
id: Shell.ID.make("sh_projector"),
|
|
421
|
-
status: "exited",
|
|
422
|
-
command: "pwd",
|
|
423
|
-
cwd: "/project",
|
|
424
|
-
shell: "/bin/sh",
|
|
425
|
-
file: "/tmp/sh_projector.out",
|
|
426
|
-
exit: 0,
|
|
427
|
-
metadata: {},
|
|
428
|
-
time: { started: 0, completed: 1 },
|
|
429
|
-
}),
|
|
430
|
-
output: { output: "/project", cursor: 8, size: 8, truncated: false },
|
|
431
|
-
})
|
|
432
|
-
yield* bus.publish(SessionEvent.Compaction.Started, {
|
|
433
|
-
sessionID,
|
|
434
|
-
reason: "manual",
|
|
435
|
-
})
|
|
436
|
-
yield* bus.publish(SessionEvent.Compaction.Delta, {
|
|
437
|
-
sessionID,
|
|
438
|
-
text: "partial",
|
|
439
|
-
})
|
|
440
|
-
expect(
|
|
441
|
-
yield* db
|
|
442
|
-
.select({ id: EventTable.id })
|
|
443
|
-
.from(EventTable)
|
|
444
|
-
.where(sql`${EventTable.type} like 'session.compaction.delta.%'`)
|
|
445
|
-
.all()
|
|
446
|
-
.pipe(Effect.orDie),
|
|
447
|
-
).toHaveLength(0)
|
|
448
|
-
expect(
|
|
449
|
-
yield* db
|
|
450
|
-
.select({ data: SessionMessageTable.data })
|
|
451
|
-
.from(SessionMessageTable)
|
|
452
|
-
.where(eq(SessionMessageTable.type, "compaction"))
|
|
453
|
-
.all()
|
|
454
|
-
.pipe(Effect.orDie),
|
|
455
|
-
).toEqual([{ data: expect.objectContaining({ status: "running", summary: "" }) }])
|
|
456
|
-
yield* bus.publish(SessionEvent.Compaction.Ended, {
|
|
457
|
-
sessionID,
|
|
458
|
-
reason: "manual",
|
|
459
|
-
text: "summary",
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
const rows = yield* db
|
|
463
|
-
.select()
|
|
464
|
-
.from(SessionMessageTable)
|
|
465
|
-
.where(eq(SessionMessageTable.session_id, sessionID))
|
|
466
|
-
.orderBy(asc(SessionMessageTable.seq))
|
|
467
|
-
.all()
|
|
468
|
-
.pipe(Effect.orDie)
|
|
469
|
-
const messages = rows.map((row) =>
|
|
470
|
-
Schema.decodeUnknownSync(SessionMessage.Info)({ ...row.data, id: row.id, type: row.type }),
|
|
471
|
-
)
|
|
472
|
-
|
|
473
|
-
expect(messages.map((message) => message.type)).toEqual([
|
|
474
|
-
"agent-switched",
|
|
475
|
-
"model-switched",
|
|
476
|
-
"synthetic",
|
|
477
|
-
"shell",
|
|
478
|
-
"compaction",
|
|
479
|
-
])
|
|
480
|
-
expect(messages.find((message) => message.type === "synthetic")).toMatchObject({
|
|
481
|
-
text: "synthetic context",
|
|
482
|
-
metadata: { source: "projector-test" },
|
|
483
|
-
})
|
|
484
|
-
expect(messages.find((message) => message.type === "agent-switched")).toMatchObject({
|
|
485
|
-
agent: build,
|
|
486
|
-
previous: "plan",
|
|
487
|
-
})
|
|
488
|
-
expect(messages.find((message) => message.type === "model-switched")).toMatchObject({ previous: previousModel })
|
|
489
|
-
expect(messages.find((message) => message.type === "shell")).toMatchObject({
|
|
490
|
-
command: "pwd",
|
|
491
|
-
status: "exited",
|
|
492
|
-
exit: 0,
|
|
493
|
-
metadata: { background: true },
|
|
494
|
-
output: { output: "/project", truncated: false },
|
|
495
|
-
time: { completed: DateTime.makeUnsafe(0) },
|
|
496
|
-
})
|
|
497
|
-
expect(messages.find((message) => message.type === "compaction")).toMatchObject({ summary: "summary" })
|
|
498
|
-
expect(rows.find((row) => row.type === "compaction")?.data).not.toHaveProperty("recent")
|
|
499
|
-
expect(
|
|
500
|
-
yield* db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get().pipe(Effect.orDie),
|
|
501
|
-
).toMatchObject({
|
|
502
|
-
agent: "build",
|
|
503
|
-
model,
|
|
504
|
-
time_updated: DateTime.toEpochMillis(created),
|
|
505
|
-
})
|
|
506
|
-
}),
|
|
507
|
-
)
|
|
508
|
-
|
|
509
|
-
it.effect("rejects distinct creator events that reuse one projected message ID", () =>
|
|
510
|
-
Effect.gen(function* () {
|
|
511
|
-
const db = yield* seedSession()
|
|
512
|
-
const bus = yield* Bus.Service
|
|
513
|
-
const id = SessionMessage.ID.make("msg_creator_collision")
|
|
514
|
-
const { id: _, type, ...data } = encodeMessage({ id, type: "synthetic", text: "existing", time: { created } })
|
|
515
|
-
yield* db
|
|
516
|
-
.insert(SessionMessageTable)
|
|
517
|
-
.values({ id, session_id: sessionID, type, seq: 0, time_created: 0, data })
|
|
518
|
-
.run()
|
|
519
|
-
|
|
520
|
-
const exit = yield* bus
|
|
521
|
-
.publish(SessionEvent.Step.Started, {
|
|
522
|
-
sessionID,
|
|
523
|
-
assistantMessageID: id,
|
|
524
|
-
agent: build,
|
|
525
|
-
model,
|
|
526
|
-
started: 0,
|
|
527
|
-
})
|
|
528
|
-
.pipe(Effect.exit)
|
|
529
|
-
|
|
530
|
-
expect(exit._tag).toBe("Failure")
|
|
531
|
-
expect(
|
|
532
|
-
yield* db.select().from(SessionMessageTable).where(eq(SessionMessageTable.id, id)).get().pipe(Effect.orDie),
|
|
533
|
-
).toMatchObject({ type: "synthetic" })
|
|
534
|
-
}),
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
it.effect("projects retry state and clears it at the next step or execution terminal", () =>
|
|
538
|
-
Effect.gen(function* () {
|
|
539
|
-
const db = yield* seedSession()
|
|
540
|
-
const bus = yield* Bus.Service
|
|
541
|
-
const first = SessionMessage.ID.make("msg_retry_first")
|
|
542
|
-
const second = SessionMessage.ID.make("msg_retry_second")
|
|
543
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
544
|
-
sessionID,
|
|
545
|
-
assistantMessageID: first,
|
|
546
|
-
agent: build,
|
|
547
|
-
model,
|
|
548
|
-
started: 0,
|
|
549
|
-
})
|
|
550
|
-
yield* bus.publish(SessionEvent.RetryScheduled, {
|
|
551
|
-
sessionID,
|
|
552
|
-
assistantMessageID: first,
|
|
553
|
-
attempt: 2,
|
|
554
|
-
at: 2_000,
|
|
555
|
-
error: { type: "provider.transport", message: "Disconnected" },
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
const decode = (row: typeof SessionMessageTable.$inferSelect) =>
|
|
559
|
-
Schema.decodeUnknownSync(SessionMessage.Info)({ ...row.data, id: row.id, type: row.type })
|
|
560
|
-
const firstRow = yield* db
|
|
561
|
-
.select()
|
|
562
|
-
.from(SessionMessageTable)
|
|
563
|
-
.where(eq(SessionMessageTable.id, first))
|
|
564
|
-
.get()
|
|
565
|
-
.pipe(Effect.orDie)
|
|
566
|
-
const projected = firstRow ?? (yield* Effect.die(new Error("Missing retry projection")))
|
|
567
|
-
expect(decode(projected)).toMatchObject({
|
|
568
|
-
retry: { attempt: 2, at: DateTime.makeUnsafe(2_000), error: { type: "provider.transport" } },
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
572
|
-
sessionID,
|
|
573
|
-
assistantMessageID: second,
|
|
574
|
-
agent: build,
|
|
575
|
-
model,
|
|
576
|
-
started: 0,
|
|
577
|
-
})
|
|
578
|
-
yield* bus.publish(SessionEvent.RetryScheduled, {
|
|
579
|
-
sessionID,
|
|
580
|
-
assistantMessageID: second,
|
|
581
|
-
attempt: 3,
|
|
582
|
-
at: 6_000,
|
|
583
|
-
error: { type: "provider.internal", message: "Unavailable" },
|
|
584
|
-
})
|
|
585
|
-
yield* bus.publish(SessionEvent.Execution.Interrupted, { sessionID, reason: "shutdown" })
|
|
586
|
-
|
|
587
|
-
const rows = yield* db
|
|
588
|
-
.select()
|
|
589
|
-
.from(SessionMessageTable)
|
|
590
|
-
.where(eq(SessionMessageTable.session_id, sessionID))
|
|
591
|
-
.orderBy(asc(SessionMessageTable.seq))
|
|
592
|
-
.all()
|
|
593
|
-
.pipe(Effect.orDie)
|
|
594
|
-
expect(decode(rows[0])).not.toHaveProperty("retry")
|
|
595
|
-
expect(decode(rows[1])).not.toHaveProperty("retry")
|
|
596
|
-
}),
|
|
597
|
-
)
|
|
598
|
-
|
|
599
|
-
it.effect("does not infer restart continuation from lifecycle history", () =>
|
|
600
|
-
Effect.gen(function* () {
|
|
601
|
-
const db = yield* seedSession()
|
|
602
|
-
const bus = yield* Bus.Service
|
|
603
|
-
const suspended = () =>
|
|
604
|
-
db
|
|
605
|
-
.select({ timeSuspended: SessionTable.time_suspended })
|
|
606
|
-
.from(SessionTable)
|
|
607
|
-
.where(eq(SessionTable.id, sessionID))
|
|
608
|
-
.get()
|
|
609
|
-
.pipe(Effect.orDie)
|
|
610
|
-
|
|
611
|
-
yield* bus.publish(SessionEvent.Execution.Interrupted, { sessionID, reason: "shutdown" })
|
|
612
|
-
expect((yield* suspended())?.timeSuspended).toBeNull()
|
|
613
|
-
|
|
614
|
-
yield* bus.publish(SessionEvent.Execution.Started, { sessionID })
|
|
615
|
-
expect((yield* suspended())?.timeSuspended).toBeNull()
|
|
616
|
-
}),
|
|
617
|
-
)
|
|
618
|
-
|
|
619
|
-
it.effect("records each execution's start, including a resume after shutdown", () =>
|
|
620
|
-
Effect.gen(function* () {
|
|
621
|
-
const db = yield* seedSession({ time_created: 0, time_updated: 0 })
|
|
622
|
-
const bus = yield* Bus.Service
|
|
623
|
-
const times = () =>
|
|
624
|
-
db
|
|
625
|
-
.select({ busy: SessionTable.time_busy, idle: SessionTable.time_idle, updated: SessionTable.time_updated })
|
|
626
|
-
.from(SessionTable)
|
|
627
|
-
.get()
|
|
628
|
-
.pipe(Effect.orDie)
|
|
629
|
-
|
|
630
|
-
yield* TestClock.setTime(10)
|
|
631
|
-
yield* bus.publish(SessionEvent.Execution.Started, { sessionID })
|
|
632
|
-
expect(yield* times()).toEqual({ busy: 10, idle: null, updated: 0 })
|
|
633
|
-
|
|
634
|
-
yield* TestClock.setTime(20)
|
|
635
|
-
yield* bus.publish(SessionEvent.Execution.Interrupted, { sessionID, reason: "shutdown" })
|
|
636
|
-
yield* TestClock.setTime(30)
|
|
637
|
-
yield* bus.publish(SessionEvent.Execution.Started, { sessionID })
|
|
638
|
-
expect(yield* times()).toEqual({ busy: 30, idle: null, updated: 0 })
|
|
639
|
-
|
|
640
|
-
yield* TestClock.setTime(40)
|
|
641
|
-
yield* bus.publish(SessionEvent.Execution.Succeeded, { sessionID })
|
|
642
|
-
expect(yield* times()).toEqual({ busy: 30, idle: 40, updated: 0 })
|
|
643
|
-
|
|
644
|
-
yield* TestClock.setTime(50)
|
|
645
|
-
yield* bus.publish(SessionEvent.Execution.Started, { sessionID })
|
|
646
|
-
expect(yield* times()).toEqual({ busy: 50, idle: 40, updated: 0 })
|
|
647
|
-
}),
|
|
648
|
-
)
|
|
649
|
-
|
|
650
|
-
it.effect("updates only the newest incomplete assistant projection", () =>
|
|
651
|
-
Effect.gen(function* () {
|
|
652
|
-
const db = yield* seedSession()
|
|
653
|
-
yield* db
|
|
654
|
-
.insert(SessionMessageTable)
|
|
655
|
-
.values([
|
|
656
|
-
assistantRow(SessionMessage.ID.make("msg_assistant_1"), 0),
|
|
657
|
-
assistantRow(SessionMessage.ID.make("msg_assistant_2"), 1),
|
|
658
|
-
])
|
|
659
|
-
.run()
|
|
660
|
-
.pipe(Effect.orDie)
|
|
661
|
-
|
|
662
|
-
const service = yield* Bus.Service
|
|
663
|
-
const usageUpdated = yield* service
|
|
664
|
-
.subscribe(SessionEvent.UsageUpdated)
|
|
665
|
-
.pipe(Stream.runHead, Effect.forkScoped({ startImmediately: true }))
|
|
666
|
-
yield* service.publish(SessionEvent.Step.Ended, {
|
|
667
|
-
sessionID,
|
|
668
|
-
assistantMessageID: SessionMessage.ID.make("msg_assistant_2"),
|
|
669
|
-
finish: "stop",
|
|
670
|
-
cost: Money.USD.make(1.25),
|
|
671
|
-
tokens: { input: 10, output: 4, reasoning: 2, cache: { read: 3, write: 1 } },
|
|
672
|
-
})
|
|
673
|
-
|
|
674
|
-
const rows = yield* db
|
|
675
|
-
.select()
|
|
676
|
-
.from(SessionMessageTable)
|
|
677
|
-
.where(eq(SessionMessageTable.session_id, sessionID))
|
|
678
|
-
.orderBy(asc(SessionMessageTable.id))
|
|
679
|
-
.all()
|
|
680
|
-
.pipe(Effect.orDie)
|
|
681
|
-
const messages = rows.map((row) =>
|
|
682
|
-
Schema.decodeUnknownSync(SessionMessage.Info)({ ...row.data, id: row.id, type: row.type }),
|
|
683
|
-
)
|
|
684
|
-
expect(messages[0]).not.toHaveProperty("time.completed")
|
|
685
|
-
expect(messages[1]).toMatchObject({
|
|
686
|
-
type: "assistant",
|
|
687
|
-
finish: "stop",
|
|
688
|
-
cost: Money.USD.make(1.25),
|
|
689
|
-
tokens: { input: 10, output: 4, reasoning: 2, cache: { read: 3, write: 1 } },
|
|
690
|
-
time: { completed: DateTime.makeUnsafe(0) },
|
|
691
|
-
})
|
|
692
|
-
expect(
|
|
693
|
-
yield* db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get().pipe(Effect.orDie),
|
|
694
|
-
).toMatchObject({
|
|
695
|
-
cost: 1.25,
|
|
696
|
-
tokens_input: 10,
|
|
697
|
-
tokens_output: 4,
|
|
698
|
-
tokens_reasoning: 2,
|
|
699
|
-
tokens_cache_read: 3,
|
|
700
|
-
tokens_cache_write: 1,
|
|
701
|
-
})
|
|
702
|
-
expect(Option.getOrThrow(yield* Fiber.join(usageUpdated)).data).toEqual({
|
|
703
|
-
sessionID,
|
|
704
|
-
cost: Money.USD.make(1.25),
|
|
705
|
-
tokens: { input: 10, output: 4, reasoning: 2, cache: { read: 3, write: 1 } },
|
|
706
|
-
})
|
|
707
|
-
}),
|
|
708
|
-
)
|
|
709
|
-
|
|
710
|
-
it.effect("reads and replays native data stored under its pre-v2.1 names", () =>
|
|
711
|
-
Effect.gen(function* () {
|
|
712
|
-
const db = yield* seedSession()
|
|
713
|
-
const store = yield* SessionStore.Service
|
|
714
|
-
const bus = yield* Bus.Service
|
|
715
|
-
const assistantID = SessionMessage.ID.make("msg_legacy_assistant")
|
|
716
|
-
const {
|
|
717
|
-
id: _,
|
|
718
|
-
type: __,
|
|
719
|
-
...assistant
|
|
720
|
-
} = encodeMessage(
|
|
721
|
-
SessionMessage.Assistant.make({
|
|
722
|
-
id: assistantID,
|
|
723
|
-
type: "assistant",
|
|
724
|
-
agent: build,
|
|
725
|
-
model,
|
|
726
|
-
content: [],
|
|
727
|
-
time: { created },
|
|
728
|
-
}),
|
|
729
|
-
)
|
|
730
|
-
const legacyAssistant = {
|
|
731
|
-
...assistant,
|
|
732
|
-
providerState: { step: "kept" },
|
|
733
|
-
content: [
|
|
734
|
-
{ type: "text", text: "hi", state: { signature: "text" } },
|
|
735
|
-
{ type: "reasoning", text: "thinking", state: { signature: "reasoning" } },
|
|
736
|
-
{
|
|
737
|
-
type: "tool",
|
|
738
|
-
id: "call",
|
|
739
|
-
name: "search",
|
|
740
|
-
executed: true,
|
|
741
|
-
providerState: { call: "kept" },
|
|
742
|
-
providerResultState: { result: "kept" },
|
|
743
|
-
state: { status: "completed", input: {}, content: [{ type: "text", text: "done" }] },
|
|
744
|
-
time: { created: 0, ran: 0, completed: 0 },
|
|
745
|
-
},
|
|
746
|
-
],
|
|
747
|
-
}
|
|
748
|
-
const legacyCompaction = {
|
|
749
|
-
status: "completed",
|
|
750
|
-
reason: "manual",
|
|
751
|
-
summary: "summary",
|
|
752
|
-
providerState: { compaction: "kept" },
|
|
753
|
-
time: { created: 0 },
|
|
754
|
-
}
|
|
755
|
-
yield* db.run(sql`
|
|
756
|
-
INSERT INTO session_message (id, session_id, type, seq, time_created, time_updated, data) VALUES
|
|
757
|
-
(${assistantID}, ${sessionID}, 'assistant', 0, 0, 0, ${JSON.stringify(legacyAssistant)}),
|
|
758
|
-
('msg_legacy_compaction', ${sessionID}, 'compaction', 1, 0, 0, ${JSON.stringify(legacyCompaction)})
|
|
759
|
-
`)
|
|
760
|
-
const stored = [
|
|
761
|
-
{
|
|
762
|
-
id: Event.ID.make("evt_legacy_0"),
|
|
763
|
-
type: "session.tool.called.1",
|
|
764
|
-
data: { id: "call", input: {}, executed: true, state: { call: "kept" } },
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
id: Event.ID.make("evt_legacy_1"),
|
|
768
|
-
type: "session.tool.success.2",
|
|
769
|
-
data: {
|
|
770
|
-
id: "call",
|
|
771
|
-
content: [{ type: "text", text: "done" }],
|
|
772
|
-
executed: true,
|
|
773
|
-
resultState: { result: "kept" },
|
|
774
|
-
},
|
|
775
|
-
},
|
|
776
|
-
].map((event, seq) => ({
|
|
777
|
-
...event,
|
|
778
|
-
seq,
|
|
779
|
-
created: 0,
|
|
780
|
-
aggregateID: sessionID,
|
|
781
|
-
data: { sessionID, assistantMessageID: assistantID, ...event.data },
|
|
782
|
-
}))
|
|
783
|
-
yield* db.run(sql`INSERT OR IGNORE INTO event_sequence (aggregate_id, seq) VALUES (${sessionID}, 1)`)
|
|
784
|
-
for (const event of stored)
|
|
785
|
-
yield* db.run(
|
|
786
|
-
sql`INSERT INTO event (id, aggregate_id, seq, created, type, data) VALUES (${event.id}, ${sessionID}, ${event.seq}, 0, ${event.type}, ${JSON.stringify(event.data)})`,
|
|
787
|
-
)
|
|
788
|
-
|
|
789
|
-
const [readAssistant, readCompaction] = yield* store.messages({ sessionID, order: "asc" })
|
|
790
|
-
expect(readAssistant).toMatchObject({
|
|
791
|
-
native: { step: "kept" },
|
|
792
|
-
content: [
|
|
793
|
-
{ type: "text", native: { signature: "text" } },
|
|
794
|
-
{ type: "reasoning", native: { signature: "reasoning" } },
|
|
795
|
-
{ type: "tool", native: { call: "kept", result: "kept" } },
|
|
796
|
-
],
|
|
797
|
-
})
|
|
798
|
-
expect(readCompaction).toMatchObject({ native: { compaction: "kept" } })
|
|
799
|
-
|
|
800
|
-
expect(
|
|
801
|
-
(yield* Stream.runCollect(bus.log({ aggregateID: sessionID }))).filter((item) => !Bus.isSynced(item)),
|
|
802
|
-
).toMatchObject([
|
|
803
|
-
{ type: "session.tool.called", data: { native: { call: "kept" } } },
|
|
804
|
-
{ type: "session.tool.success", data: { native: { result: "kept" } } },
|
|
805
|
-
])
|
|
806
|
-
|
|
807
|
-
// Re-delivering an event that is already stored in its legacy shape stays idempotent.
|
|
808
|
-
yield* Effect.forEach(stored, (event) => bus.replay(event), { discard: true })
|
|
809
|
-
|
|
810
|
-
// A legacy-shaped event replayed from elsewhere is projected and stored in the current shape.
|
|
811
|
-
yield* bus.replay({
|
|
812
|
-
id: Event.ID.make("evt_legacy_2"),
|
|
813
|
-
type: "session.step.ended.1",
|
|
814
|
-
seq: 2,
|
|
815
|
-
created: 0,
|
|
816
|
-
aggregateID: sessionID,
|
|
817
|
-
data: {
|
|
818
|
-
sessionID,
|
|
819
|
-
assistantMessageID: assistantID,
|
|
820
|
-
finish: "stop",
|
|
821
|
-
providerState: { step: "replayed" },
|
|
822
|
-
cost: 0,
|
|
823
|
-
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
824
|
-
},
|
|
825
|
-
})
|
|
826
|
-
const replayed = yield* db.get<{ data: string }>(sql`SELECT data FROM event WHERE id = 'evt_legacy_2'`)
|
|
827
|
-
expect(JSON.parse(replayed?.data ?? "{}")).toMatchObject({ native: { step: "replayed" } })
|
|
828
|
-
expect(JSON.parse(replayed?.data ?? "{}")).not.toHaveProperty("providerState")
|
|
829
|
-
|
|
830
|
-
// An envelope update rewrites the legacy row in the current shape but leaves its inline parts where they are.
|
|
831
|
-
const messageData = () =>
|
|
832
|
-
db
|
|
833
|
-
.get<{ data: string }>(sql`SELECT data FROM session_message WHERE id = ${assistantID}`)
|
|
834
|
-
.pipe(Effect.map((row) => JSON.parse(row?.data ?? "{}")))
|
|
835
|
-
const rewritten = yield* messageData()
|
|
836
|
-
expect(rewritten).not.toHaveProperty("providerState")
|
|
837
|
-
expect(rewritten).toMatchObject({ native: { step: "replayed" } })
|
|
838
|
-
expect(rewritten.content).toHaveLength(3)
|
|
839
|
-
|
|
840
|
-
// The first part write splits the legacy parts into session_part in the current shape.
|
|
841
|
-
yield* bus.publish(SessionEvent.Text.Started, { sessionID, assistantMessageID: assistantID, ordinal: 3 })
|
|
842
|
-
expect(yield* messageData()).toMatchObject({ native: { step: "replayed" }, content: [] })
|
|
843
|
-
const partRows = yield* db
|
|
844
|
-
.select({ data: SessionPartTable.data })
|
|
845
|
-
.from(SessionPartTable)
|
|
846
|
-
.where(eq(SessionPartTable.message_id, assistantID))
|
|
847
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
848
|
-
.all()
|
|
849
|
-
.pipe(Effect.orDie)
|
|
850
|
-
const rewrittenParts = partRows.map((row) => row.data).slice(0, 3)
|
|
851
|
-
expect(rewrittenParts).toMatchObject([
|
|
852
|
-
{ type: "text", native: { signature: "text" } },
|
|
853
|
-
{ type: "reasoning", native: { signature: "reasoning" } },
|
|
854
|
-
{ type: "tool", native: { call: "kept", result: "kept" } },
|
|
855
|
-
])
|
|
856
|
-
expect(rewrittenParts.map((part) => Object.keys(part).toSorted())).toEqual([
|
|
857
|
-
["native", "text", "type"],
|
|
858
|
-
["native", "text", "type"],
|
|
859
|
-
["executed", "id", "name", "native", "state", "time", "type"],
|
|
860
|
-
])
|
|
861
|
-
}).pipe(Effect.provide(partRows)),
|
|
862
|
-
)
|
|
863
|
-
|
|
864
|
-
it.effect("merges tool result native data into the call's native data", () =>
|
|
865
|
-
Effect.gen(function* () {
|
|
866
|
-
const db = yield* seedSession()
|
|
867
|
-
const assistantMessageID = SessionMessage.ID.make("msg_tools")
|
|
868
|
-
yield* db.insert(SessionMessageTable).values(assistantRow(assistantMessageID, 0)).run().pipe(Effect.orDie)
|
|
869
|
-
|
|
870
|
-
const service = yield* Bus.Service
|
|
871
|
-
const call = (id: string) =>
|
|
872
|
-
Effect.gen(function* () {
|
|
873
|
-
yield* service.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id, name: id })
|
|
874
|
-
yield* service.publish(SessionEvent.Tool.Called, {
|
|
875
|
-
sessionID,
|
|
876
|
-
assistantMessageID,
|
|
877
|
-
id,
|
|
878
|
-
input: {},
|
|
879
|
-
executed: true,
|
|
880
|
-
native: { call: id },
|
|
881
|
-
})
|
|
882
|
-
})
|
|
883
|
-
yield* call("succeeded")
|
|
884
|
-
yield* service.publish(SessionEvent.Tool.Success, {
|
|
885
|
-
sessionID,
|
|
886
|
-
assistantMessageID,
|
|
887
|
-
id: "succeeded",
|
|
888
|
-
content: [{ type: "text", text: "done" }],
|
|
889
|
-
executed: true,
|
|
890
|
-
native: { result: "succeeded" },
|
|
891
|
-
})
|
|
892
|
-
yield* call("failed")
|
|
893
|
-
yield* service.publish(SessionEvent.Tool.Failed, {
|
|
894
|
-
sessionID,
|
|
895
|
-
assistantMessageID,
|
|
896
|
-
id: "failed",
|
|
897
|
-
error: { type: "tool.execution", message: "failed" },
|
|
898
|
-
executed: true,
|
|
899
|
-
})
|
|
900
|
-
|
|
901
|
-
const row = yield* db
|
|
902
|
-
.select()
|
|
903
|
-
.from(SessionMessageTable)
|
|
904
|
-
.where(eq(SessionMessageTable.id, assistantMessageID))
|
|
905
|
-
.get()
|
|
906
|
-
.pipe(Effect.orDie)
|
|
907
|
-
expect(row?.data).toMatchObject({ content: [] })
|
|
908
|
-
expect(yield* SessionHistory.loadMessageRow(db, row!)).toMatchObject({
|
|
909
|
-
content: [
|
|
910
|
-
{ id: "succeeded", native: { call: "succeeded", result: "succeeded" }, state: { status: "completed" } },
|
|
911
|
-
{ id: "failed", native: { call: "failed" }, state: { status: "error" } },
|
|
912
|
-
],
|
|
913
|
-
})
|
|
914
|
-
}).pipe(Effect.provide(partRows)),
|
|
915
|
-
)
|
|
916
|
-
|
|
917
|
-
it.effect("projects ended and failed step terminal state", () =>
|
|
918
|
-
Effect.gen(function* () {
|
|
919
|
-
const db = yield* seedSession()
|
|
920
|
-
const endedID = SessionMessage.ID.make("msg_ended")
|
|
921
|
-
const failedID = SessionMessage.ID.make("msg_failed")
|
|
922
|
-
yield* db
|
|
923
|
-
.insert(SessionMessageTable)
|
|
924
|
-
.values([assistantRow(endedID, 0), assistantRow(failedID, 1)])
|
|
925
|
-
.run()
|
|
926
|
-
.pipe(Effect.orDie)
|
|
927
|
-
|
|
928
|
-
const service = yield* Bus.Service
|
|
929
|
-
yield* service.publish(SessionEvent.Step.Streamed, {
|
|
930
|
-
sessionID,
|
|
931
|
-
assistantMessageID: endedID,
|
|
932
|
-
})
|
|
933
|
-
yield* service.publish(SessionEvent.Step.Ended, {
|
|
934
|
-
sessionID,
|
|
935
|
-
assistantMessageID: endedID,
|
|
936
|
-
finish: "stop",
|
|
937
|
-
rawFinish: "stop_sequence",
|
|
938
|
-
native: { response: "ended" },
|
|
939
|
-
cost: Money.USD.make(1),
|
|
940
|
-
tokens: { input: 2, output: 3, reasoning: 4, cache: { read: 5, write: 6 } },
|
|
941
|
-
snapshot: Snapshot.ID.make("snap_ended"),
|
|
942
|
-
files: [RelativePath.make("src/ended.ts")],
|
|
943
|
-
})
|
|
944
|
-
yield* service.publish(SessionEvent.Step.Failed, {
|
|
945
|
-
sessionID,
|
|
946
|
-
assistantMessageID: failedID,
|
|
947
|
-
finish: "content-filter",
|
|
948
|
-
rawFinish: "blocked",
|
|
949
|
-
native: { response: "failed" },
|
|
950
|
-
error: { type: "provider.invalid-request", message: "Failed" },
|
|
951
|
-
snapshot: Snapshot.ID.make("snap_failed"),
|
|
952
|
-
files: [RelativePath.make("src/failed.ts")],
|
|
953
|
-
})
|
|
954
|
-
|
|
955
|
-
const rows = yield* db
|
|
956
|
-
.select()
|
|
957
|
-
.from(SessionMessageTable)
|
|
958
|
-
.where(eq(SessionMessageTable.session_id, sessionID))
|
|
959
|
-
.orderBy(asc(SessionMessageTable.seq))
|
|
960
|
-
.all()
|
|
961
|
-
.pipe(Effect.orDie)
|
|
962
|
-
const messages = rows.map((row) =>
|
|
963
|
-
Schema.decodeUnknownSync(SessionMessage.Info)({ ...row.data, id: row.id, type: row.type }),
|
|
964
|
-
)
|
|
965
|
-
expect(messages[0]).toMatchObject({
|
|
966
|
-
type: "assistant",
|
|
967
|
-
finish: "stop",
|
|
968
|
-
rawFinish: "stop_sequence",
|
|
969
|
-
native: { response: "ended" },
|
|
970
|
-
cost: Money.USD.make(1),
|
|
971
|
-
tokens: { input: 2, output: 3, reasoning: 4, cache: { read: 5, write: 6 } },
|
|
972
|
-
snapshot: { end: "snap_ended", files: ["src/ended.ts"] },
|
|
973
|
-
time: { streamed: created, completed: created },
|
|
974
|
-
})
|
|
975
|
-
expect(messages[1]).toMatchObject({
|
|
976
|
-
type: "assistant",
|
|
977
|
-
finish: "content-filter",
|
|
978
|
-
rawFinish: "blocked",
|
|
979
|
-
native: { response: "failed" },
|
|
980
|
-
error: { type: "provider.invalid-request", message: "Failed" },
|
|
981
|
-
snapshot: { end: "snap_failed", files: ["src/failed.ts"] },
|
|
982
|
-
time: { completed: created },
|
|
983
|
-
})
|
|
984
|
-
}),
|
|
985
|
-
)
|
|
986
|
-
|
|
987
|
-
it.effect("does not revive a stale incomplete assistant projection", () =>
|
|
988
|
-
Effect.gen(function* () {
|
|
989
|
-
const db = yield* seedSession()
|
|
990
|
-
yield* db
|
|
991
|
-
.insert(SessionMessageTable)
|
|
992
|
-
.values([
|
|
993
|
-
assistantRow(SessionMessage.ID.make("msg_assistant_stale"), 0),
|
|
994
|
-
assistantRow(SessionMessage.ID.make("msg_assistant_completed"), 1, {
|
|
995
|
-
created: DateTime.makeUnsafe(1),
|
|
996
|
-
completed: DateTime.makeUnsafe(2),
|
|
997
|
-
}),
|
|
998
|
-
])
|
|
999
|
-
.run()
|
|
1000
|
-
.pipe(Effect.orDie)
|
|
1001
|
-
|
|
1002
|
-
const service = yield* Bus.Service
|
|
1003
|
-
yield* service.publish(SessionEvent.Text.Started, {
|
|
1004
|
-
sessionID,
|
|
1005
|
-
assistantMessageID: SessionMessage.ID.make("msg_assistant_completed"),
|
|
1006
|
-
ordinal: 0,
|
|
1007
|
-
})
|
|
1008
|
-
|
|
1009
|
-
const rows = yield* db
|
|
1010
|
-
.select()
|
|
1011
|
-
.from(SessionMessageTable)
|
|
1012
|
-
.where(eq(SessionMessageTable.session_id, sessionID))
|
|
1013
|
-
.orderBy(asc(SessionMessageTable.id))
|
|
1014
|
-
.all()
|
|
1015
|
-
.pipe(Effect.orDie)
|
|
1016
|
-
const messages = yield* SessionHistory.decodeMessageRows(db, rows).pipe(Effect.orDie)
|
|
1017
|
-
expect(messages).toEqual([
|
|
1018
|
-
SessionMessage.Assistant.make({
|
|
1019
|
-
id: SessionMessage.ID.make("msg_assistant_completed"),
|
|
1020
|
-
type: "assistant",
|
|
1021
|
-
agent: build,
|
|
1022
|
-
model,
|
|
1023
|
-
content: [SessionMessage.AssistantText.make({ type: "text", text: "" })],
|
|
1024
|
-
time: { created: DateTime.makeUnsafe(1), completed: DateTime.makeUnsafe(2) },
|
|
1025
|
-
}),
|
|
1026
|
-
SessionMessage.Assistant.make({
|
|
1027
|
-
id: SessionMessage.ID.make("msg_assistant_stale"),
|
|
1028
|
-
type: "assistant",
|
|
1029
|
-
agent: build,
|
|
1030
|
-
model,
|
|
1031
|
-
content: [],
|
|
1032
|
-
time: { created },
|
|
1033
|
-
}),
|
|
1034
|
-
])
|
|
1035
|
-
}),
|
|
1036
|
-
)
|
|
1037
|
-
|
|
1038
|
-
it.effect("bumps session time_updated on step lifecycle events", () =>
|
|
1039
|
-
Effect.gen(function* () {
|
|
1040
|
-
const db = yield* seedSession({ time_created: 0, time_updated: 0 })
|
|
1041
|
-
const bus = yield* Bus.Service
|
|
1042
|
-
const updated = () =>
|
|
1043
|
-
db.select({ time_updated: SessionTable.time_updated }).from(SessionTable).get().pipe(Effect.orDie)
|
|
1044
|
-
const first = SessionMessage.ID.make("msg_touch_first")
|
|
1045
|
-
const second = SessionMessage.ID.make("msg_touch_second")
|
|
1046
|
-
|
|
1047
|
-
yield* TestClock.setTime(5)
|
|
1048
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
1049
|
-
sessionID,
|
|
1050
|
-
assistantMessageID: first,
|
|
1051
|
-
agent: build,
|
|
1052
|
-
model,
|
|
1053
|
-
started: 5,
|
|
1054
|
-
})
|
|
1055
|
-
expect(yield* updated()).toEqual({ time_updated: 5 })
|
|
1056
|
-
|
|
1057
|
-
yield* TestClock.setTime(9)
|
|
1058
|
-
yield* bus.publish(SessionEvent.Step.Ended, {
|
|
1059
|
-
sessionID,
|
|
1060
|
-
assistantMessageID: first,
|
|
1061
|
-
finish: "stop",
|
|
1062
|
-
cost: Money.USD.make(0),
|
|
1063
|
-
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
1064
|
-
})
|
|
1065
|
-
expect(yield* updated()).toEqual({ time_updated: 9 })
|
|
1066
|
-
|
|
1067
|
-
yield* TestClock.setTime(12)
|
|
1068
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
1069
|
-
sessionID,
|
|
1070
|
-
assistantMessageID: second,
|
|
1071
|
-
agent: build,
|
|
1072
|
-
model,
|
|
1073
|
-
started: 12,
|
|
1074
|
-
})
|
|
1075
|
-
yield* TestClock.setTime(15)
|
|
1076
|
-
yield* bus.publish(SessionEvent.Step.Failed, {
|
|
1077
|
-
sessionID,
|
|
1078
|
-
assistantMessageID: second,
|
|
1079
|
-
error: { type: "provider.invalid-request", message: "Failed" },
|
|
1080
|
-
})
|
|
1081
|
-
expect(yield* updated()).toEqual({ time_updated: 15 })
|
|
1082
|
-
}),
|
|
1083
|
-
)
|
|
1084
|
-
|
|
1085
|
-
it.effect("leaves a settled inline assistant message untouched when a new step starts", () =>
|
|
1086
|
-
Effect.gen(function* () {
|
|
1087
|
-
const db = yield* seedSession()
|
|
1088
|
-
const bus = yield* Bus.Service
|
|
1089
|
-
const settledID = SessionMessage.ID.make("msg_settled_inline")
|
|
1090
|
-
const seeded = assistantRow(settledID, 0, { created, completed: created })
|
|
1091
|
-
yield* db
|
|
1092
|
-
.insert(SessionMessageTable)
|
|
1093
|
-
.values({ ...seeded, data: { ...seeded.data, content: [{ type: "text", text: "old answer" }] } })
|
|
1094
|
-
.run()
|
|
1095
|
-
.pipe(Effect.orDie)
|
|
1096
|
-
yield* Bus.reserveSequence(db, sessionID, 0)
|
|
1097
|
-
const settledRow = () =>
|
|
1098
|
-
db.select().from(SessionMessageTable).where(eq(SessionMessageTable.id, settledID)).get().pipe(Effect.orDie)
|
|
1099
|
-
const before = yield* settledRow()
|
|
1100
|
-
|
|
1101
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
1102
|
-
sessionID,
|
|
1103
|
-
assistantMessageID: SessionMessage.ID.make("msg_next_step"),
|
|
1104
|
-
agent: build,
|
|
1105
|
-
model,
|
|
1106
|
-
started: 1,
|
|
1107
|
-
})
|
|
1108
|
-
yield* bus.publish(SessionEvent.Execution.Succeeded, { sessionID })
|
|
1109
|
-
|
|
1110
|
-
expect(yield* settledRow()).toEqual(before)
|
|
1111
|
-
expect(
|
|
1112
|
-
yield* db
|
|
1113
|
-
.select()
|
|
1114
|
-
.from(SessionPartTable)
|
|
1115
|
-
.where(eq(SessionPartTable.message_id, settledID))
|
|
1116
|
-
.all()
|
|
1117
|
-
.pipe(Effect.orDie),
|
|
1118
|
-
).toEqual([])
|
|
1119
|
-
}),
|
|
1120
|
-
)
|
|
1121
|
-
|
|
1122
|
-
it.effect("hydrates media:<hash> refs on message and inbox reads", () =>
|
|
1123
|
-
Effect.gen(function* () {
|
|
1124
|
-
const db = yield* seedSession()
|
|
1125
|
-
const bus = yield* Bus.Service
|
|
1126
|
-
const inbox = yield* SessionInbox.Service
|
|
1127
|
-
const store = yield* SessionStore.Service
|
|
1128
|
-
|
|
1129
|
-
const rawBytes = Buffer.from("externalized-media-payload")
|
|
1130
|
-
const base64 = rawBytes.toString("base64")
|
|
1131
|
-
const hash = "a".repeat(64)
|
|
1132
|
-
const uri = `media:${hash}`
|
|
1133
|
-
// Only media:<hash> is a ref; a plain path that looks like a media URL is left alone.
|
|
1134
|
-
const pathUri = `/api/media/${hash}`
|
|
1135
|
-
|
|
1136
|
-
yield* db
|
|
1137
|
-
.insert(BlobTable)
|
|
1138
|
-
.values({
|
|
1139
|
-
hash,
|
|
1140
|
-
mime: "application/pdf",
|
|
1141
|
-
bytes: rawBytes.byteLength,
|
|
1142
|
-
width: null,
|
|
1143
|
-
height: null,
|
|
1144
|
-
data: rawBytes,
|
|
1145
|
-
})
|
|
1146
|
-
.run()
|
|
1147
|
-
.pipe(Effect.orDie)
|
|
1148
|
-
|
|
1149
|
-
const userID = SessionMessage.ID.make("msg_read_user")
|
|
1150
|
-
const assistantID = SessionMessage.ID.make("msg_read_assistant")
|
|
1151
|
-
const inboxID = SessionMessage.ID.make("msg_read_inbox")
|
|
1152
|
-
|
|
1153
|
-
yield* db
|
|
1154
|
-
.insert(SessionMessageTable)
|
|
1155
|
-
.values([
|
|
1156
|
-
{
|
|
1157
|
-
id: userID,
|
|
1158
|
-
session_id: sessionID,
|
|
1159
|
-
type: "user",
|
|
1160
|
-
seq: 1,
|
|
1161
|
-
time_created: 1,
|
|
1162
|
-
data: {
|
|
1163
|
-
text: "user attachment",
|
|
1164
|
-
files: [
|
|
1165
|
-
SessionStored.FileRef.make({
|
|
1166
|
-
uri,
|
|
1167
|
-
mime: "application/pdf",
|
|
1168
|
-
source: { type: "inline" },
|
|
1169
|
-
name: "spec.pdf",
|
|
1170
|
-
}),
|
|
1171
|
-
],
|
|
1172
|
-
time: { created: 1 },
|
|
1173
|
-
},
|
|
1174
|
-
},
|
|
1175
|
-
{
|
|
1176
|
-
id: assistantID,
|
|
1177
|
-
session_id: sessionID,
|
|
1178
|
-
type: "assistant",
|
|
1179
|
-
seq: 2,
|
|
1180
|
-
time_created: 2,
|
|
1181
|
-
data: {
|
|
1182
|
-
agent: build,
|
|
1183
|
-
model,
|
|
1184
|
-
content: [
|
|
1185
|
-
{
|
|
1186
|
-
type: "tool",
|
|
1187
|
-
id: "call_1",
|
|
1188
|
-
name: "read",
|
|
1189
|
-
executed: true,
|
|
1190
|
-
state: {
|
|
1191
|
-
status: "completed",
|
|
1192
|
-
input: { path: "spec.pdf" },
|
|
1193
|
-
content: [
|
|
1194
|
-
SessionStored.ToolFileRef.make({ type: "file", uri, mime: "application/pdf", name: "spec.pdf" }),
|
|
1195
|
-
{ type: "file", uri: pathUri, mime: "application/pdf", name: "path.pdf" },
|
|
1196
|
-
],
|
|
1197
|
-
},
|
|
1198
|
-
time: { created: 2, ran: 2, completed: 2 },
|
|
1199
|
-
},
|
|
1200
|
-
],
|
|
1201
|
-
time: { created: 2, completed: 2 },
|
|
1202
|
-
},
|
|
1203
|
-
},
|
|
1204
|
-
])
|
|
1205
|
-
.run()
|
|
1206
|
-
.pipe(Effect.orDie)
|
|
1207
|
-
|
|
1208
|
-
yield* db
|
|
1209
|
-
.insert(SessionInboxTable)
|
|
1210
|
-
.values({
|
|
1211
|
-
id: inboxID,
|
|
1212
|
-
session_id: sessionID,
|
|
1213
|
-
type: "user",
|
|
1214
|
-
payload: {
|
|
1215
|
-
text: "queued attachment",
|
|
1216
|
-
files: [
|
|
1217
|
-
SessionStored.FileRef.make({
|
|
1218
|
-
uri,
|
|
1219
|
-
mime: "application/pdf",
|
|
1220
|
-
source: { type: "inline" },
|
|
1221
|
-
name: "queued.pdf",
|
|
1222
|
-
}),
|
|
1223
|
-
],
|
|
1224
|
-
},
|
|
1225
|
-
delivery: "queue",
|
|
1226
|
-
enqueued_seq: 3,
|
|
1227
|
-
time_created: 3,
|
|
1228
|
-
})
|
|
1229
|
-
.run()
|
|
1230
|
-
.pipe(Effect.orDie)
|
|
1231
|
-
|
|
1232
|
-
const messages = yield* store.messages({ sessionID, order: "asc" })
|
|
1233
|
-
expect(messages).toHaveLength(2)
|
|
1234
|
-
expect(messages[0]).toMatchObject({
|
|
1235
|
-
id: userID,
|
|
1236
|
-
type: "user",
|
|
1237
|
-
files: [{ data: base64, mime: "application/pdf", source: { type: "inline" }, name: "spec.pdf" }],
|
|
1238
|
-
})
|
|
1239
|
-
expect(messages[1]).toMatchObject({
|
|
1240
|
-
id: assistantID,
|
|
1241
|
-
type: "assistant",
|
|
1242
|
-
content: [
|
|
1243
|
-
{
|
|
1244
|
-
type: "tool",
|
|
1245
|
-
state: {
|
|
1246
|
-
status: "completed",
|
|
1247
|
-
content: [
|
|
1248
|
-
{
|
|
1249
|
-
type: "file",
|
|
1250
|
-
uri: `data:application/pdf;base64,${base64}`,
|
|
1251
|
-
mime: "application/pdf",
|
|
1252
|
-
name: "spec.pdf",
|
|
1253
|
-
},
|
|
1254
|
-
{ type: "file", uri: pathUri, mime: "application/pdf", name: "path.pdf" },
|
|
1255
|
-
],
|
|
1256
|
-
},
|
|
1257
|
-
},
|
|
1258
|
-
],
|
|
1259
|
-
})
|
|
1260
|
-
|
|
1261
|
-
expect((yield* store.message(userID))?.message).toEqual(messages[0]!)
|
|
1262
|
-
expect(yield* store.context(sessionID)).toEqual(messages)
|
|
1263
|
-
|
|
1264
|
-
const listedInbox = yield* inbox.list(sessionID)
|
|
1265
|
-
expect(listedInbox).toHaveLength(1)
|
|
1266
|
-
expect(listedInbox[0]).toMatchObject({
|
|
1267
|
-
id: inboxID,
|
|
1268
|
-
type: "user",
|
|
1269
|
-
payload: {
|
|
1270
|
-
text: "queued attachment",
|
|
1271
|
-
files: [{ data: base64, mime: "application/pdf", source: { type: "inline" }, name: "queued.pdf" }],
|
|
1272
|
-
},
|
|
1273
|
-
})
|
|
1274
|
-
|
|
1275
|
-
expect(yield* SessionHistory.firstUserMessage(db, sessionID)).toEqual({ id: userID, text: "user attachment" })
|
|
1276
|
-
expect(yield* SessionInbox.nextPromotable(db, sessionID, "input")).toEqual({
|
|
1277
|
-
id: inboxID,
|
|
1278
|
-
type: "user",
|
|
1279
|
-
delivery: "queue",
|
|
1280
|
-
})
|
|
1281
|
-
|
|
1282
|
-
yield* bus.publish(SessionEvent.InboxDelivered, { sessionID, inboxID })
|
|
1283
|
-
expect((yield* store.message(inboxID))?.message).toMatchObject({
|
|
1284
|
-
id: inboxID,
|
|
1285
|
-
type: "user",
|
|
1286
|
-
files: [{ data: base64, mime: "application/pdf", source: { type: "inline" }, name: "queued.pdf" }],
|
|
1287
|
-
})
|
|
1288
|
-
// Delivery keeps the ref in the stored row instead of writing the bytes back inline.
|
|
1289
|
-
const delivered = yield* db
|
|
1290
|
-
.select({ data: SessionMessageTable.data })
|
|
1291
|
-
.from(SessionMessageTable)
|
|
1292
|
-
.where(eq(SessionMessageTable.id, inboxID))
|
|
1293
|
-
.get()
|
|
1294
|
-
.pipe(Effect.orDie)
|
|
1295
|
-
expect(delivered?.data).toMatchObject({
|
|
1296
|
-
text: "queued attachment",
|
|
1297
|
-
files: [{ uri, mime: "application/pdf", source: { type: "inline" }, name: "queued.pdf" }],
|
|
1298
|
-
})
|
|
1299
|
-
expect(JSON.stringify(delivered?.data)).not.toContain(base64)
|
|
1300
|
-
}),
|
|
1301
|
-
)
|
|
1302
|
-
|
|
1303
|
-
it.effect("replaces refs to missing blobs with an unavailable placeholder on read", () =>
|
|
1304
|
-
Effect.gen(function* () {
|
|
1305
|
-
const db = yield* seedSession()
|
|
1306
|
-
const inbox = yield* SessionInbox.Service
|
|
1307
|
-
const store = yield* SessionStore.Service
|
|
1308
|
-
const hash = "b".repeat(64)
|
|
1309
|
-
const userID = SessionMessage.ID.make("msg_missing_user")
|
|
1310
|
-
const assistantID = SessionMessage.ID.make("msg_missing_assistant")
|
|
1311
|
-
const inboxID = SessionMessage.ID.make("msg_missing_inbox")
|
|
1312
|
-
const placeholder = Buffer.from("[media unavailable: shot.png (image/png)]").toString("base64")
|
|
1313
|
-
const ref = SessionStored.FileRef.make({
|
|
1314
|
-
uri: `media:${hash}`,
|
|
1315
|
-
mime: "image/png",
|
|
1316
|
-
source: { type: "inline" },
|
|
1317
|
-
name: "shot.png",
|
|
1318
|
-
})
|
|
1319
|
-
|
|
1320
|
-
yield* db
|
|
1321
|
-
.insert(SessionMessageTable)
|
|
1322
|
-
.values([
|
|
1323
|
-
{
|
|
1324
|
-
id: userID,
|
|
1325
|
-
session_id: sessionID,
|
|
1326
|
-
type: "user",
|
|
1327
|
-
seq: 1,
|
|
1328
|
-
time_created: 1,
|
|
1329
|
-
data: {
|
|
1330
|
-
text: "gone",
|
|
1331
|
-
files: [ref],
|
|
1332
|
-
time: { created: 1 },
|
|
1333
|
-
},
|
|
1334
|
-
},
|
|
1335
|
-
{
|
|
1336
|
-
id: assistantID,
|
|
1337
|
-
session_id: sessionID,
|
|
1338
|
-
type: "assistant",
|
|
1339
|
-
seq: 2,
|
|
1340
|
-
time_created: 2,
|
|
1341
|
-
data: {
|
|
1342
|
-
agent: build,
|
|
1343
|
-
model,
|
|
1344
|
-
content: [
|
|
1345
|
-
{
|
|
1346
|
-
type: "tool",
|
|
1347
|
-
id: "call_1",
|
|
1348
|
-
name: "read",
|
|
1349
|
-
executed: true,
|
|
1350
|
-
state: {
|
|
1351
|
-
status: "completed",
|
|
1352
|
-
input: { path: "shot.png" },
|
|
1353
|
-
content: [SessionStored.ToolFileRef.make({ type: "file", uri: ref.uri, mime: "image/png" })],
|
|
1354
|
-
},
|
|
1355
|
-
time: { created: 2, ran: 2, completed: 2 },
|
|
1356
|
-
},
|
|
1357
|
-
],
|
|
1358
|
-
time: { created: 2, completed: 2 },
|
|
1359
|
-
},
|
|
1360
|
-
},
|
|
1361
|
-
])
|
|
1362
|
-
.run()
|
|
1363
|
-
.pipe(Effect.orDie)
|
|
1364
|
-
yield* db
|
|
1365
|
-
.insert(SessionInboxTable)
|
|
1366
|
-
.values({
|
|
1367
|
-
id: inboxID,
|
|
1368
|
-
session_id: sessionID,
|
|
1369
|
-
type: "user",
|
|
1370
|
-
payload: { text: "queued", files: [ref] },
|
|
1371
|
-
delivery: "queue",
|
|
1372
|
-
enqueued_seq: 3,
|
|
1373
|
-
time_created: 3,
|
|
1374
|
-
})
|
|
1375
|
-
.run()
|
|
1376
|
-
.pipe(Effect.orDie)
|
|
1377
|
-
|
|
1378
|
-
const messages = yield* store.messages({ sessionID, order: "asc" })
|
|
1379
|
-
expect(messages[0]).toMatchObject({
|
|
1380
|
-
files: [{ data: placeholder, mime: "text/plain", source: { type: "inline" }, name: "shot.png" }],
|
|
1381
|
-
})
|
|
1382
|
-
expect(messages[1]).toMatchObject({
|
|
1383
|
-
content: [{ state: { content: [{ type: "text", text: "[media unavailable: image/png]" }] } }],
|
|
1384
|
-
})
|
|
1385
|
-
expect(yield* store.context(sessionID)).toEqual(messages)
|
|
1386
|
-
const listed = yield* inbox.list(sessionID)
|
|
1387
|
-
expect(listed[0]).toMatchObject({ payload: { files: [{ data: placeholder, mime: "text/plain" }] } })
|
|
1388
|
-
expect(JSON.stringify([messages, listed])).not.toContain(hash)
|
|
1389
|
-
}),
|
|
1390
|
-
)
|
|
1391
|
-
|
|
1392
|
-
it.effect("names ref attachments in kept text without reading their blobs", () =>
|
|
1393
|
-
Effect.gen(function* () {
|
|
1394
|
-
const db = yield* seedSession()
|
|
1395
|
-
const store = yield* SessionStore.Service
|
|
1396
|
-
const userID = SessionMessage.ID.make("msg_kept_user")
|
|
1397
|
-
const compactionID = SessionMessage.ID.make("msg_kept_compaction")
|
|
1398
|
-
const {
|
|
1399
|
-
id: _,
|
|
1400
|
-
type: __,
|
|
1401
|
-
...compaction
|
|
1402
|
-
} = encodeMessage(
|
|
1403
|
-
SessionMessage.CompactionCompleted.make({
|
|
1404
|
-
id: compactionID,
|
|
1405
|
-
type: "compaction",
|
|
1406
|
-
status: "completed",
|
|
1407
|
-
reason: "manual",
|
|
1408
|
-
summary: "summary",
|
|
1409
|
-
metadata: { keepID: userID },
|
|
1410
|
-
time: { created },
|
|
1411
|
-
}),
|
|
1412
|
-
)
|
|
1413
|
-
yield* db
|
|
1414
|
-
.insert(SessionMessageTable)
|
|
1415
|
-
.values([
|
|
1416
|
-
{
|
|
1417
|
-
id: userID,
|
|
1418
|
-
session_id: sessionID,
|
|
1419
|
-
type: "user",
|
|
1420
|
-
seq: 1,
|
|
1421
|
-
time_created: 1,
|
|
1422
|
-
data: {
|
|
1423
|
-
text: "look",
|
|
1424
|
-
files: [
|
|
1425
|
-
SessionStored.FileRef.make({
|
|
1426
|
-
uri: `media:${"c".repeat(64)}`,
|
|
1427
|
-
mime: "image/png",
|
|
1428
|
-
source: { type: "inline" },
|
|
1429
|
-
name: "shot.png",
|
|
1430
|
-
}),
|
|
1431
|
-
],
|
|
1432
|
-
time: { created: 1 },
|
|
1433
|
-
},
|
|
1434
|
-
},
|
|
1435
|
-
{ id: compactionID, session_id: sessionID, type: "compaction", seq: 2, time_created: 2, data: compaction },
|
|
1436
|
-
])
|
|
1437
|
-
.run()
|
|
1438
|
-
.pipe(Effect.orDie)
|
|
1439
|
-
|
|
1440
|
-
// The blob is missing, so a hydrated read would name a text/plain placeholder instead.
|
|
1441
|
-
expect(yield* store.context(sessionID)).toMatchObject([
|
|
1442
|
-
{ id: compactionID, metadata: { recent: "[User]: look\n[Attached image/png: shot.png]" } },
|
|
1443
|
-
])
|
|
1444
|
-
}),
|
|
1445
|
-
)
|
|
1446
|
-
|
|
1447
|
-
it.effect("keeps media inline unless experimental.media_blob is on", () =>
|
|
1448
|
-
Effect.gen(function* () {
|
|
1449
|
-
const db = yield* seedSession()
|
|
1450
|
-
const inbox = yield* SessionInbox.Service
|
|
1451
|
-
const id = SessionMessage.ID.make("msg_media_inline")
|
|
1452
|
-
yield* inbox.admit({
|
|
1453
|
-
id,
|
|
1454
|
-
sessionID,
|
|
1455
|
-
item: { type: "user", payload: { text: "inline", files: [attachment("shot.png")] }, delivery: "queue" },
|
|
1456
|
-
})
|
|
1457
|
-
|
|
1458
|
-
const row = yield* db
|
|
1459
|
-
.select()
|
|
1460
|
-
.from(SessionInboxTable)
|
|
1461
|
-
.where(eq(SessionInboxTable.id, id))
|
|
1462
|
-
.get()
|
|
1463
|
-
.pipe(Effect.orDie)
|
|
1464
|
-
expect(row?.payload).toEqual({ text: "inline", files: [attachment("shot.png")] })
|
|
1465
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1466
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1467
|
-
}),
|
|
1468
|
-
)
|
|
1469
|
-
|
|
1470
|
-
it.effect("stores media once and refs it from inbox, message, and tool rows when experimental.media_blob is on", () =>
|
|
1471
|
-
Effect.gen(function* () {
|
|
1472
|
-
const db = yield* seedSession()
|
|
1473
|
-
const bus = yield* Bus.Service
|
|
1474
|
-
const inbox = yield* SessionInbox.Service
|
|
1475
|
-
const store = yield* SessionStore.Service
|
|
1476
|
-
const hash = SessionBlob.hashBytes(png)
|
|
1477
|
-
const uri = SessionStored.ref(hash)
|
|
1478
|
-
const id = SessionMessage.ID.make("msg_media_user")
|
|
1479
|
-
const files = [attachment("shot.png"), attachment("copy.png")]
|
|
1480
|
-
const refs = [
|
|
1481
|
-
{ mime: "image/png", source: { type: "inline" }, name: "shot.png", uri },
|
|
1482
|
-
{ mime: "image/png", source: { type: "inline" }, name: "copy.png", uri },
|
|
1483
|
-
]
|
|
1484
|
-
|
|
1485
|
-
yield* inbox.admit({ id, sessionID, item: { type: "user", payload: { text: "look", files }, delivery: "steer" } })
|
|
1486
|
-
const queued = yield* db
|
|
1487
|
-
.select()
|
|
1488
|
-
.from(SessionInboxTable)
|
|
1489
|
-
.where(eq(SessionInboxTable.id, id))
|
|
1490
|
-
.get()
|
|
1491
|
-
.pipe(Effect.orDie)
|
|
1492
|
-
expect(queued?.payload).toEqual({ text: "look", files: refs })
|
|
1493
|
-
expect(yield* inbox.list(sessionID)).toMatchObject([{ id, payload: { text: "look", files } }])
|
|
1494
|
-
|
|
1495
|
-
const delivered = yield* bus.publish(SessionEvent.InboxDelivered, { sessionID, inboxID: id })
|
|
1496
|
-
const message = yield* db
|
|
1497
|
-
.select()
|
|
1498
|
-
.from(SessionMessageTable)
|
|
1499
|
-
.where(eq(SessionMessageTable.id, id))
|
|
1500
|
-
.get()
|
|
1501
|
-
.pipe(Effect.orDie)
|
|
1502
|
-
expect(message?.data).toMatchObject({ text: "look", files: refs })
|
|
1503
|
-
expect((yield* store.message(id))?.message).toMatchObject({ type: "user", files })
|
|
1504
|
-
|
|
1505
|
-
const assistantMessageID = SessionMessage.ID.make("msg_media_tool")
|
|
1506
|
-
yield* db.insert(SessionMessageTable).values(assistantRow(assistantMessageID, 0)).run().pipe(Effect.orDie)
|
|
1507
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id: "shot", name: "shot" })
|
|
1508
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
1509
|
-
sessionID,
|
|
1510
|
-
assistantMessageID,
|
|
1511
|
-
id: "shot",
|
|
1512
|
-
input: {},
|
|
1513
|
-
executed: true,
|
|
1514
|
-
})
|
|
1515
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
1516
|
-
sessionID,
|
|
1517
|
-
assistantMessageID,
|
|
1518
|
-
id: "shot",
|
|
1519
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
1520
|
-
executed: true,
|
|
1521
|
-
})
|
|
1522
|
-
const tool = yield* db
|
|
1523
|
-
.select()
|
|
1524
|
-
.from(SessionPartTable)
|
|
1525
|
-
.where(and(eq(SessionPartTable.message_id, assistantMessageID), eq(SessionPartTable.call_id, "shot")))
|
|
1526
|
-
.get()
|
|
1527
|
-
.pipe(Effect.orDie)
|
|
1528
|
-
expect(tool?.data).toMatchObject({
|
|
1529
|
-
state: { status: "completed", content: [{ type: "file", uri, mime: "image/png" }] },
|
|
1530
|
-
})
|
|
1531
|
-
expect((yield* store.message(assistantMessageID))?.message).toMatchObject({
|
|
1532
|
-
content: [
|
|
1533
|
-
{
|
|
1534
|
-
state: {
|
|
1535
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
1536
|
-
},
|
|
1537
|
-
},
|
|
1538
|
-
],
|
|
1539
|
-
})
|
|
1540
|
-
|
|
1541
|
-
expect(
|
|
1542
|
-
yield* db
|
|
1543
|
-
.select({
|
|
1544
|
-
hash: BlobTable.hash,
|
|
1545
|
-
mime: BlobTable.mime,
|
|
1546
|
-
bytes: BlobTable.bytes,
|
|
1547
|
-
})
|
|
1548
|
-
.from(BlobTable)
|
|
1549
|
-
.all()
|
|
1550
|
-
.pipe(Effect.orDie),
|
|
1551
|
-
).toEqual([{ hash, mime: "image/png", bytes: png.byteLength }])
|
|
1552
|
-
expect(
|
|
1553
|
-
yield* db
|
|
1554
|
-
.select({ message: BlobRefTable.message_id, hash: BlobRefTable.hash, seq: BlobRefTable.seq })
|
|
1555
|
-
.from(BlobRefTable)
|
|
1556
|
-
.orderBy(asc(BlobRefTable.seq))
|
|
1557
|
-
.all()
|
|
1558
|
-
.pipe(Effect.orDie),
|
|
1559
|
-
).toEqual([
|
|
1560
|
-
{ message: assistantMessageID, hash, seq: 0 },
|
|
1561
|
-
{ message: id, hash, seq: delivered.durable?.seq },
|
|
1562
|
-
])
|
|
1563
|
-
}).pipe(Effect.provide(mediaBlobPartRows)),
|
|
1564
|
-
)
|
|
1565
|
-
|
|
1566
|
-
it.effect("deletes a cancelled inbox row's blob refs and blobs", () =>
|
|
1567
|
-
Effect.gen(function* () {
|
|
1568
|
-
const db = yield* seedSession()
|
|
1569
|
-
const inbox = yield* SessionInbox.Service
|
|
1570
|
-
const id = SessionMessage.ID.make("msg_media_cancel")
|
|
1571
|
-
yield* inbox.admit({
|
|
1572
|
-
id,
|
|
1573
|
-
sessionID,
|
|
1574
|
-
item: { type: "user", payload: { text: "later", files: [attachment("shot.png")] }, delivery: "queue" },
|
|
1575
|
-
})
|
|
1576
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1577
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1578
|
-
|
|
1579
|
-
yield* inbox.cancel({ id, sessionID })
|
|
1580
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1581
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1582
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
1583
|
-
)
|
|
1584
|
-
|
|
1585
|
-
it.effect("deletes reverted messages' blob refs and the blobs only they referenced", () =>
|
|
1586
|
-
Effect.gen(function* () {
|
|
1587
|
-
const db = yield* seedSession()
|
|
1588
|
-
const bus = yield* Bus.Service
|
|
1589
|
-
const inbox = yield* SessionInbox.Service
|
|
1590
|
-
const text = Buffer.from("reverted attachment")
|
|
1591
|
-
const deliver = (id: SessionMessage.ID, files: ReturnType<typeof attachment>[]) =>
|
|
1592
|
-
Effect.gen(function* () {
|
|
1593
|
-
yield* inbox.admit({ id, sessionID, item: { type: "user", payload: { text: id, files }, delivery: "steer" } })
|
|
1594
|
-
yield* bus.publish(SessionEvent.InboxDelivered, { sessionID, inboxID: id })
|
|
1595
|
-
})
|
|
1596
|
-
const kept = SessionMessage.ID.make("msg_media_kept")
|
|
1597
|
-
const reverted = SessionMessage.ID.make("msg_media_reverted")
|
|
1598
|
-
const shared = SessionMessage.ID.make("msg_media_shared")
|
|
1599
|
-
yield* deliver(kept, [attachment("shot.png")])
|
|
1600
|
-
yield* deliver(reverted, [attachment("notes.txt", text, "text/plain")])
|
|
1601
|
-
yield* deliver(shared, [attachment("again.png")])
|
|
1602
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toHaveLength(3)
|
|
1603
|
-
|
|
1604
|
-
yield* bus.publish(SessionEvent.RevertEvent.Committed, { sessionID, to: reverted })
|
|
1605
|
-
expect(
|
|
1606
|
-
yield* db
|
|
1607
|
-
.select({ message: BlobRefTable.message_id, hash: BlobRefTable.hash })
|
|
1608
|
-
.from(BlobRefTable)
|
|
1609
|
-
.all()
|
|
1610
|
-
.pipe(Effect.orDie),
|
|
1611
|
-
).toEqual([{ message: kept, hash: SessionBlob.hashBytes(png) }])
|
|
1612
|
-
expect(yield* db.select({ hash: BlobTable.hash }).from(BlobTable).all().pipe(Effect.orDie)).toEqual([
|
|
1613
|
-
{ hash: SessionBlob.hashBytes(png) },
|
|
1614
|
-
])
|
|
1615
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
1616
|
-
)
|
|
1617
|
-
|
|
1618
|
-
it.effect("keeps a blob while a fork references it and deletes it with the last session", () =>
|
|
1619
|
-
Effect.gen(function* () {
|
|
1620
|
-
const db = yield* seedSession()
|
|
1621
|
-
const bus = yield* Bus.Service
|
|
1622
|
-
const inbox = yield* SessionInbox.Service
|
|
1623
|
-
const id = SessionMessage.ID.make("msg_media_forked")
|
|
1624
|
-
const childID = Session.ID.make("ses_media_fork")
|
|
1625
|
-
yield* inbox.admit({
|
|
1626
|
-
id,
|
|
1627
|
-
sessionID,
|
|
1628
|
-
item: { type: "user", payload: { text: "fork me", files: [attachment("shot.png")] }, delivery: "steer" },
|
|
1629
|
-
})
|
|
1630
|
-
yield* bus.publish(SessionEvent.InboxDelivered, { sessionID, inboxID: id })
|
|
1631
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
1632
|
-
sessionID: childID,
|
|
1633
|
-
parentID: sessionID,
|
|
1634
|
-
boundary: { type: "through", messageID: id },
|
|
1635
|
-
})
|
|
1636
|
-
expect(
|
|
1637
|
-
yield* db.select({ session: BlobRefTable.session_id }).from(BlobRefTable).all().pipe(Effect.orDie),
|
|
1638
|
-
).toEqual(expect.arrayContaining([{ session: sessionID }, { session: childID }]))
|
|
1639
|
-
|
|
1640
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID })
|
|
1641
|
-
expect(
|
|
1642
|
-
yield* db.select({ session: BlobRefTable.session_id }).from(BlobRefTable).all().pipe(Effect.orDie),
|
|
1643
|
-
).toEqual([{ session: childID }])
|
|
1644
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1645
|
-
|
|
1646
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID: childID })
|
|
1647
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1648
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1649
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
1650
|
-
)
|
|
1651
|
-
|
|
1652
|
-
it.effect("keeps a tool part's blob while a fork references it", () =>
|
|
1653
|
-
Effect.gen(function* () {
|
|
1654
|
-
const db = yield* seedSession()
|
|
1655
|
-
const bus = yield* Bus.Service
|
|
1656
|
-
const assistantMessageID = SessionMessage.ID.make("msg_media_tool_forked")
|
|
1657
|
-
const childID = Session.ID.make("ses_media_tool_fork")
|
|
1658
|
-
yield* bus.publish(SessionEvent.Step.Started, { sessionID, assistantMessageID, agent: build, model, started: 1 })
|
|
1659
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id: "shot", name: "shot" })
|
|
1660
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
1661
|
-
sessionID,
|
|
1662
|
-
assistantMessageID,
|
|
1663
|
-
id: "shot",
|
|
1664
|
-
input: {},
|
|
1665
|
-
executed: true,
|
|
1666
|
-
})
|
|
1667
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
1668
|
-
sessionID,
|
|
1669
|
-
assistantMessageID,
|
|
1670
|
-
id: "shot",
|
|
1671
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
1672
|
-
executed: true,
|
|
1673
|
-
})
|
|
1674
|
-
yield* bus.publish(SessionEvent.Step.Ended, {
|
|
1675
|
-
sessionID,
|
|
1676
|
-
assistantMessageID,
|
|
1677
|
-
finish: "stop",
|
|
1678
|
-
cost: Money.USD.make(0),
|
|
1679
|
-
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
1680
|
-
})
|
|
1681
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
1682
|
-
sessionID: childID,
|
|
1683
|
-
parentID: sessionID,
|
|
1684
|
-
boundary: { type: "through", messageID: assistantMessageID },
|
|
1685
|
-
})
|
|
1686
|
-
|
|
1687
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID })
|
|
1688
|
-
expect(
|
|
1689
|
-
yield* db.select({ session: BlobRefTable.session_id }).from(BlobRefTable).all().pipe(Effect.orDie),
|
|
1690
|
-
).toEqual([{ session: childID }])
|
|
1691
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1692
|
-
|
|
1693
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID: childID })
|
|
1694
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1695
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
1696
|
-
)
|
|
1697
|
-
|
|
1698
|
-
it.effect("releases a tool's blob when a content update drops its ref", () =>
|
|
1699
|
-
Effect.gen(function* () {
|
|
1700
|
-
const db = yield* seedSession()
|
|
1701
|
-
const bus = yield* Bus.Service
|
|
1702
|
-
const assistantMessageID = SessionMessage.ID.make("msg_media_rewritten")
|
|
1703
|
-
yield* db.insert(SessionMessageTable).values(assistantRow(assistantMessageID, 0)).run().pipe(Effect.orDie)
|
|
1704
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id: "shot", name: "shot" })
|
|
1705
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
1706
|
-
sessionID,
|
|
1707
|
-
assistantMessageID,
|
|
1708
|
-
id: "shot",
|
|
1709
|
-
input: {},
|
|
1710
|
-
executed: true,
|
|
1711
|
-
})
|
|
1712
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
1713
|
-
sessionID,
|
|
1714
|
-
assistantMessageID,
|
|
1715
|
-
id: "shot",
|
|
1716
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
1717
|
-
executed: true,
|
|
1718
|
-
})
|
|
1719
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1720
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
1721
|
-
|
|
1722
|
-
yield* bus.publish(SessionEvent.MessageContentUpdated, { sessionID, messageID: assistantMessageID, content: [] })
|
|
1723
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1724
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
1725
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
1726
|
-
)
|
|
1727
|
-
|
|
1728
|
-
it.effect(
|
|
1729
|
-
"stores interleaved assistant parts in session_part by ordinal across out-of-order tool completions and forks",
|
|
1730
|
-
() =>
|
|
1731
|
-
Effect.gen(function* () {
|
|
1732
|
-
const db = yield* seedSession()
|
|
1733
|
-
const bus = yield* Bus.Service
|
|
1734
|
-
const assistantMessageID = SessionMessage.ID.make("msg_interleaved")
|
|
1735
|
-
|
|
1736
|
-
yield* bus.publish(SessionEvent.Step.Started, {
|
|
1737
|
-
sessionID,
|
|
1738
|
-
assistantMessageID,
|
|
1739
|
-
agent: build,
|
|
1740
|
-
model,
|
|
1741
|
-
started: 1,
|
|
1742
|
-
})
|
|
1743
|
-
yield* bus.publish(SessionEvent.Reasoning.Started, { sessionID, assistantMessageID, ordinal: 0 })
|
|
1744
|
-
yield* bus.publish(SessionEvent.Reasoning.Ended, {
|
|
1745
|
-
sessionID,
|
|
1746
|
-
assistantMessageID,
|
|
1747
|
-
ordinal: 0,
|
|
1748
|
-
text: "plan first",
|
|
1749
|
-
})
|
|
1750
|
-
yield* bus.publish(SessionEvent.Text.Started, { sessionID, assistantMessageID, ordinal: 1 })
|
|
1751
|
-
yield* bus.publish(SessionEvent.Text.Ended, {
|
|
1752
|
-
sessionID,
|
|
1753
|
-
assistantMessageID,
|
|
1754
|
-
ordinal: 1,
|
|
1755
|
-
text: "running two tools",
|
|
1756
|
-
})
|
|
1757
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, {
|
|
1758
|
-
sessionID,
|
|
1759
|
-
assistantMessageID,
|
|
1760
|
-
id: "call_first",
|
|
1761
|
-
name: "read",
|
|
1762
|
-
})
|
|
1763
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
1764
|
-
sessionID,
|
|
1765
|
-
assistantMessageID,
|
|
1766
|
-
id: "call_first",
|
|
1767
|
-
input: { file: "a.ts" },
|
|
1768
|
-
executed: true,
|
|
1769
|
-
})
|
|
1770
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, {
|
|
1771
|
-
sessionID,
|
|
1772
|
-
assistantMessageID,
|
|
1773
|
-
id: "call_second",
|
|
1774
|
-
name: "read",
|
|
1775
|
-
})
|
|
1776
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
1777
|
-
sessionID,
|
|
1778
|
-
assistantMessageID,
|
|
1779
|
-
id: "call_second",
|
|
1780
|
-
input: { file: "b.ts" },
|
|
1781
|
-
executed: true,
|
|
1782
|
-
})
|
|
1783
|
-
// Complete the second tool before the first tool
|
|
1784
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
1785
|
-
sessionID,
|
|
1786
|
-
assistantMessageID,
|
|
1787
|
-
id: "call_second",
|
|
1788
|
-
content: [{ type: "text", text: "b contents" }],
|
|
1789
|
-
executed: true,
|
|
1790
|
-
})
|
|
1791
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
1792
|
-
sessionID,
|
|
1793
|
-
assistantMessageID,
|
|
1794
|
-
id: "call_first",
|
|
1795
|
-
content: [{ type: "text", text: "a contents" }],
|
|
1796
|
-
executed: true,
|
|
1797
|
-
})
|
|
1798
|
-
yield* bus.publish(SessionEvent.Text.Started, { sessionID, assistantMessageID, ordinal: 4 })
|
|
1799
|
-
yield* bus.publish(SessionEvent.Text.Ended, {
|
|
1800
|
-
sessionID,
|
|
1801
|
-
assistantMessageID,
|
|
1802
|
-
ordinal: 4,
|
|
1803
|
-
text: "all done",
|
|
1804
|
-
})
|
|
1805
|
-
yield* bus.publish(SessionEvent.Step.Ended, {
|
|
1806
|
-
sessionID,
|
|
1807
|
-
assistantMessageID,
|
|
1808
|
-
finish: "stop",
|
|
1809
|
-
cost: Money.USD.make(0),
|
|
1810
|
-
tokens: { input: 10, output: 5, reasoning: 2, cache: { read: 0, write: 0 } },
|
|
1811
|
-
})
|
|
1812
|
-
|
|
1813
|
-
const envelope = yield* db
|
|
1814
|
-
.select()
|
|
1815
|
-
.from(SessionMessageTable)
|
|
1816
|
-
.where(eq(SessionMessageTable.id, assistantMessageID))
|
|
1817
|
-
.get()
|
|
1818
|
-
.pipe(Effect.orDie)
|
|
1819
|
-
expect(envelope?.data).toMatchObject({ content: [] })
|
|
1820
|
-
|
|
1821
|
-
const parts = yield* db
|
|
1822
|
-
.select()
|
|
1823
|
-
.from(SessionPartTable)
|
|
1824
|
-
.where(eq(SessionPartTable.message_id, assistantMessageID))
|
|
1825
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
1826
|
-
.all()
|
|
1827
|
-
.pipe(Effect.orDie)
|
|
1828
|
-
expect(parts.map((row) => ({ ordinal: row.ordinal, type: row.type, callID: row.call_id }))).toEqual([
|
|
1829
|
-
{ ordinal: 0, type: "reasoning", callID: null },
|
|
1830
|
-
{ ordinal: 1, type: "text", callID: null },
|
|
1831
|
-
{ ordinal: 2, type: "tool", callID: "call_first" },
|
|
1832
|
-
{ ordinal: 3, type: "tool", callID: "call_second" },
|
|
1833
|
-
{ ordinal: 4, type: "text", callID: null },
|
|
1834
|
-
])
|
|
1835
|
-
|
|
1836
|
-
const forkedSessionID = Session.ID.make("ses_projected_fork")
|
|
1837
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
1838
|
-
sessionID: forkedSessionID,
|
|
1839
|
-
parentID: sessionID,
|
|
1840
|
-
boundary: { type: "through", messageID: assistantMessageID },
|
|
1841
|
-
})
|
|
1842
|
-
const forkedMessage = yield* db
|
|
1843
|
-
.select()
|
|
1844
|
-
.from(SessionMessageTable)
|
|
1845
|
-
.where(eq(SessionMessageTable.session_id, forkedSessionID))
|
|
1846
|
-
.get()
|
|
1847
|
-
.pipe(Effect.orDie)
|
|
1848
|
-
const loadedFork = yield* SessionHistory.loadMessageRow(db, forkedMessage!).pipe(Effect.orDie)
|
|
1849
|
-
expect(loadedFork).toMatchObject({
|
|
1850
|
-
type: "assistant",
|
|
1851
|
-
content: [
|
|
1852
|
-
{ type: "reasoning", text: "plan first" },
|
|
1853
|
-
{ type: "text", text: "running two tools" },
|
|
1854
|
-
{ type: "tool", id: "call_first", state: { status: "completed" } },
|
|
1855
|
-
{ type: "tool", id: "call_second", state: { status: "completed" } },
|
|
1856
|
-
{ type: "text", text: "all done" },
|
|
1857
|
-
],
|
|
1858
|
-
})
|
|
1859
|
-
}).pipe(Effect.provide(partRows)),
|
|
1860
|
-
)
|
|
1861
|
-
|
|
1862
|
-
it.effect("appends inline content after existing session_part rows when splitting an inline assistant row", () =>
|
|
1863
|
-
Effect.gen(function* () {
|
|
1864
|
-
const db = yield* seedSession()
|
|
1865
|
-
const bus = yield* Bus.Service
|
|
1866
|
-
const conflictID = SessionMessage.ID.make("msg_conflict_replace")
|
|
1867
|
-
|
|
1868
|
-
// Simulate a downgrade: part rows (ordinals 0..2) exist, then an older build wrote inline content
|
|
1869
|
-
yield* db
|
|
1870
|
-
.insert(SessionMessageTable)
|
|
1871
|
-
.values({
|
|
1872
|
-
id: conflictID,
|
|
1873
|
-
session_id: sessionID,
|
|
1874
|
-
seq: 1,
|
|
1875
|
-
type: "assistant",
|
|
1876
|
-
time_created: 10,
|
|
1877
|
-
time_updated: 20,
|
|
1878
|
-
data: {
|
|
1879
|
-
agent: build,
|
|
1880
|
-
model,
|
|
1881
|
-
content: [
|
|
1882
|
-
{ type: "reasoning", text: "fresh inline reasoning", time: { created: 10, completed: 12 } },
|
|
1883
|
-
{ type: "text", text: "fresh inline text" },
|
|
1884
|
-
],
|
|
1885
|
-
time: { created: 10 },
|
|
1886
|
-
},
|
|
1887
|
-
})
|
|
1888
|
-
.run()
|
|
1889
|
-
.pipe(Effect.orDie)
|
|
1890
|
-
yield* db
|
|
1891
|
-
.insert(SessionPartTable)
|
|
1892
|
-
.values([
|
|
1893
|
-
{
|
|
1894
|
-
message_id: conflictID,
|
|
1895
|
-
session_id: sessionID,
|
|
1896
|
-
ordinal: 0,
|
|
1897
|
-
type: "text",
|
|
1898
|
-
call_id: null,
|
|
1899
|
-
time_created: 1,
|
|
1900
|
-
time_updated: 1,
|
|
1901
|
-
data: { type: "text", text: "stale part 0" },
|
|
1902
|
-
},
|
|
1903
|
-
{
|
|
1904
|
-
message_id: conflictID,
|
|
1905
|
-
session_id: sessionID,
|
|
1906
|
-
ordinal: 1,
|
|
1907
|
-
type: "text",
|
|
1908
|
-
call_id: null,
|
|
1909
|
-
time_created: 2,
|
|
1910
|
-
time_updated: 2,
|
|
1911
|
-
data: { type: "text", text: "stale part 1" },
|
|
1912
|
-
},
|
|
1913
|
-
{
|
|
1914
|
-
message_id: conflictID,
|
|
1915
|
-
session_id: sessionID,
|
|
1916
|
-
ordinal: 2,
|
|
1917
|
-
type: "text",
|
|
1918
|
-
call_id: null,
|
|
1919
|
-
time_created: 3,
|
|
1920
|
-
time_updated: 3,
|
|
1921
|
-
data: { type: "text", text: "stale trailing part 2" },
|
|
1922
|
-
},
|
|
1923
|
-
])
|
|
1924
|
-
.run()
|
|
1925
|
-
.pipe(Effect.orDie)
|
|
1926
|
-
|
|
1927
|
-
yield* bus.publish(SessionEvent.Text.Started, {
|
|
1928
|
-
sessionID,
|
|
1929
|
-
assistantMessageID: conflictID,
|
|
1930
|
-
ordinal: 5,
|
|
1931
|
-
})
|
|
1932
|
-
yield* bus.publish(SessionEvent.Text.Ended, {
|
|
1933
|
-
sessionID,
|
|
1934
|
-
assistantMessageID: conflictID,
|
|
1935
|
-
ordinal: 5,
|
|
1936
|
-
text: "appended after split",
|
|
1937
|
-
})
|
|
1938
|
-
|
|
1939
|
-
const messageRow = yield* db
|
|
1940
|
-
.select()
|
|
1941
|
-
.from(SessionMessageTable)
|
|
1942
|
-
.where(eq(SessionMessageTable.id, conflictID))
|
|
1943
|
-
.get()
|
|
1944
|
-
.pipe(Effect.orDie)
|
|
1945
|
-
expect(messageRow?.data).toMatchObject({ content: [] })
|
|
1946
|
-
|
|
1947
|
-
const partRows = yield* db
|
|
1948
|
-
.select()
|
|
1949
|
-
.from(SessionPartTable)
|
|
1950
|
-
.where(eq(SessionPartTable.message_id, conflictID))
|
|
1951
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
1952
|
-
.all()
|
|
1953
|
-
.pipe(Effect.orDie)
|
|
1954
|
-
expect(partRows.map((row) => ({ ordinal: row.ordinal, data: row.data }))).toMatchObject([
|
|
1955
|
-
{ ordinal: 0, data: { type: "text", text: "stale part 0" } },
|
|
1956
|
-
{ ordinal: 1, data: { type: "text", text: "stale part 1" } },
|
|
1957
|
-
{ ordinal: 2, data: { type: "text", text: "stale trailing part 2" } },
|
|
1958
|
-
{ ordinal: 3, data: { type: "reasoning", text: "fresh inline reasoning" } },
|
|
1959
|
-
{ ordinal: 4, data: { type: "text", text: "fresh inline text" } },
|
|
1960
|
-
{ ordinal: 5, data: { type: "text", text: "appended after split" } },
|
|
1961
|
-
])
|
|
1962
|
-
}),
|
|
1963
|
-
)
|
|
1964
|
-
|
|
1965
|
-
it.effect("splits inline media out of a session_part tool row for offline blob backfills", () =>
|
|
1966
|
-
Effect.sync(() => {
|
|
1967
|
-
const hash = SessionBlob.hashBytes(png)
|
|
1968
|
-
const split = SessionBlob.split({
|
|
1969
|
-
type: "tool",
|
|
1970
|
-
id: "call_shot",
|
|
1971
|
-
name: "shot",
|
|
1972
|
-
state: {
|
|
1973
|
-
status: "completed",
|
|
1974
|
-
input: {},
|
|
1975
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
1976
|
-
time: { created: 1, completed: 2 },
|
|
1977
|
-
},
|
|
1978
|
-
})
|
|
1979
|
-
expect(split.moved).toBe(true)
|
|
1980
|
-
expect(split.hashes).toEqual(new Set([hash]))
|
|
1981
|
-
expect(split.blobs).toEqual([{ hash, mime: "image/png", bytes: png.byteLength, data: png }])
|
|
1982
|
-
expect(split.data).toMatchObject({
|
|
1983
|
-
type: "tool",
|
|
1984
|
-
state: {
|
|
1985
|
-
status: "completed",
|
|
1986
|
-
content: [{ type: "file", uri: SessionStored.ref(hash), mime: "image/png" }],
|
|
1987
|
-
},
|
|
1988
|
-
})
|
|
1989
|
-
}),
|
|
1990
|
-
)
|
|
1991
|
-
|
|
1992
|
-
// A newer release wrote this in-progress message's parts as session_part rows, then the user rolled back.
|
|
1993
|
-
it.effect("keeps projecting into session_part rows a newer release wrote for an in-progress message", () =>
|
|
1994
|
-
Effect.gen(function* () {
|
|
1995
|
-
const db = yield* seedSession()
|
|
1996
|
-
const bus = yield* Bus.Service
|
|
1997
|
-
const store = yield* SessionStore.Service
|
|
1998
|
-
const assistantMessageID = SessionMessage.ID.make("msg_rolled_back")
|
|
1999
|
-
yield* db.insert(SessionMessageTable).values(assistantRow(assistantMessageID, 0)).run().pipe(Effect.orDie)
|
|
2000
|
-
yield* db
|
|
2001
|
-
.insert(SessionPartTable)
|
|
2002
|
-
.values([
|
|
2003
|
-
{
|
|
2004
|
-
message_id: assistantMessageID,
|
|
2005
|
-
session_id: sessionID,
|
|
2006
|
-
ordinal: 0,
|
|
2007
|
-
type: "text",
|
|
2008
|
-
call_id: null,
|
|
2009
|
-
time_created: 1,
|
|
2010
|
-
time_updated: 1,
|
|
2011
|
-
data: { type: "text", text: "before rollback" },
|
|
2012
|
-
},
|
|
2013
|
-
{
|
|
2014
|
-
message_id: assistantMessageID,
|
|
2015
|
-
session_id: sessionID,
|
|
2016
|
-
ordinal: 1,
|
|
2017
|
-
type: "tool",
|
|
2018
|
-
call_id: "call_a",
|
|
2019
|
-
time_created: 1,
|
|
2020
|
-
time_updated: 1,
|
|
2021
|
-
data: {
|
|
2022
|
-
type: "tool",
|
|
2023
|
-
id: "call_a",
|
|
2024
|
-
name: "read",
|
|
2025
|
-
executed: true,
|
|
2026
|
-
state: { status: "running", input: { path: "a.ts" }, metadata: {} },
|
|
2027
|
-
time: { created: 1, ran: 1 },
|
|
2028
|
-
},
|
|
2029
|
-
},
|
|
2030
|
-
])
|
|
2031
|
-
.run()
|
|
2032
|
-
.pipe(Effect.orDie)
|
|
2033
|
-
|
|
2034
|
-
yield* TestClock.setTime(5)
|
|
2035
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
2036
|
-
sessionID,
|
|
2037
|
-
assistantMessageID,
|
|
2038
|
-
id: "call_a",
|
|
2039
|
-
content: [{ type: "text", text: "export {}" }],
|
|
2040
|
-
executed: true,
|
|
2041
|
-
})
|
|
2042
|
-
yield* bus.publish(SessionEvent.Text.Started, { sessionID, assistantMessageID, ordinal: 1 })
|
|
2043
|
-
yield* bus.publish(SessionEvent.Text.Ended, { sessionID, assistantMessageID, ordinal: 1, text: "after rollback" })
|
|
2044
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id: "call_b", name: "grep" })
|
|
2045
|
-
|
|
2046
|
-
expect((yield* store.message(assistantMessageID))?.message).toMatchObject({
|
|
2047
|
-
content: [
|
|
2048
|
-
{ type: "text", text: "before rollback" },
|
|
2049
|
-
{
|
|
2050
|
-
type: "tool",
|
|
2051
|
-
id: "call_a",
|
|
2052
|
-
state: { status: "completed", content: [{ type: "text", text: "export {}" }] },
|
|
2053
|
-
},
|
|
2054
|
-
{ type: "text", text: "after rollback" },
|
|
2055
|
-
{ type: "tool", id: "call_b", state: { status: "streaming" } },
|
|
2056
|
-
],
|
|
2057
|
-
})
|
|
2058
|
-
const row = yield* db
|
|
2059
|
-
.select({ data: SessionMessageTable.data })
|
|
2060
|
-
.from(SessionMessageTable)
|
|
2061
|
-
.where(eq(SessionMessageTable.id, assistantMessageID))
|
|
2062
|
-
.get()
|
|
2063
|
-
.pipe(Effect.orDie)
|
|
2064
|
-
expect(row?.data).toMatchObject({ content: [] })
|
|
2065
|
-
expect(
|
|
2066
|
-
yield* db
|
|
2067
|
-
.select({
|
|
2068
|
-
ordinal: SessionPartTable.ordinal,
|
|
2069
|
-
type: SessionPartTable.type,
|
|
2070
|
-
call: SessionPartTable.call_id,
|
|
2071
|
-
updated: SessionPartTable.time_updated,
|
|
2072
|
-
})
|
|
2073
|
-
.from(SessionPartTable)
|
|
2074
|
-
.where(eq(SessionPartTable.message_id, assistantMessageID))
|
|
2075
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
2076
|
-
.all()
|
|
2077
|
-
.pipe(Effect.orDie),
|
|
2078
|
-
).toEqual([
|
|
2079
|
-
{ ordinal: 0, type: "text", call: null, updated: 1 },
|
|
2080
|
-
{ ordinal: 1, type: "tool", call: "call_a", updated: 5 },
|
|
2081
|
-
{ ordinal: 2, type: "text", call: null, updated: 5 },
|
|
2082
|
-
{ ordinal: 3, type: "tool", call: "call_b", updated: 5 },
|
|
2083
|
-
])
|
|
2084
|
-
}),
|
|
2085
|
-
)
|
|
2086
|
-
|
|
2087
|
-
it.effect("forks a settled message whose parts are in session_part with its content", () =>
|
|
2088
|
-
Effect.gen(function* () {
|
|
2089
|
-
const db = yield* seedSession()
|
|
2090
|
-
const bus = yield* Bus.Service
|
|
2091
|
-
const store = yield* SessionStore.Service
|
|
2092
|
-
const messageID = SessionMessage.ID.make("msg_split_settled")
|
|
2093
|
-
const childID = Session.ID.make("ses_split_fork")
|
|
2094
|
-
yield* db
|
|
2095
|
-
.insert(SessionMessageTable)
|
|
2096
|
-
.values(assistantRow(messageID, 0, { created, completed: created }))
|
|
2097
|
-
.run()
|
|
2098
|
-
.pipe(Effect.orDie)
|
|
2099
|
-
yield* db
|
|
2100
|
-
.insert(SessionPartTable)
|
|
2101
|
-
.values({
|
|
2102
|
-
message_id: messageID,
|
|
2103
|
-
session_id: sessionID,
|
|
2104
|
-
ordinal: 0,
|
|
2105
|
-
type: "text",
|
|
2106
|
-
call_id: null,
|
|
2107
|
-
time_created: 0,
|
|
2108
|
-
time_updated: 0,
|
|
2109
|
-
data: { type: "text", text: "split answer" },
|
|
2110
|
-
})
|
|
2111
|
-
.run()
|
|
2112
|
-
.pipe(Effect.orDie)
|
|
2113
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
2114
|
-
sessionID: childID,
|
|
2115
|
-
parentID: sessionID,
|
|
2116
|
-
boundary: { type: "through", messageID },
|
|
2117
|
-
})
|
|
2118
|
-
expect(yield* store.messages({ sessionID: childID, order: "asc" })).toMatchObject([
|
|
2119
|
-
{ type: "assistant", content: [{ type: "text", text: "split answer" }] },
|
|
2120
|
-
])
|
|
2121
|
-
}),
|
|
2122
|
-
)
|
|
2123
|
-
|
|
2124
|
-
it.effect("keeps session_part rows when an older build left inline content on the same message", () =>
|
|
2125
|
-
Effect.gen(function* () {
|
|
2126
|
-
const db = yield* seedSession()
|
|
2127
|
-
const bus = yield* Bus.Service
|
|
2128
|
-
const messageID = SessionMessage.ID.make("msg_downgraded")
|
|
2129
|
-
const row = assistantRow(messageID, 0)
|
|
2130
|
-
yield* db
|
|
2131
|
-
.insert(SessionMessageTable)
|
|
2132
|
-
.values({
|
|
2133
|
-
...row,
|
|
2134
|
-
data: { ...row.data, content: [{ type: "text", text: "after downgrade" }] },
|
|
2135
|
-
})
|
|
2136
|
-
.run()
|
|
2137
|
-
.pipe(Effect.orDie)
|
|
2138
|
-
yield* db
|
|
2139
|
-
.insert(SessionPartTable)
|
|
2140
|
-
.values(
|
|
2141
|
-
["first", "second"].map((text, ordinal) => ({
|
|
2142
|
-
message_id: messageID,
|
|
2143
|
-
session_id: sessionID,
|
|
2144
|
-
ordinal,
|
|
2145
|
-
type: "text" as const,
|
|
2146
|
-
call_id: null,
|
|
2147
|
-
time_created: 0,
|
|
2148
|
-
time_updated: 0,
|
|
2149
|
-
data: { type: "text" as const, text },
|
|
2150
|
-
})),
|
|
2151
|
-
)
|
|
2152
|
-
.run()
|
|
2153
|
-
.pipe(Effect.orDie)
|
|
2154
|
-
|
|
2155
|
-
yield* bus.publish(SessionEvent.Text.Started, { sessionID, assistantMessageID: messageID, ordinal: 3 })
|
|
2156
|
-
|
|
2157
|
-
const parts = yield* db
|
|
2158
|
-
.select({ ordinal: SessionPartTable.ordinal, data: SessionPartTable.data })
|
|
2159
|
-
.from(SessionPartTable)
|
|
2160
|
-
.where(eq(SessionPartTable.message_id, messageID))
|
|
2161
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
2162
|
-
.all()
|
|
2163
|
-
.pipe(Effect.orDie)
|
|
2164
|
-
expect(parts.map((part) => [part.ordinal, part.data.type === "text" ? part.data.text : undefined])).toEqual([
|
|
2165
|
-
[0, "first"],
|
|
2166
|
-
[1, "second"],
|
|
2167
|
-
[2, "after downgrade"],
|
|
2168
|
-
[3, ""],
|
|
2169
|
-
])
|
|
2170
|
-
}),
|
|
2171
|
-
)
|
|
2172
|
-
|
|
2173
|
-
it.effect("stores a fork's copies of inline parent media as blobs and leaves the parent's rows inline", () =>
|
|
2174
|
-
Effect.gen(function* () {
|
|
2175
|
-
const db = yield* seedSession()
|
|
2176
|
-
const bus = yield* Bus.Service
|
|
2177
|
-
const store = yield* SessionStore.Service
|
|
2178
|
-
const childID = Session.ID.make("ses_media_inline_fork")
|
|
2179
|
-
const boundary = yield* seedInlineMedia(db)
|
|
2180
|
-
const parentRows = yield* messageRows(db, sessionID)
|
|
2181
|
-
const parentParts = yield* db.select().from(SessionPartTable).all().pipe(Effect.orDie)
|
|
2182
|
-
const parentMessages = yield* store.messages({ sessionID, order: "asc" })
|
|
2183
|
-
|
|
2184
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
2185
|
-
sessionID: childID,
|
|
2186
|
-
parentID: sessionID,
|
|
2187
|
-
boundary: { type: "through", messageID: boundary },
|
|
2188
|
-
})
|
|
2189
|
-
|
|
2190
|
-
const hash = SessionBlob.hashBytes(png)
|
|
2191
|
-
const uri = SessionStored.ref(hash)
|
|
2192
|
-
const childRows = yield* messageRows(db, childID)
|
|
2193
|
-
const childFull = yield* SessionHistory.withParts(db, childRows)
|
|
2194
|
-
expect(childFull.map((row) => row.data)).toMatchObject([
|
|
2195
|
-
{ files: [{ uri, mime: "image/png", name: "shot.png" }] },
|
|
2196
|
-
{ content: [{ type: "tool", state: { content: [{ type: "file", uri, mime: "image/png" }] } }] },
|
|
2197
|
-
])
|
|
2198
|
-
expect(JSON.stringify(childFull)).not.toContain(png.toString("base64"))
|
|
2199
|
-
expect(yield* messageRows(db, sessionID)).toEqual(parentRows)
|
|
2200
|
-
expect(
|
|
2201
|
-
yield* db
|
|
2202
|
-
.select()
|
|
2203
|
-
.from(SessionPartTable)
|
|
2204
|
-
.where(eq(SessionPartTable.session_id, sessionID))
|
|
2205
|
-
.all()
|
|
2206
|
-
.pipe(Effect.orDie),
|
|
2207
|
-
).toEqual(parentParts)
|
|
2208
|
-
expect(yield* db.select({ hash: BlobTable.hash }).from(BlobTable).all().pipe(Effect.orDie)).toEqual([{ hash }])
|
|
2209
|
-
expect(
|
|
2210
|
-
yield* db
|
|
2211
|
-
.select({ session: BlobRefTable.session_id, message: BlobRefTable.message_id, hash: BlobRefTable.hash })
|
|
2212
|
-
.from(BlobRefTable)
|
|
2213
|
-
.orderBy(asc(BlobRefTable.seq))
|
|
2214
|
-
.all()
|
|
2215
|
-
.pipe(Effect.orDie),
|
|
2216
|
-
).toEqual(childRows.map((row) => ({ session: childID, message: row.id, hash })))
|
|
2217
|
-
|
|
2218
|
-
// The child owns its blob, so it reads the same with the parent gone.
|
|
2219
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID })
|
|
2220
|
-
expect(yield* messageRows(db, sessionID)).toEqual([])
|
|
2221
|
-
expect(withoutIDs(yield* store.messages({ sessionID: childID, order: "asc" }))).toEqual(
|
|
2222
|
-
withoutIDs(parentMessages),
|
|
2223
|
-
)
|
|
2224
|
-
}).pipe(Effect.provideService(SessionBlob.ForkMedia, true)),
|
|
2225
|
-
)
|
|
2226
|
-
|
|
2227
|
-
it.effect("copies inline parent media inline into a fork unless the parent's location stores media as blobs", () =>
|
|
2228
|
-
Effect.gen(function* () {
|
|
2229
|
-
const db = yield* seedSession()
|
|
2230
|
-
const bus = yield* Bus.Service
|
|
2231
|
-
const store = yield* SessionStore.Service
|
|
2232
|
-
const childID = Session.ID.make("ses_media_inline_fork_off")
|
|
2233
|
-
const boundary = yield* seedInlineMedia(db)
|
|
2234
|
-
const parentRows = yield* messageRows(db, sessionID)
|
|
2235
|
-
|
|
2236
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
2237
|
-
sessionID: childID,
|
|
2238
|
-
parentID: sessionID,
|
|
2239
|
-
boundary: { type: "through", messageID: boundary },
|
|
2240
|
-
})
|
|
2241
|
-
|
|
2242
|
-
const childRows = yield* messageRows(db, childID)
|
|
2243
|
-
expect((yield* SessionHistory.withParts(db, childRows)).map((row) => row.data)).toEqual(
|
|
2244
|
-
(yield* SessionHistory.withParts(db, parentRows)).map((row) => row.data),
|
|
2245
|
-
)
|
|
2246
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2247
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2248
|
-
expect(withoutIDs(yield* store.messages({ sessionID: childID, order: "asc" }))).toEqual(
|
|
2249
|
-
withoutIDs(yield* store.messages({ sessionID, order: "asc" })),
|
|
2250
|
-
)
|
|
2251
|
-
// The caller's own config doesn't decide: Session.fork sets ForkMedia from the parent's location.
|
|
2252
|
-
}).pipe(Effect.provide(mediaBlob)),
|
|
2253
|
-
)
|
|
2254
|
-
|
|
2255
|
-
it.effect("reads a split message an older build added inline content to as its parts then that content", () =>
|
|
2256
|
-
Effect.gen(function* () {
|
|
2257
|
-
const db = yield* seedSession()
|
|
2258
|
-
const bus = yield* Bus.Service
|
|
2259
|
-
const store = yield* SessionStore.Service
|
|
2260
|
-
const messageID = SessionMessage.ID.make("msg_hybrid_read")
|
|
2261
|
-
yield* db
|
|
2262
|
-
.insert(SessionMessageTable)
|
|
2263
|
-
.values(
|
|
2264
|
-
hybridRow(messageID, [
|
|
2265
|
-
{ type: "text", text: "inline after" },
|
|
2266
|
-
{
|
|
2267
|
-
type: "tool",
|
|
2268
|
-
id: "call_inline",
|
|
2269
|
-
name: "read",
|
|
2270
|
-
executed: true,
|
|
2271
|
-
state: { status: "running", input: { path: "a.ts" }, metadata: {} },
|
|
2272
|
-
time: { created: 1, ran: 1 },
|
|
2273
|
-
},
|
|
2274
|
-
]),
|
|
2275
|
-
)
|
|
2276
|
-
.run()
|
|
2277
|
-
.pipe(Effect.orDie)
|
|
2278
|
-
yield* db
|
|
2279
|
-
.insert(SessionPartTable)
|
|
2280
|
-
.values(textPart(messageID, 0, "split first"))
|
|
2281
|
-
.run()
|
|
2282
|
-
.pipe(Effect.orDie)
|
|
2283
|
-
|
|
2284
|
-
const content = [
|
|
2285
|
-
{ type: "text", text: "split first" },
|
|
2286
|
-
{ type: "text", text: "inline after" },
|
|
2287
|
-
{ type: "tool", id: "call_inline", state: { status: "running" } },
|
|
2288
|
-
]
|
|
2289
|
-
expect((yield* store.message(messageID))?.message).toMatchObject({ content })
|
|
2290
|
-
// The runner settles stale tool calls from context, so an inline one on a split message must show up there.
|
|
2291
|
-
expect(yield* store.context(sessionID)).toMatchObject([{ id: messageID, content }])
|
|
2292
|
-
|
|
2293
|
-
yield* bus.publish(SessionEvent.Tool.Failed, {
|
|
2294
|
-
sessionID,
|
|
2295
|
-
assistantMessageID: messageID,
|
|
2296
|
-
id: "call_inline",
|
|
2297
|
-
error: { type: "aborted", message: "Tool execution interrupted: read" },
|
|
2298
|
-
executed: true,
|
|
2299
|
-
})
|
|
2300
|
-
expect((yield* store.message(messageID))?.message).toMatchObject({
|
|
2301
|
-
content: [content[0], content[1], { type: "tool", id: "call_inline", state: { status: "error" } }],
|
|
2302
|
-
})
|
|
2303
|
-
expect((yield* messageRows(db, sessionID))[0]?.data).toMatchObject({ content: [] })
|
|
2304
|
-
}),
|
|
2305
|
-
)
|
|
2306
|
-
|
|
2307
|
-
it.effect("forks a split message an older build added inline media to", () =>
|
|
2308
|
-
Effect.gen(function* () {
|
|
2309
|
-
const db = yield* seedSession()
|
|
2310
|
-
const bus = yield* Bus.Service
|
|
2311
|
-
const store = yield* SessionStore.Service
|
|
2312
|
-
const messageID = SessionMessage.ID.make("msg_hybrid_fork")
|
|
2313
|
-
const childID = Session.ID.make("ses_hybrid_fork")
|
|
2314
|
-
yield* db
|
|
2315
|
-
.insert(SessionMessageTable)
|
|
2316
|
-
.values(hybridRow(messageID, [inlineShot], { created, completed: created }))
|
|
2317
|
-
.run()
|
|
2318
|
-
.pipe(Effect.orDie)
|
|
2319
|
-
yield* db
|
|
2320
|
-
.insert(SessionPartTable)
|
|
2321
|
-
.values(textPart(messageID, 0, "split first"))
|
|
2322
|
-
.run()
|
|
2323
|
-
.pipe(Effect.orDie)
|
|
2324
|
-
const parent = yield* store.messages({ sessionID, order: "asc" })
|
|
2325
|
-
expect(parent).toMatchObject([
|
|
2326
|
-
{
|
|
2327
|
-
content: [
|
|
2328
|
-
{ type: "text", text: "split first" },
|
|
2329
|
-
{ type: "tool", id: "call_inline_shot" },
|
|
2330
|
-
],
|
|
2331
|
-
},
|
|
2332
|
-
])
|
|
2333
|
-
|
|
2334
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
2335
|
-
sessionID: childID,
|
|
2336
|
-
parentID: sessionID,
|
|
2337
|
-
boundary: { type: "through", messageID },
|
|
2338
|
-
})
|
|
2339
|
-
|
|
2340
|
-
const childRows = yield* messageRows(db, childID)
|
|
2341
|
-
expect(JSON.stringify(yield* SessionHistory.withParts(db, childRows))).not.toContain(png.toString("base64"))
|
|
2342
|
-
expect(
|
|
2343
|
-
yield* db
|
|
2344
|
-
.select({ session: BlobRefTable.session_id, message: BlobRefTable.message_id, hash: BlobRefTable.hash })
|
|
2345
|
-
.from(BlobRefTable)
|
|
2346
|
-
.all()
|
|
2347
|
-
.pipe(Effect.orDie),
|
|
2348
|
-
).toEqual([{ session: childID, message: childRows[0]!.id, hash: SessionBlob.hashBytes(png) }])
|
|
2349
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID })
|
|
2350
|
-
expect(withoutIDs(yield* store.messages({ sessionID: childID, order: "asc" }))).toEqual(withoutIDs(parent))
|
|
2351
|
-
}).pipe(Effect.provideService(SessionBlob.ForkMedia, true)),
|
|
2352
|
-
)
|
|
2353
|
-
|
|
2354
|
-
it.effect("deletes a reverted message's session_part rows and the blobs only they referenced", () =>
|
|
2355
|
-
Effect.gen(function* () {
|
|
2356
|
-
const db = yield* seedSession()
|
|
2357
|
-
const bus = yield* Bus.Service
|
|
2358
|
-
const assistantMessageID = SessionMessage.ID.make("msg_media_tool_reverted")
|
|
2359
|
-
yield* bus.publish(SessionEvent.Step.Started, { sessionID, assistantMessageID, agent: build, model, started: 1 })
|
|
2360
|
-
yield* bus.publish(SessionEvent.Tool.Input.Started, { sessionID, assistantMessageID, id: "shot", name: "shot" })
|
|
2361
|
-
yield* bus.publish(SessionEvent.Tool.Called, {
|
|
2362
|
-
sessionID,
|
|
2363
|
-
assistantMessageID,
|
|
2364
|
-
id: "shot",
|
|
2365
|
-
input: {},
|
|
2366
|
-
executed: true,
|
|
2367
|
-
})
|
|
2368
|
-
yield* bus.publish(SessionEvent.Tool.Success, {
|
|
2369
|
-
sessionID,
|
|
2370
|
-
assistantMessageID,
|
|
2371
|
-
id: "shot",
|
|
2372
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
2373
|
-
executed: true,
|
|
2374
|
-
})
|
|
2375
|
-
expect(yield* db.select().from(SessionPartTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
2376
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toHaveLength(1)
|
|
2377
|
-
|
|
2378
|
-
yield* bus.publish(SessionEvent.RevertEvent.Committed, { sessionID, to: assistantMessageID })
|
|
2379
|
-
expect(yield* db.select().from(SessionPartTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2380
|
-
expect(yield* db.select().from(BlobRefTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2381
|
-
expect(yield* db.select().from(BlobTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2382
|
-
}).pipe(Effect.provide(mediaBlobPartRows)),
|
|
2383
|
-
)
|
|
2384
|
-
|
|
2385
|
-
it.effect("moves a legacy inline media message's rewritten content to session_part with its media as a blob", () =>
|
|
2386
|
-
Effect.gen(function* () {
|
|
2387
|
-
const db = yield* seedSession()
|
|
2388
|
-
const bus = yield* Bus.Service
|
|
2389
|
-
const store = yield* SessionStore.Service
|
|
2390
|
-
const messageID = SessionMessage.ID.make("msg_legacy_media_rewritten")
|
|
2391
|
-
const hash = SessionBlob.hashBytes(png)
|
|
2392
|
-
yield* db
|
|
2393
|
-
.insert(SessionMessageTable)
|
|
2394
|
-
.values(hybridRow(messageID, [inlineShot], { created, completed: created }))
|
|
2395
|
-
.run()
|
|
2396
|
-
.pipe(Effect.orDie)
|
|
2397
|
-
|
|
2398
|
-
yield* bus.publish(SessionEvent.MessageContentUpdated, {
|
|
2399
|
-
sessionID,
|
|
2400
|
-
messageID,
|
|
2401
|
-
content: [{ type: "text", text: "rewritten" }, inlineShot],
|
|
2402
|
-
})
|
|
2403
|
-
|
|
2404
|
-
expect((yield* messageRows(db, sessionID))[0]?.data).toMatchObject({ content: [] })
|
|
2405
|
-
expect(
|
|
2406
|
-
yield* db
|
|
2407
|
-
.select({ data: SessionPartTable.data })
|
|
2408
|
-
.from(SessionPartTable)
|
|
2409
|
-
.orderBy(asc(SessionPartTable.ordinal))
|
|
2410
|
-
.all()
|
|
2411
|
-
.pipe(Effect.orDie),
|
|
2412
|
-
).toMatchObject([
|
|
2413
|
-
{ data: { type: "text", text: "rewritten" } },
|
|
2414
|
-
{ data: { type: "tool", state: { content: [{ type: "file", uri: SessionStored.ref(hash) }] } } },
|
|
2415
|
-
])
|
|
2416
|
-
expect(yield* db.select({ hash: BlobTable.hash }).from(BlobTable).all().pipe(Effect.orDie)).toEqual([{ hash }])
|
|
2417
|
-
expect(
|
|
2418
|
-
yield* db
|
|
2419
|
-
.select({ message: BlobRefTable.message_id, hash: BlobRefTable.hash })
|
|
2420
|
-
.from(BlobRefTable)
|
|
2421
|
-
.all()
|
|
2422
|
-
.pipe(Effect.orDie),
|
|
2423
|
-
).toEqual([{ message: messageID, hash }])
|
|
2424
|
-
expect((yield* store.message(messageID))?.message).toMatchObject({
|
|
2425
|
-
content: [
|
|
2426
|
-
{ type: "text", text: "rewritten" },
|
|
2427
|
-
{
|
|
2428
|
-
type: "tool",
|
|
2429
|
-
id: "call_inline_shot",
|
|
2430
|
-
state: { content: [{ type: "file", uri: inlineShot.state.content[0].uri }] },
|
|
2431
|
-
},
|
|
2432
|
-
],
|
|
2433
|
-
})
|
|
2434
|
-
}).pipe(Effect.provide(mediaBlobPartRows)),
|
|
2435
|
-
)
|
|
2436
|
-
|
|
2437
|
-
durableIt.effect("forks and reads a long session in statements under 100 bound parameters", () =>
|
|
2438
|
-
Effect.gen(function* () {
|
|
2439
|
-
const db = yield* seedSession()
|
|
2440
|
-
const bus = yield* Bus.Service
|
|
2441
|
-
const store = yield* SessionStore.Service
|
|
2442
|
-
const childID = Session.ID.make("ses_long_fork")
|
|
2443
|
-
const ids = Array.from({ length: 120 }, (_, seq) =>
|
|
2444
|
-
SessionMessage.ID.make(`msg_long_${String(seq).padStart(3, "0")}`),
|
|
2445
|
-
)
|
|
2446
|
-
yield* Effect.forEach(
|
|
2447
|
-
ids,
|
|
2448
|
-
(id, seq) =>
|
|
2449
|
-
db
|
|
2450
|
-
.insert(SessionMessageTable)
|
|
2451
|
-
.values(assistantRow(id, seq, { created, completed: created }))
|
|
2452
|
-
.run()
|
|
2453
|
-
.pipe(Effect.orDie),
|
|
2454
|
-
{ discard: true },
|
|
2455
|
-
)
|
|
2456
|
-
const texts = Array.from({ length: 30 }, (_, ordinal) => `part ${ordinal}`)
|
|
2457
|
-
yield* Effect.forEach(
|
|
2458
|
-
texts,
|
|
2459
|
-
(text, ordinal) =>
|
|
2460
|
-
db
|
|
2461
|
-
.insert(SessionPartTable)
|
|
2462
|
-
.values(textPart(ids[0]!, ordinal, text))
|
|
2463
|
-
.run()
|
|
2464
|
-
.pipe(Effect.orDie),
|
|
2465
|
-
{ discard: true },
|
|
2466
|
-
)
|
|
2467
|
-
const parent = yield* store.messages({ sessionID, order: "asc" })
|
|
2468
|
-
expect(parent).toHaveLength(ids.length)
|
|
2469
|
-
expect(parent[0]).toMatchObject({ content: texts.map((text) => ({ type: "text", text })) })
|
|
2470
|
-
|
|
2471
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
2472
|
-
sessionID: childID,
|
|
2473
|
-
parentID: sessionID,
|
|
2474
|
-
boundary: { type: "through", messageID: ids.at(-1)! },
|
|
2475
|
-
})
|
|
2476
|
-
expect(withoutIDs(yield* store.messages({ sessionID: childID, order: "asc" }))).toEqual(withoutIDs(parent))
|
|
2477
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID })
|
|
2478
|
-
expect(
|
|
2479
|
-
yield* db
|
|
2480
|
-
.select()
|
|
2481
|
-
.from(SessionPartTable)
|
|
2482
|
-
.where(eq(SessionPartTable.session_id, sessionID))
|
|
2483
|
-
.all()
|
|
2484
|
-
.pipe(Effect.orDie),
|
|
2485
|
-
).toEqual([])
|
|
2486
|
-
expect(withoutIDs(yield* store.messages({ sessionID: childID, order: "asc" }))).toEqual(withoutIDs(parent))
|
|
2487
|
-
}).pipe(Effect.provideService(SessionBlob.ForkMedia, true)),
|
|
2488
|
-
)
|
|
2489
|
-
|
|
2490
|
-
it.effect(
|
|
2491
|
-
"hydrates parts when envelope content is omitted or non-array, and fails to decode non-array content without parts",
|
|
2492
|
-
() =>
|
|
2493
|
-
Effect.gen(function* () {
|
|
2494
|
-
const db = yield* seedSession()
|
|
2495
|
-
const store = yield* SessionStore.Service
|
|
2496
|
-
const omittedID = SessionMessage.ID.make("msg_parts_omitted_content")
|
|
2497
|
-
const nullID = SessionMessage.ID.make("msg_parts_null_content")
|
|
2498
|
-
const corruptID = SessionMessage.ID.make("msg_no_parts_null_content")
|
|
2499
|
-
yield* db
|
|
2500
|
-
.insert(SessionMessageTable)
|
|
2501
|
-
.values([
|
|
2502
|
-
assistantRow(omittedID, 0, { created, completed: created }),
|
|
2503
|
-
assistantRow(nullID, 1, { created, completed: created }),
|
|
2504
|
-
assistantRow(corruptID, 2, { created, completed: created }),
|
|
2505
|
-
])
|
|
2506
|
-
.run()
|
|
2507
|
-
.pipe(Effect.orDie)
|
|
2508
|
-
yield* db
|
|
2509
|
-
.insert(SessionPartTable)
|
|
2510
|
-
.values([textPart(omittedID, 0, "from part"), textPart(nullID, 0, "from part")])
|
|
2511
|
-
.run()
|
|
2512
|
-
.pipe(Effect.orDie)
|
|
2513
|
-
|
|
2514
|
-
yield* db.run(sql`update session_message set data = json_remove(data, '$.content') where id = ${omittedID}`)
|
|
2515
|
-
expect((yield* store.message(omittedID))?.message).toMatchObject({
|
|
2516
|
-
content: [{ type: "text", text: "from part" }],
|
|
2517
|
-
})
|
|
2518
|
-
|
|
2519
|
-
// With part rows, a non-array `content` counts as no inline parts.
|
|
2520
|
-
yield* db.run(
|
|
2521
|
-
sql`update session_message set data = json_set(data, '$.content', json('null')) where id in (${nullID}, ${corruptID})`,
|
|
2522
|
-
)
|
|
2523
|
-
expect((yield* store.message(nullID))?.message).toMatchObject({
|
|
2524
|
-
agent: build,
|
|
2525
|
-
content: [{ type: "text", text: "from part" }],
|
|
2526
|
-
})
|
|
2527
|
-
|
|
2528
|
-
// Without part rows there is nothing to read instead, so the row fails to decode.
|
|
2529
|
-
expect(yield* store.messages({ sessionID }).pipe(Effect.flip)).toMatchObject({
|
|
2530
|
-
_tag: "Session.MessageDecodeError",
|
|
2531
|
-
sessionID,
|
|
2532
|
-
messageID: corruptID,
|
|
2533
|
-
})
|
|
2534
|
-
}),
|
|
2535
|
-
)
|
|
2536
|
-
|
|
2537
|
-
it.effect("writes each assistant part as a session_part row when experimental.part_rows is unset", () =>
|
|
2538
|
-
Effect.gen(function* () {
|
|
2539
|
-
const db = yield* seedSession()
|
|
2540
|
-
const store = yield* SessionStore.Service
|
|
2541
|
-
yield* projectTwoSteps(sessionID, () => undefined)
|
|
2542
|
-
|
|
2543
|
-
const parts = yield* db
|
|
2544
|
-
.select({ message: SessionPartTable.message_id, ordinal: SessionPartTable.ordinal })
|
|
2545
|
-
.from(SessionPartTable)
|
|
2546
|
-
.where(eq(SessionPartTable.session_id, sessionID))
|
|
2547
|
-
.orderBy(asc(SessionPartTable.message_id), asc(SessionPartTable.ordinal))
|
|
2548
|
-
.all()
|
|
2549
|
-
.pipe(Effect.orDie)
|
|
2550
|
-
expect(
|
|
2551
|
-
Object.values(Object.groupBy(parts, (part) => part.message)).map((rows) => rows?.map((row) => row.ordinal)),
|
|
2552
|
-
).toEqual([[0, 1, 2], [0]])
|
|
2553
|
-
for (const row of yield* messageRows(db, sessionID))
|
|
2554
|
-
if (row.type === "assistant") expect(row.data).toMatchObject({ content: [] })
|
|
2555
|
-
const messages = yield* store.messages({ sessionID, order: "asc" })
|
|
2556
|
-
expect(messages.flatMap((message) => (message.type === "assistant" ? [message.content.length] : []))).toEqual([
|
|
2557
|
-
3, 1,
|
|
2558
|
-
])
|
|
2559
|
-
}),
|
|
2560
|
-
)
|
|
2561
|
-
|
|
2562
|
-
it.effect("writes whole messages inline with experimental.part_rows set to false", () =>
|
|
2563
|
-
Effect.gen(function* () {
|
|
2564
|
-
const db = yield* seedSession()
|
|
2565
|
-
const store = yield* SessionStore.Service
|
|
2566
|
-
yield* projectTwoSteps(sessionID, () => false)
|
|
2567
|
-
|
|
2568
|
-
expect(yield* db.select().from(SessionPartTable).all().pipe(Effect.orDie)).toEqual([])
|
|
2569
|
-
const messages = yield* store.messages({ sessionID, order: "asc" })
|
|
2570
|
-
const assistants = messages.filter((message) => message.type === "assistant")
|
|
2571
|
-
expect(assistants.map((message) => message.content.length)).toEqual([3, 1])
|
|
2572
|
-
// Each row holds the whole encoded message, as before part rows existed.
|
|
2573
|
-
const rows = yield* messageRows(db, sessionID)
|
|
2574
|
-
for (const message of assistants) {
|
|
2575
|
-
const { id: _, type: __, ...data } = encodeMessage(message)
|
|
2576
|
-
expect(rows.find((row) => row.id === message.id)?.data).toEqual(data)
|
|
2577
|
-
}
|
|
2578
|
-
}),
|
|
2579
|
-
)
|
|
2580
|
-
|
|
2581
|
-
it.effect("reads the same reply when experimental.part_rows is switched on, off and on again mid-session", () =>
|
|
2582
|
-
Effect.gen(function* () {
|
|
2583
|
-
const db = yield* seedSession()
|
|
2584
|
-
const store = yield* SessionStore.Service
|
|
2585
|
-
const off = Session.ID.make("ses_part_rows_off")
|
|
2586
|
-
const on = Session.ID.make("ses_part_rows_on")
|
|
2587
|
-
yield* db
|
|
2588
|
-
.insert(SessionTable)
|
|
2589
|
-
.values(
|
|
2590
|
-
[off, on].map((id) => ({
|
|
2591
|
-
id,
|
|
2592
|
-
project_id: Project.ID.global,
|
|
2593
|
-
slug: id,
|
|
2594
|
-
directory: "/project",
|
|
2595
|
-
title: "test",
|
|
2596
|
-
version: "test",
|
|
2597
|
-
})),
|
|
2598
|
-
)
|
|
2599
|
-
.run()
|
|
2600
|
-
.pipe(Effect.orDie)
|
|
2601
|
-
|
|
2602
|
-
yield* projectTwoSteps(off, () => false)
|
|
2603
|
-
yield* projectTwoSteps(on, () => true)
|
|
2604
|
-
// On for the first step's start, off for its tool call, on for its end; then off for the second step's text start.
|
|
2605
|
-
yield* projectTwoSteps(sessionID, (index) => ![4, 5, 6, 7, 10].includes(index))
|
|
2606
|
-
|
|
2607
|
-
const read = (session: Session.ID) =>
|
|
2608
|
-
store.messages({ sessionID: session, order: "asc" }).pipe(Effect.map(withoutIDs))
|
|
2609
|
-
const mixed = yield* read(sessionID)
|
|
2610
|
-
expect(mixed).toEqual(yield* read(off))
|
|
2611
|
-
expect(mixed).toEqual(yield* read(on))
|
|
2612
|
-
expect(mixed.flatMap((message) => (message.type === "assistant" ? [message.content.length] : []))).toEqual([3, 1])
|
|
2613
|
-
|
|
2614
|
-
const parts = yield* db
|
|
2615
|
-
.select({ message: SessionPartTable.message_id, ordinal: SessionPartTable.ordinal })
|
|
2616
|
-
.from(SessionPartTable)
|
|
2617
|
-
.where(eq(SessionPartTable.session_id, sessionID))
|
|
2618
|
-
.orderBy(asc(SessionPartTable.message_id), asc(SessionPartTable.ordinal))
|
|
2619
|
-
.all()
|
|
2620
|
-
.pipe(Effect.orDie)
|
|
2621
|
-
expect(
|
|
2622
|
-
Object.values(Object.groupBy(parts, (part) => part.message)).map((rows) => rows?.map((row) => row.ordinal)),
|
|
2623
|
-
).toEqual([[0, 1, 2], [0]])
|
|
2624
|
-
for (const row of yield* messageRows(db, sessionID))
|
|
2625
|
-
if (row.type === "assistant") expect(row.data).toMatchObject({ content: [] })
|
|
2626
|
-
}),
|
|
2627
|
-
)
|
|
2628
|
-
})
|
|
2629
|
-
|
|
2630
|
-
/**
|
|
2631
|
-
* Two assistant steps, the first with reasoning, text and a tool call. Event `index` is projected with
|
|
2632
|
-
* `experimental.part_rows` set to `partRowsAt(index)`, or with no config at all when it returns undefined.
|
|
2633
|
-
*/
|
|
2634
|
-
const projectTwoSteps = Effect.fnUntraced(function* (
|
|
2635
|
-
session: Session.ID,
|
|
2636
|
-
partRowsAt: (index: number) => boolean | undefined,
|
|
2637
|
-
) {
|
|
2638
|
-
const bus = yield* Bus.Service
|
|
2639
|
-
const first = SessionMessage.ID.make(`msg_${session}_first`)
|
|
2640
|
-
const second = SessionMessage.ID.make(`msg_${session}_second`)
|
|
2641
|
-
const usage = { cost: Money.USD.make(0), tokens: { input: 1, output: 1, reasoning: 0, cache: { read: 0, write: 0 } } }
|
|
2642
|
-
const events: ReadonlyArray<Effect.Effect<unknown>> = [
|
|
2643
|
-
bus.publish(SessionEvent.Step.Started, {
|
|
2644
|
-
sessionID: session,
|
|
2645
|
-
assistantMessageID: first,
|
|
2646
|
-
agent: build,
|
|
2647
|
-
model,
|
|
2648
|
-
started: 1,
|
|
2649
|
-
}),
|
|
2650
|
-
bus.publish(SessionEvent.Reasoning.Started, { sessionID: session, assistantMessageID: first, ordinal: 0 }),
|
|
2651
|
-
bus.publish(SessionEvent.Reasoning.Ended, {
|
|
2652
|
-
sessionID: session,
|
|
2653
|
-
assistantMessageID: first,
|
|
2654
|
-
ordinal: 0,
|
|
2655
|
-
text: "plan",
|
|
2656
|
-
}),
|
|
2657
|
-
bus.publish(SessionEvent.Text.Started, { sessionID: session, assistantMessageID: first, ordinal: 1 }),
|
|
2658
|
-
bus.publish(SessionEvent.Text.Ended, {
|
|
2659
|
-
sessionID: session,
|
|
2660
|
-
assistantMessageID: first,
|
|
2661
|
-
ordinal: 1,
|
|
2662
|
-
text: "reading",
|
|
2663
|
-
}),
|
|
2664
|
-
bus.publish(SessionEvent.Tool.Input.Started, {
|
|
2665
|
-
sessionID: session,
|
|
2666
|
-
assistantMessageID: first,
|
|
2667
|
-
id: "call",
|
|
2668
|
-
name: "read",
|
|
2669
|
-
}),
|
|
2670
|
-
bus.publish(SessionEvent.Tool.Called, {
|
|
2671
|
-
sessionID: session,
|
|
2672
|
-
assistantMessageID: first,
|
|
2673
|
-
id: "call",
|
|
2674
|
-
input: { file: "a.ts" },
|
|
2675
|
-
executed: true,
|
|
2676
|
-
}),
|
|
2677
|
-
bus.publish(SessionEvent.Tool.Success, {
|
|
2678
|
-
sessionID: session,
|
|
2679
|
-
assistantMessageID: first,
|
|
2680
|
-
id: "call",
|
|
2681
|
-
content: [{ type: "text", text: "a contents" }],
|
|
2682
|
-
executed: true,
|
|
2683
|
-
}),
|
|
2684
|
-
bus.publish(SessionEvent.Step.Ended, {
|
|
2685
|
-
sessionID: session,
|
|
2686
|
-
assistantMessageID: first,
|
|
2687
|
-
finish: "tool-calls",
|
|
2688
|
-
...usage,
|
|
2689
|
-
}),
|
|
2690
|
-
bus.publish(SessionEvent.Step.Started, {
|
|
2691
|
-
sessionID: session,
|
|
2692
|
-
assistantMessageID: second,
|
|
2693
|
-
agent: build,
|
|
2694
|
-
model,
|
|
2695
|
-
started: 2,
|
|
2696
|
-
}),
|
|
2697
|
-
bus.publish(SessionEvent.Text.Started, { sessionID: session, assistantMessageID: second, ordinal: 0 }),
|
|
2698
|
-
bus.publish(SessionEvent.Text.Ended, { sessionID: session, assistantMessageID: second, ordinal: 0, text: "done" }),
|
|
2699
|
-
bus.publish(SessionEvent.Step.Ended, { sessionID: session, assistantMessageID: second, finish: "stop", ...usage }),
|
|
2700
|
-
]
|
|
2701
|
-
for (const [index, event] of events.entries()) {
|
|
2702
|
-
const enabled = partRowsAt(index)
|
|
2703
|
-
yield* enabled === undefined ? event : event.pipe(Effect.provide(enabled ? partRows : partRowsOff))
|
|
2704
|
-
}
|
|
2705
|
-
})
|
|
2706
|
-
|
|
2707
|
-
const inlineShot = {
|
|
2708
|
-
type: "tool",
|
|
2709
|
-
id: "call_inline_shot",
|
|
2710
|
-
name: "screenshot",
|
|
2711
|
-
executed: true,
|
|
2712
|
-
state: {
|
|
2713
|
-
status: "completed",
|
|
2714
|
-
input: {},
|
|
2715
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
2716
|
-
},
|
|
2717
|
-
time: { created: 2, ran: 2, completed: 2 },
|
|
2718
|
-
} as const
|
|
2719
|
-
|
|
2720
|
-
/** An assistant row with inline content, the shape an older build writes even when session_part rows exist. */
|
|
2721
|
-
const hybridRow = (
|
|
2722
|
-
messageID: SessionMessage.ID,
|
|
2723
|
-
content: ReadonlyArray<typeof SessionMessage.AssistantContent.Encoded>,
|
|
2724
|
-
time?: { created: DateTime.Utc; completed?: DateTime.Utc },
|
|
2725
|
-
) => {
|
|
2726
|
-
const row = assistantRow(messageID, 0, time)
|
|
2727
|
-
return { ...row, data: { ...row.data, content } }
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
const textPart = (messageID: SessionMessage.ID, ordinal: number, text: string) => ({
|
|
2731
|
-
message_id: messageID,
|
|
2732
|
-
session_id: sessionID,
|
|
2733
|
-
ordinal,
|
|
2734
|
-
type: "text" as const,
|
|
2735
|
-
call_id: null,
|
|
2736
|
-
time_created: 0,
|
|
2737
|
-
time_updated: 0,
|
|
2738
|
-
data: { type: "text" as const, text },
|
|
2739
|
-
})
|
|
2740
|
-
|
|
2741
|
-
const messageRows = (db: Database.Interface["db"], session: Session.ID) =>
|
|
2742
|
-
db
|
|
2743
|
-
.select()
|
|
2744
|
-
.from(SessionMessageTable)
|
|
2745
|
-
.where(eq(SessionMessageTable.session_id, session))
|
|
2746
|
-
.orderBy(asc(SessionMessageTable.seq))
|
|
2747
|
-
.all()
|
|
2748
|
-
.pipe(Effect.orDie)
|
|
2749
|
-
|
|
2750
|
-
const withoutIDs = (messages: ReadonlyArray<SessionMessage.Info>) => messages.map(({ id: _, ...message }) => message)
|
|
2751
|
-
|
|
2752
|
-
/** A parent written before media blobs: an inline user file, and a tool screenshot in a session_part row. */
|
|
2753
|
-
const seedInlineMedia = Effect.fnUntraced(function* (db: Database.Interface["db"]) {
|
|
2754
|
-
const userID = SessionMessage.ID.make("msg_inline_user")
|
|
2755
|
-
const assistantID = SessionMessage.ID.make("msg_inline_assistant")
|
|
2756
|
-
yield* db
|
|
2757
|
-
.insert(SessionMessageTable)
|
|
2758
|
-
.values([
|
|
2759
|
-
{
|
|
2760
|
-
id: userID,
|
|
2761
|
-
session_id: sessionID,
|
|
2762
|
-
type: "user",
|
|
2763
|
-
seq: 1,
|
|
2764
|
-
time_created: 1,
|
|
2765
|
-
data: { text: "look", files: [attachment("shot.png")], time: { created: 1 } },
|
|
2766
|
-
},
|
|
2767
|
-
assistantRow(assistantID, 2, { created, completed: created }),
|
|
2768
|
-
])
|
|
2769
|
-
.run()
|
|
2770
|
-
.pipe(Effect.orDie)
|
|
2771
|
-
yield* db
|
|
2772
|
-
.insert(SessionPartTable)
|
|
2773
|
-
.values({
|
|
2774
|
-
message_id: assistantID,
|
|
2775
|
-
session_id: sessionID,
|
|
2776
|
-
ordinal: 0,
|
|
2777
|
-
type: "tool",
|
|
2778
|
-
call_id: "call_shot",
|
|
2779
|
-
time_created: 2,
|
|
2780
|
-
time_updated: 2,
|
|
2781
|
-
data: {
|
|
2782
|
-
type: "tool",
|
|
2783
|
-
id: "call_shot",
|
|
2784
|
-
name: "screenshot",
|
|
2785
|
-
executed: true,
|
|
2786
|
-
state: {
|
|
2787
|
-
status: "completed",
|
|
2788
|
-
input: {},
|
|
2789
|
-
content: [{ type: "file", uri: `data:image/png;base64,${png.toString("base64")}`, mime: "image/png" }],
|
|
2790
|
-
},
|
|
2791
|
-
time: { created: 2, ran: 2, completed: 2 },
|
|
2792
|
-
},
|
|
2793
|
-
})
|
|
2794
|
-
.run()
|
|
2795
|
-
.pipe(Effect.orDie)
|
|
2796
|
-
return assistantID
|
|
2797
|
-
})
|