continuum-task-server-bundle 1.0.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 (90) hide show
  1. continuum_task_server_bundle/__init__.py +1 -0
  2. continuum_task_server_bundle/daytona/__init__.py +4 -0
  3. continuum_task_server_bundle/daytona/common.py +534 -0
  4. continuum_task_server_bundle/daytona/create_sandbox.py +166 -0
  5. continuum_task_server_bundle/daytona/dispatch.py +125 -0
  6. continuum_task_server_bundle/daytona/execute_sandbox.py +243 -0
  7. continuum_task_server_bundle/daytona/filesystem.py +330 -0
  8. continuum_task_server_bundle/daytona/fs_edit.py +127 -0
  9. continuum_task_server_bundle/daytona/git_ops.py +585 -0
  10. continuum_task_server_bundle/daytona/github_app.py +207 -0
  11. continuum_task_server_bundle/daytona/manage_sandbox.py +104 -0
  12. continuum_task_server_bundle/daytona/plugin.py +18 -0
  13. continuum_task_server_bundle/daytona/s3_transfer.py +207 -0
  14. continuum_task_server_bundle/discord/__init__.py +4 -0
  15. continuum_task_server_bundle/discord/attachment_registry_db.py +127 -0
  16. continuum_task_server_bundle/discord/attachment_resolve.py +213 -0
  17. continuum_task_server_bundle/discord/await_cleanup.py +105 -0
  18. continuum_task_server_bundle/discord/discord_ready.py +39 -0
  19. continuum_task_server_bundle/discord/message_await_apply.py +143 -0
  20. continuum_task_server_bundle/discord/message_await_db.py +197 -0
  21. continuum_task_server_bundle/discord/message_await_inbound.py +54 -0
  22. continuum_task_server_bundle/discord/message_await_logic.py +133 -0
  23. continuum_task_server_bundle/discord/message_await_poller.py +122 -0
  24. continuum_task_server_bundle/discord/message_chunking.py +45 -0
  25. continuum_task_server_bundle/discord/methods.py +408 -0
  26. continuum_task_server_bundle/discord/plugin.py +105 -0
  27. continuum_task_server_bundle/discord/reaction_await_apply.py +238 -0
  28. continuum_task_server_bundle/discord/reaction_await_db.py +174 -0
  29. continuum_task_server_bundle/discord/reaction_await_inbound.py +47 -0
  30. continuum_task_server_bundle/discord/reaction_await_logic.py +118 -0
  31. continuum_task_server_bundle/discord/reaction_await_poller.py +131 -0
  32. continuum_task_server_bundle/discord/s3_attachment_config.py +25 -0
  33. continuum_task_server_bundle/discord/s3_message_attachments.py +139 -0
  34. continuum_task_server_bundle/discord/sql/001_message_awaits.sql +112 -0
  35. continuum_task_server_bundle/discord/sql/002_reaction_awaits.sql +61 -0
  36. continuum_task_server_bundle/github/__init__.py +4 -0
  37. continuum_task_server_bundle/github/awaits/__init__.py +1 -0
  38. continuum_task_server_bundle/github/awaits/apply.py +92 -0
  39. continuum_task_server_bundle/github/awaits/cleanup.py +94 -0
  40. continuum_task_server_bundle/github/awaits/db.py +220 -0
  41. continuum_task_server_bundle/github/awaits/evaluators.py +325 -0
  42. continuum_task_server_bundle/github/awaits/fetch.py +192 -0
  43. continuum_task_server_bundle/github/awaits/poller.py +82 -0
  44. continuum_task_server_bundle/github/awaits/register.py +37 -0
  45. continuum_task_server_bundle/github/ci_status.py +70 -0
  46. continuum_task_server_bundle/github/comment_normalize.py +76 -0
  47. continuum_task_server_bundle/github/errors.py +52 -0
  48. continuum_task_server_bundle/github/github_app.py +291 -0
  49. continuum_task_server_bundle/github/github_http.py +377 -0
  50. continuum_task_server_bundle/github/methods/__init__.py +90 -0
  51. continuum_task_server_bundle/github/methods/_common.py +183 -0
  52. continuum_task_server_bundle/github/methods/awaits.py +107 -0
  53. continuum_task_server_bundle/github/methods/ci.py +158 -0
  54. continuum_task_server_bundle/github/methods/comments.py +214 -0
  55. continuum_task_server_bundle/github/methods/credentials.py +59 -0
  56. continuum_task_server_bundle/github/methods/issues.py +131 -0
  57. continuum_task_server_bundle/github/methods/pulls.py +329 -0
  58. continuum_task_server_bundle/github/methods/repos.py +424 -0
  59. continuum_task_server_bundle/github/methods/search.py +109 -0
  60. continuum_task_server_bundle/github/plugin.py +91 -0
  61. continuum_task_server_bundle/github/sql/001_github_awaits.sql +65 -0
  62. continuum_task_server_bundle/github/webhook_server.py +126 -0
  63. continuum_task_server_bundle/jira/__init__.py +4 -0
  64. continuum_task_server_bundle/jira/await_poller.py +236 -0
  65. continuum_task_server_bundle/jira/await_store.py +271 -0
  66. continuum_task_server_bundle/jira/config.py +68 -0
  67. continuum_task_server_bundle/jira/jira_client.py +382 -0
  68. continuum_task_server_bundle/jira/methods.py +246 -0
  69. continuum_task_server_bundle/jira/plugin.py +86 -0
  70. continuum_task_server_bundle/jira/sql/001_jira_issue_comment_waits.sql +19 -0
  71. continuum_task_server_bundle/jira/webhook.py +70 -0
  72. continuum_task_server_bundle/openrouter/__init__.py +4 -0
  73. continuum_task_server_bundle/openrouter/chat_service.py +1037 -0
  74. continuum_task_server_bundle/openrouter/chat_store.py +849 -0
  75. continuum_task_server_bundle/openrouter/environment.py +29 -0
  76. continuum_task_server_bundle/openrouter/handler.py +59 -0
  77. continuum_task_server_bundle/openrouter/image_context.py +207 -0
  78. continuum_task_server_bundle/openrouter/openrouter_client.py +324 -0
  79. continuum_task_server_bundle/openrouter/plugin.py +37 -0
  80. continuum_task_server_bundle/openrouter/prompt_projection.py +417 -0
  81. continuum_task_server_bundle/openrouter/sql/chat.sql +50 -0
  82. continuum_task_server_bundle/openrouter/sql/migrate_prune_then_chunk_v1.sql +11 -0
  83. continuum_task_server_bundle/roblox/__init__.py +4 -0
  84. continuum_task_server_bundle/roblox/open_cloud.py +335 -0
  85. continuum_task_server_bundle/roblox/plugin.py +30 -0
  86. continuum_task_server_bundle/roblox/storage_s3.py +55 -0
  87. continuum_task_server_bundle-1.0.0.dist-info/METADATA +109 -0
  88. continuum_task_server_bundle-1.0.0.dist-info/RECORD +90 -0
  89. continuum_task_server_bundle-1.0.0.dist-info/WHEEL +5 -0
  90. continuum_task_server_bundle-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,54 @@
