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

Function generateSessionEvents

scripts/codegen/go.ts:3677–3773  ·  view source on GitHub ↗
(schemaPath?: string, apiSchema?: ApiSchema)

Source from the content-addressed store, hash-verified

3675}
3676
3677async function generateSessionEvents(schemaPath?: string, apiSchema?: ApiSchema): Promise<void> {
3678 console.log("Go: generating session-events...");
3679
3680 const resolvedPath = schemaPath ?? (await getSessionEventsSchemaPath());
3681 const schema = cloneSchemaForCodegen((await loadSchemaJson(resolvedPath)) as JSONSchema7);
3682 const processed = propagateInternalVisibility(postProcessSchema(schema));
3683 const processedApiSchema = apiSchema
3684 ? propagateInternalVisibility(postProcessSchema(cloneSchemaForCodegen(apiSchema as JSONSchema7)) as JSONSchema7)
3685 : undefined;
3686 const sharedDefinitions = processedApiSchema
3687 ? findSharedSchemaDefinitions(
3688 processed as unknown as Record<string, unknown>,
3689 processedApiSchema as unknown as Record<string, unknown>
3690 )
3691 : new Set<string>();
3692 const reachableDefinitions = collectReachableDefinitionNames(processed as unknown as Record<string, unknown>);
3693 const sharedSessionEventDefinitions = new Set([...sharedDefinitions].filter((name) => reachableDefinitions.has(name)));
3694 const sessionSchema = rewriteSharedDefinitionReferences(processed, sharedDefinitions, "api.schema.json", true);
3695
3696 const generatedSessionCode = generateGoSessionEventsCode(
3697 sessionSchema,
3698 "rpc",
3699 processedApiSchema ? { "api.schema.json": processedApiSchema } : undefined
3700 );
3701 let generatedTypeCode = stripTrailingGoWhitespace(generatedSessionCode.typeCode);
3702 // Annotate internal session-event types (driven by the JSON Schema definition's
3703 // `visibility: "internal"` flag). Matches what the RPC generator does below;
3704 // the session-events emit path doesn't pass through that code so we apply it here.
3705 {
3706 const sessionDefs = collectDefinitionCollections(sessionSchema as Record<string, unknown>);
3707 const allSessionDefs = { ...sessionDefs.$defs, ...sessionDefs.definitions };
3708 const internalSessionTypeNames = new Set<string>();
3709 for (const [name, def] of Object.entries(allSessionDefs)) {
3710 if (def && typeof def === "object" && (def as Record<string, unknown>).visibility === "internal") {
3711 internalSessionTypeNames.add(name);
3712 }
3713 }
3714 for (const typeName of internalSessionTypeNames) {
3715 generatedTypeCode = generatedTypeCode.replace(
3716 new RegExp(`^(type ${typeName} struct)`, "m"),
3717 `// Internal: ${typeName} is an internal SDK API and is not part of the public surface.\n$1`
3718 );
3719 }
3720 }
3721 const generatedEncodingCode = stripTrailingGoWhitespace(generatedSessionCode.encodingCode);
3722 rpcSessionEventTopLevelNames = {
3723 types: new Set(collectGoTopLevelNames(generatedTypeCode, "type")),
3724 consts: new Set(collectGoTopLevelNames(generatedTypeCode, "const")),
3725 };
3726
3727 const rpcOutPath = await writeGeneratedFile("go/rpc/zsession_events.go", generatedTypeCode);
3728 console.log(` ✓ ${rpcOutPath}`);
3729
3730 await formatGoFile(rpcOutPath);
3731
3732 const rpcEncodingOutPath = await writeGeneratedFile("go/rpc/zsession_encoding.go", goGeneratedEncodingFileCode("session-events.schema.json", "rpc", generatedEncodingCode, true));
3733 console.log(` ✓ ${rpcEncodingOutPath}`);
3734

Callers 1

generateFunction · 0.70

Calls 15

cloneSchemaForCodegenFunction · 0.85
loadSchemaJsonFunction · 0.85
postProcessSchemaFunction · 0.85
collectGoTopLevelNamesFunction · 0.85
formatGoFileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…