@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,46 @@
|
|
|
1
|
+
import type { AgoMessage, ToolCallData } from "../client/types";
|
|
2
|
+
export interface SSEHandlerCallbacks {
|
|
3
|
+
onStart?: (data: {
|
|
4
|
+
conversationId: string;
|
|
5
|
+
messageId: string;
|
|
6
|
+
}) => void;
|
|
7
|
+
onChunk?: (data: {
|
|
8
|
+
content: string;
|
|
9
|
+
conversationId: string;
|
|
10
|
+
messageId: string;
|
|
11
|
+
}) => void;
|
|
12
|
+
onToolCall?: (toolCall: ToolCallData) => void;
|
|
13
|
+
onClientFunction?: (data: {
|
|
14
|
+
invocationId: string;
|
|
15
|
+
functionName: string;
|
|
16
|
+
arguments: Record<string, unknown>;
|
|
17
|
+
conversationId: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
onComplete?: (message: AgoMessage) => void;
|
|
20
|
+
onError?: (error: Error) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handles SSE streaming responses from AGO backend
|
|
24
|
+
*/
|
|
25
|
+
export declare class SSEHandler {
|
|
26
|
+
private callbacks;
|
|
27
|
+
private buffer;
|
|
28
|
+
private message;
|
|
29
|
+
private toolCalls;
|
|
30
|
+
private sources;
|
|
31
|
+
private followUpReplies;
|
|
32
|
+
private isFirstChunk;
|
|
33
|
+
constructor(callbacks: SSEHandlerCallbacks);
|
|
34
|
+
/**
|
|
35
|
+
* Process a streaming response
|
|
36
|
+
*/
|
|
37
|
+
processStream(response: Response): Promise<AgoMessage>;
|
|
38
|
+
private processBuffer;
|
|
39
|
+
private handleChunk;
|
|
40
|
+
private parseToolCall;
|
|
41
|
+
private buildFinalMessage;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if an error is a network error that should trigger polling fallback
|
|
45
|
+
*/
|
|
46
|
+
export declare function isStreamNetworkError(error: Error): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AgoClient } from "../client/AgoClient";
|
|
2
|
+
import type { AgoClientEvents, AgoEventName } from "../client/types";
|
|
3
|
+
type MockFn = (...args: any[]) => any;
|
|
4
|
+
export interface MockAgoClientOptions {
|
|
5
|
+
overrides?: Partial<Record<string, MockFn>>;
|
|
6
|
+
}
|
|
7
|
+
export interface MockAgoClient extends AgoClient {
|
|
8
|
+
/**
|
|
9
|
+
* Simulate a server-pushed event.
|
|
10
|
+
* ```ts
|
|
11
|
+
* mock.__emitEvent("message:complete", { id: "1", content: "hi", ... });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
__emitEvent<K extends AgoEventName>(event: K, data: AgoClientEvents[K]): void;
|
|
15
|
+
/**
|
|
16
|
+
* All recorded method calls: `[methodName, ...args][]`
|
|
17
|
+
*/
|
|
18
|
+
__calls: Array<{
|
|
19
|
+
method: string;
|
|
20
|
+
args: unknown[];
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Get calls for a specific method.
|
|
24
|
+
*/
|
|
25
|
+
__callsFor(method: string): Array<{
|
|
26
|
+
method: string;
|
|
27
|
+
args: unknown[];
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a mock AgoClient for testing. Works with any framework.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { createMockClient } from "@useago/sdk/testing";
|
|
35
|
+
*
|
|
36
|
+
* const mock = createMockClient();
|
|
37
|
+
* mock.__emitEvent("message:complete", someMessage);
|
|
38
|
+
* expect(mock.__callsFor("sendMessage")).toHaveLength(1);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createMockClient(options?: MockAgoClientOptions): MockAgoClient;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type EventHandler<T = unknown> = (data: T) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Simple typed event emitter
|
|
4
|
+
*/
|
|
5
|
+
export declare class EventEmitter<Events extends Record<string, any> = Record<string, unknown>> {
|
|
6
|
+
private handlers;
|
|
7
|
+
on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
|
|
8
|
+
off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
|
|
9
|
+
emit<K extends keyof Events>(event: K, data: Events[K]): void;
|
|
10
|
+
/**
|
|
11
|
+
* Subscribe to an event and auto-unsubscribe after the first call.
|
|
12
|
+
*/
|
|
13
|
+
once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a Promise that resolves the next time `event` fires.
|
|
16
|
+
* Rejects if `timeout` (ms) is reached first.
|
|
17
|
+
*/
|
|
18
|
+
waitFor<K extends keyof Events>(event: K, options?: {
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}): Promise<Events[K]>;
|
|
21
|
+
removeAllListeners(event?: keyof Events): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug logger for SDK
|
|
3
|
+
*/
|
|
4
|
+
export declare class Logger {
|
|
5
|
+
private enabled;
|
|
6
|
+
constructor(enabled?: boolean);
|
|
7
|
+
enable(): void;
|
|
8
|
+
disable(): void;
|
|
9
|
+
log(...args: unknown[]): void;
|
|
10
|
+
warn(...args: unknown[]): void;
|
|
11
|
+
error(...args: unknown[]): void;
|
|
12
|
+
debug(...args: unknown[]): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const logger: Logger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { AgoWidgetConfig, AgoWidgetColors } from "./types";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget configuration types.
|
|
3
|
+
*
|
|
4
|
+
* These types describe the `window.AGO` configuration object
|
|
5
|
+
* used by the embeddable chat widget snippet.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { AgoWidgetConfig } from "@useago/sdk/widget";
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface AgoWidgetColors {
|
|
13
|
+
button?: string;
|
|
14
|
+
header?: string;
|
|
15
|
+
agentMessage?: string;
|
|
16
|
+
agentMessageFont?: string;
|
|
17
|
+
background?: string;
|
|
18
|
+
font?: string;
|
|
19
|
+
userMessage?: string;
|
|
20
|
+
userMessageFont?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface AgoWidgetConfig {
|
|
23
|
+
basepath: string;
|
|
24
|
+
widgetApiKey: string;
|
|
25
|
+
defaultAgent?: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
prompt?: string;
|
|
30
|
+
notifications?: boolean;
|
|
31
|
+
notificationMessage?: string;
|
|
32
|
+
colors?: AgoWidgetColors;
|
|
33
|
+
hideFooter?: boolean;
|
|
34
|
+
jwt?: string;
|
|
35
|
+
authToken?: string;
|
|
36
|
+
permission?: string;
|
|
37
|
+
}
|
|
38
|
+
declare global {
|
|
39
|
+
interface Window {
|
|
40
|
+
AGO: AgoWidgetConfig;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/widget.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './widget/index'
|
package/dist/widget.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@useago/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript SDK for AGO Chat integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"import": "./dist/react.js",
|
|
17
|
+
"require": "./dist/react.cjs",
|
|
18
|
+
"types": "./dist/react.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./widget": {
|
|
21
|
+
"import": "./dist/widget.js",
|
|
22
|
+
"require": "./dist/widget.cjs",
|
|
23
|
+
"types": "./dist/widget.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
35
|
+
"dev": "vite build --watch",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest",
|
|
38
|
+
"lint": "eslint src/",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"react-markdown": "^9.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": ">=17.0.0",
|
|
46
|
+
"react-dom": ">=17.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"react": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"react-dom": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^20.0.0",
|
|
58
|
+
"@types/react": "^18.0.0",
|
|
59
|
+
"@types/react-dom": "^18.0.0",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
61
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
62
|
+
"eslint": "^8.0.0",
|
|
63
|
+
"jsdom": "^28.0.0",
|
|
64
|
+
"react": "^18.0.0",
|
|
65
|
+
"react-dom": "^18.0.0",
|
|
66
|
+
"typescript": "^5.0.0",
|
|
67
|
+
"vite": "^5.0.0",
|
|
68
|
+
"vite-plugin-dts": "^3.0.0",
|
|
69
|
+
"vitest": "^1.0.0"
|
|
70
|
+
},
|
|
71
|
+
"keywords": [
|
|
72
|
+
"ago",
|
|
73
|
+
"chat",
|
|
74
|
+
"sdk",
|
|
75
|
+
"ai",
|
|
76
|
+
"chatbot"
|
|
77
|
+
],
|
|
78
|
+
"license": "MIT",
|
|
79
|
+
"repository": {
|
|
80
|
+
"type": "git",
|
|
81
|
+
"url": "https://github.com/useago/sdk.git"
|
|
82
|
+
}
|
|
83
|
+
}
|