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

Function emitClientSessionRegistrationMethod

scripts/codegen/python.ts:3675–3716  ·  view source on GitHub ↗
(
    lines: string[],
    groupName: string,
    method: RpcMethod,
    resolveType: (name: string) => string
)

Source from the content-addressed store, hash-verified

3673}
3674
3675function emitClientSessionRegistrationMethod(
3676 lines: string[],
3677 groupName: string,
3678 method: RpcMethod,
3679 resolveType: (name: string) => string
3680): void {
3681 const rpcSegments = method.rpcMethod.split(".");
3682 const handlerVariableName = `handle_${rpcSegments.map(toSnakeCase).join("_")}`;
3683 const paramsType = resolveType(pythonParamsTypeName(method));
3684 const resultSchema = getMethodResultSchema(method);
3685 const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined;
3686 const hasResult = !isVoidSchema(resultSchema) && !nullableInner;
3687 const handlerField = toSnakeCase(groupName);
3688 const handlerMethod = clientSessionHandlerMethodName(method.rpcMethod);
3689
3690 lines.push(` async def ${handlerVariableName}(params: dict) -> dict | None:`);
3691 lines.push(` request = ${paramsType}.from_dict(params)`);
3692 lines.push(` handler = get_handlers(request.session_id).${handlerField}`);
3693 lines.push(
3694 ` if handler is None: raise RuntimeError(f"No ${handlerField} handler registered for session: {request.session_id}")`
3695 );
3696 if (hasResult) {
3697 lines.push(` result = await handler.${handlerMethod}(request)`);
3698 if (isObjectSchema(resultSchema)) {
3699 lines.push(` return result.to_dict()`);
3700 } else {
3701 lines.push(` return result.value if hasattr(result, 'value') else result`);
3702 }
3703 } else if (nullableInner) {
3704 lines.push(` result = await handler.${handlerMethod}(request)`);
3705 const resolvedInner = resolveSchema(nullableInner, rpcDefinitions) ?? nullableInner;
3706 if (isObjectSchema(resolvedInner) || nullableInner.$ref) {
3707 lines.push(` return result.to_dict() if result is not None else None`);
3708 } else {
3709 lines.push(` return result`);
3710 }
3711 } else {
3712 lines.push(` await handler.${handlerMethod}(request)`);
3713 lines.push(` return None`);
3714 }
3715 lines.push(` client.set_request_handler("${method.rpcMethod}", ${handlerVariableName})`);
3716}
3717
3718function emitClientGlobalApiRegistration(
3719 lines: string[],

Callers 1

Calls 11

pythonParamsTypeNameFunction · 0.85
getNullableInnerFunction · 0.85
isVoidSchemaFunction · 0.85
isObjectSchemaFunction · 0.85
resolveSchemaFunction · 0.85
joinMethod · 0.80
resolveTypeFunction · 0.70
getMethodResultSchemaFunction · 0.70
toSnakeCaseFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…