kimi-agent-module-api 1.0.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.
- kimi_agent_module_api-1.0.0/LICENSE +21 -0
- kimi_agent_module_api-1.0.0/PKG-INFO +51 -0
- kimi_agent_module_api-1.0.0/README.md +34 -0
- kimi_agent_module_api-1.0.0/pyproject.toml +29 -0
- kimi_agent_module_api-1.0.0/setup.cfg +4 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/__init__.py +175 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/contracts.py +1127 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/events.py +140 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/images.py +34 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/py.typed +1 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/settings.py +33 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/testing.py +1036 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/tools.py +63 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api/trust.py +36 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api.egg-info/PKG-INFO +51 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api.egg-info/SOURCES.txt +17 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api.egg-info/dependency_links.txt +1 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api.egg-info/requires.txt +4 -0
- kimi_agent_module_api-1.0.0/src/kimi_agent_module_api.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Webhead
|
|
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.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kimi-agent-module-api
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Stable contracts for community-built assistant modules
|
|
5
|
+
Author: Webhead
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Documentation, https://github.com/webhead2oo9/kimi-agent/blob/main/docs/modules.md
|
|
8
|
+
Project-URL: Issues, https://github.com/webhead2oo9/kimi-agent/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/webhead2oo9/kimi-agent
|
|
10
|
+
Requires-Python: >=3.14
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pydantic-settings>=2.14.2
|
|
14
|
+
Provides-Extra: testing
|
|
15
|
+
Requires-Dist: aiosqlite; extra == "testing"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# Kimi Agent Module API
|
|
19
|
+
|
|
20
|
+
The stable, host-independent contracts for building Kimi application modules:
|
|
21
|
+
separately installed packages that add commands, LLM tools, background jobs,
|
|
22
|
+
event handlers, per-guild settings, and durable data to a Kimi deployment.
|
|
23
|
+
|
|
24
|
+
This package contains no bot runtime, Discord client, database
|
|
25
|
+
implementation, or module loader. It exports:
|
|
26
|
+
|
|
27
|
+
- `ModuleSpec`, `ModuleLoadContext`, `ModuleRuntimeContext`: the declaration a
|
|
28
|
+
module publishes and the two contexts the host hands it.
|
|
29
|
+
- `kimi_agent_module_api.contracts`: every runtime port as a `typing.Protocol`
|
|
30
|
+
(storage, scheduler, events, Discord actions, interactions, HTTP, services,
|
|
31
|
+
trust, proposals, health) plus the validators the host runs at preflight.
|
|
32
|
+
- `kimi_agent_module_api.events`: the normalized `discord.*` event payloads.
|
|
33
|
+
- `kimi_agent_module_api.testing`: a fake for every port, `load_context()` for
|
|
34
|
+
exercising `create()`, and `MemoryStorage` (install the `testing` extra) so a
|
|
35
|
+
module can unit test itself with only this package installed.
|
|
36
|
+
|
|
37
|
+
A module exposes a `ModuleSpec` through the `kimi_agent.modules` entry-point
|
|
38
|
+
group:
|
|
39
|
+
|
|
40
|
+
```toml
|
|
41
|
+
[project]
|
|
42
|
+
dependencies = ["kimi-agent-module-api>=1,<2"]
|
|
43
|
+
|
|
44
|
+
[project.entry-points."kimi_agent.modules"]
|
|
45
|
+
my_module = "my_module_package:SPEC"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The [module guide](https://github.com/webhead2oo9/kimi-agent/blob/main/docs/modules.md)
|
|
49
|
+
documents installation, declarations, lifecycle, and every runtime port. The
|
|
50
|
+
[reference module](https://github.com/webhead2oo9/kimi-agent/tree/main/bot/modules/example)
|
|
51
|
+
is a complete, commented example that exercises every port; start there.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Kimi Agent Module API
|
|
2
|
+
|
|
3
|
+
The stable, host-independent contracts for building Kimi application modules:
|
|
4
|
+
separately installed packages that add commands, LLM tools, background jobs,
|
|
5
|
+
event handlers, per-guild settings, and durable data to a Kimi deployment.
|
|
6
|
+
|
|
7
|
+
This package contains no bot runtime, Discord client, database
|
|
8
|
+
implementation, or module loader. It exports:
|
|
9
|
+
|
|
10
|
+
- `ModuleSpec`, `ModuleLoadContext`, `ModuleRuntimeContext`: the declaration a
|
|
11
|
+
module publishes and the two contexts the host hands it.
|
|
12
|
+
- `kimi_agent_module_api.contracts`: every runtime port as a `typing.Protocol`
|
|
13
|
+
(storage, scheduler, events, Discord actions, interactions, HTTP, services,
|
|
14
|
+
trust, proposals, health) plus the validators the host runs at preflight.
|
|
15
|
+
- `kimi_agent_module_api.events`: the normalized `discord.*` event payloads.
|
|
16
|
+
- `kimi_agent_module_api.testing`: a fake for every port, `load_context()` for
|
|
17
|
+
exercising `create()`, and `MemoryStorage` (install the `testing` extra) so a
|
|
18
|
+
module can unit test itself with only this package installed.
|
|
19
|
+
|
|
20
|
+
A module exposes a `ModuleSpec` through the `kimi_agent.modules` entry-point
|
|
21
|
+
group:
|
|
22
|
+
|
|
23
|
+
```toml
|
|
24
|
+
[project]
|
|
25
|
+
dependencies = ["kimi-agent-module-api>=1,<2"]
|
|
26
|
+
|
|
27
|
+
[project.entry-points."kimi_agent.modules"]
|
|
28
|
+
my_module = "my_module_package:SPEC"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The [module guide](https://github.com/webhead2oo9/kimi-agent/blob/main/docs/modules.md)
|
|
32
|
+
documents installation, declarations, lifecycle, and every runtime port. The
|
|
33
|
+
[reference module](https://github.com/webhead2oo9/kimi-agent/tree/main/bot/modules/example)
|
|
34
|
+
is a complete, commented example that exercises every port; start there.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kimi-agent-module-api"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Stable contracts for community-built assistant modules"
|
|
5
|
+
requires-python = ">=3.14"
|
|
6
|
+
authors = [{ name = "Webhead" }]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
dependencies = ["pydantic-settings>=2.14.2"]
|
|
11
|
+
|
|
12
|
+
[project.urls]
|
|
13
|
+
Documentation = "https://github.com/webhead2oo9/kimi-agent/blob/main/docs/modules.md"
|
|
14
|
+
Issues = "https://github.com/webhead2oo9/kimi-agent/issues"
|
|
15
|
+
Repository = "https://github.com/webhead2oo9/kimi-agent"
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
# kimi_agent_module_api.testing.MemoryStorage runs real SQL in unit tests.
|
|
19
|
+
testing = ["aiosqlite"]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["setuptools>=84"]
|
|
23
|
+
build-backend = "setuptools.build_meta"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
kimi_agent_module_api = ["py.typed"]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Stable public contracts for trusted, installed assistant modules."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Protocol, TypeVar
|
|
9
|
+
|
|
10
|
+
from pydantic_settings import BaseSettings
|
|
11
|
+
|
|
12
|
+
from kimi_agent_module_api.contracts import (
|
|
13
|
+
ConfigSnapshot,
|
|
14
|
+
RoleSnapshot,
|
|
15
|
+
render_guild_settings,
|
|
16
|
+
DiscordActions,
|
|
17
|
+
EventBus,
|
|
18
|
+
GuildSettings,
|
|
19
|
+
GuildSettingsSchema,
|
|
20
|
+
HealthReporter,
|
|
21
|
+
InviteSnapshot,
|
|
22
|
+
InteractionRouter,
|
|
23
|
+
ModuleHttp,
|
|
24
|
+
ModulePermissions,
|
|
25
|
+
ModuleStorage,
|
|
26
|
+
ScopedModuleMigration,
|
|
27
|
+
ProposalActor,
|
|
28
|
+
ProposalError,
|
|
29
|
+
ProposalRef,
|
|
30
|
+
ProposalService,
|
|
31
|
+
ProposalState,
|
|
32
|
+
Scheduler,
|
|
33
|
+
ServiceDeclaration,
|
|
34
|
+
ServiceRegistry,
|
|
35
|
+
ServiceRequirement,
|
|
36
|
+
TrustLookup,
|
|
37
|
+
)
|
|
38
|
+
from kimi_agent_module_api.settings import ModuleSetting, ModuleSettingsDefinition
|
|
39
|
+
from kimi_agent_module_api.tools import (
|
|
40
|
+
ModuleToolContext,
|
|
41
|
+
ModuleToolHandler,
|
|
42
|
+
ModuleToolRegistry,
|
|
43
|
+
)
|
|
44
|
+
from kimi_agent_module_api.trust import TrustTier
|
|
45
|
+
|
|
46
|
+
MODULE_API_VERSION = 1
|
|
47
|
+
MODULE_ENTRYPOINT_GROUP = "kimi_agent.modules"
|
|
48
|
+
# Capabilities every compatible host advertises regardless of configuration.
|
|
49
|
+
BASELINE_CAPABILITIES: frozenset[str] = frozenset({"discord.history.v1", "proposals.v2"})
|
|
50
|
+
|
|
51
|
+
_SettingsT = TypeVar("_SettingsT", bound=BaseSettings)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class ModuleCapabilities:
|
|
56
|
+
available: frozenset[str]
|
|
57
|
+
members_intent: bool
|
|
58
|
+
message_content_intent: bool
|
|
59
|
+
|
|
60
|
+
def require(self, name: str) -> None:
|
|
61
|
+
if name not in self.available:
|
|
62
|
+
raise RuntimeError(f"the host does not provide required capability {name!r}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class AppModule(Protocol):
|
|
66
|
+
scoped_migrations: Sequence[ScopedModuleMigration]
|
|
67
|
+
|
|
68
|
+
async def start(self, ctx: ModuleRuntimeContext) -> None: ...
|
|
69
|
+
|
|
70
|
+
async def close(self) -> None: ...
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True)
|
|
74
|
+
class ModuleSpec:
|
|
75
|
+
name: str
|
|
76
|
+
version: str
|
|
77
|
+
create: Callable[[ModuleLoadContext], AppModule]
|
|
78
|
+
api_version: int = MODULE_API_VERSION
|
|
79
|
+
dependencies: tuple[str, ...] = ()
|
|
80
|
+
settings: ModuleSettingsDefinition | None = None
|
|
81
|
+
requires_capabilities: tuple[str, ...] = ()
|
|
82
|
+
activation_capabilities: tuple[str, ...] = ()
|
|
83
|
+
permissions: ModulePermissions = field(default_factory=ModulePermissions)
|
|
84
|
+
guild_settings: GuildSettingsSchema | None = None
|
|
85
|
+
provides: tuple[ServiceDeclaration, ...] = ()
|
|
86
|
+
consumes: tuple[ServiceRequirement, ...] = ()
|
|
87
|
+
table_aliases: Mapping[str, str] = field(default_factory=dict)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(frozen=True)
|
|
91
|
+
class ModuleLoadContext:
|
|
92
|
+
"""What ``ModuleSpec.create`` receives.
|
|
93
|
+
|
|
94
|
+
``create()`` is pure wiring: read prepared settings, register LLM tools,
|
|
95
|
+
construct the module object. No migration has run and no dependency has
|
|
96
|
+
started, so nothing here reaches storage, services, or Discord; that work
|
|
97
|
+
belongs in ``start()``. The tool registry is sealed once loading finishes,
|
|
98
|
+
so tools cannot be registered later from ``start()`` either.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
capabilities: ModuleCapabilities
|
|
102
|
+
registry: ModuleToolRegistry
|
|
103
|
+
module_settings: BaseSettings | None
|
|
104
|
+
# Host sinks behind the two convenience methods below. Tests build a
|
|
105
|
+
# context with ``kimi_agent_module_api.testing.load_context``.
|
|
106
|
+
label_sink: Callable[[Mapping[str, str]], None]
|
|
107
|
+
surface_sink: Callable[[str, Sequence[str]], None]
|
|
108
|
+
|
|
109
|
+
def settings_for(self, settings_type: type[_SettingsT]) -> _SettingsT:
|
|
110
|
+
if self.module_settings is None or not isinstance(self.module_settings, settings_type):
|
|
111
|
+
raise TypeError(f"prepared module settings are not {settings_type.__name__}")
|
|
112
|
+
return self.module_settings
|
|
113
|
+
|
|
114
|
+
def register_tool_labels(self, labels: Mapping[str, str]) -> None:
|
|
115
|
+
"""Gerund phrases shown while a tool runs, e.g. ``{"give_kudos": "Giving kudos"}``."""
|
|
116
|
+
self.label_sink(labels)
|
|
117
|
+
|
|
118
|
+
def declare_surface_tools(self, surface: str, names: Sequence[str]) -> None:
|
|
119
|
+
"""Declare which tools belong to a named evaluation surface."""
|
|
120
|
+
self.surface_sink(surface, names)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass(frozen=True)
|
|
124
|
+
class ModuleRuntimeContext:
|
|
125
|
+
"""Runtime ports supplied to one module after it has been loaded."""
|
|
126
|
+
|
|
127
|
+
module_name: str
|
|
128
|
+
is_guild_active: Callable[[int], bool]
|
|
129
|
+
current_config_dir: Callable[[], Path]
|
|
130
|
+
capabilities: ModuleCapabilities
|
|
131
|
+
events: EventBus
|
|
132
|
+
scheduler: Scheduler
|
|
133
|
+
storage: ModuleStorage
|
|
134
|
+
health: HealthReporter
|
|
135
|
+
discord: DiscordActions
|
|
136
|
+
interactions: InteractionRouter
|
|
137
|
+
http: ModuleHttp
|
|
138
|
+
services: ServiceRegistry
|
|
139
|
+
trust: TrustLookup
|
|
140
|
+
guild_settings: GuildSettings | None = None
|
|
141
|
+
proposals: ProposalService | None = None
|
|
142
|
+
raw_bot: Any = None
|
|
143
|
+
raw_storage: Any = None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
__all__ = [
|
|
147
|
+
"BASELINE_CAPABILITIES",
|
|
148
|
+
"MODULE_API_VERSION",
|
|
149
|
+
"MODULE_ENTRYPOINT_GROUP",
|
|
150
|
+
"AppModule",
|
|
151
|
+
"ConfigSnapshot",
|
|
152
|
+
"GuildSettingsSchema",
|
|
153
|
+
"InviteSnapshot",
|
|
154
|
+
"ModuleCapabilities",
|
|
155
|
+
"ModuleLoadContext",
|
|
156
|
+
"ModulePermissions",
|
|
157
|
+
"ModuleRuntimeContext",
|
|
158
|
+
"ModuleSetting",
|
|
159
|
+
"ModuleSettingsDefinition",
|
|
160
|
+
"ModuleSpec",
|
|
161
|
+
"ModuleToolContext",
|
|
162
|
+
"ModuleToolHandler",
|
|
163
|
+
"ModuleToolRegistry",
|
|
164
|
+
"ProposalActor",
|
|
165
|
+
"ProposalError",
|
|
166
|
+
"ProposalRef",
|
|
167
|
+
"ProposalService",
|
|
168
|
+
"ProposalState",
|
|
169
|
+
"RoleSnapshot",
|
|
170
|
+
"ScopedModuleMigration",
|
|
171
|
+
"ServiceDeclaration",
|
|
172
|
+
"ServiceRequirement",
|
|
173
|
+
"TrustTier",
|
|
174
|
+
"render_guild_settings",
|
|
175
|
+
]
|