@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.
@@ -10,6 +10,7 @@ export declare const listPendingActionsSchema: z.ZodObject<{
10
10
  }, z.core.$strip>;
11
11
  export declare const approveActionSchema: z.ZodObject<{
12
12
  actionId: z.ZodString;
13
+ wholeGroup: z.ZodOptional<z.ZodBoolean>;
13
14
  }, z.core.$strip>;
14
15
  export declare const rejectActionSchema: z.ZodObject<{
15
16
  actionId: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/tools/actions.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAgDvD,eAAO,MAAM,wBAAwB;;;;;;;iBAenC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;iBAI9B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;iBAa7B,CAAC;AAGH,eAAO,MAAM,oBAAoB;;iBAM/B,CAAC;AAGH,eAAO,MAAM,4BAA4B;;;iBAcvC,CAAC;AAiCH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,EAC/C,MAAM,EAAE,cAAc;;;;;;GAgBvB;AAkFD,wBAAsB,aAAa,CACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,EAC1C,MAAM,EAAE,cAAc;;;;;;GAyBvB;AAGD,wBAAsB,YAAY,CAChC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,EACzC,MAAM,EAAE,cAAc;;;;;;GA8BvB;AAOD,wBAAsB,cAAc,CAClC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,EAC3C,MAAM,EAAE,cAAc;;;;;;GAqCvB;AAyED,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,EACnD,MAAM,EAAE,cAAc;;;;;;GAwDvB"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/tools/actions.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAmDvD,eAAO,MAAM,wBAAwB;;;;;;;iBAenC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;iBAU9B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;iBAa7B,CAAC;AAGH,eAAO,MAAM,oBAAoB;;iBAM/B,CAAC;AAGH,eAAO,MAAM,4BAA4B;;;iBAcvC,CAAC;AAiCH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,EAC/C,MAAM,EAAE,cAAc;;;;;;GAgBvB;AAkFD,wBAAsB,aAAa,CACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,EAC1C,MAAM,EAAE,cAAc;;;;;;GA8BvB;AA8GD,wBAAsB,YAAY,CAChC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,EACzC,MAAM,EAAE,cAAc;;;;;;GA8BvB;AAOD,wBAAsB,cAAc,CAClC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,EAC3C,MAAM,EAAE,cAAc;;;;;;GAqCvB;AAyED,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,EACnD,MAAM,EAAE,cAAc;;;;;;GAwDvB"}
@@ -37,9 +37,21 @@ export declare function getConversationMessages(input: z.input<typeof getConvers
37
37
  }[];
38
38
  isError: boolean;
39
39
  }>;
40
+ export declare const FREE_CONVERSATION_LABEL = "Free: your first conversation";
41
+ export declare const FREE_CONVERSATION_ENDED_NOTICE = "Your free first conversation has ended; messages now use credits.";
42
+ export type ChatAnswerCost = {
43
+ free: false;
44
+ credits: number;
45
+ } | {
46
+ free: true;
47
+ label: string;
48
+ messagesLeft: number;
49
+ notice?: string;
50
+ };
40
51
  export declare function parseUiMessageStream(raw: string): {
41
52
  reply: string;
42
53
  toolsUsed: string[];
54
+ cost: ChatAnswerCost | null;
43
55
  };
44
56
  export declare function sendChatMessage(input: z.input<typeof sendChatMessageSchema>, client: FloadApiClient): Promise<{
45
57
  isError?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/tools/chat.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOvD,eAAO,MAAM,uBAAuB;;iBAQlC,CAAC;AAEH,eAAO,MAAM,6BAA6B;;iBAKxC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;iBAehC,CAAC;AASH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,EAC9C,MAAM,EAAE,cAAc;;;;;;;;;;;;GAgCvB;AAKD,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,EACpD,MAAM,EAAE,cAAc;;;;;;;;;;;;GA+BvB;AAMD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAuBA;AAOD,wBAAsB,eAAe,CACnC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,EAC5C,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 -1218,7 +1218,10 @@ var listPendingActionsSchema = z8.object({
1218
1218
  limit: z8.number().int().min(1).max(100).default(50).describe("Maximum number of actions to return")
1219
1219
  });
1220
1220
  var approveActionSchema = z8.object({
1221
- actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)")
1221
+ actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)"),
1222
+ wholeGroup: z8.boolean().optional().describe(
1223
+ "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."
1224
+ )
1222
1225
  });
