@@ -11,16 +11,23 @@ All SDKs and external facing APIs are in alpha stage and will change in breaking
1111** Location:** ` ./nodejs/ `
1212
1313``` typescript
14- import { ask , query , CopilotClient } from " @github/copilot-cli-sdk" ;
14+ import { CopilotClient } from " @github/copilot-cli-sdk" ;
1515
16- // Simple query
17- const result = await ask ( " What is 2+2? " );
18- console . log ( result . content );
16+ // Create client and session
17+ const client = new CopilotClient ( );
18+ await client . start ( );
1919
20- // Streaming
21- for await (const event of query ({ prompt: " ..." })) {
22- console .log (event );
23- }
20+ const session = await client .createSession ({ model: " gpt-5" });
21+
22+ // Listen to events
23+ session .on ((event ) => {
24+ if (event .type === " assistant.message" ) {
25+ console .log (event .data .content );
26+ }
27+ });
28+
29+ // Send messages
30+ await session .send ({ prompt: " What is 2+2?" });
2431```
2532
2633** Features:**
@@ -29,7 +36,7 @@ for await (const event of query({ prompt: "..." })) {
2936- Real-time event streaming
3037- Session history and multi-turn conversations
3138- TypeScript type definitions
32- - Automatic lifecycle management
39+ - Full lifecycle control
3340
3441** Demos:** ` ./demos/nodejs-demo/ `
3542
@@ -40,15 +47,23 @@ for await (const event of query({ prompt: "..." })) {
4047** Location:** ` ./python/ `
4148
4249``` python
43- from copilot import ask, query, CopilotClient
50+ from copilot import CopilotClient
51+
52+ # Create client and session
53+ client = CopilotClient({" use_stdio" : True })
54+ await client.start()
55+
56+ session = await client.create_session({" model" : " gpt-5" })
4457
45- # Simple query
46- result = ask(" What is 2+2?" )
47- print (result.content)
58+ # Listen to events
59+ def on_event (event ):
60+ if event.type.value == " assistant.message" :
61+ print (event.data.content)
4862
49- # Streaming
50- for event in query(prompt = " ..." ):
51- print (event)
63+ session.on(on_event)
64+
65+ # Send messages
66+ await session.send({" prompt" : " What is 2+2?" })
5267```
5368
5469** Features:**
@@ -57,7 +72,7 @@ for event in query(prompt="..."):
5772- stdio transport
5873- Async/await support
5974- Type hints (TypedDict)
60- - Exact API parity with TypeScript
75+ - Full lifecycle control
6176
6277** Demos:** ` ./demos/python-demo/ `
6378
@@ -70,58 +85,51 @@ for event in query(prompt="..."):
7085``` go
7186import copilot " github.com/github/copilot-cli-sdk-go"
7287
73- // Simple query
74- result := copilot.Ask (" What is 2+2?" , nil )
75- fmt.Println (result.Content )
88+ // Create client and session
89+ client := copilot.NewClient (&copilot.ClientOptions {UseStdio: true })
90+ client.Start ()
91+ defer client.Stop ()
92+
93+ session , _ := client.CreateSession (&copilot.SessionConfig {Model: " gpt-5" })
94+ defer session.Destroy ()
7695
77- // Streaming with channels
78- for result := range copilot. Query ( copilot.QueryOptions {Prompt: " ... " } ) {
79- if result. Event != nil {
80- fmt.Println (result. Event )
96+ // Listen to events
97+ session. On ( func (event copilot.SessionEvent ) {
98+ if event. Type == " assistant.message " {
99+ fmt.Println (*event. Data . Content )
81100 }
82- }
101+ })
102+
103+ // Send messages
104+ session.Send (copilot.MessageOptions {Prompt: " What is 2+2?" })
83105```
84106
85107** Features:**
86108
87109- Goroutine-based JSON-RPC client (zero external dependencies)
88110- stdio transport
89- - Channel-based streaming
90- - Idiomatic Go patterns (defer, goroutines, channels )
91- - Exact API parity with TypeScript/Python
111+ - Channel-based event streaming
112+ - Idiomatic Go patterns (defer, goroutines)
113+ - Full lifecycle control
92114
93115** Demos:** ` ./demos/go-demo/ `
94116
95117---
96118
97119## Architecture
98120
99- All SDKs follow the same 3-level API design:
100-
101- ### 1. High-Level Simple API
102-
103- For quick one-off queries with automatic lifecycle management:
104-
105- ```
106- ask(prompt) → result
107- ```
108-
109- ### 2. High-Level Streaming API
110-
111- For real-time event streaming:
112-
113- ```
114- query(options) → event stream
115- ```
116-
117- ### 3. Low-Level Advanced API
118-
119- For full control over lifecycle and sessions:
121+ All SDKs provide a consistent advanced API for full control over lifecycle and sessions:
120122
121123```
122124client.start() → session.create() → session.send() → events → session.destroy()
123125```
124126
127+ This gives you:
128+ - Full control over client and session lifecycle
129+ - Multiple concurrent sessions
130+ - Real-time event streaming via callbacks
131+ - Session history and multi-turn conversations
132+
125133## Common Features
126134
127135All SDKs provide:
@@ -229,9 +237,9 @@ copilot --server --port 8080
229237
230238| Feature | TypeScript | Python | Go |
231239| ---------------- | ------------------ | ----------------- | ------------------- |
232- | ** LOC** | ~ 800 | ~ 1050 | ~ 930 |
240+ | ** LOC** | ~ 600 | ~ 850 | ~ 730 |
233241| ** Concurrency** | Async/await | asyncio + threads | Goroutines |
234- | ** Streaming ** | Async generators | Async generators | Channels |
242+ | ** Events ** | Callbacks | Callbacks | Callbacks |
235243| ** JSON-RPC** | vscode-jsonrpc | Custom (threads) | Custom (goroutines) |
236244| ** Dependencies** | 1 (vscode-jsonrpc) | 0 | 0 |
237245| ** Type Safety** | TypeScript | TypedDict | Structs |
0 commit comments