Skip to content

Commit 831041f

Browse files
committed
Generate package-info.java for generated packages (#1695)
Fixes #1694 ## java/scripts/codegen/java.ts - Added `generateGeneratedPackageInfo()` to emit `package-info.java` for the `com.github.copilot.generated` package. Includes Javadoc describing session event types, key classes (`SessionEvent`, `UnknownSessionEvent`), a usage example, and cross-references to related packages. - Added `generateRpcPackageInfo()` to emit `package-info.java` for the `com.github.copilot.generated.rpc` package. Includes Javadoc describing RPC parameter/result types, key classes (`RpcCaller`, `ServerRpc`, `SessionRpc`), and cross-references. - Updated `main()` to call both new functions after existing generation steps. The files are regenerated on each run since the output directory is cleaned first. ## java/src/generated/java/com/github/copilot/generated/package-info.java - New auto-generated file. Provides package-level Javadoc for the session event types package, following the same style as the hand-written `com.github.copilot` package-info. ## java/src/generated/java/com/github/copilot/generated/rpc/package-info.java - New auto-generated file. Provides package-level Javadoc for the RPC types package, following the same style as the hand-written `com.github.copilot` package-info.
1 parent bb5a6cc commit 831041f

3 files changed

Lines changed: 184 additions & 0 deletions

File tree

java/scripts/codegen/java.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,101 @@ async function generateRpcWrappers(schemaPath: string): Promise<void> {
20532053
console.log(`✅ RPC wrapper classes generated`);
20542054
}
20552055

2056+
// ── Package-info generation ──────────────────────────────────────────────────
2057+
2058+
async function generateGeneratedPackageInfo(packageDir: string): Promise<void> {
2059+
const lines: string[] = [];
2060+
lines.push(COPYRIGHT);
2061+
lines.push("");
2062+
lines.push(AUTO_GENERATED_HEADER);
2063+
lines.push(GENERATED_FROM_SESSION_EVENTS);
2064+
lines.push("");
2065+
lines.push(`/**`);
2066+
lines.push(` * Auto-generated session event types for the GitHub Copilot SDK.`);
2067+
lines.push(` *`);
2068+
lines.push(` * <p>`);
2069+
lines.push(` * This package contains Java classes generated from the Copilot CLI's`);
2070+
lines.push(` * {@code session-events.schema.json}. Each event type corresponds to a`);
2071+
lines.push(` * notification emitted during a {@link com.github.copilot.CopilotSession}`);
2072+
lines.push(` * interaction.`);
2073+
lines.push(` *`);
2074+
lines.push(` * <h2>Key Classes</h2>`);
2075+
lines.push(` * <ul>`);
2076+
lines.push(` * <li>{@link com.github.copilot.generated.SessionEvent} - Abstract sealed base`);
2077+
lines.push(` * class for all session events. Deserialized polymorphically via the`);
2078+
lines.push(` * {@code type} discriminator.</li>`);
2079+
lines.push(` * <li>{@link com.github.copilot.generated.UnknownSessionEvent} - Fallback for`);
2080+
lines.push(` * event types not yet known to this SDK version, preserving forward`);
2081+
lines.push(` * compatibility.</li>`);
2082+
lines.push(` * </ul>`);
2083+
lines.push(` *`);
2084+
lines.push(` * <h2>Example Usage</h2>`);
2085+
lines.push(` *`);
2086+
lines.push(` * <pre>{@code`);
2087+
lines.push(` * session.on(AssistantMessageEvent.class, msg -> {`);
2088+
lines.push(` * System.out.println(msg.getData().content());`);
2089+
lines.push(` * });`);
2090+
lines.push(` * }</pre>`);
2091+
lines.push(` *`);
2092+
lines.push(` * <h2>Related Packages</h2>`);
2093+
lines.push(` * <ul>`);
2094+
lines.push(` * <li>{@link com.github.copilot} - Core SDK classes</li>`);
2095+
lines.push(` * <li>{@link com.github.copilot.generated.rpc} - Auto-generated RPC`);
2096+
lines.push(` * parameter and result types</li>`);
2097+
lines.push(` * </ul>`);
2098+
lines.push(` *`);
2099+
lines.push(` * @see com.github.copilot.CopilotSession`);
2100+
lines.push(` * @see com.github.copilot.generated.SessionEvent`);
2101+
lines.push(` */`);
2102+
lines.push(`package com.github.copilot.generated;`);
2103+
lines.push("");
2104+
2105+
await writeGeneratedFile(`${packageDir}/package-info.java`, lines.join("\n"));
2106+
}
2107+
2108+
async function generateRpcPackageInfo(packageDir: string): Promise<void> {
2109+
const lines: string[] = [];
2110+
lines.push(COPYRIGHT);
2111+
lines.push("");
2112+
lines.push(AUTO_GENERATED_HEADER);
2113+
lines.push(GENERATED_FROM_API);
2114+
lines.push("");
2115+
lines.push(`/**`);
2116+
lines.push(` * Auto-generated RPC parameter and result types for the GitHub Copilot SDK.`);
2117+
lines.push(` *`);
2118+
lines.push(` * <p>`);
2119+
lines.push(` * This package contains Java records and classes generated from the Copilot`);
2120+
lines.push(` * CLI's {@code api.schema.json}. These types represent the request parameters`);
2121+
lines.push(` * and response payloads for all JSON-RPC methods exposed by the CLI.`);
2122+
lines.push(` *`);
2123+
lines.push(` * <h2>Key Classes</h2>`);
2124+
lines.push(` * <ul>`);
2125+
lines.push(` * <li>{@link com.github.copilot.generated.rpc.RpcCaller} - Functional interface`);
2126+
lines.push(` * for invoking JSON-RPC methods with typed responses.</li>`);
2127+
lines.push(` * <li>{@link com.github.copilot.generated.rpc.ServerRpc} - Typed client for`);
2128+
lines.push(` * server-level RPC methods (session management, model listing, etc.).</li>`);
2129+
lines.push(` * <li>{@link com.github.copilot.generated.rpc.SessionRpc} - Typed client for`);
2130+
lines.push(` * session-scoped RPC methods (send messages, manage tools, etc.). Automatically`);
2131+
lines.push(` * injects the {@code sessionId} into every call.</li>`);
2132+
lines.push(` * </ul>`);
2133+
lines.push(` *`);
2134+
lines.push(` * <h2>Related Packages</h2>`);
2135+
lines.push(` * <ul>`);
2136+
lines.push(` * <li>{@link com.github.copilot} - Core SDK classes</li>`);
2137+
lines.push(` * <li>{@link com.github.copilot.generated} - Auto-generated session event`);
2138+
lines.push(` * types</li>`);
2139+
lines.push(` * </ul>`);
2140+
lines.push(` *`);
2141+
lines.push(` * @see com.github.copilot.CopilotClient`);
2142+
lines.push(` * @see com.github.copilot.generated.rpc.ServerRpc`);
2143+
lines.push(` * @see com.github.copilot.generated.rpc.SessionRpc`);
2144+
lines.push(` */`);
2145+
lines.push(`package com.github.copilot.generated.rpc;`);
2146+
lines.push("");
2147+
2148+
await writeGeneratedFile(`${packageDir}/package-info.java`, lines.join("\n"));
2149+
}
2150+
20562151
// ── Main entry point ──────────────────────────────────────────────────────────
20572152

20582153
async function main(): Promise<void> {
@@ -2074,6 +2169,12 @@ async function main(): Promise<void> {
20742169
await generateRpcTypes(apiSchemaPath);
20752170
await generateRpcWrappers(apiSchemaPath);
20762171

2172+
// Generate package-info.java for each generated package
2173+
const generatedPkgDir = `src/generated/java/com/github/copilot/generated`;
2174+
const rpcPkgDir = `src/generated/java/com/github/copilot/generated/rpc`;
2175+
await generateGeneratedPackageInfo(generatedPkgDir);
2176+
await generateRpcPackageInfo(rpcPkgDir);
2177+
20772178
console.log("\n✅ Java code generation complete!");
20782179
}
20792180

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
// AUTO-GENERATED FILE - DO NOT EDIT
6+
// Generated from: session-events.schema.json
7+
8+
/**
9+
* Auto-generated session event types for the GitHub Copilot SDK.
10+
*
11+
* <p>
12+
* This package contains Java classes generated from the Copilot CLI's
13+
* {@code session-events.schema.json}. Each event type corresponds to a
14+
* notification emitted during a {@link com.github.copilot.CopilotSession}
15+
* interaction.
16+
*
17+
* <h2>Key Classes</h2>
18+
* <ul>
19+
* <li>{@link com.github.copilot.generated.SessionEvent} - Abstract sealed base
20+
* class for all session events. Deserialized polymorphically via the
21+
* {@code type} discriminator.</li>
22+
* <li>{@link com.github.copilot.generated.UnknownSessionEvent} - Fallback for
23+
* event types not yet known to this SDK version, preserving forward
24+
* compatibility.</li>
25+
* </ul>
26+
*
27+
* <h2>Example Usage</h2>
28+
*
29+
* <pre>{@code
30+
* session.on(AssistantMessageEvent.class, msg -> {
31+
* System.out.println(msg.getData().content());
32+
* });
33+
* }</pre>
34+
*
35+
* <h2>Related Packages</h2>
36+
* <ul>
37+
* <li>{@link com.github.copilot} - Core SDK classes</li>
38+
* <li>{@link com.github.copilot.generated.rpc} - Auto-generated RPC
39+
* parameter and result types</li>
40+
* </ul>
41+
*
42+
* @see com.github.copilot.CopilotSession
43+
* @see com.github.copilot.generated.SessionEvent
44+
*/
45+
package com.github.copilot.generated;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
// AUTO-GENERATED FILE - DO NOT EDIT
6+
// Generated from: api.schema.json
7+
8+
/**
9+
* Auto-generated RPC parameter and result types for the GitHub Copilot SDK.
10+
*
11+
* <p>
12+
* This package contains Java records and classes generated from the Copilot
13+
* CLI's {@code api.schema.json}. These types represent the request parameters
14+
* and response payloads for all JSON-RPC methods exposed by the CLI.
15+
*
16+
* <h2>Key Classes</h2>
17+
* <ul>
18+
* <li>{@link com.github.copilot.generated.rpc.RpcCaller} - Functional interface
19+
* for invoking JSON-RPC methods with typed responses.</li>
20+
* <li>{@link com.github.copilot.generated.rpc.ServerRpc} - Typed client for
21+
* server-level RPC methods (session management, model listing, etc.).</li>
22+
* <li>{@link com.github.copilot.generated.rpc.SessionRpc} - Typed client for
23+
* session-scoped RPC methods (send messages, manage tools, etc.). Automatically
24+
* injects the {@code sessionId} into every call.</li>
25+
* </ul>
26+
*
27+
* <h2>Related Packages</h2>
28+
* <ul>
29+
* <li>{@link com.github.copilot} - Core SDK classes</li>
30+
* <li>{@link com.github.copilot.generated} - Auto-generated session event
31+
* types</li>
32+
* </ul>
33+
*
34+
* @see com.github.copilot.CopilotClient
35+
* @see com.github.copilot.generated.rpc.ServerRpc
36+
* @see com.github.copilot.generated.rpc.SessionRpc
37+
*/
38+
package com.github.copilot.generated.rpc;

0 commit comments

Comments
 (0)