Files
Javier Martinez 21d42fd97a feat: code execution v4 (#2295)
* feat: add bundle to remove

* fix: spaces

* feat: add xml render as skill spec

* feat: add skill volume root to cache

* fix: deduplicate values

* fix: change the mount path to skill_id

* fix: use different paths

* feat: add principal

(cherry picked from commit 5db64fe721d5706440ce9f342b1388ffe742bc16)

# Conflicts:
#	private_gpt/components/code_execution/base.py
#	private_gpt/components/code_execution/code_execution_component.py
#	private_gpt/components/code_execution/local.py
#	private_gpt/components/environment/manager.py
#	private_gpt/components/tools/builders/bash_tool_builder.py
#	private_gpt/components/tools/builders/text_editor_tool_builder.py
#	private_gpt/components/tools/processors/bash_processor.py

* fix: mypy

...

* fix: config

* fix: sandbox config

* feat: add forward cookies

* fix: loop

* feat: add present server

* feat: add feature flag for tools

* refactor: move principal to another better place

* feat: add api key principal

* docs: fix docs

* docs: add present server

* fix: principal

* fix: mypy

* fix: avoid to block the loop

* fix: blocks in expansion

* fix: remove maximum concurrent users

...

* fix: multiplexer

* fix: readers

* fix: more fixes

...

* fix: impl

* feat: tool scheduler

* feat: add adaptative

* feat: add chat worker

* fix: config

* fix: max

* feat: add chat/tools workers

* fix: mypy

* feat: add generic scheduler

* fix: get result

* feat: do serializable the tool executor

* fix: tools

* fix: config

* fix: config

* fix: args

* fix: config

* fix: serializer

* Revert "fix: blocks in expansion"

This reverts commit a2110f94a8.

* fix: unify all logic

* feat: add ingestion scheduler

* fix: settings

* fix: config

* feat: add arq worker to chat

* fix: arq worker

* fix: add nest

* fix: mypy

* fix: await

* fix: script stress

* fix: tokenizer

* fix: chat scheduler

* fix: mypy

* fix: add async tokenizer

* fix: improve condense

* fix: tool scheduler

* feat: add initial real async chat worker

* fix: mypy

* fix: do resumable local executor

...

...

...

fix: revert usleess changes

fix: remove parent chat job

fix: refactor

fix: loop

ref: rename models

fix: chat engine

fix: mypy

...

...

...

fix: fix deps

* fix: tests

* fix: tests

* ...

* fix: stream

* fix: config

* fix: scheduler

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Handle PGPT_WORKER_MODE=celery in health check worker status

* fix: cancel

* fix: arch

* fix: test ingestion

* fix: deserialization of chat messages

* fix: broken results

* fix: mypy

* fix: test

* fix: config

* fix: remove arq tool worker

* fix: output cls

* fix: preserve early resumable tool callbacks

* fix: preserve async tool result order

* refactor: address worker PR review comments

* fix: mypy

* test: colocate ARQ chat enqueue coverage

* fix: remove redis from tests

* fix: mypy

* fix: tests

* test: isolate chat mocks and cancellation timing

* fix: tests

* fix: tests

* fix: test

(cherry picked from commit f8ee460af2)

* fix: worker config

* test: remove flaky chat cancellation assertion

(cherry picked from commit 1115ff2349)

# Conflicts:
#	tests/server/chat/test_chat_routes.py

* fix: emit chat pings from stream listeners

* fix: don't duplciate the output

* fix: rss memory

...

* fix: pass the args

* fix: threads

* fix: websearch

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-15 13:05:23 +02:00

118 lines
4.0 KiB
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from private_gpt.components.environment.layout import DEFAULT_SESSION_LAYOUT
from private_gpt.components.sandbox.mount import SandboxMountSpec, VolumeSpec
if TYPE_CHECKING:
from collections.abc import Sequence
from pathlib import Path
from private_gpt.components.environment.layout import SessionMountDef
class LayoutMounter(ABC):
"""Owns the session filesystem layout — workspace, uploads, outputs.
Responsible only for structural concerns: which canonical paths make up
the session's persistent directory tree and how they are backed on the
host. Bundle content (skills, tools, ...) is a separate concern handled
by ContentMounter implementations.
"""
def __init__(
self, layout: Sequence[SessionMountDef] = DEFAULT_SESSION_LAYOUT
) -> None:
self._layout = tuple(layout)
@property
def layout(self) -> tuple[SessionMountDef, ...]:
return self._layout
@property
def workspace_canonical(self) -> str:
"""Canonical working directory: the first writable layout entry."""
return next(m.canonical for m in self._layout if m.writable)
def ensure_ready(self) -> None: # noqa: B027 — optional hook, default no-op
"""One-time idempotent setup of backing storage (e.g. mount s3fs)."""
@abstractmethod
def session_volumes(self, session_id: str) -> list[VolumeSpec] | None:
"""Host volumes backing this session's layout dirs, or None if not host-backed.
Only covers the fixed session layout (workspace, uploads, outputs).
Bundle/skill volumes are declared by ContentMounter.prepare_volume().
Implementations create the host directories they return. Idempotent.
"""
def mount_specs(self) -> list[SandboxMountSpec]:
"""Canonical mount specs for the session layout (writability enforcement).
Bundle specs are added separately by the EnvironmentManager so this
class stays unaware of content.
"""
return [
SandboxMountSpec(canonical=m.canonical, writable=m.writable)
for m in self._layout
]
# Backward-compatible alias so existing imports of `Mounter` keep working.
Mounter = LayoutMounter
class SandboxDirMounter(LayoutMounter):
"""No host backing — layout dirs are created inside the sandbox itself.
Files live and die with the sandbox. Suitable for development or
ephemeral use where persistence is not required.
"""
def session_volumes(self, session_id: str) -> list[VolumeSpec] | None:
return None
class LocalDirMounter(LayoutMounter):
"""Host-directory backing under a local base path.
Layout dirs live under ``{base}/{name}/{session_id}`` so that each folder
type sits at a top-level prefix — enabling per-folder MinIO lifecycle rules.
Bundle content is handled by LocalStorageContentMounter or
FetchContentMounter, not here.
"""
def __init__(
self,
base: Path,
layout: Sequence[SessionMountDef] = DEFAULT_SESSION_LAYOUT,
) -> None:
super().__init__(layout)
self._base = base
def ensure_ready(self) -> None:
self._base.mkdir(parents=True, exist_ok=True)
def uploads_path(self, session_id: str) -> Path:
return self._base / "uploads" / session_id
def outputs_path(self, session_id: str) -> Path:
return self._base / "outputs" / session_id
def session_volumes(self, session_id: str) -> list[VolumeSpec] | None:
volumes: list[VolumeSpec] = []
for mount in self._layout:
host = self._base / mount.name / session_id
host.mkdir(parents=True, exist_ok=True)
volumes.append(
VolumeSpec(
name=mount.name,
host_path=host,
mount_path=mount.canonical,
read_only=not mount.writable,
)
)
return volumes