zorvex-api 0.0.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 (125) hide show
  1. zorvex_api-0.0.1/.gitignore +34 -0
  2. zorvex_api-0.0.1/PKG-INFO +45 -0
  3. zorvex_api-0.0.1/alembic/env.py +76 -0
  4. zorvex_api-0.0.1/alembic/script.py.mako +24 -0
  5. zorvex_api-0.0.1/alembic/versions/0001_baseline.py +153 -0
  6. zorvex_api-0.0.1/alembic.ini +107 -0
  7. zorvex_api-0.0.1/pyproject.toml +128 -0
  8. zorvex_api-0.0.1/src/zorvex_api/__init__.py +5 -0
  9. zorvex_api-0.0.1/src/zorvex_api/api/__init__.py +1 -0
  10. zorvex_api-0.0.1/src/zorvex_api/api/a2a.py +236 -0
  11. zorvex_api-0.0.1/src/zorvex_api/api/assistants.py +245 -0
  12. zorvex_api-0.0.1/src/zorvex_api/api/crons.py +235 -0
  13. zorvex_api-0.0.1/src/zorvex_api/api/event_streaming.py +174 -0
  14. zorvex_api-0.0.1/src/zorvex_api/api/mcp.py +103 -0
  15. zorvex_api-0.0.1/src/zorvex_api/api/runs.py +423 -0
  16. zorvex_api-0.0.1/src/zorvex_api/api/stateless_runs.py +116 -0
  17. zorvex_api-0.0.1/src/zorvex_api/api/store.py +216 -0
  18. zorvex_api-0.0.1/src/zorvex_api/api/system.py +131 -0
  19. zorvex_api-0.0.1/src/zorvex_api/api/threads.py +620 -0
  20. zorvex_api-0.0.1/src/zorvex_api/api/ui.py +48 -0
  21. zorvex_api-0.0.1/src/zorvex_api/config.py +360 -0
  22. zorvex_api-0.0.1/src/zorvex_api/constants.py +8 -0
  23. zorvex_api-0.0.1/src/zorvex_api/core/__init__.py +0 -0
  24. zorvex_api-0.0.1/src/zorvex_api/core/active_runs.py +16 -0
  25. zorvex_api-0.0.1/src/zorvex_api/core/auth_deps.py +30 -0
  26. zorvex_api-0.0.1/src/zorvex_api/core/auth_filters.py +90 -0
  27. zorvex_api-0.0.1/src/zorvex_api/core/auth_middleware.py +108 -0
  28. zorvex_api-0.0.1/src/zorvex_api/core/authorization.py +162 -0
  29. zorvex_api-0.0.1/src/zorvex_api/core/database.py +176 -0
  30. zorvex_api-0.0.1/src/zorvex_api/core/loopback.py +45 -0
  31. zorvex_api-0.0.1/src/zorvex_api/core/migrations.py +130 -0
  32. zorvex_api-0.0.1/src/zorvex_api/core/orm.py +274 -0
  33. zorvex_api-0.0.1/src/zorvex_api/core/redis_manager.py +113 -0
  34. zorvex_api-0.0.1/src/zorvex_api/core/route_merger.py +72 -0
  35. zorvex_api-0.0.1/src/zorvex_api/core/serializers.py +67 -0
  36. zorvex_api-0.0.1/src/zorvex_api/core/sse.py +84 -0
  37. zorvex_api-0.0.1/src/zorvex_api/main.py +525 -0
  38. zorvex_api-0.0.1/src/zorvex_api/middleware/__init__.py +5 -0
  39. zorvex_api-0.0.1/src/zorvex_api/middleware/auth_first.py +38 -0
  40. zorvex_api-0.0.1/src/zorvex_api/middleware/configurable_headers.py +25 -0
  41. zorvex_api-0.0.1/src/zorvex_api/middleware/content_type_fix.py +59 -0
  42. zorvex_api-0.0.1/src/zorvex_api/middleware/logger_middleware.py +82 -0
  43. zorvex_api-0.0.1/src/zorvex_api/models/__init__.py +91 -0
  44. zorvex_api-0.0.1/src/zorvex_api/models/assistants.py +154 -0
  45. zorvex_api-0.0.1/src/zorvex_api/models/auth.py +34 -0
  46. zorvex_api-0.0.1/src/zorvex_api/models/crons.py +185 -0
  47. zorvex_api-0.0.1/src/zorvex_api/models/entity_ids.py +9 -0
  48. zorvex_api-0.0.1/src/zorvex_api/models/enums.py +54 -0
  49. zorvex_api-0.0.1/src/zorvex_api/models/errors.py +58 -0
  50. zorvex_api-0.0.1/src/zorvex_api/models/event_streaming.py +32 -0
  51. zorvex_api-0.0.1/src/zorvex_api/models/run_job.py +104 -0
  52. zorvex_api-0.0.1/src/zorvex_api/models/runs.py +274 -0
  53. zorvex_api-0.0.1/src/zorvex_api/models/search.py +11 -0
  54. zorvex_api-0.0.1/src/zorvex_api/models/store.py +83 -0
  55. zorvex_api-0.0.1/src/zorvex_api/models/threads.py +321 -0
  56. zorvex_api-0.0.1/src/zorvex_api/observability/__init__.py +1 -0
  57. zorvex_api-0.0.1/src/zorvex_api/observability/metrics.py +135 -0
  58. zorvex_api-0.0.1/src/zorvex_api/observability/tracing.py +222 -0
  59. zorvex_api-0.0.1/src/zorvex_api/services/__init__.py +0 -0
  60. zorvex_api-0.0.1/src/zorvex_api/services/a2a_messages.py +656 -0
  61. zorvex_api-0.0.1/src/zorvex_api/services/a2a_service.py +1296 -0
  62. zorvex_api-0.0.1/src/zorvex_api/services/a2ui.py +225 -0
  63. zorvex_api-0.0.1/src/zorvex_api/services/a2ui_schemas/README.md +6 -0
  64. zorvex_api-0.0.1/src/zorvex_api/services/a2ui_schemas/client_capabilities.json +97 -0
  65. zorvex_api-0.0.1/src/zorvex_api/services/a2ui_schemas/client_data_model.json +22 -0
  66. zorvex_api-0.0.1/src/zorvex_api/services/a2ui_schemas/client_to_server.json +104 -0
  67. zorvex_api-0.0.1/src/zorvex_api/services/a2ui_schemas/server_to_client.json +132 -0
  68. zorvex_api-0.0.1/src/zorvex_api/services/assistant_service.py +610 -0
  69. zorvex_api-0.0.1/src/zorvex_api/services/base_broker.py +160 -0
  70. zorvex_api-0.0.1/src/zorvex_api/services/base_executor.py +37 -0
  71. zorvex_api-0.0.1/src/zorvex_api/services/broker.py +273 -0
  72. zorvex_api-0.0.1/src/zorvex_api/services/checkpoints.py +105 -0
  73. zorvex_api-0.0.1/src/zorvex_api/services/cron_scheduler.py +205 -0
  74. zorvex_api-0.0.1/src/zorvex_api/services/cron_service.py +515 -0
  75. zorvex_api-0.0.1/src/zorvex_api/services/event_converter.py +30 -0
  76. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/__init__.py +6 -0
  77. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/channels.py +23 -0
  78. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/commands.py +446 -0
  79. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/native_stream.py +96 -0
  80. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/normalizers.py +353 -0
  81. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/protocol.py +55 -0
  82. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/session.py +526 -0
  83. zorvex_api-0.0.1/src/zorvex_api/services/event_streaming/ws.py +175 -0
  84. zorvex_api-0.0.1/src/zorvex_api/services/executor.py +29 -0
  85. zorvex_api-0.0.1/src/zorvex_api/services/graph_factory.py +139 -0
  86. zorvex_api-0.0.1/src/zorvex_api/services/graph_streaming.py +159 -0
  87. zorvex_api-0.0.1/src/zorvex_api/services/job_queue.py +42 -0
  88. zorvex_api-0.0.1/src/zorvex_api/services/langgraph_service.py +291 -0
  89. zorvex_api-0.0.1/src/zorvex_api/services/lease_reaper.py +281 -0
  90. zorvex_api-0.0.1/src/zorvex_api/services/local_executor.py +89 -0
  91. zorvex_api-0.0.1/src/zorvex_api/services/mcp_calls.py +662 -0
  92. zorvex_api-0.0.1/src/zorvex_api/services/mcp_elicitation.py +648 -0
  93. zorvex_api-0.0.1/src/zorvex_api/services/mcp_forms.py +308 -0
  94. zorvex_api-0.0.1/src/zorvex_api/services/mcp_server.py +290 -0
  95. zorvex_api-0.0.1/src/zorvex_api/services/ownership.py +85 -0
  96. zorvex_api-0.0.1/src/zorvex_api/services/priority.py +92 -0
  97. zorvex_api-0.0.1/src/zorvex_api/services/redis_broker.py +520 -0
  98. zorvex_api-0.0.1/src/zorvex_api/services/run_cancel.py +79 -0
  99. zorvex_api-0.0.1/src/zorvex_api/services/run_cleanup.py +210 -0
  100. zorvex_api-0.0.1/src/zorvex_api/services/run_executor.py +332 -0
  101. zorvex_api-0.0.1/src/zorvex_api/services/run_preparation.py +536 -0
  102. zorvex_api-0.0.1/src/zorvex_api/services/run_queue.py +52 -0
  103. zorvex_api-0.0.1/src/zorvex_api/services/run_status.py +190 -0
  104. zorvex_api-0.0.1/src/zorvex_api/services/run_waiters.py +179 -0
  105. zorvex_api-0.0.1/src/zorvex_api/services/streaming_service.py +163 -0
  106. zorvex_api-0.0.1/src/zorvex_api/services/thread_events.py +68 -0
  107. zorvex_api-0.0.1/src/zorvex_api/services/thread_service.py +185 -0
  108. zorvex_api-0.0.1/src/zorvex_api/services/thread_state_service.py +84 -0
  109. zorvex_api-0.0.1/src/zorvex_api/services/thread_stream.py +171 -0
  110. zorvex_api-0.0.1/src/zorvex_api/services/thread_ttl.py +277 -0
  111. zorvex_api-0.0.1/src/zorvex_api/services/webhook_delivery.py +329 -0
  112. zorvex_api-0.0.1/src/zorvex_api/services/webhook_policy.py +218 -0
  113. zorvex_api-0.0.1/src/zorvex_api/services/webhook_signing.py +54 -0
  114. zorvex_api-0.0.1/src/zorvex_api/services/worker_executor.py +620 -0
  115. zorvex_api-0.0.1/src/zorvex_api/settings.py +278 -0
  116. zorvex_api-0.0.1/src/zorvex_api/utils/__init__.py +3 -0
  117. zorvex_api-0.0.1/src/zorvex_api/utils/assistants.py +23 -0
  118. zorvex_api-0.0.1/src/zorvex_api/utils/event_loop.py +12 -0
  119. zorvex_api-0.0.1/src/zorvex_api/utils/headers.py +100 -0
  120. zorvex_api-0.0.1/src/zorvex_api/utils/jsonb.py +41 -0
  121. zorvex_api-0.0.1/src/zorvex_api/utils/loader.py +50 -0
  122. zorvex_api-0.0.1/src/zorvex_api/utils/pagination.py +12 -0
  123. zorvex_api-0.0.1/src/zorvex_api/utils/run_utils.py +120 -0
  124. zorvex_api-0.0.1/src/zorvex_api/utils/setup_logging.py +143 -0
  125. zorvex_api-0.0.1/src/zorvex_api/utils/sse_utils.py +26 -0
