@useago/sdk 0.1.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/dist/api/HttpClient.d.ts +31 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/client/AgoClient.d.ts +113 -0
- package/dist/client/errors.d.ts +48 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/types.d.ts +203 -0
- package/dist/createMockClient-BZKh_1em.cjs +941 -0
- package/dist/createMockClient-BZKh_1em.cjs.map +1 -0
- package/dist/createMockClient-uGlVyjbL.js +942 -0
- package/dist/createMockClient-uGlVyjbL.js.map +1 -0
- package/dist/functions/FunctionRegistry.d.ts +41 -0
- package/dist/functions/defineFunction.d.ts +22 -0
- package/dist/functions/index.d.ts +2 -0
- package/dist/functions/types.d.ts +50 -0
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/react/components/ChatInput.d.ts +12 -0
- package/dist/react/components/ChatWidget.d.ts +33 -0
- package/dist/react/components/Message.d.ts +7 -0
- package/dist/react/components/index.d.ts +6 -0
- package/dist/react/context/AgoContext.d.ts +36 -0
- package/dist/react/context/index.d.ts +2 -0
- package/dist/react/hooks/index.d.ts +6 -0
- package/dist/react/hooks/useAgo.d.ts +14 -0
- package/dist/react/hooks/useAgoFunction.d.ts +46 -0
- package/dist/react/hooks/useChat.d.ts +45 -0
- package/dist/react/hooks/useConversation.d.ts +28 -0
- package/dist/react/hooks/useMessages.d.ts +26 -0
- package/dist/react/index.d.ts +20 -0
- package/dist/react/testing.d.ts +2 -0
- package/dist/react.cjs +10585 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +10586 -0
- package/dist/react.js.map +1 -0
- package/dist/streaming/SSEHandler.d.ts +46 -0
- package/dist/streaming/index.d.ts +2 -0
- package/dist/testing/createMockClient.d.ts +42 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/utils/eventEmitter.d.ts +23 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/types.d.ts +42 -0
- package/dist/widget.cjs +2 -0
- package/dist/widget.cjs.map +1 -0
- package/dist/widget.d.ts +1 -0
- package/dist/widget.js +2 -0
- package/dist/widget.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AgoConfig } from "../client/types";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP client with authentication headers
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpClient {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private headers;
|
|
8
|
+
constructor(config: AgoConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Update configuration (e.g., JWT token)
|
|
11
|
+
*/
|
|
12
|
+
updateConfig(config: Partial<AgoConfig>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Make a GET request
|
|
15
|
+
*/
|
|
16
|
+
get<T>(path: string): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Make a POST request with JSON body
|
|
19
|
+
*/
|
|
20
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Make a POST request and return the raw Response (for streaming)
|
|
23
|
+
*/
|
|
24
|
+
postStream(path: string, body?: unknown): Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Make a POST request with FormData (for file uploads)
|
|
27
|
+
*/
|
|
28
|
+
postFormData(path: string, formData: FormData): Promise<Response>;
|
|
29
|
+
private request;
|
|
30
|
+
private handleErrorResponse;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HttpClient } from "./HttpClient";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ClientFunctionDefinition, ClientFunctionHandler, ClientFunctionSchema } from "../functions/types";
|
|
2
|
+
import type { AgoConfig, AgoClientEvents, AgoEventName, AgoEventHandler, AgoMessage, Conversation, SendMessageOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Main SDK client for AGO Chat integration
|
|
5
|
+
*/
|
|
6
|
+
export declare class AgoClient {
|
|
7
|
+
private httpClient;
|
|
8
|
+
private functionRegistry;
|
|
9
|
+
private eventEmitter;
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: AgoConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Send a message and receive a streaming response
|
|
14
|
+
*/
|
|
15
|
+
sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
|
|
16
|
+
private processSSEResponse;
|
|
17
|
+
private handleClientFunctionInvocation;
|
|
18
|
+
/**
|
|
19
|
+
* Get list of conversations
|
|
20
|
+
*/
|
|
21
|
+
getConversations(): Promise<Conversation[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a specific conversation with messages
|
|
24
|
+
*/
|
|
25
|
+
getConversation(conversationId: string): Promise<Conversation>;
|
|
26
|
+
/**
|
|
27
|
+
* Get messages for a conversation
|
|
28
|
+
*/
|
|
29
|
+
getMessages(conversationId: string): Promise<AgoMessage[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Submit form data for a tool call
|
|
32
|
+
*/
|
|
33
|
+
submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Confirm a tool call
|
|
36
|
+
*/
|
|
37
|
+
confirmToolCall(toolCallId: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Reject a tool call
|
|
40
|
+
*/
|
|
41
|
+
rejectToolCall(toolCallId: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Submit feedback for a message
|
|
44
|
+
*/
|
|
45
|
+
submitFeedback(messageId: string, rating: "positive" | "negative"): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Register a client-side function that AGO can call.
|
|
48
|
+
* Accepts either a definition object or (name, handler, schema) args.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Single-object (preferred)
|
|
52
|
+
* client.registerFunction({
|
|
53
|
+
* name: "lookupOrder",
|
|
54
|
+
* description: "Look up an order",
|
|
55
|
+
* parameters: { type: "object", properties: { id: { type: "string" } } },
|
|
56
|
+
* handler: async (args) => fetchOrder(args.id),
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // Classic 3-arg form
|
|
60
|
+
* client.registerFunction("lookupOrder", handler, schema);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
registerFunction(definition: ClientFunctionDefinition): void;
|
|
64
|
+
registerFunction(name: string, handler: ClientFunctionHandler, schema: Omit<ClientFunctionSchema, "name">): void;
|
|
65
|
+
/**
|
|
66
|
+
* Unregister a client-side function
|
|
67
|
+
*/
|
|
68
|
+
unregisterFunction(name: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Get all registered function schemas
|
|
71
|
+
*/
|
|
72
|
+
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
73
|
+
/**
|
|
74
|
+
* Register a navigation function that lets AGO navigate users to different pages.
|
|
75
|
+
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
76
|
+
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
77
|
+
*/
|
|
78
|
+
registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
|
|
79
|
+
name: string;
|
|
80
|
+
path: string;
|
|
81
|
+
description: string;
|
|
82
|
+
}>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Subscribe to an event
|
|
85
|
+
*/
|
|
86
|
+
on<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Unsubscribe from an event
|
|
89
|
+
*/
|
|
90
|
+
off<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to an event once — auto-unsubscribes after the first call.
|
|
93
|
+
*/
|
|
94
|
+
once<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a Promise that resolves the next time `event` fires.
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const msg = await client.waitFor("message:complete", { timeout: 10000 });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
waitFor<K extends AgoEventName>(event: K, options?: {
|
|
103
|
+
timeout?: number;
|
|
104
|
+
}): Promise<AgoClientEvents[K]>;
|
|
105
|
+
/**
|
|
106
|
+
* Update client configuration
|
|
107
|
+
*/
|
|
108
|
+
updateConfig(config: Partial<AgoConfig>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Clean up resources
|
|
111
|
+
*/
|
|
112
|
+
destroy(): void;
|
|
113
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for AGO SDK
|
|
3
|
+
*/
|
|
4
|
+
export declare class AgoError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
statusCode?: number | undefined;
|
|
7
|
+
constructor(message: string, code: string, statusCode?: number | undefined);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error from API response
|
|
11
|
+
*/
|
|
12
|
+
export declare class AgoApiError extends AgoError {
|
|
13
|
+
type: string;
|
|
14
|
+
param?: string | undefined;
|
|
15
|
+
docUrl?: string | undefined;
|
|
16
|
+
constructor(message: string, code: string, statusCode: number, type: string, param?: string | undefined, docUrl?: string | undefined);
|
|
17
|
+
static fromResponse(data: ApiErrorResponse, statusCode: number): AgoApiError;
|
|
18
|
+
}
|
|
19
|
+
export interface ApiErrorResponse {
|
|
20
|
+
error: {
|
|
21
|
+
type: string;
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
param?: string;
|
|
25
|
+
doc_url?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Network/connection error
|
|
30
|
+
*/
|
|
31
|
+
export declare class AgoNetworkError extends AgoError {
|
|
32
|
+
originalError?: Error | undefined;
|
|
33
|
+
constructor(message: string, originalError?: Error | undefined);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* SSE stream error
|
|
37
|
+
*/
|
|
38
|
+
export declare class AgoStreamError extends AgoError {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Function execution error
|
|
43
|
+
*/
|
|
44
|
+
export declare class AgoFunctionError extends AgoError {
|
|
45
|
+
functionName: string;
|
|
46
|
+
originalError?: Error | undefined;
|
|
47
|
+
constructor(message: string, functionName: string, originalError?: Error | undefined);
|
|
48
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface AgoConfig {
|
|
5
|
+
/** Widget API key (X-Widget-Key header) */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Widget ID (X-Widget-Id header) */
|
|
8
|
+
widgetId: string;
|
|
9
|
+
/** API base URL (default: https://api.useago.com) */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** Default agent ID for new conversations */
|
|
12
|
+
defaultAgentId?: string;
|
|
13
|
+
/** User email for identification */
|
|
14
|
+
userEmail?: string;
|
|
15
|
+
/** JWT token for authenticated users */
|
|
16
|
+
userJwt?: string;
|
|
17
|
+
/** Enable debug logging */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for sending a message
|
|
22
|
+
*/
|
|
23
|
+
export interface SendMessageOptions {
|
|
24
|
+
/** Existing conversation ID */
|
|
25
|
+
conversationId?: string;
|
|
26
|
+
/** Override default agent */
|
|
27
|
+
agentId?: string;
|
|
28
|
+
/** File attachments */
|
|
29
|
+
files?: File[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Message from AGO
|
|
33
|
+
*/
|
|
34
|
+
export interface AgoMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
conversationId: string;
|
|
37
|
+
content: string;
|
|
38
|
+
role: "user" | "assistant";
|
|
39
|
+
status: MessageStatus;
|
|
40
|
+
agent?: AgoAgent;
|
|
41
|
+
sources?: AgoSource[];
|
|
42
|
+
toolCalls?: ToolCallData[];
|
|
43
|
+
followUpReplies?: string[];
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
}
|
|
46
|
+
export type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
|
|
47
|
+
/**
|
|
48
|
+
* Agent information
|
|
49
|
+
*/
|
|
50
|
+
export interface AgoAgent {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
displayName?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Knowledge source citation
|
|
57
|
+
*/
|
|
58
|
+
export interface AgoSource {
|
|
59
|
+
id: string;
|
|
60
|
+
title: string;
|
|
61
|
+
url?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Conversation/Thread
|
|
65
|
+
*/
|
|
66
|
+
export interface Conversation {
|
|
67
|
+
id: string;
|
|
68
|
+
title: string;
|
|
69
|
+
lastMessageDate: Date;
|
|
70
|
+
messages?: AgoMessage[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Tool call data from SSE stream
|
|
74
|
+
*/
|
|
75
|
+
export interface ToolCallData {
|
|
76
|
+
id: string;
|
|
77
|
+
type: ToolCallType;
|
|
78
|
+
status: string;
|
|
79
|
+
toolName: string;
|
|
80
|
+
toolDisplayName?: string;
|
|
81
|
+
message?: string;
|
|
82
|
+
formSchema?: FormSchema;
|
|
83
|
+
data?: Record<string, unknown>;
|
|
84
|
+
functionName?: string;
|
|
85
|
+
arguments?: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
export type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
88
|
+
/**
|
|
89
|
+
* Form schema for tool calls requiring user input
|
|
90
|
+
*/
|
|
91
|
+
export interface FormSchema {
|
|
92
|
+
type: "object";
|
|
93
|
+
properties: Record<string, FormField>;
|
|
94
|
+
required?: string[];
|
|
95
|
+
}
|
|
96
|
+
export interface FormField {
|
|
97
|
+
type: "string" | "number" | "boolean" | "array";
|
|
98
|
+
title?: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
enum?: string[];
|
|
101
|
+
default?: unknown;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Client-side function types
|
|
105
|
+
*/
|
|
106
|
+
export interface FunctionSchema {
|
|
107
|
+
name: string;
|
|
108
|
+
description: string;
|
|
109
|
+
parameters: {
|
|
110
|
+
type: "object";
|
|
111
|
+
properties: Record<string, {
|
|
112
|
+
type: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
enum?: string[];
|
|
115
|
+
}>;
|
|
116
|
+
required?: string[];
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export type ClientFunction = (args: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
120
|
+
export interface FunctionDefinition {
|
|
121
|
+
name: string;
|
|
122
|
+
schema: FunctionSchema;
|
|
123
|
+
handler: ClientFunction;
|
|
124
|
+
}
|
|
125
|
+
export interface ClientFunctionInvocation {
|
|
126
|
+
invocationId: string;
|
|
127
|
+
functionName: string;
|
|
128
|
+
arguments: Record<string, unknown>;
|
|
129
|
+
conversationId: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* SSE stream chunk data
|
|
133
|
+
*/
|
|
134
|
+
export interface SSEChunkData {
|
|
135
|
+
content?: string;
|
|
136
|
+
full_content?: string;
|
|
137
|
+
message_id?: string;
|
|
138
|
+
status?: MessageStatus;
|
|
139
|
+
thread?: {
|
|
140
|
+
id: string;
|
|
141
|
+
};
|
|
142
|
+
agent?: {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
display_name?: string;
|
|
146
|
+
};
|
|
147
|
+
knowledge_sources?: Array<{
|
|
148
|
+
knowledge_document: {
|
|
149
|
+
id: string;
|
|
150
|
+
title: string;
|
|
151
|
+
use_external_link: boolean;
|
|
152
|
+
external_link_url?: string;
|
|
153
|
+
internal_link_url?: string;
|
|
154
|
+
};
|
|
155
|
+
position: number;
|
|
156
|
+
}>;
|
|
157
|
+
tool_call_data?: boolean;
|
|
158
|
+
type?: string;
|
|
159
|
+
id?: string;
|
|
160
|
+
tool_name?: string;
|
|
161
|
+
tool_display_name?: string;
|
|
162
|
+
function_name?: string;
|
|
163
|
+
arguments?: Record<string, unknown>;
|
|
164
|
+
form_schema?: FormSchema;
|
|
165
|
+
message?: string;
|
|
166
|
+
data?: Record<string, unknown>;
|
|
167
|
+
follow_up_replies?: string[];
|
|
168
|
+
satisfaction_feedback?: unknown;
|
|
169
|
+
ask_to_talk_to_human?: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* SDK Events
|
|
173
|
+
*/
|
|
174
|
+
export interface AgoClientEvents {
|
|
175
|
+
"message:start": {
|
|
176
|
+
conversationId: string;
|
|
177
|
+
messageId: string;
|
|
178
|
+
};
|
|
179
|
+
"message:chunk": {
|
|
180
|
+
content: string;
|
|
181
|
+
conversationId: string;
|
|
182
|
+
messageId: string;
|
|
183
|
+
};
|
|
184
|
+
"message:complete": AgoMessage;
|
|
185
|
+
"message:error": {
|
|
186
|
+
error: string;
|
|
187
|
+
conversationId?: string;
|
|
188
|
+
messageId?: string;
|
|
189
|
+
};
|
|
190
|
+
"toolCall:received": ToolCallData;
|
|
191
|
+
"toolCall:form": ToolCallData;
|
|
192
|
+
"function:invoke": ClientFunctionInvocation;
|
|
193
|
+
"function:result": {
|
|
194
|
+
invocationId: string;
|
|
195
|
+
result: unknown;
|
|
196
|
+
error?: string;
|
|
197
|
+
};
|
|
198
|
+
"connection:status": {
|
|
199
|
+
connected: boolean;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export type AgoEventName = keyof AgoClientEvents;
|
|
203
|
+
export type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
|