@tbox-dev-js/sdk 0.1.0

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/LEGAL.md ADDED
@@ -0,0 +1,7 @@
1
+ Legal Disclaimer
2
+
3
+ Within this source code, the comments in Chinese shall be the original, governing version. Any comment in other languages are for reference only. In the event of any conflict between the Chinese language version comments and other language version comments, the Chinese language version shall prevail.
4
+
5
+ 法律免责声明
6
+
7
+ 关于代码注释部分,中文注释为官方版本,其它语言注释仅做参考。中文注释可能与其它语言注释存在不一致,当中文注释与其它语言注释存在不一致时,请以中文注释为准。
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # @tbox/plugin-sdk
2
+
3
+ 百宝箱平台插件服务 JavaScript SDK,封装了插件工具执行、TTS/ASR、插件信息查询等核心能力。
4
+
5
+ 调用域名:`https://o.tbox.cn`
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @tbox/plugin-sdk
11
+ # 或
12
+ yarn add @tbox/plugin-sdk
13
+ # 或
14
+ pnpm add @tbox/plugin-sdk
15
+ ```
16
+
17
+ ## 快速开始
18
+
19
+ ```ts
20
+ import { TboxPluginClient } from '@tbox/plugin-sdk';
21
+
22
+ const client = new TboxPluginClient({
23
+ apiKey: 'your-api-key', // 百宝箱应用 API Key
24
+ });
25
+
26
+ // 按工具 ID 执行插件工具
27
+ const result = await client.run('your-plugin-tool-id', {
28
+ inputs: { city: '杭州' },
29
+ });
30
+
31
+ if (result.success) {
32
+ console.log(result.data?.output);
33
+ } else {
34
+ console.error(result.errorCode, result.errorMsg);
35
+ }
36
+ ```
37
+
38
+ ## 初始化配置
39
+
40
+ ```ts
41
+ const client = new TboxPluginClient({
42
+ // 必填:API Key(百宝箱应用维度的 API Key)
43
+ apiKey: 'your-api-key',
44
+
45
+ // 可选:自定义 base URL,默认 https://o.tbox.cn
46
+ baseUrl: 'https://o.tbox.cn',
47
+
48
+ // 可选:请求超时时间(毫秒)
49
+ timeout: 10000,
50
+ });
51
+ ```
52
+
53
+ ## API 文档
54
+
55
+ ### `client.run(pluginToolId, request)` — 按工具 ID 执行插件
56
+
57
+ **适用场景**:已知工具 ID,调用最直接、性能最好。
58
+
59
+ ```ts
60
+ const res = await client.run('tool-id-xxx', {
61
+ inputs: {
62
+ query: '今天杭州天气',
63
+ },
64
+ });
65
+ // res.data: PluginExecResult
66
+ ```
67
+
68
+ | 参数 | 类型 | 说明 |
69
+ |------|------|------|
70
+ | `pluginToolId` | `string` | 插件工具 ID |
71
+ | `request.inputs` | `Record<string, unknown>` | 工具输入参数 |
72
+
73
+ ---
74
+
75
+ ### `client.runByToolName(pluginId, toolName, request)` — 按工具名称执行插件
76
+
77
+ **适用场景**:已知插件 ID 和工具名称,SDK 内部自动解析工具 ID。
78
+
79
+ ```ts
80
+ const res = await client.runByToolName('plugin-id', 'weather_search', {
81
+ inputs: { city: '上海' },
82
+ });
83
+ ```
84
+
85
+ | 参数 | 类型 | 说明 |
86
+ |------|------|------|
87
+ | `pluginId` | `string` | 插件 ID |
88
+ | `toolName` | `string` | 工具名称 |
89
+ | `request.inputs` | `Record<string, unknown>` | 工具输入参数 |
90
+
91
+ ---
92
+
93
+ ### `client.getPluginInfo(pluginId)` — 查询插件信息
94
+
95
+ 查询插件配置信息,包含插件下的工具列表及参数定义。
96
+
97
+ ```ts
98
+ const res = await client.getPluginInfo('plugin-id');
99
+ if (res.success) {
100
+ const tools = res.data?.pluginToolList;
101
+ tools?.forEach(tool => {
102
+ console.log(tool.name, tool.description);
103
+ });
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ### `client.submitToolOutput(request)` — 提交工具输出
110
+
111
+ 在 Agent 调用工具后,将工具执行结果回传给平台。
112
+
113
+ ```ts
114
+ const res = await client.submitToolOutput({
115
+ agent_id: 'app-id-xxx', // 百宝箱应用 ID
116
+ tool_call_id: 'call-id-yyy', // 工具调用 ID
117
+ output: { result: '晴天,25°C' },
118
+ });
119
+ ```
120
+
121
+ ---
122
+
123
+ ### `client.doTts(request)` — 文字转语音
124
+
125
+ ```ts
126
+ const res = await client.doTts({
127
+ text: '你好,欢迎使用百宝箱',
128
+ voice: 'xiaoyun', // 可选,发音人
129
+ speechRate: 0, // 可选,语速 -500~500
130
+ });
131
+ if (res.success) {
132
+ const audioBase64 = res.data?.audioBase64;
133
+ }
134
+ ```
135
+
136
+ ---
137
+
138
+ ### `client.asrBase64(request)` — 语音转文字
139
+
140
+ 输入 Base64 编码的音频数据,返回识别文本。
141
+
142
+ ```ts
143
+ const res = await client.asrBase64({
144
+ audioBase64: '<base64-encoded-audio>',
145
+ format: 'mp3', // 可选,音频格式
146
+ sampleRate: 16000, // 可选,采样率
147
+ });
148
+ if (res.success) {
149
+ console.log(res.data?.text);
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 统一响应格式
156
+
157
+ 所有方法均返回 `Promise<SdkResponse<T>>`:
158
+
159
+ ```ts
160
+ interface SdkResponse<T> {
161
+ success: boolean; // 是否成功
162
+ data?: T; // 响应数据(成功时)
163
+ errorCode?: string; // 错误码(失败时)
164
+ errorMsg?: string; // 错误信息(失败时)
165
+ }
166
+ ```
167
+
168
+ ## 错误处理
169
+
170
+ ```ts
171
+ const res = await client.run('tool-id', { inputs: {} });
172
+
173
+ if (!res.success) {
174
+ switch (res.errorCode) {
175
+ case 'NETWORK_ERROR':
176
+ console.error('网络请求失败:', res.errorMsg);
177
+ break;
178
+ case 'HTTP_401':
179
+ console.error('API Key 无效或已过期');
180
+ break;
181
+ default:
182
+ console.error(`调用失败 [${res.errorCode}]:`, res.errorMsg);
183
+ }
184
+ }
185
+ ```
186
+
187
+ ## 兼容环境
188
+
189
+ - **Node.js** >= 18(原生支持 `fetch`)
190
+ - **浏览器**:支持 `fetch` API 的现代浏览器
191
+ - **模块格式**:ESM(`import`)+ CJS(`require`)双格式
192
+
193
+ ## 项目结构
194
+
195
+ ```
196
+ tbox-js/
197
+ ├── src/
198
+ │ ├── types.ts # TypeScript 类型定义
199
+ │ ├── http.ts # 底层 HTTP 封装
200
+ │ ├── plugin.ts # TboxPluginClient 核心类
201
+ │ └── index.ts # 统一导出入口
202
+ ├── dist/ # 构建产物(npm 发布内容)
203
+ │ ├── index.js # CJS 格式
204
+ │ ├── index.esm.js # ESM 格式
205
+ │ └── index.d.ts # TypeScript 类型声明
206
+ ├── package.json
207
+ ├── tsconfig.json
208
+ └── rollup.config.js
209
+ ```
210
+
211
+ ## 开发构建
212
+
213
+ ```bash
214
+ # 安装依赖
215
+ npm install
216
+
217
+ # 构建产物
218
+ npm run build
219
+
220
+ # 类型检查
221
+ npm run typecheck
222
+ ```
@@ -0,0 +1,41 @@
1
+ {
2
+ "config": {
3
+ "type": "STRUCTURED",
4
+ "topK": 5,
5
+ "scoreThreshold": 0.5,
6
+ "updateMode": "UPSERT",
7
+ "pageSize": 10
8
+ },
9
+ "tools": [
10
+ "list",
11
+ "retrieve",
12
+ "create",
13
+ "update"
14
+ ],
15
+ "knowledges": {
16
+ "产品数据": {
17
+ "datasetId": "",
18
+ "documentId": "",
19
+ "config": {
20
+ "topK": 10,
21
+ "scoreThreshold": 0.7
22
+ },
23
+ "tableSchema": {
24
+ "name": "产品表",
25
+ "description": "产品基础信息",
26
+ "columns": []
27
+ },
28
+ "indexColumns": []
29
+ },
30
+ "FAQ": {
31
+ "datasetId": "",
32
+ "documentId": "",
33
+ "tableSchema": {
34
+ "name": "FAQ表",
35
+ "description": "常见问题",
36
+ "columns": []
37
+ },
38
+ "indexColumns": []
39
+ }
40
+ }
41
+ }
package/dist/amap.d.ts ADDED
@@ -0,0 +1,373 @@
1
+ /**
2
+ * 高德地图 SDK - AmapClient 核心类
3
+ *
4
+ * 封装高德地图天气查询工具(amap_weather),
5
+ * 通过百宝箱插件服务 /openapi/v1/plugin/run/{pluginToolId} 接口调用。
6
+ */
7
+ import type { AmapClientConfig, AmapConvertRequest, AmapConvertResponse, AmapCyclingRouteRequest, AmapCyclingRouteResponse, AmapDistrictRequest, AmapDistrictResponse, AmapDrivingRouteRequest, AmapDrivingRouteResponse, AmapEbikeRouteRequest, AmapEbikeRouteResponse, AmapGeocodeRequest, AmapGeocodeResponse, AmapIpLocationRequest, AmapIpLocationResponse, AmapPeripheralSearchRequest, AmapPeripheralSearchResponse, AmapPoiSearchRequest, AmapPoiSearchResponse, AmapRegeocodeRequest, AmapRegeocodeResponse, AmapTransitRouteRequest, AmapTransitRouteResponse, AmapWalkingRouteRequest, AmapWalkingRouteResponse, AmapWeatherRequest, AmapWeatherResponse, SdkResponse } from './types';
8
+ /**
9
+ * 高德地图客户端
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { AmapClient } from '@tbox/plugin-sdk';
14
+ *
15
+ * const client = new AmapClient({ apiKey: 'your-api-key' });
16
+ *
17
+ * // 查询实况天气
18
+ * const res = await client.weather({ city: '杭州市' });
19
+ * if (res.success) {
20
+ * console.log(res.data?.lives?.[0]?.weather);
21
+ * }
22
+ *
23
+ * // 查询预报天气
24
+ * const forecast = await client.weather({ city: '上海市', extensions: 'all' });
25
+ * if (forecast.success) {
26
+ * console.log(forecast.data?.forecasts?.[0]?.casts);
27
+ * }
28
+ * ```
29
+ */
30
+ export declare class AmapClient {
31
+ private readonly http;
32
+ /** 高德天气查询工具的固定工具 ID */
33
+ private static readonly AMAP_WEATHER_TOOL_ID;
34
+ /** 高德地址转经纬度工具的固定工具 ID */
35
+ private static readonly AMAP_GEOCODE_TOOL_ID;
36
+ /** 高德骑行路线规划工具的固定工具 ID */
37
+ private static readonly AMAP_CYCLING_ROUTE_TOOL_ID;
38
+ /** 高德 IP 定位工具的固定工具 ID */
39
+ private static readonly AMAP_IP_LOCATION_TOOL_ID;
40
+ /** 高德周边搜索工具的固定工具 ID */
41
+ private static readonly AMAP_PERIPHERAL_SEARCH_TOOL_ID;
42
+ /** 高德步行路线规划工具的固定工具 ID */
43
+ private static readonly AMAP_WALKING_ROUTE_TOOL_ID;
44
+ /** 高德驾车路线规划工具的固定工具 ID */
45
+ private static readonly AMAP_DRIVING_ROUTE_TOOL_ID;
46
+ /** 高德电动车路线规划工具的固定工具 ID */
47
+ private static readonly AMAP_EBIKE_ROUTE_TOOL_ID;
48
+ /** 高德公交路线规划工具的固定工具 ID */
49
+ private static readonly AMAP_TRANSIT_ROUTE_TOOL_ID;
50
+ /** 高德行政区域查询工具的固定工具 ID */
51
+ private static readonly AMAP_DISTRICT_TOOL_ID;
52
+ /** 高德经纬度转地址工具的固定工具 ID */
53
+ private static readonly AMAP_REGEOCODE_TOOL_ID;
54
+ /** 高德坐标转换工具的固定工具 ID */
55
+ private static readonly AMAP_CONVERT_TOOL_ID;
56
+ /** 高德 POI 关键字搜索工具的固定工具 ID */
57
+ private static readonly AMAP_POI_SEARCH_TOOL_ID;
58
+ constructor(config: AmapClientConfig);
59
+ /**
60
+ * 查询天气(实况或预报)
61
+ *
62
+ * 内部调用 run('20240627231800002183', ...) 实现,对外屏蔽工具 ID 细节。
63
+ * 数据来源于中国气象局。
64
+ *
65
+ * @param request - 天气查询请求
66
+ * - `city`(必填):省份名、市名、区/县/镇、乡/村或具体地点
67
+ * - `extensions`(可选):`base`(实况,默认)或 `all`(预报)
68
+ * @returns 天气查询结果
69
+ * - `extensions=base` 时,`data.lives` 包含实况天气数据
70
+ * - `extensions=all` 时,`data.forecasts` 包含逐日预报数据
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * // 查询实况天气
75
+ * const live = await client.weather({ city: '西湖区' });
76
+ * if (live.success) {
77
+ * const w = live.data?.lives?.[0];
78
+ * console.log(`${w?.city} ${w?.weather} ${w?.temperature}℃`);
79
+ * }
80
+ *
81
+ * // 查询未来几天预报
82
+ * const forecast = await client.weather({ city: '北京市', extensions: 'all' });
83
+ * if (forecast.success) {
84
+ * for (const cast of forecast.data?.forecasts?.[0]?.casts ?? []) {
85
+ * console.log(`${cast.date} 白天:${cast.dayweather} 夜间:${cast.nightweather}`);
86
+ * }
87
+ * }
88
+ * ```
89
+ */
90
+ weather(request: AmapWeatherRequest): Promise<SdkResponse<AmapWeatherResponse>>;
91
+ /**
92
+ * 地址转经纬度(地理编码)
93
+ *
94
+ * 将详细的地名,转换为经纬度坐标。
95
+ * 内部调用 run('20240627233200002185', ...) 实现,对外屏蔽工具 ID 细节。
96
+ *
97
+ * @param request - 地址转经纬度请求
98
+ * - `address`(必填):详细地址信息(国家、省份、城市、区县、城镇、乡村、街道、门牌号)
99
+ * - `city`(可选):查询的城市,指定可提高查询精度
100
+ * @returns 地理编码结果
101
+ * - `data.geocodes` 包含地理编码信息列表
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * // 地址转经纬度
106
+ * const res = await client.geocode({ address: '北京市朝阳区阜通东大街6号', city: '北京' });
107
+ * if (res.success) {
108
+ * const geo = res.data?.geocodes?.[0];
109
+ * console.log(`地址: ${geo?.formatted_address}`);
110
+ * console.log(`经纬度: ${geo?.location}`);
111
+ * console.log(`区域编码: ${geo?.adcode}`);
112
+ * }
113
+ * ```
114
+ */
115
+ geocode(request: AmapGeocodeRequest): Promise<SdkResponse<AmapGeocodeResponse>>;
116
+ /**
117
+ * 骑行路线规划
118
+ *
119
+ * 提供起点和终点的位置,返回骑行路线,支持多条路线。
120
+ *
121
+ * @param request - 骑行路线规划请求
122
+ * - `origin`(必填):起点位置名称
123
+ * - `destination`(必填):终点位置名称
124
+ * @returns 骑行路线规划结果
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const res = await client.cyclingRoute({
129
+ * origin: '杭州市西湖区',
130
+ * destination: '杭州市余杭区'
131
+ * });
132
+ * if (res.success) {
133
+ * const path = res.data?.route?.paths?.[0];
134
+ * console.log(`距离: ${path?.distance}米, 时间: ${path?.duration}秒`);
135
+ * }
136
+ * ```
137
+ */
138
+ cyclingRoute(request: AmapCyclingRouteRequest): Promise<SdkResponse<AmapCyclingRouteResponse>>;
139
+ /**
140
+ * IP 定位
141
+ *
142
+ * 定位输入的 IP 所在的地理位置(暂不支持 IPv6)。
143
+ *
144
+ * @param request - IP 定位请求
145
+ * - `ip`(必填):需要定位的 IP 地址
146
+ * @returns IP 定位结果
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const res = await client.ipLocation({ ip: '114.114.114.114' });
151
+ * if (res.success) {
152
+ * console.log(`省份: ${res.data?.province}, 城市: ${res.data?.city}`);
153
+ * }
154
+ * ```
155
+ */
156
+ ipLocation(request: AmapIpLocationRequest): Promise<SdkResponse<AmapIpLocationResponse>>;
157
+ /**
158
+ * 周边搜索
159
+ *
160
+ * 根据指定地点和关键词,搜索周边景点、美食、酒店、运动场所等。
161
+ *
162
+ * @param request - 周边搜索请求
163
+ * - `address`(必填):中心点地址信息
164
+ * - `keyword`(必填):检索关键词(景点、美食、游玩区域等,不超过 80 字符)
165
+ * - `count`(可选):返回条数,默认 5
166
+ * - `radius`(可选):搜索半径(米),范围 0-50000
167
+ * @returns 周边搜索结果
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const res = await client.peripheralSearch({
172
+ * address: '杭州市西湖区',
173
+ * keyword: '美食',
174
+ * count: 10,
175
+ * radius: 1000
176
+ * });
177
+ * if (res.success) {
178
+ * for (const poi of res.data?.pois ?? []) {
179
+ * console.log(`${poi.name} - ${poi.address}`);
180
+ * }
181
+ * }
182
+ * ```
183
+ */
184
+ peripheralSearch(request: AmapPeripheralSearchRequest): Promise<SdkResponse<AmapPeripheralSearchResponse>>;
185
+ /**
186
+ * 步行路线规划
187
+ *
188
+ * 提供起点和终点的位置,返回步行路线,支持多条路线。
189
+ *
190
+ * @param request - 步行路线规划请求
191
+ * - `origin`(必填):起点地址
192
+ * - `destination`(必填):终点地址
193
+ * @returns 步行路线规划结果
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const res = await client.walkingRoute({
198
+ * origin: '杭州市西湖区古荡',
199
+ * destination: '杭州市西湖区西溪湿地'
200
+ * });
201
+ * if (res.success) {
202
+ * const path = res.data?.route?.paths?.[0];
203
+ * console.log(`距离: ${path?.distance}米, 时间: ${path?.duration}秒`);
204
+ * }
205
+ * ```
206
+ */
207
+ walkingRoute(request: AmapWalkingRouteRequest): Promise<SdkResponse<AmapWalkingRouteResponse>>;
208
+ /**
209
+ * 驾车路线规划
210
+ *
211
+ * 提供起点和终点的位置,返回驾车路线,支持多条路线。
212
+ *
213
+ * @param request - 驾车路线规划请求
214
+ * - `origin`(必填):起点地址或经纬度
215
+ * - `destination`(必填):终点地址或经纬度
216
+ * @returns 驾车路线规划结果
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * const res = await client.drivingRoute({
221
+ * origin: '杭州西溪湿地',
222
+ * destination: '绍兴市'
223
+ * });
224
+ * if (res.success) {
225
+ * const path = res.data?.route?.paths?.[0];
226
+ * console.log(`距离: ${path?.distance}米, 时间: ${path?.duration}秒`);
227
+ * console.log(`出租车费用: ${res.data?.route?.taxi_cost}元`);
228
+ * }
229
+ * ```
230
+ */
231
+ drivingRoute(request: AmapDrivingRouteRequest): Promise<SdkResponse<AmapDrivingRouteResponse>>;
232
+ /**
233
+ * 电动车路线规划
234
+ *
235
+ * 提供起点和终点的位置,返回电动车骑行路线,支持多条路线。
236
+ *
237
+ * @param request - 电动车路线规划请求
238
+ * - `origin`(必填):起点地址或经纬度
239
+ * - `destination`(必填):终点地址或经纬度
240
+ * @returns 电动车路线规划结果
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * const res = await client.ebikeRoute({
245
+ * origin: '杭州市西湖区',
246
+ * destination: '杭州市余杭区'
247
+ * });
248
+ * if (res.success) {
249
+ * const path = res.data?.route?.paths?.[0];
250
+ * console.log(`距离: ${path?.distance}米, 时间: ${path?.duration}秒`);
251
+ * }
252
+ * ```
253
+ */
254
+ ebikeRoute(request: AmapEbikeRouteRequest): Promise<SdkResponse<AmapEbikeRouteResponse>>;
255
+ /**
256
+ * 公交路线规划
257
+ *
258
+ * 提供起点和终点的位置,返回公交换乘方案,支持多条路线。
259
+ *
260
+ * @param request - 公交路线规划请求
261
+ * - `origin`(必填):起点地址或经纬度
262
+ * - `destination`(必填):终点地址或经纬度
263
+ * @returns 公交路线规划结果
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * const res = await client.transitRoute({
268
+ * origin: '杭州火车站',
269
+ * destination: '西湖'
270
+ * });
271
+ * if (res.success) {
272
+ * for (const transit of res.data?.route?.transits ?? []) {
273
+ * console.log(`费用: ${transit.cost}元, 时间: ${transit.duration}秒`);
274
+ * }
275
+ * }
276
+ * ```
277
+ */
278
+ transitRoute(request: AmapTransitRouteRequest): Promise<SdkResponse<AmapTransitRouteResponse>>;
279
+ /**
280
+ * 行政区域查询
281
+ *
282
+ * 根据用户输入,快速查找特定的行政区域信息。
283
+ *
284
+ * @param request - 行政区域查询请求
285
+ * - `keywords`(必填):查询关键字(行政区名称、citycode、adcode)
286
+ * @returns 行政区域查询结果
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * const res = await client.district({ keywords: '成都市' });
291
+ * if (res.success) {
292
+ * for (const district of res.data?.districts ?? []) {
293
+ * console.log(`${district.name} (${district.adcode})`);
294
+ * }
295
+ * }
296
+ * ```
297
+ */
298
+ district(request: AmapDistrictRequest): Promise<SdkResponse<AmapDistrictResponse>>;
299
+ /**
300
+ * 经纬度转地址(逆地理编码)
301
+ *
302
+ * 将经纬度转换为详细的地址,且返回附近周边的 POI、AOI 信息。
303
+ *
304
+ * @param request - 经纬度转地址请求
305
+ * - `location`(必填):经纬度坐标(经度在前,纬度在后,英文逗号分隔)
306
+ * - `extensions`(可选):base(基本地址)/ all(详细信息)
307
+ * @returns 逆地理编码结果
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * const res = await client.regeocode({
312
+ * location: '116.480881,39.989410',
313
+ * extensions: 'base'
314
+ * });
315
+ * if (res.success) {
316
+ * console.log(`地址: ${res.data?.regeocode?.formatted_address}`);
317
+ * }
318
+ * ```
319
+ */
320
+ regeocode(request: AmapRegeocodeRequest): Promise<SdkResponse<AmapRegeocodeResponse>>;
321
+ /**
322
+ * 坐标转换
323
+ *
324
+ * 将非高德坐标(GPS、mapbar、baidu 坐标)转换成高德坐标。
325
+ *
326
+ * @param request - 坐标转换请求
327
+ * - `locations`(必填):坐标点(经纬度用逗号分隔,多个坐标用 "|" 分隔,最多 40 个)
328
+ * - `coordsys`(必填):原坐标系(gps / mapbar / baidu / autonavi)
329
+ * @returns 坐标转换结果
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * const res = await client.convert({
334
+ * locations: '116.481488,39.990464',
335
+ * coordsys: 'baidu'
336
+ * });
337
+ * if (res.success) {
338
+ * console.log(`转换后的坐标: ${res.data?.locations}`);
339
+ * }
340
+ * ```
341
+ */
342
+ convert(request: AmapConvertRequest): Promise<SdkResponse<AmapConvertResponse>>;
343
+ /**
344
+ * POI 关键字搜索
345
+ *
346
+ * 通过文本关键字搜索地点信息,支持结构化地址和 POI 名称搜索。
347
+ *
348
+ * @param request - POI 关键字搜索请求
349
+ * - `keywords`(可选):查询关键字
350
+ * - `types`(可选):指定地点类型
351
+ * - `region`(可选):搜索区划(默认全国)
352
+ * - `city_limit`(可选):是否限制在 region 内(true / false)
353
+ * - `page_size`(可选):每页数据条数(1-25)
354
+ * - `page_num`(可选):分页页码(1-100)
355
+ * @returns POI 搜索结果
356
+ *
357
+ * @example
358
+ * ```ts
359
+ * const res = await client.poiSearch({
360
+ * keywords: '首开广场',
361
+ * region: '北京',
362
+ * page_size: '10',
363
+ * page_num: '1'
364
+ * });
365
+ * if (res.success) {
366
+ * for (const poi of res.data?.pois ?? []) {
367
+ * console.log(`${poi.name} - ${poi.address}`);
368
+ * }
369
+ * }
370
+ * ```
371
+ */
372
+ poiSearch(request: AmapPoiSearchRequest): Promise<SdkResponse<AmapPoiSearchResponse>>;
373
+ }
package/dist/app.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 百宝箱插件服务 SDK - 应用服务客户端
3
+ *
4
+ * 封装 /openapi/v1/app 下的接口
5
+ */
6
+ import type { SdkResponse, AppGenerateSessionRequest, AppSessionResult, TboxPluginClientConfig } from './types';
7
+ /**
8
+ * 百宝箱应用服务客户端
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const client = new TboxAppClient({ apiKey: 'your-api-key' });
13
+ *
14
+ * // 生成 sessionId,用于免登录访问百宝箱应用
15
+ * const result = await client.generateSession({
16
+ * appId: 'your-app-id',
17
+ * userId: 'user-123',
18
+ * userInfo: [
19
+ * { infoType: 'name', infoValue: '张三' },
20
+ * ],
21
+ * deviceInfo: {
22
+ * platform: 'IOS',
23
+ * appVersion: '1.0.0',
24
+ * },
25
+ * });
26
+ *
27
+ * if (result.success) {
28
+ * console.log('sessionId:', result.data?.sessionId);
29
+ * console.log('channel:', result.data?.channel);
30
+ * }
31
+ * ```
32
+ */
33
+ export declare class TboxAppClient {
34
+ private readonly http;
35
+ constructor(config: TboxPluginClientConfig);
36
+ /**
37
+ * 根据用户信息生成 sessionId 和 channel
38
+ *
39
+ * 接口:POST /openapi/v1/app/generate_session
40
+ *
41
+ * 生成的 sessionId 可用于拼接百宝箱 H5 访问链接,实现免登录跳转。
42
+ *
43
+ * @param request 请求参数,appId 和 userId 为必填
44
+ * @returns sessionId 和 channel
45
+ */
46
+ generateSession(request: AppGenerateSessionRequest): Promise<SdkResponse<AppSessionResult>>;
47
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @tbox/sdk — 常量定义
3
+ */
4
+ /** 默认 API 基础 URL */
5
+ export declare const TBOX_BASE_URL = "https://o.tbox.cn";
6
+ /** SDK 版本号 */
7
+ export declare const SDK_VERSION = "1.0.0";
8
+ /** SDK 版本标识 header key */
9
+ export declare const SDK_VERSION_HEADER = "X-Tbox-SDK-Version";