@applica-software-guru/persona-chat-sdk 0.1.102
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/.eslintrc.cjs +11 -0
- package/.github/copilot-instructions.md +3 -0
- package/.nvmrc +1 -0
- package/.prettierignore +5 -0
- package/.prettierrc +8 -0
- package/CLAUDE.md +3 -0
- package/GEMINI.md +3 -0
- package/README.md +33 -0
- package/bitbucket-pipelines.yml +19 -0
- package/components.json +24 -0
- package/dist/bundle.cjs.js +28 -0
- package/dist/bundle.cjs.js.map +1 -0
- package/dist/bundle.es.js +5173 -0
- package/dist/bundle.es.js.map +1 -0
- package/dist/bundle.iife.js +28 -0
- package/dist/bundle.iife.js.map +1 -0
- package/dist/bundle.umd.js +28 -0
- package/dist/bundle.umd.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/logging.d.ts +18 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/messages.d.ts +9 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/projects.d.ts +17 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/protocol/base.d.ts +25 -0
- package/dist/protocol/base.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +6 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/rest.d.ts +25 -0
- package/dist/protocol/rest.d.ts.map +1 -0
- package/dist/protocol/transaction.d.ts +56 -0
- package/dist/protocol/transaction.d.ts.map +1 -0
- package/dist/protocol/webrtc.d.ts +60 -0
- package/dist/protocol/webrtc.d.ts.map +1 -0
- package/dist/protocol/websocket.d.ts +22 -0
- package/dist/protocol/websocket.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +34 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/file-attachment-adapter.d.ts +15 -0
- package/dist/runtime/file-attachment-adapter.d.ts.map +1 -0
- package/dist/runtime/handlers.d.ts +21 -0
- package/dist/runtime/handlers.d.ts.map +1 -0
- package/dist/runtime/listeners.d.ts +6 -0
- package/dist/runtime/listeners.d.ts.map +1 -0
- package/dist/runtime/protocols.d.ts +17 -0
- package/dist/runtime/protocols.d.ts.map +1 -0
- package/dist/runtime/threads.d.ts +34 -0
- package/dist/runtime/threads.d.ts.map +1 -0
- package/dist/runtime/utils.d.ts +10 -0
- package/dist/runtime/utils.d.ts.map +1 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/storage/base.d.ts +9 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/persona.d.ts +29 -0
- package/dist/storage/persona.d.ts.map +1 -0
- package/dist/tools.d.ts +72 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +237 -0
- package/dist/types.d.ts.map +1 -0
- package/docs/README.md +13 -0
- package/docs/api-reference.md +16 -0
- package/docs/contributing.md +21 -0
- package/docs/customization.md +74 -0
- package/docs/features.md +7 -0
- package/docs/installation.md +9 -0
- package/docs/messages.md +214 -0
- package/docs/protocols.md +39 -0
- package/docs/transactions.md +121 -0
- package/docs/usage.md +40 -0
- package/jsconfig.node.json +10 -0
- package/package.json +82 -0
- package/playground/index.html +14 -0
- package/playground/src/app.tsx +10 -0
- package/playground/src/chat.tsx +117 -0
- package/playground/src/components/assistant-ui/assistant-modal.tsx +57 -0
- package/playground/src/components/assistant-ui/attachment.tsx +197 -0
- package/playground/src/components/assistant-ui/markdown-text.tsx +228 -0
- package/playground/src/components/assistant-ui/thread-list.tsx +91 -0
- package/playground/src/components/assistant-ui/thread.tsx +302 -0
- package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +59 -0
- package/playground/src/components/assistant-ui/tool-fallback.tsx +93 -0
- package/playground/src/components/assistant-ui/tooltip-icon-button.tsx +42 -0
- package/playground/src/components/chat/logging.tsx +53 -0
- package/playground/src/components/ui/avatar.tsx +51 -0
- package/playground/src/components/ui/button.tsx +60 -0
- package/playground/src/components/ui/dialog.tsx +141 -0
- package/playground/src/components/ui/input.tsx +21 -0
- package/playground/src/components/ui/separator.tsx +26 -0
- package/playground/src/components/ui/sheet.tsx +139 -0
- package/playground/src/components/ui/sidebar.tsx +619 -0
- package/playground/src/components/ui/skeleton.tsx +13 -0
- package/playground/src/components/ui/tooltip.tsx +59 -0
- package/playground/src/hooks/theme.ts +70 -0
- package/playground/src/hooks/use-mobile.ts +19 -0
- package/playground/src/lib/utils.ts +6 -0
- package/playground/src/main.tsx +10 -0
- package/playground/src/styles.css +120 -0
- package/playground/src/tools.ts +149 -0
- package/playground/src/vite-env.d.ts +1 -0
- package/preview-build.sh +23 -0
- package/src/index.ts +7 -0
- package/src/logging.ts +34 -0
- package/src/messages.ts +202 -0
- package/src/projects.ts +57 -0
- package/src/protocol/base.ts +73 -0
- package/src/protocol/index.ts +5 -0
- package/src/protocol/rest.ts +107 -0
- package/src/protocol/transaction.ts +182 -0
- package/src/protocol/webrtc.ts +379 -0
- package/src/protocol/websocket.ts +111 -0
- package/src/runtime/context.ts +88 -0
- package/src/runtime/file-attachment-adapter.ts +48 -0
- package/src/runtime/handlers.ts +322 -0
- package/src/runtime/index.ts +6 -0
- package/src/runtime/listeners.ts +79 -0
- package/src/runtime/protocols.ts +169 -0
- package/src/runtime/threads.ts +105 -0
- package/src/runtime/utils.ts +46 -0
- package/src/runtime.tsx +334 -0
- package/src/storage/base.ts +13 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/persona.ts +138 -0
- package/src/tools.ts +211 -0
- package/src/types.ts +284 -0
- package/tsconfig.json +36 -0
- package/tsconfig.node.json +15 -0
- package/vite.config.ts +74 -0
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type ToolParameterType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
2
|
+
export interface ToolParameter {
|
|
3
|
+
type: ToolParameterType;
|
|
4
|
+
description: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
properties?: Record<string, ToolParameter>;
|
|
7
|
+
items?: ToolParameter;
|
|
8
|
+
}
|
|
9
|
+
export interface ToolSchema {
|
|
10
|
+
type: 'local';
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
config: {
|
|
14
|
+
timeout: number;
|
|
15
|
+
parameters: {
|
|
16
|
+
type: 'object';
|
|
17
|
+
title: string;
|
|
18
|
+
required: string[];
|
|
19
|
+
properties: Record<string, ToolParameter>;
|
|
20
|
+
};
|
|
21
|
+
output: {
|
|
22
|
+
type: 'object';
|
|
23
|
+
title: string;
|
|
24
|
+
properties: Record<string, ToolParameter>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface ToolDefinition {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
title?: string;
|
|
32
|
+
timeout?: number;
|
|
33
|
+
parameters: Record<string, ToolParameter>;
|
|
34
|
+
output: Record<string, ToolParameter>;
|
|
35
|
+
implementation: (...args: any[]) => any;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a tool parameter definition
|
|
39
|
+
*/
|
|
40
|
+
export declare function createParameter(type: ToolParameterType, description: string, options?: {
|
|
41
|
+
required?: boolean;
|
|
42
|
+
properties?: Record<string, ToolParameter>;
|
|
43
|
+
items?: ToolParameter;
|
|
44
|
+
}): ToolParameter;
|
|
45
|
+
/**
|
|
46
|
+
* Generate a tool schema from a tool definition
|
|
47
|
+
*/
|
|
48
|
+
export declare function generateToolSchema(definition: ToolDefinition): ToolSchema;
|
|
49
|
+
export type ToolInstance = {
|
|
50
|
+
schema: ToolSchema;
|
|
51
|
+
implementation: (...args: any[]) => any;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Create a complete tool definition with schema and implementation
|
|
55
|
+
*/
|
|
56
|
+
export declare function createTool(definition: ToolDefinition): ToolInstance;
|
|
57
|
+
/**
|
|
58
|
+
* Extract function signature and generate schema from a JavaScript function
|
|
59
|
+
* This is a utility to help convert existing functions to tool schemas
|
|
60
|
+
*/
|
|
61
|
+
export declare function createToolFromFunction(name: string, description: string, fn: (...args: any[]) => any, parameterTypes: Record<string, ToolParameter>, outputTypes: Record<string, ToolParameter>, options?: {
|
|
62
|
+
title?: string;
|
|
63
|
+
timeout?: number;
|
|
64
|
+
}): ToolInstance;
|
|
65
|
+
export declare const sumTool: ToolInstance;
|
|
66
|
+
export declare const navigateToToolExample: ToolInstance;
|
|
67
|
+
export declare function createToolRegistry(tools: ToolDefinition[]): {
|
|
68
|
+
schemas: ToolSchema[];
|
|
69
|
+
implementations: Record<string, (...args: any[]) => any>;
|
|
70
|
+
};
|
|
71
|
+
export declare function validateToolParameters(parameters: Record<string, any>, schema: ToolSchema): boolean;
|
|
72
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAErF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ,CAAC;YACf,KAAK,EAAE,MAAM,CAAC;YACd,QAAQ,EAAE,MAAM,EAAE,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AW,EAAE,MAAM,EACnB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,OAAO,CAAC,EAAE;IACR,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,YAAY,CAYd;AAGD,eAAO,MAAM,OAAO,cAcnB,CAAC;AAGF,eAAO,MAAM,qBAAqB,cAiBhC,CAAC;AAGH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG;IAC3D,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;CAC1D,CAWA;AAGD,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CA2BnG"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { PersonaTools } from 'src/protocol';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import type { ToolInstance } from './tools';
|
|
4
|
+
import type { PersonaLogger } from './logging';
|
|
5
|
+
import type { SessionStorage } from './storage';
|
|
6
|
+
export type { PersonaLogger, SessionStorage };
|
|
7
|
+
export type ReadonlyJSONObject = {
|
|
8
|
+
readonly [key: string]: string | number | boolean | null | ReadonlyJSONObject | ReadonlyArray<ReadonlyJSONObject>;
|
|
9
|
+
};
|
|
10
|
+
export type FunctionCall = {
|
|
11
|
+
id?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
args: ReadonlyJSONObject;
|
|
14
|
+
};
|
|
15
|
+
export type FunctionResponse = {
|
|
16
|
+
name: string;
|
|
17
|
+
result: unknown;
|
|
18
|
+
function_call_id: string;
|
|
19
|
+
};
|
|
20
|
+
export type PersonaFile = {
|
|
21
|
+
name: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
base64?: string;
|
|
24
|
+
contentType: string;
|
|
25
|
+
};
|
|
26
|
+
export type PersonaSession = {
|
|
27
|
+
id: string;
|
|
28
|
+
code: string;
|
|
29
|
+
projectId: string;
|
|
30
|
+
agentId: string;
|
|
31
|
+
currentAgentId: string;
|
|
32
|
+
userId: string;
|
|
33
|
+
status: 'active' | 'finished';
|
|
34
|
+
type: 'realtime' | 'async';
|
|
35
|
+
createdAt: string;
|
|
36
|
+
finishedAt: string | null;
|
|
37
|
+
};
|
|
38
|
+
export type PersonaProjectSubscription = {
|
|
39
|
+
id: string;
|
|
40
|
+
projectId?: string | null;
|
|
41
|
+
owner?: string | null;
|
|
42
|
+
planType: 'free' | 'baby' | 'junior' | 'pro' | 'mentor';
|
|
43
|
+
status: 'creating' | 'active' | 'inactive' | 'cancelled';
|
|
44
|
+
startDate?: string | null;
|
|
45
|
+
planCredits: number;
|
|
46
|
+
extraCredits: number;
|
|
47
|
+
keepCreditsOnRenew: boolean;
|
|
48
|
+
endDate?: string | null;
|
|
49
|
+
createdAt?: string | null;
|
|
50
|
+
updatedAt?: string | null;
|
|
51
|
+
stripeCustomerId?: string | null;
|
|
52
|
+
stripeSubscriptionId?: string | null;
|
|
53
|
+
};
|
|
54
|
+
export type PersonaAgentContext = {
|
|
55
|
+
data: Record<string, unknown>;
|
|
56
|
+
files?: PersonaFile[];
|
|
57
|
+
session?: PersonaSession;
|
|
58
|
+
};
|
|
59
|
+
export type PersonaTransaction = {
|
|
60
|
+
id: string;
|
|
61
|
+
projectId: string;
|
|
62
|
+
sessionId: string;
|
|
63
|
+
status: 'pending' | 'completed' | 'failed';
|
|
64
|
+
error: string | null;
|
|
65
|
+
functionCall: FunctionCall | null;
|
|
66
|
+
context: PersonaAgentContext;
|
|
67
|
+
};
|
|
68
|
+
export type PersonaReasoning = {
|
|
69
|
+
thought: string;
|
|
70
|
+
imageUrl?: string;
|
|
71
|
+
};
|
|
72
|
+
export type PersonaImage = {
|
|
73
|
+
content: string;
|
|
74
|
+
contentType: string;
|
|
75
|
+
};
|
|
76
|
+
export type PersonaSourceChunk = {
|
|
77
|
+
start: number;
|
|
78
|
+
end: number;
|
|
79
|
+
};
|
|
80
|
+
export type PersonaSource = {
|
|
81
|
+
type: 'web' | 'document';
|
|
82
|
+
url?: string;
|
|
83
|
+
documentId?: string;
|
|
84
|
+
pageId?: string;
|
|
85
|
+
pageNumber?: number;
|
|
86
|
+
chunks?: PersonaSourceChunk[];
|
|
87
|
+
mostRelevant?: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type PersonaCommand = {
|
|
90
|
+
command: 'get_mcp_assets' | 'set_initial_context' | 'set_local_tools';
|
|
91
|
+
arguments: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
export type PersonaRequest = PersonaMessage | Array<PersonaMessage> | string;
|
|
94
|
+
export type PersonaPacketPayload = PersonaRequest | PersonaCommand | PersonaReasoning | PersonaTransaction;
|
|
95
|
+
export type PersonaPacket = {
|
|
96
|
+
type: 'request' | 'message' | 'command' | 'reasoning' | 'mcp_assets' | 'transaction';
|
|
97
|
+
payload?: PersonaPacketPayload;
|
|
98
|
+
};
|
|
99
|
+
export type PersonaMessage = {
|
|
100
|
+
id?: string | null;
|
|
101
|
+
protocol?: string;
|
|
102
|
+
thought?: string;
|
|
103
|
+
text: string;
|
|
104
|
+
image?: PersonaImage;
|
|
105
|
+
type: 'reasoning' | 'text' | 'transaction' | 'command';
|
|
106
|
+
role: 'user' | 'assistant' | 'function';
|
|
107
|
+
file?: PersonaFile;
|
|
108
|
+
sources?: PersonaSource[];
|
|
109
|
+
sessionId?: string;
|
|
110
|
+
finishReason?: 'stop' | 'function_call';
|
|
111
|
+
functionCalls?: FunctionCall[];
|
|
112
|
+
functionResponse?: FunctionResponse;
|
|
113
|
+
status?: {
|
|
114
|
+
type: 'running' | 'complete' | 'incomplete';
|
|
115
|
+
};
|
|
116
|
+
createdAt?: Date;
|
|
117
|
+
metadata?: {
|
|
118
|
+
custom?: Record<string, unknown>;
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export type ModelResponse = {
|
|
123
|
+
messages: PersonaMessage[];
|
|
124
|
+
};
|
|
125
|
+
export type PersonaResponse = {
|
|
126
|
+
sessionId: string;
|
|
127
|
+
response: ModelResponse;
|
|
128
|
+
};
|
|
129
|
+
export type PersonaBaseConfig = {
|
|
130
|
+
logger?: PersonaLogger;
|
|
131
|
+
};
|
|
132
|
+
export type PersonaWebRTCConfig = PersonaBaseConfig & {
|
|
133
|
+
webrtcUrl: string;
|
|
134
|
+
iceServers?: RTCIceServer[];
|
|
135
|
+
onDataMessage?: (msg: MessageEvent) => void;
|
|
136
|
+
};
|
|
137
|
+
export type Session = string | null | undefined;
|
|
138
|
+
export type TransformMessages = (messages: PersonaMessage[]) => PersonaMessage[];
|
|
139
|
+
export type ThreadData = {
|
|
140
|
+
threadId: string;
|
|
141
|
+
title?: string;
|
|
142
|
+
status: 'regular' | 'archived';
|
|
143
|
+
};
|
|
144
|
+
export type MessageListenerCallback = (message: PersonaPacket) => void;
|
|
145
|
+
export type StatusChangeCallback = (status: ProtocolStatus) => void;
|
|
146
|
+
export type ProtocolStatus = 'disconnected' | 'connecting' | 'connected';
|
|
147
|
+
export type PersonaProtocolBaseConfig = {
|
|
148
|
+
logger?: PersonaLogger;
|
|
149
|
+
apiKey: string;
|
|
150
|
+
agentId: string;
|
|
151
|
+
userId?: string;
|
|
152
|
+
};
|
|
153
|
+
export interface PersonaProtocol {
|
|
154
|
+
status: ProtocolStatus;
|
|
155
|
+
autostart: boolean;
|
|
156
|
+
getName: () => string;
|
|
157
|
+
getPriority: () => number;
|
|
158
|
+
connect: (session?: Session) => Promise<Session>;
|
|
159
|
+
disconnect: () => Promise<void>;
|
|
160
|
+
onTransaction: (transaction: PersonaTransaction) => void;
|
|
161
|
+
setSession: (session: Session) => Promise<void>;
|
|
162
|
+
sendPacket: (packet: PersonaPacket) => Promise<void>;
|
|
163
|
+
setAgentContext: (context: PersonaAgentContext) => Promise<void>;
|
|
164
|
+
clearListeners: () => void;
|
|
165
|
+
addStatusChangeListener: (callback: StatusChangeCallback) => void;
|
|
166
|
+
addPacketListener: (callback: MessageListenerCallback) => void;
|
|
167
|
+
}
|
|
168
|
+
export type PersonaConfig = PersonaBaseConfig & PersonaProtocolBaseConfig & {
|
|
169
|
+
/**
|
|
170
|
+
* In 'dev' mode the endpoint is set to localhost:8000,
|
|
171
|
+
* use it only for development purposes.
|
|
172
|
+
*/
|
|
173
|
+
dev?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* The base URL of the API.
|
|
176
|
+
* @default 'persona.applica.guru/api'
|
|
177
|
+
*/
|
|
178
|
+
baseUrl?: string;
|
|
179
|
+
session?: Session;
|
|
180
|
+
children: ReactNode;
|
|
181
|
+
context?: PersonaAgentContext;
|
|
182
|
+
protocols: PersonaProtocol[] | {
|
|
183
|
+
rest?: PersonaProtocolBaseConfig | boolean;
|
|
184
|
+
webrtc?: PersonaProtocolBaseConfig | boolean;
|
|
185
|
+
websocket?: PersonaProtocolBaseConfig | boolean;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Tools can be provided as an object (legacy) or as an array of { schema, implementation } (recommended)
|
|
189
|
+
*/
|
|
190
|
+
tools?: PersonaTools | ToolInstance[];
|
|
191
|
+
/**
|
|
192
|
+
* Optional message transform function that processes messages before they are displayed
|
|
193
|
+
*/
|
|
194
|
+
transformMessages?: TransformMessages;
|
|
195
|
+
/**
|
|
196
|
+
* Enable thread management support
|
|
197
|
+
*/
|
|
198
|
+
threads?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Session storage implementation
|
|
201
|
+
* If not provided, defaults to PersonaSessionStorage
|
|
202
|
+
*/
|
|
203
|
+
sessionStorage?: SessionStorage;
|
|
204
|
+
/**
|
|
205
|
+
* Initial thread list (if thread management is enabled)
|
|
206
|
+
*/
|
|
207
|
+
initialThreads?: ThreadData[];
|
|
208
|
+
/**
|
|
209
|
+
* Callback when a new thread is created
|
|
210
|
+
*/
|
|
211
|
+
onThreadCreate?: (threadId: string) => void;
|
|
212
|
+
/**
|
|
213
|
+
* Callback when switching to a thread
|
|
214
|
+
*/
|
|
215
|
+
onThreadSwitch?: (threadId: string) => void;
|
|
216
|
+
/**
|
|
217
|
+
* Callback when a thread is renamed
|
|
218
|
+
*/
|
|
219
|
+
onThreadRename?: (threadId: string, newTitle: string) => void;
|
|
220
|
+
/**
|
|
221
|
+
* Callback when a thread is archived
|
|
222
|
+
*/
|
|
223
|
+
onThreadArchive?: (threadId: string) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Callback when a thread is unarchived
|
|
226
|
+
*/
|
|
227
|
+
onThreadUnarchive?: (threadId: string) => void;
|
|
228
|
+
/**
|
|
229
|
+
* Callback when a thread is deleted
|
|
230
|
+
*/
|
|
231
|
+
onThreadDelete?: (threadId: string) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Enable file attachments (images, PDFs, text files) in the composer
|
|
234
|
+
*/
|
|
235
|
+
enableAttachments?: boolean;
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,YAAY,EAAE,aAAa,EAA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AAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAE5C;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC"}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Persona Chat SDK Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the Persona Chat SDK documentation.
|
|
4
|
+
|
|
5
|
+
- [Features](features.md)
|
|
6
|
+
- [Installation](installation.md)
|
|
7
|
+
- [Usage](usage.md)
|
|
8
|
+
- [Messages and Storage](messages.md)
|
|
9
|
+
- [Protocols](protocols.md)
|
|
10
|
+
- [API Reference](api-reference.md)
|
|
11
|
+
- [Transactions and Tools](transactions.md)
|
|
12
|
+
- [Customization](customization.md)
|
|
13
|
+
- [Contributing](contributing.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Props for `PersonaRuntimeProvider`
|
|
4
|
+
|
|
5
|
+
| Prop | Type | Default Value | Description |
|
|
6
|
+
| --------------- | ------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| `dev` | boolean | `false` | Enable development mode for local Persona API usage. |
|
|
8
|
+
| `logger` | function | `console.log` | Custom logger for debugging and logging messages. |
|
|
9
|
+
| `protocols` | object | `{ rest: true, webrtc: true, websocket: true }` | Protocols to use for the chat. Can be enabled/disabled using boolean values. |
|
|
10
|
+
| `session` | string | `undefined` | Session ID for the chat. Required for the chat to function. |
|
|
11
|
+
| `apiKey` | string | `toolkit-test` | API key for authentication. Required for the chat to function. |
|
|
12
|
+
| `agentId` | string | `default` | Agent ID for the chat. Required for the chat to function. |
|
|
13
|
+
| `messageFilter` | MessageFilter | `undefined` | Optional function to filter and transform messages before they are displayed in the chat interface. |
|
|
14
|
+
| `messageStorage`| MessageStorage| `InMemoryMessageStorage` | Optional storage implementation for persisting messages. |
|
|
15
|
+
| `threads` | boolean | `false` | Enable thread management. |
|
|
16
|
+
| `tools` | object\|array | `undefined` | Custom tools for the Transaction Protocol. |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
We welcome contributions! To get started:
|
|
4
|
+
|
|
5
|
+
1. Fork the repository.
|
|
6
|
+
2. Create a new branch for your feature or bugfix.
|
|
7
|
+
3. Submit a pull request with a detailed description of your changes.
|
|
8
|
+
|
|
9
|
+
Please ensure your code adheres to the existing style and passes all linting and testing checks.
|
|
10
|
+
|
|
11
|
+
## Support
|
|
12
|
+
|
|
13
|
+
For questions or support, contact us at [info@applica.guru](mailto:info@applica.guru).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
18
|
+
|
|
19
|
+
## Acknowledgments
|
|
20
|
+
|
|
21
|
+
This SDK is built on top of [assistant-ui](https://www.assistant-ui.com/), a powerful framework for building conversational interfaces.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Customization
|
|
2
|
+
|
|
3
|
+
The Persona Chat SDK allows you to extend its functionality by creating custom protocols and loggers.
|
|
4
|
+
|
|
5
|
+
## Custom Protocols
|
|
6
|
+
|
|
7
|
+
You can implement your own protocol by extending the `PersonaProtocolBase` class. For example:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { PersonaProtocolBase } from '@applica-software-guru/persona-chat-sdk';
|
|
11
|
+
|
|
12
|
+
class CustomProtocol extends PersonaProtocolBase {
|
|
13
|
+
// Implement required methods like connect, disconnect, send, etc.
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Example: Custom Protocol Implementation
|
|
18
|
+
|
|
19
|
+
Here’s an example of a custom protocol named `CustomProtocol`:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { PersonaProtocolBase } from '@applica-software-guru/persona-chat-sdk';
|
|
23
|
+
|
|
24
|
+
class CustomProtocol extends PersonaProtocolBase {
|
|
25
|
+
public getName(): string {
|
|
26
|
+
return 'custom';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async connect(): Promise<void> {
|
|
30
|
+
console.log('[CustomProtocol] Connecting...');
|
|
31
|
+
this.setStatus('connected');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async disconnect(): Promise<void> {
|
|
35
|
+
console.log('[CustomProtocol] Disconnecting...');
|
|
36
|
+
this.setStatus('disconnected');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async send(message: string): Promise<void> {
|
|
40
|
+
console.log(`[CustomProtocol] Sending message: ${message}`);
|
|
41
|
+
this.notifyMessage({ role: 'assistant', type: 'text', text: `Echo: ${message}` });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Custom Loggers
|
|
47
|
+
|
|
48
|
+
You can create a custom logger by implementing the `PersonaLogger` interface:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { PersonaLogger } from '@applica-software-guru/persona-chat-sdk';
|
|
52
|
+
|
|
53
|
+
class CustomLogger implements PersonaLogger {
|
|
54
|
+
log(message: string, ...args: unknown[]): void {
|
|
55
|
+
console.log(`[CustomLogger] ${message}`, ...args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
info(message: string, ...args: unknown[]): void {
|
|
59
|
+
console.info(`[CustomLogger] ${message}`, ...args);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
warn(message: string, ...args: unknown[]): void {
|
|
63
|
+
console.warn(`[CustomLogger] ${message}`, ...args);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
error(message: string, ...args: unknown[]): void {
|
|
67
|
+
console.error(`[CustomLogger] ${message}`, ...args);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
debug(message: string, ...args: unknown[]): void {
|
|
71
|
+
console.debug(`[CustomLogger] ${message}`, ...args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
package/docs/features.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Features
|
|
2
|
+
|
|
3
|
+
- **Custom Runtime Provider**: Easily integrate the Persona API with assistant-ui chat.
|
|
4
|
+
- **Local Runtime Support**: Run the assistant-ui chat locally using the Persona API.
|
|
5
|
+
- **Multiple Protocols**: Supports REST, WebSocket, and WebRTC protocols.
|
|
6
|
+
- **WebRTC Optimization**: Communicate with AI agents in real-time using the fastest protocol available.
|
|
7
|
+
- **Customizable**: Extend functionality with custom protocols and loggers.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
To get started, install the Persona Chat SDK using npm or yarn:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @applica-software-guru/persona-chat-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
If you don't already have an assistant-ui-based project, you can create one using the [Assistant UI Getting Started Guide](https://www.assistant-ui.com/docs/getting-started).
|