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/dist/index.d.ts CHANGED
@@ -1,135 +1,64 @@
1
- import { ToolSet, streamText, generateText } from 'ai';
2
-
3
- /**
4
- * Configuration options for Polymorph SDK.
5
- */
6
- interface PolymorphConfigOptions {
7
- /**
8
- * User role for potential RBAC functionality.
9
- */
10
- role: string;
11
- /**
12
- * API key for authentication. Can also be set via POLYMORPH_API_KEY env var.
13
- */
14
- apiKey?: string;
15
- /**
16
- * Base URL for the Polymorph API. Can also be set via POLYMORPH_BASE_URL env var.
17
- */
18
- baseUrl?: string;
19
- /**
20
- * HTTP request timeout in milliseconds. Defaults to 10000 (10 seconds).
21
- */
22
- httpTimeout?: number;
23
- /**
24
- * Whether HTTP logging is enabled. Defaults to true.
25
- */
26
- httpEnabled?: boolean;
27
- }
28
- /**
29
- * Configuration for tool logging and permissions.
30
- */
31
- declare class PolymorphConfig {
32
- readonly role: string;
33
- readonly apiKey: string | undefined;
34
- readonly baseUrl: string | undefined;
35
- readonly httpTimeout: number;
36
- readonly httpEnabled: boolean;
37
- constructor(options: PolymorphConfigOptions);
38
- private getEnv;
39
- }
40
-
41
- /**
42
- * HTTP client for Polymorph API calls.
43
- *
44
- * All errors are caught and logged - never crashes the SDK.
45
- */
46
- declare class PolymorphHTTPClient {
47
- private baseUrl;
48
- private apiKey;
49
- private timeout;
50
- private enabled;
51
- constructor(options: {
52
- baseUrl?: string;
53
- apiKey?: string;
54
- timeout?: number;
55
- enabled?: boolean;
56
- });
57
- /**
58
- * Make a POST request to the given endpoint.
59
- *
60
- * Returns the response JSON if successful, undefined otherwise.
61
- * All errors are caught and logged.
62
- */
63
- post<T = unknown>(endpoint: string, payload: Record<string, unknown>): Promise<T | undefined>;
64
- /**
65
- * Fire-and-forget POST request. Does not wait for response.
66
- */
67
- postFireAndForget(endpoint: string, payload: Record<string, unknown>): void;
68
- }
69
-
70
- /**
71
- * Log an entry to configured destinations.
72
- */
73
- declare function log(entry: Record<string, unknown>): void;
74
-
75
- type StreamTextParams = Parameters<typeof streamText>[0];
76
- type GenerateTextParams = Parameters<typeof generateText>[0];
77
- type StreamTextResult = ReturnType<typeof streamText>;
78
- type GenerateTextResult = ReturnType<typeof generateText>;
79
- /**
80
- * Hook context passed to pre/post tool hooks.
81
- */
82
- interface ToolHookContext {
83
- toolName: string;
84
- toolCallId: string;
85
- input: unknown;
86
- }
87
- /**
88
- * Pre-tool hook result. Return `{ deny: true, reason: string }` to deny the tool call.
89
- */
90
- interface PreToolHookResult {
91
- deny?: boolean;
92
- reason?: string;
93
- }
94
- /**
95
- * Post-tool hook context with the result.
96
- */
97
- interface PostToolHookContext extends ToolHookContext {
98
- result: unknown;
99
- error?: Error;
100
- durationMs: number;
101
- }
102
- /**
103
- * Options for creating a Polymorph AI client.
104
- */
105
- interface PolymorphAIClientOptions {
106
- config: PolymorphConfig;
107
- }
108
- /**
109
- * Polymorph AI client that wraps Vercel AI SDK functions with tool logging.
110
- */
111
- declare class PolymorphAIClient {
112
- private config;
113
- private httpClient;
114
- private preToolHook;
115
- private postToolHook;
116
- constructor(options: PolymorphAIClientOptions);
117
- /**
118
- * Wraps tools with Polymorph logging hooks.
119
- */
120
- wrapTools<T extends ToolSet>(tools: T): T;
121
- /**
122
- * Creates a wrapped streamText function that automatically wraps tools.
123
- */
124
- streamText(originalStreamText: typeof streamText): (params: StreamTextParams) => StreamTextResult;
125
- /**
126
- * Creates a wrapped generateText function that automatically wraps tools.
127
- */
128
- generateText(originalGenerateText: typeof generateText): (params: GenerateTextParams) => GenerateTextResult;
129
- }
130
- /**
131
- * Creates a Polymorph AI client for wrapping Vercel AI SDK functions.
132
- */
133
- declare function createPolymorphAIClient(options: PolymorphAIClientOptions): PolymorphAIClient;
134
-
135
- export { PolymorphAIClient, type PolymorphAIClientOptions, PolymorphConfig, type PolymorphConfigOptions, PolymorphHTTPClient, type PostToolHookContext, type PreToolHookResult, type ToolHookContext, createPolymorphAIClient, log };
1
+ import { JSX } from 'react/jsx-runtime';
2
+ import { Room } from 'livekit-client';
3
+
4
+ export declare interface ChatMessage {
5
+ id: string;
6
+ role: "user" | "agent";
7
+ text: string;
8
+ source: "chat" | "voice";
9
+ timestamp: number;
10
+ }
11
+
12
+ export declare function PolymorphWidget(props: WidgetConfig): JSX.Element;
13
+
14
+ declare interface RoomConnection {
15
+ token: string;
16
+ livekitUrl: string;
17
+ }
18
+
19
+ export declare type SessionStatus = "idle" | "connecting" | "connected" | "error";
20
+
21
+ export declare function usePolymorphSession(config: WidgetConfig): {
22
+ status: SessionStatus;
23
+ roomConnection: RoomConnection | null;
24
+ messages: ChatMessage[];
25
+ isVoiceEnabled: boolean;
26
+ isMicActive: boolean;
27
+ error: string | null;
28
+ connect: () => Promise<void>;
29
+ disconnect: () => void;
30
+ addMessage: (role: "user" | "agent", text: string, source: "chat" | "voice") => void;
31
+ sendMessage: (text: string) => void;
32
+ toggleMic: () => Promise<void>;
33
+ toggleVoice: () => Promise<void>;
34
+ setRoom: (room: Room | null) => void;
35
+ };
36
+
37
+ export declare interface WidgetBranding {
38
+ /** FAB and accent color (default: "#171717") */
39
+ primaryColor?: string;
40
+ /** Panel header title (default: "Hi there") */
41
+ title?: string;
42
+ /** Panel subheader */
43
+ subtitle?: string;
44
+ /** Initial message shown before agent connects */
45
+ greeting?: string;
46
+ }
47
+
48
+ export declare interface WidgetConfig {
49
+ apiBaseUrl: string;
50
+ apiKey?: string;
51
+ /** LiveKit dispatched agent name (default: "custom-voice-agent"). */
52
+ agentName?: string;
53
+ metadata?: Record<string, string | string[]>;
54
+ branding?: WidgetBranding;
55
+ position?: "bottom-right" | "bottom-left";
56
+ /** Enable voice call (default: true). When false, widget is chat-only. */
57
+ enableVoice?: boolean;
58
+ /** Extra options passed to fetch (e.g. { credentials: "include" }) */
59
+ fetchOptions?: RequestInit;
60
+ /** Render widget in dark mode (default: false) */
61
+ darkMode?: boolean;
62
+ }
63
+
64
+ export { }