@@ -0,0 +1,34 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # env files
13
+ .env
14
+
15
+ # Pycharm
16
+ .idea/
17
+
18
+ # VSCode
19
+ .vscode/
20
+
21
+ # Type checkers
22
+ .mypy_cache/
23
+
24
+ # Ruff
25
+ .ruff_cache/
26
+
27
+ # Pre-commit
28
+ .pre-commit-cache/
29
+
30
+ # MacOS
31
+ .DS_Store
32
+
33
+ # Claude
34
+ .claude/
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.5
2
+ Name: zorvex-api
3
+ Version: 0.0.1
4
+ Summary: Zorvex core API - Self-hosted Agent Protocol server
5
+ License-Expression: Apache-2.0
6
+ Keywords: agent-protocol,agents,fastapi,langgraph,llm
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Framework :: FastAPI
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Requires-Python: >=3.12
14
+ Requires-Dist: alembic>=1.20.1
15
+ Requires-Dist: anyio>=4.16.0
16
+ Requires-Dist: asgi-correlation-id>=5.0.1
17
+ Requires-Dist: asyncpg>=0.32.0
18
+ Requires-Dist: colorama>=0.4.6; sys_platform == 'win32'
19
+ Requires-Dist: croniter>=7.0.0
20
+ Requires-Dist: fastapi>=0.165.0
21
+ Requires-Dist: greenlet>=3.5.6
22
+ Requires-Dist: httpx>=0.28.1
23
+ Requires-Dist: jsonschema>=4.26.0
24
+ Requires-Dist: langchain-core>=1.8.4
25
+ Requires-Dist: langchain-protocol>=0.0.22
26
+ Requires-Dist: langgraph-checkpoint-postgres>=3.2.1
27
+ Requires-Dist: langgraph-sdk>=0.4.14
28
+ Requires-Dist: langgraph>=1.2.24
29
+ Requires-Dist: mcp>=2.3.0
30
+ Requires-Dist: openinference-instrumentation-langchain>=0.1.90
31
+ Requires-Dist: opentelemetry-api>=1.45.2
32
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.45.2
33
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.66b2
34
+ Requires-Dist: opentelemetry-sdk>=1.45.2
35
+ Requires-Dist: prometheus-fastapi-instrumentator>=8.1.0
36
+ Requires-Dist: psycopg[binary]>=3.3.9
37
+ Requires-Dist: pydantic-settings>=2.16.3
38
+ Requires-Dist: pydantic>=2.14.4
39
+ Requires-Dist: redis[hiredis]>=8.2.0
40
+ Requires-Dist: sqlalchemy>=2.1.9
41
+ Requires-Dist: sse-starlette<4.0.0,>=3.7.1
42
+ Requires-Dist: standardwebhooks>=1.3.0
43
+ Requires-Dist: structlog>=26.1.0
44
+ Requires-Dist: tenacity>=9.1.2
45
+ Requires-Dist: uvicorn[standard]>=0.54.0
@@ -0,0 +1,76 @@
1
+ """Alembic environment configuration for Zorvex database migrations."""
2
+
3
+ import asyncio
4
+ import threading
5
+ from logging.config import fileConfig
6
+
7
+ from sqlalchemy import pool
8
+ from sqlalchemy.engine import Connection
9
+
10
+ from alembic import context
11
+ from zorvex_api.core.database import create_db_engine
12
+ from zorvex_api.core.orm import Base
13
+
14
+ # This is the Alembic Config object, which provides
15
+ # access to the values within the .ini file in use.
16
+ config = context.config
17
+
18
+ # Interpret the config file for Python logging.
19
+ # Only reconfigure logging when running from CLI (main thread).
20
+ # When invoked programmatically via asyncio.to_thread(), fileConfig()
21
+ # causes a cross-thread deadlock with the application's logging.
22
+ # See: https://github.com/sqlalchemy/alembic/discussions/1483
23
+ if config.config_file_name is not None and threading.current_thread() is threading.main_thread():
24
+ fileConfig(config.config_file_name)
25
+
26
+ target_metadata = Base.metadata
27
+
28
+
29
+ def _include_name(name: str | None, type_: str, _parent_names: object) -> bool:
30
+ """Autogenerate compares Zorvex's tables only; LangGraph creates and migrates its own."""
31
+ return type_ != "table" or name in target_metadata.tables
32
+
33
+
34
+ def run_migrations_offline() -> None:
35
+ """Emit the migration SQL instead of running it."""
36
+ context.configure(
37
+ dialect_name="postgresql",
38
+ target_metadata=target_metadata,
39
+ include_name=_include_name,
40
+ literal_binds=True,
41
+ dialect_opts={"paramstyle": "named"},
42
+ )
43
+
44
+ with context.begin_transaction():
45
+ context.run_migrations()
46
+
47
+
48
+ def do_run_migrations(connection: Connection) -> None:
49
+ """Run migrations with the given connection."""
50
+ context.configure(connection=connection, target_metadata=target_metadata, include_name=_include_name)
51
+
52
+ with context.begin_transaction():
53
+ context.run_migrations()
54
+
55
+
56
+ async def run_async_migrations() -> None:
57
+ """Run the migrations on a connection to settings' database."""
58
+ # The URL never goes through alembic.ini: configparser would reject the %XX
59
+ # escapes of a quoted password.
60
+ connectable = create_db_engine(poolclass=pool.NullPool)
61
+
62
+ async with connectable.connect() as connection:
63
+ await connection.run_sync(do_run_migrations)
64
+
65
+ await connectable.dispose()
66
+
67
+
68
+ def run_migrations_online() -> None:
69
+ """Run migrations in 'online' mode."""
70
+ asyncio.run(run_async_migrations())
71
+
72
+
73
+ if context.is_offline_mode():
74
+ run_migrations_offline()
75
+ else:
76
+ run_migrations_online()
@@ -0,0 +1,24 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from alembic import op
9
+ import sqlalchemy as sa
10
+ ${imports if imports else ""}
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = ${repr(up_revision)}
14
+ down_revision = ${repr(down_revision)}
15
+ branch_labels = ${repr(branch_labels)}
16
+ depends_on = ${repr(depends_on)}
17
+
18
+
19
+ def upgrade() -> None:
20
+ ${upgrades if upgrades else "pass"}
21
+
22
+
23
+ def downgrade() -> None:
24
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,153 @@
1
+ """Baseline schema
2
+
3
+ Revision ID: 0001
4
+ Revises:
5
+ Create Date: 2026-11-25
6
+
7
+ Zorvex's own tables, as core/orm.py defines them. LangGraph creates and migrates
8
+ its checkpoint and store tables itself. A database from before this baseline has
9
+ no upgrade path: recreate it. One at 0002 (run priority, folded in here) already
10
+ has this schema: stamp it instead, ``alembic stamp --purge 0001``.
11
+ """
12
+
13
+ import sqlalchemy as sa
14
+ from sqlalchemy.dialects import postgresql
15
+
16
+ from alembic import op
17
+
18
+ revision = "0001"
19
+ down_revision = None
20
+ branch_labels = None
21
+ depends_on = None
22
+
23
+
24
+ def upgrade() -> None:
25
+ op.create_table(
26
+ "assistant",
27
+ sa.Column("assistant_id", sa.Text(), server_default=sa.text("gen_random_uuid()::text"), nullable=False),
28
+ sa.Column("name", sa.Text(), nullable=False),
29
+ sa.Column("description", sa.Text(), nullable=True),
30
+ sa.Column("graph_id", sa.Text(), nullable=False),
31
+ sa.Column("config", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
32
+ sa.Column("context", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
33
+ sa.Column("user_id", sa.Text(), nullable=False),
34
+ sa.Column("version", sa.Integer(), server_default=sa.text("1"), nullable=False),
35
+ sa.Column("metadata", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
36
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
37
+ sa.Column("updated_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
38
+ sa.PrimaryKeyConstraint("assistant_id"),
39
+ )
40
+ op.create_index(
41
+ "idx_assistant_metadata_gin",
42
+ "assistant",
43
+ ["metadata"],
44
+ unique=False,
45
+ postgresql_using="gin",
46
+ postgresql_ops={"metadata": "jsonb_path_ops"},
47
+ )
48
+ op.create_index("idx_assistant_user", "assistant", ["user_id"], unique=False)
49
+ op.create_table(
50
+ "thread",
51
+ sa.Column("thread_id", sa.Text(), nullable=False),
52
+ sa.Column("status", sa.Text(), server_default=sa.text("'idle'"), nullable=False),
53
+ sa.Column("metadata", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
54
+ sa.Column("config", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
55
+ sa.Column("values", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
56
+ sa.Column("interrupts", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
57
+ sa.Column("user_id", sa.Text(), nullable=False),
58
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
59
+ sa.Column("updated_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
60
+ sa.Column("state_updated_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
61
+ sa.Column("run_priority", sa.Integer(), nullable=True),
62
+ sa.Column("fairness_group", sa.Text(), nullable=True),
63
+ sa.PrimaryKeyConstraint("thread_id"),
64
+ )
65
+ op.create_index(
66
+ "idx_thread_metadata_gin",
67
+ "thread",
68
+ ["metadata"],
69
+ unique=False,
70
+ postgresql_using="gin",
71
+ postgresql_ops={"metadata": "jsonb_path_ops"},
72
+ )
73
+ op.create_index("idx_thread_user", "thread", ["user_id"], unique=False)
74
+ op.create_table(
75
+ "assistant_versions",
76
+ sa.Column("assistant_id", sa.Text(), nullable=False),
77
+ sa.Column("version", sa.Integer(), nullable=False),
78
+ sa.Column("graph_id", sa.Text(), nullable=False),
79
+ sa.Column("config", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
80
+ sa.Column("context", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
81
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
82
+ sa.Column("metadata", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
83
+ sa.Column("name", sa.Text(), nullable=False),
84
+ sa.Column("description", sa.Text(), nullable=True),
85
+ sa.ForeignKeyConstraint(["assistant_id"], ["assistant.assistant_id"], ondelete="CASCADE"),
86
+ sa.PrimaryKeyConstraint("assistant_id", "version"),
87
+ )
88
+ op.create_table(
89
+ "cron",
90
+ sa.Column("cron_id", sa.Text(), server_default=sa.text("gen_random_uuid()::text"), nullable=False),
91
+ sa.Column("assistant_id", sa.Text(), nullable=False),
92
+ sa.Column("thread_id", sa.Text(), nullable=True),
93
+ sa.Column("user_id", sa.Text(), nullable=False),
94
+ sa.Column("schedule", sa.Text(), nullable=False),
95
+ sa.Column("timezone", sa.Text(), nullable=True),
96
+ sa.Column("payload", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
97
+ sa.Column("metadata", postgresql.JSONB(), server_default=sa.text("'{}'::jsonb"), nullable=False),
98
+ sa.Column("on_run_completed", sa.Text(), nullable=True),
99
+ sa.Column("enabled", sa.Boolean(), server_default=sa.text("true"), nullable=False),
100
+ sa.Column("end_time", sa.TIMESTAMP(timezone=True), nullable=True),
101
+ sa.Column("next_run_date", sa.TIMESTAMP(timezone=True), nullable=True),
102
+ sa.Column("claimed_until", sa.TIMESTAMP(timezone=True), nullable=True),
103
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
104
+ sa.Column("updated_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
105
+ sa.ForeignKeyConstraint(["assistant_id"], ["assistant.assistant_id"], ondelete="CASCADE"),
106
+ sa.ForeignKeyConstraint(["thread_id"], ["thread.thread_id"], ondelete="CASCADE"),
107
+ sa.PrimaryKeyConstraint("cron_id"),
108
+ )
109
+ op.create_index("idx_cron_assistant_id", "cron", ["assistant_id"], unique=False)
110
+ op.create_index("idx_cron_next_run", "cron", ["enabled", "next_run_date"], unique=False)
111
+ op.create_index("idx_cron_thread_id", "cron", ["thread_id"], unique=False)
112
+ op.create_index("idx_cron_user", "cron", ["user_id"], unique=False)
113
+ op.create_table(
114
+ "run",
115
+ sa.Column("run_id", sa.Text(), server_default=sa.text("gen_random_uuid()::text"), nullable=False),
116
+ sa.Column("thread_id", sa.Text(), nullable=False),
117
+ sa.Column("assistant_id", sa.Text(), nullable=False),
118
+ sa.Column("status", sa.Text(), server_default=sa.text("'pending'"), nullable=False),
119
+ sa.Column("error", postgresql.JSONB(), nullable=True),
120
+ sa.Column("user_id", sa.Text(), nullable=False),
121
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
122
+ sa.Column("updated_at", sa.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
123
+ sa.Column("priority", sa.Integer(), server_default=sa.text("0"), nullable=False),
124
+ sa.Column("execution_params", postgresql.JSONB(), nullable=False),
125
+ sa.Column("claimed_by", sa.Text(), nullable=True),
126
+ sa.Column("lease_expires_at", sa.TIMESTAMP(timezone=True), nullable=True),
127
+ sa.Column("retries", sa.Integer(), server_default=sa.text("0"), nullable=False),
128
+ sa.Column("cancel_action", sa.Text(), nullable=True),
129
+ sa.Column("cancel_reason", sa.Text(), nullable=True),
130
+ sa.ForeignKeyConstraint(["assistant_id"], ["assistant.assistant_id"], ondelete="CASCADE"),
131
+ sa.ForeignKeyConstraint(["thread_id"], ["thread.thread_id"], ondelete="CASCADE"),
132
+ sa.PrimaryKeyConstraint("run_id"),
133
+ )
134
+ op.create_index("idx_run_assistant_id", "run", ["assistant_id"], unique=False)
135
+ op.create_index("idx_run_created_at", "run", ["created_at"], unique=False)
136
+ op.create_index("idx_run_lease_reaper", "run", ["status", "lease_expires_at"], unique=False)
137
+ op.create_index("idx_run_thread_id", "run", ["thread_id"], unique=False)
138
+ op.create_index("idx_run_user", "run", ["user_id"], unique=False)
139
+ op.create_table(
140
+ "thread_ttl",
141
+ sa.Column("thread_id", sa.Text(), nullable=False),
142
+ sa.Column("strategy", sa.Text(), server_default=sa.text("'delete'"), nullable=False),
143
+ sa.Column("ttl_minutes", sa.Float(), nullable=False),
144
+ sa.Column("expires_at", sa.TIMESTAMP(timezone=True), nullable=False),
145
+ sa.ForeignKeyConstraint(["thread_id"], ["thread.thread_id"], ondelete="CASCADE"),
146
+ sa.PrimaryKeyConstraint("thread_id"),
147
+ )
148
+ op.create_index("idx_thread_ttl_expires_at", "thread_ttl", ["expires_at"], unique=False)
149
+
150
+
151
+ def downgrade() -> None:
152
+ for table in ("thread_ttl", "run", "cron", "assistant_versions", "thread", "assistant"):
153
+ op.drop_table(table)
@@ -0,0 +1,107 @@
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts
5
+ script_location = alembic
6
+
7
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
8
+ # Using timestamp-based naming for better readability
9
+ file_template = %%(year)d%%(month).2d%%(day).2d%%(hour).2d%%(minute).2d%%(second).2d_%%(slug)s
10
+
11
+ # sys.path path, will be prepended to sys.path if present.
12
+ # defaults to the current working directory.
13
+ prepend_sys_path = .
14
+
15
+ # timezone to use when rendering the date within the migration file
16
+ # as well as the filename.
17
+ # If specified, requires the python-dateutil library that can be
18
+ # installed by adding `alembic[tz]` to the pip requirements
19
+ # string value is passed to dateutil.tz.gettz()
20
+ # leave blank for localtime
21
+ # timezone =
22
+
23
+ # max length of characters to apply to the
24
+ # "slug" field
25
+ # truncate_slug_length = 40
26
+
27
+ # set to 'true' to run the environment during
28
+ # the 'revision' command, regardless of autogenerate
29
+ # revision_environment = false
30
+
31
+ # set to 'true' to allow .pyc and .pyo files without
32
+ # a source .py file to be detected as revisions in the
33
+ # versions/ directory
34
+ # sourceless = false
35
+
36
+ # version number format
37
+ version_num_format = %%04d
38
+
39
+ # version path separator; As mentioned above, this is the character used to split
40
+ # version_locations. The default within new alembic.ini files is "os", which uses
41
+ # os.pathsep. If this key is omitted entirely, it falls back to the legacy
42
+ # behavior of splitting on spaces and/or commas.
43
+ # Valid values for version_path_separator are:
44
+ #
45
+ # version_path_separator = :
46
+ # version_path_separator = ;
47
+ # version_path_separator = space
48
+ version_path_separator = os
49
+
50
+ # the output encoding used when revision files
51
+ # are written from script.py.mako
52
+ # output_encoding = utf-8
53
+
54
+ # env.py connects to DATABASE_URI through the server's engine; no URL is configured here.
55
+
56
+
57
+ [post_write_hooks]
58
+ # post_write_hooks defines scripts or Python functions that are run
59
+ # on newly generated revision scripts. See the documentation for further
60
+ # detail and examples
61
+
62
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
63
+ # hooks = black
64
+ # black.type = console_scripts
65
+ # black.entrypoint = black
66
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
67
+
68
+ # lint with attempts to fix using "ruff" - use the exec runner, execute a binary
69
+ # hooks = ruff
70
+ # ruff.type = exec
71
+ # ruff.executable = %(here)s/.venv/bin/ruff
72
+ # ruff.options = --fix REVISION_SCRIPT_FILENAME
73
+
74
+ # Logging configuration
75
+ [loggers]
76
+ keys = root,sqlalchemy,alembic
77
+
78
+ [handlers]
79
+ keys = console
80
+
81
+ [formatters]
82
+ keys = generic
83
+
84
+ [logger_root]
85
+ level = WARN
86
+ handlers = console
87
+ qualname =
88
+
89
+ [logger_sqlalchemy]
90
+ level = WARN
91
+ handlers =
92
+ qualname = sqlalchemy.engine
93
+
94
+ [logger_alembic]
95
+ level = INFO
96
+ handlers =
97
+ qualname = alembic
98
+
99
+ [handler_console]
100
+ class = StreamHandler
101
+ args = (sys.stderr,)
102
+ level = NOTSET
103
+ formatter = generic
104
+
105
+ [formatter_generic]
106
+ format = %(levelname)-5.5s [%(name)s] %(message)s
107
+ datefmt = %H:%M:%S
@@ -0,0 +1,128 @@
1
+ [project]
2
+ name = "zorvex-api"
3
+ version = "0.0.1"
4
+ description = "Zorvex core API - Self-hosted Agent Protocol server"
5
+ requires-python = ">=3.12"
6
+ license = "Apache-2.0"
7
+ keywords = ["langgraph", "agents", "llm", "fastapi", "agent-protocol"]
8
+ classifiers = [
9
+ "Development Status :: 4 - Beta",
10
+ "Framework :: FastAPI",
11
+ "Intended Audience :: Developers",
12
+ "License :: OSI Approved :: Apache Software License",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
15
+ ]
16
+
17
+ dependencies = [
18
+ # Core
19
+ "fastapi>=0.165.0",
20
+ # [standard]: uvloop and httptools off Windows, and websockets for the WebSocket routes
21
+ "uvicorn[standard]>=0.54.0",
22
+ "pydantic>=2.14.4",
23
+ "pydantic-settings>=2.16.3",
24
+ "sse-starlette>=3.7.1,<4.0.0",
25
+ # Imported directly for CancelScope(shield=True)
26
+ "anyio>=4.16.0",
27
+
28
+ # LangGraph
29
+ "langgraph>=1.2.24",
30
+ "langchain-core>=1.8.4",
31
+ "langgraph-sdk>=0.4.14",
32
+ # Agent Protocol v2 types (event streaming)
33
+ "langchain-protocol>=0.0.22",
34
+ "langgraph-checkpoint-postgres>=3.2.1",
35
+
36
+ # Database
37
+ "sqlalchemy>=2.1.9",
38
+ "greenlet>=3.5.6",
39
+ "asyncpg>=0.32.0",
40
+ "psycopg[binary]>=3.3.9",
41
+ "alembic>=1.20.1",
42
+
43
+ # Observability (OpenTelemetry)
44
+ "opentelemetry-api>=1.45.2",
45
+ "opentelemetry-sdk>=1.45.2",
46
+ "opentelemetry-exporter-otlp-proto-http>=1.45.2",
47
+ "openinference-instrumentation-langchain>=0.1.90",
48
+ # HTTP server spans, and the W3C trace context of each request
49
+ "opentelemetry-instrumentation-fastapi>=0.66b2",
50
+
51
+ # Metrics
52
+ "prometheus-fastapi-instrumentator>=8.1.0",
53
+
54
+ # Agent interop protocols
55
+ "mcp>=2.3.0",
56
+ # MCP elicitation: answers are checked against the form, and decisions against their schema
57
+ "jsonschema>=4.26.0",
58
+
59
+ # Utils
60
+ "structlog>=26.1.0",
61
+ # structlog's colored console renderer needs it on Windows (LOG_FORMAT=console)
62
+ "colorama>=0.4.6; sys_platform == 'win32'",
63
+ "asgi-correlation-id>=5.0.1",
64
+ # Run-completion webhook delivery
65
+ "httpx>=0.28.1",
66
+ # Retries with backoff, and Standard Webhooks signatures
67
+ "tenacity>=9.1.2",
68
+ "standardwebhooks>=1.3.0",
69
+
70
+ # Redis (optional broker backend for multi-instance streaming)
71
+ "redis[hiredis]>=8.2.0",
72
+
73
+ # Cron expression parsing
74
+ "croniter>=7.0.0",
75
+ ]
76
+
77
+ [build-system]
78
+ requires = ["hatchling"]
79
+ build-backend = "hatchling.build"
80
+
81
+ [tool.hatch.build.targets.wheel]
82
+ packages = ["src/zorvex_api"]
83
+
84
+ [tool.hatch.build.targets.wheel.force-include]
85
+ "alembic.ini" = "zorvex_api/alembic.ini"
86
+ "alembic" = "zorvex_api/alembic"
87
+
88
+ [tool.ruff]
89
+ line-length = 120
90
+ target-version = "py312"
91
+
92
+ [tool.ruff.format]
93
+ # This package's [tool.ruff] overrides the root config for files beneath it, so
94
+ # the markdown exclusion has to be repeated here. See the root pyproject.toml.
95
+ exclude = ["**/*.md"]
96
+
97
+ [tool.ruff.lint]
98
+ select = [
99
+ "E", # pycodestyle errors
100
+ "W", # pycodestyle warnings
101
+ "F", # pyflakes
102
+ "I", # isort
103
+ "B", # flake8-bugbear
104
+ "C4", # flake8-comprehensions
105
+ "UP", # pyupgrade
106
+ "ARG", # flake8-unused-arguments
107
+ "SIM", # flake8-simplify
108
+ ]
109
+ ignore = [
110
+ "E501", # line too long (handled by formatter)
111
+ "B008", # do not perform function calls in argument defaults
112
+ "B904", # Within an except clause, raise exceptions with `raise ... from err`
113
+ "ARG001", # Unused function argument
114
+ "ARG002", # Unused method argument
115
+ "ARG005", # Unused lambda argument
116
+ "SIM108", # Use ternary operator (less readable in many cases)
117
+ ]
118
+
119
+ [tool.ruff.lint.isort]
120
+ known-first-party = ["zorvex_api", "zorvex_cli"]
121
+
122
+ [dependency-groups]
123
+ dev = [
124
+ "ruff>=0.17.6",
125
+ "ty>=0.0.108,<0.1.0",
126
+ "bandit>=1.9.4",
127
+ "pre-commit>=4.7.0",
128
+ ]
@@ -0,0 +1,5 @@
1
+ """Zorvex API - Self-hosted Agent Protocol server."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ __version__ = version("zorvex-api")
@@ -0,0 +1 @@
1
+ """Agent Protocol API endpoints"""