@cleanslice/bridle 0.2.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/README.md +103 -0
- package/dist/bridle.js +29 -0
- package/dist/bridle.js.map +1 -0
- package/dist/bridle.mjs +8093 -0
- package/dist/bridle.mjs.map +1 -0
- package/dist/client.d.ts +45 -0
- package/dist/index.d.ts +9 -0
- package/dist/types.d.ts +73 -0
- package/package.json +60 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BridlePart, IBridleMessage } from './types';
|
|
2
|
+
export interface IBridleClientOptions {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
botId: string;
|
|
5
|
+
/**
|
|
6
|
+
* JWT for authenticated bots. Omit when the bot is public on the hub —
|
|
7
|
+
* the connection is then authorized by the request `Origin` header.
|
|
8
|
+
*/
|
|
9
|
+
token?: string | (() => string | Promise<string>);
|
|
10
|
+
/** Optional channel for transcript scoping (default: 'web'). */
|
|
11
|
+
channel?: string;
|
|
12
|
+
}
|
|
13
|
+
type EventName = 'open' | 'close' | 'error' | 'typing' | 'message' | 'stream' | 'stream_end' | 'welcome';
|
|
14
|
+
type Listener<T = unknown> = (payload: T) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Headless Bridle client. Use this directly when you want the wire-level
|
|
17
|
+
* behavior (connect / send / stream) without the embedded UI.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const client = new BridleClient({ apiUrl, botId, token })
|
|
21
|
+
* client.on('message', (m) => console.log(m.text))
|
|
22
|
+
* await client.connect()
|
|
23
|
+
* client.send('hello')
|
|
24
|
+
*/
|
|
25
|
+
export declare class BridleClient {
|
|
26
|
+
private opts;
|
|
27
|
+
private socket;
|
|
28
|
+
private listeners;
|
|
29
|
+
private clientId;
|
|
30
|
+
constructor(opts: IBridleClientOptions);
|
|
31
|
+
connect(): Promise<void>;
|
|
32
|
+
send(text: string, parts?: BridlePart[]): void;
|
|
33
|
+
disconnect(): void;
|
|
34
|
+
on(event: 'open' | 'close' | 'typing', handler: () => void): void;
|
|
35
|
+
on(event: 'error', handler: (error: Error) => void): void;
|
|
36
|
+
on(event: 'welcome', handler: (data: {
|
|
37
|
+
clientId: string;
|
|
38
|
+
}) => void): void;
|
|
39
|
+
on(event: 'message' | 'stream' | 'stream_end', handler: (message: IBridleMessage) => void): void;
|
|
40
|
+
off(event: EventName, handler: Listener): void;
|
|
41
|
+
/** Server-assigned id of this browser session (set after the welcome event). */
|
|
42
|
+
getClientId(): string | null;
|
|
43
|
+
private fire;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BridleClient } from './client';
|
|
2
|
+
import type { IBridleInitOptions, IBridleInstance } from './types';
|
|
3
|
+
declare function init(opts: IBridleInitOptions): IBridleInstance;
|
|
4
|
+
/** Tag name of the registered Custom Element. */
|
|
5
|
+
export declare const tag = "bridle-chat";
|
|
6
|
+
/** SDK version, replaced at build time from package.json. */
|
|
7
|
+
export declare const version: string;
|
|
8
|
+
export { init, BridleClient };
|
|
9
|
+
export type { BridlePart, IBridleMessage, IBridleInitOptions, IBridleInstance, } from './types';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type BridlePart = {
|
|
2
|
+
type: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'image';
|
|
6
|
+
base64: string;
|
|
7
|
+
mediaType: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'file';
|
|
10
|
+
url: string;
|
|
11
|
+
name: string;
|
|
12
|
+
mimeType?: string;
|
|
13
|
+
};
|
|
14
|
+
export interface IBridleMessage {
|
|
15
|
+
id: string;
|
|
16
|
+
role: 'user' | 'assistant';
|
|
17
|
+
text: string;
|
|
18
|
+
parts: BridlePart[];
|
|
19
|
+
ts: number;
|
|
20
|
+
/** True between `stream` and `stream_end` events. */
|
|
21
|
+
streaming?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface IBridleInitOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Hub origin, e.g. `https://hub.example.com`. If omitted, the SDK infers it
|
|
26
|
+
* from the origin of the loading <script> tag — only works when the SDK is
|
|
27
|
+
* served from the same origin as the hub.
|
|
28
|
+
*/
|
|
29
|
+
apiUrl?: string;
|
|
30
|
+
/** Bot identifier registered on the hub (`BRIDLE_BOT_ID` on the agent). */
|
|
31
|
+
botId: string;
|
|
32
|
+
/**
|
|
33
|
+
* JWT used to authenticate the browser to the hub. Pass a string for static
|
|
34
|
+
* tokens, or a function returning a string/Promise<string> for refresh.
|
|
35
|
+
* Omit when the bot is configured as public on the hub — the hub will
|
|
36
|
+
* accept the connection based on the request `Origin` header.
|
|
37
|
+
*/
|
|
38
|
+
token?: string | (() => string | Promise<string>);
|
|
39
|
+
/**
|
|
40
|
+
* Where to mount the chat element. Defaults to <body>.
|
|
41
|
+
* Accepts a CSS selector string or an HTMLElement.
|
|
42
|
+
*/
|
|
43
|
+
mount?: string | HTMLElement;
|
|
44
|
+
/**
|
|
45
|
+
* Floating bubble in the corner (default) or inline inside `mount`.
|
|
46
|
+
*/
|
|
47
|
+
mode?: 'floating' | 'inline';
|
|
48
|
+
/** Header text. Default: "Agent Chat". */
|
|
49
|
+
title?: string;
|
|
50
|
+
/** Input placeholder. Default: "Type a message...". */
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Theme overrides — any of the documented CSS custom properties.
|
|
54
|
+
* Example: `{ '--bridle-primary': '#0070f3' }`.
|
|
55
|
+
*/
|
|
56
|
+
theme?: Record<string, string>;
|
|
57
|
+
/** Hooks for headless side effects in addition to the UI. */
|
|
58
|
+
onReady?: () => void;
|
|
59
|
+
onMessage?: (message: IBridleMessage) => void;
|
|
60
|
+
onError?: (error: Error) => void;
|
|
61
|
+
}
|
|
62
|
+
export interface IBridleInstance {
|
|
63
|
+
/** Underlying custom element. Useful for further DOM manipulation. */
|
|
64
|
+
element: HTMLElement;
|
|
65
|
+
/** Open the panel (floating mode). */
|
|
66
|
+
open: () => void;
|
|
67
|
+
/** Close the panel (floating mode). */
|
|
68
|
+
close: () => void;
|
|
69
|
+
/** Programmatically send a user message. */
|
|
70
|
+
sendMessage: (text: string) => void;
|
|
71
|
+
/** Tear down the widget and disconnect. */
|
|
72
|
+
destroy: () => void;
|
|
73
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cleanslice/bridle",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Embeddable web chat for Bridle — drop-in <script> or programmatic init.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/bridle.mjs",
|
|
7
|
+
"module": "./dist/bridle.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"unpkg": "./dist/bridle.js",
|
|
10
|
+
"jsdelivr": "./dist/bridle.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/bridle.mjs",
|
|
15
|
+
"default": "./dist/bridle.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./browser": "./dist/bridle.js",
|
|
18
|
+
"./client": {
|
|
19
|
+
"types": "./dist/client.d.ts",
|
|
20
|
+
"import": "./dist/client.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": ["dist", "README.md"],
|
|
24
|
+
"sideEffects": ["./dist/bridle.js"],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"dev": "vite build --watch",
|
|
30
|
+
"build": "vite build && tsc -p tsconfig.dts.json",
|
|
31
|
+
"typecheck": "vue-tsc --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"socket.io-client": "^4.7.5",
|
|
35
|
+
"vue": "^3.5.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
39
|
+
"typescript": "^5.4.0",
|
|
40
|
+
"vite": "^5.4.0",
|
|
41
|
+
"vue-tsc": "^2.0.0"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"bridle",
|
|
45
|
+
"cleanslice",
|
|
46
|
+
"chat",
|
|
47
|
+
"agent",
|
|
48
|
+
"embed",
|
|
49
|
+
"widget",
|
|
50
|
+
"web-component",
|
|
51
|
+
"socket.io"
|
|
52
|
+
],
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"homepage": "https://bridle.cleanslice.org",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/CleanSlice/bridle.git",
|
|
58
|
+
"directory": "sdk"
|
|
59
|
+
}
|
|
60
|
+
}
|