tavus-cli 0.13.0__tar.gz → 0.14.0__tar.gz

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.
Files changed (132) hide show
  1. tavus_cli-0.14.0/.release-please-manifest.json +3 -0
  2. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/CHANGELOG.md +7 -0
  3. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/PKG-INFO +24 -1
  4. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/README.md +23 -0
  5. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/packages/tavus/pyproject.toml +2 -2
  6. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/packages/tavus-mcp/pyproject.toml +2 -2
  7. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/pyproject.toml +1 -1
  8. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/__init__.py +1 -1
  9. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/uv.lock +1 -1
  10. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/package-lock.json +2 -2
  11. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/package.json +1 -1
  12. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/index.ts +5 -0
  13. tavus_cli-0.14.0/workers/tavus-mcp/src/slack-bot.ts +444 -0
  14. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/slack-link-store.ts +21 -0
  15. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/slack.ts +55 -16
  16. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/tavus.ts +3 -0
  17. tavus_cli-0.14.0/workers/tavus-mcp/src/version.ts +1 -0
  18. tavus_cli-0.14.0/workers/tavus-mcp/test/slack-bot.test.ts +339 -0
  19. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/slack-link.test.ts +11 -0
  20. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/worker-runtime.ts +19 -3
  21. tavus_cli-0.13.0/.release-please-manifest.json +0 -3
  22. tavus_cli-0.13.0/workers/tavus-mcp/src/version.ts +0 -1
  23. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.agents/plugins/marketplace.json +0 -0
  24. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.cursor/BUGBOT.md +0 -0
  25. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.env.example +0 -0
  26. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/review-guidelines.md +0 -0
  27. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/ci.yml +0 -0
  28. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/claude-pr-review.yml +0 -0
  29. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/codex-pr-review.yml +0 -0
  30. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/deploy-cloudflare-worker.yml +0 -0
  31. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/pr-reviews.yml +0 -0
  32. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/pypi-cli.yml +0 -0
  33. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/tail-cloudflare-worker.yml +0 -0
  34. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.github/workflows/validate-staging-deployment.yml +0 -0
  35. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/.gitignore +0 -0
  36. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/AGENTS.md +0 -0
  37. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/PROMPT.md +0 -0
  38. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/builder-guidance.md +0 -0
  39. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/chatgpt-plugin.md +0 -0
  40. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/gemini-enterprise/README.md +0 -0
  41. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/gemini-enterprise/listing.md +0 -0
  42. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/gemini-enterprise/test-queries.md +0 -0
  43. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/docs/usage-observability.md +0 -0
  44. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/packages/tavus/README.md +0 -0
  45. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/packages/tavus-mcp/README.md +0 -0
  46. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/plugins/tavus-pal/assets/icon-dark.svg +0 -0
  47. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/plugins/tavus-pal/assets/icon.svg +0 -0
  48. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/plugins/tavus-pal/mcp.json +0 -0
  49. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/plugins/tavus-pal/plugin.json +0 -0
  50. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/release-please-config.json +0 -0
  51. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/scripts/__init__.py +0 -0
  52. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/scripts/build_chatgpt_plugin.py +0 -0
  53. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/scripts/check_release_versions.py +0 -0
  54. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/SKILL.md +0 -0
  55. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/agents/openai.yaml +0 -0
  56. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/references/build-and-verify.md +0 -0
  57. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/references/builder-workflow.md +0 -0
  58. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/references/chat-mode.md +0 -0
  59. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/skills/tavus-agentic-pals/references/examples.md +0 -0
  60. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/builder_guidance.json +0 -0
  61. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/builder_guidance.py +0 -0
  62. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/cli/__init__.py +0 -0
  63. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/cli/main.py +0 -0
  64. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/__init__.py +0 -0
  65. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/auth/__init__.py +0 -0
  66. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/auth/keyring_store.py +0 -0
  67. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/auth/oauth.py +0 -0
  68. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/auth/session.py +0 -0
  69. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/client/__init__.py +0 -0
  70. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/client/http.py +0 -0
  71. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/daily_transport.py +0 -0
  72. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/env.py +0 -0
  73. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/errors.py +0 -0
  74. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/pal_urls.py +0 -0
  75. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/patch.py +0 -0
  76. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/__init__.py +0 -0
  77. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/build_and_verify.py +0 -0
  78. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/capabilities.py +0 -0
  79. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/carrier_builder.py +0 -0
  80. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/conversations.py +0 -0
  81. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/deployments.py +0 -0
  82. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/face_studio.py +0 -0
  83. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/knowledge.py +0 -0
  84. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/meetings.py +0 -0
  85. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/options.py +0 -0
  86. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/quickstart.py +0 -0
  87. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/scaffold_embed.py +0 -0
  88. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/templates.py +0 -0
  89. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/recipes/tool_reuse.py +0 -0
  90. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/__init__.py +0 -0
  91. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/deployment.py +0 -0
  92. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/face_studio.py +0 -0
  93. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/file_manifest.py +0 -0
  94. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/guardrail.py +0 -0
  95. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/objective.py +0 -0
  96. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/pal.py +0 -0
  97. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/pronunciation.py +0 -0
  98. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/sdk/schemas/tool.py +0 -0
  99. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/src/tavus_mcp/server.py +0 -0
  100. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/conftest.py +0 -0
  101. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/integration/test_cli.py +0 -0
  102. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/integration/test_client.py +0 -0
  103. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/integration/test_mcp_server.py +0 -0
  104. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/integration/test_oauth.py +0 -0
  105. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_auth.py +0 -0
  106. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_build_and_verify.py +0 -0
  107. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_builder.py +0 -0
  108. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_capabilities.py +0 -0
  109. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_conversations.py +0 -0
  110. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_daily_transport.py +0 -0
  111. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_deployments.py +0 -0
  112. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_env.py +0 -0
  113. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_guardrail_schema.py +0 -0
  114. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_objective_schema.py +0 -0
  115. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_pal_schema.py +0 -0
  116. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_patch.py +0 -0
  117. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_pronunciation_schema.py +0 -0
  118. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_release_versions.py +0 -0
  119. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_scaffold_embed.py +0 -0
  120. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_tool_reuse.py +0 -0
  121. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/tests/unit/test_tool_schema.py +0 -0
  122. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/.dev.vars.example +0 -0
  123. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/oauth-grant.ts +0 -0
  124. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/oauth-session.ts +0 -0
  125. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/src/oauth.ts +0 -0
  126. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/builder-guidance.test.ts +0 -0
  127. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/conversations.test.ts +0 -0
  128. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/oauth-session.test.ts +0 -0
  129. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/parity.test.ts +0 -0
  130. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/test/tavus.test.ts +0 -0
  131. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/tsconfig.json +0 -0
  132. {tavus_cli-0.13.0 → tavus_cli-0.14.0}/workers/tavus-mcp/wrangler.jsonc +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.14.0"
