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 CHANGED
@@ -1,102 +1,76 @@
1
- # Polymorph SDK for TypeScript
1
+ # polymorph-sdk
2
2
 
3
- Tool logging wrapper for Vercel AI SDK. Automatically logs tool calls to the Polymorph API for monitoring and analytics.
3
+ Embeddable voice AI widget for your website.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install polymorph-sdk ai
8
+ npm install polymorph-sdk
9
9
  ```
10
10
 
11
- ## Usage
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
- const config = new PolymorphConfig({ role: "user" });
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
- // Now use these wrapped functions - tools will be automatically logged
70
- const result = await polymorphStreamText({
71
- model: anthropic("claude-sonnet-4-20250514"),
72
- tools: myTools, // Tools are automatically wrapped
73
- messages: [...],
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
- | Option | Type | Default | Description |
80
- |--------|------|---------|-------------|
81
- | `role` | `string` | (required) | User role for RBAC functionality |
82
- | `apiKey` | `string` | `POLYMORPH_API_KEY` env var | API key for authentication |
83
- | `baseUrl` | `string` | `POLYMORPH_BASE_URL` env var | Base URL for Polymorph API |
84
- | `httpTimeout` | `number` | `10000` | HTTP request timeout in milliseconds |
85
- | `httpEnabled` | `boolean` | `true` | Whether HTTP logging is enabled |
86
-
87
- ## Environment Variables
88
-
89
- - `POLYMORPH_API_KEY` - API key for authentication
90
- - `POLYMORPH_BASE_URL` - Base URL for Polymorph API
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
- ## API Endpoints
57
+ ## Hooks
93
58
 
94
- The SDK sends events to the following endpoints:
59
+ For custom UIs, use the session hook directly:
95
60
 
96
- - `POST /sdk/init` - Called on client initialization
97
- - `POST /sdk/tool/pre` - Called before tool execution
98
- - `POST /sdk/tool/post` - Called after tool execution
61
+ ```tsx
62
+ import { usePolymorphSession } from "polymorph-sdk";
99
63
 
100
- ## License
64
+ function CustomWidget() {
65
+ const session = usePolymorphSession({
66
+ apiBaseUrl: "https://api.polymorph.dev",
67
+ apiKey: "pm_live_...",
68
+ });
101
69
 
102
- MIT
70
+ return (
71
+ <button onClick={session.connect}>
72
+ {session.status === "idle" ? "Start" : session.status}
73
+ </button>
74
+ );
75
+ }
76
+ ```