zettcode-plugin-api 0.4.0__py3-none-any.whl

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.
@@ -0,0 +1,330 @@
1
+ """What a plugin imports: the contract, and the one dependency it needs.
2
+
3
+ A ZettCode plugin is a class published under the ``zettcode.plugins`` entry point, and everything it may touch is
4
+ re-exported here: the base classes and hooks of the agent side and of the terminal's rows, the command a handler returns,
5
+ the row model and the presenter it implements, the pet format, the link to the shell, and the few widgets a panel is
6
+ drawn with.
7
+
8
+ This package is the bottom of the graph a plugin lives in. The engine, the widget framework and the SDK are what it
9
+ needs; it imports neither the terminal application nor any implementation of the contracts it defines. The built-in rows
10
+ (`zettcode-presenters`), the shell and the loader that builds ``ctx.tui`` (`zettcode-app`) are written *against* it, which
11
+ is what lets a plugin and the program replace each other's parts without either importing the other.
12
+
13
+ The names are resolved on first use, like the program's other facades: importing one row constant must not pull the
14
+ settings, the runtime and a provider SDK in with it, because the boot frame is drawn before any of them exist.
15
+
16
+ The names are the ones the guide shows in `docs/guide/plugins.md`. They are re-exports, not a second definition, so a
17
+ plugin and the program cannot disagree about a signature.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import importlib
23
+ from typing import TYPE_CHECKING, Any
24
+
25
+ #: Where each public name lives; read by :func:`__getattr__` on first use.
26
+ _EXPORTS = {
27
+ "Activity": ".state",
28
+ "ActivityState": ".state",
29
+ "AgentBuild": "zettcode.engine.plugins",
30
+ "BusyPolicy": ".commands",
31
+ "CONTENT_INDENT": ".presenters",
32
+ "Canvas": "zettcode.tui",
33
+ "ChangesEntry": ".entries",
34
+ "Command": ".commands",
35
+ "CommandAgent": ".commands",
36
+ "CommandContext": ".commands",
37
+ "CommandHandler": ".commands",
38
+ "CommandHost": ".commands",
39
+ "CommandList": ".commands",
40
+ "CommandProvider": ".commands",
41
+ "CommandResult": ".commands",
42
+ "CommandTranscript": ".commands",
43
+ "CommandUi": ".commands",
44
+ "Contribution": "zettcode.engine.plugins",
45
+ "DeleteEntry": ".entries",
46
+ "DisplayState": ".state",
47
+ "EditEntry": ".entries",
48
+ "Entry": ".entries",
49
+ "EntryKind": ".entries",
50
+ "EntryStatus": ".entries",
51
+ "ExtensionFactory": "zettcode.engine.plugins",
52
+ "FileChangeEntry": ".entries",
53
+ "FileSummary": ".entries",
54
+ "HOST_LINK": ".host",
55
+ "Host": "zettcode.tui",
56
+ "HostLink": ".host",
57
+ "MarkdownEntry": ".entries",
58
+ "Mention": "zettcode.mention",
59
+ "MentionProvider": "zettcode.mention",
60
+ "MessageEntry": ".entries",
61
+ "ModelConfig": "zettcode.config",
62
+ "ModelState": ".state",
63
+ "MouseAction": "zettcode.tui",
64
+ "MouseEvent": "zettcode.tui",
65
+ "NoticeLevel": ".entries",
66
+ "Pet": ".pets",
67
+ "PetSource": ".pets",
68
+ "PlainCommandContext": "zettcode.engine.plugins.commands",
69
+ "Plugin": "zettcode.engine.plugins",
70
+ "PluginAgentMixin": "zettcode.engine.plugins",
71
+ "PluginContext": "zettcode.engine.plugins",
72
+ "PluginEventMixin": "zettcode.engine.plugins",
73
+ "PluginExtension": "zettcode.engine.plugins",
74
+ "PluginMaintenanceMixin": "zettcode.engine.plugins",
75
+ "PluginMiddlewareMixin": "zettcode.engine.plugins",
76
+ "PluginModelMixin": "zettcode.engine.plugins",
77
+ "PluginRunMixin": "zettcode.engine.plugins",
78
+ "PluginSetting": "zettcode.engine.plugins",
79
+ "PluginSetupMixin": "zettcode.engine.plugins",
80
+ "PluginToolMixin": "zettcode.engine.plugins",
81
+ "PluginTurnMixin": "zettcode.engine.plugins",
82
+ "PluginUiMixin": ".mixins",
83
+ "Plugins": "zettcode.engine.plugins",
84
+ "Presenter": ".presenters",
85
+ "Presenters": ".presenters",
86
+ "Provider": "zettcode.providers",
87
+ "Rail": ".switch",
88
+ "ReadEntry": ".entries",
89
+ "Registry": "zettcode.registry",
90
+ "RelayEntry": ".entries",
91
+ "Row": ".rows",
92
+ "SWITCH_WIDTH": ".switch",
93
+ "SessionState": ".state",
94
+ "ShellContext": ".state",
95
+ "Span": "zettcode.tui",
96
+ "Style": "zettcode.tui",
97
+ "Subcommand": ".commands",
98
+ "TextCommandResult": "zettcode.engine.plugins.commands",
99
+ "TextEntry": ".entries",
100
+ "TextLine": "zettcode.tui",
101
+ "ThinkingEntry": ".entries",
102
+ "ToolEntry": ".entries",
103
+ "TuiGroup": "zettcode.plugin_tui",
104
+ "TuiPlugin": ".plugin",
105
+ "TuiPlugins": ".plugin",
106
+ "TurnCommandResult": "zettcode.engine.plugins.commands",
107
+ "TurnSegment": ".state",
108
+ "UiBuilder": ".state",
109
+ "UiRegion": ".state",
110
+ "UiRow": ".state",
111
+ "UiSegment": ".state",
112
+ "UiSide": ".state",
113
+ "WaitEntry": ".entries",
114
+ "Widget": "zettcode.tui",
115
+ "WriteEntry": ".entries",
116
+ "ZettCodeConfig": "zettcode.config",
117
+ "blend": "zettcode.tui.render",
118
+ "bottom_panel": ".panels",
119
+ "display_width": "zettcode.tui.render",
120
+ "draw_switch": ".switch",
121
+ "pressed": ".panels",
122
+ "truncate": "zettcode.tui.render",
123
+ }
124
+
125
+
126
+ if TYPE_CHECKING: # pragma: no cover - for type checkers, not the runtime
127
+ from zettcode.config import ModelConfig, ZettCodeConfig
128
+ from zettcode.engine.plugins import (
129
+ AgentBuild,
130
+ Contribution,
131
+ ExtensionFactory,
132
+ Plugin,
133
+ PluginAgentMixin,
134
+ PluginContext,
135
+ PluginEventMixin,
136
+ PluginExtension,
137
+ PluginMaintenanceMixin,
138
+ PluginMiddlewareMixin,
139
+ PluginModelMixin,
140
+ PluginRunMixin,
141
+ Plugins,
142
+ PluginSetting,
143
+ PluginSetupMixin,
144
+ PluginToolMixin,
145
+ PluginTurnMixin,
146
+ )
147
+ from zettcode.engine.plugins.commands import PlainCommandContext, TextCommandResult, TurnCommandResult
148
+ from zettcode.mention import Mention, MentionProvider
149
+ from zettcode.plugin_tui import TuiGroup
150
+ from zettcode.providers import Provider
151
+ from zettcode.registry import Registry
152
+ from zettcode.tui import Canvas, Host, MouseAction, MouseEvent, Span, Style, TextLine, Widget
153
+ from zettcode.tui.render import blend, display_width, truncate
154
+
155
+ from .commands import (
156
+ BusyPolicy,
157
+ Command,
158
+ CommandAgent,
159
+ CommandContext,
160
+ CommandHandler,
161
+ CommandHost,
162
+ CommandList,
163
+ CommandProvider,
164
+ CommandResult,
165
+ CommandTranscript,
166
+ CommandUi,
167
+ Subcommand,
168
+ )
169
+ from .entries import (
170
+ ChangesEntry,
171
+ DeleteEntry,
172
+ EditEntry,
173
+ Entry,
174
+ EntryKind,
175
+ EntryStatus,
176
+ FileChangeEntry,
177
+ FileSummary,
178
+ MarkdownEntry,
179
+ MessageEntry,
180
+ NoticeLevel,
181
+ ReadEntry,
182
+ RelayEntry,
183
+ TextEntry,
184
+ ThinkingEntry,
185
+ ToolEntry,
186
+ WaitEntry,
187
+ WriteEntry,
188
+ )
189
+ from .host import HOST_LINK, HostLink
190
+ from .mixins import PluginUiMixin
191
+ from .panels import bottom_panel, pressed
192
+ from .pets import Pet, PetSource
193
+ from .plugin import TuiPlugin, TuiPlugins
194
+ from .presenters import CONTENT_INDENT, Presenter, Presenters
195
+ from .rows import Row
196
+ from .state import (
197
+ Activity,
198
+ ActivityState,
199
+ DisplayState,
200
+ ModelState,
201
+ SessionState,
202
+ ShellContext,
203
+ TurnSegment,
204
+ UiBuilder,
205
+ UiRegion,
206
+ UiRow,
207
+ UiSegment,
208
+ UiSide,
209
+ )
210
+ from .switch import SWITCH_WIDTH, Rail, draw_switch
211
+
212
+
213
+ def __getattr__(name: str) -> Any:
214
+ """Import the module a public name lives in, the first time it is asked for.
215
+
216
+ Args:
217
+ name: The public name the plugin asked for.
218
+
219
+ Returns:
220
+ What that module defines under the name.
221
+
222
+ Raises:
223
+ AttributeError: The package has no such name.
224
+ """
225
+ module = _EXPORTS.get(name)
226
+ if module is None:
227
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
228
+ value = getattr(importlib.import_module(module, __name__), name)
229
+ globals()[name] = value
230
+ return value
231
+
232
+
233
+ __all__ = [
234
+ "Activity",
235
+ "ActivityState",
236
+ "AgentBuild",
237
+ "BusyPolicy",
238
+ "CONTENT_INDENT",
239
+ "Canvas",
240
+ "ChangesEntry",
241
+ "Command",
242
+ "CommandAgent",
243
+ "CommandContext",
244
+ "CommandHandler",
245
+ "CommandHost",
246
+ "CommandList",
247
+ "CommandProvider",
248
+ "CommandResult",
249
+ "CommandTranscript",
250
+ "CommandUi",
251
+ "Contribution",
252
+ "DeleteEntry",
253
+ "DisplayState",
254
+ "EditEntry",
255
+ "Entry",
256
+ "EntryKind",
257
+ "EntryStatus",
258
+ "ExtensionFactory",
259
+ "FileChangeEntry",
260
+ "FileSummary",
261
+ "HOST_LINK",
262
+ "Host",
263
+ "HostLink",
264
+ "MarkdownEntry",
265
+ "Mention",
266
+ "MentionProvider",
267
+ "MessageEntry",
268
+ "ModelConfig",
269
+ "ModelState",
270
+ "MouseAction",
271
+ "MouseEvent",
272
+ "NoticeLevel",
273
+ "Pet",
274
+ "PetSource",
275
+ "PlainCommandContext",
276
+ "Plugin",
277
+ "PluginAgentMixin",
278
+ "PluginContext",
279
+ "PluginEventMixin",
280
+ "PluginExtension",
281
+ "PluginMaintenanceMixin",
282
+ "PluginMiddlewareMixin",
283
+ "PluginModelMixin",
284
+ "PluginRunMixin",
285
+ "PluginSetting",
286
+ "PluginSetupMixin",
287
+ "PluginToolMixin",
288
+ "PluginTurnMixin",
289
+ "PluginUiMixin",
290
+ "Plugins",
291
+ "Presenter",
292
+ "Presenters",
293
+ "Provider",
294
+ "Rail",
295
+ "ReadEntry",
296
+ "Registry",
297
+ "RelayEntry",
298
+ "Row",
299
+ "SWITCH_WIDTH",
300
+ "SessionState",
301
+ "ShellContext",
302
+ "Span",
303
+ "Style",
304
+ "Subcommand",
305
+ "TextCommandResult",
306
+ "TextEntry",
307
+ "TextLine",
308
+ "ThinkingEntry",
309
+ "ToolEntry",
310
+ "TuiGroup",
311
+ "TuiPlugin",
312
+ "TuiPlugins",
313
+ "TurnCommandResult",
314
+ "TurnSegment",
315
+ "UiBuilder",
316
+ "UiRegion",
317
+ "UiRow",
318
+ "UiSegment",
319
+ "UiSide",
320
+ "WaitEntry",
321
+ "Widget",
322
+ "WriteEntry",
323
+ "ZettCodeConfig",
324
+ "blend",
325
+ "bottom_panel",
326
+ "display_width",
327
+ "draw_switch",
328
+ "pressed",
329
+ "truncate",
330
+ ]