3
+ }
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.14.0](https://github.com/Tavus-Engineering/tavus-mcp/compare/v0.13.0...v0.14.0) (2026-10-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * **slack:** serve the /tavus bot from the Worker ([#98](https://github.com/Tavus-Engineering/tavus-mcp/issues/98)) ([17f7616](https://github.com/Tavus-Engineering/tavus-mcp/commit/17f7616baa5b32d7455c49a9aed45328f2ad5c7f))
9
+
3
10
  ## [0.13.0](https://github.com/Tavus-Engineering/tavus-mcp/compare/v0.12.0...v0.13.0) (2026-10-28)
4
11
 
5
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tavus-cli
3
- Version: 0.13.0
3
+ Version: 0.14.0
4
4
  Summary: Tavus CLI and MCP server for agentic PAL creation and editing.
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: fastmcp>=2.0.0
@@ -99,6 +99,29 @@ so one bot serves many people without a shared Tavus key.
99
99
  - Linking uses the `SLACK_LINKS` Durable Object, so a first deploy needs the `v3`
100
100
  migration in `wrangler.jsonc`.
101
101
 
102
+ ### Tavus Slack bot
103
+
104
+ The Worker also runs the Tavus Slack bot, so one deploy serves Slack and MCP.
105
+ Slack sends the `/tavus` command to `POST /slack/commands` and events to
106
+ `POST /slack/events`. Every request must carry a valid Slack signature, and the
107
+ Worker rejects anything older than five minutes.
108
+
109
+ - Set the Worker secrets `SLACK_SIGNING_SECRET` (the Slack app's signing secret)
110
+ and `SLACK_BOT_TOKEN` (the bot token that starts with `xoxb-`). Linking also
111
+ needs `SLACK_BOT_SECRET` and `MCP_OAUTH_SIGNING_SECRET`, as described above.
112
+ - In the Slack app, turn Socket Mode off, set the slash command URL to
113
+ `https://mcp.tavus.io/slack/commands`, set the Event Subscriptions request URL
114
+ to `https://mcp.tavus.io/slack/events`, and subscribe to the bot events
115
+ `app_mention` and `message.im`. The bot scopes are `commands`,
116
+ `app_mentions:read`, `chat:write` and `im:history`.
117
+ - Commands: `pals`, `chat <PAL> <message>`, `recent [PAL]`, `transcript <id>`,
118
+ `link` and `unlink`. A user replies in a chat thread with `@Tavus` to continue
119
+ it, or with `@Tavus end` to stop it.
120
+ - The bot calls the tools in the same process with the Tavus key that Slack user
121
+ linked, so it never needs the bot secret over HTTP. A chat turn can take longer
122
+ than a request's 30-second background limit, so it runs inside a Durable Object
123
+ (`job:` names on `SLACK_LINKS`), which may run for up to 15 minutes.
124
+
102
125
  ### ChatGPT plugin
103
126
 
104
127
  `plugins/tavus-pal/` packages this same hosted server as **Tavus PAL** for
@@ -77,6 +77,29 @@ so one bot serves many people without a shared Tavus key.
77
77
  - Linking uses the `SLACK_LINKS` Durable Object, so a first deploy needs the `v3`
78
78
  migration in `wrangler.jsonc`.
79
79
 
80
+ ### Tavus Slack bot
81
+
82
+ The Worker also runs the Tavus Slack bot, so one deploy serves Slack and MCP.
83
+ Slack sends the `/tavus` command to `POST /slack/commands` and events to
84
+ `POST /slack/events`. Every request must carry a valid Slack signature, and the
85
+ Worker rejects anything older than five minutes.
86
+
87
+ - Set the Worker secrets `SLACK_SIGNING_SECRET` (the Slack app's signing secret)
88
+ and `SLACK_BOT_TOKEN` (the bot token that starts with `xoxb-`). Linking also
89
+ needs `SLACK_BOT_SECRET` and `MCP_OAUTH_SIGNING_SECRET`, as described above.
90
+ - In the Slack app, turn Socket Mode off, set the slash command URL to
91
+ `https://mcp.tavus.io/slack/commands`, set the Event Subscriptions request URL
92
+ to `https://mcp.tavus.io/slack/events`, and subscribe to the bot events
93
+ `app_mention` and `message.im`. The bot scopes are `commands`,
94
+ `app_mentions:read`, `chat:write` and `im:history`.
95
+ - Commands: `pals`, `chat <PAL> <message>`, `recent [PAL]`, `transcript <id>`,
96
+ `link` and `unlink`. A user replies in a chat thread with `@Tavus` to continue
97
+ it, or with `@Tavus end` to stop it.
98
+ - The bot calls the tools in the same process with the Tavus key that Slack user
99
+ linked, so it never needs the bot secret over HTTP. A chat turn can take longer
100
+ than a request's 30-second background limit, so it runs inside a Durable Object
101
+ (`job:` names on `SLACK_LINKS`), which may run for up to 15 minutes.
102
+
80
103
  ### ChatGPT plugin
81
104
 
82
105
  `plugins/tavus-pal/` packages this same hosted server as **Tavus PAL** for
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "tavus"
3
- version = "0.13.0" # x-release-please-version
3
+ version = "0.14.0" # x-release-please-version
4
4
  description = "Official alias for tavus-cli, the Tavus CLI and MCP server."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  dependencies = [
8
- "tavus-cli==0.13.0", # x-release-please-version
8
+ "tavus-cli==0.14.0", # x-release-please-version
9
9
  ]
10
10
 
11
11
  [project.urls]
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "tavus-mcp"
3
- version = "0.13.0" # x-release-please-version
3
+ version = "0.14.0" # x-release-please-version
4
4
  description = "Official alias for tavus-cli, which provides the tavus-mcp MCP server."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  dependencies = [
8
- "tavus-cli==0.13.0", # x-release-please-version
8
+ "tavus-cli==0.14.0", # x-release-please-version
9
9
  ]
10
10
 
11
11
  [project.urls]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tavus-cli"
3
- version = "0.13.0"
3
+ version = "0.14.0"
4
4
  description = "Tavus CLI and MCP server for agentic PAL creation and editing."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,4 +1,4 @@
1
1
  """Tavus CLI and MCP server package."""
2
2
 
3
3
  __all__ = ["__version__"]
4
- __version__ = "0.13.0" # x-release-please-version
4
+ __version__ = "0.14.0" # x-release-please-version
@@ -1303,7 +1303,7 @@ wheels = [
1303
1303
 
1304
1304
  [[package]]
1305
1305
  name = "tavus-cli"
1306
- version = "0.13.0"
1306
+ version = "0.14.0"
1307
1307
  source = { editable = "." }
1308
1308
  dependencies = [
1309
1309
  { name = "fastmcp" },
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@tavus/tavus-mcp-worker",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@tavus/tavus-mcp-worker",
9
- "version": "0.13.0",
9
+ "version": "0.14.0",
10
10
  "dependencies": {
11
11
  "@modelcontextprotocol/sdk": "^1.29.0",
12
12
  "agents": "^0.12.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tavus/tavus-mcp-worker",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,6 +1,7 @@
1
1
  import { createMcpHandler } from "agents/mcp";
2
2
 
3
3
  import { handleOAuthRequest, oauthUnauthorizedHeaders, resolveMcpApiKey } from "./oauth";
4
+ import { handleSlackBotRequest } from "./slack-bot";
4
5
  import { handleSlackRequest, isSlackBotCredential, isSlackRequest, resolveSlackApiKey } from "./slack";
5
6
  import {
6
7
  authorizationError,
@@ -27,6 +28,10 @@ export default {
27
28
  headers: { "Content-Type": "text/plain; charset=utf-8" },
28
29
  });
29
30
  }
31
+ const slackBotResponse = await handleSlackBotRequest(request, env, ctx);
32
+ if (slackBotResponse) {
33
+ return slackBotResponse;
34
+ }
30
35
  const slackResponse = await handleSlackRequest(request, env, MCP_ROUTE);
31
36
  if (slackResponse) {
32
37
  return slackResponse;
@@ -0,0 +1,444 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
3
+
4
+ import { openPayload, sealPayload, oauthSigningSecret, timingSafeEqual } from "./oauth";
5
+ import { createLinkUrl, linkedAccount, type SlackIdentity, slackIdentity, unlinkAccount } from "./slack";
6
+ import { createTavusMcpServer, type Env } from "./tavus";
7
+
8
+ const COMMANDS_ROUTE = "/slack/commands";
9
+ const EVENTS_ROUTE = "/slack/events";
10
+ const MAX_SIGNATURE_AGE_SECONDS = 5 * 60;
11
+ const MAX_MESSAGE_LENGTH = 2800;
12
+ const CHAT_TURN_TIMEOUT_SECONDS = 110;
13
+ const PAL_PAGE_SIZE = 100;
14
+ const MAX_PAL_PAGES = 10;
15
+ const CHAT_MAX_AGE_SECONDS = 24 * 60 * 60;
16
+
17
+ const HELP = [
18
+ "*/tavus pals* lists your PALs.",
19
+ "*/tavus chat <PAL name or ID> <message>* starts a text chat with a PAL. Reply in the thread with @Tavus to keep going.",
20
+ "*/tavus recent* shows your last 10 conversations. Add a PAL name to see only that PAL's.",
21
+ "*/tavus transcript <conversation ID>* shows what was said.",
22
+ "*/tavus link* connects your Tavus account. */tavus unlink* disconnects it.",
23
+ "To end a chat, reply `@Tavus end` in its thread.",
24
+ ].join("\n");
25
+
26
+ type Reply = (text: string) => Promise<void>;
27
+ type Fields = Record<string, unknown>;
28
+
29
+ export interface ChatJob {
30
+ kind: "chat";
31
+ identity: SlackIdentity;
32
+ link_id: string;
33
+ origin: string;
34
+ channel: string;
35
+ thread: string;
36
+ text: string;
37
+ pal?: { id: string; name: string };
38
+ conversation_id?: string;
39
+ }
40
+
41
+ interface ChatState {
42
+ user_id: string;
43
+ link_id: string;
44
+ conversation_id: string;
45
+ pal_name: string;
46
+ started_at: number;
47
+ }
48
+
49
+ class NotLinked extends Error {}
50
+ class AccountChanged extends Error {}
51
+
52
+ export async function handleSlackBotRequest(
53
+ request: Request,
54
+ env: Env,
55
+ ctx: ExecutionContext,
56
+ ): Promise<Response | null> {
57
+ const url = new URL(request.url);
58
+ if (url.pathname !== COMMANDS_ROUTE && url.pathname !== EVENTS_ROUTE) return null;
59
+ if (request.method !== "POST") {
60
+ return new Response("Method Not Allowed", { status: 405, headers: { Allow: "POST" } });
61
+ }
62
+ const body = await request.text();
63
+ if (!(await verifySlackSignature(request, env, body))) {
64
+ return new Response("Invalid Slack signature", { status: 401 });
65
+ }
66
+ return url.pathname === COMMANDS_ROUTE
67
+ ? handleCommand(body, url.origin, env, ctx)
68
+ : handleEvent(request, body, url.origin, env, ctx);
69
+ }
70
+
71
+ export async function verifySlackSignature(request: Request, env: Env, body: string): Promise<boolean> {
72
+ const secret = env.SLACK_SIGNING_SECRET?.trim();
73
+ const timestamp = request.headers.get("X-Slack-Request-Timestamp");
74
+ const signature = request.headers.get("X-Slack-Signature");
75
+ if (!secret || secret.length < 32 || !timestamp || !signature) return false;
76
+ const age = Math.abs(Date.now() / 1000 - Number(timestamp));
77
+ if (!Number.isFinite(age) || age > MAX_SIGNATURE_AGE_SECONDS) return false;
78
+ const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
79
+ "sign",
80
+ ]);
81
+ const digest = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`v0:${timestamp}:${body}`));
82
+ const expected = `v0=${[...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
83
+ return timingSafeEqual(expected, signature);
84
+ }
85
+
86
+ async function handleCommand(body: string, origin: string, env: Env, ctx: ExecutionContext): Promise<Response> {
87
+ const form = new URLSearchParams(body);
88
+ const identity = slackIdentity(form.get("team_id"), form.get("user_id"));
89
+ const responseUrl = form.get("response_url");
90
+ if (!identity || !responseUrl) return ephemeral("This command needs a Slack team and user.");
91
+ const text = (form.get("text") ?? "").trim();
92
+ const channel = form.get("channel_id") ?? "";
93
+ const reply: Reply = async (message) => {
94
+ await fetch(responseUrl, {
95
+ method: "POST",
96
+ headers: { "Content-Type": "application/json" },
97
+ body: JSON.stringify({ response_type: "ephemeral", text: message, unfurl_links: false, unfurl_media: false }),
98
+ });
99
+ };
100
+ const [verb] = text.split(/\s+/);
101
+ if (verb === "" || verb === "help") return ephemeral(HELP);
102
+ if (verb === "end") return ephemeral("Reply `end` in a chat thread with @Tavus to end it.");
103
+ ctx.waitUntil(runCommand({ env, ctx, identity, origin, channel, text, reply }));
104
+ return new Response(null, { status: 200 });
105
+ }
106
+
107
+ async function handleEvent(
108
+ request: Request,
109
+ body: string,
110
+ origin: string,
111
+ env: Env,
112
+ ctx: ExecutionContext,
113
+ ): Promise<Response> {
114
+ const payload = parseJson(body);
115
+ if (payload?.type === "url_verification" && typeof payload.challenge === "string") {
116
+ return new Response(payload.challenge, { headers: { "Content-Type": "text/plain" } });
117
+ }
118
+ if (request.headers.has("X-Slack-Retry-Num") || payload?.type !== "event_callback") {
119
+ return new Response(null, { status: 200 });
120
+ }
121
+ const event = (payload.event ?? {}) as Fields;
122
+ const identity = slackIdentity(payload.team_id, event.user);
123
+ const channel = typeof event.channel === "string" ? event.channel : "";
124
+ const text = typeof event.text === "string" ? event.text : "";
125
+ const isMention = event.type === "app_mention" && !event.bot_id;
126
+ const isDirectMessage = event.type === "message" && event.channel_type === "im" && !event.bot_id && !event.subtype;
127
+ if (identity && channel && (isMention || isDirectMessage)) {
128
+ const ts = typeof event.ts === "string" ? event.ts : "";
129
+ const thread = typeof event.thread_ts === "string" ? event.thread_ts : ts;
130
+ ctx.waitUntil(
131
+ runEvent({ env, ctx, identity, origin, channel, text: text.replace(/<@[A-Z0-9]+>/g, "").trim(), thread, isDirectMessage, isReply: thread !== ts }),
132
+ );
133
+ }
134
+ return new Response(null, { status: 200 });
135
+ }
136
+
137
+ interface CommandContext {
138
+ env: Env;
139
+ ctx: ExecutionContext;
140
+ identity: SlackIdentity;
141
+ origin: string;
142
+ channel: string;
143
+ text: string;
144
+ reply: Reply;
145
+ directThread?: string;
146
+ }
147
+
148
+ async function runCommand(c: CommandContext): Promise<void> {
149
+ const [verb, ...words] = c.text.split(/\s+/);
150
+ const rest = words.join(" ");
151
+ try {
152
+ if (verb === "link") return await c.reply(await linkMessage(c));
153
+ if (verb === "unlink") {
154
+ await unlinkAccount(c.env, c.identity);
155
+ return await c.reply("Your Tavus account is disconnected from Slack.");
156
+ }
157
+ const call = await toolCaller(c);
158
+ if (verb === "pals") return await c.reply(await listPals(call));
159
+ if (verb === "recent") return await c.reply(await recentConversations(call, rest));
160
+ if (verb === "transcript") return await c.reply(await transcript(call, words[0]));
161
+ if (verb === "chat") return await startChat(c, call, words);
162
+ await c.reply(HELP);
163
+ } catch (error) {
164
+ await c.reply(await failureMessage(c, error, true));
165
+ }
166
+ }
167
+
168
+ interface EventContext extends Omit<CommandContext, "reply" | "text"> {
169
+ text: string;
170
+ thread: string;
171
+ isDirectMessage: boolean;
172
+ isReply: boolean;
173
+ }
174
+
175
+ async function runEvent(e: EventContext): Promise<void> {
176
+ const reply: Reply = (message) => postMessage(e.env, e.channel, message, e.thread).then(() => undefined);
177
+ try {
178
+ const state = e.isReply || !e.isDirectMessage ? await loadChat(e.env, e.identity, e.channel, e.thread) : undefined;
179
+ if (state) {
180
+ if (state.user_id !== e.identity.user_id) {
181
+ return await reply("Only the person who started this chat can continue it.");
182
+ }
183
+ if (!state.link_id) throw new AccountChanged();
184
+ if (e.text.toLowerCase() === "end") {
185
+ const call = await toolCaller(e, state.link_id);
186
+ await call("tavus_chat_end", { conversation_id: state.conversation_id });
187
+ await e.env.SLACK_LINKS?.getByName(chatName(e.identity, e.channel, e.thread)).remove();
188
+ return await reply("Chat ended.");
189
+ }
190
+ return await dispatchJob(e.env, {
191
+ kind: "chat",
192
+ identity: e.identity,
193
+ link_id: state.link_id,
194
+ origin: e.origin,
195
+ channel: e.channel,
196
+ thread: e.thread,
197
+ text: e.text,
198
+ pal: { id: "", name: state.pal_name },
199
+ conversation_id: state.conversation_id,
200
+ });
201
+ }
202
+ if (!e.isDirectMessage) return await reply(HELP);
203
+ await runCommand({ ...e, reply, directThread: e.thread });
204
+ } catch (error) {
205
+ await reply(await failureMessage(e, error, e.isDirectMessage));
206
+ }
207
+ }
208
+
209
+ async function startChat(c: CommandContext, call: ToolCaller, words: string[]): Promise<void> {
210
+ if (words.length < 2) return c.reply("Usage: `/tavus chat <PAL name or ID> <message>`");
211
+ const pals = await allPals(call);
212
+ const byId = pals.find((pal) => pal.pal_id === words[0]);
213
+ const names = pals.map((pal) => ({ pal, words: pal.name.trim().split(/\s+/) }))
214
+ .filter((entry) => entry.words.every((word, index) => word.toLowerCase() === words[index]?.toLowerCase()))
215
+ .sort((a, b) => b.words.length - a.words.length);
216
+ if (!byId && names.length > 1 && names[0].words.length === names[1].words.length) {
217
+ throw new Error("More than one PAL has that name. Use its ID from `/tavus pals`.");
218
+ }
219
+ const pal = byId ?? names[0]?.pal ?? selectPal(pals, words[0]);
220
+ if (!pal) return c.reply(`No PAL matches \`${words[0]}\`. Use \`/tavus pals\` to see yours.`);
221
+ const used = byId ? 1 : names[0]?.words.length ?? 1;
222
+ const message = words.slice(used).join(" ");
223
+ if (!message) return c.reply("Usage: `/tavus chat <PAL name or ID> <message>`");
224
+ let thread = c.directThread;
225
+ if (!thread) {
226
+ const posted = await postMessage(c.env, c.channel, `<@${c.identity.user_id}> chat with *${pal.name}*: ${plain(message)}`);
227
+ if (!posted.ts) {
228
+ return c.reply(
229
+ posted.error === "not_in_channel" || posted.error === "channel_not_found"
230
+ ? "Invite @Tavus to this channel first, or message it directly."
231
+ : "Slack would not let the bot post here. Try a direct message with @Tavus.",
232
+ );
233
+ }
234
+ thread = posted.ts;
235
+ }
236
+ await dispatchJob(c.env, {
237
+ kind: "chat",
238
+ identity: c.identity,
239
+ link_id: call.linkId,
240
+ origin: c.origin,
241
+ channel: c.channel,
242
+ thread,
243
+ text: message,
244
+ pal: { id: pal.pal_id, name: pal.name },
245
+ });
246
+ }
247
+
248
+ export async function runJob(env: Env, job: ChatJob): Promise<void> {
249
+ const reply = (text: string) => postMessage(env, job.channel, text, job.thread).then(() => undefined);
250
+ try {
251
+ if (!job.link_id) throw new AccountChanged();
252
+ const call = await toolCaller({ env, identity: job.identity, origin: job.origin }, job.link_id);
253
+ let conversationId = job.conversation_id;
254
+ if (!conversationId) {
255
+ const started = await call("tavus_chat_start", { pal_id: job.pal?.id });
256
+ conversationId = typeof started.conversation_id === "string" ? started.conversation_id : undefined;
257
+ if (!conversationId) return await reply("The PAL did not start a chat. Try again in a minute.");
258
+ await saveChat(env, job, { user_id: job.identity.user_id, link_id: job.link_id, conversation_id: conversationId, pal_name: job.pal?.name ?? "PAL", started_at: now() });
259
+ }
260
+ const turn = await call("tavus_chat_turn", {
261
+ conversation_id: conversationId,
262
+ text: job.text,
263
+ timeout_s: CHAT_TURN_TIMEOUT_SECONDS,
264
+ });
265
+ const answer = typeof turn.text === "string" && turn.text ? turn.text : "The PAL did not reply in time. Send your message again.";
266
+ await reply(`*${job.pal?.name ?? "PAL"}:* ${plain(answer)}`);
267
+ } catch (error) {
268
+ await reply(await failureMessage({ env, identity: job.identity, origin: job.origin }, error, isDirectChannel(job.channel)));
269
+ }
270
+ }
271
+
272
+ async function dispatchJob(env: Env, job: ChatJob): Promise<void> {
273
+ if (!env.SLACK_LINKS) throw new Error("Slack chats are not configured.");
274
+ await env.SLACK_LINKS.getByName(`job:${crypto.randomUUID()}`).run(JSON.stringify(job));
275
+ }
276
+
277
+ type ToolCaller = ((name: string, args: Fields) => Promise<Fields>) & { linkId: string };
278
+
279
+ async function toolCaller(c: { env: Env; identity: SlackIdentity; origin: string }, expectedLinkId?: string): Promise<ToolCaller> {
280
+ const account = await linkedAccount(c.env, c.identity);
281
+ if (!account) throw new NotLinked();
282
+ if (expectedLinkId !== undefined && account.linkId !== expectedLinkId) throw new AccountChanged();
283
+ const { apiKey, linkId } = account;
284
+ const call = async (name: string, args: Fields): Promise<Fields> => {
285
+ const server = createTavusMcpServer(c.env, apiKey, undefined, c.origin);
286
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
287
+ const client = new Client({ name: "tavus-slack-bot", version: "1" });
288
+ await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]);
289
+ try {
290
+ const result = (await client.callTool({
291
+ name,
292
+ arguments: { ...args, intent: "Run a Tavus Slack bot command." },
293
+ }, undefined, name === "tavus_chat_turn" ? { timeout: 180_000 } : undefined)) as { isError?: boolean; content?: Array<{ type: string; text?: string }> };
294
+ const text = (result.content ?? []).map((part) => part.text ?? "").join("\n");
295
+ if (result.isError) throw new Error(text.slice(0, 300) || "The Tavus API returned an error.");
296
+ return parseJson(text) ?? { text };
297
+ } finally {
298
+ await client.close();
299
+ }
300
+ };
301
+ return Object.assign(call, { linkId });
302
+ }
303
+
304
+ async function listPals(call: ToolCaller): Promise<string> {
305
+ const pals = rows(await call("tavus_pal_list", { limit: 25, sort: "desc" }));
306
+ if (!pals.length) return "You have no PALs yet.";
307
+ return `Your newest PALs:\n${pals.map((pal) => `• *${pal.name}* \`${pal.pal_id}\``).join("\n")}`;
308
+ }
309
+
310
+ async function recentConversations(call: ToolCaller, palRef: string): Promise<string> {
311
+ const args: Fields = { limit: 10 };
312
+ if (palRef) {
313
+ const pal = await findPal(call, palRef);
314
+ if (!pal) return `No PAL matches \`${palRef}\`. Use \`/tavus pals\` to see yours.`;
315
+ args.pal_id = pal.pal_id;
316
+ }
317
+ const list = rows(await call("tavus_conversation_list", args));
318
+ if (!list.length) return "No conversations found.";
319
+ return list
320
+ .map((row) => `• \`${row.conversation_id}\` ${row.status} ${String(row.created_at ?? "").slice(0, 16)} ${row.conversation_name ?? ""}`.trimEnd())
321
+ .join("\n");
322
+ }
323
+
324
+ async function transcript(call: ToolCaller, conversationId: string | undefined): Promise<string> {
325
+ if (!conversationId) return "Usage: `/tavus transcript <conversation ID>`";
326
+ const conversation = await call("tavus_conversation_get", { conversation_id: conversationId });
327
+ const head = `\`${conversation.conversation_id}\` ${conversation.status}${conversation.shutdown_reason ? `, ended: ${conversation.shutdown_reason}` : ""}`;
328
+ const messages = Array.isArray(conversation.transcript) ? (conversation.transcript as Fields[]) : [];
329
+ if (!messages.length) return `${head}\nNo transcript is available.`;
330
+ const body = messages.map((message) => `*${message.role}:* ${message.content}`).join("\n");
331
+ return `${head}\n${body.length > MAX_MESSAGE_LENGTH ? `${body.slice(0, MAX_MESSAGE_LENGTH)}\n… (cut short)` : body}`;
332
+ }
333
+
334
+ interface PalSummary {
335
+ pal_id: string;
336
+ name: string;
337
+ }
338
+
339
+ async function findPal(call: ToolCaller, ref: string): Promise<PalSummary | undefined> {
340
+ return selectPal(await allPals(call), ref);
341
+ }
342
+
343
+ async function allPals(call: ToolCaller): Promise<PalSummary[]> {
344
+ const pals: PalSummary[] = [];
345
+ const seen = new Set<string>();
346
+ for (let page = 0; page < MAX_PAL_PAGES; page += 1) {
347
+ const batch = rows(await call("tavus_pal_list", { limit: PAL_PAGE_SIZE, page, sort: "desc" })) as unknown as PalSummary[];
348
+ const fresh = batch.filter((pal) => !seen.has(pal.pal_id));
349
+ fresh.forEach((pal) => seen.add(pal.pal_id));
350
+ pals.push(...fresh);
351
+ if (batch.length < PAL_PAGE_SIZE || fresh.length === 0) break;
352
+ }
353
+ return pals;
354
+ }
355
+
356
+ function selectPal(pals: PalSummary[], ref: string): PalSummary | undefined {
357
+ const byId = pals.find((pal) => pal.pal_id === ref);
358
+ if (byId) return byId;
359
+ const wanted = ref.toLowerCase();
360
+ const exact = pals.filter((pal) => pal.name.toLowerCase() === wanted);
361
+ const matches = exact.length ? exact : pals.filter((pal) => pal.name.toLowerCase().includes(wanted));
362
+ if (matches.length > 1) throw new Error("More than one PAL matches. Use its full name or ID from `/tavus pals`.");
363
+ return matches[0];
364
+ }
365
+
366
+ function rows(result: Fields): Fields[] {
367
+ return Array.isArray(result.data) ? (result.data as Fields[]) : [];
368
+ }
369
+
370
+ async function linkMessage(c: { env: Env; identity: SlackIdentity; origin: string }): Promise<string> {
371
+ const href = await createLinkUrl(c.env, c.identity, c.origin);
372
+ return href
373
+ ? `Connect your Tavus account first: ${href}\nThe link works for 10 minutes.`
374
+ : "Linking Tavus accounts is not set up yet. Ask your Tavus admin.";
375
+ }
376
+
377
+ async function failureMessage(
378
+ c: { env: Env; identity: SlackIdentity; origin: string },
379
+ error: unknown,
380
+ isPrivate: boolean,
381
+ ): Promise<string> {
382
+ if (error instanceof AccountChanged) return "Your Tavus account link changed. Start a new chat with `/tavus chat`.";
383
+ const message = error instanceof Error ? error.message : String(error);
384
+ if (error instanceof NotLinked || /authorization (is no longer valid|was revoked)/i.test(message)) {
385
+ return isPrivate ? linkMessage(c) : "Run `/tavus link` to connect your Tavus account.";
386
+ }
387
+ return isPrivate ? `Something went wrong: ${message.slice(0, 300)}` : "Something went wrong. Try again in a minute.";
388
+ }
389
+
390
+ function isDirectChannel(channel: string): boolean {
391
+ return channel.startsWith("D");
392
+ }
393
+
394
+ function plain(text: string): string {
395
+ return text.replace(/<!([a-z]+)[^>]*>/gi, "@$1").replace(/<@([A-Z0-9]+)(\|[^>]*)?>/g, "@$1");
396
+ }
397
+
398
+ async function postMessage(env: Env, channel: string, text: string, thread?: string): Promise<{ ts?: string; error?: string }> {
399
+ const base = env.SLACK_API_BASE_URL ?? "https://slack.com/api";
400
+ const response = await fetch(`${base}/chat.postMessage`, {
401
+ method: "POST",
402
+ headers: { "Content-Type": "application/json; charset=utf-8", Authorization: `Bearer ${env.SLACK_BOT_TOKEN ?? ""}` },
403
+ body: JSON.stringify({ channel, text, unfurl_links: false, unfurl_media: false, ...(thread ? { thread_ts: thread } : {}) }),
404
+ });
405
+ const result = (await response.json().catch(() => ({}))) as { ok?: boolean; ts?: string; error?: string };
406
+ return result.ok ? { ts: result.ts } : { error: result.error ?? "unknown_error" };
407
+ }
408
+
409
+ function chatName(identity: SlackIdentity, channel: string, thread: string): string {
410
+ return `chat:${identity.team_id}:${channel}:${thread}`;
411
+ }
412
+
413
+ async function saveChat(env: Env, job: ChatJob, state: ChatState): Promise<void> {
414
+ const secret = oauthSigningSecret(env);
415
+ if (!env.SLACK_LINKS || !secret) return;
416
+ await env.SLACK_LINKS.getByName(chatName(job.identity, job.channel, job.thread)).put(await sealPayload(state, secret));
417
+ }
418
+
419
+ async function loadChat(env: Env, identity: SlackIdentity, channel: string, thread: string): Promise<ChatState | undefined> {
420
+ const secret = oauthSigningSecret(env);
421
+ if (!env.SLACK_LINKS || !secret) return undefined;
422
+ const sealed = await env.SLACK_LINKS.getByName(chatName(identity, channel, thread)).get();
423
+ const state = sealed ? await openPayload<ChatState>(sealed, secret) : null;
424
+ return state && now() - state.started_at < CHAT_MAX_AGE_SECONDS ? state : undefined;
425
+ }
426
+
427
+ function now(): number {
428
+ return Math.floor(Date.now() / 1000);
429
+ }
430
+
431
+ function ephemeral(text: string): Response {
432
+ return new Response(JSON.stringify({ response_type: "ephemeral", text }), {
433
+ headers: { "Content-Type": "application/json" },
434
+ });
435
+ }
436
+
437
+ function parseJson(text: string): Fields | undefined {
438
+ try {
439
+ const value = JSON.parse(text);
440
+ return value && typeof value === "object" && !Array.isArray(value) ? (value as Fields) : undefined;
441
+ } catch {
442
+ return undefined;
443
+ }
444
+ }
@@ -1,9 +1,13 @@
1
1
  import { DurableObject } from "cloudflare:workers";
