cobito 0.1.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.
- cobito-0.1.0/.gitignore +10 -0
- cobito-0.1.0/.mise/locks/pipx-uv-override-prune/1.0.4/pyproject.toml +5 -0
- cobito-0.1.0/.mise/locks/pipx-uv-override-prune/1.0.4/uv.lock +45 -0
- cobito-0.1.0/CONTRIBUTING.md +48 -0
- cobito-0.1.0/LICENSE +21 -0
- cobito-0.1.0/PKG-INFO +131 -0
- cobito-0.1.0/README.md +107 -0
- cobito-0.1.0/SECURITY.md +9 -0
- cobito-0.1.0/pyproject.toml +109 -0
- cobito-0.1.0/src/cobito/__init__.py +29 -0
- cobito-0.1.0/src/cobito/_reaction.py +81 -0
- cobito-0.1.0/src/cobito/_resend.py +149 -0
- cobito-0.1.0/src/cobito/_stream.py +319 -0
- cobito-0.1.0/src/cobito/_stream_logic.py +182 -0
- cobito-0.1.0/src/cobito/_tools.py +93 -0
- cobito-0.1.0/src/cobito/_version.py +24 -0
- cobito-0.1.0/src/cobito/py.typed +0 -0
- cobito-0.1.0/tests/test_resend.py +200 -0
- cobito-0.1.0/tests/test_stream_logic.py +134 -0
- cobito-0.1.0/tests/test_stream_rollover.py +111 -0
- cobito-0.1.0/tests/test_tools.py +78 -0
cobito-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
revision = 5
|
|
3
|
+
requires-python = ">=3.11"
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "mise-pypi-tool-environment"
|
|
7
|
+
version = "0.0.0"
|
|
8
|
+
source = { virtual = "." }
|
|
9
|
+
dependencies = [
|
|
10
|
+
{ name = "uv-override-prune" },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[package.metadata]
|
|
14
|
+
requires-dist = [{ name = "uv-override-prune", specifier = "==1.0.4" }]
|
|
15
|
+
|
|
16
|
+
[[package]]
|
|
17
|
+
name = "packaging"
|
|
18
|
+
version = "26.4"
|
|
19
|
+
source = { registry = "https://pypi.org/simple/" }
|
|
20
|
+
sdist = { url = "https://files.pythonhosted.org/packages/c3/75/ffb1dc0ed12352139fb4ca0e3fde4325a23e3d0f3f40efe89717bc4f557b/packaging-26.4.tar.gz", hash = "sha256:c4b671c41ddb9bf26e543c37723610d28fb6bf7affc4da17cf048d419d2c062a", size = 355877, upload-time = "2026-11-23T21:44:11.152Z" }
|
|
21
|
+
wheels = [
|
|
22
|
+
{ url = "https://files.pythonhosted.org/packages/ba/7b/5504f91c9c2733f693d7759e50ede5d27119d4da7e5836c46d3b5ff81d56/packaging-26.4-py3-none-any.whl", hash = "sha256:81383611a09c1bc0b08b76e0fd5829d7c6824c65b27a6aee339da133f4233ea2", size = 140049, upload-time = "2026-11-23T21:44:09.531Z" },
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[[package]]
|
|
26
|
+
name = "tomlkit"
|
|
27
|
+
version = "0.15.3"
|
|
28
|
+
source = { registry = "https://pypi.org/simple/" }
|
|
29
|
+
sdist = { url = "https://files.pythonhosted.org/packages/c9/85/4a7c68111c057a6498f5bc721ef93b388b420bb31d7020759f18a5f0c2ec/tomlkit-0.15.3.tar.gz", hash = "sha256:b3c3020ec1a4bd469d12e31fb4da938e7f6ba758cdbec3fd9047db63120eaf81", size = 204435, upload-time = "2026-11-24T07:21:10.422Z" }
|
|
30
|
+
wheels = [
|
|
31
|
+
{ url = "https://files.pythonhosted.org/packages/c3/49/6b0a22e69c844c0b18cb66c206bdd791693d0cf845badc5f84e6448f2192/tomlkit-0.15.3-py3-none-any.whl", hash = "sha256:a83ce6de3b648e68dd9b50aabadad749ba823eb58b1d026f3c0a283c4767a9c1", size = 55467, upload-time = "2026-11-24T07:21:11.239Z" },
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[[package]]
|
|
35
|
+
name = "uv-override-prune"
|
|
36
|
+
version = "1.0.4"
|
|
37
|
+
source = { registry = "https://pypi.org/simple/" }
|
|
38
|
+
dependencies = [
|
|
39
|
+
{ name = "packaging" },
|
|
40
|
+
{ name = "tomlkit" },
|
|
41
|
+
]
|
|
42
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b5/ad/b78460ce8350d4c3fce06b2f11e92f2eff0d91d929d17f49562fe4785b30/uv_override_prune-1.0.4.tar.gz", hash = "sha256:c34c688809168ba8b35e618df8440021ee8a0fe08af17461c45cfce1d30d3695", size = 28901, upload-time = "2026-11-29T03:34:05.383Z" }
|
|
43
|
+
wheels = [
|
|
44
|
+
{ url = "https://files.pythonhosted.org/packages/55/94/5cd352ef3551f162383c4fa76f28977dd99890e8337d8321a2519e916a90/uv_override_prune-1.0.4-py3-none-any.whl", hash = "sha256:71681d9bf6cdd1597fe0369bc3ed77122bdde509e6c6b23b9c906b8d3561c3eb", size = 14207, upload-time = "2026-11-29T03:34:04.202Z" },
|
|
45
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
We welcome contributions! Please follow these guidelines when submitting pull requests.
|
|
4
|
+
|
|
5
|
+
## Recommended setup
|
|
6
|
+
|
|
7
|
+
After cloning, enable the git hooks:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
mise run enable-git-hooks
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This wires `./validate.sh` to `pre-commit`, plus DCO and Conventional Commits checks to `commit-msg`, so the requirements below run automatically on each commit.
|
|
14
|
+
|
|
15
|
+
## Before Submitting a PR
|
|
16
|
+
|
|
17
|
+
### 1. Run Validation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
./validate.sh
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Runs the project's validation pipeline.
|
|
24
|
+
|
|
25
|
+
### 2. Sign Commits with DCO
|
|
26
|
+
|
|
27
|
+
All commits must be signed with DCO. Use `git commit -s` to sign your commits.
|
|
28
|
+
|
|
29
|
+
- Use your real name (no pseudonyms)
|
|
30
|
+
- All commits in a PR must be signed
|
|
31
|
+
- If the DCO check fails, see the check details page for instructions on fixing unsigned commits
|
|
32
|
+
|
|
33
|
+
For more about DCO: https://developercertificate.org/
|
|
34
|
+
|
|
35
|
+
### 3. Follow Conventional Commits
|
|
36
|
+
|
|
37
|
+
Commit subjects (first line) must follow `<type>(<scope>)?!?: <description>`. Allowed types: `feat`, `fix`, `chore`, `docs`. Append `!` for breaking changes.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
feat: add dark-mode toggle
|
|
41
|
+
fix(auth): handle expired token
|
|
42
|
+
chore: bump dependencies
|
|
43
|
+
feat!: drop legacy API
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Other types (`refactor`, `ci`, `test`, etc.) are intentionally rejected — use `chore:` instead.
|
|
47
|
+
|
|
48
|
+
For more about Conventional Commits: https://www.conventionalcommits.org/
|
cobito-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Takashi Iwamoto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cobito-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cobito
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn a Slack thread into a conversation for your AI agent, and stream the agent's reply back into the thread
|
|
5
|
+
Project-URL: Repository, https://github.com/iwamot/cobito
|
|
6
|
+
Project-URL: Issues, https://github.com/iwamot/cobito/issues
|
|
7
|
+
Author: Takashi Iwamoto
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agents,llm,slack,slack-bot,streaming
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
18
|
+
Classifier: Topic :: Communications :: Chat
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: aiohttp>=3.14.5
|
|
22
|
+
Requires-Dist: slack-sdk>=3.48.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# cobito
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/cobito/)
|
|
28
|
+
[](https://pypi.org/project/cobito/)
|
|
29
|
+
|
|
30
|
+
Turn a Slack thread into a conversation for your AI agent, and stream the agent's reply back into the thread.
|
|
31
|
+
|
|
32
|
+
cobito is the Slack side of an agent bot, kept apart from how the bot calls its model or agent. It streams a reply of any length with Slack's chat streaming, shows tool calls as tasks in the reply, marks the post being worked on, and makes a conversation smaller when the agent cannot take it.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pip install cobito
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
cobito is asynchronous and works with slack-sdk's `AsyncWebClient`, as Bolt's `AsyncApp` hands it to listeners.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Streaming a reply
|
|
45
|
+
|
|
46
|
+
`RotatingChatStream` has the append/stop surface of slack-sdk's `AsyncChatStream`. When a message nears Slack's length limit, the reply moves on to a new message in the same thread at a paragraph break, so no table or code block is cut in two.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from cobito import RotatingChatStream, ToolUse, tool_chunks
|
|
50
|
+
|
|
51
|
+
stream = RotatingChatStream(
|
|
52
|
+
client,
|
|
53
|
+
channel=channel_id,
|
|
54
|
+
thread_ts=thread_ts,
|
|
55
|
+
recipient_team_id=team_id,
|
|
56
|
+
recipient_user_id=user_id,
|
|
57
|
+
buffer_size=256,
|
|
58
|
+
)
|
|
59
|
+
await stream.append(chunks=tool_chunks(started=ToolUse(name="search", tool_use_id="t1")))
|
|
60
|
+
await stream.append(chunks=tool_chunks(completed=ToolUse(name="search", tool_use_id="t1")))
|
|
61
|
+
await stream.append(markdown_text="Here is what I found.")
|
|
62
|
+
await stream.stop()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The stream opens on its first append, so a reply that fails before it has anything to show leaves no empty message behind. On shutdown, `close_open_streams(markdown_text=...)` closes every reply still streaming, with a note saying why.
|
|
66
|
+
|
|
67
|
+
### Marking the post being worked on
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from cobito import WaitingReaction
|
|
71
|
+
|
|
72
|
+
waiting = WaitingReaction(client, channel_id=channel_id, message_ts=message_ts)
|
|
73
|
+
await waiting.add()
|
|
74
|
+
try:
|
|
75
|
+
... # reply
|
|
76
|
+
finally:
|
|
77
|
+
await waiting.clear()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Both calls are best-effort: without the `reactions:write` scope the post goes unmarked.
|
|
81
|
+
|
|
82
|
+
### Resending a conversation that is too long
|
|
83
|
+
|
|
84
|
+
When the agent fails before sending anything back, the conversation may have been more than its model takes. Send it once more as it was, then drop the oldest turns with `drop_older_turns`, a tenth on the first try and twice as many on each try after. The newest turn is always kept, and a turn keeps a question together with the bot's replies to it.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from cobito import apply_history_cut, drop_older_turns, history_cut_metadata
|
|
88
|
+
|
|
89
|
+
EVENT_TYPE = "my_bot_history"
|
|
90
|
+
|
|
91
|
+
replies = apply_history_cut(replies, bot_user_id=bot_user_id, event_type=EVENT_TYPE)
|
|
92
|
+
sent = replies
|
|
93
|
+
resent_unchanged = False
|
|
94
|
+
dropping_tries = 0
|
|
95
|
+
while True:
|
|
96
|
+
cut = history_cut_metadata(sent[0]["ts"], event_type=EVENT_TYPE)
|
|
97
|
+
try:
|
|
98
|
+
await reply_with(sent, metadata=cut if dropping_tries else None)
|
|
99
|
+
break
|
|
100
|
+
except AgentFailedBeforeReplying:
|
|
101
|
+
if not resent_unchanged:
|
|
102
|
+
resent_unchanged = True
|
|
103
|
+
continue
|
|
104
|
+
dropping_tries += 1
|
|
105
|
+
shorter = drop_older_turns(
|
|
106
|
+
replies, bot_user_id=bot_user_id, attempt=dropping_tries
|
|
107
|
+
)
|
|
108
|
+
if shorter is None:
|
|
109
|
+
raise
|
|
110
|
+
sent = shorter
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`history_cut_metadata` goes on the reply as message metadata (`stop(metadata=...)`), and `apply_history_cut` reads it back from the thread, so the next turn starts from what fitted. Read the thread with `conversations.replies(include_all_metadata=True)` for the metadata to be there. The event type is yours to name; a cut recorded under another type is ignored.
|
|
114
|
+
|
|
115
|
+
## API
|
|
116
|
+
|
|
117
|
+
| Name | What it does |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `RotatingChatStream` | A streamed reply that continues in a new message when one fills up |
|
|
120
|
+
| `close_open_streams(markdown_text=)` | Close every reply still streaming, for shutdown |
|
|
121
|
+
| `note_after_reply(text)` | Set a note off from the reply it is appended to |
|
|
122
|
+
| `ToolUse`, `tool_chunks(completed=, started=, error=)` | The chunks that show a tool call starting and finishing |
|
|
123
|
+
| `PLAN_TITLE` | The heading over the tool calls |
|
|
124
|
+
| `WaitingReaction`, `WAITING_REACTION` | The reaction on the post being worked on |
|
|
125
|
+
| `history_cut_metadata(oldest_ts, event_type=)` | The message metadata recording where a conversation was cut |
|
|
126
|
+
| `apply_history_cut(replies, bot_user_id=, event_type=)` | Keep the replies from the last recorded cut |
|
|
127
|
+
| `drop_older_turns(replies, bot_user_id=, attempt=)` | Drop the oldest turns for one try |
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
cobito-0.1.0/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# cobito
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/cobito/)
|
|
4
|
+
[](https://pypi.org/project/cobito/)
|
|
5
|
+
|
|
6
|
+
Turn a Slack thread into a conversation for your AI agent, and stream the agent's reply back into the thread.
|
|
7
|
+
|
|
8
|
+
cobito is the Slack side of an agent bot, kept apart from how the bot calls its model or agent. It streams a reply of any length with Slack's chat streaming, shows tool calls as tasks in the reply, marks the post being worked on, and makes a conversation smaller when the agent cannot take it.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pip install cobito
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
cobito is asynchronous and works with slack-sdk's `AsyncWebClient`, as Bolt's `AsyncApp` hands it to listeners.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Streaming a reply
|
|
21
|
+
|
|
22
|
+
`RotatingChatStream` has the append/stop surface of slack-sdk's `AsyncChatStream`. When a message nears Slack's length limit, the reply moves on to a new message in the same thread at a paragraph break, so no table or code block is cut in two.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from cobito import RotatingChatStream, ToolUse, tool_chunks
|
|
26
|
+
|
|
27
|
+
stream = RotatingChatStream(
|
|
28
|
+
client,
|
|
29
|
+
channel=channel_id,
|
|
30
|
+
thread_ts=thread_ts,
|
|
31
|
+
recipient_team_id=team_id,
|
|
32
|
+
recipient_user_id=user_id,
|
|
33
|
+
buffer_size=256,
|
|
34
|
+
)
|
|
35
|
+
await stream.append(chunks=tool_chunks(started=ToolUse(name="search", tool_use_id="t1")))
|
|
36
|
+
await stream.append(chunks=tool_chunks(completed=ToolUse(name="search", tool_use_id="t1")))
|
|
37
|
+
await stream.append(markdown_text="Here is what I found.")
|
|
38
|
+
await stream.stop()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The stream opens on its first append, so a reply that fails before it has anything to show leaves no empty message behind. On shutdown, `close_open_streams(markdown_text=...)` closes every reply still streaming, with a note saying why.
|
|
42
|
+
|
|
43
|
+
### Marking the post being worked on
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from cobito import WaitingReaction
|
|
47
|
+
|
|
48
|
+
waiting = WaitingReaction(client, channel_id=channel_id, message_ts=message_ts)
|
|
49
|
+
await waiting.add()
|
|
50
|
+
try:
|
|
51
|
+
... # reply
|
|
52
|
+
finally:
|
|
53
|
+
await waiting.clear()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Both calls are best-effort: without the `reactions:write` scope the post goes unmarked.
|
|
57
|
+
|
|
58
|
+
### Resending a conversation that is too long
|
|
59
|
+
|
|
60
|
+
When the agent fails before sending anything back, the conversation may have been more than its model takes. Send it once more as it was, then drop the oldest turns with `drop_older_turns`, a tenth on the first try and twice as many on each try after. The newest turn is always kept, and a turn keeps a question together with the bot's replies to it.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from cobito import apply_history_cut, drop_older_turns, history_cut_metadata
|
|
64
|
+
|
|
65
|
+
EVENT_TYPE = "my_bot_history"
|
|
66
|
+
|
|
67
|
+
replies = apply_history_cut(replies, bot_user_id=bot_user_id, event_type=EVENT_TYPE)
|
|
68
|
+
sent = replies
|
|
69
|
+
resent_unchanged = False
|
|
70
|
+
dropping_tries = 0
|
|
71
|
+
while True:
|
|
72
|
+
cut = history_cut_metadata(sent[0]["ts"], event_type=EVENT_TYPE)
|
|
73
|
+
try:
|
|
74
|
+
await reply_with(sent, metadata=cut if dropping_tries else None)
|
|
75
|
+
break
|
|
76
|
+
except AgentFailedBeforeReplying:
|
|
77
|
+
if not resent_unchanged:
|
|
78
|
+
resent_unchanged = True
|
|
79
|
+
continue
|
|
80
|
+
dropping_tries += 1
|
|
81
|
+
shorter = drop_older_turns(
|
|
82
|
+
replies, bot_user_id=bot_user_id, attempt=dropping_tries
|
|
83
|
+
)
|
|
84
|
+
if shorter is None:
|
|
85
|
+
raise
|
|
86
|
+
sent = shorter
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`history_cut_metadata` goes on the reply as message metadata (`stop(metadata=...)`), and `apply_history_cut` reads it back from the thread, so the next turn starts from what fitted. Read the thread with `conversations.replies(include_all_metadata=True)` for the metadata to be there. The event type is yours to name; a cut recorded under another type is ignored.
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
| Name | What it does |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `RotatingChatStream` | A streamed reply that continues in a new message when one fills up |
|
|
96
|
+
| `close_open_streams(markdown_text=)` | Close every reply still streaming, for shutdown |
|
|
97
|
+
| `note_after_reply(text)` | Set a note off from the reply it is appended to |
|
|
98
|
+
| `ToolUse`, `tool_chunks(completed=, started=, error=)` | The chunks that show a tool call starting and finishing |
|
|
99
|
+
| `PLAN_TITLE` | The heading over the tool calls |
|
|
100
|
+
| `WaitingReaction`, `WAITING_REACTION` | The reaction on the post being worked on |
|
|
101
|
+
| `history_cut_metadata(oldest_ts, event_type=)` | The message metadata recording where a conversation was cut |
|
|
102
|
+
| `apply_history_cut(replies, bot_user_id=, event_type=)` | Keep the replies from the last recorded cut |
|
|
103
|
+
| `drop_older_turns(replies, bot_user_id=, attempt=)` | Drop the oldest turns for one try |
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
cobito-0.1.0/SECURITY.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Disclaimer
|
|
4
|
+
|
|
5
|
+
This software is provided "as is" without warranty. Security issues will be addressed on a best-effort basis.
|
|
6
|
+
|
|
7
|
+
## Reporting a Vulnerability
|
|
8
|
+
|
|
9
|
+
Please report security vulnerabilities through GitHub's Security Advisory "Report a Vulnerability" feature.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cobito"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "Turn a Slack thread into a conversation for your AI agent, and stream the agent's reply back into the thread"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "Takashi Iwamoto" }]
|
|
9
|
+
keywords = ["slack", "slack-bot", "ai-agents", "llm", "streaming"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
16
|
+
"Programming Language :: Python :: 3.14",
|
|
17
|
+
"Programming Language :: Python :: 3.15",
|
|
18
|
+
"Topic :: Communications :: Chat",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
# slack-sdk's async client (AsyncWebClient) runs on aiohttp.
|
|
23
|
+
"aiohttp>=3.14.5",
|
|
24
|
+
"slack-sdk>=3.48.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/iwamot/cobito"
|
|
29
|
+
Issues = "https://github.com/iwamot/cobito/issues"
|
|
30
|
+
|
|
31
|
+
# The dev group is included by `uv sync` and `uv run` by default, and —
|
|
32
|
+
# unlike a dev extra — is not published in the wheel metadata.
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"pip-licenses==5.5.5",
|
|
36
|
+
"pytest==9.2.0",
|
|
37
|
+
"pytest-cov==7.1.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
42
|
+
build-backend = "hatchling.build"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
source = "vcs"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.hooks.vcs]
|
|
48
|
+
version-file = "src/cobito/_version.py"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/cobito"]
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.sdist]
|
|
54
|
+
exclude = [
|
|
55
|
+
"/.codecov.yml",
|
|
56
|
+
"/.github",
|
|
57
|
+
"/compatibility.sh",
|
|
58
|
+
"/mise.lock",
|
|
59
|
+
"/mise.toml",
|
|
60
|
+
"/uv.lock",
|
|
61
|
+
"/validate.sh",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.uv]
|
|
65
|
+
exclude-newer = "1 day"
|
|
66
|
+
|
|
67
|
+
[tool.uv.audit]
|
|
68
|
+
# Check the locked packages against OSV malware advisories before any sync
|
|
69
|
+
# installs them, so a compromised release cannot run its install hooks here.
|
|
70
|
+
malware-check = true
|
|
71
|
+
|
|
72
|
+
[tool.ruff]
|
|
73
|
+
include = ["*.py", "src/**/*.py", "tests/**/*.py"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff.lint]
|
|
76
|
+
# Reference: https://pydevtools.com/handbook/how-to/how-to-configure-recommended-ruff-defaults/
|
|
77
|
+
extend-select = [
|
|
78
|
+
"F", # Pyflakes rules
|
|
79
|
+
"W", # PyCodeStyle warnings
|
|
80
|
+
"I", # Sort imports properly
|
|
81
|
+
"UP", # Warn if certain things can changed due to newer Python versions
|
|
82
|
+
"B", # Likely bugs
|
|
83
|
+
"C4", # Catch incorrect use of comprehensions, dict, list, etc
|
|
84
|
+
"FA", # Enforce from __future__ import annotations
|
|
85
|
+
"ISC", # Good use of string concatenation
|
|
86
|
+
"ICN", # Use common import conventions
|
|
87
|
+
"RET", # Good return practices
|
|
88
|
+
"TID", # Some good import practices
|
|
89
|
+
"PTH", # Use pathlib instead of os.path
|
|
90
|
+
"TD", # Be diligent with TODO comments
|
|
91
|
+
"S", # flake8-bandit (security)
|
|
92
|
+
]
|
|
93
|
+
ignore = [
|
|
94
|
+
"S101", # Allow assert in tests (pytest standard practice)
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
[tool.ty.src]
|
|
98
|
+
include = ["src", "tests"]
|
|
99
|
+
|
|
100
|
+
[tool.pytest.ini_options]
|
|
101
|
+
testpaths = ["tests"]
|
|
102
|
+
|
|
103
|
+
[tool.coverage.run]
|
|
104
|
+
source = ["cobito"]
|
|
105
|
+
branch = true
|
|
106
|
+
|
|
107
|
+
[tool.coverage.report]
|
|
108
|
+
show_missing = true
|
|
109
|
+
skip_covered = true
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Turn a Slack thread into a conversation for an AI agent, and stream the reply back."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from cobito._reaction import WAITING_REACTION, WaitingReaction
|
|
6
|
+
from cobito._resend import apply_history_cut, drop_older_turns, history_cut_metadata
|
|
7
|
+
from cobito._stream import RotatingChatStream, close_open_streams
|
|
8
|
+
from cobito._stream_logic import note_after_reply
|
|
9
|
+
from cobito._tools import PLAN_TITLE, ToolUse, tool_chunks
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from cobito._version import __version__
|
|
13
|
+
except ImportError:
|
|
14
|
+
__version__ = "0.0.0+unknown"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"PLAN_TITLE",
|
|
18
|
+
"WAITING_REACTION",
|
|
19
|
+
"RotatingChatStream",
|
|
20
|
+
"ToolUse",
|
|
21
|
+
"WaitingReaction",
|
|
22
|
+
"__version__",
|
|
23
|
+
"apply_history_cut",
|
|
24
|
+
"close_open_streams",
|
|
25
|
+
"drop_older_turns",
|
|
26
|
+
"history_cut_metadata",
|
|
27
|
+
"note_after_reply",
|
|
28
|
+
"tool_chunks",
|
|
29
|
+
]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Marks a Slack post with a waiting reaction while the app works on it.
|
|
2
|
+
|
|
3
|
+
The marker sits on the post being worked on for as long as the app is on
|
|
4
|
+
it; it comes off when the run ends, whether that is a finished reply or a
|
|
5
|
+
reported failure. Both sides are best-effort — an install that predates
|
|
6
|
+
the reactions:write scope simply goes without the marker.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
|
|
13
|
+
from slack_sdk.errors import SlackApiError
|
|
14
|
+
from slack_sdk.web.async_client import AsyncWebClient
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
# The waiting marker — deliberately not configurable, so the frame around
|
|
19
|
+
# the conversation reads the same on every deployment.
|
|
20
|
+
WAITING_REACTION = "eyes"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class WaitingReaction:
|
|
24
|
+
"""The waiting marker on one Slack post, added once and cleared once."""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
client: AsyncWebClient,
|
|
29
|
+
*,
|
|
30
|
+
channel_id: str,
|
|
31
|
+
message_ts: str,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Bind the marker to the post it will sit on.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
client (AsyncWebClient): The Slack Web API client.
|
|
38
|
+
channel_id (str): The ID of the channel holding the post.
|
|
39
|
+
message_ts (str): The timestamp of the post to mark.
|
|
40
|
+
"""
|
|
41
|
+
self._client = client
|
|
42
|
+
self._channel_id = channel_id
|
|
43
|
+
self._message_ts = message_ts
|
|
44
|
+
self._active = False
|
|
45
|
+
|
|
46
|
+
async def add(self) -> None:
|
|
47
|
+
"""
|
|
48
|
+
Put the marker on the post; a failure just leaves it off.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
None
|
|
52
|
+
"""
|
|
53
|
+
try:
|
|
54
|
+
await self._client.reactions_add(
|
|
55
|
+
channel=self._channel_id,
|
|
56
|
+
timestamp=self._message_ts,
|
|
57
|
+
name=WAITING_REACTION,
|
|
58
|
+
)
|
|
59
|
+
except SlackApiError:
|
|
60
|
+
logger.debug("Could not add the waiting reaction", exc_info=True)
|
|
61
|
+
return
|
|
62
|
+
self._active = True
|
|
63
|
+
|
|
64
|
+
async def clear(self) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Take the marker off the post. Idempotent — later calls no-op.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
None
|
|
70
|
+
"""
|
|
71
|
+
if not self._active:
|
|
72
|
+
return
|
|
73
|
+
self._active = False
|
|
74
|
+
try:
|
|
75
|
+
await self._client.reactions_remove(
|
|
76
|
+
channel=self._channel_id,
|
|
77
|
+
timestamp=self._message_ts,
|
|
78
|
+
name=WAITING_REACTION,
|
|
79
|
+
)
|
|
80
|
+
except SlackApiError:
|
|
81
|
+
logger.debug("Could not remove the waiting reaction", exc_info=True)
|