@prodact.ai/sdk 0.0.2
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/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/index.d.mts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +509 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +481 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +244 -0
- package/dist/react.d.ts +244 -0
- package/dist/react.js +1116 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +1072 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Viam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @viam/sdk
|
|
2
|
+
|
|
3
|
+
Interactive SDK for Viam - AI-powered UI interactions triggered by chat.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @viam/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### React
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { ViamProvider, ViamChat, useViamAction } from '@viam/sdk/react';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<ViamProvider
|
|
21
|
+
config={{
|
|
22
|
+
guiderId: 'your-guider-id',
|
|
23
|
+
apiUrl: 'https://api.viam.io/api/v1', // optional
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<MyApp />
|
|
27
|
+
<ViamChat position="bottom-right" />
|
|
28
|
+
</ViamProvider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ContactButton() {
|
|
33
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
34
|
+
|
|
35
|
+
// Register action - when user asks "open contact modal", this triggers
|
|
36
|
+
useViamAction('act_contact_xyz123', () => {
|
|
37
|
+
setIsOpen(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<button onClick={() => setIsOpen(true)}>Contact Us</button>
|
|
43
|
+
{isOpen && <ContactModal onClose={() => setIsOpen(false)} />}
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Using ViamTarget
|
|
50
|
+
|
|
51
|
+
Wrap elements to auto-highlight and scroll when triggered:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { ViamTarget } from '@viam/sdk/react';
|
|
55
|
+
|
|
56
|
+
function PricingSection() {
|
|
57
|
+
return (
|
|
58
|
+
<ViamTarget
|
|
59
|
+
actionKey="act_pricing_abc123"
|
|
60
|
+
onTrigger={() => console.log('User was directed to pricing!')}
|
|
61
|
+
>
|
|
62
|
+
<div className="pricing-section">
|
|
63
|
+
<h2>Pricing</h2>
|
|
64
|
+
{/* ... */}
|
|
65
|
+
</div>
|
|
66
|
+
</ViamTarget>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Vanilla JavaScript
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import { createViam } from '@viam/sdk';
|
|
75
|
+
|
|
76
|
+
const viam = createViam({
|
|
77
|
+
guiderId: 'your-guider-id',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Initialize
|
|
81
|
+
await viam.init();
|
|
82
|
+
|
|
83
|
+
// Register actions
|
|
84
|
+
viam.register('act_contact_xyz123', (payload) => {
|
|
85
|
+
document.getElementById('contact-modal').classList.add('open');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Send a message
|
|
89
|
+
const response = await viam.sendMessage('How do I contact support?');
|
|
90
|
+
// If message matches "contact" action, it will trigger automatically
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### ViamProvider Props
|
|
96
|
+
|
|
97
|
+
| Prop | Type | Description |
|
|
98
|
+
|------|------|-------------|
|
|
99
|
+
| `config.guiderId` | `string` | Your Viam guider ID (required) |
|
|
100
|
+
| `config.apiUrl` | `string` | API URL (default: `http://localhost:4001/api/v1`) |
|
|
101
|
+
| `onAction` | `(key, payload) => void` | Called when any action is triggered |
|
|
102
|
+
| `onError` | `(error) => void` | Called on errors |
|
|
103
|
+
|
|
104
|
+
### ViamChat Props
|
|
105
|
+
|
|
106
|
+
| Prop | Type | Default | Description |
|
|
107
|
+
|------|------|---------|-------------|
|
|
108
|
+
| `position` | `'bottom-right' \| 'bottom-left' \| 'inline'` | `'bottom-right'` | Chat widget position |
|
|
109
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | Color theme |
|
|
110
|
+
| `primaryColor` | `string` | `'#f97316'` | Primary accent color |
|
|
111
|
+
| `title` | `string` | `'Chat Assistant'` | Chat header title |
|
|
112
|
+
| `placeholder` | `string` | `'Ask a question...'` | Input placeholder |
|
|
113
|
+
|
|
114
|
+
### Hooks
|
|
115
|
+
|
|
116
|
+
#### `useViam()`
|
|
117
|
+
Returns the full Viam context with SDK instance, messages, and methods.
|
|
118
|
+
|
|
119
|
+
#### `useViamAction(actionKey, handler, deps?)`
|
|
120
|
+
Register an action handler that fires when the AI triggers this action.
|
|
121
|
+
|
|
122
|
+
#### `useViamMessages()`
|
|
123
|
+
Returns `{ messages, isLoading, sendMessage }` for building custom chat UIs.
|
|
124
|
+
|
|
125
|
+
#### `useViamReady()`
|
|
126
|
+
Returns `boolean` indicating if SDK is initialized.
|
|
127
|
+
|
|
128
|
+
### ViamTarget Props
|
|
129
|
+
|
|
130
|
+
| Prop | Type | Description |
|
|
131
|
+
|------|------|-------------|
|
|
132
|
+
| `actionKey` | `string` | The action key to respond to (required) |
|
|
133
|
+
| `onTrigger` | `(payload) => void` | Called when action is triggered |
|
|
134
|
+
| `highlightStyle` | `CSSProperties` | Custom highlight styles |
|
|
135
|
+
| `highlightDuration` | `number` | How long to highlight (ms, default: 3000) |
|
|
136
|
+
| `scrollIntoView` | `boolean` | Auto-scroll to element (default: true) |
|
|
137
|
+
|
|
138
|
+
## Setting Up Actions
|
|
139
|
+
|
|
140
|
+
1. Go to your Viam dashboard
|
|
141
|
+
2. Navigate to your Guider → SDK tab
|
|
142
|
+
3. Enable SDK integration
|
|
143
|
+
4. Create actions with trigger prompts:
|
|
144
|
+
- Name: "Open Contact Modal"
|
|
145
|
+
- Prompts: "contact support", "get in touch", "talk to someone"
|
|
146
|
+
5. Copy the generated action key (e.g., `act_contact_x7y8z9`)
|
|
147
|
+
6. Use the key in your code with `useViamAction` or `viam.register()`
|
|
148
|
+
|
|
149
|
+
## How It Works
|
|
150
|
+
|
|
151
|
+
1. User types a message in the chat
|
|
152
|
+
2. AI analyzes if message matches any configured SDK action
|
|
153
|
+
3. If matched, the registered handler is called
|
|
154
|
+
4. Chat displays a response confirming the action
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
interface ProduckConfig {
|
|
2
|
+
guiderId?: string;
|
|
3
|
+
sdkKey?: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
onAction?: (actionKey: string, action: ActionPayload) => void;
|
|
6
|
+
onMessage?: (message: ChatMessage) => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
onFlowStart?: (flow: FlowPayload) => void;
|
|
9
|
+
onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
|
|
10
|
+
onFlowComplete?: (result: FlowResult) => void;
|
|
11
|
+
}
|
|
12
|
+
interface ActionPayload {
|
|
13
|
+
actionKey: string;
|
|
14
|
+
name: string;
|
|
15
|
+
actionType: string;
|
|
16
|
+
actionConfig: Record<string, any>;
|
|
17
|
+
responseMessage?: string;
|
|
18
|
+
}
|
|
19
|
+
interface FlowStep {
|
|
20
|
+
operationId: string;
|
|
21
|
+
order: number;
|
|
22
|
+
condition?: Record<string, any>;
|
|
23
|
+
inputMapping?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
interface FlowPayload {
|
|
26
|
+
flowId: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
steps: FlowStep[];
|
|
30
|
+
}
|
|
31
|
+
interface FlowStepResult {
|
|
32
|
+
operationId: string;
|
|
33
|
+
order: number;
|
|
34
|
+
success: boolean;
|
|
35
|
+
data?: any;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
interface FlowResult {
|
|
39
|
+
flowId: string;
|
|
40
|
+
name: string;
|
|
41
|
+
steps: FlowStepResult[];
|
|
42
|
+
completed: boolean;
|
|
43
|
+
totalSteps: number;
|
|
44
|
+
successfulSteps: number;
|
|
45
|
+
}
|
|
46
|
+
interface ChatMessage {
|
|
47
|
+
role: 'user' | 'assistant';
|
|
48
|
+
content: string;
|
|
49
|
+
action?: ActionPayload;
|
|
50
|
+
flow?: FlowPayload;
|
|
51
|
+
flowResult?: FlowResult;
|
|
52
|
+
}
|
|
53
|
+
interface ActionHandler {
|
|
54
|
+
(payload: ActionPayload): void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
interface RegisteredAction {
|
|
57
|
+
key: string;
|
|
58
|
+
handler: ActionHandler;
|
|
59
|
+
}
|
|
60
|
+
type ProduckEventType = 'action' | 'message' | 'error' | 'ready' | 'flowStart' | 'flowStepComplete' | 'flowComplete';
|
|
61
|
+
interface ProduckEvent {
|
|
62
|
+
type: ProduckEventType;
|
|
63
|
+
data: any;
|
|
64
|
+
}
|
|
65
|
+
declare class ProduckSDK {
|
|
66
|
+
private config;
|
|
67
|
+
private actions;
|
|
68
|
+
private eventListeners;
|
|
69
|
+
private sessionToken;
|
|
70
|
+
private isReady;
|
|
71
|
+
constructor(config: ProduckConfig);
|
|
72
|
+
/**
|
|
73
|
+
* Initialize the SDK and create a chat session
|
|
74
|
+
*/
|
|
75
|
+
init(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Register an action handler
|
|
78
|
+
*/
|
|
79
|
+
register(actionKey: string, handler: ActionHandler): void;
|
|
80
|
+
/**
|
|
81
|
+
* Unregister an action handler
|
|
82
|
+
*/
|
|
83
|
+
unregister(actionKey: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Send a message and handle potential action or flow triggers
|
|
86
|
+
*/
|
|
87
|
+
sendMessage(message: string): Promise<ChatMessage>;
|
|
88
|
+
/**
|
|
89
|
+
* Execute a flow by running each step's operation sequentially
|
|
90
|
+
*/
|
|
91
|
+
executeFlow(flow: FlowPayload): Promise<FlowResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Send log data to backend for analytics
|
|
94
|
+
*/
|
|
95
|
+
private sendLogToBackend;
|
|
96
|
+
/**
|
|
97
|
+
* Send detailed log to backend
|
|
98
|
+
*/
|
|
99
|
+
private log;
|
|
100
|
+
/**
|
|
101
|
+
* Execute a registered action
|
|
102
|
+
*/
|
|
103
|
+
private executeAction;
|
|
104
|
+
/**
|
|
105
|
+
* Add event listener
|
|
106
|
+
*/
|
|
107
|
+
on(event: ProduckEventType, callback: Function): void;
|
|
108
|
+
/**
|
|
109
|
+
* Remove event listener
|
|
110
|
+
*/
|
|
111
|
+
off(event: ProduckEventType, callback: Function): void;
|
|
112
|
+
/**
|
|
113
|
+
* Emit event
|
|
114
|
+
*/
|
|
115
|
+
private emit;
|
|
116
|
+
/**
|
|
117
|
+
* Get session token
|
|
118
|
+
*/
|
|
119
|
+
getSessionToken(): string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Check if SDK is ready
|
|
122
|
+
*/
|
|
123
|
+
getIsReady(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Get registered action keys
|
|
126
|
+
*/
|
|
127
|
+
getRegisteredActions(): string[];
|
|
128
|
+
/**
|
|
129
|
+
* Destroy the SDK instance
|
|
130
|
+
*/
|
|
131
|
+
destroy(): void;
|
|
132
|
+
}
|
|
133
|
+
declare function createProduck(config: ProduckConfig): ProduckSDK;
|
|
134
|
+
|
|
135
|
+
export { type ActionHandler, type ActionPayload, type ChatMessage, type FlowPayload, type FlowResult, type FlowStep, type FlowStepResult, type ProduckConfig, type ProduckEvent, type ProduckEventType, ProduckSDK, type RegisteredAction, createProduck };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
interface ProduckConfig {
|
|
2
|
+
guiderId?: string;
|
|
3
|
+
sdkKey?: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
onAction?: (actionKey: string, action: ActionPayload) => void;
|
|
6
|
+
onMessage?: (message: ChatMessage) => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
onFlowStart?: (flow: FlowPayload) => void;
|
|
9
|
+
onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
|
|
10
|
+
onFlowComplete?: (result: FlowResult) => void;
|
|
11
|
+
}
|
|
12
|
+
interface ActionPayload {
|
|
13
|
+
actionKey: string;
|
|
14
|
+
name: string;
|
|
15
|
+
actionType: string;
|
|
16
|
+
actionConfig: Record<string, any>;
|
|
17
|
+
responseMessage?: string;
|
|
18
|
+
}
|
|
19
|
+
interface FlowStep {
|
|
20
|
+
operationId: string;
|
|
21
|
+
order: number;
|
|
22
|
+
condition?: Record<string, any>;
|
|
23
|
+
inputMapping?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
interface FlowPayload {
|
|
26
|
+
flowId: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
steps: FlowStep[];
|
|
30
|
+
}
|
|
31
|
+
interface FlowStepResult {
|
|
32
|
+
operationId: string;
|
|
33
|
+
order: number;
|
|
34
|
+
success: boolean;
|
|
35
|
+
data?: any;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
interface FlowResult {
|
|
39
|
+
flowId: string;
|
|
40
|
+
name: string;
|
|
41
|
+
steps: FlowStepResult[];
|
|
42
|
+
completed: boolean;
|
|
43
|
+
totalSteps: number;
|
|
44
|
+
successfulSteps: number;
|
|
45
|
+
}
|
|
46
|
+
interface ChatMessage {
|
|
47
|
+
role: 'user' | 'assistant';
|
|
48
|
+
content: string;
|
|
49
|
+
action?: ActionPayload;
|
|
50
|
+
flow?: FlowPayload;
|
|
51
|
+
flowResult?: FlowResult;
|
|
52
|
+
}
|
|
53
|
+
interface ActionHandler {
|
|
54
|
+
(payload: ActionPayload): void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
interface RegisteredAction {
|
|
57
|
+
key: string;
|
|
58
|
+
handler: ActionHandler;
|
|
59
|
+
}
|
|
60
|
+
type ProduckEventType = 'action' | 'message' | 'error' | 'ready' | 'flowStart' | 'flowStepComplete' | 'flowComplete';
|
|
61
|
+
interface ProduckEvent {
|
|
62
|
+
type: ProduckEventType;
|
|
63
|
+
data: any;
|
|
64
|
+
}
|
|
65
|
+
declare class ProduckSDK {
|
|
66
|
+
private config;
|
|
67
|
+
private actions;
|
|
68
|
+
private eventListeners;
|
|
69
|
+
private sessionToken;
|
|
70
|
+
private isReady;
|
|
71
|
+
constructor(config: ProduckConfig);
|
|
72
|
+
/**
|
|
73
|
+
* Initialize the SDK and create a chat session
|
|
74
|
+
*/
|
|
75
|
+
init(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Register an action handler
|
|
78
|
+
*/
|
|
79
|
+
register(actionKey: string, handler: ActionHandler): void;
|
|
80
|
+
/**
|
|
81
|
+
* Unregister an action handler
|
|
82
|
+
*/
|
|
83
|
+
unregister(actionKey: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Send a message and handle potential action or flow triggers
|
|
86
|
+
*/
|
|
87
|
+
sendMessage(message: string): Promise<ChatMessage>;
|
|
88
|
+
/**
|
|
89
|
+
* Execute a flow by running each step's operation sequentially
|
|
90
|
+
*/
|
|
91
|
+
executeFlow(flow: FlowPayload): Promise<FlowResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Send log data to backend for analytics
|
|
94
|
+
*/
|
|
95
|
+
private sendLogToBackend;
|
|
96
|
+
/**
|
|
97
|
+
* Send detailed log to backend
|
|
98
|
+
*/
|
|
99
|
+
private log;
|
|
100
|
+
/**
|
|
101
|
+
* Execute a registered action
|
|
102
|
+
*/
|
|
103
|
+
private executeAction;
|
|
104
|
+
/**
|
|
105
|
+
* Add event listener
|
|
106
|
+
*/
|
|
107
|
+
on(event: ProduckEventType, callback: Function): void;
|
|
108
|
+
/**
|
|
109
|
+
* Remove event listener
|
|
110
|
+
*/
|
|
111
|
+
off(event: ProduckEventType, callback: Function): void;
|
|
112
|
+
/**
|
|
113
|
+
* Emit event
|
|
114
|
+
*/
|
|
115
|
+
private emit;
|
|
116
|
+
/**
|
|
117
|
+
* Get session token
|
|
118
|
+
*/
|
|
119
|
+
getSessionToken(): string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Check if SDK is ready
|
|
122
|
+
*/
|
|
123
|
+
getIsReady(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Get registered action keys
|
|
126
|
+
*/
|
|
127
|
+
getRegisteredActions(): string[];
|
|
128
|
+
/**
|
|
129
|
+
* Destroy the SDK instance
|
|
130
|
+
*/
|
|
131
|
+
destroy(): void;
|
|
132
|
+
}
|
|
133
|
+
declare function createProduck(config: ProduckConfig): ProduckSDK;
|
|
134
|
+
|
|
135
|
+
export { type ActionHandler, type ActionPayload, type ChatMessage, type FlowPayload, type FlowResult, type FlowStep, type FlowStepResult, type ProduckConfig, type ProduckEvent, type ProduckEventType, ProduckSDK, type RegisteredAction, createProduck };
|