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
4 changes: 2 additions & 2 deletions .github/workflows/manual-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup Node.js for SDK
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache-dependency-path: agents-sdk/yarn.lock

- name: Install Yarn
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Setup Node.js for agents-ui
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Render .npmrc for agents-ui
working-directory: agents-ui
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-main-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup Node.js for SDK
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache-dependency-path: agents-sdk/yarn.lock

- name: Install Yarn
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Setup Node.js for agents-ui
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Render .npmrc for agents-ui
working-directory: agents-ui
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-prod-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Render .npmrc for agents-ui
working-directory: agents-ui
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
node-version: 22
registry-url: "https://registry.npmjs.org"
cache: "yarn"

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'yarn'
cache-dependency-path: yarn.lock

Expand All @@ -46,7 +46,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'yarn'
cache-dependency-path: yarn.lock

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'yarn'
cache-dependency-path: yarn.lock

Expand All @@ -100,7 +100,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'yarn'
cache-dependency-path: yarn.lock

Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22
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.57",
"version": "1.1.58",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './errors';
export * from './services/agent-manager';
export * from './types';
export { parseMessageParts } from './utils/content-parser';
37 changes: 36 additions & 1 deletion src/services/agent-manager/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('createAgentManager', () => {

it('should handle initial messages correctly', async () => {
const initialMessages = [
{ id: '1', role: 'user' as const, content: 'Hello', created_at: new Date().toISOString() },
{ id: '1', role: 'user' as const, content: 'Hello', parts: [], created_at: new Date().toISOString() },
];
(getInitialMessages as jest.Mock).mockReturnValue(initialMessages);

Expand Down Expand Up @@ -297,6 +297,30 @@ describe('createAgentManager', () => {
});
});

it('should populate parts on user message', async () => {
const mockCallback = mockOptions.callbacks.onNewMessage as jest.Mock;
mockCallback.mockClear();

await manager.chat('Hello, how are you?');

// First call is the user message
const [userMessages] = mockCallback.mock.calls[0];
const userMsg = userMessages[userMessages.length - 1];
expect(userMsg.parts).toEqual([{ type: 'text', text: 'Hello, how are you?' }]);
});

it('should populate parts on assistant response message', async () => {
const mockCallback = mockOptions.callbacks.onNewMessage as jest.Mock;
mockCallback.mockClear();

await manager.chat('Hello, how are you?');

// Second call is the answer
const [answerMessages] = mockCallback.mock.calls[1];
const assistantMsg = answerMessages[answerMessages.length - 1];
expect(assistantMsg.parts).toEqual([{ type: 'text', text: 'Agent response' }]);
});

it('should validate chat request - empty message', async () => {
await expect(manager.chat('')).rejects.toThrow('Message cannot be empty');
});
Expand Down Expand Up @@ -447,6 +471,17 @@ describe('createAgentManager', () => {
expect(lastMessage.created_at).toBeDefined();
});

it('should populate parts on speak message', async () => {
const mockCallback = mockOptions.callbacks.onNewMessage as jest.Mock;
mockCallback.mockClear();

await manager.speak('Hello from speak');

const [messages] = mockCallback.mock.calls[0];
const lastMessage = messages[messages.length - 1];
expect(lastMessage.parts).toEqual([{ type: 'text', text: 'Hello from speak' }]);
});

it('should trigger onNewMessage with script object', async () => {
const script = { type: 'text' as const, input: 'Hello from script', ssml: false };
const mockCallback = mockOptions.callbacks.onNewMessage as jest.Mock;
Expand Down
4 changes: 4 additions & 0 deletions src/services/agent-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ChatCreationFailed, ValidationError } from '@sdk/errors';
import { getRandom } from '@sdk/utils';
import { isStreamsV2Agent } from '@sdk/utils/agent';
import { isChatModeWithoutChat, isTextualChat } from '@sdk/utils/chat';
import { parseMessagePartsMemo } from '@sdk/utils/content-parser';
import { createAgentsApi } from '../../api/agents';
import { getAgentInfo, getAnalyticsInfo } from '../../utils/analytics';
import { defer } from '../../utils/defer';
Expand Down Expand Up @@ -439,6 +440,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
id: getRandom(),
role: 'user',
content: userMessage,
parts: parseMessagePartsMemo(userMessage),
created_at: new Date(latencyTimestampTracker.update()).toISOString(),
});

Expand All @@ -451,6 +453,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
id: getRandom(),
role: 'assistant',
content: response.result || '',
parts: parseMessagePartsMemo(response.result || ''),
created_at: new Date().toISOString(),
context: response.context,
matches: response.matches,
Expand Down Expand Up @@ -568,6 +571,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
id: getRandom(),
role: 'assistant',
content: script.input,
parts: parseMessagePartsMemo(script.input),
created_at: new Date().toISOString(),
});
options.callbacks.onNewMessage?.([...items.messages], 'answer');
Expand Down
Loading
Loading