Skip to content

Commit aa6cee2

Browse files
committed
feat: adds support for IUM
1 parent 0a5288d commit aa6cee2

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/packages/AgentLiveClient.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ export class AgentLiveClient extends AbstractLiveClient {
140140
this.send(JSON.stringify({ type: "InjectAgentMessage", content }));
141141
}
142142

143+
/**
144+
* Send a text-based message to the agent as if it came from the user.
145+
* This allows you to inject user messages into the conversation for the agent to respond to.
146+
* @example "Hello! Can you hear me?"
147+
* @example "What's the weather like today?"
148+
* @param content - The specific phrase or statement the agent should respond to.
149+
*/
150+
public injectUserMessage(content: string): void {
151+
this.send(JSON.stringify({ type: "InjectUserMessage", content }));
152+
}
153+
143154
/**
144155
* Respond to a function call request.
145156
* @param response - The response to the function call request.

tests/unit/live-client-message-handling.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,33 @@ describe("Unit Tests - Live Client Message Handling", () => {
536536

537537
expect(mockConnection.send).toHaveBeenCalledWith(JSON.stringify({ type: "KeepAlive" }));
538538
});
539+
540+
it("should send injectUserMessage correctly", () => {
541+
const content = "Hello! Can you hear me?";
542+
client.injectUserMessage(content);
543+
544+
expect(mockConnection.send).toHaveBeenCalledWith(
545+
JSON.stringify({ type: "InjectUserMessage", content })
546+
);
547+
});
548+
549+
it("should send injectUserMessage with different content types", () => {
550+
const testCases = [
551+
"What's the weather like today?",
552+
"Simple greeting",
553+
"Multi-line\nmessage content",
554+
"", // Edge case: empty string
555+
];
556+
557+
testCases.forEach((content) => {
558+
jest.clearAllMocks(); // Reset mock between test cases
559+
560+
client.injectUserMessage(content);
561+
562+
expect(mockConnection.send).toHaveBeenCalledWith(
563+
JSON.stringify({ type: "InjectUserMessage", content })
564+
);
565+
});
566+
});
539567
});
540568
});

0 commit comments

Comments
 (0)