From f01baf7c8a412bfcc6a01aa7eee70e7ffcf7623a Mon Sep 17 00:00:00 2001 From: hogeheer <267467744+hogeheer499-commits@users.noreply.github.com> Date: Fri, 24 Jul 2026 22:47:21 +0200 Subject: [PATCH] fix(node): exclude internal events from public union --- nodejs/src/generated/session-events.ts | 94 ----------------------- nodejs/test/session-event-codegen.test.ts | 51 ++++++++++++ scripts/codegen/typescript.ts | 17 ++-- 3 files changed, 62 insertions(+), 100 deletions(-) diff --git a/nodejs/src/generated/session-events.ts b/nodejs/src/generated/session-events.ts index b9c9612b8f..15969710bc 100644 --- a/nodejs/src/generated/session-events.ts +++ b/nodejs/src/generated/session-events.ts @@ -39,7 +39,6 @@ export type SessionEvent = | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent - | AssistantTurnRetryEvent | AssistantIntentEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent @@ -53,7 +52,6 @@ export type SessionEvent = | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent - | ModelCallStartEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent @@ -3189,54 +3187,6 @@ export interface AssistantTurnStartData { */ turnId: string; } -/** - * Session event "assistant.turn_retry". Metadata for an additional model inference attempt within an existing assistant turn - */ -/** @internal */ -export interface AssistantTurnRetryEvent { - /** - * Sub-agent instance identifier. Absent for events from the root/main agent and session-level events. - */ - agentId?: string; - data: AssistantTurnRetryData; - /** - * Always true for events that are transient and not persisted to the session event log on disk. - */ - ephemeral: true; - /** - * Unique event identifier (UUID v4), generated when the event is emitted - */ - id: string; - /** - * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. - */ - parentId: string | null; - /** - * ISO 8601 timestamp when the event was created - */ - timestamp: string; - /** - * Type discriminator. Always "assistant.turn_retry". - */ - type: "assistant.turn_retry"; -} -/** - * Metadata for an additional model inference attempt within an existing assistant turn - */ -export interface AssistantTurnRetryData { - /** - * Model identifier used for this retry, when known - */ - model?: string; - /** - * Provider or runtime classification that caused the retry, when known - */ - reason?: string; - /** - * Identifier of the turn whose model inference is being retried - */ - turnId: string; -} /** * Session event "assistant.intent". Agent intent description for current activity or plan */ @@ -4333,50 +4283,6 @@ export interface ModelCallFailureRequestFingerprint { */ toolResultMessageCount: number; } -/** - * Session event "model.call_start". Model API dispatch metadata for internal telemetry - */ -/** @internal */ -export interface ModelCallStartEvent { - /** - * Sub-agent instance identifier. Absent for events from the root/main agent and session-level events. - */ - agentId?: string; - data: ModelCallStartData; - /** - * Always true for events that are transient and not persisted to the session event log on disk. - */ - ephemeral: true; - /** - * Unique event identifier (UUID v4), generated when the event is emitted - */ - id: string; - /** - * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. - */ - parentId: string | null; - /** - * ISO 8601 timestamp when the event was created - */ - timestamp: string; - /** - * Type discriminator. Always "model.call_start". - */ - type: "model.call_start"; -} -/** - * Model API dispatch metadata for internal telemetry - */ -export interface ModelCallStartData { - /** - * Model identifier used for this API call, when known - */ - model?: string; - /** - * Identifier of the assistant turn that initiated the model call - */ - turnId: string; -} /** * Session event "abort". Turn abort information including the reason for termination */ diff --git a/nodejs/test/session-event-codegen.test.ts b/nodejs/test/session-event-codegen.test.ts index 14340292be..06616dce41 100644 --- a/nodejs/test/session-event-codegen.test.ts +++ b/nodejs/test/session-event-codegen.test.ts @@ -5,8 +5,59 @@ import { generateSessionEventsCode as generateCSharpSessionEventsCode } from ".. import { generateGoSessionEventsCode } from "../../scripts/codegen/go.ts"; import { generatePythonSessionEventsCode } from "../../scripts/codegen/python.ts"; import { generateSessionEventsCode as generateRustSessionEventsCode } from "../../scripts/codegen/rust.ts"; +import { generateTypeScriptSessionEventsCode } from "../../scripts/codegen/typescript.ts"; describe("session event codegen", () => { + it("excludes internal event wrappers from the public TypeScript union", async () => { + const schema: JSONSchema7 = { + definitions: { + SessionEvent: { + anyOf: [ + { $ref: "#/definitions/PublicEvent" }, + { $ref: "#/definitions/InternalEvent" }, + ], + }, + PublicEvent: { + type: "object", + required: ["type", "data"], + properties: { + type: { const: "session.public" }, + data: { $ref: "#/definitions/PublicData" }, + }, + }, + PublicData: { + type: "object", + required: ["message"], + properties: { + message: { type: "string" }, + }, + }, + InternalEvent: { + type: "object", + visibility: "internal", + required: ["type", "data"], + properties: { + type: { const: "session.internal" }, + data: { $ref: "#/definitions/InternalData" }, + }, + }, + InternalData: { + type: "object", + required: ["attempt"], + properties: { + attempt: { type: "number" }, + }, + }, + }, + }; + + const code = await generateTypeScriptSessionEventsCode(schema); + + expect(code).toContain("export interface PublicEvent"); + expect(code).not.toContain("InternalEvent"); + expect(code).not.toContain("InternalData"); + }); + it("maps special schema formats to the expected Python types", () => { const schema: JSONSchema7 = { definitions: { diff --git a/scripts/codegen/typescript.ts b/scripts/codegen/typescript.ts index f82e67abe6..99061cc89e 100644 --- a/scripts/codegen/typescript.ts +++ b/scripts/codegen/typescript.ts @@ -338,11 +338,7 @@ export function normalizeSchemaForTypeScript(schema: JSONSchema7): JSONSchema7 { // ── Session Events ────────────────────────────────────────────────────────── -async function generateSessionEvents(schemaPath?: string): Promise { - console.log("TypeScript: generating session-events..."); - - const resolvedPath = schemaPath ?? (await getSessionEventsSchemaPath()); - const schema = (await loadSchemaJson(resolvedPath)) as JSONSchema7; +export async function generateTypeScriptSessionEventsCode(schema: JSONSchema7): Promise { const processed = propagateInternalVisibility(postProcessSchema(schema)); const definitionCollections = collectDefinitionCollections(processed as Record); const sessionEvent = @@ -355,7 +351,7 @@ async function generateSessionEvents(schemaPath?: string): Promise { const resolvedVariant = resolveSchema(variantSchema, definitionCollections) ?? variantSchema; const dataSchema = resolvedVariant.properties?.data as JSONSchema7 | undefined; const resolvedData = dataSchema ? resolveSchema(dataSchema, definitionCollections) ?? dataSchema : undefined; - if (!isSchemaInternal(resolvedData)) { + if (!isSchemaInternal(resolvedVariant) && !isSchemaInternal(resolvedData)) { return true; } @@ -415,6 +411,15 @@ async function generateSessionEvents(schemaPath?: string): Promise { `$1/** @internal */\n$2` ); } + return annotatedTs; +} + +async function generateSessionEvents(schemaPath?: string): Promise { + console.log("TypeScript: generating session-events..."); + + const resolvedPath = schemaPath ?? (await getSessionEventsSchemaPath()); + const schema = (await loadSchemaJson(resolvedPath)) as JSONSchema7; + const annotatedTs = await generateTypeScriptSessionEventsCode(schema); const outPath = await writeGeneratedFile("nodejs/src/generated/session-events.ts", annotatedTs); console.log(` ✓ ${outPath}`); }