awdiscord 0.2.1__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 (42) hide show
  1. awdiscord-0.2.1/LICENSE +202 -0
  2. awdiscord-0.2.1/PKG-INFO +171 -0
  3. awdiscord-0.2.1/README.md +153 -0
  4. awdiscord-0.2.1/awdiscord/__init__.py +64 -0
  5. awdiscord-0.2.1/awdiscord/_doctor.py +190 -0
  6. awdiscord-0.2.1/awdiscord/agent.py +269 -0
  7. awdiscord-0.2.1/awdiscord/approvals.py +203 -0
  8. awdiscord-0.2.1/awdiscord/builtin/__init__.py +9 -0
  9. awdiscord-0.2.1/awdiscord/builtin/community.py +154 -0
  10. awdiscord-0.2.1/awdiscord/builtin/github.py +219 -0
  11. awdiscord-0.2.1/awdiscord/builtin/manage.py +66 -0
  12. awdiscord-0.2.1/awdiscord/builtin/ops.py +94 -0
  13. awdiscord-0.2.1/awdiscord/builtin/projects.py +126 -0
  14. awdiscord-0.2.1/awdiscord/builtin/web.py +197 -0
  15. awdiscord-0.2.1/awdiscord/cli.py +441 -0
  16. awdiscord-0.2.1/awdiscord/dispatch.py +290 -0
  17. awdiscord-0.2.1/awdiscord/forward.py +232 -0
  18. awdiscord-0.2.1/awdiscord/gateway.py +416 -0
  19. awdiscord-0.2.1/awdiscord/guard.py +47 -0
  20. awdiscord-0.2.1/awdiscord/install.py +59 -0
  21. awdiscord-0.2.1/awdiscord/packs.py +181 -0
  22. awdiscord-0.2.1/awdiscord/plugins.py +492 -0
  23. awdiscord-0.2.1/awdiscord/ratelimit.py +65 -0
  24. awdiscord-0.2.1/awdiscord/rest.py +84 -0
  25. awdiscord-0.2.1/awdiscord/setup.py +268 -0
  26. awdiscord-0.2.1/awdiscord/store.py +80 -0
  27. awdiscord-0.2.1/awdiscord/webhook.py +40 -0
  28. awdiscord-0.2.1/awdiscord.egg-info/PKG-INFO +171 -0
  29. awdiscord-0.2.1/awdiscord.egg-info/SOURCES.txt +40 -0
  30. awdiscord-0.2.1/awdiscord.egg-info/dependency_links.txt +1 -0
  31. awdiscord-0.2.1/awdiscord.egg-info/entry_points.txt +2 -0
  32. awdiscord-0.2.1/awdiscord.egg-info/requires.txt +6 -0
  33. awdiscord-0.2.1/awdiscord.egg-info/top_level.txt +1 -0
  34. awdiscord-0.2.1/pyproject.toml +44 -0
  35. awdiscord-0.2.1/setup.cfg +4 -0
  36. awdiscord-0.2.1/tests/test_awdiscord.py +339 -0
  37. awdiscord-0.2.1/tests/test_forward.py +451 -0
  38. awdiscord-0.2.1/tests/test_ops.py +44 -0
  39. awdiscord-0.2.1/tests/test_packs.py +153 -0
  40. awdiscord-0.2.1/tests/test_plugins.py +229 -0
  41. awdiscord-0.2.1/tests/test_setup.py +124 -0
  42. awdiscord-0.2.1/tests/test_web.py +113 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: awdiscord
