Spaces:
Running
Running
File size: 6,302 Bytes
8e438ab e99df76 8e438ab 691dc7c 8e438ab 691dc7c 8e438ab 691dc7c 8e438ab 691dc7c 8e438ab 691dc7c 8e438ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | from __future__ import annotations
"""Persistence and native execution required by Code sessions."""
from collections.abc import Awaitable, Callable, Sequence
from typing import Protocol
from free_claude_code.application.session_events import EventSubscription
from free_claude_code.core.json_types import JsonObject
from .models import (
CodeCatalog,
CodeDetail,
CodeExecutionSeed,
CodeHistory,
CodeItem,
CodeItemPage,
CodeMode,
CodePage,
CodePrompt,
CodeRun,
CodeSession,
HarnessEvent,
NativeThread,
)
# Harness connections must await each call and preserve native wire order.
type EventSink = Callable[[HarnessEvent], Awaitable[None]]
class HarnessConnection(Protocol):
generation: str
thread_id: str | None
def supports(self, selection: HarnessSelection) -> bool: ...
async def create_thread(self) -> NativeThread: ...
async def resume_thread(self, thread_id: str) -> NativeThread: ...
async def read_thread(self, thread_id: str) -> NativeThread: ...
async def start_turn(
self,
text: str,
selection: HarnessSelection,
client_id: str,
permission_defaults: JsonObject,
) -> str: ...
async def interrupt(self, turn_id: str) -> None: ...
def prepare_answer(
self, request_id: str | int, answer: JsonObject
) -> JsonObject: ...
async def respond(self, request_id: str | int, response: JsonObject) -> None: ...
async def delete_thread(self, thread_id: str) -> None: ...
async def close(self) -> None: ...
class HarnessSelection(Protocol):
@property
def mode(self) -> CodeMode: ...
@property
def model(self) -> str: ...
@property
def reasoning_effort(self) -> str | None: ...
@property
def configuration_key(self) -> str: ...
async def open(self, cwd: str, sink: EventSink) -> HarnessConnection: ...
class HarnessFactory(Protocol):
def availability(self) -> tuple[bool, str | None]: ...
def catalog(self) -> CodeCatalog: ...
async def prepare(
self, model: str, reasoning_effort: str | None, mode: CodeMode
) -> HarnessSelection: ...
async def open_history(self, cwd: str, sink: EventSink) -> HarnessConnection: ...
class CodeStore(Protocol):
async def execution_seed(self, session_id: str) -> CodeExecutionSeed: ...
async def read_history(
self,
session_id: str,
before: tuple[int, int] | None,
include_item_ids: Sequence[str],
) -> CodeHistory: ...
async def get_native_item(
self,
session_id: str,
turn_id: str,
item_id: str,
) -> CodeItem | None: ...
async def run_items(self, session_id: str, run_id: str) -> tuple[CodeItem, ...]: ...
async def get_prompt(
self, session_id: str, prompt_id: str
) -> CodePrompt | None: ...
async def has_prompt_request(
self,
session_id: str,
generation: str,
request_id: str | int,
) -> bool: ...
async def has_native_turn(self, session_id: str, turn_id: str) -> bool: ...
async def start(self) -> None: ...
async def close(self) -> None: ...
async def create(self, session: CodeSession) -> CodeSession: ...
async def get_session(self, session_id: str) -> CodeSession: ...
async def list_sessions(
self, cursor: tuple[int, str] | None, limit: int, query: str = ""
) -> CodePage: ...
async def pending_deletions(self) -> tuple[CodeSession, ...]: ...
async def is_deleted(self, session_id: str) -> bool: ...
async def get_run(self, session_id: str, run_id: str) -> CodeRun | None: ...
async def runs(self, session_id: str) -> tuple[CodeRun, ...]: ...
async def latest_run(self, session_id: str) -> CodeRun | None: ...
async def items(
self, session_id: str, before: tuple[int, int] | None, limit: int | None
) -> tuple[CodeItem, ...]: ...
async def prompts(self, session_id: str) -> tuple[CodePrompt, ...]: ...
async def item_page(
self, session_id: str, before: tuple[int, int] | None, limit: int | None
) -> CodeItemPage: ...
async def update_settings(
self, session: CodeSession, expected_revision: int
) -> CodeSession: ...
async def admit_run(
self, session: CodeSession, run: CodeRun, item: CodeItem, expected_revision: int
) -> tuple[CodeSession, CodeRun]: ...
async def claim_prompt(
self, session_id: str, prompt_id: str, response_id: str, generation: str
) -> CodePrompt: ...
async def save_progress(
self,
session: CodeSession,
expected_revision: int,
*,
run: CodeRun | None = None,
items: Sequence[CodeItem] = (),
prompts: Sequence[CodePrompt] = (),
) -> None: ...
async def delete(self, session_id: str) -> None: ...
class CodeApplicationPort(Protocol):
@property
def epoch(self) -> str: ...
@property
def cursor(self) -> int: ...
def storage_status(self) -> JsonObject: ...
def availability(self) -> tuple[bool, str | None]: ...
def catalog(self) -> CodeCatalog: ...
async def create_session(self, session_id: str, cwd: str) -> CodeSession: ...
async def list_sessions(
self, cursor: tuple[int, str] | None = None, limit: int = 25, query: str = ""
) -> CodePage: ...
async def get_detail(
self,
session_id: str,
*,
before: tuple[int, int] | None = None,
include_item_ids: Sequence[str] = (),
) -> CodeDetail: ...
async def subscribe(self) -> tuple[EventSubscription, JsonObject]: ...
async def update_settings(
self, session_id: str, revision: int, changes: JsonObject
) -> CodeSession: ...
async def send(
self,
session_id: str,
operation_id: str,
revision: int,
text: str,
*,
expected_epoch: str,
) -> CodeRun: ...
async def stop(self, session_id: str, operation_id: str) -> CodeRun: ...
async def answer(
self, session_id: str, prompt_id: str, response_id: str, answer: JsonObject
) -> CodePrompt: ...
async def delete_session(
self, session_id: str, revision: int
) -> CodeSession | None: ...
|