Skip to content

Commit 7a8861a

Browse files
Python/Go better representation of internal in codegen output
1 parent 5b23c6a commit 7a8861a

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

go/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ type Client struct {
120120
// RPC provides typed server-scoped RPC methods.
121121
// This field is nil until the client is connected via Start().
122122
RPC *rpc.ServerRpc
123+
124+
// internalRPC provides SDK-internal RPC methods (handshake helpers etc.).
125+
// Lowercase = not exported; external callers cannot reach it.
126+
internalRPC *rpc.InternalServerRpc
123127
}
124128

125129
// NewClient creates a new Copilot CLI client with the given options.
@@ -441,6 +445,7 @@ func (c *Client) Stop() error {
441445
}
442446

443447
c.RPC = nil
448+
c.internalRPC = nil
444449
return errors.Join(errs...)
445450
}
446451

@@ -512,6 +517,7 @@ func (c *Client) ForceStop() {
512517
}
513518

514519
c.RPC = nil
520+
c.internalRPC = nil
515521
}
516522

517523
func (c *Client) ensureConnected(ctx context.Context) error {
@@ -1355,7 +1361,7 @@ func (c *Client) verifyProtocolVersion(ctx context.Context) error {
13551361
t := c.effectiveConnectionToken
13561362
tokenPtr = &t
13571363
}
1358-
connectResult, err := c.RPC.Connect(ctx, &rpc.ConnectRequest{Token: tokenPtr})
1364+
connectResult, err := c.internalRPC.Connect(ctx, &rpc.ConnectRequest{Token: tokenPtr})
13591365
if err != nil {
13601366
var rpcErr *jsonrpc2.Error
13611367
if errors.As(err, &rpcErr) && rpcErr.Code == jsonrpc2.ErrMethodNotFound.Code {
@@ -1514,6 +1520,7 @@ func (c *Client) startCLIServer(ctx context.Context) error {
15141520
}()
15151521
})
15161522
c.RPC = rpc.NewServerRpc(c.client)
1523+
c.internalRPC = rpc.NewInternalServerRpc(c.client)
15171524
c.setupNotificationHandler()
15181525
c.client.Start()
15191526

@@ -1639,6 +1646,7 @@ func (c *Client) connectViaTcp(ctx context.Context) error {
16391646
}()
16401647
})
16411648
c.RPC = rpc.NewServerRpc(c.client)
1649+
c.internalRPC = rpc.NewInternalServerRpc(c.client)
16421650
c.setupNotificationHandler()
16431651
c.client.Start()
16441652

python/copilot/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ClientSessionApiHandlers,
3737
ConnectRequest,
3838
ServerRpc,
39+
_InternalServerRpc,
3940
register_client_session_api_handlers,
4041
)
4142
from .generated.session_events import (
@@ -2181,7 +2182,7 @@ async def _verify_protocol_version(self) -> None:
21812182

21822183
server_version: int | None
21832184
try:
2184-
connect_result = await ServerRpc(self._client).connect(
2185+
connect_result = await _InternalServerRpc(self._client).connect(
21852186
ConnectRequest(token=self._effective_connection_token)
21862187
)
21872188
server_version = connect_result.protocol_version

python/copilot/generated/rpc.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/python.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,13 +1836,13 @@ def _patch_model_capabilities(data: dict) -> dict:
18361836
const publicNode = filterNodeByVisibility(schema.server, "public");
18371837
if (publicNode) emitRpcWrapper(lines, publicNode, false, resolveType, "");
18381838
const internalNode = filterNodeByVisibility(schema.server, "internal");
1839-
if (internalNode) emitRpcWrapper(lines, internalNode, false, resolveType, "Internal");
1839+
if (internalNode) emitRpcWrapper(lines, internalNode, false, resolveType, "_Internal");
18401840
}
18411841
if (schema.session) {
18421842
const publicNode = filterNodeByVisibility(schema.session, "public");
18431843
if (publicNode) emitRpcWrapper(lines, publicNode, true, resolveType, "");
18441844
const internalNode = filterNodeByVisibility(schema.session, "internal");
1845-
if (internalNode) emitRpcWrapper(lines, internalNode, true, resolveType, "Internal");
1845+
if (internalNode) emitRpcWrapper(lines, internalNode, true, resolveType, "_Internal");
18461846
}
18471847
if (schema.clientSession) {
18481848
emitClientSessionApiRegistration(lines, schema.clientSession, resolveType);
@@ -1937,7 +1937,7 @@ function emitRpcWrapper(lines: string[], node: Record<string, unknown>, isSessio
19371937
// Emit wrapper class
19381938
if (isSession) {
19391939
lines.push(`class ${wrapperName}:`);
1940-
lines.push(classPrefix === "Internal"
1940+
lines.push(classPrefix === "_Internal"
19411941
? ` """Internal SDK session-scoped RPC methods. Not part of the public API."""`
19421942
: ` """Typed session-scoped RPC methods."""`);
19431943
lines.push(` def __init__(self, client: "JsonRpcClient", session_id: str):`);
@@ -1949,7 +1949,7 @@ function emitRpcWrapper(lines: string[], node: Record<string, unknown>, isSessio
19491949
}
19501950
} else {
19511951
lines.push(`class ${wrapperName}:`);
1952-
lines.push(classPrefix === "Internal"
1952+
lines.push(classPrefix === "_Internal"
19531953
? ` """Internal SDK server-scoped RPC methods (handshake helpers etc.). Not part of the public API."""`
19541954
: ` """Typed server-scoped RPC methods."""`);
19551955
lines.push(` def __init__(self, client: "JsonRpcClient"):`);

0 commit comments

Comments
 (0)