ttc-ai-chat-sdk 0.0.12-beta → 0.0.14-dev
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 +52 -29
- package/dist/assistant.js +107 -0
- package/dist/assistant.js.map +1 -0
- package/dist/construct.js +2 -2
- package/dist/construct.js.map +1 -1
- package/dist/core.js +10 -24
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +142 -298
- package/dist/internal.js +61 -65
- package/dist/internal.js.map +1 -1
- package/dist/public-types.js +7 -0
- package/dist/public-types.js.map +1 -0
- package/dist/ttc_server.js +38 -133
- package/dist/ttc_server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,311 +1,155 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { Socket } from 'socket.io-client';
|
|
4
|
-
import z from 'zod';
|
|
5
3
|
import { ZodSchema } from 'zod';
|
|
6
4
|
|
|
7
|
-
export type f_call = {
|
|
8
|
-
function: string;
|
|
9
|
-
arguments: Record<string, any>;
|
|
10
|
-
};
|
|
11
|
-
export type statusType = "success" | "error";
|
|
12
|
-
export type ClassType<T = any> = new (...args: any[]) => T;
|
|
13
|
-
export type rpcResponseType = {
|
|
14
|
-
status: statusType;
|
|
15
|
-
data?: any;
|
|
16
|
-
};
|
|
17
|
-
export type RPCMethodInfo = {
|
|
18
|
-
name: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
permission?: boolean;
|
|
21
|
-
input_schema?: string;
|
|
22
|
-
output_schema?: string;
|
|
23
|
-
};
|
|
24
5
|
export type ttc_event = "message" | "function_call" | "permission" | "sentinel_dispatch" | "sentinel_terminated" | "construct" | "status_change" | "action_log";
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
status: "success" | "error";
|
|
29
|
-
data?: T;
|
|
6
|
+
export type EventPayload = {
|
|
7
|
+
id: string;
|
|
8
|
+
payload: any;
|
|
30
9
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* sends a function response to the ai
|
|
49
|
-
*
|
|
50
|
-
* @param {conversation_id: string, response: any[], image_urls: any[]}
|
|
51
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
52
|
-
*/
|
|
53
|
-
functionResponse(conversation_id: string, response: any[], image_urls: any[]): Promise<rpcResponseType$1<any>>;
|
|
54
|
-
/**
|
|
55
|
-
* get chat history
|
|
56
|
-
*
|
|
57
|
-
* @param {conversation_id: string, limit: number, page: number}
|
|
58
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
59
|
-
*/
|
|
60
|
-
fetchChatHistory(conversation_id: string, limit: number, page: number): Promise<rpcResponseType$1<any>>;
|
|
61
|
-
/**
|
|
62
|
-
* sets a function for the app
|
|
63
|
-
*
|
|
64
|
-
* @param {conversation_id: string, func: Partial<{ }> }
|
|
65
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
66
|
-
*/
|
|
67
|
-
setAppFunctions(conversation_id: string, func: Partial<{}>): Promise<rpcResponseType$1<any>>;
|
|
68
|
-
/**
|
|
69
|
-
* Generates a chat token
|
|
70
|
-
*
|
|
71
|
-
* @param {uuid: string}
|
|
72
|
-
* @returns {Promise<rpcResponseType<{ chatId: string }>>}
|
|
73
|
-
*/
|
|
74
|
-
createChat(uuid: string): Promise<rpcResponseType$1<{
|
|
75
|
-
chatId: string;
|
|
76
|
-
}>>;
|
|
77
|
-
/**
|
|
78
|
-
* Updates a chat
|
|
79
|
-
*
|
|
80
|
-
* @param {chatId: string, metadata: Partial<{ }> }
|
|
81
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
82
|
-
*/
|
|
83
|
-
updateChat(chatId: string, metadata: Partial<{}>): Promise<rpcResponseType$1<any>>;
|
|
84
|
-
/**
|
|
85
|
-
* Fetches all chats for an app
|
|
86
|
-
*
|
|
87
|
-
* @param {page: number, limit: number}
|
|
88
|
-
* @returns {Promise<rpcResponseType<string[]>>}
|
|
89
|
-
*/
|
|
90
|
-
fetchChats(page: number, limit: number): Promise<rpcResponseType$1<string[]>>;
|
|
91
|
-
/**
|
|
92
|
-
* Fetches a chat
|
|
93
|
-
*
|
|
94
|
-
* @param {chatId: string}
|
|
95
|
-
* @returns {Promise<rpcResponseType<{ id: string; inputTokens: number; outputTokens: number; metadata?: any }>>}
|
|
96
|
-
*/
|
|
97
|
-
fetchChat(chatId: string): Promise<rpcResponseType$1<{
|
|
98
|
-
id: string;
|
|
99
|
-
inputTokens: number;
|
|
100
|
-
outputTokens: number;
|
|
101
|
-
metadata?: any;
|
|
102
|
-
}>>;
|
|
103
|
-
/**
|
|
104
|
-
* Updates a chat
|
|
105
|
-
*
|
|
106
|
-
* @param {chatId: string}
|
|
107
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
108
|
-
*/
|
|
109
|
-
deleteChat(chatId: string): Promise<rpcResponseType$1<any>>;
|
|
110
|
-
/**
|
|
111
|
-
* Clears chat history, soft clears messages but retains system prompt and functions, hard clears everything
|
|
112
|
-
*
|
|
113
|
-
* @param {conversation_id: string, mode: string}
|
|
114
|
-
* @returns {Promise<rpcResponseType<string>>}
|
|
115
|
-
*/
|
|
116
|
-
clearChatHistory(conversation_id: string, mode: string): Promise<rpcResponseType$1<string>>;
|
|
117
|
-
/**
|
|
118
|
-
* fetches an emote
|
|
119
|
-
*
|
|
120
|
-
* @param {}
|
|
121
|
-
* @returns {Promise<rpcResponseType<{ emote: string; modelId?: string }>>}
|
|
122
|
-
*/
|
|
123
|
-
fetchEmote(): Promise<rpcResponseType$1<{
|
|
124
|
-
emote: string;
|
|
125
|
-
modelId?: string;
|
|
126
|
-
}>>;
|
|
127
|
-
/**
|
|
128
|
-
* Adds a remote origin for an app
|
|
129
|
-
*
|
|
130
|
-
* @param {app_id: string}
|
|
131
|
-
* @returns {Promise<rpcResponseType<{ url: string; name: string }[]>>}
|
|
132
|
-
*/
|
|
133
|
-
fetchOrigins(app_id: string): Promise<rpcResponseType$1<{
|
|
134
|
-
url: string;
|
|
135
|
-
name: string;
|
|
136
|
-
apikey: string;
|
|
137
|
-
}[]>>;
|
|
138
|
-
};
|
|
139
|
-
AppOAuth: {
|
|
140
|
-
/**
|
|
141
|
-
* Generate OAuth authorization URL for app integration. Platform embeds this URL to start OAuth flow.
|
|
142
|
-
*
|
|
143
|
-
* @param {appId: string, redirectUri: string, scopes: string, state: string}
|
|
144
|
-
* @returns {Promise<rpcResponseType<{ authorizationUrl: string; state: string }>>}
|
|
145
|
-
*/
|
|
146
|
-
generateAuthorizationUrl(appId: string, redirectUri: string, scopes: string, state: string): Promise<rpcResponseType$1<{
|
|
147
|
-
authorizationUrl: string;
|
|
148
|
-
state: string;
|
|
149
|
-
}>>;
|
|
150
|
-
/**
|
|
151
|
-
* Exchange authorization code for access token. Called by platform backend after receiving code.
|
|
152
|
-
*
|
|
153
|
-
* @param {code: string, appId: string, redirectUri: string}
|
|
154
|
-
* @returns {Promise<rpcResponseType<{ accessToken: string; tokenType: string; expiresIn: number; appUserId: string; emote: any }>>}
|
|
155
|
-
*/
|
|
156
|
-
exchangeCodeForToken(code: string, appId: string, redirectUri: string): Promise<rpcResponseType$1<{
|
|
157
|
-
accessToken: string;
|
|
158
|
-
tokenType: string;
|
|
159
|
-
expiresIn: number;
|
|
160
|
-
appUserId: string;
|
|
161
|
-
emote: any;
|
|
162
|
-
}>>;
|
|
163
|
-
/**
|
|
164
|
-
* Refresh an expired access token for continued API access.
|
|
165
|
-
*
|
|
166
|
-
* @param {appUserId: string, appId: string}
|
|
167
|
-
* @returns {Promise<rpcResponseType<{ accessToken: string; tokenType: string; expiresIn: number; appUserId: string }>>}
|
|
168
|
-
*/
|
|
169
|
-
refreshToken(appUserId: string, appId: string): Promise<rpcResponseType$1<{
|
|
170
|
-
accessToken: string;
|
|
171
|
-
tokenType: string;
|
|
172
|
-
expiresIn: number;
|
|
173
|
-
appUserId: string;
|
|
174
|
-
}>>;
|
|
175
|
-
};
|
|
176
|
-
Media: {
|
|
177
|
-
/**
|
|
178
|
-
* Uploads an image to S3 and returns its URL. Replaces any existing image for the conversation.
|
|
179
|
-
*
|
|
180
|
-
* @param {appId: string, conversationId: string, file: any}
|
|
181
|
-
* @returns {Promise<rpcResponseType<{ url: string }>>}
|
|
182
|
-
*/
|
|
183
|
-
uploadImage(appId: string, conversationId: string, file: any): Promise<rpcResponseType$1<{
|
|
184
|
-
url: string;
|
|
185
|
-
}>>;
|
|
186
|
-
};
|
|
187
|
-
TCC: {
|
|
188
|
-
/**
|
|
189
|
-
* Get list of all models available to you
|
|
190
|
-
*
|
|
191
|
-
* @param {conversation_id: string}
|
|
192
|
-
* @returns {Promise<rpcResponseType<{ id: string; name: string; type: string; provider: string }[]>>}
|
|
193
|
-
*/
|
|
194
|
-
get_models(conversation_id: string): Promise<rpcResponseType$1<{
|
|
195
|
-
id: string;
|
|
196
|
-
name: string;
|
|
197
|
-
type: string;
|
|
198
|
-
provider: string;
|
|
199
|
-
}[]>>;
|
|
200
|
-
/**
|
|
201
|
-
* Get current model for a conversation
|
|
202
|
-
*
|
|
203
|
-
* @param {conversation_id: string}
|
|
204
|
-
* @returns {Promise<rpcResponseType<{ emote: string; nlp_model: string; assistant: string }>>}
|
|
205
|
-
*/
|
|
206
|
-
conversation_stats(conversation_id: string): Promise<rpcResponseType$1<{
|
|
207
|
-
emote: string;
|
|
208
|
-
nlp_model: string;
|
|
209
|
-
assistant: string;
|
|
210
|
-
}>>;
|
|
211
|
-
/**
|
|
212
|
-
* Changes the model for a conversation, use with caution, may discontinue chat if model is not compatible
|
|
213
|
-
*
|
|
214
|
-
* @param {conversation_id: string, model_id: string, type: string}
|
|
215
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
216
|
-
*/
|
|
217
|
-
change_to_model(conversation_id: string, model_id: string, type: string): Promise<rpcResponseType$1<any>>;
|
|
218
|
-
/**
|
|
219
|
-
* Trigger the ai to act based on a trigger message
|
|
220
|
-
*
|
|
221
|
-
* @param {conversation_id: string, message: string, eta_seconds: number}
|
|
222
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
223
|
-
*/
|
|
224
|
-
trigger(conversation_id: string, message: string, eta_seconds: number): Promise<rpcResponseType$1<any>>;
|
|
225
|
-
/**
|
|
226
|
-
* This function is used to invoke the llm with a description and instruction
|
|
227
|
-
*
|
|
228
|
-
* @param {conversation_id: string, input: Partial<{ description: string, instruction: string, construct_id: string }> }
|
|
229
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
230
|
-
*/
|
|
231
|
-
invoke_construct(conversation_id: string, input: Partial<{
|
|
232
|
-
description: string;
|
|
233
|
-
instruction: string;
|
|
234
|
-
construct_id: string;
|
|
235
|
-
}>): Promise<rpcResponseType$1<any>>;
|
|
236
|
-
/**
|
|
237
|
-
* specifies a selected data on the client for the ai to work with
|
|
238
|
-
*
|
|
239
|
-
* @param {conversation_id: string, data: string}
|
|
240
|
-
* @returns {Promise<rpcResponseType<any>>}
|
|
241
|
-
*/
|
|
242
|
-
select_context(conversation_id: string, data: string): Promise<rpcResponseType$1<any>>;
|
|
243
|
-
};
|
|
10
|
+
export interface ModuleFunctionConfig {
|
|
11
|
+
/** Function name */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Documentation for the function */
|
|
14
|
+
doc?: string;
|
|
15
|
+
/** Whether the function requires authentication */
|
|
16
|
+
auth?: boolean;
|
|
17
|
+
/** Action message to display while function executes */
|
|
18
|
+
action?: string;
|
|
19
|
+
/** Whether to validate input against the schema */
|
|
20
|
+
validate?: boolean;
|
|
21
|
+
/** Zod schema for input validation */
|
|
22
|
+
input_schema?: ZodSchema<any>;
|
|
23
|
+
/** Zod schema for output validation */
|
|
24
|
+
output_schema?: ZodSchema<any>;
|
|
25
|
+
/** The function implementation */
|
|
26
|
+
func: (...args: any[]) => Promise<any>;
|
|
244
27
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
run(conversation_id: string, instruction: string): Promise<any>;
|
|
28
|
+
export interface TTCModule {
|
|
29
|
+
/** Module name */
|
|
30
|
+
name: string;
|
|
31
|
+
/** Add a function to this module */
|
|
32
|
+
add_function(config: ModuleFunctionConfig): void;
|
|
251
33
|
}
|
|
252
|
-
|
|
34
|
+
export interface DescribeConfig {
|
|
35
|
+
/** Documentation describing what the function does */
|
|
36
|
+
doc?: string;
|
|
37
|
+
/** Action message shown in UI while function executes */
|
|
38
|
+
action?: string;
|
|
39
|
+
/** Whether the function requires authentication */
|
|
40
|
+
auth?: boolean;
|
|
41
|
+
/** Zod schema for input validation */
|
|
42
|
+
inputSchema?: ZodSchema<any>;
|
|
43
|
+
/** Zod schema for output validation */
|
|
44
|
+
outputSchema?: ZodSchema<any>;
|
|
45
|
+
/** Whether to validate input against the schema */
|
|
46
|
+
validate?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export type DescribeDecorator = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
49
|
+
export interface ChatMessage {
|
|
50
|
+
role: "user" | "assistant";
|
|
51
|
+
content: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ModelInfo {
|
|
54
|
+
id: string;
|
|
253
55
|
name: string;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
56
|
+
type: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ConversationStats {
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
export interface Construct {
|
|
63
|
+
/** Send a message to the construct */
|
|
64
|
+
send(message: string): Promise<void>;
|
|
65
|
+
/** Terminate the construct */
|
|
66
|
+
terminate(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export interface Assistant {
|
|
69
|
+
/**
|
|
70
|
+
* Subscribe to assistant events
|
|
71
|
+
* @param event - The event type to subscribe to
|
|
72
|
+
* @param cb - Callback function when event is triggered
|
|
73
|
+
*/
|
|
74
|
+
subscribe(event: ttc_event, cb: (payload: EventPayload) => void): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Create an LLM construct to handle special tasks
|
|
77
|
+
* @param description - Description of the construct's purpose
|
|
78
|
+
*/
|
|
79
|
+
construct(description: string): Promise<Construct>;
|
|
80
|
+
/**
|
|
81
|
+
* Approve or deny a function call request on permission event
|
|
82
|
+
* @param id - The permission request ID
|
|
83
|
+
* @param approval - Whether to approve or deny
|
|
84
|
+
*/
|
|
85
|
+
approveFunction(id: string, approval: boolean): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Send a message to the assistant
|
|
88
|
+
* @param text - The message text
|
|
89
|
+
*/
|
|
90
|
+
message(text: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get chat history
|
|
93
|
+
* @param limit - Number of messages to retrieve
|
|
94
|
+
* @param page - Page number for pagination
|
|
95
|
+
*/
|
|
96
|
+
history(limit: number, page: number): Promise<ChatMessage[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Clear chat messages (soft reset)
|
|
99
|
+
*/
|
|
100
|
+
clearMessages(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Wipe all assistant memory and chat messages (hard reset)
|
|
103
|
+
*/
|
|
104
|
+
reset(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Trigger the assistant with a specific message
|
|
107
|
+
* @param trigger_message - The trigger message
|
|
108
|
+
*/
|
|
109
|
+
trigger(trigger_message: string): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Get assistant statistics and information
|
|
112
|
+
*/
|
|
113
|
+
stats(): Promise<ConversationStats>;
|
|
114
|
+
/**
|
|
115
|
+
* Select an application context for the assistant to use
|
|
116
|
+
* @param context_data - The context data string
|
|
117
|
+
*/
|
|
118
|
+
selectContext(context_data: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Get list of models available to the assistant
|
|
121
|
+
*/
|
|
122
|
+
getModels(): Promise<ModelInfo[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Select a model for the assistant to use
|
|
125
|
+
* @param model_id - The model ID
|
|
126
|
+
* @param type - The model type (llm, stt, or tts)
|
|
127
|
+
*/
|
|
128
|
+
selectModel(model_id: string, type: "llm" | "stt" | "tts"): Promise<void>;
|
|
265
129
|
}
|
|
266
|
-
export
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
static invoke(method: string, args: any[], requestConfig: {
|
|
286
|
-
socket?: Socket;
|
|
287
|
-
_scid: string;
|
|
288
|
-
converstation_id: string;
|
|
289
|
-
}): Promise<rpcResponseType>;
|
|
290
|
-
static init(config: {
|
|
291
|
-
app_id: string;
|
|
292
|
-
publicKey?: string;
|
|
293
|
-
modules: any[];
|
|
294
|
-
socketCb?: (socket: Socket) => Promise<any>;
|
|
295
|
-
}): typeof ttc;
|
|
296
|
-
static generateRPCMethodsList(): Promise<RPCMethodInfo[]>;
|
|
297
|
-
static createConstruct(description: string): Promise<TTCContruct>;
|
|
298
|
-
static approveFunction(id: string, approval: boolean): Promise<void>;
|
|
299
|
-
static askPermission(id: string, func: f_call, cb: (permitted: boolean) => void): Promise<void>;
|
|
300
|
-
static subscribe(event: ttc_event, cb: (payload: {
|
|
301
|
-
id: string;
|
|
302
|
-
payload: any;
|
|
303
|
-
}) => void): Promise<void>;
|
|
304
|
-
static emit(event: ttc_event, data: {
|
|
305
|
-
id: string;
|
|
306
|
-
payload: any;
|
|
307
|
-
}): Promise<void>;
|
|
308
|
-
static module(name: string): TTCModule;
|
|
130
|
+
export interface TTC {
|
|
131
|
+
/**
|
|
132
|
+
* Initialize the assistant with a chat token and modules
|
|
133
|
+
* @param chatToken - The authentication token for the chat session
|
|
134
|
+
* @param modules - Array of module classes to register
|
|
135
|
+
* @returns The Assistant instance for interacting with the AI
|
|
136
|
+
*/
|
|
137
|
+
assistant(chatToken: string, modules: any[]): Assistant;
|
|
138
|
+
/**
|
|
139
|
+
* Decorator to describe a function that the AI can call
|
|
140
|
+
* @param config - Configuration for the function description
|
|
141
|
+
*/
|
|
142
|
+
describe(config?: DescribeConfig): DescribeDecorator;
|
|
143
|
+
/**
|
|
144
|
+
* Create a new module for organizing functions
|
|
145
|
+
* @param name - The name of the module
|
|
146
|
+
* @returns A TTCModule instance to add functions to
|
|
147
|
+
*/
|
|
148
|
+
module(name: string): TTCModule;
|
|
309
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The main TTC SDK instance
|
|
152
|
+
*/
|
|
153
|
+
export declare const ttc: TTC;
|
|
310
154
|
|
|
311
155
|
export {};
|
package/dist/internal.js
CHANGED
|
@@ -11,60 +11,56 @@ class TTCInternal {
|
|
|
11
11
|
this.getFunctionDetails = (functionName) => {
|
|
12
12
|
return this.ai?.functions[functionName];
|
|
13
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
|
-
console.error('Screenshot failed:', error);
|
|
65
|
-
throw new Error(`Screenshot failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
14
|
+
// takeScreenshot = async (conversation_id: string, x: number = 0, y: number = 0, width?: number, height?: number): Promise<string> => {
|
|
15
|
+
// try {
|
|
16
|
+
// // Request screen capture permission
|
|
17
|
+
// const stream = await navigator.mediaDevices.getDisplayMedia({
|
|
18
|
+
// video: true
|
|
19
|
+
// });
|
|
20
|
+
// const video = document.createElement('video');
|
|
21
|
+
// video.srcObject = stream;
|
|
22
|
+
// await new Promise(resolve => video.onloadedmetadata = resolve);
|
|
23
|
+
// video.play();
|
|
24
|
+
// // Create canvas to capture the screenshot
|
|
25
|
+
// const canvas = document.createElement('canvas');
|
|
26
|
+
// const ctx = canvas.getContext('2d');
|
|
27
|
+
// if (!ctx) {
|
|
28
|
+
// throw new Error('Could not get canvas context');
|
|
29
|
+
// }
|
|
30
|
+
// // Set canvas size to video dimensions or specified dimensions
|
|
31
|
+
// const videoWidth = video.videoWidth;
|
|
32
|
+
// const videoHeight = video.videoHeight;
|
|
33
|
+
// canvas.width = width || videoWidth;
|
|
34
|
+
// canvas.height = height || videoHeight;
|
|
35
|
+
// // Draw the video frame to canvas
|
|
36
|
+
// ctx.drawImage(video, x, y, width || videoWidth, height || videoHeight, 0, 0, width || videoWidth, height || videoHeight);
|
|
37
|
+
// // Stop the stream
|
|
38
|
+
// stream.getTracks().forEach(track => track.stop());
|
|
39
|
+
// // Convert to base64 data URL
|
|
40
|
+
// return new Promise<string>((resolve, reject) => {
|
|
41
|
+
// canvas.toBlob(async (blob) => {
|
|
42
|
+
// if (blob) {
|
|
43
|
+
// try {
|
|
44
|
+
// const response = await ttc.server.Media.uploadImage(ttc.app_id, conversation_id, blob);
|
|
45
|
+
// if (response.status === 'success' && response.data?.url) {
|
|
46
|
+
// console.log('Screenshot taken and uploaded:', response.data.url);
|
|
47
|
+
// resolve(response.data.url);
|
|
48
|
+
// } else {
|
|
49
|
+
// reject(new Error('Upload failed or no URL returned'));
|
|
50
|
+
// }
|
|
51
|
+
// } catch (uploadError) {
|
|
52
|
+
// reject(uploadError);
|
|
53
|
+
// }
|
|
54
|
+
// } else {
|
|
55
|
+
// reject(new Error('Could not convert canvas to blob'));
|
|
56
|
+
// }
|
|
57
|
+
// }, 'image/png');
|
|
58
|
+
// });
|
|
59
|
+
// } catch (error) {
|
|
60
|
+
// console.error('Screenshot failed:', error);
|
|
61
|
+
// throw new Error(`Screenshot failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
62
|
+
// }
|
|
63
|
+
// }
|
|
68
64
|
this.getEnvironment = () => {
|
|
69
65
|
// also get date and time
|
|
70
66
|
const dateString = new Date().toISOString();
|
|
@@ -88,14 +84,14 @@ class TTCInternal {
|
|
|
88
84
|
}
|
|
89
85
|
};
|
|
90
86
|
this.sendMessage = (conversation_id, message) => {
|
|
91
|
-
core_1.ttc.server.ttcCore.chatAI(
|
|
87
|
+
core_1.ttc.server.ttcCore.chatAI(message);
|
|
92
88
|
};
|
|
93
89
|
this.sendFunctionResponse = async (conversation_id, response, image_urls) => {
|
|
94
90
|
if (this.ai.on_call) {
|
|
95
91
|
this.function_response_cache = { response, image_urls };
|
|
96
92
|
}
|
|
97
93
|
else {
|
|
98
|
-
await core_1.ttc.server.ttcCore.functionResponse(
|
|
94
|
+
await core_1.ttc.server.ttcCore.functionResponse(response, image_urls);
|
|
99
95
|
}
|
|
100
96
|
};
|
|
101
97
|
this.speakToUser = async (conversation_id, message) => {
|
|
@@ -116,8 +112,8 @@ class TTCInternal {
|
|
|
116
112
|
return await this.fetchAppFunctions(conversation_id);
|
|
117
113
|
case 'TTCInternal.getFunctionDetails':
|
|
118
114
|
return await this.getFunctionDetails(args.functionName);
|
|
119
|
-
case 'TTCInternal.takeScreenshot':
|
|
120
|
-
|
|
115
|
+
// case 'TTCInternal.takeScreenshot':
|
|
116
|
+
// return await this.takeScreenshot(conversation_id, args.x, args.y, args.width, args.height);
|
|
121
117
|
default:
|
|
122
118
|
throw new Error(`Unknown function: ${functionName}`);
|
|
123
119
|
}
|
|
@@ -126,7 +122,7 @@ class TTCInternal {
|
|
|
126
122
|
}
|
|
127
123
|
async fetchAppFunctions(conversation_id) {
|
|
128
124
|
await this.ai?.fetchFunctions();
|
|
129
|
-
await core_1.ttc.server.ttcCore.setAppFunctions(
|
|
125
|
+
await core_1.ttc.server.ttcCore.setAppFunctions(this.ai?.functions);
|
|
130
126
|
return 'App functions have been added to your system message';
|
|
131
127
|
}
|
|
132
128
|
get_internal_functions() {
|
|
@@ -141,12 +137,12 @@ class TTCInternal {
|
|
|
141
137
|
input_schema: `{}`,
|
|
142
138
|
output_schema: `{ current_url: string, userAgent: string, language: string }`
|
|
143
139
|
},
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
140
|
+
// {
|
|
141
|
+
// name: 'TTCInternal.takeScreenshot',
|
|
142
|
+
// description: 'Take a screenshot of a portion of the screen. Parameters: x, y (coordinates), width, height (optional - defaults to full screen)',
|
|
143
|
+
// input_schema: `{ x: number, y: number, width: number?, height: number? }`,
|
|
144
|
+
// output_schema: 'string'
|
|
145
|
+
// }
|
|
150
146
|
];
|
|
151
147
|
}
|
|
152
148
|
}
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAM7B,MAAa,WAAW;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