Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.3 KB
Raw Blame
from __future__ import annotations

from dataclasses import dataclass
from typing import Literal, Protocol


type ShellExecutionMode = Literal["pty", "stdio"]


@dataclass(frozen=True, slots=True)
class ShellCommandResult:
    job_id: str
    status: str
    done: bool
    exit_code: int | None
    output: str
    offset: int
    truncated: bool
    output_path: str | None = None


@dataclass(frozen=True, slots=True)
class ShellCommandStatus:
    job_id: str
    status: str
    done: bool
    exit_code: int | None
    offset: int


@dataclass(frozen=True, slots=True)
class CompleteShellCommandResult:
    job_id: str
    status: str
    done: bool
    exit_code: int | None
    output: str
    output_complete: bool
    incomplete_reason: Literal["output_limit", "timeout"] | None
    offset: int
    output_path: str | None = None


@dataclass(frozen=True, slots=True)
class ShellPromptObservation:
    text: str
    output_path: str | None
    offset: int


class ShellProviderError(RuntimeError):
    code: str | None
    status_code: int | None

    def __init__(self, message: str, *, code: str | None = None, status_code: int | None = None) -> None:
        super().__init__(message)
        self.code = code
        self.status_code = status_code


class ShellCommandProtocol(Protocol):
    async def run(
        self,
        script: str,
        *,
        cwd: str | None = None,
        env: dict[str, str] | None = None,
        timeout: float,
        mode: ShellExecutionMode = "pty",
    ) -> ShellCommandResult: ...

    async def wait(
        self,
        job_id: str,
        *,
        offset: int,
        timeout: float,
    ) -> ShellCommandResult: ...

    async def read_output(
        self,
        job_id: str,
        *,
        offset: int,
    ) -> ShellCommandResult: ...

    async def input(
        self,
        job_id: str,
        text: str,
        *,
        offset: int,
        timeout: float,
    ) -> ShellCommandResult: ...

    async def interrupt(
        self,
        job_id: str,
        *,
        grace_seconds: float,
    ) -> ShellCommandStatus: ...

    async def tail(self, job_id: str) -> ShellCommandResult: ...

    async def delete(
        self,
        job_id: str,
        *,
        force: bool = False,
        grace_seconds: float | None = None,
    ) -> None: ...