@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.
- package/dist/cjs/index.cjs +25 -8
- package/dist/esm/index.js +25 -8
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
-
*
|
|
10972
|
-
*
|
|
10973
|
-
*
|
|
10974
|
-
|
|
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
|
|
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
|
|
10999
|
+
nextAction
|
|
10983
11000
|
};
|
|
10984
|
-
const next = failure.next && failure.next.why ===
|
|
11001
|
+
const next = failure.next && failure.next.why === current ? {
|
|
10985
11002
|
...failure.next,
|
|
10986
|
-
why:
|
|
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
|
-
*
|
|
10971
|
-
*
|
|
10972
|
-
*
|
|
10973
|
-
|
|
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
|
|
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
|
|
10998
|
+
nextAction
|
|
10982
10999
|
};
|
|
10983
|
-
const next = failure.next && failure.next.why ===
|
|
11000
|
+
const next = failure.next && failure.next.why === current ? {
|
|
10984
11001
|
...failure.next,
|
|
10985
|
-
why:
|
|
11002
|
+
why: nextAction
|
|
10986
11003
|
} : failure.next ?? null;
|
|
10987
11004
|
return {
|
|
10988
11005
|
...failure,
|