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

Function generateSessionEventsCode

scripts/codegen/rust.ts:1115–1272  ·  view source on GitHub ↗
(schema: JSONSchema7)

Source from the content-addressed store, hash-verified

1113}
1114
1115export function generateSessionEventsCode(schema: JSONSchema7): string {
1116 const variants = extractEventVariants(schema);
1117 const ctx = makeCtx(
1118 collectDefinitionCollections(schema as Record<string, unknown>),
1119 {
1120 allowUntaggedUnions: true,
1121 allowedUnionTypeNames: [
1122 "ToolExecutionCompleteContent",
1123 "ToolExecutionCompleteContentResourceDetails",
1124 ],
1125 },
1126 );
1127
1128 // Generate per-event data structs
1129 for (const variant of variants) {
1130 emitRustStruct(
1131 variant.dataClassName,
1132 variant.dataSchema,
1133 ctx,
1134 variant.description,
1135 );
1136 }
1137
1138 // Build the SessionEventType enum
1139 const typeEnumLines: string[] = [];
1140 typeEnumLines.push("/// Identifies the kind of session event.");
1141 typeEnumLines.push(
1142 "#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]",
1143 );
1144 typeEnumLines.push("pub enum SessionEventType {");
1145 for (const variant of variants) {
1146 pushRustExperimentalDocs(
1147 typeEnumLines,
1148 variant.eventExperimental,
1149 " ",
1150 );
1151 typeEnumLines.push(` #[serde(rename = "${variant.typeName}")]`);
1152 typeEnumLines.push(` ${variant.variantName},`);
1153 }
1154 typeEnumLines.push(" /// Unknown event type for forward compatibility.");
1155 typeEnumLines.push(" #[default]");
1156 typeEnumLines.push(" #[serde(other)]");
1157 typeEnumLines.push(" Unknown,");
1158 typeEnumLines.push("}");
1159
1160 // Build the SessionEventData enum (adjacently tagged by type/data)
1161 const dataEnumLines: string[] = [];
1162 dataEnumLines.push(
1163 "/// Typed session event data, discriminated by the event `type` field.",
1164 );
1165 dataEnumLines.push("///");
1166 dataEnumLines.push(
1167 "/// Use with [`TypedSessionEvent`] for fully typed event handling.",
1168 );
1169 dataEnumLines.push("#[derive(Debug, Clone, Serialize, Deserialize)]");
1170 dataEnumLines.push(`#[serde(tag = "type", content = "data")]`);
1171 dataEnumLines.push("pub enum SessionEventData {");
1172 for (const variant of variants) {

Callers 1

generateFunction · 0.70

Calls 7

makeCtxFunction · 0.85
emitRustStructFunction · 0.85
pushRustExperimentalDocsFunction · 0.85
joinMethod · 0.80
extractEventVariantsFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…