@botiverse/raft-sdk 0.12.0 → 0.12.1

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.
@@ -10967,23 +10967,40 @@ function failureOutcome(error) {
10967
10967
  text: formatOpErrorText(error)
10968
10968
  };
10969
10969
  }
10970
+ /** A next action written for the CLI: it names a `raft` command or a `--flag`. */
10971
+ const CLI_NEXT_ACTION_PATTERN = /\braft [a-z]|(^|[\s`'"(])--[a-z]/;
10970
10972
  /**
10971
- * Render the SDK's own default next action in a hint style. Only NOT_FOUND's
10972
- * default names a command; it is set deep in the shared client-error mapping,
10973
- * so `createRaft({ hints: "tool" })` re-renders it here instead of threading
10974
- * the style through every failure. A Server-sent next action is left as is.
10973
+ * The attachment routes answer one uniform 404 for missing, unreadable and
10974
+ * other-subsystem ids (no existence oracle); the Server's next action names
10975
+ * the Feedback Admin CLI command, which a tool-mode model cannot run.
10976
+ */
10977
+ const ATTACHMENT_UNAVAILABLE_TOOL_NEXT_ACTION = "This id is not an attachment you can read. Use an attachment id from a message you can see.";
10978
+ /**
10979
+ * Render a failure's next action in a hint style. In "cli" style nothing
10980
+ * changes. In "tool" style no next action names a CLI command: the SDK's own
10981
+ * NOT_FOUND default (set deep in the shared client-error mapping) is
10982
+ * re-rendered as a tool call, `ATTACHMENT_UNAVAILABLE` gets a neutral step,
10983
+ * and any other Server-sent next action written for the CLI falls back to the
10984
+ * code's default.
10975
10985
  */
10976
10986
  function restyleDefaultNextAction(outcome, style) {
10977
10987
  if (style === "cli" || !outcome || typeof outcome !== "object") return outcome;
10978
10988
  const failure = outcome;
10979
- if (failure.ok !== false || !failure.error || failure.error.nextAction !== DEFAULT_NEXT_ACTION.NOT_FOUND) return outcome;
10989
+ if (failure.ok !== false || !failure.error) return outcome;
10990
+ const current = failure.error.nextAction;
10991
+ let nextAction;
10992
+ if (current === DEFAULT_NEXT_ACTION.NOT_FOUND) nextAction = notFoundNextAction(style);
10993
+ else if (failure.error.serverCode === "ATTACHMENT_UNAVAILABLE") nextAction = ATTACHMENT_UNAVAILABLE_TOOL_NEXT_ACTION;
10994
+ else if (CLI_NEXT_ACTION_PATTERN.test(current)) nextAction = failure.error.code === "NOT_FOUND" ? notFoundNextAction(style) : DEFAULT_NEXT_ACTION[failure.error.code];
10995
+ else return outcome;
10996
+ if (nextAction === current) return outcome;
10980
10997
  const error = {
10981
10998
  ...failure.error,
10982
- nextAction: notFoundNextAction(style)
10999
+ nextAction
10983
11000
  };
10984
- const next = failure.next && failure.next.why === DEFAULT_NEXT_ACTION.NOT_FOUND ? {
11001
+ const next = failure.next && failure.next.why === current ? {
10985
11002
  ...failure.next,
10986
- why: error.nextAction
11003
+ why: nextAction
10987
11004
  } : failure.next ?? null;
10988
11005
  return {
10989
11006
  ...failure,
package/dist/esm/index.js CHANGED
@@ -10966,23 +10966,40 @@ function failureOutcome(error) {
10966
10966
  text: formatOpErrorText(error)
10967
10967
  };
10968
10968
  }
10969
+ /** A next action written for the CLI: it names a `raft` command or a `--flag`. */
10970
+ const CLI_NEXT_ACTION_PATTERN = /\braft [a-z]|(^|[\s`'"(])--[a-z]/;
10969
10971
  /**
10970
- * Render the SDK's own default next action in a hint style. Only NOT_FOUND's
10971
- * default names a command; it is set deep in the shared client-error mapping,
10972
- * so `createRaft({ hints: "tool" })` re-renders it here instead of threading
10973
- * the style through every failure. A Server-sent next action is left as is.
10972
+ * The attachment routes answer one uniform 404 for missing, unreadable and
10973
+ * other-subsystem ids (no existence oracle); the Server's next action names
10974
+ * the Feedback Admin CLI command, which a tool-mode model cannot run.
10975
+ */
10976
+ const ATTACHMENT_UNAVAILABLE_TOOL_NEXT_ACTION = "This id is not an attachment you can read. Use an attachment id from a message you can see.";
10977
+ /**
10978
+ * Render a failure's next action in a hint style. In "cli" style nothing
10979
+ * changes. In "tool" style no next action names a CLI command: the SDK's own
10980
+ * NOT_FOUND default (set deep in the shared client-error mapping) is
10981
+ * re-rendered as a tool call, `ATTACHMENT_UNAVAILABLE` gets a neutral step,
10982
+ * and any other Server-sent next action written for the CLI falls back to the
10983
+ * code's default.
10974
10984
  */
10975
10985
  function restyleDefaultNextAction(outcome, style) {
10976
10986
  if (style === "cli" || !outcome || typeof outcome !== "object") return outcome;
10977
10987
  const failure = outcome;
10978
- if (failure.ok !== false || !failure.error || failure.error.nextAction !== DEFAULT_NEXT_ACTION.NOT_FOUND) return outcome;
10988
+ if (failure.ok !== false || !failure.error) return outcome;
10989
+ const current = failure.error.nextAction;
10990
+ let nextAction;
10991
+ if (current === DEFAULT_NEXT_ACTION.NOT_FOUND) nextAction = notFoundNextAction(style);
10992
+ else if (failure.error.serverCode === "ATTACHMENT_UNAVAILABLE") nextAction = ATTACHMENT_UNAVAILABLE_TOOL_NEXT_ACTION;
10993
+ else if (CLI_NEXT_ACTION_PATTERN.test(current)) nextAction = failure.error.code === "NOT_FOUND" ? notFoundNextAction(style) : DEFAULT_NEXT_ACTION[failure.error.code];
10994
+ else return outcome;
10995
+ if (nextAction === current) return outcome;
10979
10996
  const error = {
10980
10997
  ...failure.error,
10981
- nextAction: notFoundNextAction(style)
10998
+ nextAction
10982
10999
  };
10983
- const next = failure.next && failure.next.why === DEFAULT_NEXT_ACTION.NOT_FOUND ? {
11000
+ const next = failure.next && failure.next.why === current ? {
10984
11001
  ...failure.next,
10985
- why: error.nextAction
11002
+ why: nextAction
10986
11003
  } : failure.next ?? null;
10987
11004
  return {
10988
11005
  ...failure,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botiverse/raft-sdk",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "license": "FSL-1.1-ALv2",
5
5
  "description": "Typed Raft Agent API client for external agents and bots.",
6
6
  "type": "module",