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

Function appendPythonSessionEventsAllList

scripts/codegen/python.ts:3268–3308  ·  view source on GitHub ↗

* Appends an `__all__` list to the generated session-events module so that * the public ``copilot.session_events`` shim can ``from .generated.session_events * import *`` without leaking helper functions (``from_str``, ``from_int``, …) * or TypeVars (``T``, ``EnumT``). Internal-marked types are om

(code: string, _schema: JSONSchema7, internalTypeNames: Set<string>)

Source from the content-addressed store, hash-verified

3266 * (`_`-prefixed) form is still present in the module for cross-module use.
3267 */
3268function appendPythonSessionEventsAllList(code: string, _schema: JSONSchema7, internalTypeNames: Set<string>): string {
3269 const exported = new Set<string>();
3270
3271 // All top-level public classes (schema-derived and inline event payload
3272 // shapes alike). The codegen only emits classes that are part of the
3273 // protocol surface, so a class-presence filter is sufficient — the
3274 // utility module excludes helpers like `from_str` / `to_class` because
3275 // they are functions, not classes, and TypeVars are assignments.
3276 const classPattern = /^class\s+([A-Za-z_]\w*)\b/gm;
3277 let match: RegExpExecArray | null;
3278 while ((match = classPattern.exec(code)) !== null) {
3279 const name = match[1];
3280 if (name.startsWith("_")) continue;
3281 if (internalTypeNames.has(name)) continue;
3282 exported.add(name);
3283 }
3284
3285 // Top-level CamelCase Assign targets (e.g. `SessionEventData = X | Y |
3286 // ...` discriminated-union aliases). Skip TypeVars.
3287 const assignPattern = /^([A-Z][A-Za-z0-9_]*)\s*=/gm;
3288 while ((match = assignPattern.exec(code)) !== null) {
3289 const name = match[1];
3290 if (name === "T" || name === "EnumT") continue;
3291 if (internalTypeNames.has(name)) continue;
3292 exported.add(name);
3293 }
3294
3295 // Public top-level free functions named like `session_event_from_dict`
3296 // — the documented entry point for parsing event payloads from raw dicts.
3297 // Helper functions like `from_str` / `to_class` live in `utility` (a
3298 // different module) so they don't appear here.
3299 const fnPattern = /^def\s+([a-z][A-Za-z0-9_]*)\s*\(/gm;
3300 while ((match = fnPattern.exec(code)) !== null) {
3301 const name = match[1];
3302 if (name.startsWith("_")) continue;
3303 if (!name.endsWith("_from_dict") && !name.endsWith("_to_dict")) continue;
3304 exported.add(name);
3305 }
3306
3307 return code.replace(/\s*$/, "") + "\n\n" + renderPythonAllList([...exported].sort()) + "\n";
3308}
3309
3310/**
3311 * Appends an `__all__` list to the generated RPC module so that the public

Callers 1

generateSessionEventsFunction · 0.85

Calls 3

renderPythonAllListFunction · 0.85
execMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…