@absolutejs/voice 0.0.22-beta.521 → 0.0.22-beta.522

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/dist/index.d.ts CHANGED
@@ -71,6 +71,8 @@ export { createVoiceSessionListRoutes, createVoiceSessionReplayHTMLHandler, crea
71
71
  export { createVoiceAgent, createVoiceAgentSquad, createVoiceAgentTool, } from "./agent";
72
72
  export { createPersonaVoiceCaller, createScriptedVoiceCaller, renderVoiceSimulationTranscript, runVoiceConversationSimulation, } from "./conversationSimulator";
73
73
  export type { RunVoiceConversationSimulationInput, VoiceConversationSimulationEndedReason, VoiceConversationSimulationResult, VoicePersonaCallerCompletion, VoiceScriptedCallerStep, VoiceSimulatedSpeaker, VoiceSimulatedTurn, VoiceSimulatorCaller, VoiceSimulatorCallerModel, VoiceSimulatorCallerReply, } from "./conversationSimulator";
74
+ export { createVoiceMCPToolset } from "./mcpToolset";
75
+ export type { CreateVoiceMCPToolsetOptions, MCPClientLike, MCPToolCallResult, MCPToolContentBlock, MCPToolDefinition, VoiceMCPToolResult, } from "./mcpToolset";
74
76
  export { createAIVoiceModel } from "./aiVoiceModel";
75
77
  export type { CreateAIVoiceModelOptions } from "./aiVoiceModel";
76
78
  export { createVoiceAIJudgeCompletion, createVoiceLLMJudge, } from "./llmJudge";
package/dist/index.js CHANGED
@@ -35415,6 +35415,52 @@ Respond with only your spoken line. When your goal is met or you want to hang up
35415
35415
  persona: options.persona
35416
35416
  };
35417
35417
  };
35418
+ // src/mcpToolset.ts
35419
+ var flattenContent = (result) => {
35420
+ const blocks = result.content ?? [];
35421
+ const text = blocks.filter((block) => block.type === "text" && typeof block.text === "string").map((block) => block.text).join(`
35422
+ `).trim();
35423
+ if (text.length > 0)
35424
+ return text;
35425
+ if (result.structuredContent !== undefined) {
35426
+ return JSON.stringify(result.structuredContent);
35427
+ }
35428
+ return "";
35429
+ };
35430
+ var createVoiceMCPToolset = async (options) => {
35431
+ const prefix = options.namePrefix ?? "";
35432
+ const allowed = options.allowedTools ? new Set(options.allowedTools) : undefined;
35433
+ const blocked = options.blockedTools ? new Set(options.blockedTools) : undefined;
35434
+ const listed = await Promise.resolve(options.client.listTools());
35435
+ const tools = [];
35436
+ for (const definition of listed.tools) {
35437
+ if (allowed && !allowed.has(definition.name))
35438
+ continue;
35439
+ if (blocked && blocked.has(definition.name))
35440
+ continue;
35441
+ const exposedName = `${prefix}${definition.name}`;
35442
+ tools.push(createVoiceAgentTool({
35443
+ ...definition.description !== undefined ? { description: definition.description } : {},
35444
+ execute: async ({ args }) => {
35445
+ const raw = await Promise.resolve(options.client.callTool({
35446
+ arguments: args,
35447
+ name: definition.name
35448
+ }));
35449
+ const result = {
35450
+ isError: raw.isError === true,
35451
+ raw,
35452
+ text: flattenContent(raw),
35453
+ ...raw.structuredContent !== undefined ? { structuredContent: raw.structuredContent } : {}
35454
+ };
35455
+ return result;
35456
+ },
35457
+ name: exposedName,
35458
+ ...definition.inputSchema !== undefined ? { parameters: definition.inputSchema } : {},
35459
+ resultToMessage: options.resultToMessage ?? ((result) => result.isError ? `Tool error: ${result.text || "unknown error"}` : result.text || "(no output)")
35460
+ }));
35461
+ }
35462
+ return tools;
35463
+ };
35418
35464
  // src/aiVoiceModel.ts
35419
35465
  var toProviderMessages = (messages) => {
35420
35466
  const out = [];
@@ -52389,6 +52435,7 @@ export {
52389
52435
  createVoiceMemoryAuditEventStore,
52390
52436
  createVoiceMemoryAssistantMemoryStore,
52391
52437
  createVoiceMediaPipelineRoutes,
52438
+ createVoiceMCPToolset,
52392
52439
  createVoiceLiveOpsRoutes,
52393
52440
  createVoiceLiveOpsController,
52394
52441
  createVoiceLiveMonitorRoutes,
@@ -0,0 +1,58 @@
1
+ import { type VoiceAgentTool } from "./agent";
2
+ import type { VoiceSessionRecord } from "./types";
3
+ /**
4
+ * Minimal structural shapes from the Model Context Protocol. Any MCP client
5
+ * (`@modelcontextprotocol/sdk` over stdio / SSE / streamable-HTTP, or a custom
6
+ * transport) that exposes `listTools` + `callTool` satisfies this — voice does
7
+ * not bundle an MCP SDK.
8
+ */
9
+ export type MCPToolDefinition = {
10
+ name: string;
11
+ description?: string;
12
+ inputSchema?: Record<string, unknown>;
13
+ };
14
+ export type MCPToolContentBlock = {
15
+ type: "text";
16
+ text: string;
17
+ } | {
18
+ type: string;
19
+ [key: string]: unknown;
20
+ };
21
+ export type MCPToolCallResult = {
22
+ content?: MCPToolContentBlock[];
23
+ structuredContent?: unknown;
24
+ isError?: boolean;
25
+ };
26
+ export type MCPClientLike = {
27
+ listTools: () => Promise<{
28
+ tools: MCPToolDefinition[];
29
+ }> | {
30
+ tools: MCPToolDefinition[];
31
+ };
32
+ callTool: (input: {
33
+ name: string;
34
+ arguments?: Record<string, unknown>;
35
+ }) => Promise<MCPToolCallResult> | MCPToolCallResult;
36
+ };
37
+ export type VoiceMCPToolResult = {
38
+ text: string;
39
+ structuredContent?: unknown;
40
+ isError: boolean;
41
+ raw: MCPToolCallResult;
42
+ };
43
+ export type CreateVoiceMCPToolsetOptions = {
44
+ client: MCPClientLike;
45
+ /** Prefix applied to every exposed tool name (e.g. "mcp_"). */
46
+ namePrefix?: string;
47
+ /** Only expose tools whose (unprefixed) name is in this allow-list. */
48
+ allowedTools?: ReadonlyArray<string>;
49
+ /** Drop tools whose (unprefixed) name is in this block-list. */
50
+ blockedTools?: ReadonlyArray<string>;
51
+ /** Override how an MCP result is flattened to the assistant-visible string. */
52
+ resultToMessage?: (result: VoiceMCPToolResult) => string;
53
+ };
54
+ /**
55
+ * Bridges the tools exposed by an MCP server into `VoiceAgentTool`s. Call once
56
+ * at setup; the returned array spreads straight into `createVoiceAgent({ tools })`.
57
+ */
58
+ export declare const createVoiceMCPToolset: <TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord>(options: CreateVoiceMCPToolsetOptions) => Promise<VoiceAgentTool<TContext, TSession, Record<string, unknown>, VoiceMCPToolResult>[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.521",
3
+ "version": "0.0.22-beta.522",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",