Skip to content

Commit fc6b201

Browse files
authored
Remove ask/query (#11)
1 parent b713a23 commit fc6b201

33 files changed

Lines changed: 136 additions & 2419 deletions

README.md

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7186
import 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
```
122124
client.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

127135
All 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 |

demos/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ See [nodejs-demo/README.md](nodejs-demo/README.md) for full details.
4343

4444
Complete demo showing:
4545

46-
- High-level `ask()` API
47-
- Streaming with `query()` generator
48-
- Real-time ephemeral chunks
46+
- Client/Session API usage
47+
- Real-time event streaming
4948
- Multi-turn conversations with history
5049

5150
**Quick start:**
@@ -54,23 +53,22 @@ Complete demo showing:
5453
cd python-demo
5554
PYTHONPATH=../../python:$PYTHONPATH \
5655
COPILOT_CLI_PATH=../../../dist-cli/index.js \
57-
python3 query_demo.py
56+
python3 simple_demo.py
5857
```
5958

6059
### Go (`go-demo/`)
6160

6261
Complete demo showing:
6362

64-
- High-level `Ask()` API
65-
- Channel-based streaming with `Query()`
63+
- Client/Session API usage
64+
- Event-driven callbacks
6665
- Goroutine-based concurrency
67-
- Exact API parity with TypeScript/Python
6866

6967
**Quick start:**
7068

7169
```bash
7270
cd go-demo
73-
COPILOT_CLI_PATH=../../../dist-cli/index.js go run query_demo.go
71+
COPILOT_CLI_PATH=../../../dist-cli/index.js go run simple_demo.go
7472
```
7573

7674
---

demos/go-demo/README.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Demo applications showing how to use the Go SDK for GitHub Copilot CLI.
2727

2828
```bash
2929
./run_demo.sh simple_demo.go
30-
./run_demo.sh ask_demo.go
31-
./run_demo.sh query_demo.go
3230
./run_demo.sh history_demo.go
3331
```
3432

@@ -45,15 +43,9 @@ export COPILOT_CLI_PATH=../../../dist-cli/index.js
4543
Then run demos:
4644

4745
```bash
48-
# Simple demo - low-level client/session API
46+
# Simple demo - client/session API
4947
go run simple_demo.go
5048
51-
# Ask demo - high-level helper for simple queries
52-
go run ask_demo.go
53-
54-
# Query demo - streaming events as they happen
55-
go run query_demo.go
56-
5749
# History demo - multi-turn conversation with history
5850
go run history_demo.go
5951
```
@@ -69,18 +61,6 @@ go run history_demo.go
6961
- Waiting for responses
7062
- Getting message history
7163

72-
### ask_demo.go
73-
74-
- Using the high-level `Ask()` function
75-
- Automatic lifecycle management
76-
- Simple request/response pattern
77-
78-
### query_demo.go
79-
80-
- Using the `Query()` function for streaming
81-
- Receiving events in real-time
82-
- Handling ephemeral (streaming) events
83-
8464
### history_demo.go
8565

8666
- Multi-turn conversations

demos/go-demo/ask_demo.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

demos/go-demo/query_demo.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)