3
+ Version: 0.2.1
4
+ Summary: Put any agent on Discord as a real bot - slash commands, approval buttons only your operators can press, rate limits, and no self-bots.
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Aitherium/awdiscord
7
+ Project-URL: Documentation, https://github.com/Aitherium/awdiscord#readme
8
+ Project-URL: Repository, https://github.com/Aitherium/awdiscord.git
9
+ Project-URL: Issues, https://github.com/Aitherium/awdiscord/issues
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Provides-Extra: gateway
14
+ Requires-Dist: discord.py>=2.3; extra == "gateway"
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=7.0; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # awdiscord
20
+
21
+ **Put any agent on Discord as a real bot, with an operator in the loop.**
22
+
23
+ An agent behind an OpenAI-compatible endpoint (an `adk serve` agent, llama.cpp /
24
+ Bonsai, vLLM, Ollama, LM Studio, a gateway) becomes a Discord bot with slash
25
+ commands, plugins each server turns on for itself, rate limits, and approval
26
+ buttons that only your operators can press. Your model, your machine.
27
+
28
+ ```bash
29
+ pip install "awdiscord[gateway]"
30
+ awdiscord setup # paste the bot token once; it does the rest
31
+ awdiscord run
32
+ ```
33
+
34
+ `setup` checks the token is a bot token, writes the app's profile and
35
+ least-permission install settings, finds a model server running on this machine
36
+ (Bonsai/llama.cpp :8090/:8080, Ollama :11434, LM Studio :1234, vLLM :8000), makes
37
+ the app's owner (or team) the operators, saves everything to
38
+ `~/.awdiscord/awdiscord.env` (mode 600), registers the commands and prints the
39
+ install link. The one step Discord does not allow from an API is creating the
40
+ application: do that at https://discord.com/developers/applications, open **Bot**,
41
+ press **Reset Token**.
42
+
43
+ | command | what it does |
44
+ |---|---|
45
+ | `/ask question [persona] [private]` | the agent answers; `private` shows only you |
46
+ | `/share` | posts your last answer in the channel |
47
+ | `/status` | is the agent up, which personas exist |
48
+ | `/plugins list\|info\|enable\|disable` | what this server has on (enable/disable: Manage Server) |
49
+
50
+ ## Plugins
51
+
52
+ Built in:
53
+
54
+ | plugin | default | commands |
55
+ |---|---|---|
56
+ | `community` | on | `/poll` with vote buttons, `/faq ask\|list\|set\|remove` (the agent answers from the FAQ only), `/rules` |
57
+ | `projects` | off | `/task add\|list\|start\|done\|assign\|drop`, `/standup` written by the agent from the board |
58
+ | `github` | off | `/gh board\|untracked\|issue\|connect` for a GitHub Projects board (`AWDISCORD_GITHUB_TOKEN`) |
59
+
60
+ Each server turns plugins on and off for itself; its data is kept per server and
61
+ never visible to another. A plugin's persona text is added to `/ask` only where
62
+ it is on.
63
+
64
+ Write your own:
65
+
66
+ ```bash
67
+ awdiscord new-plugin standup-bot # scaffolds ~/.awdiscord/plugins/standup_bot.py
68
+ awdiscord plugins # proves it loads (exit 1 names anything that failed)
69
+ ```
70
+
71
+ ```python
72
+ from awdiscord.plugins import Command, Option, Plugin
73
+
74
+ def hello(ctx): # ctx.user, ctx.guild, ctx.store, ctx.agent, ctx.opt()
75
+ return ctx.reply(f"hello <@{ctx.user}>")
76
+
77
+ PLUGIN = Plugin(name="hello", version="0.1.0", description="Says hello",
78
+ commands=[Command("hello", "Say hello", hello)])
79
+ ```
80
+
81
+ Plugins are found in `awdiscord.builtin`, the `awdiscord.plugins` entry-point group
82
+ (so `pip install` a plugin package and it loads), `AWDISCORD_PLUGIN_DIRS` and
83
+ `~/.awdiscord/plugins`. `AWDISCORD_PLUGINS=a,b` narrows the set.
84
+
85
+ ## Packs
86
+
87
+ ```bash
88
+ awdiscord pack install ./packs/dgg_pm # a plugin pack
89
+ awdiscord pack install ~/my-agent-pack # an awdk agent pack
90
+ awdiscord pack install https://github.com/org/repo#packs/x # from git
91
+ awdiscord pack list | remove NAME
92
+ ```
93
+
94
+ An **agent pack** (`brain_pack.yaml` / `agent.yaml` / `skills/`, the awdk and
95
+ awpack shape) becomes a plugin: its system prompt rides along on `/ask` where it
96
+ is on, its skills are listed to the agent, and `/<pack> ask` answers in its voice.
97
+ `packs/dgg_pm` is an example plugin pack: Digital Ground Game's org board with
98
+ their own status flow.
99
+
100
+ ## Run it under a supervisor
101
+
102
+ `awdiscord run --inbox-port 8371` opens `GET /health` for a supervisor. The awdk
103
+ addon manifest does exactly that, so `adk addon` (and awsh) can start, health-check
104
+ and restart the bot like any other local component.
105
+
106
+ ## Rails
107
+
108
+ - **Bot tokens only.** Every request is sent as `Authorization: Bot <token>`, and the
109
+ runtime asks Discord who the token belongs to before anything else. A user account
110
+ is refused. Driving a person's account ("self-bot") is against Discord's terms.
111
+ - **Least permission.** The install link asks for `bot` + `applications.commands` and
112
+ four permissions: view channel, send messages, embed links, read message history.
113
+ `install_url()` refuses administrator, manage-server, manage-roles, manage-webhooks,
114
+ ban, kick and mention-everyone.
115
+ - **Rate limits.** Token buckets per user, per server and for the whole bot; a request
116
+ must find room in all three, and a refusal says how long to wait.
117
+ - **Mentions off.** Every answer goes out with `allowed_mentions: {parse: []}`, so an
118
+ agent cannot ping `@everyone`.
119
+ - **Approvals.** A card with Approve / Deny buttons. The button id carries an HMAC of
120
+ the approval id and the verb, only user ids in `AWDISCORD_OPERATORS` count, a
121
+ decision is taken exactly once, and the result is POSTed to your callback with an
122
+ `X-Awdiscord-Signature` header (HMAC-SHA256 of the body under the same secret).
123
+
124
+ ## Approvals from your own code
125
+
126
+ Run the bot with an inbox, then raise cards from anything on the same machine:
127
+
128
+ ```bash
129
+ export AWDISCORD_OPERATORS=<your user id>
130
+ export AWDISCORD_APPROVAL_SECRET=$(python -c "import secrets;print(secrets.token_hex(32))")
131
+ export AWDISCORD_INBOX_PORT=8371 AWDISCORD_INBOX_TOKEN=<a long random string>
132
+ awdiscord run &
133
+ awdiscord approval "Publish the release notes?" "v1.4 notes are drafted" \
134
+ --callback http://127.0.0.1:9000/decided
135
+ ```
136
+
137
+ Without `AWDISCORD_APPROVAL_CHANNEL` the card is sent to each operator by DM.
138
+
139
+ ## Use the pieces alone
140
+
141
+ ```python
142
+ from awdiscord import install_url, RateLimiter, ApprovalDesk, post_webhook, Dispatcher
143
+
144
+ install_url("123456789012345678")
145
+ post_webhook("https://discord.com/api/webhooks/...", "deploy finished")
146
+ ```
147
+
148
+ `Dispatcher` takes the interaction JSON Discord sends and returns the response JSON,
149
+ with no network, so the bot's behaviour is testable with plain dicts.
150
+
151
+ ## Configuration
152
+
153
+ | variable | meaning |
154
+ |---|---|
155
+ | `DISCORD_BOT_TOKEN` / `AWDISCORD_TOKEN` | the bot token |
156
+ | `DISCORD_APP_ID` / `AWDISCORD_APP_ID` | application id (looked up from the token if unset) |
157
+ | `AWDISCORD_AGENT_URL`, `AWDISCORD_AGENT_MODEL`, `AWDISCORD_AGENT_KEY` | the agent |
158
+ | `AWDISCORD_PERSONAS_DIR` | `<name>.md` or `<name>/SOUL.md` files become `/ask persona:` choices |
159
+ | `AWDISCORD_DEFAULT_PERSONA` | persona used when none is chosen |
160
+ | `AWDISCORD_CA_BUNDLE` | CA file for an agent served over a private CA |
161
+ | `AWDISCORD_OPERATORS`, `AWDISCORD_APPROVAL_SECRET` | enable approvals |
162
+ | `AWDISCORD_APPROVAL_CHANNEL` | post cards here instead of DMing operators |
163
+ | `AWDISCORD_INBOX_PORT`, `AWDISCORD_INBOX_TOKEN`, `AWDISCORD_INBOX_HOST` | local inbox |
164
+ | `AWDISCORD_DEV_GUILD` | also register commands on one server (instant, for testing) |
165
+ | `AWDISCORD_STATE_DIR` | where approvals are stored (default `~/.awdiscord`) |
166
+
167
+ `awdiscord --self-test` proves every rail offline and exits non-zero if one does not hold.
168
+
169
+ ## License
170
+
171
+ Apache-2.0
@@ -0,0 +1,153 @@
1
+ # awdiscord
2
+
3
+ **Put any agent on Discord as a real bot, with an operator in the loop.**
4
+
5
+ An agent behind an OpenAI-compatible endpoint (an `adk serve` agent, llama.cpp /
6
+ Bonsai, vLLM, Ollama, LM Studio, a gateway) becomes a Discord bot with slash
7
+ commands, plugins each server turns on for itself, rate limits, and approval
8
+ buttons that only your operators can press. Your model, your machine.
9
+
10
+ ```bash
11
+ pip install "awdiscord[gateway]"
12
+ awdiscord setup # paste the bot token once; it does the rest
13
+ awdiscord run
14
+ ```
15
+
16
+ `setup` checks the token is a bot token, writes the app's profile and
17
+ least-permission install settings, finds a model server running on this machine
18
+ (Bonsai/llama.cpp :8090/:8080, Ollama :11434, LM Studio :1234, vLLM :8000), makes
19
+ the app's owner (or team) the operators, saves everything to
20
+ `~/.awdiscord/awdiscord.env` (mode 600), registers the commands and prints the
21
+ install link. The one step Discord does not allow from an API is creating the
22
+ application: do that at https://discord.com/developers/applications, open **Bot**,
23
+ press **Reset Token**.
24
+
25
+ | command | what it does |
26
+ |---|---|
27
+ | `/ask question [persona] [private]` | the agent answers; `private` shows only you |
28
+ | `/share` | posts your last answer in the channel |
29
+ | `/status` | is the agent up, which personas exist |
30
+ | `/plugins list\|info\|enable\|disable` | what this server has on (enable/disable: Manage Server) |
31
+
32
+ ## Plugins
33
+
34
+ Built in:
35
+
36
+ | plugin | default | commands |
37
+ |---|---|---|
38
+ | `community` | on | `/poll` with vote buttons, `/faq ask\|list\|set\|remove` (the agent answers from the FAQ only), `/rules` |
39
+ | `projects` | off | `/task add\|list\|start\|done\|assign\|drop`, `/standup` written by the agent from the board |
40
+ | `github` | off | `/gh board\|untracked\|issue\|connect` for a GitHub Projects board (`AWDISCORD_GITHUB_TOKEN`) |
41
+
42
+ Each server turns plugins on and off for itself; its data is kept per server and
43
+ never visible to another. A plugin's persona text is added to `/ask` only where
44
+ it is on.
45
+
46
+ Write your own:
47
+
48
+ ```bash
49
+ awdiscord new-plugin standup-bot # scaffolds ~/.awdiscord/plugins/standup_bot.py
50
+ awdiscord plugins # proves it loads (exit 1 names anything that failed)
51
+ ```
52
+
53
+ ```python
54
+ from awdiscord.plugins import Command, Option, Plugin
55
+
56
+ def hello(ctx): # ctx.user, ctx.guild, ctx.store, ctx.agent, ctx.opt()
57
+ return ctx.reply(f"hello <@{ctx.user}>")
58
+
59
+ PLUGIN = Plugin(name="hello", version="0.1.0", description="Says hello",
60
+ commands=[Command("hello", "Say hello", hello)])
61
+ ```
62
+
63
+ Plugins are found in `awdiscord.builtin`, the `awdiscord.plugins` entry-point group
64
+ (so `pip install` a plugin package and it loads), `AWDISCORD_PLUGIN_DIRS` and
65
+ `~/.awdiscord/plugins`. `AWDISCORD_PLUGINS=a,b` narrows the set.
66
+
67
+ ## Packs
68
+
69
+ ```bash
70
+ awdiscord pack install ./packs/dgg_pm # a plugin pack
71
+ awdiscord pack install ~/my-agent-pack # an awdk agent pack
72
+ awdiscord pack install https://github.com/org/repo#packs/x # from git
73
+ awdiscord pack list | remove NAME
74
+ ```
75
+
76
+ An **agent pack** (`brain_pack.yaml` / `agent.yaml` / `skills/`, the awdk and
77
+ awpack shape) becomes a plugin: its system prompt rides along on `/ask` where it
78
+ is on, its skills are listed to the agent, and `/<pack> ask` answers in its voice.
79
+ `packs/dgg_pm` is an example plugin pack: Digital Ground Game's org board with
80
+ their own status flow.
81
+
82
+ ## Run it under a supervisor
83
+
84
+ `awdiscord run --inbox-port 8371` opens `GET /health` for a supervisor. The awdk
85
+ addon manifest does exactly that, so `adk addon` (and awsh) can start, health-check
86
+ and restart the bot like any other local component.
87
+
88
+ ## Rails
89
+
90
+ - **Bot tokens only.** Every request is sent as `Authorization: Bot <token>`, and the
91
+ runtime asks Discord who the token belongs to before anything else. A user account
92
+ is refused. Driving a person's account ("self-bot") is against Discord's terms.
93
+ - **Least permission.** The install link asks for `bot` + `applications.commands` and
94
+ four permissions: view channel, send messages, embed links, read message history.
95
+ `install_url()` refuses administrator, manage-server, manage-roles, manage-webhooks,
96
+ ban, kick and mention-everyone.
97
+ - **Rate limits.** Token buckets per user, per server and for the whole bot; a request
98
+ must find room in all three, and a refusal says how long to wait.
99
+ - **Mentions off.** Every answer goes out with `allowed_mentions: {parse: []}`, so an
100
+ agent cannot ping `@everyone`.
101
+ - **Approvals.** A card with Approve / Deny buttons. The button id carries an HMAC of
102
+ the approval id and the verb, only user ids in `AWDISCORD_OPERATORS` count, a
103
+ decision is taken exactly once, and the result is POSTed to your callback with an
104
+ `X-Awdiscord-Signature` header (HMAC-SHA256 of the body under the same secret).
105
+
106
+ ## Approvals from your own code
107
+
108
+ Run the bot with an inbox, then raise cards from anything on the same machine:
109
+
110
+ ```bash
111
+ export AWDISCORD_OPERATORS=<your user id>
112
+ export AWDISCORD_APPROVAL_SECRET=$(python -c "import secrets;print(secrets.token_hex(32))")
113
+ export AWDISCORD_INBOX_PORT=8371 AWDISCORD_INBOX_TOKEN=<a long random string>
114
+ awdiscord run &
115
+ awdiscord approval "Publish the release notes?" "v1.4 notes are drafted" \
116
+ --callback http://127.0.0.1:9000/decided
117
+ ```
118
+
119
+ Without `AWDISCORD_APPROVAL_CHANNEL` the card is sent to each operator by DM.
120
+
121
+ ## Use the pieces alone
122
+
123
+ ```python
124
+ from awdiscord import install_url, RateLimiter, ApprovalDesk, post_webhook, Dispatcher
125
+
126
+ install_url("123456789012345678")
127
+ post_webhook("https://discord.com/api/webhooks/...", "deploy finished")
128
+ ```
129
+
130
+ `Dispatcher` takes the interaction JSON Discord sends and returns the response JSON,
131
+ with no network, so the bot's behaviour is testable with plain dicts.
132
+
133
+ ## Configuration
134
+
135
+ | variable | meaning |
136
+ |---|---|
137
+ | `DISCORD_BOT_TOKEN` / `AWDISCORD_TOKEN` | the bot token |
138
+ | `DISCORD_APP_ID` / `AWDISCORD_APP_ID` | application id (looked up from the token if unset) |
139
+ | `AWDISCORD_AGENT_URL`, `AWDISCORD_AGENT_MODEL`, `AWDISCORD_AGENT_KEY` | the agent |
140
+ | `AWDISCORD_PERSONAS_DIR` | `<name>.md` or `<name>/SOUL.md` files become `/ask persona:` choices |
141
+ | `AWDISCORD_DEFAULT_PERSONA` | persona used when none is chosen |
142
+ | `AWDISCORD_CA_BUNDLE` | CA file for an agent served over a private CA |
143
+ | `AWDISCORD_OPERATORS`, `AWDISCORD_APPROVAL_SECRET` | enable approvals |
144
+ | `AWDISCORD_APPROVAL_CHANNEL` | post cards here instead of DMing operators |
145
+ | `AWDISCORD_INBOX_PORT`, `AWDISCORD_INBOX_TOKEN`, `AWDISCORD_INBOX_HOST` | local inbox |
146
+ | `AWDISCORD_DEV_GUILD` | also register commands on one server (instant, for testing) |
147
+ | `AWDISCORD_STATE_DIR` | where approvals are stored (default `~/.awdiscord`) |
148
+
149
+ `awdiscord --self-test` proves every rail offline and exits non-zero if one does not hold.
150
+
151
+ ## License
152
+
153
+ Apache-2.0
@@ -0,0 +1,64 @@
1
+ """awdiscord - put any agent on Discord, as a real bot, with an operator in the loop.
2
+
3
+ from awdiscord import Bot, OpenAICompatAgent
4
+
5
+ agent = OpenAICompatAgent("http://127.0.0.1:8080/v1", model="my-agent")
6
+ Bot.from_env(agent=agent).run() # /ask, /share, /status
7
+
8
+ The pieces are usable alone:
9
+
10
+ install_url(app_id) one-click install link, minimal permissions
11
+ RateLimiter per-user / per-server / global token buckets
12
+ ApprovalDesk signed Approve/Deny cards only operators can press
13
+ post_webhook(url, "text") post to a channel webhook, mentions disabled
14
+ Dispatcher interaction JSON in, response JSON out
15
+
16
+ Bot tokens only. A user token ("self-bot") is refused at startup: it is against
17
+ Discord's terms and it is how accounts get banned.
18
+ """
19
+ from __future__ import annotations
20
+
21
+ from awdiscord.agent import (
22
+ AgentError,
23
+ CallableAgent,
24
+ EchoAgent,
25
+ OpenAICompatAgent,
26
+ load_personas,
27
+ )
28
+ from awdiscord.approvals import ApprovalDesk, ApprovalError, Decision
29
+ from awdiscord.dispatch import Dispatcher
30
+ from awdiscord.guard import TokenRefusedError, check_bot_token
31
+ from awdiscord.install import MINIMAL_PERMISSIONS, install_url
32
+ from awdiscord.ratelimit import RateLimiter
33
+ from awdiscord.webhook import WebhookError, post_webhook
34
+
35
+ __version__ = "0.2.1"
36
+
37
+ __all__ = [
38
+ "AgentError",
39
+ "ApprovalDesk",
40
+ "ApprovalError",
41
+ "CallableAgent",
42
+ "Decision",
43
+ "Dispatcher",
44
+ "EchoAgent",
45
+ "MINIMAL_PERMISSIONS",
46
+ "OpenAICompatAgent",
47
+ "RateLimiter",
48
+ "TokenRefusedError",
49
+ "WebhookError",
50
+ "check_bot_token",
51
+ "install_url",
52
+ "load_personas",
53
+ "post_webhook",
54
+ "Bot",
55
+ ]
56
+
57
+
58
+ def __getattr__(name):
59
+ # The gateway needs discord.py; import it lazily so every other piece of
60
+ # this package works with zero dependencies.
61
+ if name == "Bot":
62
+ from awdiscord.gateway import Bot
63
+ return Bot
64
+ raise AttributeError(name)