Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.8",
"version": "1.1.9",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down
32 changes: 7 additions & 25 deletions src/services/agent-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

firstConnection = false;

analytics.enrich({
chatId: chat?.id,
streamId: streamingManager?.streamId,
mode: items.chatMode,
});

changeMode(chat?.chat_mode ?? options.mode ?? ChatMode.Functional);
}

Expand Down Expand Up @@ -180,12 +186,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-chat', {
event: 'connect',
chatId: items.chat?.id,
agentId: agentEntity.id,
mode: items.chatMode,
access: agentEntity.access,
name: agentEntity.preview_name,
...(agentEntity.access === 'public' ? { from: 'agent-template' } : {}),
});
},
async reconnect() {
Expand All @@ -194,25 +195,15 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-chat', {
event: 'reconnect',
chatId: items.chat?.id,
agentId: agentEntity.id,
mode: items.chatMode,
access: agentEntity.access,
name: agentEntity.preview_name,
...(agentEntity.access === 'public' ? { from: 'agent-template' } : {}),
});
},
async disconnect() {
await disconnect();

analytics.track('agent-chat', {
event: 'disconnect',
chatId: items.chat?.id,
agentId: agentEntity.id,
mode: items.chatMode,
access: agentEntity.access,
name: agentEntity.preview_name,
...(agentEntity.access === 'public' ? { from: 'agent-template' } : {}),
});
},
async chat(userMessage: string) {
Expand Down Expand Up @@ -321,7 +312,6 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-message-send', {
event: 'success',
mode: items.chatMode,
messages: items.messages.length + 1,
});

Expand All @@ -330,7 +320,6 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-message-received', {
latency: latencyTimestampTracker.get(true),
mode: items.chatMode,
messages: items.messages.length,
});
}
Expand All @@ -343,7 +332,6 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-message-send', {
event: 'error',
mode: items.chatMode,
messages: items.messages.length,
});

Expand All @@ -365,7 +353,6 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
event: rateId ? 'update' : 'create',
thumb: score === 1 ? 'up' : 'down',
knowledge_id: agentEntity.knowledge?.id ?? '',
mode: items.chatMode,
matches,
score,
});
Expand All @@ -391,7 +378,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
throw new Error('Chat is not initialized');
}

analytics.track('agent-rate-delete', { type: 'text', chat_id: items.chat?.id, id, mode: items.chatMode });
analytics.track('agent-rate-delete', { type: 'text' });

return agentsApi.deleteRating(agentEntity.id, items.chat.id, id);
},
Expand Down Expand Up @@ -466,13 +453,8 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt

analytics.track('agent-video-interrupt', {
type: type || 'click',
stream_id: items.streamingManager?.streamId,
agent_id: agentEntity.id,
owner_id: agentEntity.owner_id,
video_duration_to_interrupt: interruptTimestampTracker.get(true),
message_duration_to_interrupt: latencyTimestampTracker.get(true),
chat_id: items.chat?.id,
mode: items.chatMode,
});

lastMessage.interrupted = true;
Expand Down
4 changes: 0 additions & 4 deletions src/services/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ export async function createChat(
analytics.track('agent-chat', {
event: 'created',
chatId: chat.id,
agentId: agent.id,
mode: chatMode,
access: agent.access,
name: agent.preview_name,
...(agent.access === 'public' ? { from: 'agent-template' } : {}),
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function getAgentInfo(agent: Agent) {
starterQuestionsCount: agent.knowledge?.starter_message?.length,
topicsToAvoid: promptCustomization?.topics_to_avoid,
maxResponseLength: promptCustomization?.max_response_length,
agentId: agent.id,
access: agent.access,
name: agent.preview_name,
...(agent.access === 'public' ? { from: 'agent-template' } : {}),
};
}
export const sumFunc = (numbers: number[]) => numbers.reduce((total, aNumber) => total + aNumber, 0);
Expand Down