griptape-nodes 0.41.0__py3-none-any.whl → 0.43.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.
Files changed (133) hide show
  1. griptape_nodes/__init__.py +0 -0
  2. griptape_nodes/app/.python-version +0 -0
  3. griptape_nodes/app/__init__.py +1 -10
  4. griptape_nodes/app/api.py +199 -0
  5. griptape_nodes/app/app.py +140 -222
  6. griptape_nodes/app/watch.py +4 -2
  7. griptape_nodes/bootstrap/__init__.py +0 -0
  8. griptape_nodes/bootstrap/bootstrap_script.py +0 -0
  9. griptape_nodes/bootstrap/register_libraries_script.py +0 -0
  10. griptape_nodes/bootstrap/structure_config.yaml +0 -0
  11. griptape_nodes/bootstrap/workflow_executors/__init__.py +0 -0
  12. griptape_nodes/bootstrap/workflow_executors/local_workflow_executor.py +0 -0
  13. griptape_nodes/bootstrap/workflow_executors/workflow_executor.py +0 -0
  14. griptape_nodes/bootstrap/workflow_runners/__init__.py +0 -0
  15. griptape_nodes/bootstrap/workflow_runners/bootstrap_workflow_runner.py +0 -0
  16. griptape_nodes/bootstrap/workflow_runners/local_workflow_runner.py +0 -0
  17. griptape_nodes/bootstrap/workflow_runners/subprocess_workflow_runner.py +6 -2
  18. griptape_nodes/bootstrap/workflow_runners/workflow_runner.py +0 -0
  19. griptape_nodes/drivers/__init__.py +0 -0
  20. griptape_nodes/drivers/storage/__init__.py +0 -0
  21. griptape_nodes/drivers/storage/base_storage_driver.py +0 -0
  22. griptape_nodes/drivers/storage/griptape_cloud_storage_driver.py +0 -0
  23. griptape_nodes/drivers/storage/local_storage_driver.py +5 -3
  24. griptape_nodes/drivers/storage/storage_backend.py +0 -0
  25. griptape_nodes/exe_types/__init__.py +0 -0
  26. griptape_nodes/exe_types/connections.py +0 -0
  27. griptape_nodes/exe_types/core_types.py +0 -0
  28. griptape_nodes/exe_types/flow.py +68 -368
  29. griptape_nodes/exe_types/node_types.py +17 -1
  30. griptape_nodes/exe_types/type_validator.py +0 -0
  31. griptape_nodes/machines/__init__.py +0 -0
  32. griptape_nodes/machines/control_flow.py +52 -20
  33. griptape_nodes/machines/fsm.py +16 -2
  34. griptape_nodes/machines/node_resolution.py +16 -14
  35. griptape_nodes/mcp_server/__init__.py +1 -0
  36. griptape_nodes/mcp_server/server.py +126 -0
  37. griptape_nodes/mcp_server/ws_request_manager.py +268 -0
  38. griptape_nodes/node_library/__init__.py +0 -0
  39. griptape_nodes/node_library/advanced_node_library.py +0 -0
  40. griptape_nodes/node_library/library_registry.py +0 -0
  41. griptape_nodes/node_library/workflow_registry.py +2 -2
  42. griptape_nodes/py.typed +0 -0
  43. griptape_nodes/retained_mode/__init__.py +0 -0
  44. griptape_nodes/retained_mode/events/__init__.py +0 -0
  45. griptape_nodes/retained_mode/events/agent_events.py +70 -8
  46. griptape_nodes/retained_mode/events/app_events.py +137 -12
  47. griptape_nodes/retained_mode/events/arbitrary_python_events.py +23 -0
  48. griptape_nodes/retained_mode/events/base_events.py +13 -31
  49. griptape_nodes/retained_mode/events/config_events.py +87 -11
  50. griptape_nodes/retained_mode/events/connection_events.py +56 -5
  51. griptape_nodes/retained_mode/events/context_events.py +27 -4
  52. griptape_nodes/retained_mode/events/execution_events.py +99 -14
  53. griptape_nodes/retained_mode/events/flow_events.py +165 -7
  54. griptape_nodes/retained_mode/events/generate_request_payload_schemas.py +0 -0
  55. griptape_nodes/retained_mode/events/library_events.py +195 -17
  56. griptape_nodes/retained_mode/events/logger_events.py +11 -0
  57. griptape_nodes/retained_mode/events/node_events.py +242 -22
  58. griptape_nodes/retained_mode/events/object_events.py +40 -4
  59. griptape_nodes/retained_mode/events/os_events.py +116 -3
  60. griptape_nodes/retained_mode/events/parameter_events.py +212 -8
  61. griptape_nodes/retained_mode/events/payload_registry.py +0 -0
  62. griptape_nodes/retained_mode/events/secrets_events.py +59 -7
  63. griptape_nodes/retained_mode/events/static_file_events.py +57 -4
  64. griptape_nodes/retained_mode/events/validation_events.py +39 -4
  65. griptape_nodes/retained_mode/events/workflow_events.py +188 -17
  66. griptape_nodes/retained_mode/griptape_nodes.py +89 -363
  67. griptape_nodes/retained_mode/managers/__init__.py +0 -0
  68. griptape_nodes/retained_mode/managers/agent_manager.py +49 -23
  69. griptape_nodes/retained_mode/managers/arbitrary_code_exec_manager.py +0 -0
  70. griptape_nodes/retained_mode/managers/config_manager.py +0 -0
  71. griptape_nodes/retained_mode/managers/context_manager.py +0 -0
  72. griptape_nodes/retained_mode/managers/engine_identity_manager.py +146 -0
  73. griptape_nodes/retained_mode/managers/event_manager.py +14 -2
  74. griptape_nodes/retained_mode/managers/flow_manager.py +751 -64
  75. griptape_nodes/retained_mode/managers/library_lifecycle/__init__.py +45 -0
  76. griptape_nodes/retained_mode/managers/library_lifecycle/data_models.py +191 -0
  77. griptape_nodes/retained_mode/managers/library_lifecycle/library_directory.py +346 -0
  78. griptape_nodes/retained_mode/managers/library_lifecycle/library_fsm.py +439 -0
  79. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/__init__.py +17 -0
  80. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/base.py +82 -0
  81. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/github.py +116 -0
  82. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/local_file.py +352 -0
  83. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/package.py +104 -0
  84. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance/sandbox.py +155 -0
  85. griptape_nodes/retained_mode/managers/library_lifecycle/library_provenance.py +18 -0
  86. griptape_nodes/retained_mode/managers/library_lifecycle/library_status.py +12 -0
  87. griptape_nodes/retained_mode/managers/library_manager.py +255 -40
  88. griptape_nodes/retained_mode/managers/node_manager.py +120 -103
  89. griptape_nodes/retained_mode/managers/object_manager.py +11 -3
  90. griptape_nodes/retained_mode/managers/operation_manager.py +0 -0
  91. griptape_nodes/retained_mode/managers/os_manager.py +582 -8
  92. griptape_nodes/retained_mode/managers/secrets_manager.py +4 -0
  93. griptape_nodes/retained_mode/managers/session_manager.py +328 -0
  94. griptape_nodes/retained_mode/managers/settings.py +7 -0
  95. griptape_nodes/retained_mode/managers/static_files_manager.py +0 -0
  96. griptape_nodes/retained_mode/managers/version_compatibility_manager.py +2 -2
  97. griptape_nodes/retained_mode/managers/workflow_manager.py +722 -456
  98. griptape_nodes/retained_mode/retained_mode.py +44 -0
  99. griptape_nodes/retained_mode/utils/__init__.py +0 -0
  100. griptape_nodes/retained_mode/utils/engine_identity.py +141 -27
  101. griptape_nodes/retained_mode/utils/name_generator.py +0 -0
  102. griptape_nodes/traits/__init__.py +0 -0
  103. griptape_nodes/traits/add_param_button.py +0 -0
  104. griptape_nodes/traits/button.py +0 -0
  105. griptape_nodes/traits/clamp.py +0 -0
  106. griptape_nodes/traits/compare.py +0 -0
  107. griptape_nodes/traits/compare_images.py +0 -0
  108. griptape_nodes/traits/file_system_picker.py +127 -0
  109. griptape_nodes/traits/minmax.py +0 -0
  110. griptape_nodes/traits/options.py +0 -0
  111. griptape_nodes/traits/slider.py +0 -0
  112. griptape_nodes/traits/trait_registry.py +0 -0
  113. griptape_nodes/traits/traits.json +0 -0
  114. griptape_nodes/updater/__init__.py +2 -2
  115. griptape_nodes/updater/__main__.py +0 -0
  116. griptape_nodes/utils/__init__.py +0 -0
  117. griptape_nodes/utils/dict_utils.py +0 -0
  118. griptape_nodes/utils/image_preview.py +128 -0
  119. griptape_nodes/utils/metaclasses.py +0 -0
  120. griptape_nodes/version_compatibility/__init__.py +0 -0
  121. griptape_nodes/version_compatibility/versions/__init__.py +0 -0
  122. griptape_nodes/version_compatibility/versions/v0_39_0/__init__.py +0 -0
  123. griptape_nodes/version_compatibility/versions/v0_39_0/modified_parameters_set_removal.py +5 -5
  124. griptape_nodes-0.43.0.dist-info/METADATA +90 -0
  125. griptape_nodes-0.43.0.dist-info/RECORD +129 -0
  126. griptape_nodes-0.43.0.dist-info/WHEEL +4 -0
  127. {griptape_nodes-0.41.0.dist-info → griptape_nodes-0.43.0.dist-info}/entry_points.txt +1 -0
  128. griptape_nodes/app/app_sessions.py +0 -458
  129. griptape_nodes/retained_mode/utils/session_persistence.py +0 -105
  130. griptape_nodes-0.41.0.dist-info/METADATA +0 -78
  131. griptape_nodes-0.41.0.dist-info/RECORD +0 -112
  132. griptape_nodes-0.41.0.dist-info/WHEEL +0 -4
  133. griptape_nodes-0.41.0.dist-info/licenses/LICENSE +0 -201
