@zhivex-ai/harness 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +17 -5
- package/SECURITY.md +1 -1
- package/SUPPORT.md +2 -2
- package/benchmarks/README.md +26 -0
- package/contracts/engine-api.json +1557 -0
- package/contracts/public-api.json +114 -0
- package/contracts/stable-api-signatures.json +17 -17
- package/dist/acp-cli.js +37 -1090
- package/dist/application/agenda.d.ts +10 -0
- package/dist/application/approval-review.d.ts +61 -0
- package/dist/application/assistant/automation/scheduler.d.ts +21 -0
- package/dist/application/assistant/automation/summary.d.ts +29 -0
- package/dist/application/assistant/automation/time.d.ts +10 -0
- package/dist/application/assistant/calendar/calendar.d.ts +238 -0
- package/dist/application/assistant/calendar/connection.d.ts +50 -0
- package/dist/application/assistant/calendar/create-event.d.ts +75 -0
- package/dist/application/assistant/calendar/environment.d.ts +2 -0
- package/dist/application/assistant/calendar/http.d.ts +6 -0
- package/dist/application/assistant/calendar/oauth.d.ts +68 -0
- package/dist/application/assistant/calendar/store.d.ts +11 -0
- package/dist/application/assistant/calendar/tools.d.ts +78 -0
- package/dist/application/assistant/client.d.ts +10 -0
- package/dist/application/assistant/config.d.ts +9 -0
- package/dist/application/assistant/contracts.d.ts +77 -0
- package/dist/application/assistant/daily/service.d.ts +181 -0
- package/dist/application/assistant/doctor.d.ts +22 -0
- package/dist/application/assistant/evaluation.d.ts +81 -0
- package/dist/application/assistant/host.d.ts +399 -0
- package/dist/application/assistant/integrations/google.d.ts +117 -0
- package/dist/application/assistant/integrations/public-web.d.ts +16 -0
- package/dist/application/assistant/managed/secrets.d.ts +10 -0
- package/dist/application/assistant/managed/setup-state.d.ts +346 -0
- package/dist/application/assistant/managed/setup.d.ts +492 -0
- package/dist/application/assistant/microsoft/connection.d.ts +73 -0
- package/dist/application/assistant/microsoft/tools.d.ts +78 -0
- package/dist/application/assistant/modules/calendar.d.ts +3 -0
- package/dist/application/assistant/modules/catalog.d.ts +38 -0
- package/dist/application/assistant/modules/daily.d.ts +5 -0
- package/dist/application/assistant/modules/github.d.ts +5 -0
- package/dist/application/assistant/modules/google.d.ts +3 -0
- package/dist/application/assistant/modules/mcp.d.ts +11 -0
- package/dist/application/assistant/modules/microsoft.d.ts +3 -0
- package/dist/application/assistant/modules/module.d.ts +224 -0
- package/dist/application/assistant/modules/tools.d.ts +11 -0
- package/dist/application/assistant/modules/web.d.ts +7 -0
- package/dist/application/assistant/private-directory.d.ts +3 -0
- package/dist/application/assistant/proactive/service.d.ts +142 -0
- package/dist/application/assistant/providers/openai-compatible.d.ts +66 -0
- package/dist/application/assistant/providers/provider.d.ts +141 -0
- package/dist/application/assistant/providers/web-citations.d.ts +2 -0
- package/dist/application/assistant/runtime.d.ts +16 -0
- package/dist/application/assistant/task-metrics.d.ts +304 -0
- package/dist/application/assistant/telegram/api.d.ts +47 -0
- package/dist/application/assistant/telegram/bridge.d.ts +69 -0
- package/dist/application/assistant/telegram/store.d.ts +10 -0
- package/dist/application/automation.d.ts +5 -0
- package/dist/application/calendar-review.d.ts +5 -0
- package/dist/application/checkpoint-review.d.ts +30 -0
- package/dist/application/client.d.ts +18 -0
- package/dist/application/code/context.d.ts +5 -0
- package/dist/application/code/delivery.d.ts +6 -0
- package/dist/application/code/git-delivery.d.ts +54 -0
- package/dist/application/code/github-git-transport.d.ts +15 -0
- package/dist/application/code/github-pr-transport.d.ts +6 -0
- package/dist/application/code/host.d.ts +25 -0
- package/dist/application/code/pr-delivery.d.ts +79 -0
- package/dist/application/code/projects.d.ts +90 -0
- package/dist/application/code/remote-delivery.d.ts +80 -0
- package/dist/application/code/repository.d.ts +9 -0
- package/dist/application/code/worktrees.d.ts +123 -0
- package/dist/application/contracts.d.ts +288 -0
- package/dist/application/coordinator-client.d.ts +33 -0
- package/dist/application/coordinator-discovery.d.ts +17 -0
- package/dist/application/coordinator-launcher.d.ts +2 -0
- package/dist/application/coordinator.d.ts +27 -0
- package/dist/application/credential-process.d.ts +13 -0
- package/dist/application/host.d.ts +7 -0
- package/dist/application/management.d.ts +68 -0
- package/dist/application/notes.d.ts +5 -0
- package/dist/application/offline-migration.d.ts +16 -0
- package/dist/application/personal-state.d.ts +5 -0
- package/dist/application/review-channel.d.ts +23 -0
- package/dist/application/review-tickets.d.ts +29 -0
- package/dist/application/runtime-binding.d.ts +4 -0
- package/dist/application-cli-wfh08g41.js +184 -0
- package/dist/application-cli-z3f9pvcf.js +209 -0
- package/dist/approvals/auto-approve.d.ts +1 -1
- package/dist/arguments-75r85mvc.js +27 -0
- package/dist/arguments-x24bbqvd.js +22 -0
- package/dist/audit/index.js +16 -472
- package/dist/audit-pack-1gnych0m.js +93 -0
- package/dist/{audit-pack-y02n8zd0.js → audit-pack-h44kjkbj.js} +17 -11
- package/dist/calendar-2xw0rr7b.js +49 -0
- package/dist/cli/application-cli.d.ts +2 -0
- package/dist/cli/arguments.d.ts +14 -1
- package/dist/cli/auto-approve-setup.d.ts +13 -0
- package/dist/cli/configured-harness.d.ts +1 -2
- package/dist/cli/console/console-budget.d.ts +16 -2
- package/dist/cli/console/console-checkpoints.d.ts +12 -0
- package/dist/cli/console/console-commands.d.ts +3 -3
- package/dist/cli/console/console-compaction.d.ts +1 -1
- package/dist/cli/console/console-diff.d.ts +2 -0
- package/dist/cli/console/console-input.d.ts +29 -1
- package/dist/cli/console/console-navigation.d.ts +2 -2
- package/dist/cli/console/console-outcome.d.ts +10 -0
- package/dist/cli/console/console-presentation.d.ts +17 -2
- package/dist/cli/console/console-pricing.d.ts +14 -0
- package/dist/cli/console/console-reasoning.d.ts +1 -1
- package/dist/cli/console/console-recovery.d.ts +2 -0
- package/dist/cli/console/console-review.d.ts +34 -0
- package/dist/cli/console/console-run-policy.d.ts +5 -0
- package/dist/cli/console/console-run-view.d.ts +28 -0
- package/dist/cli/console/console-task.d.ts +30 -0
- package/dist/cli/console/console-welcome.d.ts +13 -3
- package/dist/cli/console/review-diff.d.ts +20 -0
- package/dist/cli/presentation.d.ts +8 -6
- package/dist/cli/service-checkpoints.d.ts +234 -0
- package/dist/cli/terminal/activity-history.d.ts +4 -2
- package/dist/cli/terminal/activity-stream.d.ts +33 -0
- package/dist/cli/terminal/file-diff.d.ts +11 -0
- package/dist/cli/terminal/terminal-theme.d.ts +9 -0
- package/dist/cli/terminal/terminal-ui.d.ts +44 -2
- package/dist/cli/terminal/tool-activity.d.ts +6 -2
- package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
- package/dist/{cli-entry-j6jcb2jb.js → cli-entry-86rcbmwh.js} +294 -14
- package/dist/cli-entry-btkpb4h1.js +3627 -0
- package/dist/cli-entry-bxjbs6qq.js +200 -0
- package/dist/cli-entry-cpm89r9q.js +624 -0
- package/dist/{cli-entry-v5db3eb2.js → cli-entry-dksm56sj.js} +39 -297
- package/dist/{cli-entry-td04s0fa.js → cli-entry-eka68ttb.js} +3919 -4549
- package/dist/cli-entry-h7dcah4p.js +137 -0
- package/dist/cli-entry-kwk23ktq.js +33 -0
- package/dist/{cli-entry-ynahz9qc.js → cli-entry-vmce694z.js} +1251 -3139
- package/dist/cli-entry-wanv05db.js +1113 -0
- package/dist/{cli-zw18kdqx.js → cli-z7vhm1rk.js} +1767 -380
- package/dist/cli.js +8 -6
- package/dist/client/json-contracts.d.ts +153 -0
- package/dist/client/local-service.d.ts +7 -12
- package/dist/client/local-transport.d.ts +14 -0
- package/dist/client/protocol.d.ts +43 -1
- package/dist/compat/cli-options.d.ts +7 -1
- package/dist/compat/cli.d.ts +2 -0
- package/dist/compat/cli.js +4043 -0
- package/dist/compat/code-support.d.ts +3 -0
- package/dist/compat/code-support.js +50 -28
- package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
- package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
- package/dist/context/adaptive-compaction.d.ts +1 -0
- package/dist/context/lossless-lines.d.ts +13 -0
- package/dist/context/numbered-read-lines.d.ts +15 -0
- package/dist/context/read-attempts.d.ts +21 -0
- package/dist/context/request-projection.d.ts +32 -4
- package/dist/context/scoped-context.d.ts +14 -0
- package/dist/context/working-read-replay.d.ts +12 -0
- package/dist/coordinator-client-nzysqxf0.js +10 -0
- package/dist/engine/acp.js +27 -21
- package/dist/engine/application-client.d.ts +11 -0
- package/dist/engine/application-client.js +18 -0
- package/dist/engine/application-protocol.d.ts +5 -0
- package/dist/engine/application-protocol.js +7 -0
- package/dist/engine/application.d.ts +43 -0
- package/dist/engine/application.js +206 -0
- package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
- package/dist/engine/assistant/automation/scheduler.js +11 -0
- package/dist/engine/assistant/automation/summary.d.ts +3 -0
- package/dist/engine/assistant/automation/summary.js +8 -0
- package/dist/engine/assistant/automation/time.d.ts +5 -0
- package/dist/engine/assistant/automation/time.js +15 -0
- package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
- package/dist/engine/assistant/calendar/calendar.js +12 -0
- package/dist/engine/assistant/calendar/connection.d.ts +2 -0
- package/dist/engine/assistant/calendar/connection.js +11 -0
- package/dist/engine/assistant/calendar/environment.d.ts +1 -0
- package/dist/engine/assistant/calendar/environment.js +7 -0
- package/dist/engine/assistant/calendar/http.d.ts +3 -0
- package/dist/engine/assistant/calendar/http.js +9 -0
- package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
- package/dist/engine/assistant/calendar/oauth.js +12 -0
- package/dist/engine/assistant/calendar/store.d.ts +2 -0
- package/dist/engine/assistant/calendar/store.js +8 -0
- package/dist/engine/assistant/calendar/tools.d.ts +2 -0
- package/dist/engine/assistant/calendar/tools.js +46 -0
- package/dist/engine/assistant/client.d.ts +2 -0
- package/dist/engine/assistant/client.js +33 -0
- package/dist/engine/assistant/config.d.ts +1 -0
- package/dist/engine/assistant/config.js +102 -0
- package/dist/engine/assistant/contracts.d.ts +10 -0
- package/dist/engine/assistant/contracts.js +78 -0
- package/dist/engine/assistant/daily/service.d.ts +12 -0
- package/dist/engine/assistant/daily/service.js +27 -0
- package/dist/engine/assistant/doctor.d.ts +1 -0
- package/dist/engine/assistant/doctor.js +116 -0
- package/dist/engine/assistant/evaluation.d.ts +2 -0
- package/dist/engine/assistant/evaluation.js +76 -0
- package/dist/engine/assistant/host.d.ts +2 -0
- package/dist/engine/assistant/host.js +63 -0
- package/dist/engine/assistant/integrations/google.d.ts +9 -0
- package/dist/engine/assistant/integrations/google.js +30 -0
- package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
- package/dist/engine/assistant/integrations/public-web.js +11 -0
- package/dist/engine/assistant/managed/secrets.d.ts +1 -0
- package/dist/engine/assistant/managed/secrets.js +0 -0
- package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
- package/dist/engine/assistant/managed/setup-state.js +84 -0
- package/dist/engine/assistant/managed/setup.d.ts +3 -0
- package/dist/engine/assistant/managed/setup.js +85 -0
- package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
- package/dist/engine/assistant/microsoft/connection.js +21 -0
- package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
- package/dist/engine/assistant/microsoft/tools.js +30 -0
- package/dist/engine/assistant/modules/calendar.d.ts +1 -0
- package/dist/engine/assistant/modules/calendar.js +49 -0
- package/dist/engine/assistant/modules/catalog.d.ts +3 -0
- package/dist/engine/assistant/modules/catalog.js +67 -0
- package/dist/engine/assistant/modules/daily.d.ts +1 -0
- package/dist/engine/assistant/modules/daily.js +48 -0
- package/dist/engine/assistant/modules/github.d.ts +1 -0
- package/dist/engine/assistant/modules/github.js +43 -0
- package/dist/engine/assistant/modules/google.d.ts +1 -0
- package/dist/engine/assistant/modules/google.js +53 -0
- package/dist/engine/assistant/modules/mcp.d.ts +1 -0
- package/dist/engine/assistant/modules/mcp.js +42 -0
- package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
- package/dist/engine/assistant/modules/microsoft.js +53 -0
- package/dist/engine/assistant/modules/module.d.ts +5 -0
- package/dist/engine/assistant/modules/module.js +42 -0
- package/dist/engine/assistant/modules/tools.d.ts +2 -0
- package/dist/engine/assistant/modules/tools.js +42 -0
- package/dist/engine/assistant/modules/web.d.ts +1 -0
- package/dist/engine/assistant/modules/web.js +45 -0
- package/dist/engine/assistant/private-directory.d.ts +1 -0
- package/dist/engine/assistant/private-directory.js +7 -0
- package/dist/engine/assistant/proactive/service.d.ts +6 -0
- package/dist/engine/assistant/proactive/service.js +16 -0
- package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
- package/dist/engine/assistant/providers/openai-compatible.js +12 -0
- package/dist/engine/assistant/providers/provider.d.ts +7 -0
- package/dist/engine/assistant/providers/provider.js +54 -0
- package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
- package/dist/engine/assistant/providers/web-citations.js +7 -0
- package/dist/engine/assistant/runtime.d.ts +2 -0
- package/dist/engine/assistant/runtime.js +73 -0
- package/dist/engine/assistant/task-metrics.d.ts +8 -0
- package/dist/engine/assistant/task-metrics.js +17 -0
- package/dist/engine/assistant/telegram/api.d.ts +5 -0
- package/dist/engine/assistant/telegram/api.js +11 -0
- package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
- package/dist/engine/assistant/telegram/bridge.js +40 -0
- package/dist/engine/assistant/telegram/store.d.ts +2 -0
- package/dist/engine/assistant/telegram/store.js +8 -0
- package/dist/engine/client.js +26 -18
- package/dist/engine/desktop-providers-v1.js +4 -4
- package/dist/engine/desktop-state-v1.js +16 -13
- package/dist/engine/index.js +111 -159
- package/dist/engine/mcp-stdio-v1.js +13 -12
- package/dist/engine/models.js +65 -23
- package/dist/engine/protocol.js +10 -6
- package/dist/engine/service.js +32 -21
- package/dist/hostile-repository-demo.js +1822 -696
- package/dist/index-09rsdr2d.js +1744 -0
- package/dist/index-0csc5sc7.js +139 -0
- package/dist/{index-v86bh0eg.js → index-0dkty795.js} +8 -6
- package/dist/index-0kkgqvg7.js +0 -0
- package/dist/index-0mzz9axm.js +58 -0
- package/dist/index-1e69ar8r.js +38 -0
- package/dist/index-1z0xhkh9.js +18 -0
- package/dist/index-2cef1k92.js +356 -0
- package/dist/{index-k1a1xesg.js → index-2j0v1xwr.js} +17 -13
- package/dist/index-2jw9jd7h.js +116 -0
- package/dist/index-2n9qx4km.js +0 -0
- package/dist/index-3rvk23e8.js +877 -0
- package/dist/index-3wa4j0yk.js +71 -0
- package/dist/index-41q1k17x.js +210 -0
- package/dist/index-4vz4bqqw.js +33 -0
- package/dist/index-5jxm2wy5.js +123 -0
- package/dist/index-5rk6ss42.js +216 -0
- package/dist/index-5v1skxf7.js +1852 -0
- package/dist/{index-qz4fs9f9.js → index-6ehtssyz.js} +355 -332
- package/dist/index-76kpdbpw.js +80 -0
- package/dist/{index-r0q0r88h.js → index-7nbmhmw5.js} +10 -10
- package/dist/index-8mx0yrkz.js +31 -0
- package/dist/index-8tjev5ds.js +11 -0
- package/dist/index-91n5wr6s.js +163 -0
- package/dist/index-91trs3ew.js +151 -0
- package/dist/index-9y8p5vy5.js +222 -0
- package/dist/index-abxahprd.js +55 -0
- package/dist/index-aptyr511.js +84 -0
- package/dist/{index-8sm2a1wa.js → index-ay26xfxt.js} +28 -20
- package/dist/index-b4yed1s3.js +657 -0
- package/dist/index-bb7phvtg.js +23 -0
- package/dist/index-bk5tn9b8.js +236 -0
- package/dist/index-bw34861c.js +292 -0
- package/dist/index-c6fnjhgv.js +55 -0
- package/dist/{index-qfsrrnz6.js → index-cjevq9s8.js} +2 -2
- package/dist/{index-c39197wq.js → index-ctcwrkrc.js} +4 -4
- package/dist/{index-yx52bt4a.js → index-cztmcesv.js} +2 -2
- package/dist/index-dpbmxnrf.js +564 -0
- package/dist/index-ekxdcy36.js +134 -0
- package/dist/index-f8zpcsx3.js +289 -0
- package/dist/{index-6dxrbnxm.js → index-f970qtb4.js} +7 -143
- package/dist/index-fatcn6fp.js +2791 -0
- package/dist/index-fbzykqxy.js +105 -0
- package/dist/{index-1265j7t2.js → index-fwf274vc.js} +24 -14
- package/dist/index-fy4w0a7v.js +0 -0
- package/dist/index-gvva3e5x.js +76 -0
- package/dist/index-h7dcah4p.js +137 -0
- package/dist/index-hm9r120s.js +42 -0
- package/dist/index-j3d2tw97.js +328 -0
- package/dist/index-jfqj20x8.js +41 -0
- package/dist/{index-yp0jtaxp.js → index-k529a278.js} +6 -6
- package/dist/{index-bt2p8x7r.js → index-kbrf5bx7.js} +110 -106
- package/dist/index-kwk23ktq.js +33 -0
- package/dist/index-kz857p1j.js +557 -0
- package/dist/{index-tc2r2n8b.js → index-mkt5yrax.js} +31 -105
- package/dist/{index-tgt8gtq7.js → index-ndgnvjez.js} +18 -18
- package/dist/index-nemn4epv.js +43 -0
- package/dist/index-nkwy5bjr.js +1225 -0
- package/dist/index-nvvzr4ny.js +136 -0
- package/dist/index-pkspzsfs.js +78 -0
- package/dist/{index-fm84men1.js → index-px1tnqgt.js} +2 -2
- package/dist/index-q7qdw883.js +79 -0
- package/dist/{index-mzydbzp8.js → index-qvbg6tx1.js} +65 -23
- package/dist/index-r3mwr5fb.js +0 -0
- package/dist/index-rdr78m0k.js +91 -0
- package/dist/index-rtamqsfs.js +59 -0
- package/dist/index-s125ss45.js +38 -0
- package/dist/{index-h8r80xhk.js → index-sx1t6dnd.js} +4005 -2781
- package/dist/index-tar0ngkm.js +359 -0
- package/dist/index-tn58cr6w.js +471 -0
- package/dist/{index-v17e1xs8.js → index-v79s9bf9.js} +96 -23
- package/dist/index-vk3rq21m.js +17 -0
- package/dist/index-vmvnr28y.js +72 -0
- package/dist/index-vz629cg8.js +49 -0
- package/dist/{index-eps3c3g6.js → index-w292hdpz.js} +197 -960
- package/dist/{index-t6sjhxh8.js → index-w9eqg6p9.js} +24 -302
- package/dist/index-wj96kdw2.js +57 -0
- package/dist/index-wyck5yhd.js +141 -0
- package/dist/index-xvtk8pxs.js +674 -0
- package/dist/{index-bpc596v3.js → index-xwb691v9.js} +2 -2
- package/dist/index-ym69x168.js +518 -0
- package/dist/index-yprdjk9v.js +65 -0
- package/dist/index-z2a81ccr.js +35 -0
- package/dist/{index-3ah1f369.js → index-z69cqk74.js} +3 -3
- package/dist/index-zaakvmzq.js +62 -0
- package/dist/index-zk3m4mzg.js +232 -0
- package/dist/index-zx3wgvx4.js +218 -0
- package/dist/index.js +102 -83
- package/dist/persistence/migration-guard.d.ts +3 -0
- package/dist/runtime/harness.d.ts +2 -0
- package/dist/service-cli.js +130 -40
- package/dist/service-client-cli-2rzxy5mj.js +1166 -0
- package/dist/service-client-cli-5ne8q5ej.js +543 -0
- package/dist/tools/ooxml-zip.d.ts +21 -0
- package/dist/tools/presentations.d.ts +47 -0
- package/dist/tools/tabular-data.d.ts +114 -0
- package/dist/tools/workspace.d.ts +76 -0
- package/dist/verify-historical-migrations.js +1923 -797
- package/dist/workspace/workspace.d.ts +13 -1
- package/dist/zhx.js +8 -6
- package/docs/APPLICATION_MIGRATION.md +32 -0
- package/docs/CLI.md +166 -2
- package/docs/CODE_RELEASE.md +5 -3
- package/docs/CODE_WEB_TASKS.md +3 -114
- package/docs/CONTEXT_ENGINEERING.md +27 -0
- package/docs/ENGINE_API.md +1 -1
- package/docs/EXTENSIBILITY.md +1 -1
- package/docs/FIRST_USE.md +6 -6
- package/docs/INTERNAL_ARCHIVE.md +43 -0
- package/docs/LOCAL_SERVICE.md +1 -1
- package/docs/MODEL_CATALOG.md +14 -0
- package/docs/README.md +13 -2
- package/evaluations/representative-assembly-matrix.json +10 -1
- package/examples/README.md +3 -3
- package/examples/assistant/compatible-calendar.json +17 -0
- package/examples/assistant/composed-modules.json +23 -0
- package/examples/assistant/connected-tools.json +9 -0
- package/examples/assistant/daily-tools.json +6 -0
- package/examples/assistant/offline.mjs +24 -0
- package/fixtures/cli-compatibility/README.md +10 -0
- package/fixtures/cli-compatibility/inventory.json +7858 -0
- package/package.json +230 -28
- package/dist/cli/console/console-model-catalog.d.ts +0 -8
- package/dist/index-4gt045j0.js +0 -288
- package/dist/index-4jw3tvy8.js +0 -301
- package/dist/index-ebb5d4s3.js +0 -640
- package/dist/index-x9hv1a34.js +0 -274
- package/dist/service-client-cli-gtk26axb.js +0 -1251
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
terminalContinuationMessages
|
|
3
|
+
} from "./index-1z0xhkh9.js";
|
|
4
|
+
import {
|
|
5
|
+
runResultDocument
|
|
6
|
+
} from "./index-q7qdw883.js";
|
|
1
7
|
import {
|
|
2
8
|
openWorkspaceCheckpointStore
|
|
3
|
-
} from "./index-
|
|
9
|
+
} from "./index-0dkty795.js";
|
|
4
10
|
import {
|
|
5
11
|
appendUserMessage,
|
|
6
|
-
checkEvidence,
|
|
7
12
|
hostPolicyIdentity,
|
|
8
13
|
initializeHarnessTaskBudget,
|
|
9
14
|
issueExplicitReviewResponses,
|
|
@@ -16,17 +21,17 @@ import {
|
|
|
16
21
|
reviseHarnessTaskAcceptance,
|
|
17
22
|
runHarness,
|
|
18
23
|
runHarnessTask
|
|
19
|
-
} from "./index-
|
|
24
|
+
} from "./index-sx1t6dnd.js";
|
|
20
25
|
import {
|
|
21
26
|
ASSISTANT_RESPONSE_KEY,
|
|
22
27
|
TASK_SOURCE_KEY,
|
|
23
28
|
assistantResponses,
|
|
24
29
|
cancelHarnessRun,
|
|
25
30
|
captureTaskSources
|
|
26
|
-
} from "./index-
|
|
31
|
+
} from "./index-w9eqg6p9.js";
|
|
27
32
|
import {
|
|
28
33
|
resolvePackageCheckCommand
|
|
29
|
-
} from "./index-
|
|
34
|
+
} from "./index-v79s9bf9.js";
|
|
30
35
|
import {
|
|
31
36
|
APPROVAL_HISTORY_KEY,
|
|
32
37
|
approvalDecisionViews,
|
|
@@ -35,121 +40,36 @@ import {
|
|
|
35
40
|
inspectHarnessPolicy,
|
|
36
41
|
observeHarnessPolicyDecisions,
|
|
37
42
|
readApprovalDecisions
|
|
38
|
-
} from "./index-
|
|
43
|
+
} from "./index-kbrf5bx7.js";
|
|
39
44
|
import {
|
|
40
45
|
SESSION_RUN_STATUSES,
|
|
41
46
|
TASK_ACCEPTANCE_KEY,
|
|
42
47
|
TASK_BUDGET_KEY,
|
|
43
48
|
TaskBudget,
|
|
44
|
-
USAGE_LEDGER_KEY,
|
|
45
49
|
compileTaskAcceptanceContract,
|
|
46
50
|
inspectTaskBudgetSummary,
|
|
47
|
-
inspectUsageLedger,
|
|
48
51
|
nextTaskAcceptanceLedger,
|
|
49
52
|
openCliSessionStore,
|
|
50
53
|
readTaskAcceptanceLedger
|
|
51
|
-
} from "./index-
|
|
54
|
+
} from "./index-6ehtssyz.js";
|
|
52
55
|
import {
|
|
53
56
|
createEditProposal,
|
|
54
57
|
editProposalInputSchema,
|
|
55
58
|
fileDigestSchema
|
|
56
|
-
} from "./index-
|
|
59
|
+
} from "./index-f970qtb4.js";
|
|
57
60
|
import {
|
|
58
|
-
CLI_JSON_SCHEMA_VERSION,
|
|
59
|
-
harnessClientRequestSchema,
|
|
60
61
|
harnessTaskProjectionSchema
|
|
61
|
-
} from "./index-
|
|
62
|
+
} from "./index-rdr78m0k.js";
|
|
62
63
|
import {
|
|
63
64
|
HarnessStateConflictError,
|
|
64
65
|
harnessErrorDocument,
|
|
65
66
|
providerStreamDiagnostic
|
|
66
|
-
} from "./index-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const recorded = new Set(messages.flatMap((message) => message.parts.flatMap((part) => part.type === "tool-result" ? [part.toolResult.toolCallId] : [])));
|
|
71
|
-
return messages.flatMap((message) => {
|
|
72
|
-
if (message.role !== "assistant")
|
|
73
|
-
return [message];
|
|
74
|
-
const missing = message.parts.filter((part) => part.type === "tool-call" && !recorded.has(part.toolCall.id));
|
|
75
|
-
if (!missing.length)
|
|
76
|
-
return [message];
|
|
77
|
-
return [message, { role: "tool", parts: missing.map((part) => {
|
|
78
|
-
if (part.type !== "tool-call")
|
|
79
|
-
throw new Error("INVALID_CONTINUATION");
|
|
80
|
-
return { type: "tool-result", toolResult: { toolCallId: part.toolCall.id, toolName: part.toolCall.name, isError: true, output: { status: "outcome_unknown", reason: "Previous run ended without a recorded tool result. Inspect current state before any new proposal; do not assume execution or success." } } };
|
|
81
|
-
}) }];
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/client/run-document.ts
|
|
86
|
-
import { getAgentBudgetStatus } from "@zhivex-ai/agents";
|
|
87
|
-
import { estimateAgentRunCost } from "@zhivex-ai/agents/ops";
|
|
88
|
-
var costPricing = (harness) => harness.config.costBudget ? {
|
|
89
|
-
inputCostPer1kTokens: harness.config.costBudget.inputCostPer1kTokens,
|
|
90
|
-
outputCostPer1kTokens: harness.config.costBudget.outputCostPer1kTokens,
|
|
91
|
-
currency: "USD"
|
|
92
|
-
} : undefined;
|
|
93
|
-
var runResultDocument = (result, harness) => ({
|
|
94
|
-
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
95
|
-
kind: "run-result",
|
|
96
|
-
runId: result.state.runId,
|
|
97
|
-
status: result.status,
|
|
98
|
-
provider: result.state.provider,
|
|
99
|
-
model: result.state.modelId,
|
|
100
|
-
output: result.outputText,
|
|
101
|
-
steps: result.steps.length,
|
|
102
|
-
toolCalls: result.toolResults.length,
|
|
103
|
-
verification: checkEvidence(result.toolResults),
|
|
104
|
-
mutations: harness.workspace.mutationAudit(),
|
|
105
|
-
pendingApprovals: result.state.pendingApprovals.map((approval) => ({
|
|
106
|
-
id: approval.id,
|
|
107
|
-
kind: approval.kind ?? "provider",
|
|
108
|
-
name: approval.name,
|
|
109
|
-
arguments: approval.arguments,
|
|
110
|
-
...approval.childRunId ? { childRunId: approval.childRunId } : {},
|
|
111
|
-
...approval.childAgentId ? { childAgentId: approval.childAgentId } : {}
|
|
112
|
-
})),
|
|
113
|
-
children: (result.state.childRuns ?? []).map((child) => ({
|
|
114
|
-
runId: child.runId,
|
|
115
|
-
agentId: child.agentId,
|
|
116
|
-
toolName: child.toolName,
|
|
117
|
-
status: child.status,
|
|
118
|
-
steps: child.steps,
|
|
119
|
-
toolCalls: child.toolCalls,
|
|
120
|
-
toolErrors: child.toolErrors,
|
|
121
|
-
usage: child.usage
|
|
122
|
-
})),
|
|
123
|
-
usage: result.usage,
|
|
124
|
-
...result.state.metadata?.[USAGE_LEDGER_KEY] ? { usageLedger: inspectUsageLedger(result.state.metadata[USAGE_LEDGER_KEY]) } : {},
|
|
125
|
-
budget: getAgentBudgetStatus(result.state, harness.config.budget, result),
|
|
126
|
-
...harness.config.costBudget ? {
|
|
127
|
-
costBudget: {
|
|
128
|
-
limitUsd: harness.config.costBudget.maxCostUsd,
|
|
129
|
-
estimate: estimateAgentRunCost(result.state, costPricing(harness))
|
|
130
|
-
}
|
|
131
|
-
} : {},
|
|
132
|
-
scope: result.state.scope,
|
|
133
|
-
capabilities: harness.capabilities,
|
|
134
|
-
orchestration: {
|
|
135
|
-
profiles: harness.config.orchestration.profiles,
|
|
136
|
-
childBudget: harness.config.orchestration.childBudget,
|
|
137
|
-
mcpServers: harness.mcpConfiguration.servers.map((server) => server.name)
|
|
138
|
-
},
|
|
139
|
-
execution: harness.executionEnvironment ? {
|
|
140
|
-
backend: "oci",
|
|
141
|
-
binding: result.state.executionEnvironment,
|
|
142
|
-
image: harness.executionEnvironment.image
|
|
143
|
-
} : { backend: "none" },
|
|
144
|
-
store: {
|
|
145
|
-
backend: harness.config.storeBackend,
|
|
146
|
-
stateDirectory: harness.config.stateDirectory,
|
|
147
|
-
migration: harness.persistence?.migration
|
|
148
|
-
},
|
|
149
|
-
stateDirectory: harness.config.stateDirectory
|
|
150
|
-
});
|
|
67
|
+
} from "./index-xwb691v9.js";
|
|
68
|
+
import {
|
|
69
|
+
harnessClientRequestSchema
|
|
70
|
+
} from "./index-76kpdbpw.js";
|
|
151
71
|
|
|
152
|
-
// src/client/task-control-host.ts
|
|
72
|
+
// packages/core/src/client/task-control-host.ts
|
|
153
73
|
import { execFile } from "node:child_process";
|
|
154
74
|
import { promisify } from "node:util";
|
|
155
75
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -304,7 +224,7 @@ async function keepClientTask(host, runId, allowedRunIds, expected) {
|
|
|
304
224
|
}
|
|
305
225
|
}
|
|
306
226
|
|
|
307
|
-
// src/client/task-projection-host.ts
|
|
227
|
+
// packages/core/src/client/task-projection-host.ts
|
|
308
228
|
import { createHash as createHash2 } from "node:crypto";
|
|
309
229
|
import { createRedactionPolicy } from "@zhivex-ai/agents";
|
|
310
230
|
class TaskProjectionFault extends Error {
|
|
@@ -471,7 +391,7 @@ async function projectHarnessTask(host, request, allowedRunIds, sensitiveValues
|
|
|
471
391
|
}
|
|
472
392
|
}
|
|
473
393
|
|
|
474
|
-
// src/approvals/approval-diff.ts
|
|
394
|
+
// packages/core/src/approvals/approval-diff.ts
|
|
475
395
|
import { createHash as createHash3 } from "node:crypto";
|
|
476
396
|
import { z } from "zod";
|
|
477
397
|
var APPROVAL_DIFFS_KEY = "clientApprovalDiffsV1";
|
|
@@ -528,7 +448,7 @@ function attachAppliedDiffs(state, decisions) {
|
|
|
528
448
|
});
|
|
529
449
|
}
|
|
530
450
|
|
|
531
|
-
// src/approvals/approval-preview.ts
|
|
451
|
+
// packages/core/src/approvals/approval-preview.ts
|
|
532
452
|
import { z as z2 } from "zod";
|
|
533
453
|
async function attachApprovalPreviews(run, workspace, options = {}) {
|
|
534
454
|
let remaining = 256 * 1024;
|
|
@@ -566,7 +486,7 @@ async function attachApprovalPreviews(run, workspace, options = {}) {
|
|
|
566
486
|
return run;
|
|
567
487
|
}
|
|
568
488
|
|
|
569
|
-
// src/client/adapter.ts
|
|
489
|
+
// packages/core/src/client/adapter.ts
|
|
570
490
|
import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
|
|
571
491
|
var canonical = (value) => {
|
|
572
492
|
if (Array.isArray(value))
|
|
@@ -786,6 +706,12 @@ var createHarnessClientAdapter = async (harness, options = {}) => {
|
|
|
786
706
|
result.push(sessionDocument(await refresh(await getSession(s2.sessionId))));
|
|
787
707
|
return { kind: "sessions", sessions: result };
|
|
788
708
|
}
|
|
709
|
+
if (c.method === "checkpoint.storage")
|
|
710
|
+
return { kind: "checkpoint-storage", ...(await checkpointStore()).storageStatus() };
|
|
711
|
+
if (c.method === "checkpoint.pruneReview")
|
|
712
|
+
return { kind: "checkpoint-prune-review", ...(await checkpointStore()).prepareRetention(c.selection) };
|
|
713
|
+
if (c.method === "checkpoint.pruneApply")
|
|
714
|
+
return { kind: "checkpoint-pruned", ...await (await checkpointStore()).applyRetention(c.selection, c.reviewedPlanId) };
|
|
789
715
|
let s = await refresh(await getSession(c.sessionId));
|
|
790
716
|
if (c.method === "session.get")
|
|
791
717
|
return { kind: "session", session: sessionDocument(s) };
|
|
@@ -1104,7 +1030,7 @@ Exact editable files: ` + brief.contract.allowedWritePaths.join(", ") + ". Execu
|
|
|
1104
1030
|
return { ok: false, error: { code: "CONNECTION_EXPIRED" } };
|
|
1105
1031
|
if (!versions.includes(1))
|
|
1106
1032
|
return { ok: false, error: { code: "VERSION_UNSUPPORTED" } };
|
|
1107
|
-
return { ok: true, protocolVersion: 1, connectionId, projectId, capabilities: ["task.control.v1", "task.start", "task.review", "task.keep", "task.revise", "task.continue", "task.get", "task.projection.v1", "project.get", "policy.get", "session.list", "session.create", "session.get", "session.rename", "run.start", "run.get", "approval.resolve", "run.cancel.checkpoint", "run.cancel.active", "idempotency.connection", "revision.precondition", "checkpoint.list", "checkpoint.inspect", "checkpoint.capture", "restore.prepare", "restore.get", "restore.apply", "restore.recoverFork"] };
|
|
1033
|
+
return { ok: true, protocolVersion: 1, connectionId, projectId, capabilities: ["task.control.v1", "task.start", "task.review", "task.keep", "task.revise", "task.continue", "task.get", "task.projection.v1", "project.get", "policy.get", "session.list", "session.create", "session.get", "session.rename", "run.start", "run.get", "approval.resolve", "run.cancel.checkpoint", "run.cancel.active", "idempotency.connection", "revision.precondition", "checkpoint.storage", "checkpoint.pruneReview", "checkpoint.pruneApply", "checkpoint.list", "checkpoint.inspect", "checkpoint.capture", "restore.prepare", "restore.get", "restore.apply", "restore.recoverFork"] };
|
|
1108
1034
|
},
|
|
1109
1035
|
async dispatch(value) {
|
|
1110
1036
|
const hostReviewed = Boolean(value && typeof value === "object" && reviewedRequests.delete(value));
|
|
@@ -1228,4 +1154,4 @@ Exact editable files: ` + brief.contract.allowedWritePaths.join(", ") + ". Execu
|
|
|
1228
1154
|
return adapter;
|
|
1229
1155
|
};
|
|
1230
1156
|
|
|
1231
|
-
export {
|
|
1157
|
+
export { createHarnessClientAdapter };
|
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
combineMcpHostSessions,
|
|
4
4
|
createHarnessMcpTools,
|
|
5
5
|
issueMcpHostSession
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-k529a278.js";
|
|
7
7
|
import {
|
|
8
8
|
collectSnapshotInventory,
|
|
9
9
|
readSnapshotFile,
|
|
10
10
|
runPortableProcess
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-v79s9bf9.js";
|
|
12
12
|
import {
|
|
13
13
|
readRegularFileNoFollow
|
|
14
|
-
} from "./index-
|
|
14
|
+
} from "./index-h7dcah4p.js";
|
|
15
15
|
|
|
16
|
-
// src/execution/mcp-workspace-snapshot.ts
|
|
16
|
+
// packages/core/src/execution/mcp-workspace-snapshot.ts
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
18
|
import { chmod, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
19
19
|
import { tmpdir } from "node:os";
|
|
@@ -100,7 +100,7 @@ async function discardMcpWorkspaceSnapshot(snapshot) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
// src/persistence/mcp-resource-journal.ts
|
|
103
|
+
// packages/core/src/persistence/mcp-resource-journal.ts
|
|
104
104
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
105
105
|
import { z } from "zod";
|
|
106
106
|
var ownerInstance = randomUUID();
|
|
@@ -225,7 +225,7 @@ function matchesMcpResourceScope(plan, runId, scope, hostId) {
|
|
|
225
225
|
return !!hostId && plan.hostHash === hash2(hostId) && plan.scopeHash === hash2({ runId, scope });
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
// src/execution/mcp-resource-recovery.ts
|
|
228
|
+
// packages/core/src/execution/mcp-resource-recovery.ts
|
|
229
229
|
function ownerIsDead(pid) {
|
|
230
230
|
try {
|
|
231
231
|
process.kill(pid, 0);
|
|
@@ -327,7 +327,7 @@ async function recoverDockerMcpResources(options) {
|
|
|
327
327
|
} });
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
// src/integrations/mcp-stdio-admission.ts
|
|
330
|
+
// packages/core/src/integrations/mcp-stdio-admission.ts
|
|
331
331
|
import { createHash as createHash3 } from "node:crypto";
|
|
332
332
|
import { z as z2 } from "zod";
|
|
333
333
|
var name = z2.string().min(1).max(128).regex(/^[A-Za-z][A-Za-z0-9_-]*$/);
|
|
@@ -459,14 +459,14 @@ function createMcpStdioAdmissionAuthority(options) {
|
|
|
459
459
|
};
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
// src/execution/mcp-oci-server.ts
|
|
462
|
+
// packages/core/src/execution/mcp-oci-server.ts
|
|
463
463
|
import { constants } from "node:fs";
|
|
464
464
|
import { access, mkdtemp as mkdtemp2, realpath, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
465
465
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
466
466
|
import path2 from "node:path";
|
|
467
467
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
468
468
|
|
|
469
|
-
// src/execution/mcp-oci-channel.ts
|
|
469
|
+
// packages/core/src/execution/mcp-oci-channel.ts
|
|
470
470
|
import { spawn } from "node:child_process";
|
|
471
471
|
async function removeDockerMcpBoundary(cli, id) {
|
|
472
472
|
await cli(["stop", "--time", "2", id]).catch(() => {});
|
|
@@ -560,10 +560,10 @@ async function openDockerMcpChannel(options) {
|
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
// src/execution/mcp-oci-workspace.ts
|
|
563
|
+
// packages/core/src/execution/mcp-oci-workspace.ts
|
|
564
564
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
565
565
|
|
|
566
|
-
// src/integrations/mcp-stdio-framing.ts
|
|
566
|
+
// packages/core/src/integrations/mcp-stdio-framing.ts
|
|
567
567
|
class McpStdioProtocolError extends Error {
|
|
568
568
|
constructor(message) {
|
|
569
569
|
super(message);
|
|
@@ -652,7 +652,7 @@ class McpStdioFrameDecoder {
|
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
-
// src/integrations/mcp-stdio-client.ts
|
|
655
|
+
// packages/core/src/integrations/mcp-stdio-client.ts
|
|
656
656
|
class McpStdioClientError extends Error {
|
|
657
657
|
code;
|
|
658
658
|
outcomeUnknown;
|
|
@@ -855,7 +855,7 @@ class IsolatedMcpStdioClient {
|
|
|
855
855
|
}
|
|
856
856
|
}
|
|
857
857
|
|
|
858
|
-
// src/execution/mcp-oci-workspace.ts
|
|
858
|
+
// packages/core/src/execution/mcp-oci-workspace.ts
|
|
859
859
|
var SEEDER = String.raw`
|
|
860
860
|
const fs = require('node:fs/promises');
|
|
861
861
|
const path = require('node:path');
|
|
@@ -1046,7 +1046,7 @@ async function createDockerMcpWorkspace(options) {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
|
-
// src/integrations/mcp-stdio-launch.ts
|
|
1049
|
+
// packages/core/src/integrations/mcp-stdio-launch.ts
|
|
1050
1050
|
async function withAdmittedMcpLaunch(options) {
|
|
1051
1051
|
let result;
|
|
1052
1052
|
try {
|
|
@@ -1101,11 +1101,11 @@ async function withAdmittedMcpLaunch(options) {
|
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
1103
|
|
|
1104
|
-
// src/integrations/mcp-stdio-tools.ts
|
|
1104
|
+
// packages/core/src/integrations/mcp-stdio-tools.ts
|
|
1105
1105
|
import { createRedactionPolicy } from "@zhivex-ai/core";
|
|
1106
1106
|
import { z as z3 } from "zod";
|
|
1107
1107
|
|
|
1108
|
-
// src/persistence/mcp-execution-journal.ts
|
|
1108
|
+
// packages/core/src/persistence/mcp-execution-journal.ts
|
|
1109
1109
|
import { createHash as createHash4 } from "node:crypto";
|
|
1110
1110
|
class McpExecutionJournalError extends Error {
|
|
1111
1111
|
code;
|
|
@@ -1228,7 +1228,7 @@ function createJournaledMcpClient(options) {
|
|
|
1228
1228
|
};
|
|
1229
1229
|
}
|
|
1230
1230
|
|
|
1231
|
-
// src/integrations/mcp-stdio-tools.ts
|
|
1231
|
+
// packages/core/src/integrations/mcp-stdio-tools.ts
|
|
1232
1232
|
var record = z3.record(z3.string(), z3.unknown());
|
|
1233
1233
|
var listing = z3.object({
|
|
1234
1234
|
tools: z3.array(z3.object({
|
|
@@ -1434,7 +1434,7 @@ async function createIsolatedMcpTools(options) {
|
|
|
1434
1434
|
}
|
|
1435
1435
|
}
|
|
1436
1436
|
|
|
1437
|
-
// src/execution/mcp-oci-server.ts
|
|
1437
|
+
// packages/core/src/execution/mcp-oci-server.ts
|
|
1438
1438
|
var endpointKeys = ["HOME", "DOCKER_CONFIG", "DOCKER_CONTEXT", "DOCKER_HOST", "DOCKER_TLS_VERIFY", "DOCKER_CERT_PATH", "XDG_RUNTIME_DIR"];
|
|
1439
1439
|
async function dockerExecutable() {
|
|
1440
1440
|
for (const directory of (process.env.PATH ?? "").split(path2.delimiter).filter(Boolean)) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// packages/core/src/application/assistant/providers/web-citations.ts
|
|
2
|
+
function citeResponseText(text, response) {
|
|
3
|
+
const output = response?.output;
|
|
4
|
+
if (!Array.isArray(output))
|
|
5
|
+
return text;
|
|
6
|
+
for (const raw of output) {
|
|
7
|
+
const item = raw;
|
|
8
|
+
if (item?.type !== "message" || !Array.isArray(item.content))
|
|
9
|
+
continue;
|
|
10
|
+
for (const value of item.content) {
|
|
11
|
+
const part = value;
|
|
12
|
+
if (part?.type !== "output_text" || part.text !== text || !Array.isArray(part.annotations))
|
|
13
|
+
continue;
|
|
14
|
+
const citations = [];
|
|
15
|
+
for (const raw2 of part.annotations) {
|
|
16
|
+
const a = raw2;
|
|
17
|
+
if (a?.type !== "url_citation" || !Number.isInteger(a.start_index) || !Number.isInteger(a.end_index) || typeof a.url !== "string")
|
|
18
|
+
continue;
|
|
19
|
+
const { start_index: start, end_index: end } = a;
|
|
20
|
+
if (start < 0 || end < start || end > text.length)
|
|
21
|
+
continue;
|
|
22
|
+
try {
|
|
23
|
+
const url = new URL(a.url);
|
|
24
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password)
|
|
25
|
+
continue;
|
|
26
|
+
const label = (typeof a.title === "string" ? a.title : url.hostname).replace(/[\[\]\\\r\n]/g, " ").slice(0, 200) || url.hostname;
|
|
27
|
+
citations.push({ start, end, link: `[${label}](${url.href.replace(/\(/g, "%28").replace(/\)/g, "%29")})` });
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
let cursor = 0, result = "";
|
|
31
|
+
for (const citation of citations.sort((a, b) => a.start - b.start)) {
|
|
32
|
+
if (citation.start < cursor)
|
|
33
|
+
continue;
|
|
34
|
+
result += text.slice(cursor, citation.start) + citation.link;
|
|
35
|
+
cursor = citation.end;
|
|
36
|
+
}
|
|
37
|
+
return result + text.slice(cursor);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return text;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { citeResponseText };
|