polymorph-sdk 0.1.0 → 0.2.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/README.md +58 -84
- package/dist/index.css +2 -0
- package/dist/index.d.ts +64 -135
- package/dist/index.js +18187 -259
- package/package.json +38 -34
- package/src/ChatThread.tsx +70 -0
- package/src/PolymorphWidget.tsx +103 -0
- package/src/RoomHandler.tsx +99 -0
- package/src/VoiceOverlay.tsx +85 -0
- package/src/WidgetPanel.tsx +228 -0
- package/src/__tests__/exports.test.ts +13 -0
- package/src/env.d.ts +6 -0
- package/src/index.ts +8 -0
- package/src/styles.module.css +304 -0
- package/src/theme.ts +53 -0
- package/src/types.ts +36 -0
- package/src/usePolymorphSession.ts +203 -0
- package/dist/index.d.mts +0 -135
- package/dist/index.mjs +0 -233
package/README.md
CHANGED
|
@@ -1,102 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# polymorph-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Embeddable voice AI widget for your website.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install polymorph-sdk
|
|
8
|
+
npm install polymorph-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { streamText, tool } from "ai";
|
|
15
|
-
import { anthropic } from "@ai-sdk/anthropic";
|
|
16
|
-
import { z } from "zod";
|
|
17
|
-
import { PolymorphConfig, createPolymorphAIClient } from "polymorph-sdk";
|
|
18
|
-
|
|
19
|
-
// Create Polymorph config
|
|
20
|
-
const config = new PolymorphConfig({
|
|
21
|
-
role: "user",
|
|
22
|
-
apiKey: "your-api-key", // or set POLYMORPH_API_KEY env var
|
|
23
|
-
baseUrl: "https://api.polymorph.dev", // or set POLYMORPH_BASE_URL env var
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Create Polymorph client
|
|
27
|
-
const polymorph = createPolymorphAIClient({ config });
|
|
28
|
-
|
|
29
|
-
// Define your tools
|
|
30
|
-
const tools = {
|
|
31
|
-
getWeather: tool({
|
|
32
|
-
description: "Get the weather for a location",
|
|
33
|
-
parameters: z.object({
|
|
34
|
-
location: z.string().describe("The location to get weather for"),
|
|
35
|
-
}),
|
|
36
|
-
execute: async ({ location }) => {
|
|
37
|
-
// Your tool implementation
|
|
38
|
-
return { temperature: 72, condition: "sunny" };
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Wrap tools with Polymorph logging
|
|
44
|
-
const wrappedTools = polymorph.wrapTools(tools);
|
|
45
|
-
|
|
46
|
-
// Use with streamText
|
|
47
|
-
const result = await streamText({
|
|
48
|
-
model: anthropic("claude-sonnet-4-20250514"),
|
|
49
|
-
tools: wrappedTools,
|
|
50
|
-
messages: [{ role: "user", content: "What's the weather in San Francisco?" }],
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Alternative: Wrap streamText/generateText
|
|
55
|
-
|
|
56
|
-
You can also wrap the AI SDK functions directly:
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { streamText, generateText } from "ai";
|
|
60
|
-
import { PolymorphConfig, createPolymorphAIClient } from "polymorph-sdk";
|
|
11
|
+
> Requires `react` and `react-dom` as peer dependencies (`^18.0.0 || ^19.0.0`).
|
|
61
12
|
|
|
62
|
-
|
|
63
|
-
const polymorph = createPolymorphAIClient({ config });
|
|
64
|
-
|
|
65
|
-
// Create wrapped versions of streamText and generateText
|
|
66
|
-
const polymorphStreamText = polymorph.streamText(streamText);
|
|
67
|
-
const polymorphGenerateText = polymorph.generateText(generateText);
|
|
13
|
+
## Usage
|
|
68
14
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
15
|
+
```tsx
|
|
16
|
+
import { PolymorphWidget } from "polymorph-sdk";
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<PolymorphWidget
|
|
21
|
+
apiBaseUrl="https://api.polymorph.dev"
|
|
22
|
+
apiKey="pm_live_your_api_key_here"
|
|
23
|
+
branding={{
|
|
24
|
+
title: "Need help?",
|
|
25
|
+
subtitle: "Chat with us",
|
|
26
|
+
primaryColor: "#171717",
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
75
31
|
```
|
|
76
32
|
|
|
77
33
|
## Configuration
|
|
78
34
|
|
|
79
|
-
|
|
|
80
|
-
|
|
81
|
-
| `
|
|
82
|
-
| `apiKey` | `string` |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
35
|
+
| Prop | Type | Required | Description |
|
|
36
|
+
|------|------|----------|-------------|
|
|
37
|
+
| `apiBaseUrl` | `string` | Yes | Your Polymorph API base URL |
|
|
38
|
+
| `apiKey` | `string` | Yes | API key from Settings > API Keys |
|
|
39
|
+
| `agentName` | `string` | No | LiveKit agent name to dispatch (default: `"custom-voice-agent"`) |
|
|
40
|
+
| `metadata` | `Record<string, string>` | No | Custom metadata passed to the agent |
|
|
41
|
+
| `branding` | `WidgetBranding` | No | Customize widget appearance |
|
|
42
|
+
| `position` | `"bottom-right" \| "bottom-left"` | No | Widget position (default: `"bottom-right"`) |
|
|
43
|
+
| `enableVoice` | `boolean` | No | Enable voice calls (default: `true`) |
|
|
44
|
+
| `fetchOptions` | `RequestInit` | No | Extra options passed to fetch |
|
|
45
|
+
|
|
46
|
+
### Branding
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
interface WidgetBranding {
|
|
50
|
+
primaryColor?: string; // FAB and accent color (default: "#171717")
|
|
51
|
+
title?: string; // Panel header title (default: "Hi there")
|
|
52
|
+
subtitle?: string; // Panel subheader
|
|
53
|
+
greeting?: string; // Initial message before agent connects
|
|
54
|
+
}
|
|
55
|
+
```
|
|
91
56
|
|
|
92
|
-
##
|
|
57
|
+
## Hooks
|
|
93
58
|
|
|
94
|
-
|
|
59
|
+
For custom UIs, use the session hook directly:
|
|
95
60
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- `POST /sdk/tool/post` - Called after tool execution
|
|
61
|
+
```tsx
|
|
62
|
+
import { usePolymorphSession } from "polymorph-sdk";
|
|
99
63
|
|
|
100
|
-
|
|
64
|
+
function CustomWidget() {
|
|
65
|
+
const session = usePolymorphSession({
|
|
66
|
+
apiBaseUrl: "https://api.polymorph.dev",
|
|
67
|
+
apiKey: "pm_live_...",
|
|
68
|
+
});
|
|
101
69
|
|
|
102
|
-
|
|
70
|
+
return (
|
|
71
|
+
<button onClick={session.connect}>
|
|
72
|
+
{session.status === "idle" ? "Start" : session.status}
|
|
73
|
+
</button>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|