mirror of
https://github.com/open-webui/computer.git
synced 2026-11-29 16:35:22 -05:00
refac
This commit is contained in:
1 parent
8de0fcee14
commit
a7bce2db5b
20 files changed
+239
-222
No files matched your search
@@ -100,7 +100,7 @@ async def scheduler_worker_loop(app) -> None:
|
||||
if batch:
|
||||
logger.info("Claimed %d due automation(s)", len(batch))
|
||||
for automation in batch:
|
||||
asyncio.create_task(execute_automation(automation))
|
||||
asyncio.create_task(execute_automation(app, automation))
|
||||
except Exception:
|
||||
logger.exception("Scheduler worker error")
|
||||
|
||||
@@ -112,7 +112,7 @@ async def scheduler_worker_loop(app) -> None:
|
||||
####################
|
||||
|
||||
|
||||
async def execute_automation(automation, webhook_payload: str | None = None) -> None:
|
||||
async def execute_automation(app, automation, webhook_payload: str | None = None) -> None:
|
||||
"""Execute an automation by creating a chat and calling start_task().
|
||||
|
||||
Creates a real chat + messages, then uses the same agentic loop
|
||||
@@ -124,10 +124,12 @@ async def execute_automation(automation, webhook_payload: str | None = None) ->
|
||||
from cptr.models import Chat, ChatMessage
|
||||
from cptr.models.automations import AutomationRun
|
||||
from cptr.utils.config import now_ms
|
||||
from cptr.utils.identity import internal_request_for_user
|
||||
from cptr.socket.main import emit_to_user
|
||||
|
||||
try:
|
||||
workspace = automation.workspace
|
||||
request = await internal_request_for_user(app, automation.user_id)
|
||||
model_id = automation.model_id
|
||||
prompt = automation.prompt
|
||||
|
||||
@@ -168,11 +170,10 @@ async def execute_automation(automation, webhook_payload: str | None = None) ->
|
||||
await Chat.update_current_message(chat.id, assistant_msg.id, now_ms())
|
||||
|
||||
marker = Path(workspace) / ".cptr" / "chats" / f"{chat.id}.json"
|
||||
from cptr.utils.identity import identity_for_user_id
|
||||
|
||||
from cptr.utils.runtime import Runtime
|
||||
|
||||
identity = await identity_for_user_id(automation.user_id)
|
||||
await Runtime.write_file(identity, str(marker), "{}")
|
||||
await Runtime.write_file(request, str(marker), "{}")
|
||||
|
||||
from cptr.utils.model_targets import resolve_model_target
|
||||
|
||||
@@ -182,7 +183,7 @@ async def execute_automation(automation, webhook_payload: str | None = None) ->
|
||||
from cptr.utils.chat_task import start_task
|
||||
|
||||
start_task(
|
||||
None,
|
||||
request,
|
||||
message_id=assistant_msg.id,
|
||||
chat_id=chat.id,
|
||||
user_id=automation.user_id,
|
||||
|
||||
Reference in new issue
Block a user