pybao-xc-sdk 1.5.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -0
- package/dist/index.d.mts +3264 -0
- package/dist/index.d.ts +3264 -0
- package/dist/index.js +2423 -0
- package/dist/index.mjs +2308 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @pyb/sdk
|
|
2
|
+
|
|
3
|
+
PYB-CLI Server SDK for Web UI integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pyb/sdk
|
|
9
|
+
# or
|
|
10
|
+
bun add @pyb/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### HTTP Client
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { PybClient } from '@pyb/sdk'
|
|
19
|
+
|
|
20
|
+
const client = new PybClient({
|
|
21
|
+
baseUrl: 'http://localhost:4096/v1',
|
|
22
|
+
timeout: 120000,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// Facade-first: create a session
|
|
26
|
+
const session = await client.session.create({
|
|
27
|
+
config: {
|
|
28
|
+
model: 'claude-sonnet-4-20250514',
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Facade-first: send a prompt
|
|
33
|
+
const response = await client.session.prompt(session.sessionId, {
|
|
34
|
+
message: 'Hello, how are you?',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Facade-first: list sessions
|
|
38
|
+
const { items } = await client.session.list({ status: 'active' })
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### SSE Event Subscription
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { createSSEClient } from '@pyb/sdk'
|
|
45
|
+
|
|
46
|
+
const sse = createSSEClient({
|
|
47
|
+
baseUrl: 'http://localhost:4096/v1',
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Subscribe to specific events
|
|
51
|
+
const unsub1 = sse.subscribe('message.created', (event) => {
|
|
52
|
+
console.log('New message:', event.data.message)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const unsub2 = sse.subscribe('tool.started', (event) => {
|
|
56
|
+
console.log('Tool started:', event.data.toolName)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Subscribe to all events
|
|
60
|
+
const unsub3 = sse.subscribeAll((event) => {
|
|
61
|
+
console.log('Event:', event.type)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Connect
|
|
65
|
+
sse.connect()
|
|
66
|
+
|
|
67
|
+
// Later, clean up
|
|
68
|
+
unsub1()
|
|
69
|
+
unsub2()
|
|
70
|
+
unsub3()
|
|
71
|
+
sse.disconnect()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Permission Handling
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { createSSEClient, PybClient } from '@pyb/sdk'
|
|
78
|
+
|
|
79
|
+
const client = new PybClient()
|
|
80
|
+
const sse = createSSEClient()
|
|
81
|
+
|
|
82
|
+
sse.subscribe('permission.requested', async (event) => {
|
|
83
|
+
const { permissionId, toolName, input, risk } = event.data
|
|
84
|
+
|
|
85
|
+
// Show permission dialog to user
|
|
86
|
+
const userDecision = await showPermissionDialog({
|
|
87
|
+
toolName,
|
|
88
|
+
input,
|
|
89
|
+
risk,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// Respond to server
|
|
93
|
+
await client.respondToPermission(permissionId, {
|
|
94
|
+
decision: userDecision.decision,
|
|
95
|
+
remember: userDecision.remember ? { scope: 'session' } : undefined,
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
sse.connect()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## API Reference
|
|
103
|
+
|
|
104
|
+
### PybClient Facades
|
|
105
|
+
|
|
106
|
+
| Facade | Methods |
|
|
107
|
+
|--------|---------|
|
|
108
|
+
| `client.session` | `create/list/get/update/delete/prompt/abort/messages` |
|
|
109
|
+
| `client.mcp` | `list/connect/disconnect` |
|
|
110
|
+
| `client.tool` | `list/execute` |
|
|
111
|
+
| `client.config` | `get/update` |
|
|
112
|
+
| `client` | `getHealth/respondToPermission/getPendingPermissions` |
|
|
113
|
+
|
|
114
|
+
Legacy flat API remains temporarily for migration and maps to the facade methods above.
|
|
115
|
+
|
|
116
|
+
### SSEClient
|
|
117
|
+
|
|
118
|
+
| Method | Description |
|
|
119
|
+
|--------|-------------|
|
|
120
|
+
| `connect()` | Start SSE connection |
|
|
121
|
+
| `disconnect()` | Close SSE connection |
|
|
122
|
+
| `subscribe(eventType, callback)` | Subscribe to specific event |
|
|
123
|
+
| `subscribeAll(callback)` | Subscribe to all events |
|
|
124
|
+
| `isConnected()` | Check connection status |
|
|
125
|
+
|
|
126
|
+
## Event Types
|
|
127
|
+
|
|
128
|
+
| Event Type | Description |
|
|
129
|
+
|------------|-------------|
|
|
130
|
+
| `server.connected` | Server connection established |
|
|
131
|
+
| `server.heartbeat` | Periodic heartbeat |
|
|
132
|
+
| `session.created` | New session created |
|
|
133
|
+
| `session.updated` | Session updated |
|
|
134
|
+
| `message.created` | New message created |
|
|
135
|
+
| `message.updated` | Message content updated |
|
|
136
|
+
| `tool.started` | Tool execution started |
|
|
137
|
+
| `tool.progress` | Tool execution progress |
|
|
138
|
+
| `tool.completed` | Tool execution completed |
|
|
139
|
+
| `permission.requested` | Permission confirmation needed |
|
|
140
|
+
| `permission.responded` | Permission response received |
|
|
141
|
+
| `error` | Error occurred |
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|