@ashx-j/lunr 0.2.19 → 0.2.21
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 +36 -1
- package/README.md +2 -2
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +0 -2
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/lunr-todos.d.ts +6 -5
- package/dist/builtin-extensions/lunr-todos.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-todos.js +9 -7
- package/dist/builtin-extensions/lunr-todos.js.map +1 -1
- package/dist/builtin-extensions/pi-intercom/broker/spawn.d.ts +6 -4
- package/dist/builtin-extensions/pi-intercom/broker/spawn.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-intercom/broker/spawn.js +114 -61
- package/dist/builtin-extensions/pi-intercom/broker/spawn.js.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.js +360 -351
- package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js +2 -2
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +8 -6
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +128 -57
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts +18 -8
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +38 -13
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +24 -14
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts +8 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js +247 -18
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/result-intercom.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/result-intercom.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/result-intercom.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/result-intercom.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.d.ts +29 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js +179 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts +89 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js +541 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +11 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js +38 -12
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-job-tracker.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts +2 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js +35 -8
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts +7 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js +26 -4
- package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.js +55 -38
- package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +100 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +46 -31
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +3 -6
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js +64 -5
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/top-level-async.d.ts +15 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/background/top-level-async.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/top-level-async.js +14 -4
- package/dist/builtin-extensions/pi-subagents/src/runs/background/top-level-async.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js +2 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +21 -8
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +0 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +71 -25
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js +75 -18
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/completion-guard.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.d.ts +13 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.js +67 -11
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts +3 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +7 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js +13 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js +5 -10
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/async-guidance.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/async-guidance.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/async-guidance.js +3 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/async-guidance.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts +3 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js +68 -11
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/formatters.d.ts +12 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/formatters.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/formatters.js +21 -2
- package/dist/builtin-extensions/pi-subagents/src/shared/formatters.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +21 -4
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/delegation-adapters.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/delegation-adapters.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts +7 -0
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js +11 -7
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts +6 -0
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +46 -29
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +46 -4
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +407 -450
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/register-main.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.d.ts +2 -13
- package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.js +5 -91
- package/dist/builtin-extensions/pi-subagents/src/watchdog/tool-actions.js.map +1 -1
- package/dist/core/customize.d.ts +2 -0
- package/dist/core/customize.d.ts.map +1 -1
- package/dist/core/customize.js +3 -0
- package/dist/core/customize.js.map +1 -1
- package/dist/core/permissions.d.ts +1 -0
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +8 -4
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +0 -5
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/runtime-bridges.d.ts.map +1 -1
- package/dist/core/runtime-bridges.js +0 -2
- package/dist/core/runtime-bridges.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/subagent-cancellation.d.ts +21 -0
- package/dist/core/subagent-cancellation.d.ts.map +1 -0
- package/dist/core/subagent-cancellation.js +53 -0
- package/dist/core/subagent-cancellation.js.map +1 -0
- package/dist/core/subagent-spinner-setting.d.ts +6 -0
- package/dist/core/subagent-spinner-setting.d.ts.map +1 -0
- package/dist/core/subagent-spinner-setting.js +12 -0
- package/dist/core/subagent-spinner-setting.js.map +1 -0
- package/dist/core/subagent-spinner.d.ts +4 -0
- package/dist/core/subagent-spinner.d.ts.map +1 -0
- package/dist/core/subagent-spinner.js +6 -0
- package/dist/core/subagent-spinner.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +12 -18
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +73 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +12 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/extension-widget-order.d.ts +8 -0
- package/dist/modes/interactive/extension-widget-order.d.ts.map +1 -0
- package/dist/modes/interactive/extension-widget-order.js +37 -0
- package/dist/modes/interactive/extension-widget-order.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +44 -22
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/node-runtime/{agent-session-services-35WNVGMR.js → agent-session-services-C743TYQE.js} +6 -5
- package/dist/node-runtime/{builtin-extensions-322XDDEM.js → builtin-extensions-JCOPAAB5.js} +3 -2
- package/dist/node-runtime/{chunk-XATUM2HK.js → chunk-25I2BHAA.js} +1 -1
- package/dist/node-runtime/{chunk-TXHKBRHZ.js → chunk-2BUAYZ7K.js} +136 -53
- package/dist/node-runtime/chunk-5ZH3ZFIZ.js +308 -0
- package/dist/node-runtime/{chunk-J26TSGDL.js → chunk-6N22HULO.js} +8 -5
- package/dist/node-runtime/chunk-A3KMVBZV.js +60 -0
- package/dist/node-runtime/{chunk-4FX25LWP.js → chunk-AWVD5IEY.js} +20 -421
- package/dist/node-runtime/{chunk-ZRCBN365.js → chunk-GB2MGFLI.js} +12 -12
- package/dist/node-runtime/chunk-LISUTZS3.js +19 -0
- package/dist/node-runtime/{chunk-PNJSG3IZ.js → chunk-LTYWTR3V.js} +1 -369
- package/dist/node-runtime/{chunk-TFBIJTM3.js → chunk-PDNXVXMD.js} +13 -13
- package/dist/node-runtime/{chunk-MCUNIRD5.js → chunk-SY2TFMLO.js} +532 -261
- package/dist/node-runtime/{chunk-HQCKFM2O.js → chunk-VGYZ3APQ.js} +3 -0
- package/dist/node-runtime/{chunk-4DJ6HEGH.js → chunk-VZR3NCM7.js} +3 -3
- package/dist/node-runtime/chunk-W3SILANP.js +24 -0
- package/dist/node-runtime/{chunk-CBGB57XT.js → chunk-WLLDXJRT.js} +10 -0
- package/dist/node-runtime/{chunk-ATGA2WLC.js → chunk-XI77KVKA.js} +399 -36
- package/dist/node-runtime/{chunk-4CSFRBCN.js → chunk-Y5KOEMBH.js} +1 -1
- package/dist/node-runtime/{chunk-AROOY4BB.js → chunk-YMEAYRBE.js} +1 -1
- package/dist/node-runtime/{command-DWUM5X3U.js → command-P4NYCJ2M.js} +1 -1
- package/dist/node-runtime/{customize-XEXL2DGQ.js → customize-LF5VST47.js} +1 -1
- package/dist/node-runtime/{gateway-UZXMFGWY.js → gateway-BM6NLOH4.js} +2 -2
- package/dist/node-runtime/index.js +16 -13
- package/dist/node-runtime/{interactive-mode-QT5IKGQ5.js → interactive-mode-EVVBA64D.js} +11 -8
- package/dist/node-runtime/{lunr-cron-QPBTKBGI.js → lunr-cron-4VHP4E4B.js} +2 -2
- package/dist/node-runtime/main.js +14 -12
- package/dist/node-runtime/{package-manager-cli-7RKSZGEN.js → package-manager-cli-N37546V5.js} +5 -4
- package/dist/node-runtime/{pi-intercom-EEMBGQID.js → pi-intercom-NV2LW6X7.js} +108 -87
- package/dist/node-runtime/{pi-subagents-7YJ3I4VE.js → pi-subagents-6MUIFNDM.js} +1262 -599
- package/dist/node-runtime/rpc-entry.js +14 -12
- package/dist/node-runtime/{runtime-bridges-3RKBDLNA.js → runtime-bridges-2VQTLPOZ.js} +3 -5
- package/dist/node-runtime/{settings-manager-GHPTUN7R.js → settings-manager-CUGAZWAB.js} +2 -1
- package/dist/node-runtime/{subagent-executor-5Q5A4HJ2.js → subagent-executor-MH4A7CCF.js} +181 -294
- package/dist/node-runtime/{update-cli-L3JIBH2U.js → update-cli-XTZMZGOL.js} +2 -1
- package/docs/features.md +22 -4
- package/docs/keybindings.md +3 -1
- package/docs/settings.md +3 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
- package/dist/builtin-extensions/lunr-settings-tools.d.ts +0 -4
- package/dist/builtin-extensions/lunr-settings-tools.d.ts.map +0 -1
- package/dist/builtin-extensions/lunr-settings-tools.js +0 -120
- package/dist/builtin-extensions/lunr-settings-tools.js.map +0 -1
- package/dist/core/settings-tools-bridge.d.ts +0 -35
- package/dist/core/settings-tools-bridge.d.ts.map +0 -1
- package/dist/core/settings-tools-bridge.js +0 -56
- package/dist/core/settings-tools-bridge.js.map +0 -1
- package/dist/node-runtime/chunk-3NMWLTPV.js +0 -64
|
@@ -3,7 +3,7 @@ import { randomUUID } from "crypto";
|
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { Text } from "@ashx-j/lunr-tui";
|
|
5
5
|
import { IntercomClient } from "./broker/client.js";
|
|
6
|
-
import { spawnBrokerIfNeeded } from "./broker/spawn.js";
|
|
6
|
+
import { isNativeSupervisorChannelActive, spawnBrokerIfNeeded } from "./broker/spawn.js";
|
|
7
7
|
import { SessionListOverlay } from "./ui/session-list.js";
|
|
8
8
|
import { ComposeOverlay } from "./ui/compose.js";
|
|
9
9
|
import { InlineMessageComponent } from "./ui/inline-message.js";
|
|
@@ -310,7 +310,8 @@ function parseSubagentIntercomPayload(payload) {
|
|
|
310
310
|
return null;
|
|
311
311
|
}
|
|
312
312
|
const requestId = typeof record.requestId === "string" ? record.requestId : undefined;
|
|
313
|
-
|
|
313
|
+
const ownerNotificationSessionId = typeof record.ownerNotificationSessionId === "string" ? record.ownerNotificationSessionId : undefined;
|
|
314
|
+
return { to: record.to, message: record.message, ...(requestId ? { requestId } : {}), ...(ownerNotificationSessionId ? { ownerNotificationSessionId } : {}) };
|
|
314
315
|
}
|
|
315
316
|
function resolveIntercomPresenceName(sessionName, sessionId) {
|
|
316
317
|
const trimmedName = sessionName?.trim();
|
|
@@ -875,6 +876,9 @@ export default function piIntercomExtension(pi) {
|
|
|
875
876
|
agentRunning = false;
|
|
876
877
|
activeTools.clear();
|
|
877
878
|
startNamePoll();
|
|
879
|
+
if (isNativeSupervisorChannelActive()) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
878
882
|
const startupGeneration = runtimeGeneration;
|
|
879
883
|
startupConnectTimer = setTimeout(() => {
|
|
880
884
|
startupConnectTimer = null;
|
|
@@ -899,67 +903,70 @@ export default function piIntercomExtension(pi) {
|
|
|
899
903
|
...(error ? { error: getErrorMessage(error) } : {}),
|
|
900
904
|
});
|
|
901
905
|
}
|
|
906
|
+
const resultDeliveries = new Map();
|
|
907
|
+
const acknowledgedResults = [];
|
|
902
908
|
function relaySubagentIntercomPayload(payload, options) {
|
|
903
909
|
const parsed = parseSubagentIntercomPayload(payload);
|
|
904
910
|
if (!parsed)
|
|
905
911
|
return;
|
|
906
912
|
const relayGeneration = runtimeGeneration;
|
|
907
|
-
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
if (currentSessionTargetMatches(parsed.to)) {
|
|
913
|
-
deliverLocalSubagentRelayMessage(options.sender, options.status, parsed.message);
|
|
914
|
-
if (options.acknowledge)
|
|
915
|
-
emitResultDelivery(parsed.requestId, true);
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
let activeClient;
|
|
919
|
-
let target;
|
|
920
|
-
try {
|
|
921
|
-
activeClient = await ensureConnected("background");
|
|
922
|
-
target = await resolveSessionTarget(activeClient, parsed.to) ?? parsed.to;
|
|
923
|
-
}
|
|
924
|
-
catch (error) {
|
|
925
|
-
if (!relayStillLive())
|
|
926
|
-
return;
|
|
927
|
-
recordSubagentDeliveryError(options.errorEntryType, parsed.to, parsed.message, error);
|
|
928
|
-
if (options.acknowledge)
|
|
929
|
-
emitResultDelivery(parsed.requestId, false, error);
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
if (!relayStillLive()) {
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
if (currentSessionTargetMatches(parsed.to, target, activeClient)) {
|
|
936
|
-
deliverLocalSubagentRelayMessage(options.sender, options.status, parsed.message);
|
|
937
|
-
if (options.acknowledge)
|
|
938
|
-
emitResultDelivery(parsed.requestId, true);
|
|
913
|
+
const deliverLocal = () => {
|
|
914
|
+
const ctx = getLiveContext(runtimeContext, relayGeneration);
|
|
915
|
+
const ownerSessionId = ctx?.sessionManager.getSessionFile?.() ?? ctx?.sessionManager.getSessionId();
|
|
916
|
+
// The owner already receives subagent-notify; keep the relay ACK without another model message.
|
|
917
|
+
if (options.sender === "subagent-result" && ownerSessionId && parsed.ownerNotificationSessionId === ownerSessionId)
|
|
939
918
|
return;
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
if (
|
|
949
|
-
|
|
950
|
-
|
|
919
|
+
deliverLocalSubagentRelayMessage(options.sender, options.status, parsed.message);
|
|
920
|
+
};
|
|
921
|
+
const key = options.acknowledge && parsed.requestId ? `${relayGeneration}:${parsed.requestId}` : undefined;
|
|
922
|
+
let delivery = key ? resultDeliveries.get(key) : undefined;
|
|
923
|
+
if (!delivery) {
|
|
924
|
+
delivery = (async () => {
|
|
925
|
+
const relayStillLive = () => !runtimeStarted || Boolean(getLiveContext(runtimeContext, relayGeneration));
|
|
926
|
+
try {
|
|
927
|
+
if (!relayStillLive())
|
|
928
|
+
return false;
|
|
929
|
+
if (currentSessionTargetMatches(parsed.to)) {
|
|
930
|
+
deliverLocal();
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
const activeClient = await ensureConnected("background");
|
|
934
|
+
const target = await resolveSessionTarget(activeClient, parsed.to) ?? parsed.to;
|
|
935
|
+
if (!relayStillLive())
|
|
936
|
+
return false;
|
|
937
|
+
if (currentSessionTargetMatches(parsed.to, target, activeClient)) {
|
|
938
|
+
deliverLocal();
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
const result = await activeClient.send(target, { text: parsed.message });
|
|
942
|
+
if (!result.delivered)
|
|
943
|
+
throw new Error(result.reason ?? "Session may not exist or has disconnected.");
|
|
944
|
+
return true;
|
|
951
945
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
946
|
+
catch (error) {
|
|
947
|
+
if (relayStillLive())
|
|
948
|
+
recordSubagentDeliveryError(options.errorEntryType, parsed.to, parsed.message, error);
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
})();
|
|
952
|
+
if (key) {
|
|
953
|
+
resultDeliveries.set(key, delivery);
|
|
954
|
+
void delivery.then((delivered) => {
|
|
955
|
+
if (!delivered) {
|
|
956
|
+
if (resultDeliveries.get(key) === delivery)
|
|
957
|
+
resultDeliveries.delete(key);
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
acknowledgedResults.push(key);
|
|
961
|
+
while (acknowledgedResults.length > 1024)
|
|
962
|
+
resultDeliveries.delete(acknowledgedResults.shift());
|
|
963
|
+
});
|
|
961
964
|
}
|
|
962
|
-
}
|
|
965
|
+
}
|
|
966
|
+
void delivery.then((delivered) => {
|
|
967
|
+
if (options.acknowledge)
|
|
968
|
+
emitResultDelivery(parsed.requestId, delivered);
|
|
969
|
+
});
|
|
963
970
|
}
|
|
964
971
|
const unsubscribeSubagentControlIntercom = pi.events.on(SUBAGENT_CONTROL_INTERCOM_EVENT, (payload) => {
|
|
965
972
|
relaySubagentIntercomPayload(payload, {
|
|
@@ -1100,7 +1107,8 @@ export default function piIntercomExtension(pi) {
|
|
|
1100
1107
|
}
|
|
1101
1108
|
});
|
|
1102
1109
|
const childOrchestratorMetadata = readChildOrchestratorMetadata();
|
|
1103
|
-
|
|
1110
|
+
const nativeSupervisorChannel = isNativeSupervisorChannelActive();
|
|
1111
|
+
if (childOrchestratorMetadata && !nativeSupervisorChannel) {
|
|
1104
1112
|
pi.registerTool({
|
|
1105
1113
|
name: "contact_supervisor",
|
|
1106
1114
|
label: "Contact Supervisor",
|
|
@@ -1361,10 +1369,11 @@ export default function piIntercomExtension(pi) {
|
|
|
1361
1369
|
},
|
|
1362
1370
|
});
|
|
1363
1371
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1372
|
+
if (!nativeSupervisorChannel)
|
|
1373
|
+
pi.registerTool({
|
|
1374
|
+
name: "intercom",
|
|
1375
|
+
label: "Intercom",
|
|
1376
|
+
description: `Send a message to another pi session running on this machine.
|
|
1368
1377
|
Use this to communicate findings, request help, or coordinate work with other sessions.
|
|
1369
1378
|
|
|
1370
1379
|
Usage:
|
|
@@ -1374,158 +1383,131 @@ Usage:
|
|
|
1374
1383
|
intercom({ action: "reply", message: "..." }) → Reply to the active/single pending ask
|
|
1375
1384
|
intercom({ action: "pending" }) → List unresolved inbound asks
|
|
1376
1385
|
intercom({ action: "status" }) → Show connection status`,
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1386
|
+
promptSnippet: "Use to coordinate with other local pi sessions: list peers, send updates, ask for help, or check intercom connectivity.",
|
|
1387
|
+
parameters: Type.Object({
|
|
1388
|
+
action: StringEnum(["list", "send", "ask", "reply", "pending", "status"], {
|
|
1389
|
+
description: "Action: 'list', 'send', 'ask', 'reply', 'pending', or 'status'",
|
|
1390
|
+
}),
|
|
1391
|
+
to: Type.Optional(Type.String({
|
|
1392
|
+
description: "Target session name or ID (for 'send', 'ask', or disambiguating 'reply')",
|
|
1393
|
+
})),
|
|
1394
|
+
message: Type.Optional(Type.String({
|
|
1395
|
+
description: "Message to send (for 'send', 'ask', or 'reply' action)",
|
|
1396
|
+
})),
|
|
1397
|
+
attachments: Type.Optional(Type.Array(Type.Object({
|
|
1398
|
+
type: StringEnum(["file", "snippet", "context"]),
|
|
1399
|
+
name: Type.String(),
|
|
1400
|
+
content: Type.String(),
|
|
1401
|
+
language: Type.Optional(Type.String()),
|
|
1402
|
+
}))),
|
|
1403
|
+
replyTo: Type.Optional(Type.String({
|
|
1404
|
+
description: "Message ID to reply to (for threading or responding to an 'ask')",
|
|
1405
|
+
})),
|
|
1381
1406
|
}),
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
if (!currentSession) {
|
|
1407
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
1408
|
+
let connectedClient;
|
|
1409
|
+
try {
|
|
1410
|
+
connectedClient = await ensureConnected("tool");
|
|
1411
|
+
}
|
|
1412
|
+
catch (error) {
|
|
1413
|
+
return {
|
|
1414
|
+
content: [{ type: "text", text: `Intercom not connected: ${getErrorMessage(error)}` }],
|
|
1415
|
+
details: { error: true },
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
syncPresenceIdentity(ctx.sessionManager.getSessionId());
|
|
1419
|
+
const { action, to, message, attachments, replyTo } = params;
|
|
1420
|
+
switch (action) {
|
|
1421
|
+
case "list": {
|
|
1422
|
+
try {
|
|
1423
|
+
const mySessionId = connectedClient.sessionId;
|
|
1424
|
+
const sessions = await connectedClient.listSessions();
|
|
1425
|
+
const currentSession = sessions.find(s => s.id === mySessionId);
|
|
1426
|
+
const otherSessions = sessions.filter(s => s.id !== mySessionId);
|
|
1427
|
+
if (!currentSession) {
|
|
1428
|
+
return {
|
|
1429
|
+
content: [{ type: "text", text: "Current session is missing from intercom session list." }],
|
|
1430
|
+
details: { error: true },
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
const currentSection = `**Current session:**\n${formatSessionListRow(currentSession, currentSession.cwd, true)}`;
|
|
1434
|
+
const otherSection = otherSessions.length === 0
|
|
1435
|
+
? "**Other sessions:**\nNo other sessions connected."
|
|
1436
|
+
: `**Other sessions:**\n${otherSessions.map(s => formatSessionListRow(s, currentSession.cwd, false)).join("\n")}`;
|
|
1437
|
+
return {
|
|
1438
|
+
content: [{ type: "text", text: `${currentSection}\n\n${otherSection}` }],
|
|
1439
|
+
details: {},
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
catch (error) {
|
|
1419
1443
|
return {
|
|
1420
|
-
content: [{ type: "text", text:
|
|
1444
|
+
content: [{ type: "text", text: `Failed to list sessions: ${getErrorMessage(error)}` }],
|
|
1421
1445
|
details: { error: true },
|
|
1422
1446
|
};
|
|
1423
1447
|
}
|
|
1424
|
-
const currentSection = `**Current session:**\n${formatSessionListRow(currentSession, currentSession.cwd, true)}`;
|
|
1425
|
-
const otherSection = otherSessions.length === 0
|
|
1426
|
-
? "**Other sessions:**\nNo other sessions connected."
|
|
1427
|
-
: `**Other sessions:**\n${otherSessions.map(s => formatSessionListRow(s, currentSession.cwd, false)).join("\n")}`;
|
|
1428
|
-
return {
|
|
1429
|
-
content: [{ type: "text", text: `${currentSection}\n\n${otherSection}` }],
|
|
1430
|
-
details: {},
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
catch (error) {
|
|
1434
|
-
return {
|
|
1435
|
-
content: [{ type: "text", text: `Failed to list sessions: ${getErrorMessage(error)}` }],
|
|
1436
|
-
details: { error: true },
|
|
1437
|
-
};
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
case "send": {
|
|
1441
|
-
if (!to || !message) {
|
|
1442
|
-
return {
|
|
1443
|
-
content: [{ type: "text", text: "Missing 'to' or 'message' parameter" }],
|
|
1444
|
-
details: { error: true },
|
|
1445
|
-
};
|
|
1446
1448
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
if (sendTo === connectedClient.sessionId) {
|
|
1449
|
+
case "send": {
|
|
1450
|
+
if (!to || !message) {
|
|
1450
1451
|
return {
|
|
1451
|
-
content: [{ type: "text", text: "
|
|
1452
|
+
content: [{ type: "text", text: "Missing 'to' or 'message' parameter" }],
|
|
1452
1453
|
details: { error: true },
|
|
1453
1454
|
};
|
|
1454
1455
|
}
|
|
1455
|
-
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
if (!confirmed) {
|
|
1456
|
+
try {
|
|
1457
|
+
const sendTo = await resolveSessionTarget(connectedClient, to) ?? to;
|
|
1458
|
+
if (sendTo === connectedClient.sessionId) {
|
|
1459
1459
|
return {
|
|
1460
|
-
content: [{ type: "text", text: "
|
|
1461
|
-
details: {},
|
|
1460
|
+
content: [{ type: "text", text: "Cannot message the current session" }],
|
|
1461
|
+
details: { error: true },
|
|
1462
1462
|
};
|
|
1463
1463
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1464
|
+
if (!replyTo && config.confirmSend && ctx.hasUI) {
|
|
1465
|
+
const attachmentText = attachments?.length ? formatAttachments(attachments) : "";
|
|
1466
|
+
const confirmed = await ctx.ui.confirm("Send Message", `Send to "${to}":\n\n${message}${attachmentText}`);
|
|
1467
|
+
if (!confirmed) {
|
|
1468
|
+
return {
|
|
1469
|
+
content: [{ type: "text", text: "Message cancelled by user" }],
|
|
1470
|
+
details: {},
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
const result = await connectedClient.send(sendTo, {
|
|
1475
|
+
text: message,
|
|
1476
|
+
attachments,
|
|
1477
|
+
replyTo,
|
|
1478
|
+
});
|
|
1479
|
+
if (!result.delivered) {
|
|
1480
|
+
const errorText = result.reason ?? "Session may not exist or has disconnected.";
|
|
1481
|
+
return {
|
|
1482
|
+
content: [{ type: "text", text: `Message to "${to}" was not delivered: ${errorText}` }],
|
|
1483
|
+
details: { messageId: result.id, delivered: false, reason: result.reason },
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
pi.appendEntry("intercom_sent", {
|
|
1487
|
+
to,
|
|
1488
|
+
message: { text: message, attachments, replyTo },
|
|
1489
|
+
messageId: result.id,
|
|
1490
|
+
timestamp: Date.now(),
|
|
1491
|
+
});
|
|
1492
|
+
if (replyTo) {
|
|
1493
|
+
replyTracker.markReplied(replyTo);
|
|
1494
|
+
}
|
|
1472
1495
|
return {
|
|
1473
|
-
content: [{ type: "text", text: `Message to
|
|
1474
|
-
details: { messageId: result.id, delivered:
|
|
1496
|
+
content: [{ type: "text", text: `Message sent to ${to}` }],
|
|
1497
|
+
details: { messageId: result.id, delivered: true },
|
|
1475
1498
|
};
|
|
1476
1499
|
}
|
|
1477
|
-
|
|
1478
|
-
to,
|
|
1479
|
-
message: { text: message, attachments, replyTo },
|
|
1480
|
-
messageId: result.id,
|
|
1481
|
-
timestamp: Date.now(),
|
|
1482
|
-
});
|
|
1483
|
-
if (replyTo) {
|
|
1484
|
-
replyTracker.markReplied(replyTo);
|
|
1485
|
-
}
|
|
1486
|
-
return {
|
|
1487
|
-
content: [{ type: "text", text: `Message sent to ${to}` }],
|
|
1488
|
-
details: { messageId: result.id, delivered: true },
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
catch (error) {
|
|
1492
|
-
return {
|
|
1493
|
-
content: [{ type: "text", text: `Failed to send: ${getErrorMessage(error)}` }],
|
|
1494
|
-
details: { error: true },
|
|
1495
|
-
};
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
case "ask": {
|
|
1499
|
-
if (!to || !message) {
|
|
1500
|
-
return {
|
|
1501
|
-
content: [{ type: "text", text: "Missing 'to' or 'message' parameter" }],
|
|
1502
|
-
details: { error: true },
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
if (replyWaiter) {
|
|
1506
|
-
return {
|
|
1507
|
-
content: [{ type: "text", text: "Already waiting for a reply" }],
|
|
1508
|
-
details: { error: true },
|
|
1509
|
-
};
|
|
1510
|
-
}
|
|
1511
|
-
if (_signal?.aborted) {
|
|
1512
|
-
return {
|
|
1513
|
-
content: [{ type: "text", text: "Cancelled" }],
|
|
1514
|
-
details: { error: true },
|
|
1515
|
-
};
|
|
1516
|
-
}
|
|
1517
|
-
let replyPromise = null;
|
|
1518
|
-
try {
|
|
1519
|
-
const sendTo = await resolveSessionTarget(connectedClient, to) ?? to;
|
|
1520
|
-
if (_signal?.aborted) {
|
|
1500
|
+
catch (error) {
|
|
1521
1501
|
return {
|
|
1522
|
-
content: [{ type: "text", text:
|
|
1502
|
+
content: [{ type: "text", text: `Failed to send: ${getErrorMessage(error)}` }],
|
|
1523
1503
|
details: { error: true },
|
|
1524
1504
|
};
|
|
1525
1505
|
}
|
|
1526
|
-
|
|
1506
|
+
}
|
|
1507
|
+
case "ask": {
|
|
1508
|
+
if (!to || !message) {
|
|
1527
1509
|
return {
|
|
1528
|
-
content: [{ type: "text", text: "
|
|
1510
|
+
content: [{ type: "text", text: "Missing 'to' or 'message' parameter" }],
|
|
1529
1511
|
details: { error: true },
|
|
1530
1512
|
};
|
|
1531
1513
|
}
|
|
@@ -1535,198 +1517,225 @@ Usage:
|
|
|
1535
1517
|
details: { error: true },
|
|
1536
1518
|
};
|
|
1537
1519
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1520
|
+
if (_signal?.aborted) {
|
|
1521
|
+
return {
|
|
1522
|
+
content: [{ type: "text", text: "Cancelled" }],
|
|
1523
|
+
details: { error: true },
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
let replyPromise = null;
|
|
1527
|
+
try {
|
|
1528
|
+
const sendTo = await resolveSessionTarget(connectedClient, to) ?? to;
|
|
1529
|
+
if (_signal?.aborted) {
|
|
1530
|
+
return {
|
|
1531
|
+
content: [{ type: "text", text: "Cancelled" }],
|
|
1532
|
+
details: { error: true },
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
if (sendTo === connectedClient.sessionId) {
|
|
1536
|
+
return {
|
|
1537
|
+
content: [{ type: "text", text: "Cannot message the current session" }],
|
|
1538
|
+
details: { error: true },
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
if (replyWaiter) {
|
|
1542
|
+
return {
|
|
1543
|
+
content: [{ type: "text", text: "Already waiting for a reply" }],
|
|
1544
|
+
details: { error: true },
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
const questionId = randomUUID();
|
|
1548
|
+
replyPromise = waitForReply(sendTo, questionId, _signal, () => connectedClient.cancelAsk(questionId));
|
|
1549
|
+
replyPromise.catch(() => undefined);
|
|
1550
|
+
const sendResult = await connectedClient.send(sendTo, {
|
|
1551
|
+
messageId: questionId,
|
|
1552
|
+
text: message,
|
|
1553
|
+
attachments,
|
|
1554
|
+
replyTo,
|
|
1555
|
+
expectsReply: true,
|
|
1556
|
+
});
|
|
1557
|
+
if (!sendResult.delivered) {
|
|
1558
|
+
const errorText = sendResult.reason ?? "Session may not exist or has disconnected.";
|
|
1559
|
+
rejectReplyWaiter(new Error(`Message to "${to}" was not delivered: ${errorText}`));
|
|
1560
|
+
if (replyPromise) {
|
|
1561
|
+
try {
|
|
1562
|
+
await replyPromise;
|
|
1563
|
+
}
|
|
1564
|
+
catch {
|
|
1565
|
+
// The waiter was already rejected above. Keep the delivery failure as the only error here.
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
return {
|
|
1569
|
+
content: [{ type: "text", text: `Message to "${to}" was not delivered: ${errorText}` }],
|
|
1570
|
+
details: { error: true },
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
pi.appendEntry("intercom_sent", {
|
|
1574
|
+
to,
|
|
1575
|
+
message: { text: message, attachments, replyTo },
|
|
1576
|
+
messageId: sendResult.id,
|
|
1577
|
+
timestamp: Date.now(),
|
|
1578
|
+
});
|
|
1579
|
+
const replyMessage = await replyPromise;
|
|
1580
|
+
const replyText = replyMessage.content.text;
|
|
1581
|
+
const replyAttachments = replyMessage.content.attachments?.length
|
|
1582
|
+
? formatAttachments(replyMessage.content.attachments)
|
|
1583
|
+
: "";
|
|
1584
|
+
pi.appendEntry("intercom_received", {
|
|
1585
|
+
from: to,
|
|
1586
|
+
message: { text: replyText, attachments: replyMessage.content.attachments },
|
|
1587
|
+
messageId: replyMessage.id,
|
|
1588
|
+
timestamp: replyMessage.timestamp,
|
|
1589
|
+
});
|
|
1590
|
+
return {
|
|
1591
|
+
content: [{ type: "text", text: `**Reply from ${to}:**\n${replyText}${replyAttachments}` }],
|
|
1592
|
+
details: {},
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
catch (error) {
|
|
1596
|
+
rejectReplyWaiter(toError(error));
|
|
1551
1597
|
if (replyPromise) {
|
|
1552
1598
|
try {
|
|
1553
1599
|
await replyPromise;
|
|
1554
1600
|
}
|
|
1555
1601
|
catch {
|
|
1556
|
-
// The waiter
|
|
1602
|
+
// The waiter is cleanup-only on this path. The real failure is the one from the outer catch.
|
|
1557
1603
|
}
|
|
1558
1604
|
}
|
|
1559
1605
|
return {
|
|
1560
|
-
content: [{ type: "text", text: `
|
|
1606
|
+
content: [{ type: "text", text: `Failed: ${getErrorMessage(error)}` }],
|
|
1561
1607
|
details: { error: true },
|
|
1562
1608
|
};
|
|
1563
1609
|
}
|
|
1564
|
-
pi.appendEntry("intercom_sent", {
|
|
1565
|
-
to,
|
|
1566
|
-
message: { text: message, attachments, replyTo },
|
|
1567
|
-
messageId: sendResult.id,
|
|
1568
|
-
timestamp: Date.now(),
|
|
1569
|
-
});
|
|
1570
|
-
const replyMessage = await replyPromise;
|
|
1571
|
-
const replyText = replyMessage.content.text;
|
|
1572
|
-
const replyAttachments = replyMessage.content.attachments?.length
|
|
1573
|
-
? formatAttachments(replyMessage.content.attachments)
|
|
1574
|
-
: "";
|
|
1575
|
-
pi.appendEntry("intercom_received", {
|
|
1576
|
-
from: to,
|
|
1577
|
-
message: { text: replyText, attachments: replyMessage.content.attachments },
|
|
1578
|
-
messageId: replyMessage.id,
|
|
1579
|
-
timestamp: replyMessage.timestamp,
|
|
1580
|
-
});
|
|
1581
|
-
return {
|
|
1582
|
-
content: [{ type: "text", text: `**Reply from ${to}:**\n${replyText}${replyAttachments}` }],
|
|
1583
|
-
details: {},
|
|
1584
|
-
};
|
|
1585
1610
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1611
|
+
case "reply": {
|
|
1612
|
+
if (!message) {
|
|
1613
|
+
return {
|
|
1614
|
+
content: [{ type: "text", text: "Missing 'message' parameter" }],
|
|
1615
|
+
details: { error: true },
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
try {
|
|
1619
|
+
const target = replyTracker.resolveReplyTarget({ to, replyTo });
|
|
1620
|
+
if (target.from.id === connectedClient.sessionId) {
|
|
1621
|
+
return {
|
|
1622
|
+
content: [{ type: "text", text: "Cannot message the current session" }],
|
|
1623
|
+
details: { error: true },
|
|
1624
|
+
};
|
|
1591
1625
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1626
|
+
const result = await connectedClient.send(target.from.id, {
|
|
1627
|
+
text: message,
|
|
1628
|
+
replyTo: target.message.id,
|
|
1629
|
+
});
|
|
1630
|
+
if (!result.delivered) {
|
|
1631
|
+
const errorText = result.reason ?? "Session may not exist or has disconnected.";
|
|
1632
|
+
if (result.reason === "Session not found") {
|
|
1633
|
+
replyTracker.dismissPendingAsk(target.message.id);
|
|
1634
|
+
}
|
|
1635
|
+
return {
|
|
1636
|
+
content: [{ type: "text", text: `Reply to "${target.from.name || target.from.id}" was not delivered: ${errorText}` }],
|
|
1637
|
+
details: { messageId: result.id, delivered: false, reason: result.reason },
|
|
1638
|
+
};
|
|
1594
1639
|
}
|
|
1640
|
+
replyTracker.markReplied(target.message.id);
|
|
1641
|
+
pi.appendEntry("intercom_sent", {
|
|
1642
|
+
to: target.from.name || target.from.id,
|
|
1643
|
+
message: { text: message, replyTo: target.message.id },
|
|
1644
|
+
messageId: result.id,
|
|
1645
|
+
timestamp: Date.now(),
|
|
1646
|
+
});
|
|
1647
|
+
return {
|
|
1648
|
+
content: [{ type: "text", text: `Reply sent to ${target.from.name || target.from.id}` }],
|
|
1649
|
+
details: { messageId: result.id, delivered: true, replyTo: target.message.id },
|
|
1650
|
+
};
|
|
1595
1651
|
}
|
|
1596
|
-
|
|
1597
|
-
content: [{ type: "text", text: `Failed: ${getErrorMessage(error)}` }],
|
|
1598
|
-
details: { error: true },
|
|
1599
|
-
};
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
case "reply": {
|
|
1603
|
-
if (!message) {
|
|
1604
|
-
return {
|
|
1605
|
-
content: [{ type: "text", text: "Missing 'message' parameter" }],
|
|
1606
|
-
details: { error: true },
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
try {
|
|
1610
|
-
const target = replyTracker.resolveReplyTarget({ to, replyTo });
|
|
1611
|
-
if (target.from.id === connectedClient.sessionId) {
|
|
1652
|
+
catch (error) {
|
|
1612
1653
|
return {
|
|
1613
|
-
content: [{ type: "text", text:
|
|
1654
|
+
content: [{ type: "text", text: `Failed to reply: ${getErrorMessage(error)}` }],
|
|
1614
1655
|
details: { error: true },
|
|
1615
1656
|
};
|
|
1616
1657
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
if (!result.delivered) {
|
|
1622
|
-
const errorText = result.reason ?? "Session may not exist or has disconnected.";
|
|
1623
|
-
if (result.reason === "Session not found") {
|
|
1624
|
-
replyTracker.dismissPendingAsk(target.message.id);
|
|
1625
|
-
}
|
|
1658
|
+
}
|
|
1659
|
+
case "pending": {
|
|
1660
|
+
const pendingAsks = replyTracker.listPending();
|
|
1661
|
+
if (pendingAsks.length === 0) {
|
|
1626
1662
|
return {
|
|
1627
|
-
content: [{ type: "text", text:
|
|
1628
|
-
details: {
|
|
1663
|
+
content: [{ type: "text", text: "No unresolved inbound asks." }],
|
|
1664
|
+
details: {},
|
|
1629
1665
|
};
|
|
1630
1666
|
}
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
timestamp: Date.now(),
|
|
1667
|
+
const now = Date.now();
|
|
1668
|
+
const lines = pendingAsks.map(({ from, message, receivedAt }) => {
|
|
1669
|
+
const preview = message.content.text.replace(/\s+/g, " ").slice(0, 80);
|
|
1670
|
+
const elapsedSeconds = Math.max(0, Math.floor((now - receivedAt) / 1000));
|
|
1671
|
+
return `- ${from.name || from.id} · ${message.id} · ${elapsedSeconds}s ago · ${preview}`;
|
|
1637
1672
|
});
|
|
1638
1673
|
return {
|
|
1639
|
-
content: [{ type: "text", text:
|
|
1640
|
-
details: { messageId: result.id, delivered: true, replyTo: target.message.id },
|
|
1641
|
-
};
|
|
1642
|
-
}
|
|
1643
|
-
catch (error) {
|
|
1644
|
-
return {
|
|
1645
|
-
content: [{ type: "text", text: `Failed to reply: ${getErrorMessage(error)}` }],
|
|
1646
|
-
details: { error: true },
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
case "pending": {
|
|
1651
|
-
const pendingAsks = replyTracker.listPending();
|
|
1652
|
-
if (pendingAsks.length === 0) {
|
|
1653
|
-
return {
|
|
1654
|
-
content: [{ type: "text", text: "No unresolved inbound asks." }],
|
|
1674
|
+
content: [{ type: "text", text: `**Pending asks:**\n${lines.join("\n")}` }],
|
|
1655
1675
|
details: {},
|
|
1656
1676
|
};
|
|
1657
1677
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
text: `**Intercom Status:**\nConnected: Yes\nSession ID: ${mySessionId}\nActive sessions: ${sessions.length}`,
|
|
1677
|
-
}],
|
|
1678
|
-
details: {},
|
|
1679
|
-
};
|
|
1678
|
+
case "status": {
|
|
1679
|
+
try {
|
|
1680
|
+
const mySessionId = connectedClient.sessionId;
|
|
1681
|
+
const sessions = await connectedClient.listSessions();
|
|
1682
|
+
return {
|
|
1683
|
+
content: [{
|
|
1684
|
+
type: "text",
|
|
1685
|
+
text: `**Intercom Status:**\nConnected: Yes\nSession ID: ${mySessionId}\nActive sessions: ${sessions.length}`,
|
|
1686
|
+
}],
|
|
1687
|
+
details: {},
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
catch (error) {
|
|
1691
|
+
return {
|
|
1692
|
+
content: [{ type: "text", text: `Failed to get status: ${getErrorMessage(error)}` }],
|
|
1693
|
+
details: { error: true },
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1680
1696
|
}
|
|
1681
|
-
|
|
1697
|
+
default:
|
|
1682
1698
|
return {
|
|
1683
|
-
content: [{ type: "text", text: `
|
|
1699
|
+
content: [{ type: "text", text: `Unknown action: ${action}` }],
|
|
1684
1700
|
details: { error: true },
|
|
1685
1701
|
};
|
|
1686
|
-
}
|
|
1687
1702
|
}
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
if (details?.reason && context.expanded) {
|
|
1725
|
-
text += "\n" + theme.fg("dim", `Reason: ${details.reason}`);
|
|
1726
|
-
}
|
|
1727
|
-
return new Text(text, 0, 0);
|
|
1728
|
-
},
|
|
1729
|
-
});
|
|
1703
|
+
},
|
|
1704
|
+
renderCall(args, theme) {
|
|
1705
|
+
const action = typeof args.action === "string" ? args.action : "intercom";
|
|
1706
|
+
const target = typeof args.to === "string" && args.to.trim() ? args.to.trim() : undefined;
|
|
1707
|
+
const messagePreview = previewText(args.message, 96);
|
|
1708
|
+
const attachmentCount = Array.isArray(args.attachments) ? args.attachments.length : 0;
|
|
1709
|
+
let text = theme.fg("toolTitle", theme.bold("intercom "));
|
|
1710
|
+
text += theme.fg(action === "ask" ? "warning" : action === "reply" ? "success" : "accent", action);
|
|
1711
|
+
if (target) {
|
|
1712
|
+
text += " " + theme.fg("muted", "→") + " " + theme.fg("accent", target);
|
|
1713
|
+
}
|
|
1714
|
+
if (attachmentCount > 0) {
|
|
1715
|
+
text += " " + theme.fg("dim", `(${attachmentCount} attachment${attachmentCount === 1 ? "" : "s"})`);
|
|
1716
|
+
}
|
|
1717
|
+
if (messagePreview) {
|
|
1718
|
+
text += "\n " + theme.fg("dim", messagePreview);
|
|
1719
|
+
}
|
|
1720
|
+
return new Text(text, 0, 0);
|
|
1721
|
+
},
|
|
1722
|
+
renderResult(result, { isPartial }, theme, context) {
|
|
1723
|
+
if (isPartial) {
|
|
1724
|
+
return new Text(theme.fg("warning", "Intercom working..."), 0, 0);
|
|
1725
|
+
}
|
|
1726
|
+
const details = result.details;
|
|
1727
|
+
const failed = Boolean(context.isError || details?.error === true || details?.delivered === false);
|
|
1728
|
+
let text = failed ? theme.fg("error", "✗ ") : theme.fg("success", "✓ ");
|
|
1729
|
+
text += theme.fg(failed ? "error" : "text", firstTextContent(result));
|
|
1730
|
+
if (details?.messageId && !context.expanded) {
|
|
1731
|
+
text += theme.fg("dim", ` (${details.messageId.slice(0, 8)})`);
|
|
1732
|
+
}
|
|
1733
|
+
if (details?.reason && context.expanded) {
|
|
1734
|
+
text += "\n" + theme.fg("dim", `Reason: ${details.reason}`);
|
|
1735
|
+
}
|
|
1736
|
+
return new Text(text, 0, 0);
|
|
1737
|
+
},
|
|
1738
|
+
});
|
|
1730
1739
|
async function openIntercomOverlay(ctx) {
|
|
1731
1740
|
const overlayGeneration = runtimeGeneration;
|
|
1732
1741
|
const liveContext = getLiveContext(ctx, overlayGeneration);
|