1
+ """Real-time path: merge messages from Discord gateway events (on_message)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import logging
7
+ from uuid import UUID
8
+
9
+ import discord
10
+ from continuum_task_server import TaskServer
11
+
12
+ import continuum_task_server_bundle.discord.message_await_db as db
13
+ import continuum_task_server_bundle.discord.message_await_logic as logic
14
+ from continuum_task_server_bundle.discord.message_await_apply import apply_new_discord_messages
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ async def handle_incoming_message_for_awaits(
20
+ server: TaskServer,
21
+ client: discord.Client,
22
+ message: discord.Message,
23
+ ) -> None:
24
+ """When a message arrives, update any active await on that channel/thread (Postgres is source of truth)."""
25
+ if not db.database_url():
26
+ return
27
+
28
+ rows = db.list_active_for_discord_channel(int(message.channel.id))
29
+ if not rows:
30
+ return
31
+
32
+ loop = asyncio.get_running_loop()
33
+ for row in rows:
34
+ if str(message.id) in logic.parse_ignore_message_ids(row):
35
+ continue
36
+ if int(message.id) <= logic.effective_after_snowflake(row):
37
+ continue
38
+ if (
39
+ logic.parse_ignore_own_bot_messages(row)
40
+ and client.user is not None
41
+ and message.author.id == client.user.id
42
+ ):
43
+ continue
44
+ row_id = UUID(str(row["id"]))
45
+ await loop.run_in_executor(
46
+ None,
47
+ lambda rid=row_id, cl=client: apply_new_discord_messages(
48
+ server,
49
+ rid,
50
+ [message],
51
+ heartbeat_after=True,
52
+ client=cl,
53
+ ),
54
+ )
@@ -0,0 +1,133 @@
1
+ """Shared rules for message_awaits (cutoff snowflake, merge, completion)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from datetime import datetime, timedelta, timezone
7
+ from typing import Any
8
+
9
+ import discord
10
+
11
+
12
+ def utc(dt: datetime) -> datetime:
13
+ if dt.tzinfo is None:
14
+ return dt.replace(tzinfo=timezone.utc)
15
+ return dt.astimezone(timezone.utc)
16
+
17
+
18
+ def effective_after_snowflake(row: dict[str, Any]) -> int:
19
+ parts: list[int] = []
20
+ lm = row.get("last_message_snowflake")
21
+ if lm is not None:
22
+ parts.append(int(lm))
23
+ am = row.get("after_message_id")
24
+ if am is not None:
25
+ parts.append(int(am))
26
+ if parts:
27
+ return max(parts)
28
+ reg = row["registered_at"]
29
+ return discord.utils.time_snowflake(utc(reg))
30
+
31
+
32
+ def parse_ignore_message_ids(row: dict[str, Any]) -> frozenset[str]:
33
+ """Snowflake ids (as str) to exclude from merge and inbound handling."""
34
+ raw = row.get("ignore_message_ids")
35
+ if raw is None:
36
+ return frozenset()
37
+ if isinstance(raw, str):
38
+ try:
39
+ raw = json.loads(raw)
40
+ except (json.JSONDecodeError, TypeError):
41
+ return frozenset()
42
+ if not isinstance(raw, list):
43
+ return frozenset()
44
+ out: list[str] = []
45
+ for x in raw[:10]:
46
+ if x is None:
47
+ continue
48
+ try:
49
+ out.append(str(int(str(x))))
50
+ except (TypeError, ValueError):
51
+ continue
52
+ return frozenset(out)
53
+
54
+
55
+ def parse_ignore_own_bot_messages(row: dict[str, Any]) -> bool:
56
+ """When True, exclude messages authored by the logged-in bot user."""
57
+ v = row.get("ignore_own_bot_messages")
58
+ if v is None:
59
+ return True
60
+ return bool(v)
61
+
62
+
63
+ def merge_messages(
64
+ existing: list[dict[str, Any]],
65
+ new: list[discord.Message],
66
+ *,
67
+ message_limit: int,
68
+ message_to_dict,
69
+ ignore_ids: frozenset[str] | None = None,
70
+ ignore_own_bot: bool = False,
71
+ bot_user_id: int | None = None,
72
+ ) -> list[dict[str, Any]]:
73
+ skip = ignore_ids or frozenset()
74
+ by_id: dict[str, dict[str, Any]] = {}
75
+ for m in existing:
76
+ sid = str(m["id"])
77
+ if sid in skip:
78
+ continue
79
+ if ignore_own_bot and bot_user_id is not None:
80
+ try:
81
+ if int(m.get("author_id", 0)) == bot_user_id:
82
+ continue
83
+ except (TypeError, ValueError):
84
+ pass
85
+ by_id[sid] = m
86
+ for m in new:
87
+ sid = str(m.id)
88
+ if sid in skip:
89
+ continue
90
+ if ignore_own_bot and bot_user_id is not None and m.author.id == bot_user_id:
91
+ continue
92
+ d = message_to_dict(m)
93
+ by_id[sid] = d
94
+ merged = sorted(by_id.values(), key=lambda x: int(x["id"]))
95
+ return merged[:message_limit]
96
+
97
+
98
+ def last_message_time(messages: list[dict[str, Any]]) -> datetime | None:
99
+ if not messages:
100
+ return None
101
+ last = max(messages, key=lambda x: int(x["id"]))
102
+ raw = last.get("created_at")
103
+ if not raw:
104
+ return None
105
+ return datetime.fromisoformat(raw)
106
+
107
+
108
+ def last_message_snowflake(messages: list[dict[str, Any]]) -> int | None:
109
+ if not messages:
110
+ return None
111
+ return int(max(int(m["id"]) for m in messages))
112
+
113
+
114
+ def completion_decision(
115
+ *,
116
+ merged: list[dict[str, Any]],
117
+ deadline_at: datetime,
118
+ quiet_period_seconds: float,
119
+ now: datetime,
120
+ ) -> tuple[bool, bool]:
121
+ """Return (should_complete, timed_out)."""
122
+ deadline = utc(deadline_at)
123
+ quiet_sec = float(quiet_period_seconds)
124
+ last_at = last_message_time(merged)
125
+
126
+ timed_out = now >= deadline
127
+ quiet_ok = (
128
+ bool(merged)
129
+ and last_at is not None
130
+ and (now >= last_at + timedelta(seconds=quiet_sec))
131
+ )
132
+ should_complete = timed_out or quiet_ok
133
+ return should_complete, timed_out
@@ -0,0 +1,122 @@
1
+ """Background polling for Postgres-backed await_messages (reconcile + heartbeat)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ import threading
7
+ from typing import Any
8
+ from uuid import UUID
9
+
10
+ import discord
11
+ from continuum_task_server import TaskServer
12
+ from continuum_task_server.exceptions import ContinuumError
13
+
14
+ import continuum_task_server_bundle.discord.message_await_db as db
15
+ import continuum_task_server_bundle.discord.message_await_logic as logic
16
+ from continuum_task_server_bundle.discord.await_cleanup import heartbeat_claim_or_drop
17
+ from continuum_task_server_bundle.discord.discord_ready import discord_usable
18
+ from continuum_task_server_bundle.discord.message_await_apply import apply_new_discord_messages
19
+ from continuum_task_server_bundle.discord.reaction_await_poller import poll_reaction_awaits_tick
20
+ from continuum_task_server_bundle.discord.methods import (
21
+ get_message_container_by_ids,
22
+ _await_on_discord_client,
23
+ _fetch_history_after,
24
+ )
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ def _fail_row(
30
+ server: TaskServer,
31
+ row_id: UUID,
32
+ _queue_item_id: UUID,
33
+ message: str,
34
+ *,
35
+ type_name: str = "RuntimeError",
36
+ ) -> None:
37
+ err = {"error": message, "type": type_name}
38
+ updated = db.mark_failed(row_id=row_id, error=err)
39
+ if updated is None:
40
+ return
41
+ try:
42
+ server.fail_queue_item(updated, error=err)
43
+ except ContinuumError as e:
44
+ logger.error("fail_queue_item failed for %s: %s", updated, e)
45
+
46
+
47
+ def _process_row(server: TaskServer, client: discord.Client, row: dict[str, Any]) -> None:
48
+ row_id = UUID(str(row["id"]))
49
+ qid = row["queue_item_id"]
50
+ if isinstance(qid, str):
51
+ qid = UUID(qid)
52
+
53
+ if not heartbeat_claim_or_drop(server, qid):
54
+ return
55
+
56
+ try:
57
+ container = get_message_container_by_ids(
58
+ client,
59
+ int(row["channel_id"]),
60
+ int(row["thread_id"]) if row.get("thread_id") is not None else None,
61
+ )
62
+ except RuntimeError as e:
63
+ _fail_row(server, row_id, qid, str(e))
64
+ return
65
+
66
+ accumulated = db.parse_messages_json(row.get("messages_json"))
67
+ msg_limit = int(row["message_limit"])
68
+ remaining = max(1, min(100, msg_limit - len(accumulated)))
69
+ after_id = logic.effective_after_snowflake(row)
70
+
71
+ try:
72
+ new_messages = _await_on_discord_client(
73
+ client,
74
+ _fetch_history_after(container, after_id=after_id, limit=remaining),
75
+ timeout=60.0,
76
+ )
77
+ except Exception as e:
78
+ logger.exception("Discord history fetch failed for row %s", row_id)
79
+ _fail_row(server, row_id, qid, str(e), type_name=type(e).__name__)
80
+ return
81
+
82
+ apply_new_discord_messages(
83
+ server,
84
+ row_id,
85
+ new_messages,
86
+ heartbeat_after=False,
87
+ client=client,
88
+ )
89
+
90
+
91
+ def poll_message_awaits_tick(server: TaskServer, client: discord.Client) -> None:
92
+ if not db.database_url():
93
+ return
94
+ if not discord_usable(client):
95
+ return
96
+ try:
97
+ rows = db.claim_due_awaits(limit=15)
98
+ except Exception:
99
+ logger.exception("claim_due_awaits failed")
100
+ return
101
+
102
+ for row in rows:
103
+ try:
104
+ _process_row(server, client, row)
105
+ except Exception:
106
+ logger.exception("process message_await row %s failed", row.get("id"))
107
+
108
+ try:
109
+ poll_reaction_awaits_tick(server, client)
110
+ except Exception:
111
+ logger.exception("poll_reaction_awaits_tick failed")
112
+
113
+
114
+ def run_message_await_poller(
115
+ server: TaskServer,
116
+ client: discord.Client,
117
+ *,
118
+ stop_event: threading.Event,
119
+ idle_seconds: float = 0.25,
120
+ ) -> None:
121
+ while not stop_event.wait(timeout=idle_seconds):
122
+ poll_message_awaits_tick(server, client)
@@ -0,0 +1,45 @@
1
+ """Utilities for splitting long Discord messages.
2
+
3
+ Discord rejects messages longer than 2000 characters. We use a slightly
4
+ lower threshold (1900) to leave headroom for any wrapping the caller may add.
5
+ """
6
+
7
+ DISCORD_MESSAGE_CHAR_LIMIT = 1900
8
+
9
+
10
+ def split_message_for_discord(
11
+ text: str, limit: int = DISCORD_MESSAGE_CHAR_LIMIT
12
+ ) -> list[str]:
13
+ """Split ``text`` into chunks no longer than ``limit`` characters.
14
+
15
+ Splits are preferred at newlines. If no newline exists within the limit
16
+ of the remaining text, the chunk is broken at the character boundary.
17
+
18
+ An empty input yields a single empty-string chunk so callers can still
19
+ issue a send (matching the previous behaviour of sending empty content).
20
+ """
21
+ if limit <= 0:
22
+ raise ValueError("limit must be positive")
23
+
24
+ if text == "":
25
+ return [""]
26
+
27
+ chunks: list[str] = []
28
+ remaining = text
29
+
30
+ while len(remaining) > limit:
31
+ window = remaining[:limit]
32
+ split_at = window.rfind("\n")
33
+
34
+ if split_at <= 0:
35
+ split_at = limit
36
+ chunk = remaining[:split_at]
37
+ remaining = remaining[split_at:]
38
+ else:
39
+ chunk = remaining[:split_at]
40
+ remaining = remaining[split_at + 1 :]
41
+
42
+ chunks.append(chunk)
43
+
44
+ chunks.append(remaining)
45
+ return chunks