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

Function generateRpc

scripts/codegen/go.ts:3777–4004  ·  view source on GitHub ↗
(schemaPath?: string)

Source from the content-addressed store, hash-verified

3775// ── RPC Types ───────────────────────────────────────────────────────────────
3776
3777async function generateRpc(schemaPath?: string): Promise<void> {
3778 console.log("Go: generating RPC types...");
3779
3780 const resolvedPath = schemaPath ?? (await getApiSchemaPath());
3781 const schema = propagateInternalVisibility(fixNullableRequiredRefsInApiSchema(cloneSchemaForCodegen((await loadSchemaJson(resolvedPath)) as ApiSchema)) as JSONSchema7) as unknown as ApiSchema;
3782
3783 const allMethods = [
3784 ...collectRpcMethods(schema.server || {}),
3785 ...collectRpcMethods(schema.session || {}),
3786 ...collectRpcMethods(schema.clientSession || {}),
3787 ...collectRpcMethods(schema.clientGlobal || {}),
3788 ].sort((left, right) => left.rpcMethod.localeCompare(right.rpcMethod));
3789
3790 // Build a combined definition map, including shared API definitions plus
3791 // method-specific request/result wrapper types.
3792 rpcDefinitions = collectDefinitionCollections(schema as Record<string, unknown>);
3793 const allDefinitions: Record<string, JSONSchema7> = {
3794 ...Object.fromEntries(
3795 Object.entries(rpcDefinitions.$defs ?? {}).filter(([, value]) => typeof value === "object" && value !== null)
3796 ) as Record<string, JSONSchema7>,
3797 ...Object.fromEntries(
3798 Object.entries(rpcDefinitions.definitions ?? {}).filter(([, value]) => typeof value === "object" && value !== null)
3799 ) as Record<string, JSONSchema7>,
3800 };
3801
3802 for (const method of allMethods) {
3803 const resultSchema = getMethodResultSchema(method);
3804 const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined;
3805 if (nullableInner) {
3806 // Nullable results (e.g., *SessionFSError) don't need a wrapper type;
3807 // the inner type is already in definitions via shared hoisting.
3808 } else if (isOpaqueJson(resultSchema)) {
3809 // Opaque JSON results map to `any` — no named struct needed.
3810 } else if (isVoidSchema(resultSchema)) {
3811 // Emit an empty struct for void results (forward-compatible with adding fields later)
3812 allDefinitions[goResultTypeName(method)] = {
3813 title: goResultTypeName(method),
3814 type: "object",
3815 properties: {},
3816 additionalProperties: false,
3817 };
3818 } else if (method.result) {
3819 allDefinitions[goResultTypeName(method)] = withRootTitle(
3820 schemaSourceForNamedDefinition(method.result, resultSchema),
3821 goResultTypeName(method)
3822 );
3823 }
3824 const resolvedParams = getMethodParamsSchema(method);
3825 if (method.params && hasSchemaPayload(resolvedParams)) {
3826 // For session methods, filter out sessionId from params type
3827 if (method.rpcMethod.startsWith("session.") && resolvedParams?.properties) {
3828 const filtered: JSONSchema7 = {
3829 ...resolvedParams,
3830 properties: Object.fromEntries(
3831 Object.entries(resolvedParams.properties).filter(([k]) => k !== "sessionId")
3832 ),
3833 required: resolvedParams.required?.filter((r) => r !== "sessionId"),
3834 };

Callers 1

generateFunction · 0.70

Calls 15

cloneSchemaForCodegenFunction · 0.85
loadSchemaJsonFunction · 0.85
getNullableInnerFunction · 0.85
isOpaqueJsonFunction · 0.85
isVoidSchemaFunction · 0.85
goResultTypeNameFunction · 0.85
hasSchemaPayloadFunction · 0.85
goParamsTypeNameFunction · 0.85
generateGoRpcTypeCodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…