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/dist/index.d.ts
CHANGED
|
@@ -1,135 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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 { }
|