MCPcopy Index your code
hub / github.com/github/copilot-sdk / emitRpcWrapper

Function emitRpcWrapper

scripts/codegen/python.ts:3430–3476  ·  view source on GitHub ↗
(lines: string[], node: Record<string, unknown>, isSession: boolean, resolveType: (name: string) => string, classPrefix: string = "")

Source from the content-addressed store, hash-verified

3428}
3429
3430function emitRpcWrapper(lines: string[], node: Record<string, unknown>, isSession: boolean, resolveType: (name: string) => string, classPrefix: string = ""): void {
3431 const groups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v));
3432 const topLevelMethods = Object.entries(node).filter(([, v]) => isRpcMethod(v));
3433
3434 const wrapperName = classPrefix + (isSession ? "SessionRpc" : "ServerRpc");
3435
3436 // Emit API classes for groups (recursively handles sub-groups)
3437 for (const [groupName, groupNode] of groups) {
3438 const prefix = classPrefix + (isSession ? "" : "Server");
3439 const apiName = prefix + toPascalCase(groupName) + "Api";
3440 const groupExperimental = isNodeFullyExperimental(groupNode as Record<string, unknown>);
3441 const groupDeprecated = isNodeFullyDeprecated(groupNode as Record<string, unknown>);
3442 emitPyApiGroup(lines, apiName, groupNode as Record<string, unknown>, isSession, resolveType, groupExperimental, groupDeprecated, classPrefix);
3443 }
3444
3445 // Emit wrapper class
3446 if (isSession) {
3447 lines.push(`class ${wrapperName}:`);
3448 lines.push(classPrefix === "_Internal"
3449 ? ` """Internal SDK session-scoped RPC methods. Not part of the public API."""`
3450 : ` """Typed session-scoped RPC methods."""`);
3451 lines.push(` def __init__(self, client: "JsonRpcClient", session_id: str):`);
3452 lines.push(` self._client = client`);
3453 lines.push(` self._session_id = session_id`);
3454 for (const [groupName] of groups) {
3455 lines.push(` self.${toSnakeCase(groupName)} = ${classPrefix}${toPascalCase(groupName)}Api(client, session_id)`);
3456 }
3457 } else {
3458 lines.push(`class ${wrapperName}:`);
3459 lines.push(classPrefix === "_Internal"
3460 ? ` """Internal SDK server-scoped RPC methods. Not part of the public API."""`
3461 : ` """Typed server-scoped RPC methods."""`);
3462 lines.push(` def __init__(self, client: "JsonRpcClient"):`);
3463 lines.push(` self._client = client`);
3464 for (const [groupName] of groups) {
3465 lines.push(` self.${toSnakeCase(groupName)} = ${classPrefix}Server${toPascalCase(groupName)}Api(client)`);
3466 }
3467 }
3468 lines.push(``);
3469
3470 // Top-level methods
3471 for (const [key, value] of topLevelMethods) {
3472 if (!isRpcMethod(value)) continue;
3473 emitMethod(lines, key, value, isSession, resolveType, false);
3474 }
3475 lines.push(``);
3476}
3477
3478function emitMethod(lines: string[], name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, groupExperimental = false, groupDeprecated = false): void {
3479 const isInternal = method.visibility === "internal";

Callers 1

generateRpcFunction · 0.70

Calls 8

isNodeFullyExperimentalFunction · 0.85
isNodeFullyDeprecatedFunction · 0.85
emitPyApiGroupFunction · 0.85
isRpcMethodFunction · 0.70
toPascalCaseFunction · 0.70
toSnakeCaseFunction · 0.70
emitMethodFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…