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

Function emitSessionApiClass

scripts/codegen/csharp.ts:2118–2158  ·  view source on GitHub ↗
(className: string, node: Record<string, unknown>, classes: string[])

Source from the content-addressed store, hash-verified

2116}
2117
2118function emitSessionApiClass(className: string, node: Record<string, unknown>, classes: string[]): string[] {
2119 const parts: string[] = [];
2120 const displayName = className.replace(/Api$/, "");
2121 const groupExperimental = isNodeFullyExperimental(node);
2122 const groupDeprecated = isNodeFullyDeprecated(node);
2123 const experimentalAttr = groupExperimental ? `${experimentalAttribute()}\n` : "";
2124 const deprecatedAttr = groupDeprecated ? `${obsoleteAttributeBlock()}\n` : "";
2125 const subGroups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v));
2126
2127 const lines = [`/// <summary>Provides session-scoped ${displayName} APIs.</summary>`, `${experimentalAttr}${deprecatedAttr}public sealed class ${className}`, `{`, ` private readonly CopilotSession _session;`, ""];
2128 lines.push(` internal ${className}(CopilotSession session)`, ` {`, ` _session = session;`);
2129 lines.push(` }`);
2130
2131 for (const [key, value] of Object.entries(node)) {
2132 if (!isRpcMethod(value)) continue;
2133 emitSessionMethod(key, value, lines, classes, " ", groupExperimental, groupDeprecated);
2134 }
2135
2136 for (const [subGroupName] of subGroups) {
2137 const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api";
2138 const propertyName = toPascalCase(subGroupName);
2139 lines.push("");
2140 lines.push(` /// <summary>${propertyName} APIs.</summary>`);
2141 lines.push(
2142 ` public ${subClassName} ${propertyName} =>`,
2143 ` field ??`,
2144 ` Interlocked.CompareExchange(ref field, new(_session), null) ??`,
2145 ` field;`
2146 );
2147 }
2148
2149 lines.push(`}`);
2150 parts.push(lines.join("\n"));
2151
2152 for (const [subGroupName, subGroupNode] of subGroups) {
2153 const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api";
2154 parts.push(...emitSessionApiClass(subClassName, subGroupNode as Record<string, unknown>, classes));
2155 }
2156
2157 return parts;
2158}
2159
2160function collectClientGroups(node: Record<string, unknown>): Array<{ groupName: string; groupNode: Record<string, unknown>; methods: RpcMethod[] }> {
2161 const groups: Array<{ groupName: string; groupNode: Record<string, unknown>; methods: RpcMethod[] }> = [];

Callers 1

emitSessionRpcClassesFunction · 0.85

Calls 9

isNodeFullyExperimentalFunction · 0.85
isNodeFullyDeprecatedFunction · 0.85
experimentalAttributeFunction · 0.85
obsoleteAttributeBlockFunction · 0.85
emitSessionMethodFunction · 0.85
joinMethod · 0.80
isRpcMethodFunction · 0.70
toPascalCaseFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…