@geminixiang/mikan 1.0.0-beta.76 → 1.0.0-beta.78
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 +39 -0
- package/dist/adapters/commands/login.d.ts.map +1 -1
- package/dist/adapters/commands/login.js +0 -9
- package/dist/adapters/commands/login.js.map +1 -1
- package/dist/adapters/commands/manifest.d.ts +0 -19
- package/dist/adapters/commands/manifest.d.ts.map +1 -1
- package/dist/adapters/commands/manifest.js +0 -34
- package/dist/adapters/commands/manifest.js.map +1 -1
- package/dist/adapters/commands/model.d.ts +0 -5
- package/dist/adapters/commands/model.d.ts.map +1 -1
- package/dist/adapters/commands/model.js +0 -5
- package/dist/adapters/commands/model.js.map +1 -1
- package/dist/adapters/commands/new.d.ts.map +1 -1
- package/dist/adapters/commands/new.js +0 -2
- package/dist/adapters/commands/new.js.map +1 -1
- package/dist/adapters/commands/registry.d.ts +0 -1
- package/dist/adapters/commands/registry.d.ts.map +1 -1
- package/dist/adapters/commands/registry.js +0 -8
- package/dist/adapters/commands/registry.js.map +1 -1
- package/dist/adapters/commands/session-view.d.ts.map +1 -1
- package/dist/adapters/commands/session-view.js +0 -2
- package/dist/adapters/commands/session-view.js.map +1 -1
- package/dist/adapters/commands/types.d.ts +0 -29
- package/dist/adapters/commands/types.d.ts.map +1 -1
- package/dist/adapters/commands/types.js.map +1 -1
- package/dist/adapters/commands/utils.d.ts +0 -3
- package/dist/adapters/commands/utils.d.ts.map +1 -1
- package/dist/adapters/commands/utils.js +0 -3
- package/dist/adapters/commands/utils.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +0 -4
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +5 -41
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/components.d.ts +0 -23
- package/dist/adapters/discord/components.d.ts.map +1 -1
- package/dist/adapters/discord/components.js +0 -23
- package/dist/adapters/discord/components.js.map +1 -1
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +1 -11
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/discord/format.d.ts +0 -1
- package/dist/adapters/discord/format.d.ts.map +1 -1
- package/dist/adapters/discord/format.js +0 -37
- package/dist/adapters/discord/format.js.map +1 -1
- package/dist/adapters/github/bot.d.ts +0 -44
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +1 -120
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/client.d.ts +0 -57
- package/dist/adapters/github/client.d.ts.map +1 -1
- package/dist/adapters/github/client.js +0 -59
- package/dist/adapters/github/client.js.map +1 -1
- package/dist/adapters/github/context.d.ts.map +1 -1
- package/dist/adapters/github/context.js +1 -8
- package/dist/adapters/github/context.js.map +1 -1
- package/dist/adapters/github/github-ops.d.ts +0 -55
- package/dist/adapters/github/github-ops.d.ts.map +1 -1
- package/dist/adapters/github/github-ops.js +0 -59
- package/dist/adapters/github/github-ops.js.map +1 -1
- package/dist/adapters/github/ids.d.ts +0 -27
- package/dist/adapters/github/ids.d.ts.map +1 -1
- package/dist/adapters/github/ids.js +0 -29
- package/dist/adapters/github/ids.js.map +1 -1
- package/dist/adapters/github/repo.d.ts +0 -25
- package/dist/adapters/github/repo.d.ts.map +1 -1
- package/dist/adapters/github/repo.js +0 -49
- package/dist/adapters/github/repo.js.map +1 -1
- package/dist/adapters/github/tool-pack.d.ts +0 -10
- package/dist/adapters/github/tool-pack.d.ts.map +1 -1
- package/dist/adapters/github/tool-pack.js +0 -10
- package/dist/adapters/github/tool-pack.js.map +1 -1
- package/dist/adapters/github/tools/checks.d.ts +0 -6
- package/dist/adapters/github/tools/checks.d.ts.map +1 -1
- package/dist/adapters/github/tools/checks.js +0 -7
- package/dist/adapters/github/tools/checks.js.map +1 -1
- package/dist/adapters/github/tools/issue.d.ts +0 -5
- package/dist/adapters/github/tools/issue.d.ts.map +1 -1
- package/dist/adapters/github/tools/issue.js +0 -5
- package/dist/adapters/github/tools/issue.js.map +1 -1
- package/dist/adapters/github/tools/pr.d.ts +0 -7
- package/dist/adapters/github/tools/pr.d.ts.map +1 -1
- package/dist/adapters/github/tools/pr.js +0 -7
- package/dist/adapters/github/tools/pr.js.map +1 -1
- package/dist/adapters/github/tools/read.d.ts +0 -6
- package/dist/adapters/github/tools/read.d.ts.map +1 -1
- package/dist/adapters/github/tools/read.js +0 -8
- package/dist/adapters/github/tools/read.js.map +1 -1
- package/dist/adapters/github/tools/review-reply.d.ts +0 -5
- package/dist/adapters/github/tools/review-reply.d.ts.map +1 -1
- package/dist/adapters/github/tools/review-reply.js +0 -5
- package/dist/adapters/github/tools/review-reply.js.map +1 -1
- package/dist/adapters/github/tools/sync.d.ts +0 -6
- package/dist/adapters/github/tools/sync.d.ts.map +1 -1
- package/dist/adapters/github/tools/sync.js +0 -6
- package/dist/adapters/github/tools/sync.js.map +1 -1
- package/dist/adapters/github/types.d.ts +0 -88
- package/dist/adapters/github/types.d.ts.map +1 -1
- package/dist/adapters/github/types.js.map +1 -1
- package/dist/adapters/github/webhook.d.ts +0 -13
- package/dist/adapters/github/webhook.d.ts.map +1 -1
- package/dist/adapters/github/webhook.js +0 -16
- package/dist/adapters/github/webhook.js.map +1 -1
- package/dist/adapters/index.d.ts +3 -4
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/intake.d.ts +0 -17
- package/dist/adapters/intake.d.ts.map +1 -1
- package/dist/adapters/intake.js +6 -32
- package/dist/adapters/intake.js.map +1 -1
- package/dist/adapters/markdown-tables.d.ts +0 -10
- package/dist/adapters/markdown-tables.d.ts.map +1 -1
- package/dist/adapters/markdown-tables.js +1 -42
- package/dist/adapters/markdown-tables.js.map +1 -1
- package/dist/adapters/progressive-renderer.d.ts.map +1 -1
- package/dist/adapters/progressive-renderer.js +3 -25
- package/dist/adapters/progressive-renderer.js.map +1 -1
- package/dist/adapters/shared.d.ts +0 -57
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +0 -71
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/slack/assistant.d.ts +0 -49
- package/dist/adapters/slack/assistant.d.ts.map +1 -1
- package/dist/adapters/slack/assistant.js +0 -97
- package/dist/adapters/slack/assistant.js.map +1 -1
- package/dist/adapters/slack/auto-reply-context.d.ts +0 -7
- package/dist/adapters/slack/auto-reply-context.d.ts.map +1 -1
- package/dist/adapters/slack/auto-reply-context.js +0 -7
- package/dist/adapters/slack/auto-reply-context.js.map +1 -1
- package/dist/adapters/slack/blocks.d.ts +0 -9
- package/dist/adapters/slack/blocks.d.ts.map +1 -1
- package/dist/adapters/slack/blocks.js +0 -20
- package/dist/adapters/slack/blocks.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +0 -116
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +7 -231
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +1 -3
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/jev-context.d.ts +0 -13
- package/dist/adapters/slack/jev-context.d.ts.map +1 -1
- package/dist/adapters/slack/jev-context.js +0 -12
- package/dist/adapters/slack/jev-context.js.map +1 -1
- package/dist/adapters/slack/markdown.d.ts +0 -1
- package/dist/adapters/slack/markdown.d.ts.map +1 -1
- package/dist/adapters/slack/markdown.js +0 -5
- package/dist/adapters/slack/markdown.js.map +1 -1
- package/dist/adapters/slack/persona.d.ts +0 -9
- package/dist/adapters/slack/persona.d.ts.map +1 -1
- package/dist/adapters/slack/persona.js +0 -9
- package/dist/adapters/slack/persona.js.map +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +1 -45
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/session.d.ts +2 -1
- package/dist/adapters/slack/session.d.ts.map +1 -1
- package/dist/adapters/slack/session.js +2 -2
- package/dist/adapters/slack/session.js.map +1 -1
- package/dist/adapters/slack/stream-limits.d.ts +0 -25
- package/dist/adapters/slack/stream-limits.d.ts.map +1 -1
- package/dist/adapters/slack/stream-limits.js +0 -34
- package/dist/adapters/slack/stream-limits.js.map +1 -1
- package/dist/adapters/slack/task-intent.d.ts +0 -13
- package/dist/adapters/slack/task-intent.d.ts.map +1 -1
- package/dist/adapters/slack/task-intent.js +0 -7
- package/dist/adapters/slack/task-intent.js.map +1 -1
- package/dist/adapters/slack/task-status.d.ts +0 -1
- package/dist/adapters/slack/task-status.d.ts.map +1 -1
- package/dist/adapters/slack/task-status.js +1 -9
- package/dist/adapters/slack/task-status.js.map +1 -1
- package/dist/adapters/slack/tool-pack.d.ts +0 -6
- package/dist/adapters/slack/tool-pack.d.ts.map +1 -1
- package/dist/adapters/slack/tool-pack.js +0 -6
- package/dist/adapters/slack/tool-pack.js.map +1 -1
- package/dist/adapters/slack/tools/blockkit.d.ts.map +1 -1
- package/dist/adapters/slack/tools/blockkit.js +0 -11
- package/dist/adapters/slack/tools/blockkit.js.map +1 -1
- package/dist/adapters/slack/types.d.ts +0 -19
- package/dist/adapters/slack/types.d.ts.map +1 -1
- package/dist/adapters/slack/types.js.map +1 -1
- package/dist/adapters/slack/update-diagnostics.d.ts +0 -1
- package/dist/adapters/slack/update-diagnostics.d.ts.map +1 -1
- package/dist/adapters/slack/update-diagnostics.js +1 -7
- package/dist/adapters/slack/update-diagnostics.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +0 -6
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +1 -50
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +1 -8
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/types.d.ts +0 -57
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/web/admin/client-assets.d.ts +4 -0
- package/dist/adapters/web/admin/client-assets.d.ts.map +1 -0
- package/dist/adapters/web/admin/client-assets.js +1765 -0
- package/dist/adapters/web/admin/client-assets.js.map +1 -0
- package/dist/adapters/web/admin/portal.d.ts +0 -10
- package/dist/adapters/web/admin/portal.d.ts.map +1 -1
- package/dist/adapters/web/admin/portal.js +6 -1909
- package/dist/adapters/web/admin/portal.js.map +1 -1
- package/dist/adapters/web/admin/types.d.ts +0 -3
- package/dist/adapters/web/admin/types.d.ts.map +1 -1
- package/dist/adapters/web/admin/types.js.map +1 -1
- package/dist/adapters/web/login/oauth.d.ts.map +1 -1
- package/dist/adapters/web/login/oauth.js +3 -7
- package/dist/adapters/web/login/oauth.js.map +1 -1
- package/dist/adapters/web/login/portal.d.ts +0 -10
- package/dist/adapters/web/login/portal.d.ts.map +1 -1
- package/dist/adapters/web/login/portal.js +4 -37
- package/dist/adapters/web/login/portal.js.map +1 -1
- package/dist/adapters/web/login/types.d.ts +0 -5
- package/dist/adapters/web/login/types.d.ts.map +1 -1
- package/dist/adapters/web/login/types.js.map +1 -1
- package/dist/adapters/web/portal-shell.d.ts +0 -12
- package/dist/adapters/web/portal-shell.d.ts.map +1 -1
- package/dist/adapters/web/portal-shell.js +8 -25
- package/dist/adapters/web/portal-shell.js.map +1 -1
- package/dist/adapters/web/server.d.ts +0 -1
- package/dist/adapters/web/server.d.ts.map +1 -1
- package/dist/adapters/web/server.js +0 -2
- package/dist/adapters/web/server.js.map +1 -1
- package/dist/adapters/web/session-view/portal.d.ts.map +1 -1
- package/dist/adapters/web/session-view/portal.js +13 -24
- package/dist/adapters/web/session-view/portal.js.map +1 -1
- package/dist/adapters/web/session-view/types.d.ts.map +1 -1
- package/dist/adapters/web/session-view/types.js.map +1 -1
- package/dist/adapters/web/token-store.d.ts +0 -2
- package/dist/adapters/web/token-store.d.ts.map +1 -1
- package/dist/adapters/web/token-store.js +0 -2
- package/dist/adapters/web/token-store.js.map +1 -1
- package/dist/cli/arg-grammar.d.ts +0 -3
- package/dist/cli/arg-grammar.d.ts.map +1 -1
- package/dist/cli/arg-grammar.js +0 -3
- package/dist/cli/arg-grammar.js.map +1 -1
- package/dist/cli/boot.d.ts.map +1 -1
- package/dist/cli/boot.js +3 -12
- package/dist/cli/boot.js.map +1 -1
- package/dist/cli/download.d.ts.map +1 -1
- package/dist/cli/download.js +2 -6
- package/dist/cli/download.js.map +1 -1
- package/dist/cli/office.d.ts.map +1 -1
- package/dist/cli/office.js +0 -31
- package/dist/cli/office.js.map +1 -1
- package/dist/cli/onboard.d.ts +0 -2
- package/dist/cli/onboard.d.ts.map +1 -1
- package/dist/cli/onboard.js +0 -30
- package/dist/cli/onboard.js.map +1 -1
- package/dist/cli/process-lifecycle.d.ts +0 -5
- package/dist/cli/process-lifecycle.d.ts.map +1 -1
- package/dist/cli/process-lifecycle.js +0 -6
- package/dist/cli/process-lifecycle.js.map +1 -1
- package/dist/cli/sandbox.d.ts +3 -0
- package/dist/cli/sandbox.d.ts.map +1 -0
- package/dist/cli/sandbox.js +79 -0
- package/dist/cli/sandbox.js.map +1 -0
- package/dist/cli/sessions.d.ts.map +1 -1
- package/dist/cli/sessions.js +0 -11
- package/dist/cli/sessions.js.map +1 -1
- package/dist/cli/types.d.ts +2 -6
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/env-manifest.d.ts +0 -21
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +0 -11
- package/dist/env-manifest.js.map +1 -1
- package/dist/events/index.d.ts +0 -51
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +0 -42
- package/dist/events/index.js.map +1 -1
- package/dist/events/scheduler.d.ts +0 -8
- package/dist/events/scheduler.d.ts.map +1 -1
- package/dist/events/scheduler.js +0 -8
- package/dist/events/scheduler.js.map +1 -1
- package/dist/file-guards.d.ts +0 -15
- package/dist/file-guards.d.ts.map +1 -1
- package/dist/file-guards.js +2 -26
- package/dist/file-guards.js.map +1 -1
- package/dist/harness/execution-env.d.ts +0 -15
- package/dist/harness/execution-env.d.ts.map +1 -1
- package/dist/harness/execution-env.js +4 -55
- package/dist/harness/execution-env.js.map +1 -1
- package/dist/harness/http.d.ts +0 -12
- package/dist/harness/http.d.ts.map +1 -1
- package/dist/harness/http.js +0 -34
- package/dist/harness/http.js.map +1 -1
- package/dist/harness/index.d.ts +4 -7
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +4 -7
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/jev.d.ts +0 -28
- package/dist/harness/jev.d.ts.map +1 -1
- package/dist/harness/jev.js +0 -45
- package/dist/harness/jev.js.map +1 -1
- package/dist/harness/mcp-result.d.ts +20 -0
- package/dist/harness/mcp-result.d.ts.map +1 -0
- package/dist/harness/mcp-result.js +171 -0
- package/dist/harness/mcp-result.js.map +1 -0
- package/dist/harness/mcp.d.ts +0 -19
- package/dist/harness/mcp.d.ts.map +1 -1
- package/dist/harness/mcp.js +7 -66
- package/dist/harness/mcp.js.map +1 -1
- package/dist/harness/models.d.ts +0 -19
- package/dist/harness/models.d.ts.map +1 -1
- package/dist/harness/models.js +0 -52
- package/dist/harness/models.js.map +1 -1
- package/dist/harness/open-connector.d.ts +0 -12
- package/dist/harness/open-connector.d.ts.map +1 -1
- package/dist/harness/open-connector.js +0 -22
- package/dist/harness/open-connector.js.map +1 -1
- package/dist/harness/presenter.d.ts +1 -0
- package/dist/harness/presenter.d.ts.map +1 -1
- package/dist/harness/presenter.js +16 -66
- package/dist/harness/presenter.js.map +1 -1
- package/dist/harness/prompt.d.ts +0 -11
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js +1 -18
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +8 -28
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session.d.ts +11 -28
- package/dist/harness/session.d.ts.map +1 -1
- package/dist/harness/session.js +100 -38
- package/dist/harness/session.js.map +1 -1
- package/dist/harness/skills.d.ts +0 -22
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +0 -20
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/subagent-profiles.d.ts +0 -4
- package/dist/harness/subagent-profiles.d.ts.map +1 -1
- package/dist/harness/subagent-profiles.js +0 -29
- package/dist/harness/subagent-profiles.js.map +1 -1
- package/dist/harness/subagent.d.ts +0 -25
- package/dist/harness/subagent.d.ts.map +1 -1
- package/dist/harness/subagent.js +1 -70
- package/dist/harness/subagent.js.map +1 -1
- package/dist/harness/tools/event.d.ts.map +1 -1
- package/dist/harness/tools/event.js +0 -9
- package/dist/harness/tools/event.js.map +1 -1
- package/dist/harness/tools/generate-image.d.ts +0 -6
- package/dist/harness/tools/generate-image.d.ts.map +1 -1
- package/dist/harness/tools/generate-image.js.map +1 -1
- package/dist/harness/tools/host-fn-tool.d.ts +0 -17
- package/dist/harness/tools/host-fn-tool.d.ts.map +1 -1
- package/dist/harness/tools/host-fn-tool.js +0 -16
- package/dist/harness/tools/host-fn-tool.js.map +1 -1
- package/dist/harness/tools/index.d.ts +1 -7
- package/dist/harness/tools/index.d.ts.map +1 -1
- package/dist/harness/tools/index.js +3 -14
- package/dist/harness/tools/index.js.map +1 -1
- package/dist/harness/tools/jev-browser.d.ts +4 -94
- package/dist/harness/tools/jev-browser.d.ts.map +1 -1
- package/dist/harness/tools/jev-browser.js +203 -92
- package/dist/harness/tools/jev-browser.js.map +1 -1
- package/dist/harness/tools/jev.d.ts +0 -8
- package/dist/harness/tools/jev.d.ts.map +1 -1
- package/dist/harness/tools/jev.js +0 -11
- package/dist/harness/tools/jev.js.map +1 -1
- package/dist/harness/tools/pi-tools.d.ts +1 -11
- package/dist/harness/tools/pi-tools.d.ts.map +1 -1
- package/dist/harness/tools/pi-tools.js +1 -30
- package/dist/harness/tools/pi-tools.js.map +1 -1
- package/dist/harness/tools/react.d.ts +0 -5
- package/dist/harness/tools/react.d.ts.map +1 -1
- package/dist/harness/tools/react.js +0 -5
- package/dist/harness/tools/react.js.map +1 -1
- package/dist/harness/tools/secret-redaction.d.ts +0 -25
- package/dist/harness/tools/secret-redaction.d.ts.map +1 -1
- package/dist/harness/tools/secret-redaction.js +3 -36
- package/dist/harness/tools/secret-redaction.js.map +1 -1
- package/dist/harness/tools/subagent.d.ts +0 -34
- package/dist/harness/tools/subagent.d.ts.map +1 -1
- package/dist/harness/tools/subagent.js +0 -92
- package/dist/harness/tools/subagent.js.map +1 -1
- package/dist/harness/tools/task.d.ts +0 -1
- package/dist/harness/tools/task.d.ts.map +1 -1
- package/dist/harness/tools/task.js +0 -1
- package/dist/harness/tools/task.js.map +1 -1
- package/dist/harness/tools/types.d.ts +0 -16
- package/dist/harness/tools/types.d.ts.map +1 -1
- package/dist/harness/tools/types.js.map +1 -1
- package/dist/harness/types.d.ts +1 -77
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +0 -13
- package/dist/log.js.map +1 -1
- package/dist/main.js +7 -52
- package/dist/main.js.map +1 -1
- package/dist/memory-capture/index.d.ts +16 -0
- package/dist/memory-capture/index.d.ts.map +1 -0
- package/dist/memory-capture/index.js +194 -0
- package/dist/memory-capture/index.js.map +1 -0
- package/dist/memory-capture/types.d.ts +27 -0
- package/dist/memory-capture/types.d.ts.map +1 -0
- package/dist/memory-capture/types.js.map +1 -0
- package/dist/observability/index.d.ts +0 -9
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +0 -9
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/instrument.js +0 -5
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/otel.js +0 -1
- package/dist/observability/otel.js.map +1 -1
- package/dist/observability/sentry.d.ts +0 -18
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +0 -36
- package/dist/observability/sentry.js.map +1 -1
- package/dist/observability/types.d.ts +1 -10
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/observability/types.js.map +1 -1
- package/dist/office/index.d.ts +0 -76
- package/dist/office/index.d.ts.map +1 -1
- package/dist/office/index.js +4 -154
- package/dist/office/index.js.map +1 -1
- package/dist/office/projection.d.ts +0 -29
- package/dist/office/projection.d.ts.map +1 -1
- package/dist/office/projection.js +5 -41
- package/dist/office/projection.js.map +1 -1
- package/dist/office/types.d.ts +0 -66
- package/dist/office/types.d.ts.map +1 -1
- package/dist/office/types.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +22 -83
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +0 -10
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js +0 -12
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -29
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sandbox/cloudflare.d.ts.map +1 -1
- package/dist/sandbox/cloudflare.js +2 -1
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +21 -15
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +0 -2
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/identity.d.ts +0 -28
- package/dist/sandbox/identity.d.ts.map +1 -1
- package/dist/sandbox/identity.js +0 -28
- package/dist/sandbox/identity.js.map +1 -1
- package/dist/sandbox/index.d.ts +0 -18
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +2 -19
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/layout.d.ts +7 -0
- package/dist/sandbox/layout.d.ts.map +1 -0
- package/dist/sandbox/layout.js +13 -0
- package/dist/sandbox/layout.js.map +1 -0
- package/dist/sandbox/provisioner.d.ts +24 -65
- package/dist/sandbox/provisioner.d.ts.map +1 -1
- package/dist/sandbox/provisioner.js +213 -125
- package/dist/sandbox/provisioner.js.map +1 -1
- package/dist/sandbox/types.d.ts +0 -39
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +2 -5
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +31 -31
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts +0 -6
- package/dist/sessions/chat-history-sync.d.ts.map +1 -1
- package/dist/sessions/chat-history-sync.js +1 -33
- package/dist/sessions/chat-history-sync.js.map +1 -1
- package/dist/sessions/history-line.d.ts +0 -20
- package/dist/sessions/history-line.d.ts.map +1 -1
- package/dist/sessions/history-line.js +0 -20
- package/dist/sessions/history-line.js.map +1 -1
- package/dist/sessions/migrate-common.d.ts +0 -15
- package/dist/sessions/migrate-common.d.ts.map +1 -1
- package/dist/sessions/migrate-common.js +0 -19
- package/dist/sessions/migrate-common.js.map +1 -1
- package/dist/sessions/migrate-pi-084.d.ts.map +1 -1
- package/dist/sessions/migrate-pi-084.js +0 -7
- package/dist/sessions/migrate-pi-084.js.map +1 -1
- package/dist/sessions/migrate-v3.d.ts +0 -7
- package/dist/sessions/migrate-v3.d.ts.map +1 -1
- package/dist/sessions/migrate-v3.js +1 -67
- package/dist/sessions/migrate-v3.js.map +1 -1
- package/dist/sessions/session-key.d.ts +3 -17
- package/dist/sessions/session-key.d.ts.map +1 -1
- package/dist/sessions/session-key.js +8 -35
- package/dist/sessions/session-key.js.map +1 -1
- package/dist/sessions/session-store.d.ts +1 -7
- package/dist/sessions/session-store.d.ts.map +1 -1
- package/dist/sessions/session-store.js +8 -50
- package/dist/sessions/session-store.js.map +1 -1
- package/dist/sessions/store.d.ts +0 -60
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +0 -113
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +0 -17
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/settings/apply.d.ts +0 -6
- package/dist/settings/apply.d.ts.map +1 -1
- package/dist/settings/apply.js +0 -29
- package/dist/settings/apply.js.map +1 -1
- package/dist/settings/index.d.ts +0 -53
- package/dist/settings/index.d.ts.map +1 -1
- package/dist/settings/index.js +0 -77
- package/dist/settings/index.js.map +1 -1
- package/dist/settings/migrate.d.ts +0 -5
- package/dist/settings/migrate.d.ts.map +1 -1
- package/dist/settings/migrate.js +0 -17
- package/dist/settings/migrate.js.map +1 -1
- package/dist/types.d.ts +9 -159
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vault/index.d.ts +2 -36
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +135 -65
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/types.d.ts +0 -15
- package/dist/vault/types.d.ts.map +1 -1
- package/dist/vault/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/dream/index.d.ts +0 -20
- package/dist/dream/index.d.ts.map +0 -1
- package/dist/dream/index.js +0 -264
- package/dist/dream/index.js.map +0 -1
- package/dist/dream/types.d.ts +0 -30
- package/dist/dream/types.d.ts.map +0 -1
- package/dist/dream/types.js.map +0 -1
- /package/dist/{dream → memory-capture}/types.js +0 -0
|
@@ -1,52 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slack's agent / assistant surface — the app's own pane, separate from
|
|
3
|
-
* channels and ordinary DMs.
|
|
4
|
-
*
|
|
5
|
-
* There are two of these, not one, and they differ in which events signal
|
|
6
|
-
* "someone opened a conversation":
|
|
7
|
-
*
|
|
8
|
-
* | Manifest key | Opened signal | Prompts |
|
|
9
|
-
* | ----------------- | ------------------------------------ | ------------- |
|
|
10
|
-
* | `agent_view` | `app_home_opened` with tab=`messages` | pinned to the DM |
|
|
11
|
-
* | `assistant_view` | `assistant_thread_started` | per thread |
|
|
12
|
-
*
|
|
13
|
-
* Slack's own words for the newer one: "rely on the `app_home_opened` event to
|
|
14
|
-
* know when a user has actively opened a DM with your app", and
|
|
15
|
-
* "the `assistant_thread_started` event no longer indicates this". What the
|
|
16
|
-
* docs do *not* say is whether `assistant_thread_started` still fires for an
|
|
17
|
-
* `agent_view` app — so both paths are handled rather than guessed at, which
|
|
18
|
-
* also means an app on either manifest key works without a migration.
|
|
19
|
-
*
|
|
20
|
-
* The two signals need different behaviour, and conflating them would be a
|
|
21
|
-
* bug: `assistant_thread_started` fires once per new conversation, so greeting
|
|
22
|
-
* is right; `app_home_opened` fires **every time the pane is opened**, so
|
|
23
|
-
* greeting there would nag. The agent path therefore only refreshes the
|
|
24
|
-
* pinned prompts, which is idempotent.
|
|
25
|
-
*
|
|
26
|
-
* Session semantics are deliberately unchanged. Each conversation is a thread
|
|
27
|
-
* and mikan already scopes a thread to its own session — the right shape,
|
|
28
|
-
* because the pane's sidebar is a list of separate conversations rather than
|
|
29
|
-
* one transcript. Continuity across them comes from the office's memory.
|
|
30
|
-
*
|
|
31
|
-
* Suggested prompts are deterministic, varying only with the channel Slack
|
|
32
|
-
* says the person is viewing. Enough to feel aware without spending a model
|
|
33
|
-
* call before they have typed anything.
|
|
34
|
-
*/
|
|
35
1
|
import * as log from "../../log.js";
|
|
36
|
-
/** The `assistant_thread` payload on the `assistant_view` lifecycle events. */
|
|
37
2
|
const GREETING = "有什麼我可以幫忙的?";
|
|
38
3
|
const GREETING_WITH_CHANNEL = (channel) => `有什麼我可以幫忙的?我看得到你正在 #${channel}。`;
|
|
39
|
-
/** Prompts offered with no channel context — general-purpose starting points. */
|
|
40
4
|
const DEFAULT_PROMPTS = [
|
|
41
5
|
{ title: "看看工作區", message: "這個工作區裡有什麼?先給我一個概覽。" },
|
|
42
6
|
{ title: "最近的變更", message: "最近的程式碼變更有哪些?挑重要的說。" },
|
|
43
7
|
{ title: "排一個提醒", message: "幫我排一個每天早上的提醒。" },
|
|
44
8
|
];
|
|
45
|
-
/**
|
|
46
|
-
* Prompts when Slack tells us which channel the person is looking at. Naming
|
|
47
|
-
* the channel is the cheap half of "context-aware": it costs nothing and it is
|
|
48
|
-
* what makes the suggestions feel addressed to the moment.
|
|
49
|
-
*/
|
|
50
9
|
function promptsFor(channel) {
|
|
51
10
|
if (!channel)
|
|
52
11
|
return DEFAULT_PROMPTS;
|
|
@@ -56,18 +15,6 @@ function promptsFor(channel) {
|
|
|
56
15
|
{ title: "看看工作區", message: "這個工作區裡有什麼?先給我一個概覽。" },
|
|
57
16
|
];
|
|
58
17
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Which conversations belong to this surface, and the context Slack last
|
|
61
|
-
* reported for each.
|
|
62
|
-
*
|
|
63
|
-
* Two levels, because the two manifest keys register at different grains: an
|
|
64
|
-
* `agent_view` DM is known before any thread exists, while an
|
|
65
|
-
* `assistant_view` thread is known individually.
|
|
66
|
-
*
|
|
67
|
-
* In memory on purpose: transient UI state that Slack re-sends on open and on
|
|
68
|
-
* every change, so a restart self-heals on the next interaction. Persisting it
|
|
69
|
-
* would add a store to keep consistent for nothing that survives the trip.
|
|
70
|
-
*/
|
|
71
18
|
export class AssistantThreadRegistry {
|
|
72
19
|
constructor() {
|
|
73
20
|
this.threads = new Map();
|
|
@@ -77,31 +24,21 @@ export class AssistantThreadRegistry {
|
|
|
77
24
|
key(channelId, threadTs) {
|
|
78
25
|
return `${channelId}\n${threadTs}`;
|
|
79
26
|
}
|
|
80
|
-
/** An `assistant_view` thread. */
|
|
81
27
|
remember(channelId, threadTs, context) {
|
|
82
28
|
this.threads.set(this.key(channelId, threadTs), context ?? {});
|
|
83
29
|
}
|
|
84
|
-
/** An `agent_view` DM, which has no thread yet. */
|
|
85
30
|
rememberChannel(channelId, context) {
|
|
86
31
|
this.channels.set(channelId, context ?? {});
|
|
87
32
|
}
|
|
88
|
-
/** Thread context, falling back to the channel's. */
|
|
89
33
|
contextFor(channelId, threadTs) {
|
|
90
34
|
return this.threads.get(this.key(channelId, threadTs)) ?? this.channels.get(channelId);
|
|
91
35
|
}
|
|
92
36
|
channelContext(channelId) {
|
|
93
37
|
return this.channels.get(channelId);
|
|
94
38
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Whether this thread is part of the pane — either registered individually,
|
|
97
|
-
* or living in a DM known to be the agent surface. The second case is what
|
|
98
|
-
* makes titles work under `agent_view`, where Slack opens threads itself and
|
|
99
|
-
* never announces them.
|
|
100
|
-
*/
|
|
101
39
|
isAgentSurface(channelId, threadTs) {
|
|
102
40
|
return this.threads.has(this.key(channelId, threadTs)) || this.channels.has(channelId);
|
|
103
41
|
}
|
|
104
|
-
/** True the first time a thread is seen, so a title is set exactly once. */
|
|
105
42
|
claimTitle(channelId, threadTs) {
|
|
106
43
|
const key = this.key(channelId, threadTs);
|
|
107
44
|
if (this.titled.has(key))
|
|
@@ -110,14 +47,6 @@ export class AssistantThreadRegistry {
|
|
|
110
47
|
return true;
|
|
111
48
|
}
|
|
112
49
|
}
|
|
113
|
-
/**
|
|
114
|
-
* `assistant_view`: a new conversation opened. Greet, and offer prompts for
|
|
115
|
-
* that thread.
|
|
116
|
-
*
|
|
117
|
-
* Failures are logged, never thrown. A greeting that did not post is a worse
|
|
118
|
-
* pane, not a broken conversation, and taking the socket handler down over it
|
|
119
|
-
* would break the surface entirely.
|
|
120
|
-
*/
|
|
121
50
|
export async function handleAssistantThreadStarted(ops, registry, thread) {
|
|
122
51
|
const channelId = thread.channel_id;
|
|
123
52
|
const threadTs = thread.thread_ts;
|
|
@@ -130,34 +59,17 @@ export async function handleAssistantThreadStarted(ops, registry, thread) {
|
|
|
130
59
|
await swallow("greeting", () => ops.postInThread(channelId, threadTs, channel ? GREETING_WITH_CHANNEL(channel) : GREETING));
|
|
131
60
|
await swallow("setSuggestedPrompts", () => ops.setSuggestedPrompts(channelId, threadTs, promptsFor(channel)));
|
|
132
61
|
}
|
|
133
|
-
/**
|
|
134
|
-
* `agent_view`: the person opened the app's DM. Refresh the prompts pinned to
|
|
135
|
-
* it — and deliberately do not greet, because Slack sends this on *every*
|
|
136
|
-
* open, so a greeting here would arrive again and again.
|
|
137
|
-
*/
|
|
138
62
|
export async function handleAgentDmOpened(ops, registry, channelId, context) {
|
|
139
63
|
if (!channelId)
|
|
140
64
|
return;
|
|
141
65
|
registry.rememberChannel(channelId, context);
|
|
142
66
|
const channel = context?.channel_id ? ops.channelName(context.channel_id) : undefined;
|
|
143
|
-
// The agent surface is otherwise silent, and its failure mode — no prompts,
|
|
144
|
-
// untitled conversations — looks identical from the outside to Slack simply
|
|
145
|
-
// not sending the event. This line is the difference between the two, and
|
|
146
|
-
// is the first thing to look for when the pane seems inert.
|
|
147
67
|
log.logInfo(`[${channelId}] Slack agent DM opened${channel ? ` (viewing #${channel})` : ""}; refreshing suggested prompts`);
|
|
148
68
|
await swallow("setSuggestedPrompts", () => ops.setSuggestedPrompts(channelId, undefined, promptsFor(channel)));
|
|
149
69
|
}
|
|
150
|
-
/**
|
|
151
|
-
* The person navigated elsewhere. Recorded at both grains so the next turn —
|
|
152
|
-
* and the next prompt refresh — knows where they are, whichever manifest key
|
|
153
|
-
* this app uses.
|
|
154
|
-
*/
|
|
155
70
|
export function handleAgentContextChanged(registry, payload) {
|
|
156
71
|
if (!payload.channel_id)
|
|
157
72
|
return;
|
|
158
|
-
// Logged for the same reason as the open event: these two are the whole
|
|
159
|
-
// agent surface, and whether either is subscribed is otherwise invisible
|
|
160
|
-
// from inside mikan.
|
|
161
73
|
log.logInfo(`[${payload.channel_id}] Slack agent context changed${payload.context?.channel_id ? ` (viewing ${payload.context.channel_id})` : ""}`);
|
|
162
74
|
if (payload.thread_ts) {
|
|
163
75
|
registry.remember(payload.channel_id, payload.thread_ts, payload.context);
|
|
@@ -165,10 +77,6 @@ export function handleAgentContextChanged(registry, payload) {
|
|
|
165
77
|
}
|
|
166
78
|
registry.rememberChannel(payload.channel_id, payload.context);
|
|
167
79
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Title a conversation from the first thing the person said, so the pane's
|
|
170
|
-
* sidebar is navigable. Without it every past conversation looks the same.
|
|
171
|
-
*/
|
|
172
80
|
export async function titleAssistantThread(ops, registry, channelId, threadTs, firstMessage) {
|
|
173
81
|
if (!registry.isAgentSurface(channelId, threadTs))
|
|
174
82
|
return;
|
|
@@ -179,11 +87,6 @@ export async function titleAssistantThread(ops, registry, channelId, threadTs, f
|
|
|
179
87
|
return;
|
|
180
88
|
await swallow("setTitle", () => ops.setTitle(channelId, threadTs, title));
|
|
181
89
|
}
|
|
182
|
-
/**
|
|
183
|
-
* First line, trimmed to something a sidebar can show. Deliberately not a
|
|
184
|
-
* model call: a title is worth having immediately and cheaply, and the
|
|
185
|
-
* person's own words label the conversation better than a paraphrase.
|
|
186
|
-
*/
|
|
187
90
|
export function summarizeTitle(message) {
|
|
188
91
|
const firstLine = message
|
|
189
92
|
.replace(/<@[^>]+>/g, "")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../../src/adapters/slack/assistant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAepC,+EAA+E;AAC/E,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,EAAE,CAChD,sBAAsB,OAAO,GAAG,CAAC;AAEnC,iFAAiF;AACjF,MAAM,eAAe,GAAsB;IACzC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE;IACjD,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE;IACjD,EAAE,KAAK,EAAE,OAAO,E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AC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,OAAO,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;AAC3E,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,KAAa,EAAE,GAA2B;IAC/D,IAAI,CAAC;QACH,MAAM,GAAG,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,UAAU,CACZ,uBAAuB,KAAK,SAAS,EACrC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Slack's agent / assistant surface — the app's own pane, separate from\n * channels and ordinary DMs.\n *\n * There are two of these, not one, and they differ in which events signal\n * \"someone opened a conversation\":\n *\n * | Manifest key | Opened signal | Prompts |\n * | ----------------- | ------------------------------------ | ------------- |\n * | `agent_view` | `app_home_opened` with tab=`messages` | pinned to the DM |\n * | `assistant_view` | `assistant_thread_started` | per thread |\n *\n * Slack's own words for the newer one: \"rely on the `app_home_opened` event to\n * know when a user has actively opened a DM with your app\", and\n * \"the `assistant_thread_started` event no longer indicates this\". What the\n * docs do *not* say is whether `assistant_thread_started` still fires for an\n * `agent_view` app — so both paths are handled rather than guessed at, which\n * also means an app on either manifest key works without a migration.\n *\n * The two signals need different behaviour, and conflating them would be a\n * bug: `assistant_thread_started` fires once per new conversation, so greeting\n * is right; `app_home_opened` fires **every time the pane is opened**, so\n * greeting there would nag. The agent path therefore only refreshes the\n * pinned prompts, which is idempotent.\n *\n * Session semantics are deliberately unchanged. Each conversation is a thread\n * and mikan already scopes a thread to its own session — the right shape,\n * because the pane's sidebar is a list of separate conversations rather than\n * one transcript. Continuity across them comes from the office's memory.\n *\n * Suggested prompts are deterministic, varying only with the channel Slack\n * says the person is viewing. Enough to feel aware without spending a model\n * call before they have typed anything.\n */\nimport * as log from \"../../log.js\";\nimport type {\n AgentContext,\n AssistantSurfaceOps,\n AssistantThreadPayload,\n SuggestedPrompt,\n} from \"./types.js\";\n\nexport type {\n AgentContext,\n AssistantSurfaceOps,\n AssistantThreadPayload,\n SuggestedPrompt,\n} from \"./types.js\";\n\n/** The `assistant_thread` payload on the `assistant_view` lifecycle events. */\nconst GREETING = \"有什麼我可以幫忙的?\";\nconst GREETING_WITH_CHANNEL = (channel: string) =>\n `有什麼我可以幫忙的?我看得到你正在 #${channel}。`;\n\n/** Prompts offered with no channel context — general-purpose starting points. */\nconst DEFAULT_PROMPTS: SuggestedPrompt[] = [\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n { title: \"最近的變更\", message: \"最近的程式碼變更有哪些?挑重要的說。\" },\n { title: \"排一個提醒\", message: \"幫我排一個每天早上的提醒。\" },\n];\n\n/**\n * Prompts when Slack tells us which channel the person is looking at. Naming\n * the channel is the cheap half of \"context-aware\": it costs nothing and it is\n * what makes the suggestions feel addressed to the moment.\n */\nfunction promptsFor(channel: string | undefined): SuggestedPrompt[] {\n if (!channel) return DEFAULT_PROMPTS;\n return [\n { title: `#${channel} 在討論什麼`, message: `幫我摘要 #${channel} 最近的討論。` },\n { title: \"有什麼要我接手\", message: `#${channel} 裡有沒有需要我處理或追蹤的事?` },\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n ];\n}\n\n/**\n * Which conversations belong to this surface, and the context Slack last\n * reported for each.\n *\n * Two levels, because the two manifest keys register at different grains: an\n * `agent_view` DM is known before any thread exists, while an\n * `assistant_view` thread is known individually.\n *\n * In memory on purpose: transient UI state that Slack re-sends on open and on\n * every change, so a restart self-heals on the next interaction. Persisting it\n * would add a store to keep consistent for nothing that survives the trip.\n */\nexport class AssistantThreadRegistry {\n private threads = new Map<string, AgentContext>();\n private channels = new Map<string, AgentContext>();\n private titled = new Set<string>();\n\n private key(channelId: string, threadTs: string): string {\n return `${channelId}\\n${threadTs}`;\n }\n\n /** An `assistant_view` thread. */\n remember(channelId: string, threadTs: string, context?: AgentContext): void {\n this.threads.set(this.key(channelId, threadTs), context ?? {});\n }\n\n /** An `agent_view` DM, which has no thread yet. */\n rememberChannel(channelId: string, context?: AgentContext): void {\n this.channels.set(channelId, context ?? {});\n }\n\n /** Thread context, falling back to the channel's. */\n contextFor(channelId: string, threadTs: string): AgentContext | undefined {\n return this.threads.get(this.key(channelId, threadTs)) ?? this.channels.get(channelId);\n }\n\n channelContext(channelId: string): AgentContext | undefined {\n return this.channels.get(channelId);\n }\n\n /**\n * Whether this thread is part of the pane — either registered individually,\n * or living in a DM known to be the agent surface. The second case is what\n * makes titles work under `agent_view`, where Slack opens threads itself and\n * never announces them.\n */\n isAgentSurface(channelId: string, threadTs: string): boolean {\n return this.threads.has(this.key(channelId, threadTs)) || this.channels.has(channelId);\n }\n\n /** True the first time a thread is seen, so a title is set exactly once. */\n claimTitle(channelId: string, threadTs: string): boolean {\n const key = this.key(channelId, threadTs);\n if (this.titled.has(key)) return false;\n this.titled.add(key);\n return true;\n }\n}\n\n/**\n * `assistant_view`: a new conversation opened. Greet, and offer prompts for\n * that thread.\n *\n * Failures are logged, never thrown. A greeting that did not post is a worse\n * pane, not a broken conversation, and taking the socket handler down over it\n * would break the surface entirely.\n */\nexport async function handleAssistantThreadStarted(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n thread: AssistantThreadPayload,\n): Promise<void> {\n const channelId = thread.channel_id;\n const threadTs = thread.thread_ts;\n if (!channelId || !threadTs) return;\n\n registry.remember(channelId, threadTs, thread.context);\n const channel = thread.context?.channel_id\n ? ops.channelName(thread.context.channel_id)\n : undefined;\n\n await swallow(\"greeting\", () =>\n ops.postInThread(channelId, threadTs, channel ? GREETING_WITH_CHANNEL(channel) : GREETING),\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, threadTs, promptsFor(channel)),\n );\n}\n\n/**\n * `agent_view`: the person opened the app's DM. Refresh the prompts pinned to\n * it — and deliberately do not greet, because Slack sends this on *every*\n * open, so a greeting here would arrive again and again.\n */\nexport async function handleAgentDmOpened(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n context?: AgentContext,\n): Promise<void> {\n if (!channelId) return;\n registry.rememberChannel(channelId, context);\n const channel = context?.channel_id ? ops.channelName(context.channel_id) : undefined;\n // The agent surface is otherwise silent, and its failure mode — no prompts,\n // untitled conversations — looks identical from the outside to Slack simply\n // not sending the event. This line is the difference between the two, and\n // is the first thing to look for when the pane seems inert.\n log.logInfo(\n `[${channelId}] Slack agent DM opened${channel ? ` (viewing #${channel})` : \"\"}; refreshing suggested prompts`,\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, undefined, promptsFor(channel)),\n );\n}\n\n/**\n * The person navigated elsewhere. Recorded at both grains so the next turn —\n * and the next prompt refresh — knows where they are, whichever manifest key\n * this app uses.\n */\nexport function handleAgentContextChanged(\n registry: AssistantThreadRegistry,\n payload: { channel_id?: string; thread_ts?: string; context?: AgentContext },\n): void {\n if (!payload.channel_id) return;\n // Logged for the same reason as the open event: these two are the whole\n // agent surface, and whether either is subscribed is otherwise invisible\n // from inside mikan.\n log.logInfo(\n `[${payload.channel_id}] Slack agent context changed${payload.context?.channel_id ? ` (viewing ${payload.context.channel_id})` : \"\"}`,\n );\n if (payload.thread_ts) {\n registry.remember(payload.channel_id, payload.thread_ts, payload.context);\n return;\n }\n registry.rememberChannel(payload.channel_id, payload.context);\n}\n\n/**\n * Title a conversation from the first thing the person said, so the pane's\n * sidebar is navigable. Without it every past conversation looks the same.\n */\nexport async function titleAssistantThread(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n threadTs: string,\n firstMessage: string,\n): Promise<void> {\n if (!registry.isAgentSurface(channelId, threadTs)) return;\n if (!registry.claimTitle(channelId, threadTs)) return;\n const title = summarizeTitle(firstMessage);\n if (!title) return;\n await swallow(\"setTitle\", () => ops.setTitle(channelId, threadTs, title));\n}\n\n/**\n * First line, trimmed to something a sidebar can show. Deliberately not a\n * model call: a title is worth having immediately and cheaply, and the\n * person's own words label the conversation better than a paraphrase.\n */\nexport function summarizeTitle(message: string): string {\n const firstLine = message\n .replace(/<@[^>]+>/g, \"\")\n .split(\"\\n\")\n .map((line) => line.trim())\n .find((line) => line.length > 0);\n if (!firstLine) return \"\";\n return firstLine.length <= 50 ? firstLine : `${firstLine.slice(0, 49)}…`;\n}\n\nasync function swallow(label: string, run: () => Promise<unknown>): Promise<void> {\n try {\n await run();\n } catch (err) {\n log.logWarning(\n `Slack agent surface ${label} failed`,\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../../src/adapters/slack/assistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAepC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,EAAE,CAChD,sBAAsB,OAAO,GAAG,CAAC;AAEnC,MAAM,eAAe,GAAsB;IACzC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE;IACjD,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE;IACjD,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE;CAC7C,CAAC;AAEF,SAAS,UAAU,CAAC,OAA2B;IAC7C,IAAI,CAAC,OAAO;QAAE,OAAO,eAAe,CAAC;IACrC,OAAO;QACL,EAAE,KAAK,EAAE,IAAI,OAAO,QAAQ,EAAE,OAAO,EAAE,SAAS,OAAO,SAAS,EAAE;QACl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M,CAAC,GAAG,CAAC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import * as log from \"../../log.js\";\nimport type {\n AgentContext,\n AssistantSurfaceOps,\n AssistantThreadPayload,\n SuggestedPrompt,\n} from \"./types.js\";\n\nexport type {\n AgentContext,\n AssistantSurfaceOps,\n AssistantThreadPayload,\n SuggestedPrompt,\n} from \"./types.js\";\n\nconst GREETING = \"有什麼我可以幫忙的?\";\nconst GREETING_WITH_CHANNEL = (channel: string) =>\n `有什麼我可以幫忙的?我看得到你正在 #${channel}。`;\n\nconst DEFAULT_PROMPTS: SuggestedPrompt[] = [\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n { title: \"最近的變更\", message: \"最近的程式碼變更有哪些?挑重要的說。\" },\n { title: \"排一個提醒\", message: \"幫我排一個每天早上的提醒。\" },\n];\n\nfunction promptsFor(channel: string | undefined): SuggestedPrompt[] {\n if (!channel) return DEFAULT_PROMPTS;\n return [\n { title: `#${channel} 在討論什麼`, message: `幫我摘要 #${channel} 最近的討論。` },\n { title: \"有什麼要我接手\", message: `#${channel} 裡有沒有需要我處理或追蹤的事?` },\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n ];\n}\n\nexport class AssistantThreadRegistry {\n private threads = new Map<string, AgentContext>();\n private channels = new Map<string, AgentContext>();\n private titled = new Set<string>();\n\n private key(channelId: string, threadTs: string): string {\n return `${channelId}\\n${threadTs}`;\n }\n\n remember(channelId: string, threadTs: string, context?: AgentContext): void {\n this.threads.set(this.key(channelId, threadTs), context ?? {});\n }\n\n rememberChannel(channelId: string, context?: AgentContext): void {\n this.channels.set(channelId, context ?? {});\n }\n\n contextFor(channelId: string, threadTs: string): AgentContext | undefined {\n return this.threads.get(this.key(channelId, threadTs)) ?? this.channels.get(channelId);\n }\n\n channelContext(channelId: string): AgentContext | undefined {\n return this.channels.get(channelId);\n }\n\n isAgentSurface(channelId: string, threadTs: string): boolean {\n return this.threads.has(this.key(channelId, threadTs)) || this.channels.has(channelId);\n }\n\n claimTitle(channelId: string, threadTs: string): boolean {\n const key = this.key(channelId, threadTs);\n if (this.titled.has(key)) return false;\n this.titled.add(key);\n return true;\n }\n}\n\nexport async function handleAssistantThreadStarted(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n thread: AssistantThreadPayload,\n): Promise<void> {\n const channelId = thread.channel_id;\n const threadTs = thread.thread_ts;\n if (!channelId || !threadTs) return;\n\n registry.remember(channelId, threadTs, thread.context);\n const channel = thread.context?.channel_id\n ? ops.channelName(thread.context.channel_id)\n : undefined;\n\n await swallow(\"greeting\", () =>\n ops.postInThread(channelId, threadTs, channel ? GREETING_WITH_CHANNEL(channel) : GREETING),\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, threadTs, promptsFor(channel)),\n );\n}\n\nexport async function handleAgentDmOpened(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n context?: AgentContext,\n): Promise<void> {\n if (!channelId) return;\n registry.rememberChannel(channelId, context);\n const channel = context?.channel_id ? ops.channelName(context.channel_id) : undefined;\n log.logInfo(\n `[${channelId}] Slack agent DM opened${channel ? ` (viewing #${channel})` : \"\"}; refreshing suggested prompts`,\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, undefined, promptsFor(channel)),\n );\n}\n\nexport function handleAgentContextChanged(\n registry: AssistantThreadRegistry,\n payload: { channel_id?: string; thread_ts?: string; context?: AgentContext },\n): void {\n if (!payload.channel_id) return;\n log.logInfo(\n `[${payload.channel_id}] Slack agent context changed${payload.context?.channel_id ? ` (viewing ${payload.context.channel_id})` : \"\"}`,\n );\n if (payload.thread_ts) {\n registry.remember(payload.channel_id, payload.thread_ts, payload.context);\n return;\n }\n registry.rememberChannel(payload.channel_id, payload.context);\n}\n\nexport async function titleAssistantThread(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n threadTs: string,\n firstMessage: string,\n): Promise<void> {\n if (!registry.isAgentSurface(channelId, threadTs)) return;\n if (!registry.claimTitle(channelId, threadTs)) return;\n const title = summarizeTitle(firstMessage);\n if (!title) return;\n await swallow(\"setTitle\", () => ops.setTitle(channelId, threadTs, title));\n}\n\nexport function summarizeTitle(message: string): string {\n const firstLine = message\n .replace(/<@[^>]+>/g, \"\")\n .split(\"\\n\")\n .map((line) => line.trim())\n .find((line) => line.length > 0);\n if (!firstLine) return \"\";\n return firstLine.length <= 50 ? firstLine : `${firstLine.slice(0, 49)}…`;\n}\n\nasync function swallow(label: string, run: () => Promise<unknown>): Promise<void> {\n try {\n await run();\n } catch (err) {\n log.logWarning(\n `Slack agent surface ${label} failed`,\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n"]}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { type SlackNameResolver } from "./jev-context.js";
|
|
2
|
-
/** The one question Jev answers for an unaddressed shared-channel message. */
|
|
3
2
|
export declare const JEV_ADDRESSED_INSTRUCTIONS = "Given the recent Slack conversation, does the NEW message address, ask, or request the mikan AI assistant to do something (including continuing something mikan was already helping with), rather than being conversation between humans that needs no reply from mikan? A message that @-mentions a specific person other than mikan is directed at that person.";
|
|
4
|
-
/**
|
|
5
|
-
* Build the shared `state` Jev scores when deciding whether an unaddressed
|
|
6
|
-
* shared-channel message is meant for mikan: the surrounding scope plus, for
|
|
7
|
-
* a thread, whether mikan has already taken part in it. Mentions are shown
|
|
8
|
-
* as names so "@someone else" reads as such.
|
|
9
|
-
*/
|
|
10
3
|
export declare function buildAutoReplyState(conversationDir: string, event: {
|
|
11
4
|
ts: string;
|
|
12
5
|
thread_ts?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-reply-context.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/auto-reply-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,
|
|
1
|
+
{"version":3,"file":"auto-reply-context.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/auto-reply-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,0BAA0B,sWAC8T,CAAC;AAEtW,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACrE,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,GACL,MAAM,CAiBR"}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { formatRecentScope, humanizeMentions, readRecentScope, } from "./jev-context.js";
|
|
2
|
-
/** The one question Jev answers for an unaddressed shared-channel message. */
|
|
3
2
|
export const JEV_ADDRESSED_INSTRUCTIONS = "Given the recent Slack conversation, does the NEW message address, ask, or request the mikan AI assistant to do something (including continuing something mikan was already helping with), rather than being conversation between humans that needs no reply from mikan? A message that @-mentions a specific person other than mikan is directed at that person.";
|
|
4
|
-
/**
|
|
5
|
-
* Build the shared `state` Jev scores when deciding whether an unaddressed
|
|
6
|
-
* shared-channel message is meant for mikan: the surrounding scope plus, for
|
|
7
|
-
* a thread, whether mikan has already taken part in it. Mentions are shown
|
|
8
|
-
* as names so "@someone else" reads as such.
|
|
9
|
-
*/
|
|
10
3
|
export function buildAutoReplyState(conversationDir, event, options = {}) {
|
|
11
4
|
const resolve = options.resolveName ?? (() => undefined);
|
|
12
5
|
const humanize = (text) => humanizeMentions(text, resolve, options.botUserId ?? null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-reply-context.js","sourceRoot":"","sources":["../../../src/adapters/slack/auto-reply-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAE1B,
|
|
1
|
+
{"version":3,"file":"auto-reply-context.js","sourceRoot":"","sources":["../../../src/adapters/slack/auto-reply-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,0BAA0B,GACrC,mWAAmW,CAAC;AAEtW,MAAM,UAAU,mBAAmB,CACjC,eAAuB,EACvB,KAAqE,EACrE,OAAO,GAKH,EAAE;IAEN,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;IAC9F,MAAM,MAAM,GAAG,eAAe,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS;QAC5B,CAAC,CAAC,iCAAiC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,aAAa,kBAAkB;QACtH,CAAC,CAAC,kCAAkC,CAAC;IACvC,OAAO;QACL,MAAM;QACN,4EAA4E;QAC5E,EAAE;QACF,iCAAiC;QACjC,iBAAiB,CAAC,MAAM,CAAC;QACzB,EAAE;QACF,oBAAoB,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG;QACpD,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;KACrB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC","sourcesContent":["import {\n formatRecentScope,\n humanizeMentions,\n readRecentScope,\n type SlackNameResolver,\n} from \"./jev-context.js\";\n\nexport const JEV_ADDRESSED_INSTRUCTIONS =\n \"Given the recent Slack conversation, does the NEW message address, ask, or request the mikan AI assistant to do something (including continuing something mikan was already helping with), rather than being conversation between humans that needs no reply from mikan? A message that @-mentions a specific person other than mikan is directed at that person.\";\n\nexport function buildAutoReplyState(\n conversationDir: string,\n event: { ts: string; thread_ts?: string; user: string; text: string },\n options: {\n speaker?: string;\n limit?: number;\n resolveName?: SlackNameResolver;\n botUserId?: string | null;\n } = {},\n): string {\n const resolve = options.resolveName ?? (() => undefined);\n const humanize = (text: string) => humanizeMentions(text, resolve, options.botUserId ?? null);\n const recent = readRecentScope(conversationDir, event, { limit: options.limit, humanize });\n const header = event.thread_ts\n ? `Slack thread reply. mikan has ${recent.some((l) => l.isMikan) ? \"already replied\" : \"not replied\"} in this thread.`\n : \"Slack channel top-level message.\";\n return [\n header,\n \"The AI assistant is named mikan; mentions of other people appear as @Name.\",\n \"\",\n \"Recent messages (oldest first):\",\n formatRecentScope(recent),\n \"\",\n `NEW message from ${options.speaker ?? event.user}:`,\n humanize(event.text),\n ].join(\"\\n\");\n}\n"]}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import type { KnownBlock } from "@slack/types";
|
|
2
|
-
/**
|
|
3
|
-
* Resolve response-source mentions to Slack's native form.
|
|
4
|
-
*
|
|
5
|
-
* The response source is platform-neutral: the model writes `<@userName>`
|
|
6
|
-
* from the prompt's Users table, and the adapter owns the conversion to
|
|
7
|
-
* `<@U…>` — Slack only links and notifies on the raw user id. Lookup covers
|
|
8
|
-
* userName and displayName case-insensitively; native-id mentions pass
|
|
9
|
-
* through, and unknown names stay verbatim rather than guessing.
|
|
10
|
-
*/
|
|
11
2
|
export declare function resolveSlackMentions(source: string, users: Iterable<{
|
|
12
3
|
id: string;
|
|
13
4
|
userName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/blocks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/blocks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAkB/C,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,GACrE,MAAM,CAgBR;AAqDD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CA+BxF"}
|
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
import MarkdownIt from "markdown-it";
|
|
2
2
|
import { normalizeSlackCurrencyBold } from "./markdown.js";
|
|
3
3
|
import { extractMarkdownTables, inlinePlainText, normalizeMarkdownTables, } from "../markdown-tables.js";
|
|
4
|
-
// Parser is used only to locate tables and derive plain-text fallback.
|
|
5
|
-
// Prose is never re-serialized from tokens: it is sliced verbatim from the
|
|
6
|
-
// source and handed to Slack as a native `markdown` block, so Slack owns
|
|
7
|
-
// all prose rendering (same renderer as the markdown_text streaming API).
|
|
8
4
|
const markdown = new MarkdownIt({ html: false });
|
|
9
5
|
const MAX_BLOCKS = 50;
|
|
10
|
-
// Slack rejects messages whose markdown block text exceeds 12k (msg_too_long).
|
|
11
6
|
const MARKDOWN_TEXT_LIMIT = 12000;
|
|
12
7
|
const FIELD_TEXT_LIMIT = 2000;
|
|
13
|
-
// Legacy Slack-style links (<url|label>) predate the standard-GFM response
|
|
14
|
-
// source contract; system producers may still emit them.
|
|
15
8
|
const LEGACY_MRKDWN_LINK_PATTERN = /<(https?:\/\/[^<>|\s]+)\|([^<>\n]+)>/g;
|
|
16
|
-
// Slack user/bot-user ids: U/W prefix. Already-native mentions pass through.
|
|
17
9
|
const SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{2,}$/;
|
|
18
10
|
const MENTION_PATTERN = /<@([^<>\n]+)>/g;
|
|
19
|
-
/**
|
|
20
|
-
* Resolve response-source mentions to Slack's native form.
|
|
21
|
-
*
|
|
22
|
-
* The response source is platform-neutral: the model writes `<@userName>`
|
|
23
|
-
* from the prompt's Users table, and the adapter owns the conversion to
|
|
24
|
-
* `<@U…>` — Slack only links and notifies on the raw user id. Lookup covers
|
|
25
|
-
* userName and displayName case-insensitively; native-id mentions pass
|
|
26
|
-
* through, and unknown names stay verbatim rather than guessing.
|
|
27
|
-
*/
|
|
28
11
|
export function resolveSlackMentions(source, users) {
|
|
29
12
|
if (!source.includes("<@"))
|
|
30
13
|
return source;
|
|
@@ -34,7 +17,6 @@ export function resolveSlackMentions(source, users) {
|
|
|
34
17
|
if (user.userName)
|
|
35
18
|
byName.set(user.userName.toLowerCase(), user.id);
|
|
36
19
|
}
|
|
37
|
-
// Display names never shadow a userName held by someone else.
|
|
38
20
|
for (const user of list) {
|
|
39
21
|
const display = user.displayName?.toLowerCase();
|
|
40
22
|
if (display && !byName.has(display))
|
|
@@ -59,8 +41,6 @@ function buildTableBlock(headers, rows) {
|
|
|
59
41
|
column_settings: tableHeaders.map(() => ({ is_wrapped: true })),
|
|
60
42
|
};
|
|
61
43
|
}
|
|
62
|
-
/** Split prose into chunks under the markdown block limit, preferring
|
|
63
|
-
* paragraph boundaries, then line boundaries, then a hard slice. */
|
|
64
44
|
function splitProse(text) {
|
|
65
45
|
if (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CAAC,CAAC,CAAC;IAE9F,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,UAAU;QACzD,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import MarkdownIt from \"markdown-it\";\nimport { normalizeSlackCurrencyBold } from \"./markdown.js\";\nimport type Token from \"markdown-it/lib/token.mjs\";\nimport type { KnownBlock } from \"@slack/types\";\nimport {\n extractMarkdownTables,\n inlinePlainText,\n normalizeMarkdownTables,\n} from \"../markdown-tables.js\";\n\n// Parser is used only to locate tables and derive plain-text fallback.\n// Prose is never re-serialized from tokens: it is sliced verbatim from the\n// source and handed to Slack as a native `markdown` block, so Slack owns\n// all prose rendering (same renderer as the markdown_text streaming API).\nconst markdown = new MarkdownIt({ html: false });\n\nconst MAX_BLOCKS = 50;\n// Slack rejects messages whose markdown block text exceeds 12k (msg_too_long).\nconst MARKDOWN_TEXT_LIMIT = 12000;\nconst FIELD_TEXT_LIMIT = 2000;\n\n// Legacy Slack-style links (<url|label>) predate the standard-GFM response\n// source contract; system producers may still emit them.\nconst LEGACY_MRKDWN_LINK_PATTERN = /<(https?:\\/\\/[^<>|\\s]+)\\|([^<>\\n]+)>/g;\n\n// Slack user/bot-user ids: U/W prefix. Already-native mentions pass through.\nconst SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{2,}$/;\nconst MENTION_PATTERN = /<@([^<>\\n]+)>/g;\n\n/**\n * Resolve response-source mentions to Slack's native form.\n *\n * The response source is platform-neutral: the model writes `<@userName>`\n * from the prompt's Users table, and the adapter owns the conversion to\n * `<@U…>` — Slack only links and notifies on the raw user id. Lookup covers\n * userName and displayName case-insensitively; native-id mentions pass\n * through, and unknown names stay verbatim rather than guessing.\n */\nexport function resolveSlackMentions(\n source: string,\n users: Iterable<{ id: string; userName: string; displayName: string }>,\n): string {\n if (!source.includes(\"<@\")) return source;\n const list = [...users];\n const byName = new Map<string, string>();\n for (const user of list) {\n if (user.userName) byName.set(user.userName.toLowerCase(), user.id);\n }\n // Display names never shadow a userName held by someone else.\n for (const user of list) {\n const display = user.displayName?.toLowerCase();\n if (display && !byName.has(display)) byName.set(display, user.id);\n }\n return source.replace(MENTION_PATTERN, (mention, name: string) => {\n if (SLACK_USER_ID_PATTERN.test(name)) return mention;\n const id = byName.get(name.trim().replace(/^@/, \"\").toLowerCase());\n return id ? `<@${id}>` : mention;\n });\n}\n\nfunction buildTableBlock(headers: string[], rows: string[][]): KnownBlock {\n const hasIndex = headers[0] === \"#\";\n const tableHeaders = hasIndex ? headers : [\"#\", ...headers];\n const tableRows = hasIndex\n ? rows\n : rows.map((row, rowNumber) => [String(rowNumber + 1)].concat(row));\n return {\n type: \"table\",\n rows: [tableHeaders, ...tableRows].map((row) =>\n row.map((cell) => ({ type: \"raw_text\", text: (cell || \" \").slice(0, FIELD_TEXT_LIMIT) })),\n ),\n column_settings: tableHeaders.map(() => ({ is_wrapped: true })),\n } as KnownBlock;\n}\n\n/** Split prose into chunks under the markdown block limit, preferring\n * paragraph boundaries, then line boundaries, then a hard slice. */\nfunction splitProse(text: string): string[] {\n if (text.length <= MARKDOWN_TEXT_LIMIT) return [text];\n const chunks: string[] = [];\n let rest = text;\n while (rest.length > MARKDOWN_TEXT_LIMIT) {\n const window = rest.slice(0, MARKDOWN_TEXT_LIMIT);\n let cut = window.lastIndexOf(\"\\n\\n\");\n if (cut <= 0) cut = window.lastIndexOf(\"\\n\");\n if (cut <= 0) cut = MARKDOWN_TEXT_LIMIT;\n chunks.push(rest.slice(0, cut));\n rest = rest.slice(cut);\n }\n if (rest.trim()) chunks.push(rest);\n return chunks;\n}\n\nfunction pushMarkdown(blocks: KnownBlock[], prose: string): void {\n const trimmed = prose.trim();\n if (!trimmed) return;\n for (const chunk of splitProse(trimmed)) {\n if (blocks.length >= MAX_BLOCKS) return;\n const text = chunk.trim();\n if (text) blocks.push({ type: \"markdown\", text } as KnownBlock);\n }\n}\n\nfunction plainTextFallback(tokens: Token[]): string {\n const parts: string[] = [];\n for (const token of tokens) {\n if (token.type === \"inline\") parts.push(inlinePlainText(token.children) || token.content);\n else if (token.type === \"fence\" || token.type === \"code_block\")\n parts.push(token.content.trimEnd());\n }\n return parts.filter(Boolean).join(\"\\n\");\n}\n\nexport function renderSlackBlocks(source: string): { text: string; blocks: KnownBlock[] } {\n const normalized = normalizeMarkdownTables(\n normalizeSlackCurrencyBold(source.replace(LEGACY_MRKDWN_LINK_PATTERN, \"[$2]($1)\")),\n );\n const lines = normalized.split(\"\\n\");\n\n const tables = extractMarkdownTables(normalized);\n\n const blocks: KnownBlock[] = [];\n const fallback: string[] = [];\n let cursor = 0;\n for (const table of tables) {\n const prose = lines.slice(cursor, table.startLine).join(\"\\n\");\n pushMarkdown(blocks, prose);\n if (prose.trim()) fallback.push(plainTextFallback(markdown.parse(prose, {})));\n if (blocks.length < MAX_BLOCKS) {\n blocks.push(buildTableBlock(table.headers, table.rows));\n fallback.push(\n [table.headers.join(\" | \"), ...table.rows.map((row) => row.join(\" | \"))].join(\"\\n\"),\n );\n }\n cursor = table.endLine;\n }\n const trailingProse = lines.slice(cursor).join(\"\\n\");\n pushMarkdown(blocks, trailingProse);\n if (trailingProse.trim()) fallback.push(plainTextFallback(markdown.parse(trailingProse, {})));\n\n return {\n text: fallback.filter(Boolean).join(\"\\n\\n\") || normalized,\n blocks,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../../src/adapters/slack/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAEjD,MAAM,UAAU,GAAG,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AE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACxD,QAAQ,CAAC,IAAI,CACX,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACpF,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IACD,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,IAAI,aAAa,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAE9F,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,UAAU;QACzD,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import MarkdownIt from \"markdown-it\";\nimport { normalizeSlackCurrencyBold } from \"./markdown.js\";\nimport type Token from \"markdown-it/lib/token.mjs\";\nimport type { KnownBlock } from \"@slack/types\";\nimport {\n extractMarkdownTables,\n inlinePlainText,\n normalizeMarkdownTables,\n} from \"../markdown-tables.js\";\n\nconst markdown = new MarkdownIt({ html: false });\n\nconst MAX_BLOCKS = 50;\nconst MARKDOWN_TEXT_LIMIT = 12000;\nconst FIELD_TEXT_LIMIT = 2000;\n\nconst LEGACY_MRKDWN_LINK_PATTERN = /<(https?:\\/\\/[^<>|\\s]+)\\|([^<>\\n]+)>/g;\n\nconst SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{2,}$/;\nconst MENTION_PATTERN = /<@([^<>\\n]+)>/g;\n\nexport function resolveSlackMentions(\n source: string,\n users: Iterable<{ id: string; userName: string; displayName: string }>,\n): string {\n if (!source.includes(\"<@\")) return source;\n const list = [...users];\n const byName = new Map<string, string>();\n for (const user of list) {\n if (user.userName) byName.set(user.userName.toLowerCase(), user.id);\n }\n for (const user of list) {\n const display = user.displayName?.toLowerCase();\n if (display && !byName.has(display)) byName.set(display, user.id);\n }\n return source.replace(MENTION_PATTERN, (mention, name: string) => {\n if (SLACK_USER_ID_PATTERN.test(name)) return mention;\n const id = byName.get(name.trim().replace(/^@/, \"\").toLowerCase());\n return id ? `<@${id}>` : mention;\n });\n}\n\nfunction buildTableBlock(headers: string[], rows: string[][]): KnownBlock {\n const hasIndex = headers[0] === \"#\";\n const tableHeaders = hasIndex ? headers : [\"#\", ...headers];\n const tableRows = hasIndex\n ? rows\n : rows.map((row, rowNumber) => [String(rowNumber + 1)].concat(row));\n return {\n type: \"table\",\n rows: [tableHeaders, ...tableRows].map((row) =>\n row.map((cell) => ({ type: \"raw_text\", text: (cell || \" \").slice(0, FIELD_TEXT_LIMIT) })),\n ),\n column_settings: tableHeaders.map(() => ({ is_wrapped: true })),\n } as KnownBlock;\n}\n\nfunction splitProse(text: string): string[] {\n if (text.length <= MARKDOWN_TEXT_LIMIT) return [text];\n const chunks: string[] = [];\n let rest = text;\n while (rest.length > MARKDOWN_TEXT_LIMIT) {\n const window = rest.slice(0, MARKDOWN_TEXT_LIMIT);\n let cut = window.lastIndexOf(\"\\n\\n\");\n if (cut <= 0) cut = window.lastIndexOf(\"\\n\");\n if (cut <= 0) cut = MARKDOWN_TEXT_LIMIT;\n chunks.push(rest.slice(0, cut));\n rest = rest.slice(cut);\n }\n if (rest.trim()) chunks.push(rest);\n return chunks;\n}\n\nfunction pushMarkdown(blocks: KnownBlock[], prose: string): void {\n const trimmed = prose.trim();\n if (!trimmed) return;\n for (const chunk of splitProse(trimmed)) {\n if (blocks.length >= MAX_BLOCKS) return;\n const text = chunk.trim();\n if (text) blocks.push({ type: \"markdown\", text } as KnownBlock);\n }\n}\n\nfunction plainTextFallback(tokens: Token[]): string {\n const parts: string[] = [];\n for (const token of tokens) {\n if (token.type === \"inline\") parts.push(inlinePlainText(token.children) || token.content);\n else if (token.type === \"fence\" || token.type === \"code_block\")\n parts.push(token.content.trimEnd());\n }\n return parts.filter(Boolean).join(\"\\n\");\n}\n\nexport function renderSlackBlocks(source: string): { text: string; blocks: KnownBlock[] } {\n const normalized = normalizeMarkdownTables(\n normalizeSlackCurrencyBold(source.replace(LEGACY_MRKDWN_LINK_PATTERN, \"[$2]($1)\")),\n );\n const lines = normalized.split(\"\\n\");\n\n const tables = extractMarkdownTables(normalized);\n\n const blocks: KnownBlock[] = [];\n const fallback: string[] = [];\n let cursor = 0;\n for (const table of tables) {\n const prose = lines.slice(cursor, table.startLine).join(\"\\n\");\n pushMarkdown(blocks, prose);\n if (prose.trim()) fallback.push(plainTextFallback(markdown.parse(prose, {})));\n if (blocks.length < MAX_BLOCKS) {\n blocks.push(buildTableBlock(table.headers, table.rows));\n fallback.push(\n [table.headers.join(\" | \"), ...table.rows.map((row) => row.join(\" | \"))].join(\"\\n\"),\n );\n }\n cursor = table.endLine;\n }\n const trailingProse = lines.slice(cursor).join(\"\\n\");\n pushMarkdown(blocks, trailingProse);\n if (trailingProse.trim()) fallback.push(plainTextFallback(markdown.parse(trailingProse, {})));\n\n return {\n text: fallback.filter(Boolean).join(\"\\n\\n\") || normalized,\n blocks,\n };\n}\n"]}
|
|
@@ -4,12 +4,7 @@ import type { EventScheduler } from "../../events/scheduler.js";
|
|
|
4
4
|
import type { SlackChannel, SlackUser } from "./types.js";
|
|
5
5
|
import { type SuggestedPrompt } from "./assistant.js";
|
|
6
6
|
import type { SlackPersonaIdentity } from "./persona.js";
|
|
7
|
-
/** Slices `text` into pieces that each fit one streaming call. */
|
|
8
7
|
export declare function chunkStreamText(text: string, limit?: number): string[];
|
|
9
|
-
/**
|
|
10
|
-
* Build a Slack context block whose text is capped at the mrkdwn limit.
|
|
11
|
-
* Used for muted diagnostics and ephemeral command responses.
|
|
12
|
-
*/
|
|
13
8
|
export declare function buildMrkdwnContextBlock(text: string): object;
|
|
14
9
|
export type { SlackChannel, SlackEvent, SlackUser } from "./types.js";
|
|
15
10
|
export declare class SlackMessagingBot implements MessagingBot {
|
|
@@ -27,20 +22,12 @@ export declare class SlackMessagingBot implements MessagingBot {
|
|
|
27
22
|
private startupTs;
|
|
28
23
|
private users;
|
|
29
24
|
private channels;
|
|
30
|
-
/** Which threads belong to the assistant pane, and their last known context. */
|
|
31
25
|
private assistantThreads;
|
|
32
|
-
/**
|
|
33
|
-
* Native response streams opened recently. Per bot rather than per module:
|
|
34
|
-
* the rate tier applies per workspace, and this bot is the connection to
|
|
35
|
-
* one — which also means a test constructing a bot gets a fresh budget
|
|
36
|
-
* instead of inheriting whatever ran before it.
|
|
37
|
-
*/
|
|
38
26
|
private streamStarts;
|
|
39
27
|
private stopped;
|
|
40
28
|
private queues;
|
|
41
29
|
private intake;
|
|
42
30
|
private eventScheduler;
|
|
43
|
-
/** Host office dir for a Slack conversation. */
|
|
44
31
|
private conversationDir;
|
|
45
32
|
private resolveReplyMode;
|
|
46
33
|
private createContext;
|
|
@@ -57,11 +44,6 @@ export declare class SlackMessagingBot implements MessagingBot {
|
|
|
57
44
|
getAllUsers(): SlackUser[];
|
|
58
45
|
getAllChannels(): SlackChannel[];
|
|
59
46
|
private stripOwnMention;
|
|
60
|
-
/**
|
|
61
|
-
* Response-source `<@userName>` mentions become native `<@U…>` here — the
|
|
62
|
-
* one conversion every outgoing response path funnels through. Slack only
|
|
63
|
-
* links and notifies on raw user ids.
|
|
64
|
-
*/
|
|
65
47
|
private resolveMentions;
|
|
66
48
|
postMessage(channel: string, text: string, threadTs?: string, identity?: SlackPersonaIdentity): Promise<string>;
|
|
67
49
|
addReaction(channel: string, messageTs: string, emoji: string): Promise<void>;
|
|
@@ -74,62 +56,20 @@ export declare class SlackMessagingBot implements MessagingBot {
|
|
|
74
56
|
style?: "muted" | "error";
|
|
75
57
|
}): Promise<void>;
|
|
76
58
|
openDirectConversation(userId: string): Promise<string>;
|
|
77
|
-
/**
|
|
78
|
-
* Fetch recent messages from a channel, oldest first. Without `threadTs`
|
|
79
|
-
* this is one `conversations.history` page of top-level messages (thread
|
|
80
|
-
* replies are not expanded); with it, one `conversations.replies` page of
|
|
81
|
-
* that thread's replies, excluding the parent. Callers page forward by
|
|
82
|
-
* passing the last returned `ts` as `oldest`.
|
|
83
|
-
*/
|
|
84
59
|
fetchHistory(channel: string, options?: PlatformHistoryOptions): Promise<PlatformHistoryMessage[]>;
|
|
85
|
-
/** Refresh and list the workspace's active users (`users.list`). */
|
|
86
60
|
listUsers(): Promise<PlatformUserInfo[]>;
|
|
87
61
|
updateMessage(channel: string, ts: string, text: string): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Claim one native stream, or decline. Declining is not an error: the caller
|
|
90
|
-
* falls back to edit-based updates, which is a working answer rather than a
|
|
91
|
-
* degraded one, and costs no request against the tighter start tier.
|
|
92
|
-
*/
|
|
93
62
|
tryReserveStreamStart(): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Open a stream, carrying text of any length.
|
|
96
|
-
*
|
|
97
|
-
* Slack caps `markdown_text` at 12,000 characters per call, and a long first
|
|
98
|
-
* render exceeds that easily — mikan allows 35,000 in a message. Rather than
|
|
99
|
-
* truncating (losing the answer) or failing (falling back to edit mode for
|
|
100
|
-
* the whole response), the opening call takes the first slice and the rest
|
|
101
|
-
* follows as appends before this resolves. The caller sees one operation
|
|
102
|
-
* that sent everything, so the renderer's idea of what has been streamed
|
|
103
|
-
* stays true.
|
|
104
|
-
*
|
|
105
|
-
* Splitting mid-word or mid-fence is harmless here: a stream concatenates,
|
|
106
|
-
* so Slack renders the reassembled text, not the pieces.
|
|
107
|
-
*/
|
|
108
63
|
startMessageStream(channel: string, text: string, threadTs?: string, recipientUserId?: string): Promise<string>;
|
|
109
|
-
/** Append a delta of any length, split to the per-call cap. */
|
|
110
64
|
appendMessageStream(channel: string, ts: string, text: string): Promise<void>;
|
|
111
65
|
private appendStreamChunk;
|
|
112
66
|
stopMessageStream(channel: string, ts: string): Promise<void>;
|
|
113
67
|
deleteMessage(channel: string, ts: string): Promise<void>;
|
|
114
|
-
/** Set the status for an assistant thread (shows "thinking" state) */
|
|
115
68
|
setAssistantStatus(channel: string, threadTs: string, status: string): Promise<void>;
|
|
116
|
-
/** Offer starting points in a new assistant thread. */
|
|
117
69
|
setAssistantSuggestedPrompts(channel: string, threadTs: string | undefined, prompts: SuggestedPrompt[]): Promise<void>;
|
|
118
|
-
/** Name an assistant thread, which is what the sidebar conversation list shows. */
|
|
119
70
|
setAssistantTitle(channel: string, threadTs: string, title: string): Promise<void>;
|
|
120
|
-
/** The assistant surface's view of this bot, handed to the lifecycle handlers. */
|
|
121
71
|
private assistantOps;
|
|
122
|
-
/**
|
|
123
|
-
* A new conversation opened in the assistant pane. Slack waits for the app
|
|
124
|
-
* to speak first here; staying silent is what makes the pane look broken.
|
|
125
|
-
*/
|
|
126
72
|
private handleAssistantThreadStarted;
|
|
127
|
-
/**
|
|
128
|
-
* The person navigated to another channel while the pane is open. Slack
|
|
129
|
-
* sends this as `assistant_thread_context_changed` under `assistant_view`
|
|
130
|
-
* and `app_context_changed` under `agent_view`; the payload differs enough
|
|
131
|
-
* to normalize here rather than in the handler.
|
|
132
|
-
*/
|
|
133
73
|
private handleAgentContextChangedEvent;
|
|
134
74
|
postInThread(channel: string, threadTs: string, text: string, identity?: SlackPersonaIdentity): Promise<string>;
|
|
135
75
|
postInThreadBlocks(channel: string, threadTs: string, text: string, blocks: object[]): Promise<string>;
|
|
@@ -138,89 +78,33 @@ export declare class SlackMessagingBot implements MessagingBot {
|
|
|
138
78
|
logBotResponse(channel: string, text: string, ts: string, threadTs?: string, slackBlocks?: object[]): void;
|
|
139
79
|
ownsBlockKitMessage(channel: string, ts: string, threadTs?: string): boolean;
|
|
140
80
|
getMessagingInfo(): MessagingInfo;
|
|
141
|
-
/**
|
|
142
|
-
* Enqueue an event for processing. Always queues (no "already working" rejection).
|
|
143
|
-
* Returns true if enqueued, false if queue is full (max 5).
|
|
144
|
-
*/
|
|
145
81
|
enqueueEvent(event: ConversationEvent): boolean;
|
|
146
82
|
private getQueue;
|
|
147
83
|
private resolveQueueKey;
|
|
148
84
|
private isTaskThread;
|
|
149
85
|
private hasRunningTaskThread;
|
|
150
86
|
private hasKnownThreadSession;
|
|
151
|
-
/**
|
|
152
|
-
* Slack's own conversation vocabulary for this channel, from the metadata
|
|
153
|
-
* fetchChannels() already loads. Externally shared channels report
|
|
154
|
-
* "external" regardless of privacy — platform-public within one workspace
|
|
155
|
-
* is the sharing condition, and a channel visible to another organization
|
|
156
|
-
* does not satisfy it. Unknown channels return undefined (never recorded,
|
|
157
|
-
* so the projection keeps its isolated default).
|
|
158
|
-
*/
|
|
159
87
|
private channelKindFor;
|
|
160
|
-
/**
|
|
161
|
-
* Office visibility follows the recorded channel kind, and an unrecorded
|
|
162
|
-
* kind fails closed to private (ADR 0008). Offices created before kinds
|
|
163
|
-
* were recorded would therefore lose public status until their next
|
|
164
|
-
* message; the channel list loaded at startup already knows every kind, so
|
|
165
|
-
* record it for all registered Slack offices now. Metadata only.
|
|
166
|
-
*/
|
|
167
88
|
private backfillChannelKinds;
|
|
168
89
|
private processSlackMessageIntake;
|
|
169
90
|
private appendRunningTasks;
|
|
170
|
-
/**
|
|
171
|
-
* Scheduled jobs of the opener's own DM office only: the App Home is a
|
|
172
|
-
* personal surface, so other offices' schedules are not listed here.
|
|
173
|
-
*/
|
|
174
91
|
private appendScheduledJobs;
|
|
175
92
|
private buildHomeView;
|
|
176
93
|
private createCommandAdapters;
|
|
177
94
|
private buildSlashCommandEvent;
|
|
178
|
-
/**
|
|
179
|
-
* Generic slash-command route: synthesize the command text per the
|
|
180
|
-
* manifest's SlackSlashRoute data and dispatch to the handler. Every
|
|
181
|
-
* routed command — including `/pi-new` — reaches its CommandHandler
|
|
182
|
-
* through runtime dispatch; the adapter holds no per-command behavior.
|
|
183
|
-
*/
|
|
184
95
|
private routeSlashCommand;
|
|
185
96
|
private setupEventHandlers;
|
|
186
97
|
private handleAppMention;
|
|
187
98
|
private admitHumanMessage;
|
|
188
|
-
/**
|
|
189
|
-
* Handle a DM message that may be about a background task without spending
|
|
190
|
-
* a model turn: a pure status question is answered from observation, and a
|
|
191
|
-
* supplement is steered into the running task. Jev decides which (falling
|
|
192
|
-
* back to the regex status shortcut); anything else returns false so the
|
|
193
|
-
* message becomes an ordinary conversation turn.
|
|
194
|
-
*/
|
|
195
99
|
private deliverTaskUpdate;
|
|
196
|
-
/**
|
|
197
|
-
* Ask Jev a single typed yes/no question about whether this unaddressed
|
|
198
|
-
* shared-channel message (top-level or thread reply) addresses mikan. The
|
|
199
|
-
* scored state carries the surrounding scope from log.jsonl, since a bare
|
|
200
|
-
* thread reply cannot be judged from its own text. Only called in `jev`
|
|
201
|
-
* auto-reply mode, and only awaited by the caller in that mode, so
|
|
202
|
-
* `on`/`off` stay synchronous (magic-word `stop` handling depends on that).
|
|
203
|
-
* Any failure (including a missing `OPENROUTER_API_KEY`) fails closed to
|
|
204
|
-
* "not addressed" so a misconfiguration cannot make the bot noisy in a
|
|
205
|
-
* shared channel.
|
|
206
|
-
*/
|
|
207
100
|
private evaluateJevAddressed;
|
|
208
101
|
private handleMessageEvent;
|
|
209
102
|
private handleSlashCommand;
|
|
210
103
|
private handleAppHomeOpened;
|
|
211
104
|
private handleBlockAction;
|
|
212
105
|
private handleSlackInteraction;
|
|
213
|
-
/**
|
|
214
|
-
* Download Slack message files into the office's attachments directory.
|
|
215
|
-
* The Slack contract is all-or-error: any failed download throws after the
|
|
216
|
-
* successful ones are on disk, so callers still log the message text.
|
|
217
|
-
*/
|
|
218
106
|
private processAttachments;
|
|
219
|
-
/** Authorized download with retry; Slack file URLs require the bot token. */
|
|
220
107
|
private downloadSlackFile;
|
|
221
|
-
/**
|
|
222
|
-
* Log a user message to log.jsonl after attachments are ready.
|
|
223
|
-
*/
|
|
224
108
|
private logUserMessage;
|
|
225
109
|
private logExternalMessagingBotMessage;
|
|
226
110
|
private getExistingTimestamps;
|