@paymanai/payman-typescript-ask-sdk 1.0.0
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 +159 -0
- package/dist/index.d.mts +173 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +600 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +596 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.native.js +624 -0
- package/dist/index.native.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Payman TypeScript Ask SDK
|
|
2
|
+
|
|
3
|
+
**Core TypeScript SDK for Payman workflows - Logic only, no UI components**
|
|
4
|
+
|
|
5
|
+
This package contains only the business logic for interacting with Payman workflows. Use this if you want to build your own custom UI or integrate Payman into existing applications without including the default UI components.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @paymanai/payman-typescript-ask-sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @paymanai/payman-typescript-ask-sdk
|
|
13
|
+
# or
|
|
14
|
+
bun add @paymanai/payman-typescript-ask-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- ✅ **`useChat` Hook** - React hook for managing chat state and streaming
|
|
20
|
+
- ✅ **Streaming Client** - Low-level streaming utilities
|
|
21
|
+
- ✅ **TypeScript Types** - Full type definitions
|
|
22
|
+
- ✅ **Cross-Platform** - Works in web and React Native
|
|
23
|
+
- ✅ **Zero UI Dependencies** - No UI libraries included
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic Example with Custom UI
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { useChat } from '@paymanai/payman-typescript-ask-sdk';
|
|
31
|
+
|
|
32
|
+
function MyCustomChat() {
|
|
33
|
+
const {
|
|
34
|
+
messages,
|
|
35
|
+
sendMessage,
|
|
36
|
+
isWaitingForResponse,
|
|
37
|
+
resetSession,
|
|
38
|
+
} = useChat({
|
|
39
|
+
config: {
|
|
40
|
+
api: {
|
|
41
|
+
baseUrl: 'https://api.payman.ai',
|
|
42
|
+
authToken: 'your-api-key',
|
|
43
|
+
},
|
|
44
|
+
workflowName: 'my-workflow',
|
|
45
|
+
stage: 'DEV',
|
|
46
|
+
sessionParams: {
|
|
47
|
+
id: 'user-123',
|
|
48
|
+
name: 'John Doe',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div>
|
|
55
|
+
{/* Your custom UI */}
|
|
56
|
+
{messages.map((msg) => (
|
|
57
|
+
<div key={msg.id}>{msg.content}</div>
|
|
58
|
+
))}
|
|
59
|
+
|
|
60
|
+
<button
|
|
61
|
+
onClick={() => sendMessage('Hello')}
|
|
62
|
+
disabled={isWaitingForResponse}
|
|
63
|
+
>
|
|
64
|
+
Send
|
|
65
|
+
</button>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Direct Streaming API
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { streamWorkflowEvents } from '@paymanai/payman-typescript-ask-sdk';
|
|
75
|
+
|
|
76
|
+
await streamWorkflowEvents(
|
|
77
|
+
'https://api.payman.ai/api/workflows/ask/stream',
|
|
78
|
+
{
|
|
79
|
+
workflowName: 'my-workflow',
|
|
80
|
+
userInput: 'Hello',
|
|
81
|
+
sessionOwnerId: 'user-123',
|
|
82
|
+
sessionOwnerLabel: 'John Doe',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
'x-yaak-api-key': 'your-api-key',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
onEvent: (event) => {
|
|
89
|
+
console.log('Received event:', event);
|
|
90
|
+
},
|
|
91
|
+
onComplete: () => {
|
|
92
|
+
console.log('Stream completed');
|
|
93
|
+
},
|
|
94
|
+
onError: (error) => {
|
|
95
|
+
console.error('Stream error:', error);
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## API Reference
|
|
102
|
+
|
|
103
|
+
### `useChat(options)`
|
|
104
|
+
|
|
105
|
+
React hook for managing chat state.
|
|
106
|
+
|
|
107
|
+
**Parameters:**
|
|
108
|
+
- `config: ChatConfig` - Configuration object
|
|
109
|
+
- `api.baseUrl: string` - API base URL
|
|
110
|
+
- `api.authToken?: string` - Authentication token
|
|
111
|
+
- `api.headers?: Record<string, string>` - Custom headers
|
|
112
|
+
- `workflowName: string` - Workflow name
|
|
113
|
+
- `stage?: WorkflowStage` - Environment stage (DEV, SANDBOX, PROD)
|
|
114
|
+
- `sessionParams?: SessionParams` - Session owner information
|
|
115
|
+
- `callbacks?: ChatCallbacks` - Event callbacks
|
|
116
|
+
|
|
117
|
+
**Returns:**
|
|
118
|
+
- `messages: MessageDisplay[]` - Array of messages
|
|
119
|
+
- `sendMessage: (message: string) => Promise<void>` - Send a message
|
|
120
|
+
- `resetSession: () => void` - Reset the session
|
|
121
|
+
- `cancelStream: () => void` - Cancel current stream
|
|
122
|
+
- `isWaitingForResponse: boolean` - Loading state
|
|
123
|
+
|
|
124
|
+
### `streamWorkflowEvents(url, body, headers, options)`
|
|
125
|
+
|
|
126
|
+
Low-level streaming function.
|
|
127
|
+
|
|
128
|
+
**Parameters:**
|
|
129
|
+
- `url: string` - API endpoint URL
|
|
130
|
+
- `body: Record<string, unknown>` - Request body
|
|
131
|
+
- `headers: Record<string, string>` - Request headers
|
|
132
|
+
- `options: StreamOptions` - Streaming options
|
|
133
|
+
- `onEvent?: (event: StreamEvent) => void` - Event callback
|
|
134
|
+
- `onComplete?: () => void` - Completion callback
|
|
135
|
+
- `onError?: (error: Error) => void` - Error callback
|
|
136
|
+
- `signal?: AbortSignal` - Abort signal
|
|
137
|
+
|
|
138
|
+
## TypeScript Types
|
|
139
|
+
|
|
140
|
+
All types are exported:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import type {
|
|
144
|
+
ChatConfig,
|
|
145
|
+
ChatCallbacks,
|
|
146
|
+
MessageDisplay,
|
|
147
|
+
StreamingStep,
|
|
148
|
+
WorkflowStage,
|
|
149
|
+
// ... and more
|
|
150
|
+
} from '@paymanai/payman-typescript-ask-sdk';
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Related Packages
|
|
154
|
+
|
|
155
|
+
- **[@paymanai/payman-ask-sdk](../payman-ask-sdk)** - Full SDK with UI components (uses this package internally)
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type MessageRole = "user" | "assistant" | "system";
|
|
4
|
+
type StreamProgress = "started" | "processing" | "completed" | "error";
|
|
5
|
+
type WorkflowStage = "DEV" | "SANDBOX" | "PROD" | "ARCHIVED";
|
|
6
|
+
type StreamingStep = {
|
|
7
|
+
id: string;
|
|
8
|
+
eventType: string;
|
|
9
|
+
message: string;
|
|
10
|
+
status: "in_progress" | "completed" | "error" | "pending";
|
|
11
|
+
timestamp: number;
|
|
12
|
+
elapsedMs?: number;
|
|
13
|
+
};
|
|
14
|
+
type ChunkDisplay = {
|
|
15
|
+
id?: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
similarityScore?: number;
|
|
18
|
+
rrfScore?: number;
|
|
19
|
+
};
|
|
20
|
+
type MessageDisplay = {
|
|
21
|
+
id: string;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
role: MessageRole;
|
|
24
|
+
content: string;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
isError?: boolean;
|
|
27
|
+
errorDetails?: string;
|
|
28
|
+
chunks?: ChunkDisplay[];
|
|
29
|
+
tracingData?: unknown;
|
|
30
|
+
executionId?: string;
|
|
31
|
+
isStreaming?: boolean;
|
|
32
|
+
streamingContent?: string;
|
|
33
|
+
currentWorker?: string;
|
|
34
|
+
currentMessage?: string;
|
|
35
|
+
streamProgress?: StreamProgress;
|
|
36
|
+
steps?: StreamingStep[];
|
|
37
|
+
isCancelled?: boolean;
|
|
38
|
+
currentExecutingStepId?: string;
|
|
39
|
+
};
|
|
40
|
+
type SessionParams = {
|
|
41
|
+
id?: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
attributes?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
type APIConfig = {
|
|
46
|
+
/** Base API URL */
|
|
47
|
+
baseUrl: string;
|
|
48
|
+
/** Auth token */
|
|
49
|
+
authToken?: string;
|
|
50
|
+
/** Custom headers */
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
/** API endpoint for streaming (default: /api/workflows/ask/stream) */
|
|
53
|
+
streamEndpoint?: string;
|
|
54
|
+
};
|
|
55
|
+
type ChatConfig = {
|
|
56
|
+
/** API configuration - required for the library to make calls */
|
|
57
|
+
api: APIConfig;
|
|
58
|
+
/** Workflow name */
|
|
59
|
+
workflowName: string;
|
|
60
|
+
/** Workflow version */
|
|
61
|
+
workflowVersion?: number;
|
|
62
|
+
/** Stage/Environment */
|
|
63
|
+
stage?: WorkflowStage;
|
|
64
|
+
/** Session params */
|
|
65
|
+
sessionParams?: SessionParams;
|
|
66
|
+
/** Custom placeholder text */
|
|
67
|
+
placeholder?: string;
|
|
68
|
+
/** Empty state text */
|
|
69
|
+
emptyStateText?: string;
|
|
70
|
+
/** Show icon in empty state */
|
|
71
|
+
showEmptyStateIcon?: boolean;
|
|
72
|
+
/** Show agent name */
|
|
73
|
+
showAgentName?: boolean;
|
|
74
|
+
/** Agent name */
|
|
75
|
+
agentName?: string;
|
|
76
|
+
/** Show avatars for user and assistant messages */
|
|
77
|
+
showAvatars?: boolean;
|
|
78
|
+
/** Show user avatar only (overrides showAvatars for user messages) */
|
|
79
|
+
showUserAvatar?: boolean;
|
|
80
|
+
/** Show assistant avatar only (overrides showAvatars for assistant messages) */
|
|
81
|
+
showAssistantAvatar?: boolean;
|
|
82
|
+
/** Show execution steps section with "Completed in X.Xs" */
|
|
83
|
+
showExecutionSteps?: boolean;
|
|
84
|
+
/** Show animated dot indicator during streaming */
|
|
85
|
+
showStreamingDot?: boolean;
|
|
86
|
+
/** Custom text format for streaming steps button. Use {count} for step count. Default: "View progress ({count} steps)" */
|
|
87
|
+
streamingStepsText?: string;
|
|
88
|
+
/** Custom text format for completed steps button. Use {count} for step count, {time} for elapsed time. Default: "Completed in {time}s ({count} steps)" */
|
|
89
|
+
completedStepsText?: string;
|
|
90
|
+
/** Input style variant: "rounded" (yaak style) or "flat" (paygent-central style). Default: "rounded" */
|
|
91
|
+
inputStyle?: "rounded" | "flat";
|
|
92
|
+
/** Layout style: "centered" (durango style) or "full-width" (default). Default: "full-width" */
|
|
93
|
+
layout?: "centered" | "full-width";
|
|
94
|
+
/** Show timestamps on messages */
|
|
95
|
+
showTimestamps?: boolean;
|
|
96
|
+
/** Enable animations */
|
|
97
|
+
animated?: boolean;
|
|
98
|
+
/** Disable input */
|
|
99
|
+
disableInput?: boolean;
|
|
100
|
+
/** Has permission to ask */
|
|
101
|
+
hasAskPermission?: boolean;
|
|
102
|
+
/** Auto-generate session ID */
|
|
103
|
+
autoGenerateSessionId?: boolean;
|
|
104
|
+
/** Disable the entire chat and show disabled state */
|
|
105
|
+
isChatDisabled?: boolean;
|
|
106
|
+
/** Custom component to render when chat is disabled. If not provided, default disabled UI will be shown */
|
|
107
|
+
disabledComponent?: React.ReactNode;
|
|
108
|
+
};
|
|
109
|
+
type ChatCallbacks = {
|
|
110
|
+
/** Called when a message is sent (before API call) */
|
|
111
|
+
onMessageSent?: (message: string) => void;
|
|
112
|
+
/** Called when streaming starts */
|
|
113
|
+
onStreamStart?: () => void;
|
|
114
|
+
/** Called when streaming completes */
|
|
115
|
+
onStreamComplete?: (message: MessageDisplay) => void;
|
|
116
|
+
/** Called when an error occurs */
|
|
117
|
+
onError?: (error: Error) => void;
|
|
118
|
+
/** Called when execution trace is clicked - provides data instead of UI */
|
|
119
|
+
onExecutionTraceClick?: (data: {
|
|
120
|
+
message: MessageDisplay;
|
|
121
|
+
tracingData?: unknown;
|
|
122
|
+
executionId?: string;
|
|
123
|
+
}) => void;
|
|
124
|
+
/** Called when session ID changes */
|
|
125
|
+
onSessionIdChange?: (sessionId: string) => void;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
declare function useChat(config: ChatConfig, callbacks?: ChatCallbacks): {
|
|
129
|
+
messages: MessageDisplay[];
|
|
130
|
+
sendMessage: (userMessage: string) => Promise<void>;
|
|
131
|
+
clearMessages: () => void;
|
|
132
|
+
cancelStream: () => void;
|
|
133
|
+
resetSession: () => void;
|
|
134
|
+
getSessionId: () => string | undefined;
|
|
135
|
+
getMessages: () => MessageDisplay[];
|
|
136
|
+
isWaitingForResponse: boolean;
|
|
137
|
+
sessionId: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Cross-platform UUID v4 generator
|
|
142
|
+
* Works in both browser and React Native environments
|
|
143
|
+
*/
|
|
144
|
+
declare function generateId(): string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Streaming client for handling SSE (Server-Sent Events) from the API
|
|
148
|
+
*/
|
|
149
|
+
type StreamEvent = {
|
|
150
|
+
eventType: string;
|
|
151
|
+
workerName?: string;
|
|
152
|
+
message?: string;
|
|
153
|
+
errorMessage?: string;
|
|
154
|
+
response?: unknown;
|
|
155
|
+
executionId?: string;
|
|
156
|
+
sessionId?: string;
|
|
157
|
+
inputTokens?: number;
|
|
158
|
+
outputTokens?: number;
|
|
159
|
+
elapsedMs?: number;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
};
|
|
162
|
+
type StreamOptions = {
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
onEvent?: (event: StreamEvent) => void;
|
|
165
|
+
onError?: (error: Error) => void;
|
|
166
|
+
onComplete?: () => void;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Stream workflow events from the API
|
|
170
|
+
*/
|
|
171
|
+
declare function streamWorkflowEvents(url: string, body: Record<string, unknown>, headers: Record<string, string>, options?: StreamOptions): Promise<void>;
|
|
172
|
+
|
|
173
|
+
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type WorkflowStage, generateId, streamWorkflowEvents, useChat };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type MessageRole = "user" | "assistant" | "system";
|
|
4
|
+
type StreamProgress = "started" | "processing" | "completed" | "error";
|
|
5
|
+
type WorkflowStage = "DEV" | "SANDBOX" | "PROD" | "ARCHIVED";
|
|
6
|
+
type StreamingStep = {
|
|
7
|
+
id: string;
|
|
8
|
+
eventType: string;
|
|
9
|
+
message: string;
|
|
10
|
+
status: "in_progress" | "completed" | "error" | "pending";
|
|
11
|
+
timestamp: number;
|
|
12
|
+
elapsedMs?: number;
|
|
13
|
+
};
|
|
14
|
+
type ChunkDisplay = {
|
|
15
|
+
id?: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
similarityScore?: number;
|
|
18
|
+
rrfScore?: number;
|
|
19
|
+
};
|
|
20
|
+
type MessageDisplay = {
|
|
21
|
+
id: string;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
role: MessageRole;
|
|
24
|
+
content: string;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
isError?: boolean;
|
|
27
|
+
errorDetails?: string;
|
|
28
|
+
chunks?: ChunkDisplay[];
|
|
29
|
+
tracingData?: unknown;
|
|
30
|
+
executionId?: string;
|
|
31
|
+
isStreaming?: boolean;
|
|
32
|
+
streamingContent?: string;
|
|
33
|
+
currentWorker?: string;
|
|
34
|
+
currentMessage?: string;
|
|
35
|
+
streamProgress?: StreamProgress;
|
|
36
|
+
steps?: StreamingStep[];
|
|
37
|
+
isCancelled?: boolean;
|
|
38
|
+
currentExecutingStepId?: string;
|
|
39
|
+
};
|
|
40
|
+
type SessionParams = {
|
|
41
|
+
id?: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
attributes?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
type APIConfig = {
|
|
46
|
+
/** Base API URL */
|
|
47
|
+
baseUrl: string;
|
|
48
|
+
/** Auth token */
|
|
49
|
+
authToken?: string;
|
|
50
|
+
/** Custom headers */
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
/** API endpoint for streaming (default: /api/workflows/ask/stream) */
|
|
53
|
+
streamEndpoint?: string;
|
|
54
|
+
};
|
|
55
|
+
type ChatConfig = {
|
|
56
|
+
/** API configuration - required for the library to make calls */
|
|
57
|
+
api: APIConfig;
|
|
58
|
+
/** Workflow name */
|
|
59
|
+
workflowName: string;
|
|
60
|
+
/** Workflow version */
|
|
61
|
+
workflowVersion?: number;
|
|
62
|
+
/** Stage/Environment */
|
|
63
|
+
stage?: WorkflowStage;
|
|
64
|
+
/** Session params */
|
|
65
|
+
sessionParams?: SessionParams;
|
|
66
|
+
/** Custom placeholder text */
|
|
67
|
+
placeholder?: string;
|
|
68
|
+
/** Empty state text */
|
|
69
|
+
emptyStateText?: string;
|
|
70
|
+
/** Show icon in empty state */
|
|
71
|
+
showEmptyStateIcon?: boolean;
|
|
72
|
+
/** Show agent name */
|
|
73
|
+
showAgentName?: boolean;
|
|
74
|
+
/** Agent name */
|
|
75
|
+
agentName?: string;
|
|
76
|
+
/** Show avatars for user and assistant messages */
|
|
77
|
+
showAvatars?: boolean;
|
|
78
|
+
/** Show user avatar only (overrides showAvatars for user messages) */
|
|
79
|
+
showUserAvatar?: boolean;
|
|
80
|
+
/** Show assistant avatar only (overrides showAvatars for assistant messages) */
|
|
81
|
+
showAssistantAvatar?: boolean;
|
|
82
|
+
/** Show execution steps section with "Completed in X.Xs" */
|
|
83
|
+
showExecutionSteps?: boolean;
|
|
84
|
+
/** Show animated dot indicator during streaming */
|
|
85
|
+
showStreamingDot?: boolean;
|
|
86
|
+
/** Custom text format for streaming steps button. Use {count} for step count. Default: "View progress ({count} steps)" */
|
|
87
|
+
streamingStepsText?: string;
|
|
88
|
+
/** Custom text format for completed steps button. Use {count} for step count, {time} for elapsed time. Default: "Completed in {time}s ({count} steps)" */
|
|
89
|
+
completedStepsText?: string;
|
|
90
|
+
/** Input style variant: "rounded" (yaak style) or "flat" (paygent-central style). Default: "rounded" */
|
|
91
|
+
inputStyle?: "rounded" | "flat";
|
|
92
|
+
/** Layout style: "centered" (durango style) or "full-width" (default). Default: "full-width" */
|
|
93
|
+
layout?: "centered" | "full-width";
|
|
94
|
+
/** Show timestamps on messages */
|
|
95
|
+
showTimestamps?: boolean;
|
|
96
|
+
/** Enable animations */
|
|
97
|
+
animated?: boolean;
|
|
98
|
+
/** Disable input */
|
|
99
|
+
disableInput?: boolean;
|
|
100
|
+
/** Has permission to ask */
|
|
101
|
+
hasAskPermission?: boolean;
|
|
102
|
+
/** Auto-generate session ID */
|
|
103
|
+
autoGenerateSessionId?: boolean;
|
|
104
|
+
/** Disable the entire chat and show disabled state */
|
|
105
|
+
isChatDisabled?: boolean;
|
|
106
|
+
/** Custom component to render when chat is disabled. If not provided, default disabled UI will be shown */
|
|
107
|
+
disabledComponent?: React.ReactNode;
|
|
108
|
+
};
|
|
109
|
+
type ChatCallbacks = {
|
|
110
|
+
/** Called when a message is sent (before API call) */
|
|
111
|
+
onMessageSent?: (message: string) => void;
|
|
112
|
+
/** Called when streaming starts */
|
|
113
|
+
onStreamStart?: () => void;
|
|
114
|
+
/** Called when streaming completes */
|
|
115
|
+
onStreamComplete?: (message: MessageDisplay) => void;
|
|
116
|
+
/** Called when an error occurs */
|
|
117
|
+
onError?: (error: Error) => void;
|
|
118
|
+
/** Called when execution trace is clicked - provides data instead of UI */
|
|
119
|
+
onExecutionTraceClick?: (data: {
|
|
120
|
+
message: MessageDisplay;
|
|
121
|
+
tracingData?: unknown;
|
|
122
|
+
executionId?: string;
|
|
123
|
+
}) => void;
|
|
124
|
+
/** Called when session ID changes */
|
|
125
|
+
onSessionIdChange?: (sessionId: string) => void;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
declare function useChat(config: ChatConfig, callbacks?: ChatCallbacks): {
|
|
129
|
+
messages: MessageDisplay[];
|
|
130
|
+
sendMessage: (userMessage: string) => Promise<void>;
|
|
131
|
+
clearMessages: () => void;
|
|
132
|
+
cancelStream: () => void;
|
|
133
|
+
resetSession: () => void;
|
|
134
|
+
getSessionId: () => string | undefined;
|
|
135
|
+
getMessages: () => MessageDisplay[];
|
|
136
|
+
isWaitingForResponse: boolean;
|
|
137
|
+
sessionId: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Cross-platform UUID v4 generator
|
|
142
|
+
* Works in both browser and React Native environments
|
|
143
|
+
*/
|
|
144
|
+
declare function generateId(): string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Streaming client for handling SSE (Server-Sent Events) from the API
|
|
148
|
+
*/
|
|
149
|
+
type StreamEvent = {
|
|
150
|
+
eventType: string;
|
|
151
|
+
workerName?: string;
|
|
152
|
+
message?: string;
|
|
153
|
+
errorMessage?: string;
|
|
154
|
+
response?: unknown;
|
|
155
|
+
executionId?: string;
|
|
156
|
+
sessionId?: string;
|
|
157
|
+
inputTokens?: number;
|
|
158
|
+
outputTokens?: number;
|
|
159
|
+
elapsedMs?: number;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
};
|
|
162
|
+
type StreamOptions = {
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
onEvent?: (event: StreamEvent) => void;
|
|
165
|
+
onError?: (error: Error) => void;
|
|
166
|
+
onComplete?: () => void;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Stream workflow events from the API
|
|
170
|
+
*/
|
|
171
|
+
declare function streamWorkflowEvents(url: string, body: Record<string, unknown>, headers: Record<string, string>, options?: StreamOptions): Promise<void>;
|
|
172
|
+
|
|
173
|
+
export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type WorkflowStage, generateId, streamWorkflowEvents, useChat };
|