@tung-engineering/agent-platform-web-sdk 0.0.78 → 0.0.81
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 +132 -0
- package/dist/web-sdk.cjs +124 -85
- package/dist/web-sdk.cjs.map +1 -1
- package/dist/web-sdk.min.js +114 -75
- package/dist/web-sdk.min.js.map +1 -1
- package/dist/web-sdk.mjs +2253 -2197
- package/dist/web-sdk.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @tung-engineering/agent-platform-web-sdk
|
|
2
|
+
|
|
3
|
+
Embeddable Web SDK for [Agent Platform](https://agent-platform.tung.engineering). Drop it into any web page to get a floating capture button that turns any element — or any recorded click-through flow — into an Agent Platform task or planning session, without leaving the page you're looking at.
|
|
4
|
+
|
|
5
|
+
- 🖱️ **Element picker** — click the capture button, then click any element on the page to attach it (with surrounding DOM context) to a new task or planning session
|
|
6
|
+
- ⏺️ **Interaction recorder** — record a multi-step click-through flow and turn the whole sequence into a browser-automation task
|
|
7
|
+
- 🤖 **Automation runner** — a floating panel that streams a running task's browser actions live, with per-step approve/answer prompts when the agent needs input
|
|
8
|
+
- 📋 **Captures list** — a running list of everything captured from the current browser, with unread/status badges
|
|
9
|
+
- 🔒 **Secure by design** — connects via a short-lived, OAuth2-style token exchange; your long-lived Agent Platform API token is never entered into or stored by the SDK
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @tung-engineering/agent-platform-web-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Node.js is only used to install the package — the SDK itself is a browser-only, zero-dependency-at-runtime bundle (its few dependencies are bundled in).
|
|
18
|
+
|
|
19
|
+
## Quick start (npm package)
|
|
20
|
+
|
|
21
|
+
**1. Import and initialize.** `init()` needs your project's short code and, to actually connect to a backend, a `backendUrl` + short-lived `token` (see [Getting a token](#getting-a-token) below — you can skip both and use the built-in connect UI instead, see step 3).
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { init } from '@tung-engineering/agent-platform-web-sdk';
|
|
25
|
+
|
|
26
|
+
await init({
|
|
27
|
+
projectCode: 'YOUR_PROJECT_CODE',
|
|
28
|
+
backendUrl: 'https://your-agent-platform-instance.example.com',
|
|
29
|
+
token: sdkToken, // short-lived SDK token, see "Getting a token"
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This injects the SDK's styles and shows a floating capture button (FAB) in the bottom-right corner of the page.
|
|
34
|
+
|
|
35
|
+
**2. Use the picker.** Click the FAB, then click any element on the page — a capture panel opens letting you turn that element into a task or planning session in your Agent Platform project. This also works from your own code:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { activateElementPicker } from '@tung-engineering/agent-platform-web-sdk';
|
|
39
|
+
|
|
40
|
+
activateElementPicker(); // same as clicking the FAB yourself
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**3. Or skip the token exchange — use the built-in connect UI.** If you don't already have a short-lived token (e.g. building an internal tool, not shipping a hardcoded token to end users), call `configure()` instead of `init()`. It opens a small panel where the user enters your backend URL, signs in via a popup, and picks a project — the SDK stores the resulting short-lived token in `sessionStorage` and initializes itself:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { configure } from '@tung-engineering/agent-platform-web-sdk';
|
|
47
|
+
|
|
48
|
+
configure(); // opens the "Connect to Agent Platform" panel
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**4. Clean up when you're done** (e.g. on route change in an SPA):
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { destroy } from '@tung-engineering/agent-platform-web-sdk';
|
|
55
|
+
|
|
56
|
+
destroy(); // removes the FAB, closes any open panels, tears down listeners
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick start (script tag, no build step)
|
|
60
|
+
|
|
61
|
+
You can also load the SDK directly from your Agent Platform backend without installing anything:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script src="https://your-agent-platform-instance.example.com/web-sdk/web-sdk.min.js"></script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This self-boots: it looks for a saved connection in `sessionStorage` and either restores it (showing a ready-to-use FAB) or shows the FAB in "click to connect" mode. Once loaded, the same API is available on `window.AgentPlatformWebSdk`:
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<script>
|
|
71
|
+
// Open the connect panel (same flow as configure() above)
|
|
72
|
+
AgentPlatformWebSdk.configure();
|
|
73
|
+
|
|
74
|
+
// Or connect programmatically with a token obtained out-of-band
|
|
75
|
+
AgentPlatformWebSdk.init({
|
|
76
|
+
projectCode: 'YOUR_PROJECT_CODE',
|
|
77
|
+
backendUrl: 'https://your-agent-platform-instance.example.com',
|
|
78
|
+
token: sdkToken,
|
|
79
|
+
});
|
|
80
|
+
</script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Getting a token
|
|
84
|
+
|
|
85
|
+
The SDK never accepts or stores a long-lived personal API token. There are two ways to get the short-lived token `init()` expects:
|
|
86
|
+
|
|
87
|
+
1. **Interactive (recommended for most integrations)** — call `configure()` / `AgentPlatformWebSdk.configure()`. It opens a popup to your Agent Platform instance's own sign-in/consent screen, receives a single-use authorization code via `postMessage`, and exchanges it for a short-lived SDK token automatically. Nothing to implement on your end.
|
|
88
|
+
2. **Out-of-band (for pre-authenticated embeds)** — have your own backend perform the same authorization-code exchange (`POST /auth/tokens/exchange-code` on your Agent Platform instance) and pass the resulting token straight into `init({ token })`.
|
|
89
|
+
|
|
90
|
+
Either way, the token is short-lived and is only ever persisted to `sessionStorage` — closing the browser/tab always requires reconnecting.
|
|
91
|
+
|
|
92
|
+
## API reference
|
|
93
|
+
|
|
94
|
+
| Export | Description |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `init(options: SdkOptions): Promise<void>` | Initializes the SDK and shows the FAB. Safe to call again with the same options (no-op). |
|
|
97
|
+
| `updateCredentials(backendUrl: string, token: string): Promise<void>` | Swaps the backend URL / token on an already-initialized SDK (e.g. after a token refresh). |
|
|
98
|
+
| `configure(): void` | Opens the built-in "Connect to Agent Platform" panel; saves the result and calls `init()` for you. |
|
|
99
|
+
| `clearConfig(): void` | Clears saved credentials from `sessionStorage` and tears down the SDK back to setup mode. |
|
|
100
|
+
| `activateElementPicker(): void` / `deactivateElementPicker(): void` | Starts/stops the element picker without clicking the FAB. |
|
|
101
|
+
| `isPickerRunning(): boolean` | Whether the element picker is currently active. |
|
|
102
|
+
| `showFab(): void` / `hideFab(): void` | Show/hide the floating buttons without tearing down the rest of the SDK. |
|
|
103
|
+
| `destroy(): void` | Fully tears down the SDK: removes the FAB, closes any open panel, stops all listeners. |
|
|
104
|
+
| `autoInit(): void` | Runs automatically when the script-tag bundle is loaded; not meant to be called from the npm import. |
|
|
105
|
+
|
|
106
|
+
`SdkOptions`:
|
|
107
|
+
|
|
108
|
+
| Field | Type | Required | Description |
|
|
109
|
+
|---|---|---|---|
|
|
110
|
+
| `projectCode` | `string` | yes | Short, human-readable project code (e.g. `"AP"`). |
|
|
111
|
+
| `backendUrl` | `string` | no | Base URL of your Agent Platform backend. Omit to boot in "click to connect" mode. |
|
|
112
|
+
| `token` | `string` | no | Short-lived SDK token (see [Getting a token](#getting-a-token)). Omit to boot in "click to connect" mode. |
|
|
113
|
+
|
|
114
|
+
## TypeScript
|
|
115
|
+
|
|
116
|
+
Type declarations ship with the package — no `@types/...` package needed.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { init, type SdkOptions } from '@tung-engineering/agent-platform-web-sdk';
|
|
120
|
+
|
|
121
|
+
const options: SdkOptions = {
|
|
122
|
+
projectCode: 'YOUR_PROJECT_CODE',
|
|
123
|
+
backendUrl: 'https://your-agent-platform-instance.example.com',
|
|
124
|
+
token: sdkToken,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
await init(options);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Browser support
|
|
131
|
+
|
|
132
|
+
The SDK is browser-only — it reads `window`/`document`/`sessionStorage`/`localStorage` at call time and is a no-op in non-browser environments (safe to import in an SSR/isomorphic build; just don't call `init()`/`configure()` on the server).
|