1223
1226
  var rejectActionSchema = z8.object({
1224
1227
  actionId: z8.string().describe("The inbox item ID to reject (from list_pending_actions)"),
@@ -1323,6 +1326,10 @@ function refusedMessage(result) {
1323
1326
  }
1324
1327
  async function approveAction(input, client) {
1325
1328
  try {
1329
+ if (input.wholeGroup) {
1330
+ const grouped = await approveGroup(client, input.actionId);
1331
+ if (grouped) return grouped;
1332
+ }
1326
1333
  const { command, result } = await commandItem(
1327
1334
  client,
1328
1335
  input.actionId,
@@ -1345,6 +1352,80 @@ async function approveAction(input, client) {
1345
1352
  return toolError(error);
1346
1353
  }
1347
1354
  }
1355
+ async function groupOf(client, item) {
1356
+ if (!item.proposalBatch || item.status !== "needs_approval") return [item];
1357
+ const isSibling = (other) => typeof other === "object" && other !== null && other.status === "needs_approval" && other.proposalBatch === item.proposalBatch && other.assetId === item.assetId && other.id !== item.id;
1358
+ const siblings = [];
1359
+ let cursor;
1360
+ do {
1361
+ const response = await client.get("/api/actions/items", {
1362
+ view: "open",
1363
+ limit: 100,
1364
+ ...item.assetId ? { assetId: item.assetId } : {},
1365
+ ...cursor ? { cursor } : {}
1366
+ });
1367
+ siblings.push(...(response.items ?? []).filter(isSibling));
1368
+ cursor = response.nextCursor;
1369
+ } while (cursor);
1370
+ return [item, ...siblings];
1371
+ }
1372
+ async function approveGroup(client, actionId) {
1373
+ const detail = await client.get(
1374
+ `/api/actions/items/${encodeURIComponent(actionId)}`
1375
+ );
1376
+ if (!detail.item) throw new Error("Action not found");
1377
+ const group = await groupOf(client, detail.item);
1378
+ if (group.length <= 1) return null;
1379
+ const approvable = group.filter(
1380
+ (item) => item.allowedCommands?.includes("approve")
1381
+ );
1382
+ const skipped = group.filter((item) => !approvable.includes(item)).map((item) => item.id);
1383
+ if (approvable.length === 0)
1384
+ return toolText(
1385
+ {
1386
+ success: false,
1387
+ actionId,
1388
+ skipped,
1389
+ message: "Nothing in this card can be approved right now."
1390
+ },
1391
+ true
1392
+ );
1393
+ const answer = await client.postForAnswer(
1394
+ "/api/actions/commands",
1395
+ {
1396
+ command: "approve",
1397
+ idempotencyKey: `mcp:approve-group:${actionId}:${randomUUID()}`,
1398
+ targets: approvable.map((item) => ({
1399
+ itemId: item.id,
1400
+ ...item.currentRevisionId ? { revisionId: item.currentRevisionId } : {}
1401
+ }))
1402
+ }
1403
+ );
1404
+ const results = (answer.body?.results ?? []).map((result) => ({
1405
+ itemId: result.itemId,
1406
+ result: result.result,
1407
+ ...result.error ? {
1408
+ error: publicMcpErrorMessage(
1409
+ result.error,
1410
+ "Fload could not apply this change."
1411
+ )
1412
+ } : {}
1413
+ }));
1414
+ const approved = results.filter(
1415
+ (r) => r.result === "applied" || r.result === "replayed"
1416
+ ).length;
1417
+ return toolText(
1418
+ {
1419
+ success: approved > 0,
1420
+ actionId,
1421
+ approved,
1422
+ results,
1423
+ ...skipped.length ? { skipped } : {},
1424
+ 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."
1425
+ },
1426
+ approved === 0
1427
+ );
1428
+ }
1348
1429
  async function rejectAction(input, client) {
1349
1430
  try {
1350
1431
  const { command, result } = await commandItem(
@@ -1786,9 +1867,26 @@ async function getConversationMessages(input, client) {
1786
1867
  };
1787
1868
  }
1788
1869
  }
1870
+ var FREE_CONVERSATION_LABEL = "Free: your first conversation";
1871
+ var FREE_CONVERSATION_ENDED_NOTICE = "Your free first conversation has ended; messages now use credits.";
1872
+ function answerCostOf(data) {
1873
+ if (!data || typeof data !== "object") return null;
1874
+ const usage = data;
1875
+ const free = usage.freeConversation;
1876
+ if (free && typeof free.messagesLeft === "number") {
1877
+ return {
1878
+ free: true,
1879
+ label: FREE_CONVERSATION_LABEL,
1880
+ messagesLeft: free.messagesLeft,
1881
+ ...free.ended === true ? { notice: FREE_CONVERSATION_ENDED_NOTICE } : {}
1882
+ };
1883
+ }
1884
+ return typeof usage.credits === "number" ? { free: false, credits: usage.credits } : null;
1885
+ }
1789
1886
  function parseUiMessageStream(raw) {
1790
1887
  let reply = "";
1791
1888
  const toolsUsed = [];
1889
+ let cost = null;
1792
1890
  for (const line of raw.split("\n")) {
1793
1891
  if (!line.startsWith("data:")) continue;
1794
1892
  const payload = line.slice(5).trim();
@@ -1799,11 +1897,13 @@ function parseUiMessageStream(raw) {
1799
1897
  reply += String(event.delta ?? event.textDelta ?? "");
1800
1898
  } else if (typeof event.type === "string" && event.type === "tool-input-start" && typeof event.toolName === "string") {
1801
1899
  toolsUsed.push(event.toolName);
1900
+ } else if (event.type === "data-usage") {
1901
+ cost = answerCostOf(event.data) ?? cost;
1802
1902
  }
1803
1903
  } catch {
1804
1904
  }
1805
1905
  }
1806
- return { reply, toolsUsed };
1906
+ return { reply, toolsUsed, cost };
1807
1907
  }
1808
1908
  async function sendChatMessage(input, client) {
1809
1909
  try {
@@ -1844,7 +1944,7 @@ async function sendChatMessage(input, client) {
1844
1944
  };
1845
1945
  }
1846
1946
  const raw = await client.postStream("/api/chat", body);
1847
- const { reply, toolsUsed } = parseUiMessageStream(raw);
1947
+ const { reply, toolsUsed, cost } = parseUiMessageStream(raw);
1848
1948
  return {
1849
1949
  content: [
1850
1950
  {
@@ -1853,6 +1953,8 @@ async function sendChatMessage(input, client) {
1853
1953
  conversationId,
1854
1954
  reply: reply || "The assistant returned no text response.",
1855
1955
  toolsUsed,
1956
+ // FLO-2669: the credits the answer used, or that it was free.
1957
+ ...cost ? { cost } : {},
1856
1958
  tip: "Pass this conversationId to continue the conversation or to get_conversation_messages for the full transcript."
1857
1959
  })
1858
1960
  }
@@ -2184,13 +2286,15 @@ function registerTools(server, client, options = {}) {
2184
2286
  tool(
2185
2287
  "send_chat_message",
2186
2288
  "Send chat message",
2187
- "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.",
2289
+ "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).",
2188
2290
  sendChatMessageSchema,
2189
2291
  sendChatMessage,
2190
2292
  { readOnlyHint: false, destructiveHint: false, openWorldHint: true }
2191
2293
  );
2192
2294
  }
2193
2295
  export {
2296
+ FREE_CONVERSATION_ENDED_NOTICE,
2297
+ FREE_CONVERSATION_LABEL,
2194
2298
  approveAction,
2195
2299
  approveActionSchema,
2196
2300
  checkActionNow,