@mcpc-tech/unplugin-dev-inspector-mcp 0.0.24 → 0.0.27

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.
@@ -87226,7 +87226,7 @@ function setupInspectorMiddleware(middlewares, config) {
87226
87226
  }
87227
87227
 
87228
87228
  //#endregion
87229
- //#region ../../node_modules/.pnpm/@mcpc-tech+acp-ai-provider@0.1.31/node_modules/@mcpc-tech/acp-ai-provider/index.mjs
87229
+ //#region ../../node_modules/.pnpm/@mcpc-tech+acp-ai-provider@0.1.33/node_modules/@mcpc-tech/acp-ai-provider/index.mjs
87230
87230
  (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
87231
87231
  function formatToolError(toolResult) {
87232
87232
  if (!toolResult || toolResult.length === 0) return "Unknown tool error";
@@ -87236,9 +87236,6 @@ function formatToolError(toolResult) {
87236
87236
  }
87237
87237
  return parts.join("\n");
87238
87238
  }
87239
- function extractBase64Data(data$1) {
87240
- return data$1.includes(",") ? data$1.split(",")[1] : data$1;
87241
- }
87242
87239
  function createResponse(id, result) {
87243
87240
  return {
87244
87241
  jsonrpc: "2.0",
@@ -87516,6 +87513,65 @@ function getExecuteByName(name) {
87516
87513
  function hasRegisteredExecute(name) {
87517
87514
  return executeRegistry.has(name);
87518
87515
  }
87516
+ function extractBase64Data(data$1) {
87517
+ return data$1.includes(",") ? data$1.split(",")[1] : data$1;
87518
+ }
87519
+ function convertAiSdkMessagesToAcp(options, isFreshSession) {
87520
+ const messages = !isFreshSession ? options.prompt.filter((m) => m.role === "user").slice(-1) : options.prompt;
87521
+ const contentBlocks = [];
87522
+ for (const msg of messages) {
87523
+ let prefix = "";
87524
+ if (msg.role === "system") prefix = "System: ";
87525
+ else if (msg.role === "assistant") prefix = "Assistant: ";
87526
+ else if (msg.role === "tool") prefix = "Result: ";
87527
+ if (Array.isArray(msg.content)) {
87528
+ let isFirst = true;
87529
+ for (const part of msg.content) if (part.type === "text") {
87530
+ const text$2 = isFirst ? `${prefix}${part.text} ` : part.text;
87531
+ contentBlocks.push({
87532
+ type: "text",
87533
+ text: text$2
87534
+ });
87535
+ isFirst = false;
87536
+ } else if (part.type === "tool-result") {
87537
+ const resultText = JSON.stringify(part.result);
87538
+ const text$2 = isFirst ? `${prefix}${resultText} ` : resultText;
87539
+ contentBlocks.push({
87540
+ type: "text",
87541
+ text: text$2
87542
+ });
87543
+ isFirst = false;
87544
+ } else if (part.type === "file" && typeof part.data === "string") {
87545
+ const type = part.mediaType.startsWith("image/") ? "image" : part.mediaType.startsWith("audio/") ? "audio" : null;
87546
+ if (type) contentBlocks.push({
87547
+ type,
87548
+ mimeType: part.mediaType,
87549
+ data: extractBase64Data(part.data)
87550
+ });
87551
+ }
87552
+ } else if (typeof msg.content === "string") contentBlocks.push({
87553
+ type: "text",
87554
+ text: `${prefix}${msg.content} `
87555
+ });
87556
+ }
87557
+ return contentBlocks;
87558
+ }
87559
+ function extractACPTools(tools) {
87560
+ const acpTools2 = [];
87561
+ if (!tools) return acpTools2;
87562
+ for (const t$5 of tools) if (t$5.type === "function") {
87563
+ const toolInputSchema = t$5.inputSchema;
87564
+ if (hasRegisteredExecute(t$5.name) && toolInputSchema) {
87565
+ const execute = getExecuteByName(t$5.name);
87566
+ if (execute) acpTools2.push({
87567
+ ...t$5,
87568
+ name: t$5.name,
87569
+ execute
87570
+ });
87571
+ }
87572
+ }
87573
+ return acpTools2;
87574
+ }
87519
87575
  var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2 = "acp.acp_provider_agent_dynamic_tool";
87520
87576
  var providerAgentDynamicToolSchema = zod.default.object({
87521
87577
  toolCallId: zod.default.string().describe("The unique ID of the tool call."),
@@ -87565,6 +87621,7 @@ var ACPLanguageModel = class {
87565
87621
  client = null;
87566
87622
  currentModelId = null;
87567
87623
  currentModeId = null;
87624
+ isFreshSession = true;
87568
87625
  textBlockIndex = 0;
87569
87626
  thinkBlockIndex = 0;
87570
87627
  currentTextId = null;
@@ -87588,36 +87645,27 @@ var ACPLanguageModel = class {
87588
87645
  }
87589
87646
  /**
87590
87647
  * Parses a 'tool_call' notification update into a structured object.
87648
+ * Note: We only use rawInput for tool input (content is for UI display).
87591
87649
  */
87592
87650
  parseToolCall(update$1) {
87593
87651
  if (update$1.sessionUpdate !== "tool_call") throw new Error("Invalid update type for parseToolCall");
87594
- const toolCallId = update$1.toolCallId;
87595
- const toolName = update$1.title || update$1.toolCallId;
87596
- let toolInput = {};
87597
- if (update$1.content && update$1.content.length > 0) toolInput = update$1.content;
87598
- else if (update$1.rawInput) toolInput = update$1.rawInput;
87599
87652
  return {
87600
- toolCallId,
87601
- toolName,
87602
- toolInput
87653
+ toolCallId: update$1.toolCallId,
87654
+ toolName: update$1.title || update$1.toolCallId,
87655
+ toolInput: update$1.rawInput ?? {}
87603
87656
  };
87604
87657
  }
87605
87658
  /**
87606
87659
  * Parses a 'tool_call_update' notification update into a structured object.
87660
+ * Note: We only use rawOutput for tool result (content is for UI display).
87607
87661
  */
87608
87662
  parseToolResult(update$1) {
87609
87663
  if (update$1.sessionUpdate !== "tool_call_update") throw new Error("Invalid update type for parseToolResult");
87610
- const toolCallId = update$1.toolCallId;
87611
- const toolName = update$1.title || update$1.toolCallId;
87612
- let toolResult = null;
87613
- if (update$1.content && update$1.content.length > 0) toolResult = update$1.content;
87614
- else if (update$1.rawOutput) toolResult = update$1.rawOutput;
87615
- const isError = update$1.status === "failed";
87616
87664
  return {
87617
- toolCallId,
87618
- toolName,
87619
- toolResult,
87620
- isError,
87665
+ toolCallId: update$1.toolCallId,
87666
+ toolName: update$1.title || update$1.toolCallId,
87667
+ toolResult: update$1.rawOutput ?? null,
87668
+ isError: update$1.status === "failed",
87621
87669
  status: update$1.status
87622
87670
  };
87623
87671
  }
@@ -87626,36 +87674,6 @@ var ACPLanguageModel = class {
87626
87674
  * When session exists, only extracts the last user message (history is in session).
87627
87675
  * Prefixes text with role since ACP ContentBlock has no role field.
87628
87676
  */
87629
- getPromptContent(options) {
87630
- const messages = this.sessionId ? options.prompt.filter((m) => m.role === "user").slice(-1) : options.prompt;
87631
- const contentBlocks = [];
87632
- for (const msg of messages) {
87633
- if (msg.role === "tool") continue;
87634
- const prefix = msg.role === "system" ? "System: " : msg.role === "assistant" ? "Assistant: " : "";
87635
- if (Array.isArray(msg.content)) {
87636
- let isFirst = true;
87637
- for (const part of msg.content) if (part.type === "text") {
87638
- const text$2 = isFirst ? `${prefix}${part.text} ` : part.text;
87639
- contentBlocks.push({
87640
- type: "text",
87641
- text: text$2
87642
- });
87643
- isFirst = false;
87644
- } else if (part.type === "file" && typeof part.data === "string") {
87645
- const type = part.mediaType.startsWith("image/") ? "image" : part.mediaType.startsWith("audio/") ? "audio" : null;
87646
- if (type) contentBlocks.push({
87647
- type,
87648
- mimeType: part.mediaType,
87649
- data: extractBase64Data(part.data)
87650
- });
87651
- }
87652
- } else if (typeof msg.content === "string") contentBlocks.push({
87653
- type: "text",
87654
- text: `${prefix}${msg.content} `
87655
- });
87656
- }
87657
- return contentBlocks;
87658
- }
87659
87677
  /**
87660
87678
  * Ensures the ACP agent process is running and a session is established.
87661
87679
  * @param acpTools - Tools from streamText options to proxy
@@ -87706,30 +87724,6 @@ var ACPLanguageModel = class {
87706
87724
  } else console.log(`[acp-ai-provider] No authentication methods required by the ACP agent, skipping authentication step.`);
87707
87725
  }
87708
87726
  /**
87709
- * Prepares the list of MCP servers, including the tool proxy if needed.
87710
- */
87711
- async prepareMcpServers(acpTools2) {
87712
- const mcpServers = [...this.config.session?.mcpServers ?? []];
87713
- if (acpTools2 && acpTools2.length > 0) {
87714
- if (!this.toolProxyHost) this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
87715
- for (const t$5 of acpTools2) this.toolProxyHost.registerTool(t$5.name, t$5);
87716
- if (!this.toolProxyHost) {
87717
- this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
87718
- for (const t$5 of acpTools2) this.toolProxyHost.registerTool(t$5.name, t$5);
87719
- const proxyConfig = await this.toolProxyHost.start();
87720
- mcpServers.push(proxyConfig);
87721
- }
87722
- }
87723
- return mcpServers;
87724
- }
87725
- async prepareToolProxy(acpTools2, mcpServers) {
87726
- if (this.toolProxyHost) return;
87727
- this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
87728
- for (const t$5 of acpTools2) this.toolProxyHost.registerTool(t$5.name, t$5);
87729
- const proxyConfig = await this.toolProxyHost.start();
87730
- mcpServers.push(proxyConfig);
87731
- }
87732
- /**
87733
87727
  * Starts a new session or updates the existing one.
87734
87728
  * Assumes connectClient() has been called.
87735
87729
  */
@@ -87754,6 +87748,7 @@ var ACPLanguageModel = class {
87754
87748
  mcpServers
87755
87749
  });
87756
87750
  this.sessionId = this.sessionResponse.sessionId;
87751
+ this.isFreshSession = true;
87757
87752
  await this.applySessionDelay();
87758
87753
  return;
87759
87754
  }
@@ -87766,6 +87761,7 @@ var ACPLanguageModel = class {
87766
87761
  });
87767
87762
  this.sessionId = this.config.existingSessionId;
87768
87763
  this.sessionResponse = { sessionId: this.config.existingSessionId };
87764
+ this.isFreshSession = false;
87769
87765
  } else {
87770
87766
  this.sessionResponse = await this.connection.newSession({
87771
87767
  ...this.config.session,
@@ -87773,6 +87769,7 @@ var ACPLanguageModel = class {
87773
87769
  mcpServers
87774
87770
  });
87775
87771
  this.sessionId = this.sessionResponse.sessionId;
87772
+ this.isFreshSession = true;
87776
87773
  }
87777
87774
  const { models, modes } = this.sessionResponse ?? {};
87778
87775
  if (models?.currentModelId) this.currentModelId = models.currentModelId;
@@ -87958,30 +87955,84 @@ var ACPLanguageModel = class {
87958
87955
  this.currentThinkingId = null;
87959
87956
  }
87960
87957
  const { toolCallId, toolName, toolInput } = this.parseToolCall(update$1);
87961
- controller.enqueue({
87962
- type: "tool-call",
87963
- toolCallId,
87964
- toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
87965
- input: JSON.stringify({
87958
+ const existingToolCall = this.toolCallsMap.get(toolCallId);
87959
+ const hasInput = toolInput && typeof toolInput === "object" && Object.keys(toolInput).length > 0;
87960
+ if (!existingToolCall) {
87961
+ this.toolCallsMap.set(toolCallId, {
87962
+ index: this.toolCallsMap.size,
87963
+ name: toolName,
87964
+ inputStarted: true,
87965
+ inputAvailable: !!hasInput
87966
+ });
87967
+ controller.enqueue({
87968
+ type: "tool-input-start",
87969
+ id: toolCallId,
87970
+ toolName
87971
+ });
87972
+ if (hasInput) controller.enqueue({
87973
+ type: "tool-call",
87966
87974
  toolCallId,
87967
- toolName,
87968
- args: toolInput
87969
- })
87970
- });
87971
- this.toolCallsMap.set(toolCallId, {
87972
- index: this.toolCallsMap.size,
87973
- name: toolName
87974
- });
87975
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
87976
+ input: JSON.stringify({
87977
+ toolCallId,
87978
+ toolName,
87979
+ args: toolInput
87980
+ })
87981
+ });
87982
+ } else if (!existingToolCall.inputAvailable && hasInput) {
87983
+ existingToolCall.inputAvailable = true;
87984
+ controller.enqueue({
87985
+ type: "tool-call",
87986
+ toolCallId,
87987
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
87988
+ input: JSON.stringify({
87989
+ toolCallId,
87990
+ toolName,
87991
+ args: toolInput
87992
+ })
87993
+ });
87994
+ }
87975
87995
  break;
87976
87996
  }
87977
87997
  case "tool_call_update": {
87978
87998
  const { toolCallId, toolName, toolResult, isError, status } = this.parseToolResult(update$1);
87979
- if (!["completed", "failed"].includes(status)) break;
87980
87999
  let toolInfo = this.toolCallsMap.get(toolCallId);
88000
+ if (status === "in_progress") {
88001
+ if (!toolInfo) {
88002
+ toolInfo = {
88003
+ index: this.toolCallsMap.size,
88004
+ name: toolName,
88005
+ inputStarted: true,
88006
+ inputAvailable: true
88007
+ };
88008
+ this.toolCallsMap.set(toolCallId, toolInfo);
88009
+ controller.enqueue({
88010
+ type: "tool-input-start",
88011
+ id: toolCallId,
88012
+ toolName
88013
+ });
88014
+ }
88015
+ if (!toolInfo.inputAvailable) {
88016
+ toolInfo.inputAvailable = true;
88017
+ controller.enqueue({
88018
+ type: "tool-call",
88019
+ toolCallId,
88020
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
88021
+ input: JSON.stringify({
88022
+ toolCallId,
88023
+ toolName,
88024
+ args: {}
88025
+ })
88026
+ });
88027
+ }
88028
+ break;
88029
+ }
88030
+ if (!["completed", "failed"].includes(status)) break;
87981
88031
  if (!toolInfo) {
87982
88032
  toolInfo = {
87983
88033
  index: this.toolCallsMap.size,
87984
- name: toolName
88034
+ name: toolName,
88035
+ inputAvailable: true
87985
88036
  };
87986
88037
  this.toolCallsMap.set(toolCallId, toolInfo);
87987
88038
  controller.enqueue({
@@ -87993,6 +88044,18 @@ var ACPLanguageModel = class {
87993
88044
  toolName
87994
88045
  })
87995
88046
  });
88047
+ } else if (!toolInfo.inputAvailable) {
88048
+ toolInfo.inputAvailable = true;
88049
+ controller.enqueue({
88050
+ type: "tool-call",
88051
+ toolCallId,
88052
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
88053
+ input: JSON.stringify({
88054
+ toolCallId,
88055
+ toolName,
88056
+ args: {}
88057
+ })
88058
+ });
87996
88059
  }
87997
88060
  controller.enqueue({
87998
88061
  type: "tool-result",
@@ -88015,7 +88078,8 @@ var ACPLanguageModel = class {
88015
88078
  async doGenerate(options) {
88016
88079
  try {
88017
88080
  await this.ensureConnected();
88018
- const promptContent = this.getPromptContent(options);
88081
+ const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
88082
+ this.isFreshSession = false;
88019
88083
  let accumulatedText = "";
88020
88084
  const toolCalls = [];
88021
88085
  const toolResults = /* @__PURE__ */ new Map();
@@ -88088,22 +88152,10 @@ var ACPLanguageModel = class {
88088
88152
  * Implements the streaming generation method.
88089
88153
  */
88090
88154
  async doStream(options) {
88091
- const acpTools2 = [];
88092
- if (options.tools) {
88093
- for (const t$5 of options.tools) if (t$5.type === "function") {
88094
- const toolInputSchema = t$5.inputSchema;
88095
- if (hasRegisteredExecute(t$5.name) && toolInputSchema) {
88096
- const execute = getExecuteByName(t$5.name);
88097
- if (execute) acpTools2.push({
88098
- ...t$5,
88099
- name: t$5.name,
88100
- execute
88101
- });
88102
- }
88103
- }
88104
- }
88155
+ const acpTools2 = extractACPTools(options.tools);
88105
88156
  await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
88106
- const promptContent = this.getPromptContent(options);
88157
+ const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
88158
+ this.isFreshSession = false;
88107
88159
  const connection = this.connection;
88108
88160
  const sessionId = this.sessionId;
88109
88161
  const client = this.client;