Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Formatting
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
SteveSandersonMS and Copilot committed Mar 20, 2026
commit f9eab61cc5fb018f1f21538326cacd7746fccd62
24 changes: 12 additions & 12 deletions go/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ type sessionHandler struct {
// })
type Session struct {
// SessionID is the unique identifier for this session.
SessionID string
workspacePath string
client *jsonrpc2.Client
handlers []sessionHandler
nextHandlerID uint64
handlerMutex sync.RWMutex
toolHandlers map[string]ToolHandler
toolHandlersM sync.RWMutex
permissionHandler PermissionHandlerFunc
permissionMux sync.RWMutex
userInputHandler UserInputHandler
userInputMux sync.RWMutex
SessionID string
workspacePath string
client *jsonrpc2.Client
handlers []sessionHandler
nextHandlerID uint64
handlerMutex sync.RWMutex
toolHandlers map[string]ToolHandler
toolHandlersM sync.RWMutex
permissionHandler PermissionHandlerFunc
permissionMux sync.RWMutex
userInputHandler UserInputHandler
userInputMux sync.RWMutex
hooks *SessionHooks
hooksMux sync.RWMutex
transformCallbacks map[string]SectionTransformFn
Expand Down
4 changes: 1 addition & 3 deletions nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ function toJsonSchema(parameters: Tool["parameters"]): Record<string, unknown> |
* Function-valued actions are replaced with `{ action: "transform" }` for serialization,
* and the original callbacks are returned in a separate map.
*/
function extractTransformCallbacks(
systemMessage: SessionConfig["systemMessage"]
): {
function extractTransformCallbacks(systemMessage: SessionConfig["systemMessage"]): {
wirePayload: SessionConfig["systemMessage"];
transformCallbacks: Map<string, SectionTransformFn> | undefined;
} {
Expand Down
7 changes: 6 additions & 1 deletion nodejs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ export type SectionTransformFn = (currentContent: string) => string | Promise<st
* - `"prepend"`: Prepend to existing section content
* - `function`: Transform callback — receives current section content, returns new content
*/
export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | SectionTransformFn;
export type SectionOverrideAction =
| "replace"
| "remove"
| "append"
| "prepend"
| SectionTransformFn;

/**
* Override operation for a single system prompt section.
Expand Down
10 changes: 4 additions & 6 deletions python/copilot/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ def on(self, handler: Callable[[SessionEvent], None]) -> Callable[[], None]:
... print(f"Assistant: {event.data.content}")
... elif event.type == "session.error":
... print(f"Error: {event.data.message}")
...
>>> unsubscribe = session.on(handle_event)
...
>>> # Later, to stop receiving events:
>>> unsubscribe()
"""
Expand Down Expand Up @@ -639,7 +637,9 @@ async def _handle_hooks_invoke(self, hook_type: str, input_data: Any) -> Any:
# Hook failed, return None
return None

def _register_transform_callbacks(self, callbacks: dict[str, SectionTransformFn] | None) -> None:
def _register_transform_callbacks(
self, callbacks: dict[str, SectionTransformFn] | None
) -> None:
"""
Register transform callbacks for system message sections.

Expand Down Expand Up @@ -787,9 +787,7 @@ async def abort(self) -> None:
>>> import asyncio
>>>
>>> # Start a long-running request
>>> task = asyncio.create_task(
... session.send("Write a very long story...")
... )
>>> task = asyncio.create_task(session.send("Write a very long story..."))
>>>
>>> # Abort after 5 seconds
>>> await asyncio.sleep(5)
Expand Down
4 changes: 1 addition & 3 deletions python/copilot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ class Tool:
SectionTransformFn = Callable[[str], str | Awaitable[str]]
"""Transform callback: receives current section content, returns new content."""

SectionOverrideAction = (
Literal["replace", "remove", "append", "prepend"] | SectionTransformFn
)
SectionOverrideAction = Literal["replace", "remove", "append", "prepend"] | SectionTransformFn
"""Override action: a string literal for static overrides, or a callback for transforms."""


Expand Down
4 changes: 1 addition & 3 deletions python/e2e/test_system_message_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ async def identity_transform(content: str) -> str:

write_file(ctx.work_dir, "combo.txt", "Combo test!")

await session.send_and_wait(
"Read the contents of combo.txt and tell me what it says"
)
await session.send_and_wait("Read the contents of combo.txt and tell me what it says")

# The transform callback should have been invoked
assert len(identity_contents) > 0
Expand Down
Loading