appkit-assistant 0.16.2__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 (36) hide show
  1. appkit_assistant-0.16.2/.gitignore +114 -0
  2. appkit_assistant-0.16.2/PKG-INFO +362 -0
  3. appkit_assistant-0.16.2/README.md +337 -0
  4. appkit_assistant-0.16.2/docs/assistant.png +0 -0
  5. appkit_assistant-0.16.2/pyproject.toml +49 -0
  6. appkit_assistant-0.16.2/src/appkit_assistant/backend/mcp_auth_service.py +796 -0
  7. appkit_assistant-0.16.2/src/appkit_assistant/backend/model_manager.py +135 -0
  8. appkit_assistant-0.16.2/src/appkit_assistant/backend/models.py +261 -0
  9. appkit_assistant-0.16.2/src/appkit_assistant/backend/processor.py +65 -0
  10. appkit_assistant-0.16.2/src/appkit_assistant/backend/processors/lorem_ipsum_processor.py +123 -0
  11. appkit_assistant-0.16.2/src/appkit_assistant/backend/processors/openai_base.py +189 -0
  12. appkit_assistant-0.16.2/src/appkit_assistant/backend/processors/openai_chat_completion_processor.py +117 -0
  13. appkit_assistant-0.16.2/src/appkit_assistant/backend/processors/openai_responses_processor.py +760 -0
  14. appkit_assistant-0.16.2/src/appkit_assistant/backend/processors/perplexity_processor.py +121 -0
  15. appkit_assistant-0.16.2/src/appkit_assistant/backend/repositories.py +162 -0
  16. appkit_assistant-0.16.2/src/appkit_assistant/backend/services/thread_service.py +134 -0
  17. appkit_assistant-0.16.2/src/appkit_assistant/backend/system_prompt_cache.py +171 -0
  18. appkit_assistant-0.16.2/src/appkit_assistant/components/__init__.py +36 -0
  19. appkit_assistant-0.16.2/src/appkit_assistant/components/composer.py +154 -0
  20. appkit_assistant-0.16.2/src/appkit_assistant/components/composer_key_handler.py +38 -0
  21. appkit_assistant-0.16.2/src/appkit_assistant/components/mcp_oauth.py +46 -0
  22. appkit_assistant-0.16.2/src/appkit_assistant/components/mcp_server_dialogs.py +652 -0
  23. appkit_assistant-0.16.2/src/appkit_assistant/components/mcp_server_table.py +76 -0
  24. appkit_assistant-0.16.2/src/appkit_assistant/components/message.py +417 -0
  25. appkit_assistant-0.16.2/src/appkit_assistant/components/system_prompt_editor.py +78 -0
  26. appkit_assistant-0.16.2/src/appkit_assistant/components/thread.py +256 -0
  27. appkit_assistant-0.16.2/src/appkit_assistant/components/threadlist.py +147 -0
  28. appkit_assistant-0.16.2/src/appkit_assistant/components/tools_modal.py +97 -0
  29. appkit_assistant-0.16.2/src/appkit_assistant/configuration.py +11 -0
  30. appkit_assistant-0.16.2/src/appkit_assistant/logic/response_accumulator.py +228 -0
  31. appkit_assistant-0.16.2/src/appkit_assistant/pages.py +17 -0
  32. appkit_assistant-0.16.2/src/appkit_assistant/state/mcp_oauth_state.py +222 -0
  33. appkit_assistant-0.16.2/src/appkit_assistant/state/mcp_server_state.py +290 -0
  34. appkit_assistant-0.16.2/src/appkit_assistant/state/system_prompt_state.py +203 -0
  35. appkit_assistant-0.16.2/src/appkit_assistant/state/thread_list_state.py +292 -0
  36. appkit_assistant-0.16.2/src/appkit_assistant/state/thread_state.py +811 -0
