@opencode-ai/core 0.0.0-dev-18673 → 0.0.0-dev-18677
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/dist/agent.js +2 -2
- package/dist/bus.js +1 -1
- package/dist/catalog.js +5 -5
- package/dist/chunks/{job-6xnprn33.js → job-0ard5z33.js} +6 -6
- package/dist/chunks/{job-2crbvxrz.js → job-0mhpcp7m.js} +3 -3
- package/dist/chunks/{job-x7r2g85h.js → job-0vhffh46.js} +2 -2
- package/dist/chunks/{job-wjd92vx4.js → job-11rrpezh.js} +2 -2
- package/dist/chunks/{job-ngdmqv4f.js → job-1emzt0wt.js} +2 -2
- package/dist/chunks/{job-qtqph8kb.js → job-25d8xd9w.js} +4 -4
- package/dist/chunks/{job-nr9st120.js → job-2jft3yd5.js} +4 -4
- package/dist/chunks/{job-f2v2a3w4.js → job-2ptj9njb.js} +2 -2
- package/dist/chunks/{job-522kq8qa.js → job-2spyzfer.js} +1 -1
- package/dist/chunks/{job-dv3yagct.js → job-2xxqbh3j.js} +4 -4
- package/dist/chunks/{job-ek7xs75a.js → job-30ngbap7.js} +1 -1
- package/dist/chunks/{job-vgthr3zd.js → job-3asq9qd5.js} +3 -3
- package/dist/chunks/{job-rngafpkn.js → job-3fbdyapk.js} +3 -3
- package/dist/chunks/{job-1795kap3.js → job-3fhw42bc.js} +6 -6
- package/dist/chunks/{job-7khw64yh.js → job-41qzzbpz.js} +2 -1
- package/dist/chunks/{job-gmvz6tt0.js → job-46crkez1.js} +1 -1
- package/dist/chunks/{job-b09nc7xz.js → job-47gdfeya.js} +16 -16
- package/dist/chunks/{job-twchz7da.js → job-48vsw0jw.js} +1 -1
- package/dist/chunks/{job-2rc1qwhy.js → job-4df507vk.js} +50 -42
- package/dist/chunks/{job-6xx60510.js → job-4seh17cq.js} +1 -1
- package/dist/chunks/{job-zpyt1ezn.js → job-54fer0d0.js} +1 -1
- package/dist/chunks/job-57pbmnfc.js +33 -0
- package/dist/chunks/{job-9qkcnssy.js → job-587cy5wm.js} +2 -2
- package/dist/chunks/{job-jxfq75rv.js → job-61m6ks43.js} +1 -1
- package/dist/chunks/job-6266zj4e.js +34 -0
- package/dist/chunks/{job-ppc4pq6n.js → job-6421j3fd.js} +2 -2
- package/dist/chunks/job-68jwqkqq.js +203 -0
- package/dist/chunks/{job-arfgd8hp.js → job-762jys75.js} +2 -2
- package/dist/chunks/{job-r1bm65q2.js → job-7b8p713x.js} +2 -2
- package/dist/chunks/{job-vt9vdee9.js → job-7jp3zpyh.js} +16 -16
- package/dist/chunks/{job-ccc48pq3.js → job-7s30ncaq.js} +1 -1
- package/dist/chunks/{job-ggy6v1em.js → job-813exka1.js} +3 -3
- package/dist/chunks/{job-d0dbhb87.js → job-8hhxd7er.js} +2 -2
- package/dist/chunks/{job-k36tycg5.js → job-8n8yxdw2.js} +2 -2
- package/dist/chunks/{job-ndwaftrw.js → job-910ht18m.js} +7 -7
- package/dist/chunks/{job-493bygj2.js → job-9bg23qva.js} +5 -5
- package/dist/chunks/{job-ntrwn9c5.js → job-9e6s2wbs.js} +1 -1
- package/dist/chunks/{job-53s1vm97.js → job-9jtvr9f7.js} +1 -1
- package/dist/chunks/{job-bv3cft66.js → job-9tna6sny.js} +6 -6
- package/dist/chunks/{job-w6r7reh9.js → job-af6k8xdc.js} +5 -5
- package/dist/chunks/{job-1gwra17j.js → job-ajmf56n3.js} +8 -8
- package/dist/chunks/{job-1y7r54v0.js → job-ajzk3rs2.js} +1 -1
- package/dist/chunks/{job-9tbbhhr5.js → job-aksqn8ry.js} +1 -1
- package/dist/chunks/{job-3raka4vp.js → job-arxtz9h4.js} +1 -1
- package/dist/chunks/{job-ea0dq72e.js → job-ave2dd3r.js} +46 -44
- package/dist/chunks/{job-tb3sg9tv.js → job-b2jn2z3c.js} +3 -3
- package/dist/chunks/{job-662k41g4.js → job-b4jawdm2.js} +2 -2
- package/dist/chunks/{job-ke8148ty.js → job-bfbx87ej.js} +1 -1
- package/dist/chunks/{job-17rksvd3.js → job-bn0n0hq9.js} +2 -2
- package/dist/chunks/{job-pjq3bk07.js → job-bv2z3evd.js} +5 -5
- package/dist/chunks/{job-vf9yn9vx.js → job-bvavh6pe.js} +3 -3
- package/dist/chunks/{job-s7azyhqy.js → job-caf5y5zg.js} +2 -2
- package/dist/chunks/{job-3x82cc09.js → job-cdm889rz.js} +1 -1
- package/dist/chunks/job-cgqn2mrm.js +147 -0
- package/dist/chunks/{job-za8wqpca.js → job-cqr0z25w.js} +2 -2
- package/dist/chunks/job-cs1gk7aw.js +330 -0
- package/dist/chunks/{job-w989xrsb.js → job-dc495s0z.js} +2 -2
- package/dist/chunks/{job-e663gt7g.js → job-dh8ckpgp.js} +1 -1
- package/dist/chunks/{job-9kxkwge9.js → job-dmvhg2kz.js} +3 -3
- package/dist/chunks/{job-qgr3f3b0.js → job-dn8yfcj9.js} +2 -2
- package/dist/chunks/{job-knm8yv8d.js → job-dv2qtrbh.js} +1 -1
- package/dist/chunks/{job-m4nj1rxs.js → job-e08y7spt.js} +2 -2
- package/dist/chunks/{job-04ve9v9t.js → job-e43zqy1x.js} +4 -4
- package/dist/chunks/{job-p3ahxk9y.js → job-e4v0c7ed.js} +1 -1
- package/dist/chunks/{job-69r90z8c.js → job-emzj2mnz.js} +1 -1
- package/dist/chunks/{job-v42pfaxk.js → job-evztkcdr.js} +1 -1
- package/dist/chunks/{job-1t1wgrhv.js → job-ey3px3v3.js} +2 -2
- package/dist/chunks/{job-dgn4zcks.js → job-f59p8r33.js} +42 -42
- package/dist/chunks/{job-z1t08826.js → job-fagh19yc.js} +5 -5
- package/dist/chunks/{job-wyghbada.js → job-fbd4gqt5.js} +1 -1
- package/dist/chunks/{job-edjh5g28.js → job-fe8hw932.js} +2 -2
- package/dist/chunks/{job-yrxhe8a3.js → job-fg9cms5n.js} +6 -6
- package/dist/chunks/{job-ecft2zb7.js → job-fjvbp1rw.js} +97 -71
- package/dist/chunks/{job-dnxrkvvt.js → job-g9rvq1b5.js} +1 -1
- package/dist/chunks/{job-kxn229zn.js → job-g9vy0vzc.js} +1 -1
- package/dist/chunks/{job-mrdgq75n.js → job-h5cf492r.js} +3 -3
- package/dist/chunks/{job-wvmyfgqa.js → job-h9bbwcgd.js} +1 -1
- package/dist/chunks/job-hym53p1s.js +120 -0
- package/dist/chunks/{job-d64twz5j.js → job-jp8kwwgf.js} +1 -1
- package/dist/chunks/{job-cfzsy64h.js → job-jq8sgn79.js} +2 -2
- package/dist/chunks/{job-1kexajey.js → job-jr5hd5p5.js} +2 -2
- package/dist/chunks/{job-spcjzfgq.js → job-k4t29e2h.js} +2 -2
- package/dist/chunks/{job-rcmgh3ca.js → job-ka9jgdn3.js} +2 -2
- package/dist/chunks/{job-c48kc6fa.js → job-kaffyxmp.js} +4 -4
- package/dist/chunks/{job-zk95prvm.js → job-kh42a55x.js} +3 -3
- package/dist/chunks/{job-vx4s9vef.js → job-khy57ct7.js} +1 -1
- package/dist/chunks/{job-wf9by8hw.js → job-knqwwztd.js} +2 -2
- package/dist/chunks/{job-bz4yk1t4.js → job-kpkmmjx3.js} +4 -4
- package/dist/chunks/{job-2jqw5dy6.js → job-m1fdqckz.js} +2 -2
- package/dist/chunks/{job-7xyyvdqe.js → job-m90gkrdr.js} +2 -2
- package/dist/chunks/{job-0kdsfzn8.js → job-me02a623.js} +1 -1
- package/dist/chunks/{job-v2shkc71.js → job-me5d9f22.js} +6 -6
- package/dist/chunks/{job-ngrdkqab.js → job-n5tqbq9v.js} +1 -1
- package/dist/chunks/{job-y1a7rf83.js → job-ndmfymhz.js} +1 -1
- package/dist/chunks/{job-9ah4t5gc.js → job-new463fc.js} +1 -1
- package/dist/chunks/{job-q5ke20s1.js → job-nh8pkdtv.js} +1 -1
- package/dist/chunks/{job-44ehhp8z.js → job-nvaw7ncd.js} +18 -18
- package/dist/chunks/{job-gg11cpea.js → job-pkn40a12.js} +4 -4
- package/dist/chunks/{job-eyavsrxt.js → job-pskv33a2.js} +2 -2
- package/dist/chunks/{job-52hchg7s.js → job-q87p9xpa.js} +1 -1
- package/dist/chunks/{job-r5qypb3j.js → job-qba7b96d.js} +3 -3
- package/dist/chunks/{job-x6p3vk3n.js → job-qjge9hjg.js} +3 -3
- package/dist/chunks/{job-t981ghyw.js → job-qyg9b9kw.js} +3 -3
- package/dist/chunks/{job-eqacz5gw.js → job-rvnd6a2n.js} +1 -1
- package/dist/chunks/{job-0bw528m8.js → job-sx7e8x54.js} +16 -16
- package/dist/chunks/{job-wpn3tqwb.js → job-t0esftz3.js} +82 -82
- package/dist/chunks/{job-3apyg94z.js → job-tjvgp8sx.js} +1 -1
- package/dist/chunks/{job-dm0vs72c.js → job-tywfhfz1.js} +6 -6
- package/dist/chunks/{job-c1fr40sx.js → job-v4rnjb1g.js} +1 -1
- package/dist/chunks/{job-sqzywsbq.js → job-v50dw4p6.js} +2 -2
- package/dist/chunks/{job-83zdjmgg.js → job-v9j3k8n3.js} +2 -2
- package/dist/chunks/{job-qarwrfd1.js → job-x9rd2vnh.js} +1 -1
- package/dist/chunks/{job-6eb12gng.js → job-xygthxr3.js} +2 -2
- package/dist/chunks/{job-vzgmc9jp.js → job-y3sfr5g3.js} +4 -4
- package/dist/chunks/{job-830qkp09.js → job-ye4yygw2.js} +1 -1
- package/dist/chunks/job-yyjmndg0.js +483 -0
- package/dist/chunks/{job-4gv2h1pd.js → job-yypfb467.js} +3 -3
- package/dist/chunks/{job-j0e9tdbc.js → job-z136m2k9.js} +3 -3
- package/dist/chunks/{job-n2c9k96k.js → job-z3fjxbtv.js} +4 -4
- package/dist/chunks/{job-ba35xjtb.js → job-z61mvmr2.js} +6 -6
- package/dist/chunks/{job-xes8c7na.js → job-zjdkpeq1.js} +8 -6
- package/dist/chunks/{job-hnxf074g.js → job-zq3dpz3n.js} +1 -1
- package/dist/chunks/{job-vhxe1a2q.js → job-zr6va574.js} +2 -2
- package/dist/chunks/{job-h41pqsxw.js → job-zrccwvnf.js} +1 -1
- package/dist/chunks/{job-tdk41tnh.js → job-zzhrh7mp.js} +2 -2
- package/dist/chunks/{job-nkej4bfa.js → job-zzp6hyw7.js} +2 -2
- package/dist/command.js +2 -2
- package/dist/config/plugin/agent.js +15 -15
- package/dist/config/plugin/command.js +9 -9
- package/dist/config/plugin/compaction.js +22 -22
- package/dist/config/plugin/entry-observer.js +8 -8
- package/dist/config/plugin/formatter.js +10 -10
- package/dist/config/plugin/image.js +14 -14
- package/dist/config/plugin/instruction.js +7 -7
- package/dist/config/plugin/location-watcher.js +9 -9
- package/dist/config/plugin/mcp.js +13 -13
- package/dist/config/plugin/policy.js +9 -9
- package/dist/config/plugin/provider.js +9 -9
- package/dist/config/plugin/reference.js +10 -10
- package/dist/config/plugin/shell.js +9 -9
- package/dist/config/plugin/skill-file.js +13 -13
- package/dist/config/plugin/skill.js +17 -17
- package/dist/config/plugin/snapshot.js +10 -10
- package/dist/config/plugin/source.js +9 -9
- package/dist/config/plugin/tool-output.js +9 -9
- package/dist/config/plugin/websearch.js +9 -9
- package/dist/config.js +8 -8
- package/dist/credential.js +2 -2
- package/dist/effect/app-node-builder.js +146 -142
- package/dist/environment/environment.js +6 -6
- package/dist/environment/index.js +6 -6
- package/dist/event-logger.js +1 -1
- package/dist/file-mutation.js +7 -7
- package/dist/filesystem/location-watcher.js +125 -123
- package/dist/filesystem/search.js +8 -8
- package/dist/filesystem.js +9 -9
- package/dist/form.js +2 -2
- package/dist/formatter.js +6 -6
- package/dist/generate.js +7 -7
- package/dist/github-copilot/chat/openai-compatible-chat-language-model.js +4 -4
- package/dist/github-copilot/copilot-provider.js +9 -9
- package/dist/github-copilot/responses/openai-responses-language-model.js +5 -5
- package/dist/github-copilot/responses/openai-responses-prepare-tools.js +2 -2
- package/dist/image/photon.js +10 -10
- package/dist/image.js +10 -10
- package/dist/instance.js +145 -141
- package/dist/instruction-discovery.js +2 -2
- package/dist/instructions/builtins.js +6 -6
- package/dist/integration.js +4 -4
- package/dist/location-activity.js +5 -5
- package/dist/location-mutation.js +6 -6
- package/dist/location-service-map.js +5 -5
- package/dist/location-services.js +146 -142
- package/dist/location.js +5 -5
- package/dist/mcp/client.js +7 -7
- package/dist/mcp/index.js +10 -10
- package/dist/mcp/instructions.js +23 -23
- package/dist/mcp/stdio.js +7 -7
- package/dist/model-resolver.js +6 -6
- package/dist/models-dev.js +2 -2
- package/dist/permission.js +11 -11
- package/dist/persistent-pty/index.js +2 -2
- package/dist/persistent-pty.js +2 -2
- package/dist/plugin/agent.js +12 -12
- package/dist/plugin/command.js +11 -11
- package/dist/plugin/host.js +47 -45
- package/dist/plugin/internal.js +120 -118
- package/dist/plugin/models-dev.js +3 -3
- package/dist/plugin/plan.js +12 -12
- package/dist/plugin/provider/azure.js +13 -13
- package/dist/plugin/provider/cloudflare-ai-gateway.js +13 -13
- package/dist/plugin/provider/cloudflare-workers-ai.js +13 -13
- package/dist/plugin/provider/configured.js +12 -12
- package/dist/plugin/provider/github-copilot.js +7 -7
- package/dist/plugin/provider/llmgateway.js +5 -5
- package/dist/plugin/provider/lmstudio.js +13 -13
- package/dist/plugin/provider/ollama.js +13 -13
- package/dist/plugin/provider/openai.js +5 -5
- package/dist/plugin/provider/opencode.js +5 -5
- package/dist/plugin/provider/vllm.js +13 -13
- package/dist/plugin/provider/xai.js +5 -5
- package/dist/plugin/provider.js +35 -35
- package/dist/plugin/runtime.js +41 -39
- package/dist/plugin/sdk.js +2 -2
- package/dist/plugin/skill.js +17 -17
- package/dist/plugin/supervisor.js +126 -124
- package/dist/plugin/vcs/git.js +7 -7
- package/dist/plugin/vcs/hg.js +7 -7
- package/dist/plugin/warming.js +9 -9
- package/dist/plugin/websearch/index.js +3 -3
- package/dist/plugin.js +48 -46
- package/dist/project/markers.js +3 -3
- package/dist/project.js +4 -4
- package/dist/pty.js +6 -6
- package/dist/reference/instructions.js +3 -3
- package/dist/reference.js +2 -2
- package/dist/ripgrep.js +7 -7
- package/dist/session/compaction.js +19 -19
- package/dist/session/context.js +133 -131
- package/dist/session/error.js +23 -1
- package/dist/session/execution/restart.js +39 -37
- package/dist/session/execution.js +21 -21
- package/dist/session/generate-node.js +134 -132
- package/dist/session/history.js +2 -2
- package/dist/session/inbox.js +11 -15
- package/dist/session/instructions.js +10 -10
- package/dist/session/model-request.js +25 -25
- package/dist/session/projector.js +3 -3
- package/dist/session/prompt-node.js +320 -0
- package/dist/session/prompt.js +130 -0
- package/dist/session/revert-node.js +320 -0
- package/dist/session/revert.js +17 -12
- package/dist/session/run-coordinator.js +1 -1
- package/dist/session/runner/index.js +7 -7
- package/dist/session/runner/llm.js +138 -136
- package/dist/session/runner/model.js +7 -7
- package/dist/session/runner/retry.js +1 -1
- package/dist/session/runner/step.js +29 -29
- package/dist/session/session.js +181 -0
- package/dist/session/store.js +4 -4
- package/dist/session/title.js +134 -132
- package/dist/session/to-session-error.js +18 -18
- package/dist/session/transfer.js +40 -38
- package/dist/session.js +50 -48
- package/dist/shell.js +10 -10
- package/dist/skill/instructions.js +13 -13
- package/dist/skill.js +12 -12
- package/dist/snapshot.js +6 -6
- package/dist/tool/mcp.js +22 -22
- package/dist/tool/plugin/edit.js +16 -16
- package/dist/tool/plugin/glob.js +17 -17
- package/dist/tool/plugin/grep.js +17 -17
- package/dist/tool/plugin/patch.js +16 -16
- package/dist/tool/plugin/question.js +13 -13
- package/dist/tool/plugin/read.js +19 -19
- package/dist/tool/plugin/shell.js +43 -41
- package/dist/tool/plugin/skill.js +13 -13
- package/dist/tool/plugin/subagent.js +42 -40
- package/dist/tool/plugin/webfetch.js +12 -12
- package/dist/tool/plugin/websearch.js +14 -14
- package/dist/tool/plugin/write.js +16 -16
- package/dist/tool/read-filesystem.js +10 -10
- package/dist/tool.js +17 -17
- package/dist/types/instance.d.ts +2 -2
- package/dist/types/location-service-map.d.ts +2 -2
- package/dist/types/plugin/host.d.ts +4 -18
- package/dist/types/project.d.ts +1 -0
- package/dist/types/session/error.d.ts +115 -0
- package/dist/types/session/execution.d.ts +2 -0
- package/dist/types/session/inbox.d.ts +557 -176
- package/dist/types/session/prompt-node.d.ts +3 -0
- package/dist/types/session/prompt.d.ts +126 -0
- package/dist/types/session/revert-node.d.ts +3 -0
- package/dist/types/session/revert.d.ts +24 -29
- package/dist/types/session/run-coordinator.d.ts +2 -0
- package/dist/types/session/session.d.ts +232 -0
- package/dist/types/session.d.ts +14 -141
- package/dist/vcs.js +6 -6
- package/dist/websearch.js +2 -2
- package/dist/wellknown/plugin.js +3 -3
- package/dist/wellknown.js +2 -2
- package/dist/worktree.js +6 -6
- package/package.json +7 -7
- package/dist/chunks/job-fb7nfzf2.js +0 -71
- package/dist/chunks/job-k3b93ktv.js +0 -909
- package/dist/chunks/job-x7z7742t.js +0 -115
- package/dist/chunks/{job-dchkjjs1.js → job-5y7h4bj8.js} +6 -6
- package/dist/chunks/{job-yd18a1xb.js → job-pzy8panz.js} +9 -9
- package/dist/chunks/{job-tkazpfmd.js → job-qj3yfbbj.js} +3 -3
- /package/dist/chunks/{job-ryg4g4zw.js → job-s5a3kj32.js} +0 -0
- /package/dist/chunks/{job-j925pnyr.js → job-wcdz88tf.js} +0 -0
|
@@ -1,909 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
exports_supervisor_service
|
|
3
|
-
} from "./job-s33fw6zm.js";
|
|
4
|
-
import {
|
|
5
|
-
exports_revert
|
|
6
|
-
} from "./job-x7z7742t.js";
|
|
7
|
-
import {
|
|
8
|
-
exports_execution
|
|
9
|
-
} from "./job-xes8c7na.js";
|
|
10
|
-
import {
|
|
11
|
-
exports_generate
|
|
12
|
-
} from "./job-xgv25zxy.js";
|
|
13
|
-
import {
|
|
14
|
-
exports_projector
|
|
15
|
-
} from "./job-dv3yagct.js";
|
|
16
|
-
import {
|
|
17
|
-
exports_instruction_entry
|
|
18
|
-
} from "./job-0j6yxnr1.js";
|
|
19
|
-
import {
|
|
20
|
-
exports_inbox
|
|
21
|
-
} from "./job-ecft2zb7.js";
|
|
22
|
-
import {
|
|
23
|
-
exports_model_transport
|
|
24
|
-
} from "./job-tjrfm0xh.js";
|
|
25
|
-
import {
|
|
26
|
-
exports_shell
|
|
27
|
-
} from "./job-c48kc6fa.js";
|
|
28
|
-
import {
|
|
29
|
-
exports_result
|
|
30
|
-
} from "./job-etvrgfqj.js";
|
|
31
|
-
import {
|
|
32
|
-
exports_environment
|
|
33
|
-
} from "./job-6ky7rqk7.js";
|
|
34
|
-
import {
|
|
35
|
-
Slug
|
|
36
|
-
} from "./job-df3v2q6j.js";
|
|
37
|
-
import {
|
|
38
|
-
exports_skill
|
|
39
|
-
} from "./job-sqzywsbq.js";
|
|
40
|
-
import {
|
|
41
|
-
exports_command
|
|
42
|
-
} from "./job-d64twz5j.js";
|
|
43
|
-
import {
|
|
44
|
-
exports_app
|
|
45
|
-
} from "./job-50jxp3hw.js";
|
|
46
|
-
import {
|
|
47
|
-
exports_location_service_map
|
|
48
|
-
} from "./job-zdkg1k91.js";
|
|
49
|
-
import {
|
|
50
|
-
exports_store
|
|
51
|
-
} from "./job-wvmyfgqa.js";
|
|
52
|
-
import {
|
|
53
|
-
exports_history
|
|
54
|
-
} from "./job-ngrdkqab.js";
|
|
55
|
-
import {
|
|
56
|
-
fromRow
|
|
57
|
-
} from "./job-264e1nfp.js";
|
|
58
|
-
import {
|
|
59
|
-
exports_instruction_state
|
|
60
|
-
} from "./job-hxcd35r2.js";
|
|
61
|
-
import {
|
|
62
|
-
ForkEmptyError,
|
|
63
|
-
MessageDecodeError,
|
|
64
|
-
NotFoundError
|
|
65
|
-
} from "./job-fb7nfzf2.js";
|
|
66
|
-
import {
|
|
67
|
-
SessionMessageTable,
|
|
68
|
-
SessionTable
|
|
69
|
-
} from "./job-q606pcse.js";
|
|
70
|
-
import {
|
|
71
|
-
exports_hooks
|
|
72
|
-
} from "./job-v2wshkax.js";
|
|
73
|
-
import {
|
|
74
|
-
exports_image
|
|
75
|
-
} from "./job-ryg4g4zw.js";
|
|
76
|
-
import {
|
|
77
|
-
SessionEvent
|
|
78
|
-
} from "./job-a83yvq99.js";
|
|
79
|
-
import {
|
|
80
|
-
exports_job
|
|
81
|
-
} from "./job-2hnk029s.js";
|
|
82
|
-
import {
|
|
83
|
-
SessionMessage
|
|
84
|
-
} from "./job-8rpfd2h6.js";
|
|
85
|
-
import {
|
|
86
|
-
ID,
|
|
87
|
-
Info,
|
|
88
|
-
SessionSchema
|
|
89
|
-
} from "./job-bjwj8hwv.js";
|
|
90
|
-
import {
|
|
91
|
-
exports_mime
|
|
92
|
-
} from "./job-dhphtf1x.js";
|
|
93
|
-
import {
|
|
94
|
-
exports_location
|
|
95
|
-
} from "./job-knm8yv8d.js";
|
|
96
|
-
import {
|
|
97
|
-
exports_project
|
|
98
|
-
} from "./job-9qkcnssy.js";
|
|
99
|
-
import {
|
|
100
|
-
upsertProject
|
|
101
|
-
} from "./job-c8ya26sa.js";
|
|
102
|
-
import {
|
|
103
|
-
exports_bus
|
|
104
|
-
} from "./job-j925pnyr.js";
|
|
105
|
-
import {
|
|
106
|
-
exports_database
|
|
107
|
-
} from "./job-rp954h3j.js";
|
|
108
|
-
import {
|
|
109
|
-
AbsolutePath,
|
|
110
|
-
PositiveInt,
|
|
111
|
-
RelativePath
|
|
112
|
-
} from "./job-j07kk359.js";
|
|
113
|
-
import {
|
|
114
|
-
__export
|
|
115
|
-
} from "./job-rvfvac9x.js";
|
|
116
|
-
|
|
117
|
-
// src/session.ts
|
|
118
|
-
var exports_session = {};
|
|
119
|
-
__export(exports_session, {
|
|
120
|
-
node: () => node,
|
|
121
|
-
SyntheticConflictError: () => SyntheticConflictError,
|
|
122
|
-
SkillNotFoundError: () => SkillNotFoundError,
|
|
123
|
-
SessionSchema: () => SessionSchema,
|
|
124
|
-
Session: () => exports_session,
|
|
125
|
-
Service: () => Service,
|
|
126
|
-
PromptConflictError: () => PromptConflictError,
|
|
127
|
-
NotFoundError: () => NotFoundError,
|
|
128
|
-
MessageToolIncompleteError: () => MessageToolIncompleteError,
|
|
129
|
-
MessageNotFoundError: () => MessageNotFoundError,
|
|
130
|
-
MessageNotAssistantError: () => MessageNotAssistantError,
|
|
131
|
-
MessageIncompleteError: () => MessageIncompleteError,
|
|
132
|
-
MessageDecodeError: () => MessageDecodeError,
|
|
133
|
-
ListInput: () => ListInput,
|
|
134
|
-
ListAnchor: () => ListAnchor,
|
|
135
|
-
Info: () => Info,
|
|
136
|
-
InboxConflictError: () => InboxConflictError,
|
|
137
|
-
ID: () => ID,
|
|
138
|
-
DestinationUnavailableError: () => DestinationUnavailableError,
|
|
139
|
-
DestinationNotFoundError: () => DestinationNotFoundError,
|
|
140
|
-
DestinationNotDirectoryError: () => DestinationNotDirectoryError,
|
|
141
|
-
CompactionConflictError: () => CompactionConflictError,
|
|
142
|
-
BusyError: () => BusyError,
|
|
143
|
-
AttachmentError: () => AttachmentError
|
|
144
|
-
});
|
|
145
|
-
import { Cause, Effect, Fiber, Layer, Schema, Context, RcMap, Stream, Scope } from "effect";
|
|
146
|
-
import { ListAnchor } from "@opencode-ai/schema/session";
|
|
147
|
-
import { and, asc, desc, eq, gt, isNull, like, lt, or } from "drizzle-orm";
|
|
148
|
-
import { Workspace } from "@opencode-ai/schema/workspace";
|
|
149
|
-
import { Model } from "@opencode-ai/schema/model";
|
|
150
|
-
import { Base64, FileAttachment, Prompt } from "@opencode-ai/schema/prompt";
|
|
151
|
-
import path from "path";
|
|
152
|
-
import { makeGlobalNode } from "@opencode-ai/util/effect/app-node";
|
|
153
|
-
import { FSUtil } from "@opencode-ai/util/fs-util";
|
|
154
|
-
import { Event } from "@opencode-ai/schema/event";
|
|
155
|
-
import { Global } from "@opencode-ai/util/global";
|
|
156
|
-
import { fileURLToPath } from "url";
|
|
157
|
-
var ListInputBase = {
|
|
158
|
-
workspaceID: Workspace.ID.pipe(Schema.optional),
|
|
159
|
-
search: Schema.String.pipe(Schema.optional),
|
|
160
|
-
limit: PositiveInt.pipe(Schema.optional),
|
|
161
|
-
order: Schema.Literals(["asc", "desc"]).pipe(Schema.optional),
|
|
162
|
-
parentID: Schema.NullOr(SessionSchema.ID).pipe(Schema.optional),
|
|
163
|
-
anchor: ListAnchor.pipe(Schema.optional)
|
|
164
|
-
};
|
|
165
|
-
var ListDirectoryInput = Schema.Struct({
|
|
166
|
-
...ListInputBase,
|
|
167
|
-
directory: AbsolutePath
|
|
168
|
-
});
|
|
169
|
-
var ListProjectInput = Schema.Struct({
|
|
170
|
-
...ListInputBase,
|
|
171
|
-
project: exports_project.ID,
|
|
172
|
-
subpath: RelativePath.pipe(Schema.optional)
|
|
173
|
-
});
|
|
174
|
-
var ListAllInput = Schema.Struct(ListInputBase);
|
|
175
|
-
var ListInput = Schema.Union([ListDirectoryInput, ListProjectInput, ListAllInput]);
|
|
176
|
-
class PromptConflictError extends Schema.TaggedError()("Session.PromptConflictError", {
|
|
177
|
-
sessionID: SessionSchema.ID,
|
|
178
|
-
messageID: SessionMessage.ID
|
|
179
|
-
}) {
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
class SyntheticConflictError extends Schema.TaggedError()("Session.SyntheticConflictError", {
|
|
183
|
-
sessionID: SessionSchema.ID,
|
|
184
|
-
inputID: SessionMessage.ID
|
|
185
|
-
}) {
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
class AttachmentError extends Schema.TaggedError()("Session.AttachmentError", {
|
|
189
|
-
uri: Schema.String,
|
|
190
|
-
message: Schema.String
|
|
191
|
-
}) {
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
class CompactionConflictError extends Schema.TaggedError()("Session.CompactionConflictError", {
|
|
195
|
-
sessionID: SessionSchema.ID,
|
|
196
|
-
inputID: SessionMessage.ID
|
|
197
|
-
}) {
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
class BusyError extends Schema.TaggedError()("Session.BusyError", {
|
|
201
|
-
sessionID: SessionSchema.ID
|
|
202
|
-
}) {
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
class MessageNotAssistantError extends Schema.TaggedError()("Session.MessageNotAssistantError", {
|
|
206
|
-
sessionID: SessionSchema.ID,
|
|
207
|
-
messageID: SessionMessage.ID
|
|
208
|
-
}) {
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
class MessageIncompleteError extends Schema.TaggedError()("Session.MessageIncompleteError", {
|
|
212
|
-
sessionID: SessionSchema.ID,
|
|
213
|
-
messageID: SessionMessage.ID
|
|
214
|
-
}) {
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
class MessageToolIncompleteError extends Schema.TaggedError()("Session.MessageToolIncompleteError", {
|
|
218
|
-
sessionID: SessionSchema.ID,
|
|
219
|
-
messageID: SessionMessage.ID
|
|
220
|
-
}) {
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
class InboxConflictError extends Schema.TaggedError()("Session.InboxConflictError", {
|
|
224
|
-
sessionID: SessionSchema.ID,
|
|
225
|
-
inboxID: SessionMessage.ID
|
|
226
|
-
}) {
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
class SkillNotFoundError extends Schema.TaggedError()("Session.SkillNotFoundError", {
|
|
230
|
-
skill: exports_skill.ID
|
|
231
|
-
}) {
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
class DestinationNotFoundError extends Schema.TaggedError()("Session.DestinationNotFoundError", { directory: AbsolutePath }) {
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
class DestinationNotDirectoryError extends Schema.TaggedError()("Session.DestinationNotDirectoryError", { directory: AbsolutePath }) {
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
class DestinationUnavailableError extends Schema.TaggedError()("Session.DestinationUnavailableError", { directory: AbsolutePath }) {
|
|
241
|
-
}
|
|
242
|
-
var MessageNotFoundError = exports_revert.MessageNotFoundError;
|
|
243
|
-
|
|
244
|
-
class Service extends Context.Service()("@opencode/Session") {
|
|
245
|
-
}
|
|
246
|
-
var layer = Layer.effect(Service, Effect.gen(function* () {
|
|
247
|
-
const app = yield* exports_app.Metadata;
|
|
248
|
-
const database = yield* exports_database.Service;
|
|
249
|
-
const db = database.db;
|
|
250
|
-
const bus = yield* exports_bus.Service;
|
|
251
|
-
const projects = yield* exports_project.Service;
|
|
252
|
-
const global = yield* Global.Service;
|
|
253
|
-
const execution = yield* exports_execution.Service;
|
|
254
|
-
const store = yield* exports_store.Service;
|
|
255
|
-
const locations = yield* exports_location_service_map.Service;
|
|
256
|
-
const fs = yield* FSUtil.Service;
|
|
257
|
-
const jobs = yield* exports_job.Service;
|
|
258
|
-
const environments = yield* exports_environment.Service;
|
|
259
|
-
const scope = yield* Scope.Scope;
|
|
260
|
-
const closeTransport = Effect.fn("Session.closeTransport")(function* (session) {
|
|
261
|
-
const location = exports_location.Ref.make({
|
|
262
|
-
directory: session.location.directory,
|
|
263
|
-
workspaceID: session.location.workspaceID
|
|
264
|
-
});
|
|
265
|
-
if (!(yield* RcMap.has(locations.rcMap, location)))
|
|
266
|
-
return;
|
|
267
|
-
yield* exports_model_transport.Service.use((transport) => transport.close(session.id)).pipe(Effect.provide(locations.get(location)));
|
|
268
|
-
});
|
|
269
|
-
const isDurableSessionEvent = Schema.is(SessionEvent.Durable);
|
|
270
|
-
const persistProject = (project) => upsertProject(db, project).pipe(Effect.orDie);
|
|
271
|
-
const pendingConflict = Effect.fn("Session.pendingConflict")(function* (input) {
|
|
272
|
-
yield* result.get(input.sessionID);
|
|
273
|
-
return yield* new InboxConflictError(input);
|
|
274
|
-
});
|
|
275
|
-
const mutatePending = (input, mutation, wake = false) => Effect.uninterruptible(Effect.gen(function* () {
|
|
276
|
-
yield* mutation(bus, { sessionID: input.sessionID, id: input.inboxID }).pipe(Effect.catchDefect((defect) => defect instanceof exports_inbox.LifecycleConflict ? pendingConflict(input) : Effect.die(defect)));
|
|
277
|
-
if (wake)
|
|
278
|
-
yield* execution.wake(input.sessionID);
|
|
279
|
-
}));
|
|
280
|
-
const result = Service.of({
|
|
281
|
-
create: Effect.fn("Session.create")(function* (input) {
|
|
282
|
-
const sessionID = input.id ?? SessionSchema.ID.create();
|
|
283
|
-
const recorded = yield* store.get(sessionID);
|
|
284
|
-
if (recorded)
|
|
285
|
-
return recorded;
|
|
286
|
-
const parent = input.parentID ? yield* store.get(input.parentID) : undefined;
|
|
287
|
-
if (input.parentID && parent === undefined)
|
|
288
|
-
return yield* new NotFoundError({ sessionID: input.parentID });
|
|
289
|
-
const location = parent?.location ?? input.location;
|
|
290
|
-
if (location === undefined)
|
|
291
|
-
return yield* Effect.die(new Error("Session.create requires either location or an existing parentID"));
|
|
292
|
-
const project = yield* projects.resolve(location.directory);
|
|
293
|
-
yield* persistProject(project);
|
|
294
|
-
const projected = yield* bus.publish(SessionEvent.Created, {
|
|
295
|
-
sessionID,
|
|
296
|
-
slug: Slug.create(),
|
|
297
|
-
version: app.version,
|
|
298
|
-
projectID: project.id,
|
|
299
|
-
parentID: input.parentID,
|
|
300
|
-
location,
|
|
301
|
-
subpath: RelativePath.make(path.relative(project.directory, location.directory).replaceAll("\\", "/")),
|
|
302
|
-
title: input.title,
|
|
303
|
-
agent: input.agent,
|
|
304
|
-
metadata: input.metadata ?? parent?.metadata,
|
|
305
|
-
model: input.model ? {
|
|
306
|
-
id: Model.ID.make(input.model.id),
|
|
307
|
-
providerID: input.model.providerID,
|
|
308
|
-
variant: input.model.variant
|
|
309
|
-
} : undefined
|
|
310
|
-
}, { location }).pipe(Effect.as({ type: "created" }), Effect.catchDefect((defect) => {
|
|
311
|
-
if (!(defect instanceof exports_projector.SessionAlreadyProjected)) {
|
|
312
|
-
return Effect.die(defect);
|
|
313
|
-
}
|
|
314
|
-
return store.get(sessionID).pipe(Effect.flatMap((session) => session ? Effect.succeed({ type: "existing", session }) : Effect.die(defect)));
|
|
315
|
-
}));
|
|
316
|
-
if (projected.type === "existing")
|
|
317
|
-
return projected.session;
|
|
318
|
-
return yield* result.get(sessionID).pipe(Effect.orDie);
|
|
319
|
-
}),
|
|
320
|
-
fork: Effect.fn("Session.fork")(function* (input) {
|
|
321
|
-
const parent = yield* result.get(input.sessionID);
|
|
322
|
-
const boundary = yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).where(and(eq(SessionMessageTable.session_id, input.sessionID), input.boundary.type === "before" ? eq(SessionMessageTable.id, input.boundary.messageID) : undefined)).orderBy(desc(SessionMessageTable.seq)).limit(1).get().pipe(Effect.orDie);
|
|
323
|
-
if (!boundary && input.boundary.type === "before")
|
|
324
|
-
return yield* new MessageNotFoundError({
|
|
325
|
-
sessionID: input.sessionID,
|
|
326
|
-
messageID: input.boundary.messageID
|
|
327
|
-
});
|
|
328
|
-
if (!boundary)
|
|
329
|
-
return yield* new ForkEmptyError({ sessionID: input.sessionID });
|
|
330
|
-
const sessionID = SessionSchema.ID.create();
|
|
331
|
-
const inherited = yield* db.transaction(() => Effect.all({
|
|
332
|
-
instructions: exports_instruction_state.current(db, parent.id),
|
|
333
|
-
instructionEntries: exports_instruction_entry.snapshot(db, parent.id)
|
|
334
|
-
})).pipe(Effect.orDie);
|
|
335
|
-
yield* bus.publish(SessionEvent.Forked, {
|
|
336
|
-
sessionID,
|
|
337
|
-
parentID: parent.id,
|
|
338
|
-
boundary: { ...input.boundary, messageID: boundary.id },
|
|
339
|
-
...inherited
|
|
340
|
-
});
|
|
341
|
-
return yield* result.get(sessionID).pipe(Effect.orDie);
|
|
342
|
-
}),
|
|
343
|
-
get: Effect.fn("Session.get")(function* (sessionID) {
|
|
344
|
-
const session = yield* store.get(sessionID);
|
|
345
|
-
if (!session)
|
|
346
|
-
return yield* new NotFoundError({ sessionID });
|
|
347
|
-
return session;
|
|
348
|
-
}),
|
|
349
|
-
environment: Effect.fn("Session.environment")(function* (input) {
|
|
350
|
-
yield* result.get(input.sessionID);
|
|
351
|
-
if (input.variables !== undefined)
|
|
352
|
-
yield* environments.set(input.sessionID, input.variables);
|
|
353
|
-
return yield* environments.get(input.sessionID);
|
|
354
|
-
}),
|
|
355
|
-
view: Effect.fn("Session.view")(function* (input) {
|
|
356
|
-
const row = yield* db.select({ idle: SessionTable.time_idle, viewed: SessionTable.time_viewed }).from(SessionTable).where(eq(SessionTable.id, input.sessionID)).get().pipe(Effect.orDie);
|
|
357
|
-
if (!row)
|
|
358
|
-
return yield* new NotFoundError({ sessionID: input.sessionID });
|
|
359
|
-
if (row.idle === null || input.idle > row.idle || row.viewed !== null && row.viewed >= input.idle)
|
|
360
|
-
return yield* Effect.void;
|
|
361
|
-
yield* bus.publish(SessionEvent.Viewed, { sessionID: input.sessionID, idle: input.idle });
|
|
362
|
-
}),
|
|
363
|
-
remove: Effect.fn("Session.remove")(function* (sessionID) {
|
|
364
|
-
const session = yield* result.get(sessionID);
|
|
365
|
-
yield* execution.interrupt(sessionID);
|
|
366
|
-
yield* execution.awaitIdle(sessionID);
|
|
367
|
-
yield* closeTransport(session);
|
|
368
|
-
const children = yield* result.list({ parentID: sessionID });
|
|
369
|
-
yield* Effect.forEach(children.data, (child) => result.remove(child.id), { concurrency: 1, discard: true });
|
|
370
|
-
yield* environments.clear(sessionID);
|
|
371
|
-
yield* bus.publish(SessionEvent.Deleted, { sessionID });
|
|
372
|
-
yield* bus.remove(sessionID);
|
|
373
|
-
}),
|
|
374
|
-
list: Effect.fn("Session.list")(function* (input = {}) {
|
|
375
|
-
const direction = input.anchor?.direction ?? "next";
|
|
376
|
-
const requestedOrder = input.order ?? "desc";
|
|
377
|
-
const order = direction === "previous" ? requestedOrder === "asc" ? "desc" : "asc" : requestedOrder;
|
|
378
|
-
const sortColumn = SessionTable.time_updated;
|
|
379
|
-
const conditions = [];
|
|
380
|
-
if ("directory" in input)
|
|
381
|
-
conditions.push(eq(SessionTable.directory, input.directory));
|
|
382
|
-
if (input.workspaceID)
|
|
383
|
-
conditions.push(eq(SessionTable.workspace_id, input.workspaceID));
|
|
384
|
-
if ("project" in input)
|
|
385
|
-
conditions.push(eq(SessionTable.project_id, input.project));
|
|
386
|
-
if ("project" in input && input.subpath !== undefined)
|
|
387
|
-
conditions.push(eq(SessionTable.path, input.subpath));
|
|
388
|
-
if (input.search)
|
|
389
|
-
conditions.push(like(SessionTable.title, `%${input.search}%`));
|
|
390
|
-
if (input.parentID !== undefined)
|
|
391
|
-
conditions.push(input.parentID === null ? isNull(SessionTable.parent_id) : eq(SessionTable.parent_id, input.parentID));
|
|
392
|
-
if (input.anchor) {
|
|
393
|
-
conditions.push(order === "asc" ? or(gt(sortColumn, input.anchor.time), and(eq(sortColumn, input.anchor.time), gt(SessionTable.id, input.anchor.id))) : or(lt(sortColumn, input.anchor.time), and(eq(sortColumn, input.anchor.time), lt(SessionTable.id, input.anchor.id))));
|
|
394
|
-
}
|
|
395
|
-
const query = db.select().from(SessionTable).where(conditions.length > 0 ? and(...conditions) : undefined).orderBy(order === "asc" ? asc(sortColumn) : desc(sortColumn), order === "asc" ? asc(SessionTable.id) : desc(SessionTable.id));
|
|
396
|
-
const rows = yield* (input.limit === undefined ? query.all() : query.limit(input.limit).all()).pipe(Effect.orDie);
|
|
397
|
-
return { data: (direction === "previous" ? rows.toReversed() : rows).map((row) => fromRow(row)) };
|
|
398
|
-
}),
|
|
399
|
-
messages: Effect.fn("Session.messages")(function* (input) {
|
|
400
|
-
yield* result.get(input.sessionID);
|
|
401
|
-
const direction = input.cursor?.direction ?? "next";
|
|
402
|
-
const requestedOrder = input.order ?? "desc";
|
|
403
|
-
const order = direction === "previous" ? requestedOrder === "asc" ? "desc" : "asc" : requestedOrder;
|
|
404
|
-
const anchor = input.cursor ? yield* db.select({ seq: SessionMessageTable.seq }).from(SessionMessageTable).where(and(eq(SessionMessageTable.session_id, input.sessionID), eq(SessionMessageTable.id, input.cursor.id))).get().pipe(Effect.orDie) : undefined;
|
|
405
|
-
if (input.cursor && !anchor)
|
|
406
|
-
return [];
|
|
407
|
-
const boundary = anchor ? order === "asc" ? gt(SessionMessageTable.seq, anchor.seq) : lt(SessionMessageTable.seq, anchor.seq) : undefined;
|
|
408
|
-
const where = boundary ? and(eq(SessionMessageTable.session_id, input.sessionID), boundary) : eq(SessionMessageTable.session_id, input.sessionID);
|
|
409
|
-
const query = db.select().from(SessionMessageTable).where(where).orderBy(order === "asc" ? asc(SessionMessageTable.seq) : desc(SessionMessageTable.seq));
|
|
410
|
-
const rows = yield* (input.limit === undefined ? query.all() : query.limit(input.limit).all()).pipe(Effect.orDie);
|
|
411
|
-
return yield* Effect.forEach(direction === "previous" ? rows.toReversed() : rows, exports_history.decodeMessageRow);
|
|
412
|
-
}),
|
|
413
|
-
message: Effect.fn("Session.message")(function* (input) {
|
|
414
|
-
const stored = yield* store.message(input.messageID);
|
|
415
|
-
return stored?.sessionID === input.sessionID ? stored.message : undefined;
|
|
416
|
-
}),
|
|
417
|
-
updateMessage: Effect.fn("Session.updateMessage")(function* (input) {
|
|
418
|
-
const ref = { sessionID: input.sessionID, messageID: input.messageID };
|
|
419
|
-
yield* result.get(ref.sessionID);
|
|
420
|
-
if ((yield* execution.active).has(ref.sessionID))
|
|
421
|
-
return yield* new BusyError({ sessionID: ref.sessionID });
|
|
422
|
-
const message = yield* result.message(ref);
|
|
423
|
-
if (!message)
|
|
424
|
-
return yield* new MessageNotFoundError(ref);
|
|
425
|
-
if (message.type !== "assistant")
|
|
426
|
-
return yield* new MessageNotAssistantError(ref);
|
|
427
|
-
if (!message.time.completed)
|
|
428
|
-
return yield* new MessageIncompleteError(ref);
|
|
429
|
-
if (input.content.some((content) => content.type === "tool" && (content.state.status === "streaming" || content.state.status === "running")))
|
|
430
|
-
return yield* new MessageToolIncompleteError(ref);
|
|
431
|
-
yield* bus.publish(SessionEvent.MessageContentUpdated, {
|
|
432
|
-
...ref,
|
|
433
|
-
content: Schema.encodeSync(Schema.Array(SessionMessage.AssistantContent))(input.content)
|
|
434
|
-
});
|
|
435
|
-
const updated = yield* result.message(ref);
|
|
436
|
-
if (updated?.type !== "assistant")
|
|
437
|
-
return yield* new MessageNotFoundError(ref);
|
|
438
|
-
return updated;
|
|
439
|
-
}),
|
|
440
|
-
context: Effect.fn("Session.context")(function* (sessionID) {
|
|
441
|
-
yield* result.get(sessionID);
|
|
442
|
-
return yield* store.context(sessionID);
|
|
443
|
-
}),
|
|
444
|
-
inbox: Effect.fn("Session.inbox")(function* (sessionID) {
|
|
445
|
-
yield* result.get(sessionID);
|
|
446
|
-
return yield* exports_inbox.list(db, sessionID);
|
|
447
|
-
}),
|
|
448
|
-
cancelInbox: Effect.fn("Session.cancelInbox")((input) => mutatePending(input, exports_inbox.cancel)),
|
|
449
|
-
steerInbox: Effect.fn("Session.steerInbox")((input) => mutatePending(input, exports_inbox.steer, true)),
|
|
450
|
-
queueInbox: Effect.fn("Session.queueInbox")((input) => mutatePending(input, exports_inbox.queue)),
|
|
451
|
-
log: (input) => Stream.unwrap(result.get(input.sessionID).pipe(Effect.as(bus.log({ aggregateID: input.sessionID, after: input.after, follow: input.follow })))).pipe(Stream.filter((item) => exports_bus.isSynced(item) || isDurableSessionEvent(item))),
|
|
452
|
-
prompt: Effect.fn("Session.prompt")((input) => Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
|
|
453
|
-
const session = yield* result.get(input.sessionID);
|
|
454
|
-
const messageID = input.id ?? SessionMessage.ID.create();
|
|
455
|
-
const admitted = yield* Effect.gen(function* () {
|
|
456
|
-
const existing = yield* exports_inbox.reconcile(db, {
|
|
457
|
-
id: messageID,
|
|
458
|
-
sessionID: session.id,
|
|
459
|
-
delivery: input.delivery ?? "steer"
|
|
460
|
-
});
|
|
461
|
-
if (existing)
|
|
462
|
-
return existing;
|
|
463
|
-
const item = yield* restore(preparePrompt(input, messageID).pipe(Effect.provide(locations.get(session.location)), Effect.provideService(FSUtil.Service, fs)));
|
|
464
|
-
if (session.revert)
|
|
465
|
-
yield* exports_revert.commit(session).pipe(Effect.provideService(exports_bus.Service, bus));
|
|
466
|
-
return yield* exports_inbox.admit(db, bus, {
|
|
467
|
-
id: messageID,
|
|
468
|
-
sessionID: session.id,
|
|
469
|
-
item
|
|
470
|
-
});
|
|
471
|
-
}).pipe(Effect.catchDefect((defect) => defect instanceof exports_inbox.LifecycleConflict ? new PromptConflictError({ sessionID: input.sessionID, messageID }) : Effect.die(defect)));
|
|
472
|
-
if (admitted.type !== "user" || admitted.sessionID !== input.sessionID)
|
|
473
|
-
return yield* new PromptConflictError({ sessionID: input.sessionID, messageID });
|
|
474
|
-
if (input.resume !== false)
|
|
475
|
-
yield* execution.wake(admitted.sessionID);
|
|
476
|
-
return admitted;
|
|
477
|
-
}))),
|
|
478
|
-
generate: Effect.fn("Session.generate")(function* (input) {
|
|
479
|
-
const session = yield* result.get(input.sessionID);
|
|
480
|
-
const generate = yield* exports_generate.Service.pipe(Effect.provide(locations.get(session.location)));
|
|
481
|
-
return yield* generate.generate(input);
|
|
482
|
-
}),
|
|
483
|
-
command: Effect.fn("Session.command")(function* (input) {
|
|
484
|
-
const session = yield* result.get(input.sessionID);
|
|
485
|
-
const commands = yield* Effect.gen(function* () {
|
|
486
|
-
const plugins = yield* exports_supervisor_service.Service;
|
|
487
|
-
yield* plugins.flush;
|
|
488
|
-
return yield* exports_command.Service;
|
|
489
|
-
}).pipe(Effect.provide(locations.get(session.location)));
|
|
490
|
-
const delivery = input.delivery ?? "steer";
|
|
491
|
-
yield* commands.execute({
|
|
492
|
-
name: input.command,
|
|
493
|
-
invocation: {
|
|
494
|
-
sessionID: input.sessionID,
|
|
495
|
-
prompt: {
|
|
496
|
-
text: input.text,
|
|
497
|
-
files: input.files,
|
|
498
|
-
agents: input.agents,
|
|
499
|
-
skills: input.skills
|
|
500
|
-
},
|
|
501
|
-
delivery
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
}),
|
|
505
|
-
shell: Effect.fn("Session.shell")(function* (input) {
|
|
506
|
-
const session = yield* result.get(input.sessionID);
|
|
507
|
-
const running = yield* Effect.gen(function* () {
|
|
508
|
-
const shell = yield* Effect.gen(function* () {
|
|
509
|
-
const plugins = yield* exports_supervisor_service.Service;
|
|
510
|
-
yield* plugins.flush;
|
|
511
|
-
return yield* exports_shell.Service;
|
|
512
|
-
}).pipe(Effect.provide(locations.get(session.location)));
|
|
513
|
-
const started = yield* shell.create({
|
|
514
|
-
command: input.command,
|
|
515
|
-
cwd: session.location.directory,
|
|
516
|
-
timeout: 0,
|
|
517
|
-
metadata: { sessionID: input.sessionID, background: true }
|
|
518
|
-
}).pipe(Effect.tapError((error) => result.synthetic({
|
|
519
|
-
sessionID: input.sessionID,
|
|
520
|
-
text: `User shell command failed to start:
|
|
521
|
-
${input.command}
|
|
522
|
-
|
|
523
|
-
${error.message}`,
|
|
524
|
-
description: input.command,
|
|
525
|
-
metadata: { source: "shell", state: "error" },
|
|
526
|
-
resume: false
|
|
527
|
-
})), Effect.orDie);
|
|
528
|
-
yield* bus.publish(SessionEvent.Shell.Started, {
|
|
529
|
-
sessionID: input.sessionID,
|
|
530
|
-
shell: started
|
|
531
|
-
}, { id: input.id });
|
|
532
|
-
const terminal = yield* shell.result(started);
|
|
533
|
-
const preview = yield* shell.output(started.id, { limit: SHELL_MAX_CAPTURE_BYTES }).pipe(Effect.catchTag("Shell.NotFoundError", () => Effect.succeed(exports_result.unavailable)));
|
|
534
|
-
yield* bus.publish(SessionEvent.Shell.Ended, {
|
|
535
|
-
sessionID: input.sessionID,
|
|
536
|
-
shell: terminal.info,
|
|
537
|
-
output: preview
|
|
538
|
-
});
|
|
539
|
-
yield* result.synthetic({
|
|
540
|
-
...exports_result.userNotification(terminal),
|
|
541
|
-
sessionID: input.sessionID,
|
|
542
|
-
resume: false
|
|
543
|
-
}).pipe(Effect.catchTag("Session.NotFoundError", () => Effect.void), Effect.orDie);
|
|
544
|
-
}).pipe(Effect.forkIn(scope, { startImmediately: true }));
|
|
545
|
-
yield* Fiber.join(running);
|
|
546
|
-
}),
|
|
547
|
-
skill: Effect.fn("Session.skill")(function* (input) {
|
|
548
|
-
const session = yield* result.get(input.sessionID);
|
|
549
|
-
const skills = yield* exports_skill.Service.pipe(Effect.provide(locations.get(session.location)));
|
|
550
|
-
const skill = yield* skills.get(input.skill);
|
|
551
|
-
if (!skill)
|
|
552
|
-
return yield* new SkillNotFoundError({ skill: input.skill });
|
|
553
|
-
yield* bus.publish(SessionEvent.Skill.Activated, {
|
|
554
|
-
sessionID: input.sessionID,
|
|
555
|
-
id: skill.id,
|
|
556
|
-
name: skill.name,
|
|
557
|
-
text: skill.content
|
|
558
|
-
}, { id: input.id ? Event.ID.make(input.id.replace(/^msg_/, "evt_")) : undefined });
|
|
559
|
-
if (input.resume !== false)
|
|
560
|
-
yield* execution.resume(input.sessionID).pipe(Effect.ignore, Effect.forkIn(scope, { startImmediately: true }), Effect.asVoid);
|
|
561
|
-
}),
|
|
562
|
-
switchAgent: Effect.fn("Session.switchAgent")(function* (input) {
|
|
563
|
-
const session = yield* result.get(input.sessionID);
|
|
564
|
-
yield* bus.publish(SessionEvent.AgentSelected, {
|
|
565
|
-
sessionID: input.sessionID,
|
|
566
|
-
agent: input.agent,
|
|
567
|
-
previous: session.agent
|
|
568
|
-
});
|
|
569
|
-
}),
|
|
570
|
-
switchModel: Effect.fn("Session.switchModel")(function* (input) {
|
|
571
|
-
const session = yield* result.get(input.sessionID);
|
|
572
|
-
if (session.model?.providerID === input.model.providerID && session.model.id === input.model.id && (session.model.variant ?? "default") === (input.model.variant ?? "default"))
|
|
573
|
-
return;
|
|
574
|
-
yield* bus.publish(SessionEvent.ModelSelected, {
|
|
575
|
-
sessionID: input.sessionID,
|
|
576
|
-
model: input.model,
|
|
577
|
-
previous: session.model
|
|
578
|
-
});
|
|
579
|
-
}),
|
|
580
|
-
rename: Effect.fn("Session.rename")(function* (input) {
|
|
581
|
-
yield* result.get(input.sessionID);
|
|
582
|
-
yield* bus.publish(SessionEvent.Renamed, {
|
|
583
|
-
sessionID: input.sessionID,
|
|
584
|
-
title: input.title
|
|
585
|
-
});
|
|
586
|
-
}),
|
|
587
|
-
move: Effect.fn("Session.move")(function* (input) {
|
|
588
|
-
const current = yield* result.get(input.sessionID);
|
|
589
|
-
const value = input.directory.trim();
|
|
590
|
-
const expanded = value === "~" ? global.home : value.startsWith("~/") ? path.join(global.home, value.slice(2)) : value;
|
|
591
|
-
const directory = AbsolutePath.make(path.resolve(current.location.directory, expanded));
|
|
592
|
-
const info = yield* fs.stat(directory).pipe(Effect.orElseSucceed(() => {
|
|
593
|
-
return;
|
|
594
|
-
}));
|
|
595
|
-
if (!info)
|
|
596
|
-
return yield* new DestinationNotFoundError({ directory });
|
|
597
|
-
if (info.type !== "Directory")
|
|
598
|
-
return yield* new DestinationNotDirectoryError({ directory });
|
|
599
|
-
const project = yield* projects.resolve(directory);
|
|
600
|
-
const payload = {
|
|
601
|
-
location: exports_location.Ref.make({ directory, workspaceID: input.workspaceID }),
|
|
602
|
-
projectID: project.id,
|
|
603
|
-
subpath: RelativePath.make(path.relative(project.directory, directory).replaceAll("\\", "/"))
|
|
604
|
-
};
|
|
605
|
-
yield* exports_location.Service.pipe(Effect.provide(locations.get(payload.location)), Effect.scoped, Effect.catchCause((cause) => {
|
|
606
|
-
if (Cause.hasInterruptsOnly(cause))
|
|
607
|
-
return Effect.failCause(cause);
|
|
608
|
-
return Effect.logWarning("session move destination unavailable", { directory, cause }).pipe(Effect.andThen(Effect.fail(new DestinationUnavailableError({ directory }))));
|
|
609
|
-
}));
|
|
610
|
-
yield* persistProject(project);
|
|
611
|
-
const item = exports_inbox.Item.make({
|
|
612
|
-
type: "move",
|
|
613
|
-
payload,
|
|
614
|
-
delivery: input.delivery ?? "steer"
|
|
615
|
-
});
|
|
616
|
-
yield* exports_inbox.serialized(input.sessionID, Effect.gen(function* () {
|
|
617
|
-
const latest = yield* result.get(input.sessionID);
|
|
618
|
-
const source = yield* fs.stat(latest.location.directory).pipe(Effect.orElseSucceed(() => {
|
|
619
|
-
return;
|
|
620
|
-
}));
|
|
621
|
-
if (!source || source.type !== "Directory") {
|
|
622
|
-
const cancellations = (yield* exports_inbox.moveIDs(db, input.sessionID)).map((item2) => [SessionEvent.InboxCancelled, { sessionID: input.sessionID, inboxID: item2.id }]);
|
|
623
|
-
const moved = [SessionEvent.Moved, { sessionID: input.sessionID, ...payload }];
|
|
624
|
-
const first = cancellations[0];
|
|
625
|
-
if (!first)
|
|
626
|
-
return yield* bus.publish(...moved).pipe(Effect.asVoid);
|
|
627
|
-
return yield* bus.publishAll([first, ...cancellations.slice(1), moved]);
|
|
628
|
-
}
|
|
629
|
-
yield* exports_inbox.admit(db, bus, {
|
|
630
|
-
id: SessionMessage.ID.create(),
|
|
631
|
-
sessionID: input.sessionID,
|
|
632
|
-
item
|
|
633
|
-
});
|
|
634
|
-
}));
|
|
635
|
-
yield* execution.wake(input.sessionID);
|
|
636
|
-
}),
|
|
637
|
-
compact: Effect.fn("Session.compact")(function* (input) {
|
|
638
|
-
yield* result.get(input.sessionID);
|
|
639
|
-
const inputID = input.id ?? SessionMessage.ID.create();
|
|
640
|
-
const admitted = yield* exports_inbox.admitCompaction(db, bus, {
|
|
641
|
-
id: inputID,
|
|
642
|
-
sessionID: input.sessionID,
|
|
643
|
-
delivery: input.delivery ?? "steer"
|
|
644
|
-
}).pipe(Effect.catchDefect((defect) => defect instanceof exports_inbox.LifecycleConflict ? new CompactionConflictError({ sessionID: input.sessionID, inputID }) : Effect.die(defect)));
|
|
645
|
-
yield* execution.wake(input.sessionID);
|
|
646
|
-
return admitted;
|
|
647
|
-
}),
|
|
648
|
-
wait: Effect.fn("Session.wait")(function* (sessionID) {
|
|
649
|
-
yield* result.get(sessionID);
|
|
650
|
-
yield* execution.awaitIdle(sessionID);
|
|
651
|
-
}),
|
|
652
|
-
active: execution.active,
|
|
653
|
-
background: Effect.fn("Session.background")(function* (sessionID) {
|
|
654
|
-
yield* result.get(sessionID);
|
|
655
|
-
const backgrounded = yield* jobs.backgroundAll({ sessionID });
|
|
656
|
-
if (backgrounded.length === 0)
|
|
657
|
-
return;
|
|
658
|
-
yield* result.synthetic({
|
|
659
|
-
sessionID,
|
|
660
|
-
text: [
|
|
661
|
-
"User requested that active blocking work be moved to the background.",
|
|
662
|
-
"",
|
|
663
|
-
"Backgrounded work:",
|
|
664
|
-
...backgrounded.map((job) => `- ${job.type}: ${job.title && job.title.length > 0 ? job.title : job.id}`),
|
|
665
|
-
"",
|
|
666
|
-
"The backgrounded work is still unfinished. Move on to other work if you can. If there is nothing else useful to do, finish your response. Do not wait, sleep, poll, or report the backgrounded work as complete until a later completion notification is added to the conversation."
|
|
667
|
-
].join(`
|
|
668
|
-
`)
|
|
669
|
-
}).pipe(Effect.catchTag("Session.SyntheticConflictError", Effect.die));
|
|
670
|
-
}),
|
|
671
|
-
resume: Effect.fn("Session.resume")(function* (sessionID) {
|
|
672
|
-
yield* result.get(sessionID);
|
|
673
|
-
yield* execution.resume(sessionID);
|
|
674
|
-
}),
|
|
675
|
-
synthetic: Effect.fn("Session.synthetic")((input) => Effect.uninterruptible(Effect.gen(function* () {
|
|
676
|
-
yield* result.get(input.sessionID);
|
|
677
|
-
const inputID = input.id ?? SessionMessage.ID.create();
|
|
678
|
-
const admittedInput = exports_inbox.Item.make({
|
|
679
|
-
type: "synthetic",
|
|
680
|
-
payload: {
|
|
681
|
-
text: input.text,
|
|
682
|
-
description: input.description,
|
|
683
|
-
metadata: input.metadata
|
|
684
|
-
},
|
|
685
|
-
delivery: input.delivery ?? "steer"
|
|
686
|
-
});
|
|
687
|
-
const admitted = yield* exports_inbox.admit(db, bus, {
|
|
688
|
-
id: inputID,
|
|
689
|
-
sessionID: input.sessionID,
|
|
690
|
-
item: admittedInput
|
|
691
|
-
}).pipe(Effect.catchDefect((defect) => defect instanceof exports_inbox.LifecycleConflict ? new SyntheticConflictError({ sessionID: input.sessionID, inputID }) : Effect.die(defect)));
|
|
692
|
-
if (admitted.type !== "synthetic" || admitted.sessionID !== input.sessionID)
|
|
693
|
-
return yield* new SyntheticConflictError({ sessionID: input.sessionID, inputID });
|
|
694
|
-
if (input.resume !== false && !(yield* result.get(input.sessionID)).revert)
|
|
695
|
-
yield* execution.wake(input.sessionID);
|
|
696
|
-
return admitted;
|
|
697
|
-
}))),
|
|
698
|
-
interrupt: Effect.fn("Session.interrupt")((sessionID, options) => Effect.uninterruptible(execution.interrupt(sessionID, options))),
|
|
699
|
-
revert: {
|
|
700
|
-
stage: Effect.fn("Session.revert.stage")(function* (input) {
|
|
701
|
-
const session = yield* result.get(input.sessionID);
|
|
702
|
-
if ((yield* execution.active).has(input.sessionID))
|
|
703
|
-
return yield* new BusyError({ sessionID: input.sessionID });
|
|
704
|
-
return yield* Effect.gen(function* () {
|
|
705
|
-
const plugins = yield* exports_supervisor_service.Service;
|
|
706
|
-
yield* plugins.flush;
|
|
707
|
-
return yield* exports_revert.stage({ session, messageID: input.messageID, files: input.files }).pipe(Effect.provideService(exports_database.Service, database), Effect.provideService(exports_bus.Service, bus));
|
|
708
|
-
}).pipe(Effect.provide(locations.get(session.location)));
|
|
709
|
-
}),
|
|
710
|
-
clear: Effect.fn("Session.revert.clear")(function* (sessionID) {
|
|
711
|
-
const session = yield* result.get(sessionID);
|
|
712
|
-
if ((yield* execution.active).has(sessionID))
|
|
713
|
-
return yield* new BusyError({ sessionID });
|
|
714
|
-
const revert = yield* Effect.gen(function* () {
|
|
715
|
-
const plugins = yield* exports_supervisor_service.Service;
|
|
716
|
-
yield* plugins.flush;
|
|
717
|
-
return yield* exports_revert.clear(session).pipe(Effect.provideService(exports_bus.Service, bus));
|
|
718
|
-
}).pipe(Effect.provide(locations.get(session.location)));
|
|
719
|
-
yield* execution.wake(sessionID);
|
|
720
|
-
return revert;
|
|
721
|
-
}),
|
|
722
|
-
commit: Effect.fn("Session.revert.commit")(function* (sessionID) {
|
|
723
|
-
const session = yield* result.get(sessionID);
|
|
724
|
-
if ((yield* execution.active).has(sessionID))
|
|
725
|
-
return yield* new BusyError({ sessionID });
|
|
726
|
-
return yield* exports_revert.commit(session).pipe(Effect.provideService(exports_bus.Service, bus));
|
|
727
|
-
})
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
return result;
|
|
731
|
-
}));
|
|
732
|
-
var preparePrompt = Effect.fn("Session.preparePrompt")(function* (request, messageID) {
|
|
733
|
-
const plugins = yield* exports_supervisor_service.Service;
|
|
734
|
-
yield* plugins.flush;
|
|
735
|
-
const hooks = yield* exports_hooks.Service;
|
|
736
|
-
const event = yield* hooks.trigger("session", "prompt", {
|
|
737
|
-
sessionID: request.sessionID,
|
|
738
|
-
messageID,
|
|
739
|
-
prompt: structuredClone({
|
|
740
|
-
text: request.text,
|
|
741
|
-
files: request.files?.slice(),
|
|
742
|
-
agents: request.agents?.slice(),
|
|
743
|
-
skills: request.skills?.slice()
|
|
744
|
-
}),
|
|
745
|
-
metadata: structuredClone(request.metadata),
|
|
746
|
-
delivery: request.delivery ?? "steer"
|
|
747
|
-
});
|
|
748
|
-
const input = event.prompt;
|
|
749
|
-
const fs = yield* FSUtil.Service;
|
|
750
|
-
const files = input.files ? yield* Effect.forEach(input.files, (file) => materializeAttachment(fs, file), { concurrency: 8 }) : undefined;
|
|
751
|
-
const requested = input.skills;
|
|
752
|
-
const selected = yield* Effect.gen(function* () {
|
|
753
|
-
if (!requested?.length)
|
|
754
|
-
return;
|
|
755
|
-
const skillService = yield* exports_skill.Service;
|
|
756
|
-
const prepared = new Map;
|
|
757
|
-
return yield* Effect.forEach(requested, (attachment) => Effect.gen(function* () {
|
|
758
|
-
const name = prepared.get(attachment.id);
|
|
759
|
-
if (name !== undefined)
|
|
760
|
-
return { id: attachment.id, name, mention: attachment.mention };
|
|
761
|
-
const skill = yield* skillService.get(attachment.id);
|
|
762
|
-
if (!skill)
|
|
763
|
-
return yield* new SkillNotFoundError({ skill: attachment.id });
|
|
764
|
-
prepared.set(skill.id, skill.name);
|
|
765
|
-
return {
|
|
766
|
-
id: skill.id,
|
|
767
|
-
name: skill.name,
|
|
768
|
-
text: (yield* exports_skill.prepare(fs, skill).pipe(Effect.orDie)).output,
|
|
769
|
-
mention: attachment.mention
|
|
770
|
-
};
|
|
771
|
-
}));
|
|
772
|
-
});
|
|
773
|
-
return exports_inbox.Item.make({
|
|
774
|
-
type: "user",
|
|
775
|
-
payload: {
|
|
776
|
-
...Prompt.make({
|
|
777
|
-
text: input.text,
|
|
778
|
-
agents: input.agents,
|
|
779
|
-
files,
|
|
780
|
-
skills: selected?.length ? selected : undefined
|
|
781
|
-
}),
|
|
782
|
-
metadata: event.metadata
|
|
783
|
-
},
|
|
784
|
-
delivery: event.delivery
|
|
785
|
-
});
|
|
786
|
-
});
|
|
787
|
-
var MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
788
|
-
var materializeAttachment = Effect.fn("Session.materializeAttachment")(function* (fs, input) {
|
|
789
|
-
const resolved = input.uri.startsWith("data:") ? {
|
|
790
|
-
bytes: yield* decodeDataURL(input.uri),
|
|
791
|
-
source: { type: "inline" },
|
|
792
|
-
start: undefined,
|
|
793
|
-
end: undefined,
|
|
794
|
-
name: undefined,
|
|
795
|
-
mime: undefined
|
|
796
|
-
} : yield* readFileAttachment(fs, input.uri);
|
|
797
|
-
if (resolved.bytes.byteLength > MAX_ATTACHMENT_BYTES)
|
|
798
|
-
return yield* new AttachmentError({
|
|
799
|
-
uri: input.uri,
|
|
800
|
-
message: `Attachment exceeds the ${MAX_ATTACHMENT_BYTES} byte limit: ${input.uri}`
|
|
801
|
-
});
|
|
802
|
-
const mime = resolved.mime ?? exports_mime.detect(resolved.bytes);
|
|
803
|
-
const content = mime === "text/plain" && resolved.start !== undefined ? Buffer.from(Buffer.from(resolved.bytes).toString("utf8").split(`
|
|
804
|
-
`).slice(resolved.start - 1, resolved.end).join(`
|
|
805
|
-
`)) : resolved.bytes;
|
|
806
|
-
const normalized = yield* normalizeImageAttachment(input, Buffer.from(content).toString("base64"), mime);
|
|
807
|
-
return FileAttachment.create({
|
|
808
|
-
data: normalized.data,
|
|
809
|
-
mime: normalized.mime,
|
|
810
|
-
source: resolved.source,
|
|
811
|
-
name: input.name ?? resolved.name,
|
|
812
|
-
description: input.description,
|
|
813
|
-
mention: input.mention
|
|
814
|
-
});
|
|
815
|
-
});
|
|
816
|
-
var normalizeImageAttachment = Effect.fn("Session.normalizeImageAttachment")(function* (input, data, mime) {
|
|
817
|
-
if (!mime.startsWith("image/"))
|
|
818
|
-
return { data: Base64.make(data), mime };
|
|
819
|
-
const service = yield* exports_image.Service;
|
|
820
|
-
const label = input.name ?? (input.uri.startsWith("data:") ? "inline attachment" : input.uri);
|
|
821
|
-
const content = { uri: label, content: data, encoding: "base64", mime };
|
|
822
|
-
const normalized = yield* service.normalize(label, content).pipe(Effect.catchTag("Image.ResizerUnavailableError", () => Effect.succeed(content)), Effect.mapError((error) => new AttachmentError({ uri: label, message: error.message })));
|
|
823
|
-
return { data: Base64.make(normalized.content), mime: normalized.mime };
|
|
824
|
-
});
|
|
825
|
-
var readFileAttachment = Effect.fn("Session.readFileAttachment")(function* (fs, uri) {
|
|
826
|
-
const url = yield* Effect.try({
|
|
827
|
-
try: () => new URL(uri),
|
|
828
|
-
catch: () => new AttachmentError({ uri, message: `Invalid attachment URI: ${uri}` })
|
|
829
|
-
});
|
|
830
|
-
if (url.protocol !== "file:")
|
|
831
|
-
return yield* new AttachmentError({ uri, message: `Unsupported attachment URI: ${uri}` });
|
|
832
|
-
const start = positiveInt(url.searchParams.get("start"));
|
|
833
|
-
const end = positiveInt(url.searchParams.get("end"));
|
|
834
|
-
const target = yield* Effect.try({
|
|
835
|
-
try: () => {
|
|
836
|
-
url.search = "";
|
|
837
|
-
url.hash = "";
|
|
838
|
-
return fileURLToPath(url);
|
|
839
|
-
},
|
|
840
|
-
catch: () => new AttachmentError({ uri, message: `Invalid file URI: ${uri}` })
|
|
841
|
-
});
|
|
842
|
-
const info = yield* fs.stat(target).pipe(Effect.mapError(() => new AttachmentError({ uri, message: `Unable to read attachment: ${uri}` })));
|
|
843
|
-
if (info.type === "Directory") {
|
|
844
|
-
const entries = yield* fs.readDirectoryEntries(target).pipe(Effect.mapError(() => new AttachmentError({ uri, message: `Unable to read attachment: ${uri}` })));
|
|
845
|
-
return {
|
|
846
|
-
bytes: Buffer.from(entries.filter((entry) => entry.type === "file" || entry.type === "directory").sort((a, b) => a.type === b.type ? a.name.localeCompare(b.name) : a.type === "directory" ? -1 : 1).map((entry) => entry.name + (entry.type === "directory" ? path.sep : "")).join(`
|
|
847
|
-
`)),
|
|
848
|
-
source: { type: "uri", uri },
|
|
849
|
-
start: undefined,
|
|
850
|
-
end: undefined,
|
|
851
|
-
name: path.basename(target),
|
|
852
|
-
mime: "application/x-directory"
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
if (info.type !== "File")
|
|
856
|
-
return yield* new AttachmentError({ uri, message: `Attachment is not a file: ${uri}` });
|
|
857
|
-
if (Number(info.size) > MAX_ATTACHMENT_BYTES)
|
|
858
|
-
return yield* new AttachmentError({
|
|
859
|
-
uri,
|
|
860
|
-
message: `Attachment exceeds the ${MAX_ATTACHMENT_BYTES} byte limit: ${uri}`
|
|
861
|
-
});
|
|
862
|
-
const bytes = yield* fs.readFile(target).pipe(Effect.mapError(() => new AttachmentError({ uri, message: `Unable to read attachment: ${uri}` })));
|
|
863
|
-
return { bytes, source: { type: "uri", uri }, start, end, name: path.basename(target), mime: undefined };
|
|
864
|
-
});
|
|
865
|
-
function decodeDataURL(uri) {
|
|
866
|
-
return Effect.try({
|
|
867
|
-
try: () => {
|
|
868
|
-
const comma = uri.indexOf(",");
|
|
869
|
-
if (comma === -1)
|
|
870
|
-
throw new Error("Invalid data URL");
|
|
871
|
-
const metadata = uri.slice(5, comma);
|
|
872
|
-
const payload = uri.slice(comma + 1);
|
|
873
|
-
if (!metadata.split(";").some((part) => part.toLowerCase() === "base64"))
|
|
874
|
-
return Buffer.from(decodeURIComponent(payload));
|
|
875
|
-
const bytes = Buffer.from(payload, "base64");
|
|
876
|
-
if (bytes.toString("base64") !== payload)
|
|
877
|
-
throw new Error("Non-canonical base64");
|
|
878
|
-
return bytes;
|
|
879
|
-
},
|
|
880
|
-
catch: () => new AttachmentError({ uri, message: "Invalid attachment data URL" })
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
function positiveInt(value) {
|
|
884
|
-
if (value === null)
|
|
885
|
-
return;
|
|
886
|
-
const parsed = Number(value);
|
|
887
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
888
|
-
}
|
|
889
|
-
var SHELL_MAX_CAPTURE_BYTES = 1024 * 1024;
|
|
890
|
-
var node = makeGlobalNode({
|
|
891
|
-
service: Service,
|
|
892
|
-
layer,
|
|
893
|
-
deps: [
|
|
894
|
-
exports_job.node,
|
|
895
|
-
exports_environment.node,
|
|
896
|
-
exports_database.node,
|
|
897
|
-
exports_bus.node,
|
|
898
|
-
exports_project.node,
|
|
899
|
-
exports_execution.node,
|
|
900
|
-
exports_store.node,
|
|
901
|
-
exports_location_service_map.node,
|
|
902
|
-
exports_projector.node,
|
|
903
|
-
FSUtil.node,
|
|
904
|
-
Global.node,
|
|
905
|
-
exports_app.node
|
|
906
|
-
]
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
export { ListAnchor, ListInput, PromptConflictError, SyntheticConflictError, AttachmentError, CompactionConflictError, BusyError, MessageNotAssistantError, MessageIncompleteError, MessageToolIncompleteError, InboxConflictError, SkillNotFoundError, DestinationNotFoundError, DestinationNotDirectoryError, DestinationUnavailableError, MessageNotFoundError, Service, node, exports_session };
|