pybao-xc-sdk 1.5.51 → 1.5.53
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 +12 -140
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -1,145 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pybao-xc-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
pybao-xc-sdk is an SDK for integrating with PYB server capabilities across Web, Electron, and Node environments.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Feature Overview
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
- Unified HTTP client access to PYB server APIs
|
|
8
|
+
- SSE subscription and real-time event stream handling
|
|
9
|
+
- Core domain support for sessions, messages, tools, config, and permissions
|
|
10
|
+
- Stability features including reconnect, replay-aware recovery, and deduplication
|
|
11
|
+
- Runtime/protocol session backend routing support
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Typical Use Cases
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
15
|
+
- Custom frontend console integration with PYB
|
|
16
|
+
- Electron desktop applications powered by PYB
|
|
17
|
+
- Middleware services orchestrating PYB capabilities
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pybao-xc-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.53",
|
|
4
4
|
"description": "PYB-CLI Server SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,14 +28,12 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"sync:root-version": "node ../../scripts/sdk-version-sync.mjs --mode sync --source sdk",
|
|
32
|
-
"check:version-aligned": "node ../../scripts/sdk-version-sync.mjs --mode check --source sdk",
|
|
33
31
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
34
32
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
35
33
|
"test": "bun test",
|
|
36
34
|
"typecheck": "tsc --noEmit",
|
|
37
35
|
"lint": "eslint \"src/**/*.ts\"",
|
|
38
|
-
"prepublishOnly": "npm run
|
|
36
|
+
"prepublishOnly": "npm run build"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
39
|
"zod": "^3.25.76",
|