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

Function generatePythonSessionEventsCode

scripts/codegen/python.ts:2443–2789  ·  view source on GitHub ↗
(schema: JSONSchema7)

Source from the content-addressed store, hash-verified

2441}
2442
2443export function generatePythonSessionEventsCode(schema: JSONSchema7): string {
2444 const variants = extractPyEventVariants(schema);
2445 const ctx: PyCodegenCtx = {
2446 classes: [],
2447 aliases: [],
2448 aliasesByName: new Set(),
2449 enums: [],
2450 enumsByName: new Map(),
2451 generatedNames: new Set(),
2452 usesTimedelta: false,
2453 usesIntegerTimedelta: false,
2454 definitions: collectDefinitionCollections(schema as Record<string, unknown>),
2455 refBasedUnions: [],
2456 };
2457
2458 for (const variant of variants) {
2459 emitPyClass(
2460 variant.dataClassName,
2461 variant.dataSchema,
2462 ctx,
2463 variant.dataDescription,
2464 variant.dataExperimental
2465 );
2466 }
2467 const envelopeProperties = getPySharedEventEnvelopeProperties(schema, ctx);
2468 const envelopePropertiesWithoutDefaults = envelopeProperties.filter((property) => !property.hasDefault);
2469 const envelopePropertiesWithDefaults = envelopeProperties.filter((property) => property.hasDefault);
2470
2471 const eventTypeLines: string[] = [];
2472 eventTypeLines.push(`class SessionEventType(Enum):`);
2473 for (const variant of variants) {
2474 if (variant.eventExperimental) {
2475 pushPyExperimentalComment(eventTypeLines, "event", " ");
2476 }
2477 eventTypeLines.push(` ${toEnumMemberName(variant.typeName)} = ${JSON.stringify(variant.typeName)}`);
2478 }
2479 eventTypeLines.push(` UNKNOWN = "unknown"`);
2480 eventTypeLines.push(``);
2481 eventTypeLines.push(` @classmethod`);
2482 eventTypeLines.push(` def _missing_(cls, value: object) -> "SessionEventType":`);
2483 eventTypeLines.push(` return cls.UNKNOWN`);
2484
2485 const out: string[] = [];
2486 out.push(`"""`);
2487 out.push(`AUTO-GENERATED FILE - DO NOT EDIT`);
2488 out.push(`Generated from: session-events.schema.json`);
2489 out.push(`"""`);
2490 out.push(``);
2491 out.push(`from __future__ import annotations`);
2492 out.push(``);
2493 out.push(`from collections.abc import Callable`);
2494 out.push(`from dataclasses import dataclass`);
2495 out.push(ctx.usesTimedelta ? `from datetime import datetime, timedelta` : `from datetime import datetime`);
2496 out.push(`from enum import Enum`);
2497 out.push(`from typing import Any, TypeVar, cast`);
2498 out.push(`from uuid import UUID`);
2499 out.push(``);
2500 out.push(`import dateutil.parser`);

Calls 10

extractPyEventVariantsFunction · 0.85
emitPyClassFunction · 0.85
toEnumMemberNameFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…