@fload-ai/mcp 0.11.0 → 0.12.0

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.js CHANGED
@@ -1318,7 +1318,10 @@ var listPendingActionsSchema = z8.object({
1318
1318
  limit: z8.number().int().min(1).max(100).default(50).describe("Maximum number of actions to return")
1319
1319
  });
1320
1320
  var approveActionSchema = z8.object({
1321
- actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)")
1321
+ actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)"),
1322
+ wholeGroup: z8.boolean().optional().describe(
1323
+ "Approve every language of this item's card at once: the items still waiting for approval that share its proposalBatch (one listing change across locales, as the inbox shows it as one card with one Approve). Languages that cannot be approved now are left as they are and listed."
1324
+ )
1322
1325
  });
1323
1326
  var rejectActionSchema = z8.object({
1324
1327
  actionId: z8.string().describe("The inbox item ID to reject (from list_pending_actions)"),
@@ -1423,6 +1426,10 @@ function refusedMessage(result) {
1423
1426
  }
1424
1427
  async function approveAction(input, client) {
1425
1428
  try {
1429
+ if (input.wholeGroup) {
1430
+ const grouped = await approveGroup(client, input.actionId);
1431
+ if (grouped) return grouped;
1432
+ }
1426
1433
  const { command, result } = await commandItem(
1427
1434
  client,
1428
1435
  input.actionId,
@@ -1445,6 +1452,80 @@ async function approveAction(input, client) {
1445
1452
  return toolError(error);
1446
1453
  }
1447
1454
  }
1455
+ async function groupOf(client, item) {
1456
+ if (!item.proposalBatch || item.status !== "needs_approval") return [item];
1457
+ const isSibling = (other) => typeof other === "object" && other !== null && other.status === "needs_approval" && other.proposalBatch === item.proposalBatch && other.assetId === item.assetId && other.id !== item.id;
1458
+ const siblings = [];
1459
+ let cursor;
1460
+ do {
1461
+ const response = await client.get("/api/actions/items", {
1462
+ view: "open",
1463
+ limit: 100,
1464
+ ...item.assetId ? { assetId: item.assetId } : {},
1465
+ ...cursor ? { cursor } : {}
1466
+ });
1467
+ siblings.push(...(response.items ?? []).filter(isSibling));
1468
+ cursor = response.nextCursor;
1469
+ } while (cursor);
1470
+ return [item, ...siblings];
1471
+ }
1472
+ async function approveGroup(client, actionId) {
1473
+ const detail = await client.get(
1474
+ `/api/actions/items/${encodeURIComponent(actionId)}`
1475
+ );
1476
+ if (!detail.item) throw new Error("Action not found");
1477
+ const group = await groupOf(client, detail.item);
1478
+ if (group.length <= 1) return null;
1479
+ const approvable = group.filter(
1480
+ (item) => item.allowedCommands?.includes("approve")
1481
+ );
1482
+ const skipped = group.filter((item) => !approvable.includes(item)).map((item) => item.id);
1483
+ if (approvable.length === 0)
1484
+ return toolText(
1485
+ {
1486
+ success: false,
1487
+ actionId,
1488
+ skipped,
1489
+ message: "Nothing in this card can be approved right now."
1490
+ },
1491
+ true
1492
+ );
1493
+ const answer = await client.postForAnswer(
1494
+ "/api/actions/commands",
1495
+ {
1496
+ command: "approve",
1497
+ idempotencyKey: `mcp:approve-group:${actionId}:${randomUUID()}`,
1498
+ targets: approvable.map((item) => ({
1499
+ itemId: item.id,
1500
+ ...item.currentRevisionId ? { revisionId: item.currentRevisionId } : {}
1501
+ }))
1502
+ }
1503
+ );
1504
+ const results = (answer.body?.results ?? []).map((result) => ({
1505
+ itemId: result.itemId,
1506
+ result: result.result,
1507
+ ...result.error ? {
1508
+ error: publicMcpErrorMessage(
1509
+ result.error,
1510
+ "Fload could not apply this change."
1511
+ )
1512
+ } : {}
1513
+ }));
1514
+ const approved = results.filter(
1515
+ (r) => r.result === "applied" || r.result === "replayed"
1516
+ ).length;
1517
+ return toolText(
1518
+ {
1519
+ success: approved > 0,
1520
+ actionId,
1521
+ approved,
1522
+ results,
1523
+ ...skipped.length ? { skipped } : {},
1524
+ message: approved > 0 ? `Approved ${approved} of ${group.length}. Fload delivers them after a short undo window; the inbox shows where each is.` : "The approval could not be recorded."
1525
+ },
1526
+ approved === 0
1527
+ );
1528
+ }
1448
1529
  async function rejectAction(input, client) {
1449
1530
  try {
1450
1531
  const { command, result } = await commandItem(
@@ -1886,9 +1967,26 @@ async function getConversationMessages(input, client) {
1886
1967
  };
1887
1968
  }
1888
1969
  }
1970
+ var FREE_CONVERSATION_LABEL = "Free: your first conversation";
1971
+ var FREE_CONVERSATION_ENDED_NOTICE = "Your free first conversation has ended; messages now use credits.";
1972
+ function answerCostOf(data) {
1973
+ if (!data || typeof data !== "object") return null;
1974
+ const usage = data;
1975
+ const free = usage.freeConversation;
1976
+ if (free && typeof free.messagesLeft === "number") {
1977
+ return {
1978
+ free: true,
1979
+ label: FREE_CONVERSATION_LABEL,
1980
+ messagesLeft: free.messagesLeft,
1981
+ ...free.ended === true ? { notice: FREE_CONVERSATION_ENDED_NOTICE } : {}
1982
+ };
1983
+ }
1984
+ return typeof usage.credits === "number" ? { free: false, credits: usage.credits } : null;
1985
+ }
1889
1986
  function parseUiMessageStream(raw) {
1890
1987
  let reply = "";
1891
1988
  const toolsUsed = [];
1989
+ let cost = null;
1892
1990
  for (const line of raw.split("\n")) {
1893
1991
  if (!line.startsWith("data:")) continue;
1894
1992
  const payload = line.slice(5).trim();
@@ -1899,11 +1997,13 @@ function parseUiMessageStream(raw) {
1899
1997
  reply += String(event.delta ?? event.textDelta ?? "");
1900
1998
  } else if (typeof event.type === "string" && event.type === "tool-input-start" && typeof event.toolName === "string") {
1901
1999
  toolsUsed.push(event.toolName);
2000
+ } else if (event.type === "data-usage") {
2001
+ cost = answerCostOf(event.data) ?? cost;
1902
2002
  }
1903
2003
  } catch {
1904
2004
  }
1905
2005
  }
1906
- return { reply, toolsUsed };
2006
+ return { reply, toolsUsed, cost };
1907
2007
  }
1908
2008
  async function sendChatMessage(input, client) {
1909
2009
  try {
@@ -1944,7 +2044,7 @@ async function sendChatMessage(input, client) {
1944
2044
  };
1945
2045
  }
1946
2046
  const raw = await client.postStream("/api/chat", body);
1947
- const { reply, toolsUsed } = parseUiMessageStream(raw);
2047
+ const { reply, toolsUsed, cost } = parseUiMessageStream(raw);
1948
2048
  return {
1949
2049
  content: [
1950
2050
  {
@@ -1953,6 +2053,8 @@ async function sendChatMessage(input, client) {
1953
2053
  conversationId,
1954
2054
  reply: reply || "The assistant returned no text response.",
1955
2055
  toolsUsed,
2056
+ // FLO-2669: the credits the answer used, or that it was free.
2057
+ ...cost ? { cost } : {},
1956
2058
  tip: "Pass this conversationId to continue the conversation or to get_conversation_messages for the full transcript."
1957
2059
  })
1958
2060
  }
@@ -2284,7 +2386,7 @@ function registerTools(server, client, options = {}) {
2284
2386
  tool(
2285
2387
  "send_chat_message",
2286
2388
  "Send chat message",
2287
- "Send a message to the Fload AI chat assistant. Starts a new conversation if no conversationId is provided, or continues an existing one. Optionally specify an agentType to route to a specialized agent (review, aso). Adds a message to your chat history \u2014 not publicly visible.",
2389
+ "Send a message to the Fload AI chat assistant. Starts a new conversation if no conversationId is provided, or continues an existing one. Optionally specify an agentType to route to a specialized agent (review, aso). Adds a message to your chat history \u2014 not publicly visible. The result's `cost` says what the answer used: `credits`, or `free: true` with the free answers left when a new organization's free first conversation carried it (and a `notice` on the answer that ended it).",
2288
2390
  sendChatMessageSchema,
2289
2391
  sendChatMessage,
2290
2392
  { readOnlyHint: false, destructiveHint: false, openWorldHint: true }