2
2
 
3
+ import { type ChatJob, runJob } from "./slack-bot";
4
+ import type { Env } from "./tavus";
5
+
3
6
  export interface SlackLinkStoreStub {
4
7
  put(encryptedKey: string): Promise<void>;
5
8
  get(): Promise<string | null>;
6
9
  remove(): Promise<void>;
10
+ run(job: string): Promise<void>;
7
11
  }
8
12
 
9
13
  export interface SlackLinkStoreBinding {
@@ -11,6 +15,8 @@ export interface SlackLinkStoreBinding {
11
15
  }
12
16
 
13
17
  // One object per Slack team and user holds the Tavus account key that person linked.
18
+ // Other names reuse the same single-slot storage: `chat:` objects remember a chat thread and
19
+ // `job:` objects run one slow chat turn from an alarm, which a request's 30-second background limit would cut off.
14
20
  export class SlackLinkStore extends DurableObject {
15
21
  constructor(ctx: DurableObjectState, env: Cloudflare.Env) {
16
22
  super(ctx, env);
@@ -37,4 +43,19 @@ export class SlackLinkStore extends DurableObject {
37
43
  remove(): void {
38
44
  this.ctx.storage.sql.exec(`DELETE FROM link`);
39
45
  }
46
+
47
+ async run(job: string): Promise<void> {
48
+ await this.ctx.storage.put("job", job);
49
+ await this.ctx.storage.setAlarm(Date.now());
50
+ }
51
+
52
+ async alarm(): Promise<void> {
53
+ const job = await this.ctx.storage.get<string>("job");
54
+ if (!job) return;
55
+ try {
56
+ await runJob(this.env as unknown as Env, JSON.parse(job) as ChatJob);
57
+ } finally {
58
+ await this.ctx.storage.deleteAll();
59
+ }
60
+ }
40
61
  }