@geminixiang/mikan 1.0.0-beta.44 → 1.0.0-beta.46
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 +32 -0
- package/README.md +12 -19
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +3 -1
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +143 -141
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/context.d.ts +2 -8
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +1 -1
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/discord/format.d.ts.map +1 -1
- package/dist/adapters/discord/format.js +2 -4
- package/dist/adapters/discord/format.js.map +1 -1
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +1 -4
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/context.d.ts +2 -9
- package/dist/adapters/github/context.d.ts.map +1 -1
- package/dist/adapters/github/context.js.map +1 -1
- package/dist/adapters/github/github-ops.d.ts +4 -17
- package/dist/adapters/github/github-ops.d.ts.map +1 -1
- package/dist/adapters/github/github-ops.js +17 -86
- package/dist/adapters/github/github-ops.js.map +1 -1
- package/dist/adapters/github/tool-pack.d.ts.map +1 -1
- package/dist/adapters/github/tool-pack.js +0 -1
- package/dist/adapters/github/tool-pack.js.map +1 -1
- package/dist/adapters/github/tools/checks.d.ts +0 -1
- package/dist/adapters/github/tools/checks.d.ts.map +1 -1
- package/dist/adapters/github/tools/checks.js +3 -22
- package/dist/adapters/github/tools/checks.js.map +1 -1
- package/dist/adapters/github/types.d.ts +0 -33
- package/dist/adapters/github/types.d.ts.map +1 -1
- package/dist/adapters/github/types.js.map +1 -1
- package/dist/adapters/progressive-renderer.d.ts.map +1 -1
- package/dist/adapters/progressive-renderer.js +311 -318
- package/dist/adapters/progressive-renderer.js.map +1 -1
- package/dist/adapters/slack/blocks.d.ts.map +1 -1
- package/dist/adapters/slack/blocks.js +1 -4
- package/dist/adapters/slack/blocks.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +12 -0
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +158 -178
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/context.d.ts +2 -8
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +1 -1
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +135 -123
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/stream-limits.d.ts +1 -1
- package/dist/adapters/slack/stream-limits.js +1 -1
- package/dist/adapters/slack/stream-limits.js.map +1 -1
- package/dist/adapters/slack/types.d.ts +4 -0
- package/dist/adapters/slack/types.d.ts.map +1 -1
- package/dist/adapters/slack/types.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts +2 -8
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +1 -2
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/types.d.ts +11 -5
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/agent/catalog.d.ts +6 -18
- package/dist/agent/catalog.d.ts.map +1 -1
- package/dist/agent/catalog.js +19 -155
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/execution.d.ts +0 -7
- package/dist/agent/execution.d.ts.map +1 -1
- package/dist/agent/execution.js +23 -21
- package/dist/agent/execution.js.map +1 -1
- package/dist/agent/presenter.d.ts +7 -9
- package/dist/agent/presenter.d.ts.map +1 -1
- package/dist/agent/presenter.js +355 -357
- package/dist/agent/presenter.js.map +1 -1
- package/dist/agent/prompt.d.ts +5 -12
- package/dist/agent/prompt.d.ts.map +1 -1
- package/dist/agent/prompt.js +56 -81
- package/dist/agent/prompt.js.map +1 -1
- package/dist/agent/runner.d.ts +0 -7
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +255 -308
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/types.d.ts +21 -17
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js +0 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/cli/boot.d.ts.map +1 -1
- package/dist/cli/boot.js +7 -10
- package/dist/cli/boot.js.map +1 -1
- package/dist/cli/onboard.d.ts +10 -0
- package/dist/cli/onboard.d.ts.map +1 -0
- package/dist/cli/onboard.js +237 -0
- package/dist/cli/onboard.js.map +1 -0
- package/dist/cli/types.d.ts +8 -3
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/commands/auto-reply.d.ts.map +1 -1
- package/dist/commands/auto-reply.js +5 -12
- package/dist/commands/auto-reply.js.map +1 -1
- package/dist/commands/manifest.d.ts.map +1 -1
- package/dist/commands/manifest.js +9 -16
- package/dist/commands/manifest.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +15 -10
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +0 -2
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +89 -70
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/session-view.js +9 -2
- package/dist/commands/session-view.js.map +1 -1
- package/dist/commands/types.d.ts +4 -3
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/config.d.ts +13 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +39 -37
- package/dist/config.js.map +1 -1
- package/dist/dream/index.d.ts +20 -0
- package/dist/dream/index.d.ts.map +1 -0
- package/dist/dream/index.js +253 -0
- package/dist/dream/index.js.map +1 -0
- package/dist/dream/types.d.ts +30 -0
- package/dist/dream/types.d.ts.map +1 -0
- package/dist/dream/types.js.map +1 -0
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +2 -34
- package/dist/env-manifest.js.map +1 -1
- package/dist/execution-resolver.d.ts +9 -2
- package/dist/execution-resolver.d.ts.map +1 -1
- package/dist/execution-resolver.js +26 -27
- package/dist/execution-resolver.js.map +1 -1
- package/dist/harness/event-format.d.ts +1 -2
- package/dist/harness/event-format.d.ts.map +1 -1
- package/dist/harness/event-format.js +9 -15
- package/dist/harness/event-format.js.map +1 -1
- package/dist/harness/index.d.ts +1 -7
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +0 -4
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/models.d.ts.map +1 -1
- package/dist/harness/models.js +15 -35
- package/dist/harness/models.js.map +1 -1
- package/dist/harness/runner.d.ts +7 -16
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +13 -131
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session-store.d.ts +1 -1
- package/dist/harness/session-store.d.ts.map +1 -1
- package/dist/harness/session-store.js +1 -1
- package/dist/harness/session-store.js.map +1 -1
- package/dist/harness/subagent-runner.d.ts +2 -2
- package/dist/harness/subagent-runner.d.ts.map +1 -1
- package/dist/harness/subagent-runner.js +157 -162
- package/dist/harness/subagent-runner.js.map +1 -1
- package/dist/harness/types.d.ts +1 -13
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/main.js +31 -212
- package/dist/main.js.map +1 -1
- package/dist/mcp/catalog.d.ts +5 -0
- package/dist/mcp/catalog.d.ts.map +1 -0
- package/dist/mcp/catalog.js +135 -0
- package/dist/mcp/catalog.js.map +1 -0
- package/dist/mcp/loader.d.ts.map +1 -1
- package/dist/mcp/loader.js +3 -6
- package/dist/mcp/loader.js.map +1 -1
- package/dist/mcp/types.d.ts +22 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/types.js.map +1 -1
- package/dist/office/index.d.ts +136 -8
- package/dist/office/index.d.ts.map +1 -1
- package/dist/office/index.js +1050 -9
- package/dist/office/index.js.map +1 -1
- package/dist/office/types.d.ts +19 -1
- package/dist/office/types.d.ts.map +1 -1
- package/dist/office/types.js.map +1 -1
- package/dist/packages/index.d.ts +168 -5
- package/dist/packages/index.d.ts.map +1 -1
- package/dist/packages/index.js +749 -5
- package/dist/packages/index.js.map +1 -1
- package/dist/packages/types.d.ts +1 -5
- package/dist/packages/types.d.ts.map +1 -1
- package/dist/packages/types.js.map +1 -1
- package/dist/provisioner.d.ts +2 -9
- package/dist/provisioner.d.ts.map +1 -1
- package/dist/provisioner.js +3 -12
- package/dist/provisioner.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +117 -380
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +32 -18
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js +159 -46
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +4 -26
- 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 -3
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts +0 -1
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +2 -3
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +4 -2
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/identity.d.ts +10 -19
- package/dist/sandbox/identity.d.ts.map +1 -1
- package/dist/sandbox/identity.js +8 -8
- package/dist/sandbox/identity.js.map +1 -1
- package/dist/sandbox/index.d.ts +7 -10
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +45 -16
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/types.d.ts +13 -45
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +5 -0
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +10 -0
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts +1 -3
- package/dist/sessions/chat-history-sync.d.ts.map +1 -1
- package/dist/sessions/chat-history-sync.js +58 -11
- package/dist/sessions/chat-history-sync.js.map +1 -1
- package/dist/sessions/migrate-v3.d.ts +2 -5
- package/dist/sessions/migrate-v3.d.ts.map +1 -1
- package/dist/sessions/migrate-v3.js +34 -4
- package/dist/sessions/migrate-v3.js.map +1 -1
- package/dist/sessions/store.d.ts +5 -6
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +62 -2
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +9 -0
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +2 -10
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/read.js +2 -2
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +2 -3
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/subagent.d.ts +1 -1
- package/dist/tools/subagent.js.map +1 -1
- package/dist/types.d.ts +38 -127
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vault/index.d.ts +9 -2
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +29 -5
- package/dist/vault/index.js.map +1 -1
- package/dist/web/admin/portal.d.ts +12 -1
- package/dist/web/admin/portal.d.ts.map +1 -1
- package/dist/web/admin/portal.js +437 -422
- package/dist/web/admin/portal.js.map +1 -1
- package/dist/web/admin/types.d.ts +2 -2
- package/dist/web/admin/types.d.ts.map +1 -1
- package/dist/web/admin/types.js.map +1 -1
- package/dist/web/login/portal.d.ts +7 -1
- package/dist/web/login/portal.d.ts.map +1 -1
- package/dist/web/login/portal.js +143 -78
- package/dist/web/login/portal.js.map +1 -1
- package/dist/web/portal-shell.d.ts +1 -0
- package/dist/web/portal-shell.d.ts.map +1 -1
- package/dist/web/portal-shell.js +12 -1
- package/dist/web/portal-shell.js.map +1 -1
- package/dist/web/server.d.ts +3 -3
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js.map +1 -1
- package/dist/web/session-view/portal.d.ts +8 -1
- package/dist/web/session-view/portal.d.ts.map +1 -1
- package/dist/web/session-view/portal.js +609 -132
- package/dist/web/session-view/portal.js.map +1 -1
- package/dist/web/session-view/types.d.ts +8 -0
- package/dist/web/session-view/types.d.ts.map +1 -1
- package/dist/web/session-view/types.js.map +1 -1
- package/dist/workspace-projection/index.d.ts +14 -2
- package/dist/workspace-projection/index.d.ts.map +1 -1
- package/dist/workspace-projection/index.js +102 -14
- package/dist/workspace-projection/index.js.map +1 -1
- package/dist/workspace-projection/types.d.ts +14 -1
- package/dist/workspace-projection/types.d.ts.map +1 -1
- package/dist/workspace-projection/types.js.map +1 -1
- package/package.json +3 -5
- package/dist/adapters/github/cloudbuild.d.ts +0 -19
- package/dist/adapters/github/cloudbuild.d.ts.map +0 -1
- package/dist/adapters/github/cloudbuild.js +0 -71
- package/dist/adapters/github/cloudbuild.js.map +0 -1
- package/dist/adapters/github/gcp-auth.d.ts +0 -28
- package/dist/adapters/github/gcp-auth.d.ts.map +0 -1
- package/dist/adapters/github/gcp-auth.js +0 -196
- package/dist/adapters/github/gcp-auth.js.map +0 -1
- package/dist/agent/index.d.ts +0 -9
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/agent/index.js +0 -8
- package/dist/agent/index.js.map +0 -1
- package/dist/cli/ext-dev.d.ts +0 -2
- package/dist/cli/ext-dev.d.ts.map +0 -1
- package/dist/cli/ext-dev.js +0 -188
- package/dist/cli/ext-dev.js.map +0 -1
- package/dist/cli/ext.d.ts +0 -2
- package/dist/cli/ext.d.ts.map +0 -1
- package/dist/cli/ext.js +0 -324
- package/dist/cli/ext.js.map +0 -1
- package/dist/commands/extensions.d.ts +0 -26
- package/dist/commands/extensions.d.ts.map +0 -1
- package/dist/commands/extensions.js +0 -103
- package/dist/commands/extensions.js.map +0 -1
- package/dist/extension-schedules.d.ts +0 -31
- package/dist/extension-schedules.d.ts.map +0 -1
- package/dist/extension-schedules.js +0 -229
- package/dist/extension-schedules.js.map +0 -1
- package/dist/harness/auth.d.ts +0 -17
- package/dist/harness/auth.d.ts.map +0 -1
- package/dist/harness/auth.js +0 -92
- package/dist/harness/auth.js.map +0 -1
- package/dist/harness/extensions/loader.d.ts +0 -40
- package/dist/harness/extensions/loader.d.ts.map +0 -1
- package/dist/harness/extensions/loader.js +0 -723
- package/dist/harness/extensions/loader.js.map +0 -1
- package/dist/harness/extensions/registry.d.ts +0 -155
- package/dist/harness/extensions/registry.d.ts.map +0 -1
- package/dist/harness/extensions/registry.js +0 -420
- package/dist/harness/extensions/registry.js.map +0 -1
- package/dist/harness/extensions/types.d.ts +0 -665
- package/dist/harness/extensions/types.d.ts.map +0 -1
- package/dist/harness/extensions/types.js.map +0 -1
- package/dist/office/address.d.ts +0 -31
- package/dist/office/address.d.ts.map +0 -1
- package/dist/office/address.js +0 -113
- package/dist/office/address.js.map +0 -1
- package/dist/office/layout.d.ts +0 -27
- package/dist/office/layout.d.ts.map +0 -1
- package/dist/office/layout.js +0 -97
- package/dist/office/layout.js.map +0 -1
- package/dist/office/migration.d.ts +0 -44
- package/dist/office/migration.d.ts.map +0 -1
- package/dist/office/migration.js +0 -255
- package/dist/office/migration.js.map +0 -1
- package/dist/office/registry.d.ts +0 -75
- package/dist/office/registry.d.ts.map +0 -1
- package/dist/office/registry.js +0 -646
- package/dist/office/registry.js.map +0 -1
- package/dist/packages/admin.d.ts +0 -17
- package/dist/packages/admin.d.ts.map +0 -1
- package/dist/packages/admin.js +0 -98
- package/dist/packages/admin.js.map +0 -1
- package/dist/packages/inspect.d.ts +0 -11
- package/dist/packages/inspect.d.ts.map +0 -1
- package/dist/packages/inspect.js +0 -98
- package/dist/packages/inspect.js.map +0 -1
- package/dist/packages/materialize.d.ts +0 -40
- package/dist/packages/materialize.d.ts.map +0 -1
- package/dist/packages/materialize.js +0 -297
- package/dist/packages/materialize.js.map +0 -1
- package/dist/packages/resolve.d.ts +0 -25
- package/dist/packages/resolve.d.ts.map +0 -1
- package/dist/packages/resolve.js +0 -208
- package/dist/packages/resolve.js.map +0 -1
- package/dist/packages/source.d.ts +0 -39
- package/dist/packages/source.d.ts.map +0 -1
- package/dist/packages/source.js +0 -189
- package/dist/packages/source.js.map +0 -1
- package/dist/sandbox/errors.d.ts +0 -6
- package/dist/sandbox/errors.d.ts.map +0 -1
- package/dist/sandbox/errors.js +0 -11
- package/dist/sandbox/errors.js.map +0 -1
- package/dist/sandbox/firecracker.d.ts +0 -18
- package/dist/sandbox/firecracker.d.ts.map +0 -1
- package/dist/sandbox/firecracker.js +0 -223
- package/dist/sandbox/firecracker.js.map +0 -1
- package/dist/sandbox/gondolin.d.ts +0 -57
- package/dist/sandbox/gondolin.d.ts.map +0 -1
- package/dist/sandbox/gondolin.js +0 -764
- package/dist/sandbox/gondolin.js.map +0 -1
- package/dist/sandbox/image.d.ts +0 -3
- package/dist/sandbox/image.d.ts.map +0 -1
- package/dist/sandbox/image.js +0 -29
- package/dist/sandbox/image.js.map +0 -1
- package/dist/sessions/conversation-log.d.ts +0 -9
- package/dist/sessions/conversation-log.d.ts.map +0 -1
- package/dist/sessions/conversation-log.js +0 -50
- package/dist/sessions/conversation-log.js.map +0 -1
- package/dist/sessions/rotation.d.ts +0 -2
- package/dist/sessions/rotation.d.ts.map +0 -1
- package/dist/sessions/rotation.js +0 -41
- package/dist/sessions/rotation.js.map +0 -1
- package/dist/vault/disabled.d.ts +0 -9
- package/dist/vault/disabled.d.ts.map +0 -1
- package/dist/vault/disabled.js +0 -25
- package/dist/vault/disabled.js.map +0 -1
- package/dist/web/admin/store.d.ts +0 -13
- package/dist/web/admin/store.d.ts.map +0 -1
- package/dist/web/admin/store.js +0 -14
- package/dist/web/admin/store.js.map +0 -1
- package/dist/web/login/store.d.ts +0 -8
- package/dist/web/login/store.d.ts.map +0 -1
- package/dist/web/login/store.js +0 -15
- package/dist/web/login/store.js.map +0 -1
- package/dist/web/session-view/service.d.ts +0 -6
- package/dist/web/session-view/service.d.ts.map +0 -1
- package/dist/web/session-view/service.js +0 -517
- package/dist/web/session-view/service.js.map +0 -1
- package/dist/web/session-view/store.d.ts +0 -8
- package/dist/web/session-view/store.d.ts.map +0 -1
- package/dist/web/session-view/store.js +0 -15
- package/dist/web/session-view/store.js.map +0 -1
- /package/dist/{harness/extensions → dream}/types.js +0 -0
|
@@ -25,416 +25,409 @@ export function formatMarkdownToolResult(result) {
|
|
|
25
25
|
* rate with it instead of queueing work it cannot deliver.
|
|
26
26
|
*/
|
|
27
27
|
const DEFAULT_FLUSH_INTERVAL_MS = 1000;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
class ProgressiveRenderer {
|
|
29
|
+
constructor(platform) {
|
|
30
|
+
this.platform = platform;
|
|
31
|
+
this.now = Date.now;
|
|
32
|
+
this.queueTail = Promise.resolve();
|
|
33
|
+
this.state = {
|
|
34
|
+
responseId: platform.initialResponseId ?? null,
|
|
35
|
+
source: "",
|
|
36
|
+
working: true,
|
|
37
|
+
streamActive: false,
|
|
38
|
+
streamUnavailable: false,
|
|
39
|
+
streamedSource: "",
|
|
40
|
+
pendingChars: 0,
|
|
41
|
+
lastFlushAt: 0,
|
|
42
|
+
resetDelta: false,
|
|
43
|
+
typingInterval: null,
|
|
44
|
+
typingFailureWarned: false,
|
|
45
|
+
extraIds: [],
|
|
46
|
+
continuationIds: [],
|
|
47
|
+
};
|
|
48
|
+
this.sanitize = platform.sanitize ?? ((text) => text);
|
|
49
|
+
this.reportResponseError = platform.responseErrorContext
|
|
50
|
+
? createChatResponseErrorReporter(() => platform.responseErrorContext(this.state.responseId))
|
|
51
|
+
: undefined;
|
|
52
|
+
this.flushIntervalMs = platform.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
53
|
+
this.responder = this.createResponder();
|
|
54
|
+
}
|
|
55
|
+
createResponder() {
|
|
56
|
+
return {
|
|
57
|
+
respond: (text) => this.respond(text),
|
|
58
|
+
appendResponseDelta: this.platform.supportsDeltas || this.platform.stream
|
|
59
|
+
? (delta) => this.appendDelta(delta)
|
|
60
|
+
: undefined,
|
|
61
|
+
finishResponse: this.platform.supportsDeltas || this.platform.stream
|
|
62
|
+
? (finalText) => this.finishResponse(finalText)
|
|
63
|
+
: undefined,
|
|
64
|
+
replaceResponse: (text, options) => this.replaceResponse(text, options),
|
|
65
|
+
replaceSubagentProgress: this.platform.formatSubagentProgress
|
|
66
|
+
? (progress, finalText) => this.replaceSubagentProgress(progress, finalText)
|
|
67
|
+
: undefined,
|
|
68
|
+
respondDiagnostic: (text, options) => this.respondDiagnostic(text, options),
|
|
69
|
+
respondToolResult: (result) => this.respondToolResult(result),
|
|
70
|
+
setTyping: (isTyping) => this.setTyping(isTyping),
|
|
71
|
+
setWorking: (working) => this.setWorking(working),
|
|
72
|
+
uploadFile: (filePath, title) => this.uploadFile(filePath, title),
|
|
73
|
+
...(this.platform.react ? { react: this.platform.react } : {}),
|
|
74
|
+
deleteResponse: () => this.deleteResponse(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
stopTyping() {
|
|
78
|
+
if (this.state.typingInterval !== null) {
|
|
79
|
+
clearInterval(this.state.typingInterval);
|
|
80
|
+
this.state.typingInterval = null;
|
|
54
81
|
}
|
|
55
82
|
}
|
|
56
|
-
|
|
57
|
-
if (platform.formatProvisional)
|
|
58
|
-
return platform.formatProvisional(text, working);
|
|
59
|
-
return working && platform.workingIndicator ? text + platform.workingIndicator : text;
|
|
83
|
+
provisional(text, working) {
|
|
84
|
+
if (this.platform.formatProvisional)
|
|
85
|
+
return this.platform.formatProvisional(text, working);
|
|
86
|
+
return working && this.platform.workingIndicator ? text + this.platform.workingIndicator : text;
|
|
60
87
|
}
|
|
61
|
-
|
|
62
|
-
return splitText(text, platform.maxLength, platform.formatContinuation);
|
|
88
|
+
split(text) {
|
|
89
|
+
return splitText(text, this.platform.maxLength, this.platform.formatContinuation);
|
|
63
90
|
}
|
|
64
|
-
async
|
|
65
|
-
if (state.responseId !== null) {
|
|
66
|
-
await platform.update(state.responseId, text);
|
|
91
|
+
async postOrUpdate(text) {
|
|
92
|
+
if (this.state.responseId !== null) {
|
|
93
|
+
await this.platform.update(this.state.responseId, text);
|
|
67
94
|
return;
|
|
68
95
|
}
|
|
69
|
-
if (platform.typing?.stopOnSend)
|
|
70
|
-
stopTyping();
|
|
71
|
-
state.responseId = await platform.post(text);
|
|
96
|
+
if (this.platform.typing?.stopOnSend)
|
|
97
|
+
this.stopTyping();
|
|
98
|
+
this.state.responseId = await this.platform.post(text);
|
|
72
99
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
* The overflow is *edited* on later redraws, not re-posted. A streaming
|
|
78
|
-
* response redraws roughly once a second, and re-posting meant every redraw
|
|
79
|
-
* past the length limit dropped another copy of the tail into the channel —
|
|
80
|
-
* a single long answer arrived as one correct message followed by six
|
|
81
|
-
* partial duplicates of itself.
|
|
82
|
-
*
|
|
83
|
-
* Reuse is positional: overflow N always lives in the same message, so the
|
|
84
|
-
* text a reader has already scrolled past does not move. A platform whose
|
|
85
|
-
* `postExtra` reports no id cannot be edited, and falls back to the old
|
|
86
|
-
* behaviour rather than losing the content.
|
|
87
|
-
*/
|
|
88
|
-
async function postSplit(text) {
|
|
89
|
-
const [head = text, ...tail] = split(text);
|
|
90
|
-
await postOrUpdate(head);
|
|
100
|
+
async postSplit(text) {
|
|
101
|
+
const [head = text, ...tail] = this.split(text);
|
|
102
|
+
await this.postOrUpdate(head);
|
|
91
103
|
for (const [index, part] of tail.entries()) {
|
|
92
|
-
const existing = state.continuationIds[index];
|
|
104
|
+
const existing = this.state.continuationIds[index];
|
|
93
105
|
if (existing !== undefined) {
|
|
94
|
-
await platform.update(String(existing), part);
|
|
106
|
+
await this.platform.update(String(existing), part);
|
|
95
107
|
continue;
|
|
96
108
|
}
|
|
97
|
-
if (platform.typing?.stopOnSend)
|
|
98
|
-
stopTyping();
|
|
99
|
-
const id = await platform.postExtra(part, state.responseId);
|
|
109
|
+
if (this.platform.typing?.stopOnSend)
|
|
110
|
+
this.stopTyping();
|
|
111
|
+
const id = await this.platform.postExtra(part, this.state.responseId);
|
|
100
112
|
if (id !== undefined && id !== null)
|
|
101
|
-
state.continuationIds[index] = id;
|
|
113
|
+
this.state.continuationIds[index] = id;
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
|
-
async
|
|
105
|
-
if (platform.typing?.stopOnSend)
|
|
106
|
-
stopTyping();
|
|
107
|
-
await platform.postExtra(text, state.responseId);
|
|
116
|
+
async postExtra(text) {
|
|
117
|
+
if (this.platform.typing?.stopOnSend)
|
|
118
|
+
this.stopTyping();
|
|
119
|
+
await this.platform.postExtra(text, this.state.responseId);
|
|
108
120
|
}
|
|
109
|
-
async
|
|
110
|
-
if (!state.streamActive || state.responseId === null || !platform.stream)
|
|
121
|
+
async stopNativeStream() {
|
|
122
|
+
if (!this.state.streamActive || this.state.responseId === null || !this.platform.stream)
|
|
111
123
|
return;
|
|
112
|
-
const streamId = state.responseId;
|
|
113
|
-
state.streamActive = false;
|
|
114
|
-
state.streamedSource = "";
|
|
115
|
-
await platform.stream.stop(streamId);
|
|
124
|
+
const streamId = this.state.responseId;
|
|
125
|
+
this.state.streamActive = false;
|
|
126
|
+
this.state.streamedSource = "";
|
|
127
|
+
await this.platform.stream.stop(streamId);
|
|
116
128
|
}
|
|
117
|
-
async
|
|
118
|
-
if (!platform.stream || state.responseId === null)
|
|
129
|
+
async abandonNativeStream() {
|
|
130
|
+
if (!this.platform.stream || this.state.responseId === null)
|
|
119
131
|
return;
|
|
120
|
-
const streamId = state.responseId;
|
|
121
|
-
state.streamActive = false;
|
|
122
|
-
state.streamedSource = "";
|
|
123
|
-
await platform.stream.stop(streamId).catch(() => undefined);
|
|
124
|
-
if (state.responseId === streamId)
|
|
125
|
-
state.responseId = null;
|
|
132
|
+
const streamId = this.state.responseId;
|
|
133
|
+
this.state.streamActive = false;
|
|
134
|
+
this.state.streamedSource = "";
|
|
135
|
+
await this.platform.stream.stop(streamId).catch(() => undefined);
|
|
136
|
+
if (this.state.responseId === streamId)
|
|
137
|
+
this.state.responseId = null;
|
|
126
138
|
}
|
|
127
|
-
async
|
|
139
|
+
async renderRaw(text, operation, options, canonicalText = text) {
|
|
128
140
|
try {
|
|
129
|
-
await postSplit(text);
|
|
141
|
+
await this.postSplit(text);
|
|
130
142
|
return canonicalText;
|
|
131
143
|
}
|
|
132
144
|
catch (err) {
|
|
133
|
-
if (!platform.handleTooLong)
|
|
145
|
+
if (!this.platform.handleTooLong)
|
|
134
146
|
throw err;
|
|
135
|
-
|
|
136
|
-
// failure as "too long" turned a transient rate limit into a response
|
|
137
|
-
// cut to a few thousand characters under a notice blaming its length,
|
|
138
|
-
// and the retry it triggered kept the limit alive.
|
|
139
|
-
if (platform.isTooLongError && !platform.isTooLongError(err))
|
|
147
|
+
if (this.platform.isTooLongError && !this.platform.isTooLongError(err))
|
|
140
148
|
throw err;
|
|
141
|
-
const fallback = await platform.handleTooLong(
|
|
149
|
+
const fallback = await this.platform.handleTooLong({
|
|
150
|
+
text: canonicalText,
|
|
151
|
+
operation,
|
|
152
|
+
options,
|
|
153
|
+
responseId: this.state.responseId,
|
|
154
|
+
write: (fallbackText) => this.postSplit(fallbackText),
|
|
155
|
+
getResponseId: () => this.state.responseId,
|
|
156
|
+
});
|
|
142
157
|
return fallback.text;
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
|
-
async
|
|
146
|
-
if (state.working && !text.trim())
|
|
160
|
+
async renderDelta(text) {
|
|
161
|
+
if (this.state.working && !text.trim())
|
|
147
162
|
return text;
|
|
148
|
-
const prepared = platform.prepareSource?.(text, state.working) ?? text;
|
|
149
|
-
const stream = platform.stream;
|
|
150
|
-
const display = provisional(prepared, state.working);
|
|
151
|
-
if (!stream || state.streamUnavailable) {
|
|
152
|
-
await renderRaw(display, "render", undefined, prepared);
|
|
163
|
+
const prepared = this.platform.prepareSource?.(text, this.state.working) ?? text;
|
|
164
|
+
const stream = this.platform.stream;
|
|
165
|
+
const display = this.provisional(prepared, this.state.working);
|
|
166
|
+
if (!stream || this.state.streamUnavailable) {
|
|
167
|
+
await this.renderRaw(display, "render", undefined, prepared);
|
|
153
168
|
return prepared;
|
|
154
169
|
}
|
|
155
|
-
if (state.responseId !== null && !state.streamActive) {
|
|
156
|
-
await renderRaw(display, "render", undefined, prepared);
|
|
170
|
+
if (this.state.responseId !== null && !this.state.streamActive) {
|
|
171
|
+
await this.renderRaw(display, "render", undefined, prepared);
|
|
157
172
|
return prepared;
|
|
158
173
|
}
|
|
159
|
-
if (state.responseId !== null &&
|
|
160
|
-
state.streamActive &&
|
|
161
|
-
!prepared.startsWith(state.streamedSource)) {
|
|
162
|
-
await abandonNativeStream();
|
|
163
|
-
await renderRaw(display, "render", undefined, prepared);
|
|
174
|
+
if (this.state.responseId !== null &&
|
|
175
|
+
this.state.streamActive &&
|
|
176
|
+
!prepared.startsWith(this.state.streamedSource)) {
|
|
177
|
+
await this.abandonNativeStream();
|
|
178
|
+
await this.renderRaw(display, "render", undefined, prepared);
|
|
164
179
|
return prepared;
|
|
165
180
|
}
|
|
166
181
|
try {
|
|
167
|
-
if (state.responseId !== null) {
|
|
168
|
-
const delta = prepared.slice(state.streamedSource.length);
|
|
169
|
-
// Below the threshold the delta stays pending: `state.streamedSource`
|
|
170
|
-
// does not advance, so the next tick recomputes it from the same base
|
|
171
|
-
// and `renderFinal` flushes the remainder before stopping.
|
|
182
|
+
if (this.state.responseId !== null) {
|
|
183
|
+
const delta = prepared.slice(this.state.streamedSource.length);
|
|
172
184
|
if (delta && delta.length >= (stream.minDeltaChars ?? 0)) {
|
|
173
|
-
await stream.append(state.responseId, delta);
|
|
174
|
-
state.streamedSource = prepared;
|
|
185
|
+
await stream.append(this.state.responseId, delta);
|
|
186
|
+
this.state.streamedSource = prepared;
|
|
175
187
|
}
|
|
176
188
|
return prepared;
|
|
177
189
|
}
|
|
178
|
-
state.responseId = await stream.start(prepared);
|
|
179
|
-
state.streamActive = true;
|
|
180
|
-
state.streamedSource = prepared;
|
|
190
|
+
this.state.responseId = await stream.start(prepared);
|
|
191
|
+
this.state.streamActive = true;
|
|
192
|
+
this.state.streamedSource = prepared;
|
|
181
193
|
return prepared;
|
|
182
194
|
}
|
|
183
195
|
catch (err) {
|
|
184
|
-
state.streamUnavailable = true;
|
|
196
|
+
this.state.streamUnavailable = true;
|
|
185
197
|
log.logWarning("Native response streaming unavailable; falling back to message updates", err instanceof Error ? err.message : String(err));
|
|
186
|
-
await abandonNativeStream();
|
|
187
|
-
await renderRaw(display, "render", undefined, prepared);
|
|
198
|
+
await this.abandonNativeStream();
|
|
199
|
+
await this.renderRaw(display, "render", undefined, prepared);
|
|
188
200
|
return prepared;
|
|
189
201
|
}
|
|
190
202
|
}
|
|
191
|
-
async
|
|
192
|
-
const stream = platform.stream;
|
|
193
|
-
if (stream && state.streamActive && state.responseId !== null) {
|
|
203
|
+
async renderFinal(text) {
|
|
204
|
+
const stream = this.platform.stream;
|
|
205
|
+
if (stream && this.state.streamActive && this.state.responseId !== null) {
|
|
194
206
|
let streamed = false;
|
|
195
207
|
try {
|
|
196
|
-
if (text.startsWith(state.streamedSource)) {
|
|
197
|
-
const delta = text.slice(state.streamedSource.length);
|
|
208
|
+
if (text.startsWith(this.state.streamedSource)) {
|
|
209
|
+
const delta = text.slice(this.state.streamedSource.length);
|
|
198
210
|
if (delta)
|
|
199
|
-
await stream.append(state.responseId, delta);
|
|
200
|
-
await stream.stop(state.responseId);
|
|
211
|
+
await stream.append(this.state.responseId, delta);
|
|
212
|
+
await stream.stop(this.state.responseId);
|
|
201
213
|
streamed = true;
|
|
202
214
|
}
|
|
203
215
|
}
|
|
204
216
|
catch (err) {
|
|
205
|
-
state.streamUnavailable = true;
|
|
217
|
+
this.state.streamUnavailable = true;
|
|
206
218
|
log.logWarning("Native response streaming unavailable; falling back to message updates", err instanceof Error ? err.message : String(err));
|
|
207
219
|
}
|
|
208
|
-
state.streamActive = false;
|
|
209
|
-
state.streamedSource = "";
|
|
220
|
+
this.state.streamActive = false;
|
|
221
|
+
this.state.streamedSource = "";
|
|
210
222
|
if (streamed) {
|
|
211
|
-
if (platform.needsCanonicalRender?.(text))
|
|
212
|
-
await renderRaw(text, "render");
|
|
223
|
+
if (this.platform.needsCanonicalRender?.(text))
|
|
224
|
+
await this.renderRaw(text, "render");
|
|
213
225
|
return text;
|
|
214
226
|
}
|
|
215
|
-
await abandonNativeStream();
|
|
227
|
+
await this.abandonNativeStream();
|
|
216
228
|
}
|
|
217
|
-
if (state.responseId !== null || text)
|
|
218
|
-
return renderRaw(text, "render");
|
|
229
|
+
if (this.state.responseId !== null || text)
|
|
230
|
+
return this.renderRaw(text, "render");
|
|
219
231
|
return text;
|
|
220
232
|
}
|
|
221
|
-
async
|
|
222
|
-
const operationPromise = queueTail.then(work);
|
|
233
|
+
async run(label, operation, work, extra) {
|
|
234
|
+
const operationPromise = this.queueTail.then(work);
|
|
223
235
|
const handled = operationPromise.catch(async (err) => {
|
|
224
236
|
const message = err instanceof Error ? err.message : String(err);
|
|
225
|
-
log.logWarning(`${platform.label} ${label} error`, message);
|
|
226
|
-
reportResponseError(err, operation, extra());
|
|
227
|
-
if (platform.notifySendFailure) {
|
|
237
|
+
log.logWarning(`${this.platform.label} ${label} error`, message);
|
|
238
|
+
this.reportResponseError?.(err, operation, extra());
|
|
239
|
+
if (this.platform.notifySendFailure) {
|
|
228
240
|
try {
|
|
229
|
-
await platform.notifySendFailure(message);
|
|
241
|
+
await this.platform.notifySendFailure(message);
|
|
230
242
|
}
|
|
231
243
|
catch {
|
|
232
244
|
// A secondary notification must not poison the response queue.
|
|
233
245
|
}
|
|
234
246
|
}
|
|
235
247
|
});
|
|
236
|
-
queueTail = handled.catch(() => undefined);
|
|
248
|
+
this.queueTail = handled.catch(() => undefined);
|
|
237
249
|
return handled;
|
|
238
250
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
await run("appendResponseDelta", "respond", async () => {
|
|
251
|
+
async appendDelta(delta) {
|
|
252
|
+
await this.run("appendResponseDelta", "respond", async () => {
|
|
242
253
|
if (!delta)
|
|
243
254
|
return;
|
|
244
|
-
if (state.resetDelta) {
|
|
245
|
-
state.source = "";
|
|
246
|
-
state.pendingChars = 0;
|
|
247
|
-
state.resetDelta = false;
|
|
255
|
+
if (this.state.resetDelta) {
|
|
256
|
+
this.state.source = "";
|
|
257
|
+
this.state.pendingChars = 0;
|
|
258
|
+
this.state.resetDelta = false;
|
|
248
259
|
}
|
|
249
|
-
const sanitized = sanitize(delta);
|
|
250
|
-
state.source += sanitized;
|
|
251
|
-
state.pendingChars += sanitized.length;
|
|
252
|
-
const elapsed = now() - state.lastFlushAt;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
state.
|
|
258
|
-
state.source = await renderDelta(state.source);
|
|
259
|
-
// Stamp on completion: a slow or retrying send pushes the next
|
|
260
|
-
// redraw out by however long it took, so pressure never compounds.
|
|
261
|
-
state.lastFlushAt = now();
|
|
260
|
+
const sanitized = this.sanitize(delta);
|
|
261
|
+
this.state.source += sanitized;
|
|
262
|
+
this.state.pendingChars += sanitized.length;
|
|
263
|
+
const elapsed = this.now() - this.state.lastFlushAt;
|
|
264
|
+
if (this.state.lastFlushAt === 0 ||
|
|
265
|
+
(elapsed >= this.flushIntervalMs && this.state.pendingChars > 0)) {
|
|
266
|
+
this.state.pendingChars = 0;
|
|
267
|
+
this.state.source = await this.renderDelta(this.state.source);
|
|
268
|
+
this.state.lastFlushAt = this.now();
|
|
262
269
|
}
|
|
263
|
-
}, () => ({ textLength: delta.length, accumulatedLength: state.source.length }));
|
|
270
|
+
}, () => ({ textLength: delta.length, accumulatedLength: this.state.source.length }));
|
|
264
271
|
}
|
|
265
|
-
|
|
266
|
-
respond
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
platform.logBotResponse?.(text, state.responseId);
|
|
274
|
-
}
|
|
275
|
-
}, () => ({
|
|
276
|
-
phase: state.responseId ? "update" : "initial_post",
|
|
277
|
-
textLength: text.length,
|
|
278
|
-
accumulatedLength: state.source.length,
|
|
279
|
-
}));
|
|
280
|
-
},
|
|
281
|
-
appendResponseDelta: platform.supportsDeltas || platform.stream ? appendDelta : undefined,
|
|
282
|
-
finishResponse: platform.supportsDeltas || platform.stream
|
|
283
|
-
? async (finalText) => {
|
|
284
|
-
await run("finishResponse", "set_working", async () => {
|
|
285
|
-
if (finalText !== undefined)
|
|
286
|
-
state.source = sanitize(finalText);
|
|
287
|
-
state.resetDelta = false;
|
|
288
|
-
state.pendingChars = 0;
|
|
289
|
-
stopTyping();
|
|
290
|
-
state.working = false;
|
|
291
|
-
state.source = await renderFinal(state.source);
|
|
292
|
-
if (state.responseId !== null)
|
|
293
|
-
platform.logBotResponse?.(state.source, state.responseId);
|
|
294
|
-
await platform.onFinish?.(state.source, state.responseId);
|
|
295
|
-
}, () => ({ finalTextLength: finalText?.length }));
|
|
272
|
+
async respond(text) {
|
|
273
|
+
await this.run("respond", "respond", async () => {
|
|
274
|
+
const sanitized = this.sanitize(text);
|
|
275
|
+
this.state.source = this.state.source ? `${this.state.source}\n${sanitized}` : sanitized;
|
|
276
|
+
this.state.pendingChars = 0;
|
|
277
|
+
this.state.source = await this.renderDelta(this.state.source);
|
|
278
|
+
if (this.state.responseId !== null && this.platform.logIntermediateResponses) {
|
|
279
|
+
this.platform.logBotResponse?.(text, this.state.responseId);
|
|
296
280
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
state.source
|
|
314
|
-
// The prepared text is what was sent, so it is also what the
|
|
315
|
-
// renderer must remember it sent.
|
|
316
|
-
prepared);
|
|
317
|
-
}, () => ({
|
|
318
|
-
textLength: text.length,
|
|
319
|
-
hadExistingResponse: Boolean(state.responseId),
|
|
320
|
-
}));
|
|
321
|
-
},
|
|
322
|
-
replaceSubagentProgress: platform.formatSubagentProgress
|
|
323
|
-
? async (progress, finalText) => {
|
|
324
|
-
const dashboard = platform.formatSubagentProgress(progress);
|
|
325
|
-
await responder.replaceResponse(finalText ? `${dashboard}\n\n${finalText}` : dashboard);
|
|
281
|
+
}, () => ({
|
|
282
|
+
phase: this.state.responseId ? "update" : "initial_post",
|
|
283
|
+
textLength: text.length,
|
|
284
|
+
accumulatedLength: this.state.source.length,
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
async finishResponse(finalText) {
|
|
288
|
+
await this.run("finishResponse", "set_working", async () => {
|
|
289
|
+
if (finalText !== undefined)
|
|
290
|
+
this.state.source = this.sanitize(finalText);
|
|
291
|
+
this.state.resetDelta = false;
|
|
292
|
+
this.state.pendingChars = 0;
|
|
293
|
+
this.stopTyping();
|
|
294
|
+
this.state.working = false;
|
|
295
|
+
this.state.source = await this.renderFinal(this.state.source);
|
|
296
|
+
if (this.state.responseId !== null) {
|
|
297
|
+
this.platform.logBotResponse?.(this.state.source, this.state.responseId);
|
|
326
298
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
await
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
299
|
+
await this.platform.onFinish?.(this.state.source, this.state.responseId);
|
|
300
|
+
}, () => ({ finalTextLength: finalText?.length }));
|
|
301
|
+
}
|
|
302
|
+
async replaceResponse(text, options) {
|
|
303
|
+
await this.run("replaceResponse", "replace_response", async () => {
|
|
304
|
+
this.state.source = this.sanitize(text);
|
|
305
|
+
this.state.pendingChars = 0;
|
|
306
|
+
this.state.resetDelta = true;
|
|
307
|
+
if (this.state.streamActive)
|
|
308
|
+
await this.stopNativeStream();
|
|
309
|
+
if (this.state.working && !this.state.source.trim())
|
|
310
|
+
return;
|
|
311
|
+
const prepared = this.platform.prepareSource?.(this.state.source, this.state.working) ?? this.state.source;
|
|
312
|
+
this.state.source = await this.renderRaw(this.provisional(prepared, this.state.working), "replace", options, prepared);
|
|
313
|
+
}, () => ({ textLength: text.length, hadExistingResponse: Boolean(this.state.responseId) }));
|
|
314
|
+
}
|
|
315
|
+
async replaceSubagentProgress(progress, finalText) {
|
|
316
|
+
const dashboard = this.platform.formatSubagentProgress(progress);
|
|
317
|
+
await this.responder.replaceResponse(finalText ? `${dashboard}\n\n${finalText}` : dashboard);
|
|
318
|
+
}
|
|
319
|
+
async respondDiagnostic(text, options = {}) {
|
|
320
|
+
await this.run("respondDiagnostic", "respond_diagnostic", async () => {
|
|
321
|
+
const ids = this.platform.postDiagnostic
|
|
322
|
+
? await this.platform.postDiagnostic(text, options, this.state.responseId)
|
|
323
|
+
: await this.postDefaultDiagnostic(text, options);
|
|
324
|
+
this.state.extraIds.push(...ids);
|
|
325
|
+
}, () => ({ textLength: text.length, style: options.style }));
|
|
326
|
+
}
|
|
327
|
+
async respondToolResult(result) {
|
|
328
|
+
await this.responder.respondDiagnostic(this.platform.formatToolResult(result));
|
|
329
|
+
}
|
|
330
|
+
async setTyping(isTyping) {
|
|
331
|
+
await this.run("setTyping", "set_working", async () => {
|
|
332
|
+
if (this.platform.setTyping) {
|
|
333
|
+
await this.platform.setTyping(isTyping, this.state.responseId);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const typing = this.platform.typing;
|
|
337
|
+
if (!typing)
|
|
338
|
+
return;
|
|
339
|
+
const onTypingError = (err) => {
|
|
340
|
+
if (this.state.typingFailureWarned)
|
|
347
341
|
return;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
if (isTyping && state.typingInterval === null) {
|
|
342
|
+
this.state.typingFailureWarned = true;
|
|
343
|
+
log.logWarning(`${this.platform.label} sendTyping failed (further occurrences suppressed for this session)`, err instanceof Error ? err.message : String(err));
|
|
344
|
+
};
|
|
345
|
+
if (isTyping && this.state.typingInterval === null) {
|
|
346
|
+
typing.send().catch(onTypingError);
|
|
347
|
+
this.state.typingInterval = setInterval(() => {
|
|
355
348
|
typing.send().catch(onTypingError);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (state.responseId === null || (!platform.workingIndicator && !platform.stream))
|
|
372
|
-
return;
|
|
373
|
-
if (working && !state.source.trim())
|
|
374
|
-
return;
|
|
375
|
-
if (state.streamActive && !working) {
|
|
376
|
-
await stopNativeStream();
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (state.responseId !== null) {
|
|
380
|
-
state.source = await renderRaw(provisional(state.source, working), "render", undefined, state.source);
|
|
381
|
-
}
|
|
382
|
-
}, () => ({ working }));
|
|
383
|
-
},
|
|
384
|
-
uploadFile: async (filePath, title) => {
|
|
385
|
-
if (platform.uploadFile) {
|
|
386
|
-
await platform.uploadFile(filePath, title);
|
|
349
|
+
}, typing.intervalMs);
|
|
350
|
+
}
|
|
351
|
+
else if (!isTyping) {
|
|
352
|
+
this.stopTyping();
|
|
353
|
+
}
|
|
354
|
+
}, () => ({ working: isTyping }));
|
|
355
|
+
}
|
|
356
|
+
async setWorking(working) {
|
|
357
|
+
await this.run("setWorking", "set_working", async () => {
|
|
358
|
+
this.state.working = working;
|
|
359
|
+
if (!working)
|
|
360
|
+
this.stopTyping();
|
|
361
|
+
await this.platform.onWorkingChanged?.(working, this.state.responseId);
|
|
362
|
+
if (this.state.responseId === null ||
|
|
363
|
+
(!this.platform.workingIndicator && !this.platform.stream)) {
|
|
387
364
|
return;
|
|
388
365
|
}
|
|
389
|
-
|
|
390
|
-
|
|
366
|
+
if (working && !this.state.source.trim())
|
|
367
|
+
return;
|
|
368
|
+
if (this.state.streamActive && !working) {
|
|
369
|
+
await this.stopNativeStream();
|
|
391
370
|
return;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
371
|
+
}
|
|
372
|
+
if (this.state.responseId !== null) {
|
|
373
|
+
this.state.source = await this.renderRaw(this.provisional(this.state.source, working), "render", undefined, this.state.source);
|
|
374
|
+
}
|
|
375
|
+
}, () => ({ working }));
|
|
376
|
+
}
|
|
377
|
+
async uploadFile(filePath, title) {
|
|
378
|
+
if (this.platform.uploadFile) {
|
|
379
|
+
await this.platform.uploadFile(filePath, title);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const note = this.platform.uploadFallbackNote?.(title ?? filePath);
|
|
383
|
+
if (note === undefined)
|
|
384
|
+
return;
|
|
385
|
+
await this.run("uploadFile", "respond_diagnostic", () => this.postExtra(note), () => ({ filePath }));
|
|
386
|
+
}
|
|
387
|
+
async deleteResponse() {
|
|
388
|
+
await this.run("deleteResponse", "respond", async () => {
|
|
389
|
+
this.stopTyping();
|
|
390
|
+
if (this.state.streamActive)
|
|
391
|
+
await this.stopNativeStream().catch(() => undefined);
|
|
392
|
+
for (const id of [...this.state.extraIds, ...this.state.continuationIds]) {
|
|
393
|
+
try {
|
|
394
|
+
await this.platform.deleteExtra?.(id);
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
// Deleting diagnostics is best effort.
|
|
407
398
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
catch {
|
|
415
|
-
// Deleting the main response is best effort.
|
|
416
|
-
}
|
|
399
|
+
}
|
|
400
|
+
this.state.extraIds = [];
|
|
401
|
+
this.state.continuationIds = [];
|
|
402
|
+
if (this.state.responseId !== null) {
|
|
403
|
+
try {
|
|
404
|
+
await this.platform.delete?.(this.state.responseId);
|
|
417
405
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
406
|
+
catch {
|
|
407
|
+
// Deleting the main response is best effort.
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
this.state.responseId = null;
|
|
411
|
+
this.state.source = "";
|
|
412
|
+
this.state.streamUnavailable = false;
|
|
413
|
+
this.state.streamedSource = "";
|
|
414
|
+
this.state.streamActive = false;
|
|
415
|
+
this.state.resetDelta = false;
|
|
416
|
+
this.state.working = true;
|
|
417
|
+
}, () => ({}));
|
|
418
|
+
}
|
|
419
|
+
async postDefaultDiagnostic(text, options) {
|
|
420
|
+
const prefix = options.style === "error" ? this.platform.errorPrefix : "";
|
|
430
421
|
const ids = [];
|
|
431
|
-
for (const part of split(sanitize(`${prefix}${text}`))) {
|
|
432
|
-
const id = await platform.postExtra(part, state.responseId);
|
|
422
|
+
for (const part of this.split(this.sanitize(`${prefix}${text}`))) {
|
|
423
|
+
const id = await this.platform.postExtra(part, this.state.responseId);
|
|
433
424
|
if (typeof id === "string" || typeof id === "number")
|
|
434
425
|
ids.push(id);
|
|
435
426
|
}
|
|
436
427
|
return ids;
|
|
437
428
|
}
|
|
438
|
-
|
|
429
|
+
}
|
|
430
|
+
export function createProgressiveRenderer(platform) {
|
|
431
|
+
return { responder: new ProgressiveRenderer(platform).responder };
|
|
439
432
|
}
|
|
440
433
|
//# sourceMappingURL=progressive-renderer.js.map
|