Class: AIAssistantService
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:63
Extends
BaseService
Constructors
Constructor
new AIAssistantService(
client):AIAssistantService
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:12
Parameters
client
Returns
AIAssistantService
Inherited from
BaseService.constructor
Properties
client
protectedclient:TanqoryClient
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:10
Inherited from
BaseService.client
Methods
buildQuery()
protectedbuildQuery(options?):Record<string,any>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:26
Build query parameters
Parameters
options?
Returns
Record<string, any>
Inherited from
BaseService.buildQuery
cancelAction()
cancelAction(
storeId,actionId):Promise<{success:boolean; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:279
Cancel a pending action
Parameters
storeId
string
actionId
string
Returns
Promise<{ success: boolean; }>
Example
await client.aiAssistant.cancelAction('store-123', 'action-123')
chat()
chat(
storeId,threadId,input):Promise<AsyncGenerator<{data?:any;type:"error"|"message_start"|"content_delta"|"tool_call_start"|"tool_call_result"|"message_complete"; },any,any>>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:109
Send a message and get streaming response Uses Server-Sent Events for real-time streaming
Parameters
storeId
string
threadId
string
input
context?
{ listFilters?: Record<string, any>; pageType?: "list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"; pathname?: string; resourceData?: Record<string, any>; resourceId?: string; resourceType?: "customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"; selectedItems?: string[]; storeId?: string; }
context.listFilters?
Record<string, any>
context.pageType?
"list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"
context.pathname?
string
context.resourceData?
Record<string, any>
context.resourceId?
string
context.resourceType?
"customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"
context.selectedItems?
string[]
context.storeId?
string
message
string
requireConfirmation?
boolean
threadId?
string
Returns
Promise<AsyncGenerator<{ data?: any; type: "error" | "message_start" | "content_delta" | "tool_call_start" | "tool_call_result" | "message_complete"; }, any, any>>
Example
const stream = await client.aiAssistant.chat('store-123', 'thread-123', {
message: 'Create a product named "Test" priced at 100'
})
for await (const event of stream) {
switch (event.type) {
case 'content_delta':
process.stdout.write(event.data.content)
break
case 'tool_call_start':
console.log('Executing:', event.data.toolName)
break
case 'tool_call_result':
console.log('Result:', event.data.result)
break
case 'message_complete':
console.log('Done!')
break
}
}
chatSync()
chatSync(
storeId,threadId,input):Promise<{message: {content:string;createdAt:Date;id:string;role:"user"|"assistant";toolCalls?:object[]; };pendingActions?:object[];requiresConfirmation?:boolean;threadId:string;toolCalls?:object[]; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:138
Send a message and get non-streaming response For clients that don't support SSE
Parameters
storeId
string
threadId
string
input
context?
{ listFilters?: Record<string, any>; pageType?: "list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"; pathname?: string; resourceData?: Record<string, any>; resourceId?: string; resourceType?: "customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"; selectedItems?: string[]; storeId?: string; }
context.listFilters?
Record<string, any>
context.pageType?
"list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"
context.pathname?
string
context.resourceData?
Record<string, any>
context.resourceId?
string
context.resourceType?
"customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"
context.selectedItems?
string[]
context.storeId?
string
message
string
requireConfirmation?
boolean
threadId?
string
Returns
Promise<{ message: { content: string; createdAt: Date; id: string; role: "user" | "assistant"; toolCalls?: object[]; }; pendingActions?: object[]; requiresConfirmation?: boolean; threadId: string; toolCalls?: object[]; }>
Example
const response = await client.aiAssistant.chatSync('store-123', 'thread-123', {
message: 'How many products do I have?'
})
console.log(response.message.content)
confirmAction()
confirmAction(
storeId,actionId):Promise<{result?:any;success:boolean; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:264
Confirm a pending action
Parameters
storeId
string
actionId
string
Returns
Promise<{ result?: any; success: boolean; }>
Example
const result = await client.aiAssistant.confirmAction('store-123', 'action-123')
if (result.success) {
console.log('Action executed:', result.result)
}
createThread()
createThread(
storeId,input?):Promise<{createdAt:Date;id:string;openaiThreadId:string;title?:string;updatedAt:Date; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:75
Create a new conversation thread
Parameters
storeId
string
input?
context?
string
title?
string
Returns
Promise<{ createdAt: Date; id: string; openaiThreadId: string; title?: string; updatedAt: Date; }>
Example
const thread = await client.aiAssistant.createThread('store-123', {
title: 'Product Questions',
context: 'User is on the products page'
})
deleteThread()
deleteThread(
storeId,threadId):Promise<{success:boolean; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:229
Delete a thread
Parameters
storeId
string
threadId
string
Returns
Promise<{ success: boolean; }>
Example
await client.aiAssistant.deleteThread('store-123', 'thread-123')
generateIdempotencyKey()
protectedgenerateIdempotencyKey(prefix):string
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:19
Generate idempotency key
Parameters
prefix
string
Returns
string
Inherited from
BaseService.generateIdempotencyKey
getActionHistory()
getActionHistory(
storeId,options?):Promise<{actions:object[];total:number; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:244
Get action history (audit trail)
Parameters
storeId
string
options?
AiAssistantActionHistoryOptions
Returns
Promise<{ actions: object[]; total: number; }>
Example
const { actions, total } = await client.aiAssistant.getActionHistory('store-123', {
limit: 50,
toolName: 'createProduct'
})
getExportMimeType()
protectedgetExportMimeType(format):string
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:45
Get MIME type for export format
Parameters
format
string
Returns
string
Inherited from
BaseService.getExportMimeType
getMessages()
getMessages(
storeId,threadId,options?):Promise<{hasMore:boolean;messages:object[]; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:209
Get message history for a thread
Parameters
storeId
string
threadId
string
options?
Returns
Promise<{ hasMore: boolean; messages: object[]; }>
Example
const { messages, hasMore } = await client.aiAssistant.getMessages(
'store-123',
'thread-123',
{ limit: 50 }
)
listThreads()
listThreads(
storeId,options?):Promise<{threads:object[];total:number; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:188
List all threads for the current user
Parameters
storeId
string
options?
Returns
Promise<{ threads: object[]; total: number; }>
Example
const { threads, total } = await client.aiAssistant.listThreads('store-123', {
limit: 10,
offset: 0
})
quickChat()
quickChat(
storeId,input):Promise<AsyncGenerator<{data?:any;type:"error"|"message_start"|"content_delta"|"tool_call_start"|"tool_call_result"|"message_complete"; },any,any>>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:161
Quick chat - create thread and send message in one call Useful for one-off questions
Parameters
storeId
string
input
context?
{ listFilters?: Record<string, any>; pageType?: "list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"; pathname?: string; resourceData?: Record<string, any>; resourceId?: string; resourceType?: "customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"; selectedItems?: string[]; storeId?: string; }
context.listFilters?
Record<string, any>
context.pageType?
"list" | "create" | "unknown" | "settings" | "detail" | "edit" | "dashboard"
context.pathname?
string
context.resourceData?
Record<string, any>
context.resourceId?
string
context.resourceType?
"customer" | "product" | "discount" | "order" | "inventory" | "collection" | "unknown" | "transfer" | "gift_card" | "store_settings"
context.selectedItems?
string[]
context.storeId?
string
message
string
requireConfirmation?
boolean
threadId?
string
Returns
Promise<AsyncGenerator<{ data?: any; type: "error" | "message_start" | "content_delta" | "tool_call_start" | "tool_call_result" | "message_complete"; }, any, any>>
Example
const stream = await client.aiAssistant.quickChat('store-123', {
message: 'ยอดขายวันนี้เท่าไหร่'
})
saveGeneratedImage()
saveGeneratedImage(
storeId,input):Promise<{data?: {filename?:string;fileSize?:number;height?:number;mediaId?:string;mimeType?:string;url:string;width?:number; };error?:string;success:boolean; }>
Defined in: tanqory-platform-packages/packages/api/sdk/src/services/ai-assistant.ts:296
Save AI-generated image directly (without pending action) Use this as fallback when confirmAction fails due to service restart
Parameters
storeId
string
input
alt?
string
folder?
string
imageUrl
string
productId?
string
tags?
string[]
Returns
Promise<{ data?: { filename?: string; fileSize?: number; height?: number; mediaId?: string; mimeType?: string; url: string; width?: number; }; error?: string; success: boolean; }>
Example
const result = await client.aiAssistant.saveGeneratedImage('store-123', {
imageUrl: 'https://oaidalleapiprodscus.blob.core.windows.net/...',
folder: 'products',
alt: 'AI generated product image'
})