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

Function emitClientGlobalApiRegistration

scripts/codegen/typescript.ts:947–1034  ·  view source on GitHub ↗

* Generate handler interfaces and a registration function for client *global* * API groups. * * Unlike client-session APIs, these methods carry no implicit `sessionId` * dispatch key. The SDK consumer registers a single process-wide handler set * via `registerClientGlobalApiHandlers`; the runti

(clientSchema: Record<string, unknown>)

Source from the content-addressed store, hash-verified

945 * runtime session triggered it.
946 */
947function emitClientGlobalApiRegistration(clientSchema: Record<string, unknown>): string[] {
948 const lines: string[] = [];
949 const groups = collectClientGroups(clientSchema);
950
951 for (const [groupName, methods] of groups) {
952 const interfaceName = toPascalCase(groupName) + "Handler";
953 const groupDeprecated = isNodeFullyDeprecated(clientSchema[groupName] as Record<string, unknown>);
954 const groupExperimental = isNodeFullyExperimental(clientSchema[groupName] as Record<string, unknown>);
955 if (groupDeprecated) {
956 lines.push(`/** @deprecated Handler for \`${groupName}\` client global API methods. */`);
957 } else if (groupExperimental) {
958 lines.push(`/** Handler for \`${groupName}\` client global API methods. */`);
959 lines.push(TS_EXPERIMENTAL_JSDOC);
960 } else {
961 lines.push(`/** Handler for \`${groupName}\` client global API methods. */`);
962 }
963 lines.push(`export interface ${interfaceName} {`);
964 for (const method of methods) {
965 const name = handlerMethodName(method.rpcMethod);
966 const hasParams = hasSchemaPayload(getMethodParamsSchema(method));
967 const pType = hasParams ? paramsTypeName(method) : "";
968 const rType = tsResultType(method);
969
970 pushTsRpcMethodJsDoc(lines, " ", method, {
971 summaryFallback: `Handles \`${method.rpcMethod}\`.`,
972 paramsName: hasParams ? "params" : undefined,
973 paramsDescription: rpcParamsDescription(method, getMethodParamsSchema(method)),
974 includeDeprecated: method.deprecated && !groupDeprecated,
975 includeExperimental: method.stability === "experimental" && !groupExperimental,
976 });
977 if (hasParams) {
978 lines.push(` ${name}(params: ${pType}): Promise<${rType}>;`);
979 } else {
980 lines.push(` ${name}(): Promise<${rType}>;`);
981 }
982 }
983 lines.push(`}`);
984 lines.push("");
985 }
986
987 lines.push(`/** All client global API handler groups. */`);
988 lines.push(`export interface ClientGlobalApiHandlers {`);
989 for (const [groupName] of groups) {
990 const interfaceName = toPascalCase(groupName) + "Handler";
991 lines.push(` ${groupName}?: ${interfaceName};`);
992 }
993 lines.push(`}`);
994 lines.push("");
995
996 lines.push(`/**`);
997 lines.push(` * Register client global API handlers on a JSON-RPC connection.`);
998 lines.push(` * The server calls these methods to delegate work to the client.`);
999 lines.push(` * Unlike session-scoped client APIs, these methods carry no implicit`);
1000 lines.push(` * \`sessionId\` dispatch key — a single set of handlers serves the entire`);
1001 lines.push(` * connection.`);
1002 lines.push(` */`);
1003 lines.push(`export function registerClientGlobalApiHandlers(`);
1004 lines.push(` connection: MessageConnection,`);

Callers 1

generateRpcFunction · 0.70

Calls 12

isNodeFullyDeprecatedFunction · 0.85
isNodeFullyExperimentalFunction · 0.85
handlerMethodNameFunction · 0.85
hasSchemaPayloadFunction · 0.85
tsResultTypeFunction · 0.85
pushTsRpcMethodJsDocFunction · 0.85
collectClientGroupsFunction · 0.70
toPascalCaseFunction · 0.70
getMethodParamsSchemaFunction · 0.70
paramsTypeNameFunction · 0.70
rpcParamsDescriptionFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…