@@ -0,0 +1,114 @@
1
+ __pycache__/
2
+ __pypackages__/
3
+ .cache
4
+ .coverage
5
+ .coverage.*
6
+ .dmypy.json
7
+ .DS_Store
8
+ .eggs/
9
+ .env
10
+ .env.backup
11
+ .env.docker
12
+ .hypothesis/
13
+ .idea/
14
+ .installed.cfg
15
+ .ipynb_checkpoints
16
+ .mypy_cache/
17
+ .nox/
18
+ .pdm.toml
19
+ .pybuilder/
20
+ .pyre/
21
+ .pytest_cache/
22
+ .Python
23
+ .python_packages
24
+ .pytype/
25
+ .ropeproject
26
+ .scrapy
27
+ .spyderproject
28
+ .spyproject
29
+ .states
30
+ .tox/
31
+ .venv
32
+ .venv.mac
33
+ .web
34
+ .webassets-cache
35
+ *.bak
36
+ *.cover
37
+ *.db
38
+ *.egg
39
+ *.egg-info/
40
+ *.kv-env.*
41
+ *.log
42
+ *.manifest
43
+ *.mo
44
+ *.pot
45
+ *.py,cover
46
+ *.py[cod]
47
+ *.sage.py
48
+ *.so
49
+ *.spec
50
+ *.terraform.lock.hcl
51
+ *.tfplan
52
+ *.tfstate
53
+ *.tfstate.*.backup
54
+ *.tfstate.backup
55
+ *.tfvars
56
+ **/.terraform/*
57
+ *$py.class
58
+ /site
59
+ /vectorstore/
60
+ aila-storage/
61
+ assets/external/
62
+ build/
63
+ celerybeat-schedule
64
+ celerybeat.pid
65
+ configuration/config.abaz009.yaml
66
+ configuration/config.bubb001.yaml
67
+ configuration/config.stie104.yaml
68
+ configuration/config.voro047.yaml
69
+ connector examples/sharepoint.json
70
+ cover/
71
+ coverage.xml
72
+ cython_debug/
73
+ db.sqlite3
74
+ db.sqlite3-journal
75
+ develop-eggs/
76
+ dist/
77
+ dmypy.json
78
+ docs/_build/
79
+ Documents/
80
+ downloads/
81
+ eggs/
82
+ env.bak/
83
+ env/
84
+ ENV/
85
+ htmlcov/
86
+ instance/
87
+ ipython_config.py
88
+ knowledge/migrate.py
89
+ lib/
90
+ lib64/
91
+ local_settings.py
92
+ local.settings.json
93
+ MANIFEST
94
+ nosetests.xml
95
+ out
96
+ parts/
97
+ pip-delete-this-directory.txt
98
+ pip-log.txt
99
+ Pipfile
100
+ profile_default/
101
+ sdist/
102
+ share/python-wheels/
103
+ sketchpad/
104
+ sketchpad/
105
+ stores/
106
+ target/
107
+ tests/mcp_test.py
108
+ tmp.txt
109
+ uploaded_files/
110
+ uploads/
111
+ var/
112
+ venv.bak/
113
+ venv/
114
+ wheels/
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.4
2
+ Name: appkit-assistant
3
+ Version: 0.16.2
4
+ Summary: Add your description here
5
+ Project-URL: Homepage, https://github.com/jenreh/appkit
6
+ Project-URL: Documentation, https://github.com/jenreh/appkit/tree/main/docs
7
+ Project-URL: Repository, https://github.com/jenreh/appkit
8
+ Project-URL: Issues, https://github.com/jenreh/appkit/issues
9
+ Author: Jens Rehpöhler
10
+ License: MIT
11
+ Keywords: components,mantine,reflex,ui,web
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Software Development :: User Interfaces
18
+ Requires-Python: >=3.13
19
+ Requires-Dist: appkit-commons
20
+ Requires-Dist: appkit-mantine
21
+ Requires-Dist: appkit-ui
22
+ Requires-Dist: openai>=2.3.0
23
+ Requires-Dist: reflex>=0.8.22
24
+ Description-Content-Type: text/markdown
25
+
26
+ # appkit-assistant
27
+
28
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ **AI assistant component for Reflex applications with MCP server integration.**
32
+
33
+ appkit-assistant provides a complete conversational AI interface built on Reflex, featuring OpenAI and Perplexity integrations, Model Context Protocol (MCP) server management, and secure credential handling. It includes both backend processing services and ready-to-use UI components for building AI-powered applications.
34
+
35
+ ![Assistant](https://raw.githubusercontent.com/jenreh/appkit/refs/heads/main/components/appkit-assistant/docs/assistant.png)
36
+
37
+ ---
38
+
39
+ ## ✨ Features
40
+
41
+ - **Multi-Model Support** - OpenAI Chat Completions, OpenAI Responses API, Perplexity, and fallback Lorem Ipsum processor
42
+ - **MCP Server Integration** - Manage and connect to Model Context Protocol servers as tools
43
+ - **System Prompt Management** - Versioned system prompts with admin editor interface
44
+ - **Secure Credential Management** - Encrypted storage and handling of API keys and server credentials
45
+ - **Reflex UI Components** - Pre-built assistant interface with composer, thread management, and message display
46
+ - **Streaming Responses** - Real-time streaming of AI responses with chunked content
47
+ - **Thread Management** - Persistent conversation threads with state management
48
+
49
+ ---
50
+
51
+ ## 🚀 Installation
52
+
53
+ ### As Part of AppKit Workspace
54
+
55
+ If you're using the full AppKit workspace:
56
+
57
+ ```bash
58
+ git clone https://github.com/jenreh/appkit.git
59
+ cd appkit
60
+ uv sync
61
+ ```
62
+
63
+ ### Standalone Installation
64
+
65
+ Install from PyPI:
66
+
67
+ ```bash
68
+ pip install appkit-assistant
69
+ ```
70
+
71
+ Or with uv:
72
+
73
+ ```bash
74
+ uv add appkit-assistant
75
+ ```
76
+
77
+ ### Dependencies
78
+
79
+ - `appkit-commons` (shared utilities)
80
+ - `openai>=2.3.0` (OpenAI API client)
81
+
82
+ ---
83
+
84
+ ## 🏁 Quick Start
85
+
86
+ ### Basic Setup
87
+
88
+ 1. Configure your API keys in your application's configuration:
89
+
90
+ ```python
91
+ from appkit_assistant.configuration import AssistantConfig
92
+
93
+ # In your app configuration
94
+ assistant_config = AssistantConfig(
95
+ openai_api_key="your-openai-key",
96
+ perplexity_api_key="your-perplexity-key",
97
+ # Optional: custom OpenAI base URL
98
+ openai_base_url="https://api.openai.com/v1"
99
+ )
100
+ ```
101
+
102
+ 2. Register processors with the ModelManager:
103
+
104
+ ```python
105
+ from appkit_assistant.backend.model_manager import ModelManager
106
+ from appkit_assistant.backend.processors.openai_chat_completion_processor import OpenAIChatCompletionProcessor
107
+ from appkit_assistant.backend.processors.perplexity_processor import PerplexityProcessor
108
+
109
+ manager = ModelManager()
110
+ manager.register_processor("openai", OpenAIChatCompletionProcessor(assistant_config))
111
+ manager.register_processor("perplexity", PerplexityProcessor(assistant_config))
112
+ ```
113
+
114
+ 3. Use the assistant component in your Reflex app:
115
+
116
+ ```python
117
+ import reflex as rx
118
+ from appkit_assistant.components import Assistant
119
+
120
+ def assistant_page():
121
+ return rx.container(
122
+ Assistant(),
123
+ height="100vh"
124
+ )
125
+ ```
126
+
127
+ ---
128
+
129
+ ## 📖 Usage
130
+
131
+ ### Model Management
132
+
133
+ The `ModelManager` singleton handles all AI processors and models:
134
+
135
+ ```python
136
+ from appkit_assistant.backend.model_manager import ModelManager
137
+
138
+ manager = ModelManager()
139
+
140
+ # Get all available models
141
+ models = manager.get_all_models()
142
+
143
+ # Get a specific model
144
+ model = manager.get_model("gpt-4")
145
+
146
+ # Set default model
147
+ manager.set_default_model("gpt-4")
148
+ ```
149
+
150
+ ### Processing Messages
151
+
152
+ Process conversations using the registered processors:
153
+
154
+ ```python
155
+ from appkit_assistant.backend.models import Message, MessageType
156
+
157
+ messages = [
158
+ Message(role="user", content="Hello, how are you?", type=MessageType.TEXT)
159
+ ]
160
+
161
+ async for chunk in manager.get_processor_for_model("gpt-4").process(messages, "gpt-4"):
162
+ print(f"Received: {chunk.content}")
163
+ ```
164
+
165
+ ### MCP Server Management
166
+
167
+ Manage MCP servers for tool integration:
168
+
169
+ ```python
170
+ from appkit_assistant.backend.models import MCPServer
171
+
172
+ mcp_server = MCPServer(
173
+ name="my-server",
174
+ command="python",
175
+ args=["-m", "my_mcp_server"],
176
+ headers={"Authorization": "Bearer token"}
177
+ )
178
+
179
+ # Use in processing
180
+ async for chunk in processor.process(messages, "gpt-4", mcp_servers=[mcp_server]):
181
+ # Handle response with MCP tools
182
+ pass
183
+ ```
184
+
185
+ ### UI Components
186
+
187
+ #### Assistant Interface
188
+
189
+ The main `Assistant` component provides a complete chat interface:
190
+
191
+ ```python
192
+ from appkit_assistant.components import Assistant
193
+
194
+ def chat_page():
195
+ return Assistant()
196
+ ```
197
+
198
+ #### Individual Components
199
+
200
+ Use individual components for custom layouts:
201
+
202
+ ```python
203
+ import reflex as rx
204
+ from appkit_assistant.components import ThreadList, composer
205
+
206
+ def custom_assistant():
207
+ return rx.vstack(
208
+ ThreadList(),
209
+ composer(),
210
+ spacing="4"
211
+ )
212
+ ```
213
+
214
+ #### MCP Server Management UI
215
+
216
+ Display and manage MCP servers:
217
+
218
+ ```python
219
+ from appkit_assistant.components import mcp_servers_table
220
+
221
+ def servers_page():
222
+ return mcp_servers_table()
223
+ ```
224
+
225
+ #### System Prompt Editor
226
+
227
+ Admin interface for managing versioned system prompts:
228
+
229
+ ```python
230
+ from appkit_assistant.components.system_prompt_editor import system_prompt_editor
231
+
232
+ def prompt_editor_page():
233
+ return system_prompt_editor()
234
+ ```
235
+
236
+ ---
237
+
238
+ ## 🔧 Configuration
239
+
240
+ ### AssistantConfig
241
+
242
+ Configure API keys and settings:
243
+
244
+ ```python
245
+ from appkit_assistant.configuration import AssistantConfig
246
+
247
+ config = AssistantConfig(
248
+ openai_api_key="sk-...",
249
+ openai_base_url="https://custom.openai.endpoint/v1",
250
+ perplexity_api_key="pplx-...",
251
+ google_api_key="AIza..." # For future Google integrations
252
+ )
253
+ ```
254
+
255
+ ### Processor Registration
256
+
257
+ Register processors based on available credentials:
258
+
259
+ ```python
260
+ from appkit_assistant.backend.processors import (
261
+ OpenAIChatCompletionProcessor,
262
+ PerplexityProcessor,
263
+ LoremIpsumProcessor
264
+ )
265
+
266
+ manager = ModelManager()
267
+
268
+ if config.openai_api_key:
269
+ manager.register_processor("openai", OpenAIChatCompletionProcessor(config))
270
+
271
+ if config.perplexity_api_key:
272
+ manager.register_processor("perplexity", PerplexityProcessor(config))
273
+
274
+ # Always available fallback
275
+ manager.register_processor("lorem", LoremIpsumProcessor())
276
+ ```
277
+
278
+ ---
279
+
280
+ ## 📋 API Reference
281
+
282
+ ### Core Classes
283
+
284
+ - `ModelManager` - Singleton model and processor registry
285
+ - `Processor` - Abstract base for AI processors
286
+ - `AIModel` - Model metadata and configuration
287
+ - `Message` - Conversation message structure
288
+ - `MCPServer` - MCP server configuration
289
+
290
+ ### Component API
291
+
292
+ - `Assistant` - Complete assistant interface
293
+ - `composer` - Message input component
294
+ - `ThreadList` - Conversation thread list
295
+ - `MessageComponent` - Individual message display
296
+ - `mcp_servers_table` - MCP server management table
297
+ - `system_prompt_editor` - Admin interface for system prompts
298
+
299
+
300
+ ### State Management
301
+
302
+ - `ThreadState` - Individual thread state
303
+ - `ThreadListState` - Thread list management
304
+
305
+ ---
306
+
307
+ ## 🔒 Security
308
+
309
+ > [!IMPORTANT]
310
+ > API keys and MCP server credentials are handled securely using the appkit-commons configuration system. Never hardcode secrets in your code.
311
+
312
+ - Use `SecretStr` for sensitive configuration values
313
+ - Credentials are encrypted at rest when stored in the database
314
+ - MCP server headers support encrypted storage
315
+
316
+ ---
317
+
318
+ ## 🤝 Integration Examples
319
+
320
+ ### With AppKit User Management
321
+
322
+ Combine with appkit-user for authenticated assistants:
323
+
324
+ ```python
325
+ from appkit_user import authenticated, requires_role
326
+
327
+ @authenticated()
328
+ @requires_role("assistant_user")
329
+ def protected_assistant_page():
330
+ return assistant.Assistant()
331
+ ```
332
+
333
+ ### Custom Processor Implementation
334
+
335
+ Implement your own AI processor:
336
+
337
+ ```python
338
+ from appkit_assistant.backend.processor import Processor
339
+ from appkit_assistant.backend.models import AIModel, Chunk, Message
340
+
341
+ class CustomProcessor(Processor):
342
+ def get_supported_models(self):
343
+ return {
344
+ "custom-model": AIModel(
345
+ id="custom-model",
346
+ text="Custom AI Model",
347
+ icon="🤖"
348
+ )
349
+ }
350
+
351
+ async def process(self, messages, model_id, files=None, mcp_servers=None):
352
+ # Your AI processing logic here
353
+ yield Chunk(content="Response from custom model", type="text")
354
+ ```
355
+
356
+ ---
357
+
358
+ ## 📚 Related Components
359
+
360
+ - **[appkit-mantine](./../appkit-mantine)** - UI components used in the assistant interface
361
+ - **[appkit-user](./../appkit-user)** - User authentication and authorization
362
+ - **[appkit-commons](./../appkit-commons)** - Shared utilities and configuration