pybao-xc-sdk 1.5.51 → 1.5.52

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.
Files changed (2) hide show
  1. package/README.md +12 -140
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,145 +1,17 @@
1
- # @pyb/sdk
1
+ # pybao-xc-sdk
2
2
 
3
- PYB-CLI Server SDK for Web UI integration.
3
+ pybao-xc-sdk 是用于接入 PYB 服务端能力的 SDK,面向 Web/Electron/Node 场景。
4
4
 
5
- ## Installation
5
+ ## 功能概览
6
6
 
7
- ```bash
8
- npm install @pyb/sdk
9
- # or
10
- bun add @pyb/sdk
11
- ```
7
+ - 提供统一的 HTTP 客户端能力
8
+ - 提供 SSE 事件订阅与实时消息流处理能力
9
+ - 支持会话、消息、工具、配置、权限等核心业务域
10
+ - 支持断线重连、事件续传与去重等稳态能力
11
+ - 支持运行时会话后端与协议后端路由能力
12
12
 
13
- ## Usage
13
+ ## 适用场景
14
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
15
+ - 自定义前端控制台接入 PYB
16
+ - Electron 桌面应用接入 PYB
17
+ - 中间层服务聚合调用 PYB 能力
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pybao-xc-sdk",
3
- "version": "1.5.51",
3
+ "version": "1.5.52",
4
4
  "description": "PYB-CLI Server SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",