Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
from agent_framework.observability import AgentTelemetryLayer

try:
from copilot import CopilotClient, CopilotSession, SubprocessConfig
from copilot.generated.session_events import PermissionRequest, SessionEvent, SessionEventType
from copilot import CopilotClient, CopilotSession, RuntimeConnection
from copilot.generated.rpc import PermissionDecisionUserNotAvailable
from copilot.session import MCPServerConfig, PermissionRequestResult, ProviderConfig, SystemMessageConfig
from copilot.session_events import PermissionRequest, SessionEvent, SessionEventType
from copilot.tools import Tool as CopilotTool
Comment thread
giles17 marked this conversation as resolved.
from copilot.tools import ToolInvocation, ToolResult
except ImportError as _copilot_import_error:
Expand All @@ -57,8 +58,10 @@
DEFAULT_TIMEOUT_SECONDS: float = 60.0
"""Default timeout in seconds for Copilot requests."""

PermissionHandlerType = Callable[[PermissionRequest, dict[str, str]], PermissionRequestResult]
"""Type for permission request handlers."""
PermissionHandlerType = Callable[
[PermissionRequest, dict[str, str]], "PermissionRequestResult | Awaitable[PermissionRequestResult]"
]
"""Type for permission request handlers. Supports both sync and async callbacks."""


FunctionApprovalCallback = Callable[[Content], "bool | Awaitable[bool]"]
Expand Down Expand Up @@ -121,7 +124,7 @@ def _deny_all_permissions(
_invocation: dict[str, str],
) -> PermissionRequestResult:
"""Default permission handler that denies all requests."""
return PermissionRequestResult()
return PermissionDecisionUserNotAvailable()


class GitHubCopilotSettings(TypedDict, total=False):
Expand All @@ -140,9 +143,9 @@ class GitHubCopilotSettings(TypedDict, total=False):
Can be set via environment variable GITHUB_COPILOT_TIMEOUT.
log_level: CLI log level.
Can be set via environment variable GITHUB_COPILOT_LOG_LEVEL.
copilot_home: Directory where the CLI stores session state, configuration,
base_directory: Directory where the CLI stores session state, configuration,
and other persistent data. Can be set via environment variable
GITHUB_COPILOT_COPILOT_HOME. Defaults to ~/.copilot when not set.
GITHUB_COPILOT_BASE_DIRECTORY. Defaults to ~/.copilot when not set.
Only applicable when the SDK spawns the CLI process (ignored when
connecting to an external server via a pre-configured client).
"""
Expand All @@ -151,7 +154,7 @@ class GitHubCopilotSettings(TypedDict, total=False):
model: str | None
timeout: float | None
log_level: str | None
copilot_home: str | None
base_directory: str | None


class GitHubCopilotOptions(TypedDict, total=False):
Expand Down Expand Up @@ -314,7 +317,7 @@ def __init__(
provider: ProviderConfig | None = opts.pop("provider", None)
instruction_directories: list[str] | None = opts.pop("instruction_directories", None)
on_function_approval: FunctionApprovalCallback | None = opts.pop("on_function_approval", None)
copilot_home = opts.pop("copilot_home", None)
base_directory = opts.pop("base_directory", None)

self._settings = load_settings(
GitHubCopilotSettings,
Expand All @@ -323,7 +326,7 @@ def __init__(
model=model,
timeout=timeout,
log_level=log_level,
copilot_home=copilot_home,
base_directory=base_directory,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
Expand Down Expand Up @@ -362,14 +365,16 @@ async def start(self) -> None:
if self._client is None:
cli_path = self._settings.get("cli_path") or None
log_level = self._settings.get("log_level") or None
copilot_home = self._settings.get("copilot_home") or None
base_directory = self._settings.get("base_directory") or None

subprocess_kwargs: dict[str, Any] = {"cli_path": cli_path}
client_kwargs: dict[str, Any] = {}
if cli_path:
client_kwargs["connection"] = RuntimeConnection.for_stdio(path=cli_path)
if log_level:
subprocess_kwargs["log_level"] = log_level
if copilot_home:
subprocess_kwargs["copilot_home"] = copilot_home
self._client = CopilotClient(SubprocessConfig(**subprocess_kwargs))
client_kwargs["log_level"] = log_level
if base_directory:
client_kwargs["base_directory"] = base_directory
self._client = CopilotClient(**client_kwargs)

try:
await self._client.start()
Expand Down
2 changes: 1 addition & 1 deletion python/packages/github_copilot/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
]
dependencies = [
"agent-framework-core>=1.6.0,<2",
"github-copilot-sdk>=1.0.0b2,<=1.0.0b2; python_version >= '3.11'",
"github-copilot-sdk>=1.0.0,<2; python_version >= '3.11'",
]

[tool.uv]
Expand Down
Loading
Loading