chatablex-web-sdk 1.0.0 → 1.0.3
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 +700 -109
- package/README.zh-CN.md +699 -108
- package/dist/index.d.mts +8 -33
- package/dist/index.d.ts +8 -33
- package/dist/index.js +72 -10
- package/dist/index.mjs +72 -10
- package/package.json +13 -4
- package/src/bridge.ts +1 -1
- package/src/index.ts +4 -3
- package/src/modules/platform.ts +14 -0
- package/src/modules/ui.ts +2 -2
- package/src/types.ts +6 -38
- package/src/modules/skills.ts +0 -14
package/dist/index.d.mts
CHANGED
|
@@ -66,31 +66,6 @@ interface ToolResult {
|
|
|
66
66
|
duration?: number;
|
|
67
67
|
}
|
|
68
68
|
type ToolExecuteHandler = (params: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
69
|
-
interface Skill {
|
|
70
|
-
id: string;
|
|
71
|
-
name: string;
|
|
72
|
-
description: string;
|
|
73
|
-
version: string;
|
|
74
|
-
author?: string;
|
|
75
|
-
category?: string;
|
|
76
|
-
toolIds: string[];
|
|
77
|
-
variables: SkillVariable[];
|
|
78
|
-
installed: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface SkillVariable {
|
|
81
|
-
name: string;
|
|
82
|
-
type: string;
|
|
83
|
-
description: string;
|
|
84
|
-
required: boolean;
|
|
85
|
-
default?: unknown;
|
|
86
|
-
}
|
|
87
|
-
interface SkillResult {
|
|
88
|
-
success: boolean;
|
|
89
|
-
data?: unknown;
|
|
90
|
-
error?: string;
|
|
91
|
-
skillId: string;
|
|
92
|
-
toolResults?: ToolResult[];
|
|
93
|
-
}
|
|
94
69
|
type NotificationType = 'info' | 'success' | 'warning' | 'error';
|
|
95
70
|
interface FilePickerOptions {
|
|
96
71
|
type?: 'any' | 'image' | 'video' | 'audio' | 'custom';
|
|
@@ -155,10 +130,6 @@ interface ChatableXTools {
|
|
|
155
130
|
execute(toolId: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
156
131
|
executeWithConfirm(toolId: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
157
132
|
}
|
|
158
|
-
interface ChatableXSkills {
|
|
159
|
-
list(): Promise<Skill[]>;
|
|
160
|
-
execute(skillId: string, variables: Record<string, unknown>): Promise<SkillResult>;
|
|
161
|
-
}
|
|
162
133
|
interface ChatableXUI {
|
|
163
134
|
showNotification(message: string, type?: NotificationType): Promise<void>;
|
|
164
135
|
showConfirm(title: string, message: string): Promise<boolean>;
|
|
@@ -181,14 +152,18 @@ interface ChatableXToolModule {
|
|
|
181
152
|
getInfo(): ToolInfo;
|
|
182
153
|
onExecute(handler: ToolExecuteHandler): void;
|
|
183
154
|
}
|
|
155
|
+
interface ChatableXPlatform {
|
|
156
|
+
/** Open URL in system browser with auth handoff (WebView only; implemented by Flutter host). */
|
|
157
|
+
openInBrowser(targetUrl: string): Promise<void>;
|
|
158
|
+
}
|
|
184
159
|
interface ChatableXSDK {
|
|
185
160
|
ai: ChatableXAI;
|
|
186
161
|
tools: ChatableXTools;
|
|
187
|
-
skills: ChatableXSkills;
|
|
188
162
|
ui: ChatableXUI;
|
|
189
163
|
events: ChatableXEvents;
|
|
190
164
|
storage: ChatableXStorage;
|
|
191
165
|
tool: ChatableXToolModule;
|
|
166
|
+
platform: ChatableXPlatform;
|
|
192
167
|
}
|
|
193
168
|
declare global {
|
|
194
169
|
interface Window {
|
|
@@ -224,7 +199,7 @@ declare class Bridge {
|
|
|
224
199
|
/** Wait for ChatableXBridge (set by Flutter) to become available. */
|
|
225
200
|
waitForBridge(timeoutMs: number): Promise<void>;
|
|
226
201
|
/** Send a request to Flutter and wait for a response. */
|
|
227
|
-
sendMessage(method: string, params?:
|
|
202
|
+
sendMessage(method: string, params?: object, requestTimeoutMs?: number): Promise<unknown>;
|
|
228
203
|
private _handleResponse;
|
|
229
204
|
private _handleEvent;
|
|
230
205
|
addEventListener(eventType: string, handler: EventHandler): () => void;
|
|
@@ -255,7 +230,7 @@ declare class Bridge {
|
|
|
255
230
|
* ```
|
|
256
231
|
*/
|
|
257
232
|
|
|
258
|
-
declare const SDK_VERSION
|
|
233
|
+
declare const SDK_VERSION: string;
|
|
259
234
|
/**
|
|
260
235
|
* Main entry point. Provides `ChatableX.init()` to bootstrap the SDK.
|
|
261
236
|
*/
|
|
@@ -277,4 +252,4 @@ declare const ChatableX: {
|
|
|
277
252
|
version: string;
|
|
278
253
|
};
|
|
279
254
|
|
|
280
|
-
export { type AiResponseEventData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXEvents, type ChatableXInitConfig, type
|
|
255
|
+
export { type AiResponseEventData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };
|
package/dist/index.d.ts
CHANGED
|
@@ -66,31 +66,6 @@ interface ToolResult {
|
|
|
66
66
|
duration?: number;
|
|
67
67
|
}
|
|
68
68
|
type ToolExecuteHandler = (params: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
69
|
-
interface Skill {
|
|
70
|
-
id: string;
|
|
71
|
-
name: string;
|
|
72
|
-
description: string;
|
|
73
|
-
version: string;
|
|
74
|
-
author?: string;
|
|
75
|
-
category?: string;
|
|
76
|
-
toolIds: string[];
|
|
77
|
-
variables: SkillVariable[];
|
|
78
|
-
installed: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface SkillVariable {
|
|
81
|
-
name: string;
|
|
82
|
-
type: string;
|
|
83
|
-
description: string;
|
|
84
|
-
required: boolean;
|
|
85
|
-
default?: unknown;
|
|
86
|
-
}
|
|
87
|
-
interface SkillResult {
|
|
88
|
-
success: boolean;
|
|
89
|
-
data?: unknown;
|
|
90
|
-
error?: string;
|
|
91
|
-
skillId: string;
|
|
92
|
-
toolResults?: ToolResult[];
|
|
93
|
-
}
|
|
94
69
|
type NotificationType = 'info' | 'success' | 'warning' | 'error';
|
|
95
70
|
interface FilePickerOptions {
|
|
96
71
|
type?: 'any' | 'image' | 'video' | 'audio' | 'custom';
|
|
@@ -155,10 +130,6 @@ interface ChatableXTools {
|
|
|
155
130
|
execute(toolId: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
156
131
|
executeWithConfirm(toolId: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
157
132
|
}
|
|
158
|
-
interface ChatableXSkills {
|
|
159
|
-
list(): Promise<Skill[]>;
|
|
160
|
-
execute(skillId: string, variables: Record<string, unknown>): Promise<SkillResult>;
|
|
161
|
-
}
|
|
162
133
|
interface ChatableXUI {
|
|
163
134
|
showNotification(message: string, type?: NotificationType): Promise<void>;
|
|
164
135
|
showConfirm(title: string, message: string): Promise<boolean>;
|
|
@@ -181,14 +152,18 @@ interface ChatableXToolModule {
|
|
|
181
152
|
getInfo(): ToolInfo;
|
|
182
153
|
onExecute(handler: ToolExecuteHandler): void;
|
|
183
154
|
}
|
|
155
|
+
interface ChatableXPlatform {
|
|
156
|
+
/** Open URL in system browser with auth handoff (WebView only; implemented by Flutter host). */
|
|
157
|
+
openInBrowser(targetUrl: string): Promise<void>;
|
|
158
|
+
}
|
|
184
159
|
interface ChatableXSDK {
|
|
185
160
|
ai: ChatableXAI;
|
|
186
161
|
tools: ChatableXTools;
|
|
187
|
-
skills: ChatableXSkills;
|
|
188
162
|
ui: ChatableXUI;
|
|
189
163
|
events: ChatableXEvents;
|
|
190
164
|
storage: ChatableXStorage;
|
|
191
165
|
tool: ChatableXToolModule;
|
|
166
|
+
platform: ChatableXPlatform;
|
|
192
167
|
}
|
|
193
168
|
declare global {
|
|
194
169
|
interface Window {
|
|
@@ -224,7 +199,7 @@ declare class Bridge {
|
|
|
224
199
|
/** Wait for ChatableXBridge (set by Flutter) to become available. */
|
|
225
200
|
waitForBridge(timeoutMs: number): Promise<void>;
|
|
226
201
|
/** Send a request to Flutter and wait for a response. */
|
|
227
|
-
sendMessage(method: string, params?:
|
|
202
|
+
sendMessage(method: string, params?: object, requestTimeoutMs?: number): Promise<unknown>;
|
|
228
203
|
private _handleResponse;
|
|
229
204
|
private _handleEvent;
|
|
230
205
|
addEventListener(eventType: string, handler: EventHandler): () => void;
|
|
@@ -255,7 +230,7 @@ declare class Bridge {
|
|
|
255
230
|
* ```
|
|
256
231
|
*/
|
|
257
232
|
|
|
258
|
-
declare const SDK_VERSION
|
|
233
|
+
declare const SDK_VERSION: string;
|
|
259
234
|
/**
|
|
260
235
|
* Main entry point. Provides `ChatableX.init()` to bootstrap the SDK.
|
|
261
236
|
*/
|
|
@@ -277,4 +252,4 @@ declare const ChatableX: {
|
|
|
277
252
|
version: string;
|
|
278
253
|
};
|
|
279
254
|
|
|
280
|
-
export { type AiResponseEventData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXEvents, type ChatableXInitConfig, type
|
|
255
|
+
export { type AiResponseEventData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };
|
package/dist/index.js
CHANGED
|
@@ -286,20 +286,82 @@ function createToolsModule(bridge) {
|
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
// src/modules/
|
|
290
|
-
function
|
|
289
|
+
// src/modules/platform.ts
|
|
290
|
+
function createPlatformModule(bridge) {
|
|
291
291
|
return {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
292
|
+
async openInBrowser(targetUrl) {
|
|
293
|
+
const url = typeof targetUrl === "string" ? targetUrl.trim() : "";
|
|
294
|
+
if (!url) {
|
|
295
|
+
throw new Error("openInBrowser: targetUrl is required");
|
|
296
|
+
}
|
|
297
|
+
await bridge.sendMessage("host.openInBrowser", { url });
|
|
297
298
|
}
|
|
298
299
|
};
|
|
299
300
|
}
|
|
300
301
|
|
|
302
|
+
// package.json
|
|
303
|
+
var package_default = {
|
|
304
|
+
name: "chatablex-web-sdk",
|
|
305
|
+
version: "1.0.3",
|
|
306
|
+
description: "ChatableX Web SDK for AI App WebUI development. Provides bridge communication with the ChatableX Flutter client.",
|
|
307
|
+
main: "dist/index.js",
|
|
308
|
+
module: "dist/index.mjs",
|
|
309
|
+
types: "dist/index.d.ts",
|
|
310
|
+
exports: {
|
|
311
|
+
".": {
|
|
312
|
+
types: "./dist/index.d.ts",
|
|
313
|
+
import: "./dist/index.mjs",
|
|
314
|
+
require: "./dist/index.js"
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
files: [
|
|
318
|
+
"dist",
|
|
319
|
+
"src",
|
|
320
|
+
"README.md",
|
|
321
|
+
"README.zh-CN.md"
|
|
322
|
+
],
|
|
323
|
+
scripts: {
|
|
324
|
+
build: "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
325
|
+
dev: "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
326
|
+
typecheck: "tsc --noEmit",
|
|
327
|
+
test: "vitest run",
|
|
328
|
+
"test:watch": "vitest",
|
|
329
|
+
"test:examples": "npm test --prefix examples/counter-app && npm test --prefix examples/todo-app",
|
|
330
|
+
"build:examples": "npm run build --prefix examples/counter-app && npm run build --prefix examples/todo-app",
|
|
331
|
+
"deploy:examples": "bash scripts/deploy-examples.sh",
|
|
332
|
+
"test:e2e": "node scripts/e2e-verify.mjs",
|
|
333
|
+
"verify:all": "npm test && npm run test:examples && npm run build:examples && npm run deploy:examples && npm run test:e2e",
|
|
334
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
335
|
+
prepublishOnly: "npm run build"
|
|
336
|
+
},
|
|
337
|
+
keywords: [
|
|
338
|
+
"chatablex",
|
|
339
|
+
"sdk",
|
|
340
|
+
"webui",
|
|
341
|
+
"ai",
|
|
342
|
+
"flutter",
|
|
343
|
+
"webview",
|
|
344
|
+
"bridge"
|
|
345
|
+
],
|
|
346
|
+
author: "ChatableX Team",
|
|
347
|
+
license: "MIT",
|
|
348
|
+
repository: {
|
|
349
|
+
type: "git",
|
|
350
|
+
url: "https://github.com/chatablex/chatablex-web-sdk.git"
|
|
351
|
+
},
|
|
352
|
+
devDependencies: {
|
|
353
|
+
jsdom: "^26.0.0",
|
|
354
|
+
tsup: "^8.0.1",
|
|
355
|
+
typescript: "^5.3.0",
|
|
356
|
+
vitest: "^3.0.0"
|
|
357
|
+
},
|
|
358
|
+
engines: {
|
|
359
|
+
node: ">=16.0.0"
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
301
363
|
// src/index.ts
|
|
302
|
-
var SDK_VERSION =
|
|
364
|
+
var SDK_VERSION = package_default.version;
|
|
303
365
|
var _instance = null;
|
|
304
366
|
var ChatableX = {
|
|
305
367
|
/**
|
|
@@ -335,11 +397,11 @@ var ChatableX = {
|
|
|
335
397
|
const sdk = {
|
|
336
398
|
ai: createAIModule(bridge),
|
|
337
399
|
tools: createToolsModule(bridge),
|
|
338
|
-
skills: createSkillsModule(bridge),
|
|
339
400
|
ui: createUIModule(bridge),
|
|
340
401
|
events: createEventsModule(bridge),
|
|
341
402
|
storage: createStorageModule(bridge),
|
|
342
|
-
tool: toolModule
|
|
403
|
+
tool: toolModule,
|
|
404
|
+
platform: createPlatformModule(bridge)
|
|
343
405
|
};
|
|
344
406
|
window.ChatableX = sdk;
|
|
345
407
|
_instance = sdk;
|
package/dist/index.mjs
CHANGED
|
@@ -258,20 +258,82 @@ function createToolsModule(bridge) {
|
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
// src/modules/
|
|
262
|
-
function
|
|
261
|
+
// src/modules/platform.ts
|
|
262
|
+
function createPlatformModule(bridge) {
|
|
263
263
|
return {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
async openInBrowser(targetUrl) {
|
|
265
|
+
const url = typeof targetUrl === "string" ? targetUrl.trim() : "";
|
|
266
|
+
if (!url) {
|
|
267
|
+
throw new Error("openInBrowser: targetUrl is required");
|
|
268
|
+
}
|
|
269
|
+
await bridge.sendMessage("host.openInBrowser", { url });
|
|
269
270
|
}
|
|
270
271
|
};
|
|
271
272
|
}
|
|
272
273
|
|
|
274
|
+
// package.json
|
|
275
|
+
var package_default = {
|
|
276
|
+
name: "chatablex-web-sdk",
|
|
277
|
+
version: "1.0.3",
|
|
278
|
+
description: "ChatableX Web SDK for AI App WebUI development. Provides bridge communication with the ChatableX Flutter client.",
|
|
279
|
+
main: "dist/index.js",
|
|
280
|
+
module: "dist/index.mjs",
|
|
281
|
+
types: "dist/index.d.ts",
|
|
282
|
+
exports: {
|
|
283
|
+
".": {
|
|
284
|
+
types: "./dist/index.d.ts",
|
|
285
|
+
import: "./dist/index.mjs",
|
|
286
|
+
require: "./dist/index.js"
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
files: [
|
|
290
|
+
"dist",
|
|
291
|
+
"src",
|
|
292
|
+
"README.md",
|
|
293
|
+
"README.zh-CN.md"
|
|
294
|
+
],
|
|
295
|
+
scripts: {
|
|
296
|
+
build: "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
297
|
+
dev: "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
298
|
+
typecheck: "tsc --noEmit",
|
|
299
|
+
test: "vitest run",
|
|
300
|
+
"test:watch": "vitest",
|
|
301
|
+
"test:examples": "npm test --prefix examples/counter-app && npm test --prefix examples/todo-app",
|
|
302
|
+
"build:examples": "npm run build --prefix examples/counter-app && npm run build --prefix examples/todo-app",
|
|
303
|
+
"deploy:examples": "bash scripts/deploy-examples.sh",
|
|
304
|
+
"test:e2e": "node scripts/e2e-verify.mjs",
|
|
305
|
+
"verify:all": "npm test && npm run test:examples && npm run build:examples && npm run deploy:examples && npm run test:e2e",
|
|
306
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
307
|
+
prepublishOnly: "npm run build"
|
|
308
|
+
},
|
|
309
|
+
keywords: [
|
|
310
|
+
"chatablex",
|
|
311
|
+
"sdk",
|
|
312
|
+
"webui",
|
|
313
|
+
"ai",
|
|
314
|
+
"flutter",
|
|
315
|
+
"webview",
|
|
316
|
+
"bridge"
|
|
317
|
+
],
|
|
318
|
+
author: "ChatableX Team",
|
|
319
|
+
license: "MIT",
|
|
320
|
+
repository: {
|
|
321
|
+
type: "git",
|
|
322
|
+
url: "https://github.com/chatablex/chatablex-web-sdk.git"
|
|
323
|
+
},
|
|
324
|
+
devDependencies: {
|
|
325
|
+
jsdom: "^26.0.0",
|
|
326
|
+
tsup: "^8.0.1",
|
|
327
|
+
typescript: "^5.3.0",
|
|
328
|
+
vitest: "^3.0.0"
|
|
329
|
+
},
|
|
330
|
+
engines: {
|
|
331
|
+
node: ">=16.0.0"
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
273
335
|
// src/index.ts
|
|
274
|
-
var SDK_VERSION =
|
|
336
|
+
var SDK_VERSION = package_default.version;
|
|
275
337
|
var _instance = null;
|
|
276
338
|
var ChatableX = {
|
|
277
339
|
/**
|
|
@@ -307,11 +369,11 @@ var ChatableX = {
|
|
|
307
369
|
const sdk = {
|
|
308
370
|
ai: createAIModule(bridge),
|
|
309
371
|
tools: createToolsModule(bridge),
|
|
310
|
-
skills: createSkillsModule(bridge),
|
|
311
372
|
ui: createUIModule(bridge),
|
|
312
373
|
events: createEventsModule(bridge),
|
|
313
374
|
storage: createStorageModule(bridge),
|
|
314
|
-
tool: toolModule
|
|
375
|
+
tool: toolModule,
|
|
376
|
+
platform: createPlatformModule(bridge)
|
|
315
377
|
};
|
|
316
378
|
window.ChatableX = sdk;
|
|
317
379
|
_instance = sdk;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chatablex-web-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "ChatableX Web SDK for AI App WebUI development. Provides bridge communication with the ChatableX Flutter client.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
23
23
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:examples": "npm test --prefix examples/counter-app && npm test --prefix examples/todo-app",
|
|
28
|
+
"build:examples": "npm run build --prefix examples/counter-app && npm run build --prefix examples/todo-app",
|
|
29
|
+
"deploy:examples": "bash scripts/deploy-examples.sh",
|
|
30
|
+
"test:e2e": "node scripts/e2e-verify.mjs",
|
|
31
|
+
"verify:all": "npm test && npm run test:examples && npm run build:examples && npm run deploy:examples && npm run test:e2e",
|
|
32
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
25
33
|
"prepublishOnly": "npm run build"
|
|
26
34
|
},
|
|
27
35
|
"keywords": [
|
|
@@ -37,12 +45,13 @@
|
|
|
37
45
|
"license": "MIT",
|
|
38
46
|
"repository": {
|
|
39
47
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
41
|
-
"directory": "chatablex-web-sdk"
|
|
48
|
+
"url": "https://github.com/chatablex/chatablex-web-sdk.git"
|
|
42
49
|
},
|
|
43
50
|
"devDependencies": {
|
|
51
|
+
"jsdom": "^26.0.0",
|
|
44
52
|
"tsup": "^8.0.1",
|
|
45
|
-
"typescript": "^5.3.0"
|
|
53
|
+
"typescript": "^5.3.0",
|
|
54
|
+
"vitest": "^3.0.0"
|
|
46
55
|
},
|
|
47
56
|
"engines": {
|
|
48
57
|
"node": ">=16.0.0"
|
package/src/bridge.ts
CHANGED
|
@@ -70,7 +70,7 @@ export class Bridge {
|
|
|
70
70
|
// -------------------------------------------------------------------------
|
|
71
71
|
|
|
72
72
|
/** Send a request to Flutter and wait for a response. */
|
|
73
|
-
sendMessage(method: string, params:
|
|
73
|
+
sendMessage(method: string, params: object = {}, requestTimeoutMs = 30_000): Promise<unknown> {
|
|
74
74
|
return new Promise((resolve, reject) => {
|
|
75
75
|
const id = this._nextId();
|
|
76
76
|
const message = { id, method, params, timestamp: Date.now() };
|
package/src/index.ts
CHANGED
|
@@ -25,10 +25,11 @@ import { createAIModule } from './modules/ai';
|
|
|
25
25
|
import { createUIModule } from './modules/ui';
|
|
26
26
|
import { createStorageModule } from './modules/storage';
|
|
27
27
|
import { createToolsModule } from './modules/tools';
|
|
28
|
-
import {
|
|
28
|
+
import { createPlatformModule } from './modules/platform';
|
|
29
29
|
import type { ChatableXSDK, ChatableXInitConfig, ToolInfo } from './types';
|
|
30
|
+
import pkg from '../package.json';
|
|
30
31
|
|
|
31
|
-
export const SDK_VERSION =
|
|
32
|
+
export const SDK_VERSION = pkg.version;
|
|
32
33
|
|
|
33
34
|
let _instance: ChatableXSDK | null = null;
|
|
34
35
|
|
|
@@ -80,11 +81,11 @@ export const ChatableX = {
|
|
|
80
81
|
const sdk: ChatableXSDK = {
|
|
81
82
|
ai: createAIModule(bridge),
|
|
82
83
|
tools: createToolsModule(bridge),
|
|
83
|
-
skills: createSkillsModule(bridge),
|
|
84
84
|
ui: createUIModule(bridge),
|
|
85
85
|
events: createEventsModule(bridge),
|
|
86
86
|
storage: createStorageModule(bridge),
|
|
87
87
|
tool: toolModule,
|
|
88
|
+
platform: createPlatformModule(bridge),
|
|
88
89
|
};
|
|
89
90
|
|
|
90
91
|
// Expose on window for debugging / Flutter interop
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Bridge } from '../bridge';
|
|
2
|
+
import type { ChatableXPlatform } from '../types';
|
|
3
|
+
|
|
4
|
+
export function createPlatformModule(bridge: Bridge): ChatableXPlatform {
|
|
5
|
+
return {
|
|
6
|
+
async openInBrowser(targetUrl: string): Promise<void> {
|
|
7
|
+
const url = typeof targetUrl === 'string' ? targetUrl.trim() : '';
|
|
8
|
+
if (!url) {
|
|
9
|
+
throw new Error('openInBrowser: targetUrl is required');
|
|
10
|
+
}
|
|
11
|
+
await bridge.sendMessage('host.openInBrowser', { url });
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
package/src/modules/ui.ts
CHANGED
|
@@ -16,11 +16,11 @@ export function createUIModule(bridge: Bridge): ChatableXUI {
|
|
|
16
16
|
},
|
|
17
17
|
|
|
18
18
|
openTab(config: TabConfig): Promise<void> {
|
|
19
|
-
return bridge.sendMessage('ui.openTab', config
|
|
19
|
+
return bridge.sendMessage('ui.openTab', config) as Promise<void>;
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
updateState(state: StateUpdate): Promise<void> {
|
|
23
|
-
return bridge.sendMessage('ui.updateState', state
|
|
23
|
+
return bridge.sendMessage('ui.updateState', state) as Promise<void>;
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
26
|
}
|
package/src/types.ts
CHANGED
|
@@ -80,38 +80,6 @@ export interface ToolResult {
|
|
|
80
80
|
|
|
81
81
|
export type ToolExecuteHandler = (params: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
82
82
|
|
|
83
|
-
// ---------------------------------------------------------------------------
|
|
84
|
-
// Skill
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
|
|
87
|
-
export interface Skill {
|
|
88
|
-
id: string;
|
|
89
|
-
name: string;
|
|
90
|
-
description: string;
|
|
91
|
-
version: string;
|
|
92
|
-
author?: string;
|
|
93
|
-
category?: string;
|
|
94
|
-
toolIds: string[];
|
|
95
|
-
variables: SkillVariable[];
|
|
96
|
-
installed: boolean;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface SkillVariable {
|
|
100
|
-
name: string;
|
|
101
|
-
type: string;
|
|
102
|
-
description: string;
|
|
103
|
-
required: boolean;
|
|
104
|
-
default?: unknown;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface SkillResult {
|
|
108
|
-
success: boolean;
|
|
109
|
-
data?: unknown;
|
|
110
|
-
error?: string;
|
|
111
|
-
skillId: string;
|
|
112
|
-
toolResults?: ToolResult[];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
83
|
// ---------------------------------------------------------------------------
|
|
116
84
|
// UI
|
|
117
85
|
// ---------------------------------------------------------------------------
|
|
@@ -211,11 +179,6 @@ export interface ChatableXTools {
|
|
|
211
179
|
executeWithConfirm(toolId: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
212
180
|
}
|
|
213
181
|
|
|
214
|
-
export interface ChatableXSkills {
|
|
215
|
-
list(): Promise<Skill[]>;
|
|
216
|
-
execute(skillId: string, variables: Record<string, unknown>): Promise<SkillResult>;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
182
|
export interface ChatableXUI {
|
|
220
183
|
showNotification(message: string, type?: NotificationType): Promise<void>;
|
|
221
184
|
showConfirm(title: string, message: string): Promise<boolean>;
|
|
@@ -242,14 +205,19 @@ export interface ChatableXToolModule {
|
|
|
242
205
|
onExecute(handler: ToolExecuteHandler): void;
|
|
243
206
|
}
|
|
244
207
|
|
|
208
|
+
export interface ChatableXPlatform {
|
|
209
|
+
/** Open URL in system browser with auth handoff (WebView only; implemented by Flutter host). */
|
|
210
|
+
openInBrowser(targetUrl: string): Promise<void>;
|
|
211
|
+
}
|
|
212
|
+
|
|
245
213
|
export interface ChatableXSDK {
|
|
246
214
|
ai: ChatableXAI;
|
|
247
215
|
tools: ChatableXTools;
|
|
248
|
-
skills: ChatableXSkills;
|
|
249
216
|
ui: ChatableXUI;
|
|
250
217
|
events: ChatableXEvents;
|
|
251
218
|
storage: ChatableXStorage;
|
|
252
219
|
tool: ChatableXToolModule;
|
|
220
|
+
platform: ChatableXPlatform;
|
|
253
221
|
}
|
|
254
222
|
|
|
255
223
|
// ---------------------------------------------------------------------------
|
package/src/modules/skills.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Bridge } from '../bridge';
|
|
2
|
-
import type { Skill, SkillResult, ChatableXSkills } from '../types';
|
|
3
|
-
|
|
4
|
-
export function createSkillsModule(bridge: Bridge): ChatableXSkills {
|
|
5
|
-
return {
|
|
6
|
-
list(): Promise<Skill[]> {
|
|
7
|
-
return bridge.sendMessage('skills.list', {}) as Promise<Skill[]>;
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
execute(skillId: string, variables: Record<string, unknown>): Promise<SkillResult> {
|
|
11
|
-
return bridge.sendMessage('skills.execute', { skillId, variables }) as Promise<SkillResult>;
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|