@@ -1,458 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import asyncio
4
- import binascii
5
- import json
6
- import logging
7
- import os
8
- import signal
9
- import sys
10
- import threading
11
- from pathlib import Path
12
- from queue import Queue
13
- from typing import Any, cast
14
- from urllib.parse import urljoin
15
-
16
- import uvicorn
17
- from fastapi import FastAPI, HTTPException, Request
18
- from fastapi.middleware.cors import CORSMiddleware
19
- from fastapi.staticfiles import StaticFiles
20
- from griptape.events import (
21
- EventBus,
22
- EventListener,
23
- )
24
- from rich.align import Align
25
- from rich.console import Console
26
- from rich.logging import RichHandler
27
- from rich.panel import Panel
28
- from websockets.asyncio.client import connect
29
- from websockets.exceptions import ConnectionClosed, WebSocketException
30
-
31
- # This import is necessary to register all events, even if not technically used
32
- from griptape_nodes.retained_mode.events import app_events, execution_events
33
- from griptape_nodes.retained_mode.events.base_events import (
34
- AppEvent,
35
- EventRequest,
36
- EventResultFailure,
37
- EventResultSuccess,
38
- ExecutionEvent,
39
- ExecutionGriptapeNodeEvent,
40
- GriptapeNodeEvent,
41
- ProgressEvent,
42
- deserialize_event,
43
- )
44
- from griptape_nodes.retained_mode.events.logger_events import LogHandlerEvent
45
- from griptape_nodes.retained_mode.griptape_nodes import GriptapeNodes
46
-
47
- # This is a global event queue that will be used to pass events between threads
48
- event_queue = Queue()
49
-
50
- # Global WebSocket connection for sending events
51
- ws_connection_for_sending = None
52
- event_loop = None
53
-
54
- # Whether to enable the static server
55
- STATIC_SERVER_ENABLED = os.getenv("STATIC_SERVER_ENABLED", "true").lower() == "true"
56
- # Host of the static server
57
- STATIC_SERVER_HOST = os.getenv("STATIC_SERVER_HOST", "localhost")
58
- # Port of the static server
59
- STATIC_SERVER_PORT = int(os.getenv("STATIC_SERVER_PORT", "8124"))
60
- # URL path for the static server
61
- STATIC_SERVER_URL = os.getenv("STATIC_SERVER_URL", "/static")
62
- # Log level for the static server
63
- STATIC_SERVER_LOG_LEVEL = os.getenv("STATIC_SERVER_LOG_LEVEL", "info").lower()
64
-
65
-
66
- class EventLogHandler(logging.Handler):
67
- """Custom logging handler that emits log messages as AppEvents.
68
-
69
- This is used to forward log messages to the event queue so they can be sent to the GUI.
70
- """
71
-
72
- def emit(self, record: logging.LogRecord) -> None:
73
- event_queue.put(
74
- AppEvent(
75
- payload=LogHandlerEvent(message=record.getMessage(), levelname=record.levelname, created=record.created)
76
- )
77
- )
78
-
79
-
80
- # Logger for this module. Important that this is not the same as the griptape_nodes logger or else we'll have infinite log events.
81
- logger = logging.getLogger("griptape_nodes_app")
82
- console = Console()
83
-
84
-
85
- def start_app() -> None:
86
- """Main entry point for the Griptape Nodes app.
87
-
88
- Starts the event loop and listens for events from the Nodes API.
89
- """
90
- _init_event_listeners()
91
-
92
- griptape_nodes_logger = logging.getLogger("griptape_nodes")
93
- # When running as an app, we want to forward all log messages to the event queue so they can be sent to the GUI
94
- griptape_nodes_logger.addHandler(EventLogHandler())
95
- griptape_nodes_logger.addHandler(RichHandler(show_time=True, show_path=False, markup=True, rich_tracebacks=True))
96
- griptape_nodes_logger.setLevel(logging.INFO)
97
-
98
- # Listen for any signals to exit the app
99
- for sig in (signal.SIGINT, signal.SIGTERM):
100
- signal.signal(sig, lambda *_: sys.exit(0))
101
-
102
- # SSE subscription pushes events into event_queue
103
- threading.Thread(target=_listen_for_api_events, daemon=True).start()
104
-
105
- if STATIC_SERVER_ENABLED:
106
- threading.Thread(target=_serve_static_server, daemon=True).start()
107
-
108
- _process_event_queue()
109
-
110
-
111
- def _serve_static_server() -> None:
112
- """Run FastAPI with Uvicorn in order to serve static files produced by nodes."""
113
- config_manager = GriptapeNodes.ConfigManager()
114
- app = FastAPI()
115
-
116
- static_dir = config_manager.workspace_path / config_manager.merged_config["static_files_directory"]
117
-
118
- if not static_dir.exists():
119
- static_dir.mkdir(parents=True, exist_ok=True)
120
-
121
- app.add_middleware(
122
- CORSMiddleware,
123
- allow_origins=[
124
- os.getenv("GRIPTAPE_NODES_UI_BASE_URL", "https://app.nodes.griptape.ai"),
125
- "https://app.nodes-staging.griptape.ai",
126
- "http://localhost:5173",
127
- ],
128
- allow_credentials=True,
129
- allow_methods=["OPTIONS", "GET", "POST", "PUT"],
130
- allow_headers=["*"],
131
- )
132
-
133
- app.mount(
134
- STATIC_SERVER_URL,
135
- StaticFiles(directory=static_dir),
136
- name="static",
137
- )
138
-
139
- @app.post("/static-upload-urls")
140
- async def create_static_file_upload_url(request: Request) -> dict:
141
- """Create a URL for uploading a static file.
142
-
143
- Similar to a presigned URL, but for uploading files to the static server.
144
- """
145
- base_url = request.base_url
146
- body = await request.json()
147
- file_name = body["file_name"]
148
- url = urljoin(str(base_url), f"/static-uploads/{file_name}")
149
-
150
- return {"url": url}
151
-
152
- @app.put("/static-uploads/{file_name:str}")
153
- async def create_static_file(request: Request, file_name: str) -> dict:
154
- """Upload a static file to the static server."""
155
- if not STATIC_SERVER_ENABLED:
156
- msg = "Static server is not enabled. Please set STATIC_SERVER_ENABLED to True."
157
- raise ValueError(msg)
158
-
159
- if not static_dir.exists():
160
- static_dir.mkdir(parents=True, exist_ok=True)
161
- data = await request.body()
162
- try:
163
- Path(static_dir / file_name).write_bytes(data)
164
- except binascii.Error as e:
165
- msg = f"Invalid base64 encoding for file {file_name}."
166
- logger.error(msg)
167
- raise HTTPException(status_code=400, detail=msg) from e
168
- except (OSError, PermissionError) as e:
169
- msg = f"Failed to write file {file_name} to {config_manager.workspace_path}: {e}"
170
- logger.error(msg)
171
- raise HTTPException(status_code=500, detail=msg) from e
172
-
173
- static_url = f"http://{STATIC_SERVER_HOST}:{STATIC_SERVER_PORT}{STATIC_SERVER_URL}/{file_name}"
174
- return {"url": static_url}
175
-
176
- @app.post("/engines/request")
177
- async def create_event(request: Request) -> None:
178
- body = await request.json()
179
- if "payload" in body:
180
- __process_api_event(body["payload"])
181
-
182
- logging.getLogger("uvicorn").addHandler(
183
- RichHandler(show_time=True, show_path=False, markup=True, rich_tracebacks=True)
184
- )
185
-
186
- uvicorn.run(
187
- app, host=STATIC_SERVER_HOST, port=STATIC_SERVER_PORT, log_level=STATIC_SERVER_LOG_LEVEL, log_config=None
188
- )
189
-
190
-
191
- def _init_event_listeners() -> None:
192
- """Set up the Griptape EventBus EventListeners."""
193
- EventBus.add_event_listener(
194
- event_listener=EventListener(on_event=__process_node_event, event_types=[GriptapeNodeEvent])
195
- )
196
-
197
- EventBus.add_event_listener(
198
- event_listener=EventListener(
199
- on_event=__process_execution_node_event,
200
- event_types=[ExecutionGriptapeNodeEvent],
201
- )
202
- )
203
-
204
- EventBus.add_event_listener(
205
- event_listener=EventListener(
206
- on_event=__process_progress_event,
207
- event_types=[ProgressEvent],
208
- )
209
- )
210
-
211
- EventBus.add_event_listener(
212
- event_listener=EventListener(
213
- on_event=__process_app_event, # pyright: ignore[reportArgumentType] TODO: https://github.com/griptape-ai/griptape-nodes/issues/868
214
- event_types=[AppEvent], # pyright: ignore[reportArgumentType] TODO: https://github.com/griptape-ai/griptape-nodes/issues/868
215
- )
216
- )
217
-
218
-
219
- async def _alisten_for_api_requests() -> None:
220
- """Listen for events from the Nodes API and process them asynchronously."""
221
- global ws_connection_for_sending, event_loop # noqa: PLW0603
222
- event_loop = asyncio.get_running_loop() # Store the event loop reference
223
- nodes_app_url = os.getenv("GRIPTAPE_NODES_UI_BASE_URL", "https://nodes.griptape.ai")
224
- logger.info("Listening for events from Nodes API via async WebSocket")
225
-
226
- # Auto reconnect https://websockets.readthedocs.io/en/stable/reference/asyncio/client.html#opening-a-connection
227
- connection_stream = __create_async_websocket_connection()
228
- initialized = False
229
- async for ws_connection in connection_stream:
230
- try:
231
- ws_connection_for_sending = ws_connection # Store for sending events
232
- if not initialized:
233
- __broadcast_app_initialization_complete(nodes_app_url)
234
- initialized = True
235
-
236
- async for message in ws_connection:
237
- try:
238
- data = json.loads(message)
239
-
240
- payload = data.get("payload", {})
241
- __process_api_event(payload)
242
- except Exception:
243
- logger.exception("Error processing event, skipping.")
244
- except ConnectionClosed:
245
- continue
246
- except Exception as e:
247
- logger.error("Error while listening for events. Retrying in 2 seconds... %s", e)
248
- await asyncio.sleep(2)
249
-
250
-
251
- def _listen_for_api_events() -> None:
252
- """Run the async WebSocket listener in an event loop."""
253
- asyncio.run(_alisten_for_api_requests())
254
-
255
-
256
- def __process_node_event(event: GriptapeNodeEvent) -> None:
257
- """Process GriptapeNodeEvents and send them to the API."""
258
- # Emit the result back to the GUI
259
- result_event = event.wrapped_event
260
- if isinstance(result_event, EventResultSuccess):
261
- dest_socket = "success_result"
262
- elif isinstance(result_event, EventResultFailure):
263
- dest_socket = "failure_result"
264
- else:
265
- msg = f"Unknown/unsupported result event type encountered: '{type(result_event)}'."
266
- raise TypeError(msg) from None
267
-
268
- # Don't send events over the wire that don't have a request_id set (e.g. engine-internal events)
269
- event_json = result_event.json()
270
- __schedule_async_task(__emit_message(dest_socket, event_json))
271
-
272
-
273
- def __process_execution_node_event(event: ExecutionGriptapeNodeEvent) -> None:
274
- """Process ExecutionGriptapeNodeEvents and send them to the API."""
275
- result_event = event.wrapped_event
276
- if type(result_event.payload).__name__ == "NodeStartProcessEvent":
277
- GriptapeNodes.EventManager().current_active_node = result_event.payload.node_name
278
- event_json = result_event.json()
279
-
280
- if type(result_event.payload).__name__ == "ResumeNodeProcessingEvent":
281
- node_name = result_event.payload.node_name
282
- logger.info("Resuming Node '%s'", node_name)
283
- flow_name = GriptapeNodes.NodeManager().get_node_parent_flow_by_name(node_name)
284
- request = EventRequest(request=execution_events.SingleExecutionStepRequest(flow_name=flow_name))
285
- event_queue.put(request)
286
-
287
- if type(result_event.payload).__name__ == "NodeFinishProcessEvent":
288
- if result_event.payload.node_name != GriptapeNodes.EventManager().current_active_node:
289
- msg = "Node start and finish do not match."
290
- raise KeyError(msg) from None
291
- GriptapeNodes.EventManager().current_active_node = None
292
- __schedule_async_task(__emit_message("execution_event", event_json))
293
-
294
-
295
- def __process_progress_event(gt_event: ProgressEvent) -> None:
296
- """Process Griptape framework events and send them to the API."""
297
- node_name = gt_event.node_name
298
- if node_name:
299
- value = gt_event.value
300
- payload = execution_events.GriptapeEvent(
301
- node_name=node_name, parameter_name=gt_event.parameter_name, type=type(gt_event).__name__, value=value
302
- )
303
- event_to_emit = ExecutionEvent(payload=payload)
304
- __schedule_async_task(__emit_message("execution_event", event_to_emit.json()))
305
-
306
-
307
- def __process_app_event(event: AppEvent) -> None:
308
- """Process AppEvents and send them to the API."""
309
- # Let Griptape Nodes broadcast it.
310
- GriptapeNodes.broadcast_app_event(event.payload)
311
-
312
- __schedule_async_task(__emit_message("app_event", event.json()))
313
-
314
-
315
- def _process_event_queue() -> None:
316
- """Listen for events in the event queue and process them.
317
-
318
- Event queue will be populated by background threads listening for events from the Nodes API.
319
- """
320
- while True:
321
- event = event_queue.get(block=True)
322
- if isinstance(event, EventRequest):
323
- request_payload = event.request
324
- GriptapeNodes.handle_request(request_payload)
325
- elif isinstance(event, AppEvent):
326
- __process_app_event(event)
327
- else:
328
- logger.warning("Unknown event type encountered: '%s'.", type(event))
329
-
330
- event_queue.task_done()
331
-
332
-
333
- def __create_async_websocket_connection() -> Any:
334
- """Create an async WebSocket connection to the Nodes API."""
335
- secrets_manager = GriptapeNodes.SecretsManager()
336
- api_key = secrets_manager.get_secret("GT_CLOUD_API_KEY")
337
- if api_key is None:
338
- message = Panel(
339
- Align.center(
340
- "[bold red]Nodes API key is not set, please run [code]gtn init[/code] with a valid key: [/bold red]"
341
- "[code]gtn init --api-key <your key>[/code]\n"
342
- "[bold red]You can generate a new key from [/bold red][bold blue][link=https://nodes.griptape.ai]https://nodes.griptape.ai[/link][/bold blue]",
343
- ),
344
- title="🔑 ❌ Missing Nodes API Key",
345
- border_style="red",
346
- padding=(1, 4),
347
- )
348
- console.print(message)
349
- sys.exit(1)
350
-
351
- endpoint = urljoin(
352
- os.getenv("GRIPTAPE_NODES_API_BASE_URL", "https://api.nodes.griptape.ai").replace("http", "ws"),
353
- "/ws/engines/events?publish_channel=responses&subscribe_channel=requests",
354
- )
355
-
356
- return connect(
357
- endpoint,
358
- additional_headers={"Authorization": f"Bearer {api_key}"},
359
- )
360
-
361
-
362
- async def __emit_message(event_type: str, payload: str) -> None:
363
- """Send a message via WebSocket asynchronously."""
364
- global ws_connection_for_sending # noqa: PLW0602
365
- if ws_connection_for_sending is None:
366
- logger.warning("WebSocket connection not available for sending message")
367
- return
368
-
369
- try:
370
- body = {"type": event_type, "payload": json.loads(payload) if payload else {}}
371
- await ws_connection_for_sending.send(json.dumps(body))
372
- except WebSocketException as e:
373
- logger.error("Error sending event to Nodes API: %s", e)
374
- except Exception as e:
375
- logger.error("Unexpected error while sending event to Nodes API: %s", e)
376
-
377
-
378
- def __schedule_async_task(coro: Any) -> None:
379
- """Schedule an async coroutine to run in the event loop from a sync context."""
380
- if event_loop and event_loop.is_running():
381
- asyncio.run_coroutine_threadsafe(coro, event_loop)
382
- else:
383
- logger.warning("Event loop not available for scheduling async task")
384
-
385
-
386
- def __broadcast_app_initialization_complete(nodes_app_url: str) -> None:
387
- """Broadcast the AppInitializationComplete event to all listeners.
388
-
389
- This is used to notify the GUI that the app is ready to receive events.
390
- """
391
- # Initialize engine ID and persistent data
392
- from griptape_nodes.retained_mode.events.base_events import BaseEvent
393
-
394
- BaseEvent.initialize_engine_id()
395
- BaseEvent.initialize_session_id()
396
-
397
- # Broadcast this to anybody who wants a callback on "hey, the app's ready to roll"
398
- payload = app_events.AppInitializationComplete()
399
- app_event = AppEvent(payload=payload)
400
- __process_app_event(app_event)
401
-
402
- engine_version_request = app_events.GetEngineVersionRequest()
403
- engine_version_result = GriptapeNodes.get_instance().handle_engine_version_request(engine_version_request)
404
- if isinstance(engine_version_result, app_events.GetEngineVersionResultSuccess):
405
- engine_version = f"v{engine_version_result.major}.{engine_version_result.minor}.{engine_version_result.patch}"
406
- else:
407
- engine_version = "<UNKNOWN ENGINE VERSION>"
408
-
409
- # Get current session ID
410
- session_id = GriptapeNodes.get_session_id()
411
- session_info = f" | Session: {session_id[:8]}..." if session_id else " | No Session"
412
-
413
- message = Panel(
414
- Align.center(
415
- f"[bold green]Engine is ready to receive events[/bold green]\n"
416
- f"[bold blue]Return to: [link={nodes_app_url}]{nodes_app_url}[/link] to access the Workflow Editor[/bold blue]",
417
- vertical="middle",
418
- ),
419
- title="🚀 Griptape Nodes Engine Started",
420
- subtitle=f"[green]{engine_version}{session_info}[/green]",
421
- border_style="green",
422
- padding=(1, 4),
423
- )
424
- console.print(message)
425
-
426
-
427
- def __process_api_event(data: dict) -> None:
428
- """Process API events and send them to the event queue."""
429
- try:
430
- data["request"]
431
- except KeyError:
432
- msg = "Error: 'request' was expected but not found."
433
- raise RuntimeError(msg) from None
434
-
435
- try:
436
- event_type = data["event_type"]
437
- if event_type != "EventRequest":
438
- msg = "Error: 'event_type' was found on request, but did not match 'EventRequest' as expected."
439
- raise RuntimeError(msg) from None
440
- except KeyError:
441
- msg = "Error: 'event_type' not found in request."
442
- raise RuntimeError(msg) from None
443
-
444
- # Now attempt to convert it into an EventRequest.
445
- try:
446
- request_event: EventRequest = cast("EventRequest", deserialize_event(json_data=data))
447
- except Exception as e:
448
- msg = f"Unable to convert request JSON into a valid EventRequest object. Error Message: '{e}'"
449
- raise RuntimeError(msg) from None
450
-
451
- # Add a request_id to the payload
452
- request_id = request_event.request.request_id
453
- request_event.request.request_id = request_id
454
-
455
- # Add the event to the queue
456
- event_queue.put(request_event)
457
-
458
- return request_id
@@ -1,105 +0,0 @@
1
- """Manages session persistence using XDG state directory.
2
-
3
- Handles storing and retrieving active session information across engine restarts.
4
- """
5
-
6
- import json
7
- from datetime import UTC, datetime
8
- from pathlib import Path
9
-
10
- from xdg_base_dirs import xdg_state_home
11
-
12
-
13
- class SessionPersistence:
14
- """Manages session persistence for active session tracking."""
15
-
16
- _SESSION_STATE_FILE = "session.json"
17
-
18
- @classmethod
19
- def _get_session_state_dir(cls) -> Path:
20
- """Get the XDG state directory for session persistence."""
21
- return xdg_state_home() / "griptape_nodes"
22
-
23
- @classmethod
24
- def _get_session_state_file(cls) -> Path:
25
- """Get the path to the session state storage file."""
26
- return cls._get_session_state_dir() / cls._SESSION_STATE_FILE
27
-
28
- @classmethod
29
- def _load_session_data(cls) -> dict:
30
- """Load session data from storage.
31
-
32
- Returns:
33
- dict: Session data including id, timestamps
34
- """
35
- session_state_file = cls._get_session_state_file()
36
-
37
- if session_state_file.exists():
38
- try:
39
- with session_state_file.open("r") as f:
40
- data = json.load(f)
41
- if isinstance(data, dict):
42
- return data
43
- except (json.JSONDecodeError, OSError):
44
- # If file is corrupted, return empty dict
45
- pass
46
-
47
- return {}
48
-
49
- @classmethod
50
- def _save_session_data(cls, session_data: dict) -> None:
51
- """Save session data to storage.
52
-
53
- Args:
54
- session_data: Session data to save
55
- """
56
- session_state_dir = cls._get_session_state_dir()
57
- session_state_dir.mkdir(parents=True, exist_ok=True)
58
-
59
- session_state_file = cls._get_session_state_file()
60
- with session_state_file.open("w") as f:
61
- json.dump(session_data, f, indent=2)
62
-
63
- @classmethod
64
- def persist_session(cls, session_id: str) -> None:
65
- """Persist the active session ID to storage.
66
-
67
- Args:
68
- session_id: The session ID to persist
69
- """
70
- session_data = {
71
- "session_id": session_id,
72
- "started_at": datetime.now(tz=UTC).isoformat(),
73
- "last_updated": datetime.now(tz=UTC).isoformat(),
74
- }
75
- cls._save_session_data(session_data)
76
-
77
- @classmethod
78
- def get_persisted_session_id(cls) -> str | None:
79
- """Get the persisted session ID if it exists.
80
-
81
- Returns:
82
- str | None: The persisted session ID or None if no session is persisted
83
- """
84
- session_data = cls._load_session_data()
85
- return session_data.get("session_id")
86
-
87
- @classmethod
88
- def clear_persisted_session(cls) -> None:
89
- """Clear the persisted session data."""
90
- session_state_file = cls._get_session_state_file()
91
- if session_state_file.exists():
92
- try:
93
- session_state_file.unlink()
94
- except OSError:
95
- # If we can't delete the file, just clear its contents
96
- cls._save_session_data({})
97
-
98
- @classmethod
99
- def has_persisted_session(cls) -> bool:
100
- """Check if there is a persisted session.
101
-
102
- Returns:
103
- bool: True if there is a persisted session, False otherwise
104
- """
105
- return cls.get_persisted_session_id() is not None
@@ -1,78 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: griptape-nodes
3
- Version: 0.41.0
4
- Summary: Add your description here
5
- License-File: LICENSE
6
- Requires-Python: ~=3.12
7
- Requires-Dist: fastapi>=0.115.12
8
- Requires-Dist: griptape[drivers-prompt-amazon-bedrock,drivers-prompt-anthropic,drivers-prompt-cohere,drivers-prompt-ollama,drivers-web-scraper-trafilatura,drivers-web-search-duckduckgo,drivers-web-search-exa,loaders-image]>=1.7.1
9
- Requires-Dist: httpx<1.0.0,>=0.28.0
10
- Requires-Dist: imageio-ffmpeg>=0.6.0
11
- Requires-Dist: json-repair>=0.46.1
12
- Requires-Dist: packaging>=25.0
13
- Requires-Dist: pydantic>=2.10.6
14
- Requires-Dist: python-dotenv>=1.0.1
15
- Requires-Dist: python-multipart>=0.0.20
16
- Requires-Dist: tomlkit>=0.13.2
17
- Requires-Dist: uv>=0.6.16
18
- Requires-Dist: uvicorn>=0.34.2
19
- Requires-Dist: websockets<16.0.0,>=15.0.1
20
- Requires-Dist: xdg-base-dirs>=6.0.2
21
- Provides-Extra: profiling
22
- Requires-Dist: austin-dist>=3.7.0; extra == 'profiling'
23
- Description-Content-Type: text/markdown
24
-
25
- # Griptape Nodes
26
-
27
- Griptape Nodes provides a powerful, visual, node-based interface for building and executing complex AI workflows. It combines a cloud-based IDE with a locally runnable engine, allowing for easy development, debugging, and execution of Griptape applications.
28
-
29
- [![Griptape Nodes Trailer Preview](docs/assets/img/video-thumbnail.jpg)](https://vimeo.com/1064451891)
30
- *(Clicking the image opens the video on Vimeo)*
31
-
32
- **Key Features:**
33
-
34
- - **Visual Workflow Editor:** Design and connect nodes representing different AI tasks, tools, and logic.
35
- - **Local Engine:** Run workflows securely on your own machine or infrastructure.
36
- - **Debugging & Stepping:** Analyze flow execution step-by-step.
37
- - **Scriptable Interface:** Interact with and control flows programmatically.
38
- - **Extensible:** Build your own custom nodes.
39
-
40
- **Learn More:**
41
-
42
- - **Full Documentation:** [docs.griptapenodes.com](https://docs.griptapenodes.com)
43
- - **Installation:** [docs.griptapenodes.com/en/stable/installation/](https://docs.griptapenodes.com/en/latest/installation/)
44
- - **Engine Configuration:** [docs.griptapenodes.com/en/stable/configuration/](https://docs.griptapenodes.com/en/latest/configuration/)
45
-
46
- ______________________________________________________________________
47
-
48
- ## Quick Installation
49
-
50
- Follow these steps to get the Griptape Nodes engine running on your system:
51
-
52
- 1. **Login:** Visit [Griptape Nodes](https://griptapenodes.com) and log in or sign up using your Griptape Cloud credentials.
53
-
54
- 1. **Install Command:** Once logged in, you'll find a setup screen. Copy the installation command provided in the "New Installation" section. It will look similar to this (use the **exact** command provided on the website):
55
-
56
- ```bash
57
- curl -LsSf https://raw.githubusercontent.com/griptape-ai/griptape-nodes/main/install.sh | bash
58
- ```
59
-
60
- 1. **Run Installer:** Open a terminal on your machine (local or cloud environment) and paste/run the command. The installer uses `uv` for fast installation; if `uv` isn't present, the script will typically handle installing it.
61
-
62
- 1. **Initial Configuration (Automatic on First Run):**
63
-
64
- - The first time you run the engine command (`griptape-nodes` or `gtn`), it will guide you through the initial setup:
65
- - **Workspace Directory:** You'll be prompted to choose a directory where Griptape Nodes will store configurations, project files, secrets (`.env`), and generated assets. You can accept the default (`<current_directory>/GriptapeNodes`) or specify a custom path.
66
- - **Griptape Cloud API Key:** Return to the [Griptape Nodes setup page](https://griptapenodes.com) in your browser, click "Generate API Key", copy the key, and paste it when prompted in the terminal.
67
-
68
- 1. **Start the Engine:** After configuration, start the engine by running:
69
-
70
- ```bash
71
- griptape-nodes
72
- ```
73
-
74
- *(or the shorter alias `gtn`)*
75
-
76
- 1. **Connect Workflow Editor:** Refresh the Griptape Nodes Workflow Editor page in your browser. It should now connect to your running engine.
77
-
78
- You're now ready to start building flows! For more detailed setup options and troubleshooting, see the full [Documentation](https://docs.griptapenodes.com/).