@primusclaw/personal-agent 0.15.3 → 0.15.5
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 +543 -129
- package/dist/types/assistant/chat.d.ts +22 -3
- package/dist/types/config/settings.d.ts +7 -1
- package/dist/types/locales/key-needed.d.ts +6 -0
- package/dist/types/locales/link.d.ts +1 -0
- package/dist/types/locales/model-key.d.ts +6 -0
- package/dist/types/locales/remote.d.ts +2 -0
- package/dist/types/plugins/model-refusal-policy.d.ts +5 -1
- package/dist/types/protocol/claw-api/index.d.ts +2 -0
- package/dist/types/protocol/claw-api/model-key.d.ts +30 -0
- package/dist/types/protocol/claw-api/platform-key.d.ts +10 -0
- package/dist/types/remote/chats.d.ts +5 -0
- package/dist/types/remote/events.d.ts +7 -0
- package/dist/types/remote/follow/echoes.d.ts +31 -0
- package/dist/types/remote/follow/follower.d.ts +1 -1
- package/dist/types/remote/follow/retract.d.ts +27 -0
- package/dist/types/remote/follow/speaker.d.ts +21 -2
- package/dist/types/remote/follow/timings.d.ts +4 -0
- package/dist/types/remote/lines.d.ts +3 -0
- package/dist/types/remote/turns/runner.d.ts +11 -0
- package/dist/types/routing/credentials.d.ts +17 -0
- package/dist/types/routing/features.d.ts +5 -0
- package/dist/types/routing/personal-router.d.ts +12 -0
- package/dist/types/routing/turn-runner.d.ts +6 -0
- package/dist/types/routing/turn-start.d.ts +6 -0
- package/dist/types/subscriptions/subscriptions.d.ts +1 -1
- package/dist/types/turn/engine/model-key.d.ts +10 -0
- package/dist/types/turn/turn-state.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4950,6 +4950,11 @@ var ObserveBoard = class {
|
|
|
4950
4950
|
}
|
|
4951
4951
|
};
|
|
4952
4952
|
|
|
4953
|
+
// packages/core/src/claw/credential.ts
|
|
4954
|
+
function isApiKey(credential2) {
|
|
4955
|
+
return credential2.startsWith("ak-");
|
|
4956
|
+
}
|
|
4957
|
+
|
|
4953
4958
|
// packages/core/src/note/note.ts
|
|
4954
4959
|
function noteMessage(model) {
|
|
4955
4960
|
return { body: { type: "view", view: { name: "note", model }, fallbackText: model.text } };
|
|
@@ -5106,7 +5111,11 @@ var Observer = class {
|
|
|
5106
5111
|
return reopen();
|
|
5107
5112
|
}
|
|
5108
5113
|
try {
|
|
5109
|
-
|
|
5114
|
+
const linked = isApiKey(key) ? null : this.deps.links.getKey(card.userId);
|
|
5115
|
+
await this.deps.assistant.send(key, sessionId, request, {
|
|
5116
|
+
...plugin(this.deps.pluginId),
|
|
5117
|
+
...linked === null || linked === "" ? {} : { modelKey: linked }
|
|
5118
|
+
});
|
|
5110
5119
|
} catch (err2) {
|
|
5111
5120
|
if (!isClawFailure(err2)) throw err2;
|
|
5112
5121
|
this.deps.log.warn("observe: an accepted suggestion was not taken", { why: errorKind(err2) });
|
|
@@ -5302,6 +5311,35 @@ var NOTIFICATION_SURFACE_PATTERN = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
|
5302
5311
|
// ../claw/packages/protocol/src/claw-api/session-events.ts
|
|
5303
5312
|
var HISTORY_COMPLETE_EVENT = "historyComplete";
|
|
5304
5313
|
|
|
5314
|
+
// ../claw/packages/protocol/src/claw-api/model-key.ts
|
|
5315
|
+
var TURN_FAILURE_REASON_FIELD = "failure_reason";
|
|
5316
|
+
var MODEL_KEY_INVALID = "model_key_invalid";
|
|
5317
|
+
var MODEL_KEY_MISSING = "model_key_missing";
|
|
5318
|
+
var PREFIX = String.raw`^\s*(?:(?:API |[A-Za-z_.]{1,40})Error:\s*){0,3}`;
|
|
5319
|
+
var GAP = String.raw`[^\n]{0,400}?`;
|
|
5320
|
+
var MISSING_KEY = new RegExp(
|
|
5321
|
+
String.raw`${PREFIX}(?:403\b${GAP}No APIM Key binding found|401\b${GAP}missing subscription key)`,
|
|
5322
|
+
"i"
|
|
5323
|
+
);
|
|
5324
|
+
var INVALID_KEY = new RegExp(String.raw`${PREFIX}401\b${GAP}invalid subscription key`, "i");
|
|
5325
|
+
function modelKeyRefusalOf(text9) {
|
|
5326
|
+
if (typeof text9 !== "string") return null;
|
|
5327
|
+
if (MISSING_KEY.test(text9)) return "missing";
|
|
5328
|
+
if (INVALID_KEY.test(text9)) return "invalid";
|
|
5329
|
+
return null;
|
|
5330
|
+
}
|
|
5331
|
+
function modelKeyFailureCode(refusal4) {
|
|
5332
|
+
return refusal4 === "invalid" ? MODEL_KEY_INVALID : MODEL_KEY_MISSING;
|
|
5333
|
+
}
|
|
5334
|
+
function modelKeyRefusalOfCode(code3) {
|
|
5335
|
+
if (code3 === MODEL_KEY_INVALID) return "invalid";
|
|
5336
|
+
if (code3 === MODEL_KEY_MISSING) return "missing";
|
|
5337
|
+
return null;
|
|
5338
|
+
}
|
|
5339
|
+
|
|
5340
|
+
// ../claw/packages/protocol/src/claw-api/platform-key.ts
|
|
5341
|
+
var PLATFORM_KEY_REQUIRED = "platform_key_required";
|
|
5342
|
+
|
|
5305
5343
|
// ../claw/packages/protocol/src/remote-agents.ts
|
|
5306
5344
|
import { createHash } from "node:crypto";
|
|
5307
5345
|
var REMOTE_AGENT_PROTOCOL_VERSION = 1;
|
|
@@ -5821,11 +5859,6 @@ function parseInput(what, schema, input) {
|
|
|
5821
5859
|
return err({ kind: "invalid_input", what, paths: [...new Set(paths)] });
|
|
5822
5860
|
}
|
|
5823
5861
|
|
|
5824
|
-
// packages/core/src/claw/credential.ts
|
|
5825
|
-
function isApiKey(credential2) {
|
|
5826
|
-
return credential2.startsWith("ak-");
|
|
5827
|
-
}
|
|
5828
|
-
|
|
5829
5862
|
// packages/core/src/claw/remote.ts
|
|
5830
5863
|
import { z as z2 } from "zod";
|
|
5831
5864
|
|
|
@@ -6817,6 +6850,104 @@ ${errorLine}` : errorLine];
|
|
|
6817
6850
|
${errorLine}` : part);
|
|
6818
6851
|
}
|
|
6819
6852
|
|
|
6853
|
+
// packages/core/src/locales/key-needed.ts
|
|
6854
|
+
var keyNeededText = defineCatalog({
|
|
6855
|
+
en: {
|
|
6856
|
+
keyNeeded: (p) => `PrimusClaw has no API key of yours to run this with, so nothing was started.
|
|
6857
|
+
|
|
6858
|
+
To link one, open this page, sign in, and select Connect ${p.channel}:
|
|
6859
|
+
|
|
6860
|
+
${p.page}
|
|
6861
|
+
|
|
6862
|
+
You will get a short code; send \`/link CODE\` here (valid for 10 minutes, works once). Then ask me again.`
|
|
6863
|
+
},
|
|
6864
|
+
zh: {
|
|
6865
|
+
keyNeeded: (p) => `PrimusClaw \u91CC\u8FD8\u6CA1\u6709\u4F60\u7684 API key\uFF0C\u8FD9\u6B21\u6CA1\u6709\u5F00\u59CB\u3002
|
|
6866
|
+
|
|
6867
|
+
\u8BF7\u6253\u5F00\u8FD9\u4E2A\u9875\u9762\uFF0C\u767B\u5F55\u540E\u9009\u62E9 Connect ${p.channel}\uFF1A
|
|
6868
|
+
|
|
6869
|
+
${p.page}
|
|
6870
|
+
|
|
6871
|
+
\u4F60\u4F1A\u62FF\u5230\u4E00\u4E2A\u77ED\u7801\uFF1B\u5728\u8FD9\u91CC\u53D1 \`/link CODE\`\uFF08CODE \u6362\u6210\u77ED\u7801\uFF0C10 \u5206\u949F\u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09\uFF0C\u7136\u540E\u518D\u95EE\u6211\u4E00\u6B21\u3002`
|
|
6872
|
+
}
|
|
6873
|
+
});
|
|
6874
|
+
|
|
6875
|
+
// packages/core/src/locales/link.ts
|
|
6876
|
+
var linkText = defineCatalog({
|
|
6877
|
+
en: {
|
|
6878
|
+
linkSteps: (p) => `${p.lead}To use ${p.bot}, connect your PrimusClaw account first. Open this page, sign in, and select Connect ${p.channel}:
|
|
6879
|
+
|
|
6880
|
+
${p.page}
|
|
6881
|
+
|
|
6882
|
+
You will get a short code; send \`/link CODE\` here (valid for 10 minutes, works once).
|
|
6883
|
+
|
|
6884
|
+
` + p.notice,
|
|
6885
|
+
platformDown: "I could not reach the Primus platform to check your connection. Please try again in a minute.",
|
|
6886
|
+
notConfirmedYet: "I do not see your confirmation yet. ",
|
|
6887
|
+
notConfirmedLine: "I do not see your confirmation yet. Open the link in the card above and confirm, then press the button again.",
|
|
6888
|
+
platformUnreachable: "I could not reach the Primus platform. Please try again in a minute.",
|
|
6889
|
+
pressConfirmAgain: " Press Confirm again then.",
|
|
6890
|
+
connectTitle: (p) => `Connect ${p.bot}`,
|
|
6891
|
+
connected: "Connected. ",
|
|
6892
|
+
runningFromGroup: "I am running your request from the group chat now; the answer will be posted there.",
|
|
6893
|
+
getStarted: "Send me a message to get started, or /help for commands.",
|
|
6894
|
+
linkedAs: (p) => `Connected${p.who}. If this is not you, send /unlink now.
|
|
6895
|
+
|
|
6896
|
+
`,
|
|
6897
|
+
tooManyWrong: (p) => `Too many wrong codes. Wait ${String(p.minutes)} minute${p.minutes !== 1 ? "s" : ""} and try again.`,
|
|
6898
|
+
linkingPaused: "Linking is paused for a few minutes because of too many wrong codes. Please try again later.",
|
|
6899
|
+
badCode: "That code is not valid or has expired. Get a new one on the console page.",
|
|
6900
|
+
identityRefused: "That needs you in person: confirm your identity once on this card, then ask again.",
|
|
6901
|
+
identityFallback: "Your assistant could not take this message, so I handled it the usual way. You can also confirm your identity once on this card, so it can act as you."
|
|
6902
|
+
},
|
|
6903
|
+
zh: {
|
|
6904
|
+
linkSteps: (p) => `${p.lead}\u8981\u4F7F\u7528 ${p.bot}\uFF0C\u8BF7\u5148\u8FDE\u4E0A\u4F60\u7684 PrimusClaw \u8D26\u53F7\u3002\u6253\u5F00\u8FD9\u4E2A\u9875\u9762\uFF0C\u767B\u5F55\u540E\u9009\u62E9 Connect ${p.channel}\uFF1A
|
|
6905
|
+
|
|
6906
|
+
${p.page}
|
|
6907
|
+
|
|
6908
|
+
\u4F60\u4F1A\u62FF\u5230\u4E00\u4E2A\u77ED\u7801\uFF1B\u5728\u8FD9\u91CC\u53D1 \`/link CODE\`\uFF08CODE \u6362\u6210\u77ED\u7801\uFF0C10 \u5206\u949F\u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09\u3002`,
|
|
6909
|
+
platformDown: "I could not reach the Primus platform to check your connection. Please try again in a minute.",
|
|
6910
|
+
notConfirmedYet: "\u6211\u8FD8\u6CA1\u770B\u5230\u4F60\u7684\u786E\u8BA4\u3002",
|
|
6911
|
+
notConfirmedLine: "\u6211\u8FD8\u6CA1\u770B\u5230\u4F60\u7684\u786E\u8BA4\u3002\u6253\u5F00\u4E0A\u9762\u5361\u7247\u91CC\u7684\u94FE\u63A5\u786E\u8BA4\uFF0C\u7136\u540E\u518D\u6309\u4E00\u6B21\u6309\u94AE\u3002",
|
|
6912
|
+
platformUnreachable: "I could not reach the Primus platform. Please try again in a minute.",
|
|
6913
|
+
pressConfirmAgain: " Press Confirm again then.",
|
|
6914
|
+
connectTitle: (p) => `Connect ${p.bot}`,
|
|
6915
|
+
connected: "Connected. ",
|
|
6916
|
+
runningFromGroup: "\u6211\u73B0\u5728\u5728\u7FA4\u804A\u91CC\u8FD0\u884C\u4F60\u7684\u8BF7\u6C42\uFF0C\u7B54\u6848\u4F1A\u53D1\u5728\u90A3\u91CC\u3002",
|
|
6917
|
+
getStarted: "\u7ED9\u6211\u53D1\u6761\u6D88\u606F\u5C31\u5F00\u59CB\uFF0C\u6216\u8005\u53D1 /help \u770B\u6211\u80FD\u505A\u4EC0\u4E48\u3002",
|
|
6918
|
+
linkedAs: (p) => `\u5DF2\u8FDE\u63A5${p.who}\u3002\u5982\u679C\u4E0D\u662F\u4F60\uFF0C\u73B0\u5728\u53D1 /unlink\u3002
|
|
6919
|
+
|
|
6920
|
+
`,
|
|
6921
|
+
tooManyWrong: (p) => `Too many wrong codes. Wait ${String(p.minutes)} minute${p.minutes !== 1 ? "s" : ""} and try again.`,
|
|
6922
|
+
linkingPaused: "Linking is paused for a few minutes because of too many wrong codes. Please try again later.",
|
|
6923
|
+
badCode: "That code is not valid or has expired. Get a new one on the console page.",
|
|
6924
|
+
identityRefused: "\u8FD9\u4E00\u6B65\u9700\u8981\u4F60\u672C\u4EBA\uFF1A\u5728\u8FD9\u5F20\u5361\u7247\u4E0A\u786E\u8BA4\u4E00\u6B21\u8EAB\u4EFD\uFF0C\u7136\u540E\u518D\u8BF4\u4E00\u904D\u5C31\u884C\u3002",
|
|
6925
|
+
identityFallback: "\u4F60\u7684\u52A9\u7406\u8FD9\u6B21\u6CA1\u80FD\u63A5\u624B\u8FD9\u6761\u6D88\u606F\uFF0C\u6211\u5DF2\u6309\u5E38\u89C4\u65B9\u5F0F\u5904\u7406\u3002\u4F60\u4E5F\u53EF\u4EE5\u5728\u8FD9\u5F20\u5361\u7247\u4E0A\u786E\u8BA4\u4E00\u6B21\u8EAB\u4EFD\uFF0C\u4E4B\u540E\u5B83\u5C31\u80FD\u4EE5\u4F60\u7684\u8EAB\u4EFD\u529E\u4E8B\u3002"
|
|
6926
|
+
}
|
|
6927
|
+
});
|
|
6928
|
+
function linkPage(publicBaseUrl, channel) {
|
|
6929
|
+
return `${publicBaseUrl}/primus-claw/${channel}-link`;
|
|
6930
|
+
}
|
|
6931
|
+
function linkKeyName(shortName2) {
|
|
6932
|
+
return `PrimusClaw ${shortName2}`;
|
|
6933
|
+
}
|
|
6934
|
+
var unlinkText = defineCatalog({
|
|
6935
|
+
en: {
|
|
6936
|
+
bindingOnly: "This chat acts as you through a SaFE identity binding, which only you can remove: delete it in SaFE under identity bindings. Until then I keep working for you.",
|
|
6937
|
+
deleted: "The API key was deleted.",
|
|
6938
|
+
notDeleted: (p) => `I could not delete the API key named "${p.key}"; please delete it in SaFE under API keys.`,
|
|
6939
|
+
stillBound: " This chat is still connected through a SaFE identity binding, which only you can remove: delete it in SaFE under identity bindings.",
|
|
6940
|
+
unlinked: (p) => `Unlinked. ${p.tail}`
|
|
6941
|
+
},
|
|
6942
|
+
zh: {
|
|
6943
|
+
bindingOnly: "\u8FD9\u4E2A\u804A\u5929\u901A\u8FC7 SaFE \u8EAB\u4EFD\u7ED1\u5B9A\u4EE5\u4F60\u7684\u8EAB\u4EFD\u5DE5\u4F5C\uFF0C\u53EA\u6709\u4F60\u80FD\u5220\u9664\u8FD9\u4E2A\u7ED1\u5B9A\uFF1A\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u3002\u5220\u9664\u4E4B\u524D\u6211\u4F1A\u7EE7\u7EED\u4E3A\u4F60\u5DE5\u4F5C\u3002",
|
|
6944
|
+
deleted: "API key \u5DF2\u5220\u9664\u3002",
|
|
6945
|
+
notDeleted: (p) => `\u6211\u6CA1\u80FD\u5220\u9664 API key "${p.key}"; \u8BF7\u5728 SaFE \u7684 API keys \u91CC\u5220\u9664\u3002`,
|
|
6946
|
+
stillBound: "\u8FD9\u4E2A\u804A\u5929\u4ECD\u901A\u8FC7 SaFE \u8EAB\u4EFD\u7ED1\u5B9A\u8FDE\u7740\uFF0C\u53EA\u6709\u4F60\u80FD\u5220\u9664\u5B83\uFF1A\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u3002",
|
|
6947
|
+
unlinked: (p) => `\u5DF2\u65AD\u5F00\u3002${p.tail}`
|
|
6948
|
+
}
|
|
6949
|
+
});
|
|
6950
|
+
|
|
6820
6951
|
// packages/core/src/turn/ports.ts
|
|
6821
6952
|
function nowSeconds(clock2) {
|
|
6822
6953
|
return clock2.monotonicMs() / 1e3;
|
|
@@ -8463,6 +8594,8 @@ var TurnState = class {
|
|
|
8463
8594
|
prSummary = "";
|
|
8464
8595
|
/** How Claw ended the turn; undefined: not yet. */
|
|
8465
8596
|
failed = void 0;
|
|
8597
|
+
/** Why Claw says the turn failed (its `failure_reason`, a code); '' when it said none, or the turn did not fail. */
|
|
8598
|
+
failureReason = "";
|
|
8466
8599
|
get answer() {
|
|
8467
8600
|
return this.finalText || this.text;
|
|
8468
8601
|
}
|
|
@@ -8586,6 +8719,8 @@ var TurnState = class {
|
|
|
8586
8719
|
const inner = objectOr(data["data"]);
|
|
8587
8720
|
this.finalText = textOf3(truthy(data["final_text"]) ? data["final_text"] : inner["result"]);
|
|
8588
8721
|
this.failed = Boolean(this.failed) || inner["subtype"] !== "success";
|
|
8722
|
+
const reason = data[TURN_FAILURE_REASON_FIELD];
|
|
8723
|
+
if (typeof reason === "string") this.failureReason = reason;
|
|
8589
8724
|
return { finished: true, error: inner["subtype"] === "error" };
|
|
8590
8725
|
}
|
|
8591
8726
|
statusUpdate(data) {
|
|
@@ -9032,6 +9167,42 @@ async function rerunOnFallback(ctx, sessionId, status, onSession, running) {
|
|
|
9032
9167
|
}
|
|
9033
9168
|
}
|
|
9034
9169
|
|
|
9170
|
+
// packages/core/src/locales/model-key.ts
|
|
9171
|
+
var modelKeyText = defineCatalog({
|
|
9172
|
+
en: {
|
|
9173
|
+
invalid: "The model access key bound to your account in the LLM gateway was refused, so I could not call the model.\n\nUpdate it in the LLM gateway settings in SaFE, then ask me again.",
|
|
9174
|
+
missing: "No model access key is bound to your account in the LLM gateway, so I could not call a model for you.\n\nAdd one in the LLM gateway settings in SaFE, then ask me again.",
|
|
9175
|
+
leadInvalid: "Your model access key in the LLM gateway was refused, so a backup model answered. Update it in the LLM gateway settings in SaFE to get yours back.",
|
|
9176
|
+
leadMissing: "No model access key is bound to your account in the LLM gateway, so a backup model answered. Add one in the LLM gateway settings in SaFE to get yours back."
|
|
9177
|
+
},
|
|
9178
|
+
zh: {
|
|
9179
|
+
invalid: "\u4F60\u5728 LLM \u7F51\u5173\u4E2D\u7ED1\u5B9A\u7684\u6A21\u578B\u8BBF\u95EE Key \u88AB\u62D2\u7EDD\u4E86\uFF08\u65E0\u6548\u6216\u5DF2\u8FC7\u671F\uFF09\uFF0C\u6211\u6682\u65F6\u65E0\u6CD5\u8C03\u7528\u6A21\u578B\u3002\n\n\u8BF7\u5230 SaFE \u7684 LLM \u7F51\u5173\u8BBE\u7F6E\u4E2D\u66F4\u65B0\uFF0C\u7136\u540E\u518D\u95EE\u6211\u4E00\u6B21\u3002",
|
|
9180
|
+
missing: "\u4F60\u7684\u8D26\u53F7\u8FD8\u6CA1\u6709\u5728 LLM \u7F51\u5173\u4E2D\u7ED1\u5B9A\u6A21\u578B\u8BBF\u95EE Key\uFF0C\u6211\u6682\u65F6\u65E0\u6CD5\u4E3A\u4F60\u8C03\u7528\u6A21\u578B\u3002\n\n\u8BF7\u5230 SaFE \u7684 LLM \u7F51\u5173\u8BBE\u7F6E\u4E2D\u6DFB\u52A0\uFF0C\u7136\u540E\u518D\u95EE\u6211\u4E00\u6B21\u3002",
|
|
9181
|
+
leadInvalid: "\u4F60\u5728 LLM \u7F51\u5173\u4E2D\u7684\u6A21\u578B\u8BBF\u95EE Key \u88AB\u62D2\u7EDD\u4E86\uFF0C\u8FD9\u6B21\u7528\u7684\u662F\u5907\u7528\u6A21\u578B\uFF1B\u5230 SaFE \u7684 LLM \u7F51\u5173\u8BBE\u7F6E\u4E2D\u66F4\u65B0\u540E\u5373\u53EF\u6062\u590D\u3002",
|
|
9182
|
+
leadMissing: "\u4F60\u7684\u8D26\u53F7\u8FD8\u6CA1\u6709\u5728 LLM \u7F51\u5173\u4E2D\u7ED1\u5B9A\u6A21\u578B\u8BBF\u95EE Key\uFF0C\u8FD9\u6B21\u7528\u7684\u662F\u5907\u7528\u6A21\u578B\uFF1B\u5230 SaFE \u7684 LLM \u7F51\u5173\u8BBE\u7F6E\u4E2D\u6DFB\u52A0\u540E\u5373\u53EF\u6062\u590D\u3002"
|
|
9183
|
+
}
|
|
9184
|
+
});
|
|
9185
|
+
|
|
9186
|
+
// packages/core/src/turn/engine/model-key.ts
|
|
9187
|
+
function refusalOf(ctx, state) {
|
|
9188
|
+
const read = ctx.deps.refusals.classify(state.answer, state.failed);
|
|
9189
|
+
if (read !== void 0 || state.failed === false) return read;
|
|
9190
|
+
const own3 = modelKeyRefusalOfCode(state.failureReason);
|
|
9191
|
+
return own3 === null ? void 0 : { kind: own3 };
|
|
9192
|
+
}
|
|
9193
|
+
function guidanceOf(ctx, refusal4, lang) {
|
|
9194
|
+
const own3 = ctx.deps.refusals.guidance(refusal4, lang);
|
|
9195
|
+
if (own3) return own3;
|
|
9196
|
+
const text9 = modelKeyText.in(lang);
|
|
9197
|
+
return refusal4.kind === "invalid" ? text9.invalid : refusal4.kind === "missing" ? text9.missing : "";
|
|
9198
|
+
}
|
|
9199
|
+
function leadOf2(ctx, refusal4, lang) {
|
|
9200
|
+
const own3 = ctx.deps.refusals.fallbackLead(refusal4, lang);
|
|
9201
|
+
if (own3) return own3;
|
|
9202
|
+
const text9 = modelKeyText.in(lang);
|
|
9203
|
+
return refusal4.kind === "invalid" ? text9.leadInvalid : refusal4.kind === "missing" ? text9.leadMissing : "";
|
|
9204
|
+
}
|
|
9205
|
+
|
|
9035
9206
|
// packages/core/src/turn/engine/run-turn.ts
|
|
9036
9207
|
var ACTING_AS_MUST_BE_SELF = "acting_as_must_be_self";
|
|
9037
9208
|
var DeadlineExpired = class extends Error {
|
|
@@ -9118,22 +9289,22 @@ var TurnRun = class {
|
|
|
9118
9289
|
let stopped = this.controls.stopRequested();
|
|
9119
9290
|
let lead = "";
|
|
9120
9291
|
let fallbackFailed = false;
|
|
9121
|
-
const refusal4 = stopped ? void 0 : ctx
|
|
9292
|
+
const refusal4 = stopped ? void 0 : refusalOf(ctx, state);
|
|
9122
9293
|
if (refusal4) {
|
|
9123
9294
|
const rerun = await rerunOnFallback(ctx, sessionId, this.status, this.controls.onSession, this.running);
|
|
9124
9295
|
if (rerun) {
|
|
9125
9296
|
({ state, ok: ok2 } = rerun);
|
|
9126
9297
|
this.state = state;
|
|
9127
9298
|
stopped = this.controls.stopRequested();
|
|
9128
|
-
lead = ctx
|
|
9299
|
+
lead = leadOf2(ctx, refusal4, langOf(ctx));
|
|
9129
9300
|
fallbackFailed = Boolean(state.failed);
|
|
9130
9301
|
if (fallbackFailed && !stopped)
|
|
9131
9302
|
ctx.deps.log.warn("the fallback model failed too; the user is told to upload the key");
|
|
9132
9303
|
}
|
|
9133
9304
|
}
|
|
9134
|
-
const refused3 = fallbackFailed ? refusal4 : ctx
|
|
9305
|
+
const refused3 = fallbackFailed ? refusal4 : refusalOf(ctx, state);
|
|
9135
9306
|
if (!stopped && refused3) {
|
|
9136
|
-
await this.status.finish([ctx
|
|
9307
|
+
await this.status.finish([guidanceOf(ctx, refusal4 ?? refused3, langOf(ctx))], { rich: true });
|
|
9137
9308
|
this.tell("failed");
|
|
9138
9309
|
return;
|
|
9139
9310
|
}
|
|
@@ -9221,6 +9392,12 @@ var TurnRun = class {
|
|
|
9221
9392
|
}
|
|
9222
9393
|
this.tell("failed");
|
|
9223
9394
|
const review = Boolean(ctx.request.actingAs);
|
|
9395
|
+
if (!review && err2.status === 403 && err2.code === PLATFORM_KEY_REQUIRED) {
|
|
9396
|
+
const { channel, name } = ctx.deps.surface.caps;
|
|
9397
|
+
const page = linkPage(ctx.request.publicBaseUrl, channel);
|
|
9398
|
+
await this.status.finish([keyNeededText.in(langOf(ctx)).keyNeeded({ page, channel: name })]);
|
|
9399
|
+
return;
|
|
9400
|
+
}
|
|
9224
9401
|
ctx.record.refusal = review && err2.status === 401 ? err2 : void 0;
|
|
9225
9402
|
await this.status.finish([resultLead(ctx, this.state) + clawFailure(ctx.deps.errors, err2, review)]);
|
|
9226
9403
|
await offerReport(ctx);
|
|
@@ -9448,6 +9625,7 @@ var TurnEngine = class {
|
|
|
9448
9625
|
const review = run.review?.turn;
|
|
9449
9626
|
return {
|
|
9450
9627
|
key: run.credential,
|
|
9628
|
+
...run.modelKey ? { modelKey: run.modelKey } : {},
|
|
9451
9629
|
text: run.text,
|
|
9452
9630
|
idempotencyKey: run.messageId,
|
|
9453
9631
|
publicBaseUrl: this.deps.publicBaseUrl,
|
|
@@ -10424,80 +10602,6 @@ function dataStatement(lang, remote = false, groupContext, channel) {
|
|
|
10424
10602
|
return [`**${DATA_TITLE[chosen]}**`, ...lines.map((line3) => `- ${line3}`)].join("\n");
|
|
10425
10603
|
}
|
|
10426
10604
|
|
|
10427
|
-
// packages/core/src/locales/link.ts
|
|
10428
|
-
var linkText = defineCatalog({
|
|
10429
|
-
en: {
|
|
10430
|
-
linkSteps: (p) => `${p.lead}To use ${p.bot}, connect your PrimusClaw account first. Open this page, sign in, and select Connect ${p.channel}:
|
|
10431
|
-
|
|
10432
|
-
${p.page}
|
|
10433
|
-
|
|
10434
|
-
You will get a short code; send \`/link CODE\` here (valid for 10 minutes, works once).
|
|
10435
|
-
|
|
10436
|
-
` + p.notice,
|
|
10437
|
-
platformDown: "I could not reach the Primus platform to check your connection. Please try again in a minute.",
|
|
10438
|
-
notConfirmedYet: "I do not see your confirmation yet. ",
|
|
10439
|
-
notConfirmedLine: "I do not see your confirmation yet. Open the link in the card above and confirm, then press the button again.",
|
|
10440
|
-
platformUnreachable: "I could not reach the Primus platform. Please try again in a minute.",
|
|
10441
|
-
pressConfirmAgain: " Press Confirm again then.",
|
|
10442
|
-
connectTitle: (p) => `Connect ${p.bot}`,
|
|
10443
|
-
connected: "Connected. ",
|
|
10444
|
-
runningFromGroup: "I am running your request from the group chat now; the answer will be posted there.",
|
|
10445
|
-
getStarted: "Send me a message to get started, or /help for commands.",
|
|
10446
|
-
linkedAs: (p) => `Connected${p.who}. If this is not you, send /unlink now.
|
|
10447
|
-
|
|
10448
|
-
`,
|
|
10449
|
-
tooManyWrong: (p) => `Too many wrong codes. Wait ${String(p.minutes)} minute${p.minutes !== 1 ? "s" : ""} and try again.`,
|
|
10450
|
-
linkingPaused: "Linking is paused for a few minutes because of too many wrong codes. Please try again later.",
|
|
10451
|
-
badCode: "That code is not valid or has expired. Get a new one on the console page.",
|
|
10452
|
-
identityRefused: "That needs you in person: confirm your identity once on this card, then ask again."
|
|
10453
|
-
},
|
|
10454
|
-
zh: {
|
|
10455
|
-
linkSteps: (p) => `${p.lead}\u8981\u4F7F\u7528 ${p.bot}\uFF0C\u8BF7\u5148\u8FDE\u4E0A\u4F60\u7684 PrimusClaw \u8D26\u53F7\u3002\u6253\u5F00\u8FD9\u4E2A\u9875\u9762\uFF0C\u767B\u5F55\u540E\u9009\u62E9 Connect ${p.channel}\uFF1A
|
|
10456
|
-
|
|
10457
|
-
${p.page}
|
|
10458
|
-
|
|
10459
|
-
\u4F60\u4F1A\u62FF\u5230\u4E00\u4E2A\u77ED\u7801\uFF1B\u5728\u8FD9\u91CC\u53D1 \`/link CODE\`\uFF08CODE \u6362\u6210\u77ED\u7801\uFF0C10 \u5206\u949F\u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09\u3002`,
|
|
10460
|
-
platformDown: "I could not reach the Primus platform to check your connection. Please try again in a minute.",
|
|
10461
|
-
notConfirmedYet: "\u6211\u8FD8\u6CA1\u770B\u5230\u4F60\u7684\u786E\u8BA4\u3002",
|
|
10462
|
-
notConfirmedLine: "\u6211\u8FD8\u6CA1\u770B\u5230\u4F60\u7684\u786E\u8BA4\u3002\u6253\u5F00\u4E0A\u9762\u5361\u7247\u91CC\u7684\u94FE\u63A5\u786E\u8BA4\uFF0C\u7136\u540E\u518D\u6309\u4E00\u6B21\u6309\u94AE\u3002",
|
|
10463
|
-
platformUnreachable: "I could not reach the Primus platform. Please try again in a minute.",
|
|
10464
|
-
pressConfirmAgain: " Press Confirm again then.",
|
|
10465
|
-
connectTitle: (p) => `Connect ${p.bot}`,
|
|
10466
|
-
connected: "Connected. ",
|
|
10467
|
-
runningFromGroup: "\u6211\u73B0\u5728\u5728\u7FA4\u804A\u91CC\u8FD0\u884C\u4F60\u7684\u8BF7\u6C42\uFF0C\u7B54\u6848\u4F1A\u53D1\u5728\u90A3\u91CC\u3002",
|
|
10468
|
-
getStarted: "\u7ED9\u6211\u53D1\u6761\u6D88\u606F\u5C31\u5F00\u59CB\uFF0C\u6216\u8005\u53D1 /help \u770B\u6211\u80FD\u505A\u4EC0\u4E48\u3002",
|
|
10469
|
-
linkedAs: (p) => `\u5DF2\u8FDE\u63A5${p.who}\u3002\u5982\u679C\u4E0D\u662F\u4F60\uFF0C\u73B0\u5728\u53D1 /unlink\u3002
|
|
10470
|
-
|
|
10471
|
-
`,
|
|
10472
|
-
tooManyWrong: (p) => `Too many wrong codes. Wait ${String(p.minutes)} minute${p.minutes !== 1 ? "s" : ""} and try again.`,
|
|
10473
|
-
linkingPaused: "Linking is paused for a few minutes because of too many wrong codes. Please try again later.",
|
|
10474
|
-
badCode: "That code is not valid or has expired. Get a new one on the console page.",
|
|
10475
|
-
identityRefused: "\u8FD9\u4E00\u6B65\u9700\u8981\u4F60\u672C\u4EBA\uFF1A\u5728\u8FD9\u5F20\u5361\u7247\u4E0A\u786E\u8BA4\u4E00\u6B21\u8EAB\u4EFD\uFF0C\u7136\u540E\u518D\u8BF4\u4E00\u904D\u5C31\u884C\u3002"
|
|
10476
|
-
}
|
|
10477
|
-
});
|
|
10478
|
-
function linkPage(publicBaseUrl, channel) {
|
|
10479
|
-
return `${publicBaseUrl}/primus-claw/${channel}-link`;
|
|
10480
|
-
}
|
|
10481
|
-
function linkKeyName(shortName2) {
|
|
10482
|
-
return `PrimusClaw ${shortName2}`;
|
|
10483
|
-
}
|
|
10484
|
-
var unlinkText = defineCatalog({
|
|
10485
|
-
en: {
|
|
10486
|
-
bindingOnly: "This chat acts as you through a SaFE identity binding, which only you can remove: delete it in SaFE under identity bindings. Until then I keep working for you.",
|
|
10487
|
-
deleted: "The API key was deleted.",
|
|
10488
|
-
notDeleted: (p) => `I could not delete the API key named "${p.key}"; please delete it in SaFE under API keys.`,
|
|
10489
|
-
stillBound: " This chat is still connected through a SaFE identity binding, which only you can remove: delete it in SaFE under identity bindings.",
|
|
10490
|
-
unlinked: (p) => `Unlinked. ${p.tail}`
|
|
10491
|
-
},
|
|
10492
|
-
zh: {
|
|
10493
|
-
bindingOnly: "\u8FD9\u4E2A\u804A\u5929\u901A\u8FC7 SaFE \u8EAB\u4EFD\u7ED1\u5B9A\u4EE5\u4F60\u7684\u8EAB\u4EFD\u5DE5\u4F5C\uFF0C\u53EA\u6709\u4F60\u80FD\u5220\u9664\u8FD9\u4E2A\u7ED1\u5B9A\uFF1A\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u3002\u5220\u9664\u4E4B\u524D\u6211\u4F1A\u7EE7\u7EED\u4E3A\u4F60\u5DE5\u4F5C\u3002",
|
|
10494
|
-
deleted: "API key \u5DF2\u5220\u9664\u3002",
|
|
10495
|
-
notDeleted: (p) => `\u6211\u6CA1\u80FD\u5220\u9664 API key "${p.key}"; \u8BF7\u5728 SaFE \u7684 API keys \u91CC\u5220\u9664\u3002`,
|
|
10496
|
-
stillBound: "\u8FD9\u4E2A\u804A\u5929\u4ECD\u901A\u8FC7 SaFE \u8EAB\u4EFD\u7ED1\u5B9A\u8FDE\u7740\uFF0C\u53EA\u6709\u4F60\u80FD\u5220\u9664\u5B83\uFF1A\u5728 SaFE \u7684\u8EAB\u4EFD\u7ED1\u5B9A\u91CC\u5220\u9664\u3002",
|
|
10497
|
-
unlinked: (p) => `\u5DF2\u65AD\u5F00\u3002${p.tail}`
|
|
10498
|
-
}
|
|
10499
|
-
});
|
|
10500
|
-
|
|
10501
10605
|
// packages/core/src/locales/routing.ts
|
|
10502
10606
|
var routingText = defineCatalog({
|
|
10503
10607
|
en: {
|
|
@@ -10550,6 +10654,8 @@ var CredentialUnavailable = class extends Error {
|
|
|
10550
10654
|
};
|
|
10551
10655
|
var IDENTITY_CARD_INTERVAL_SECONDS = 24 * 3600;
|
|
10552
10656
|
var IDENTITY_CARD_NOTICE = "identity_card";
|
|
10657
|
+
var FALLBACK_CARD_INTERVAL_SECONDS = 365 * 24 * 3600;
|
|
10658
|
+
var FALLBACK_CARD_NOTICE = "identity_card_fallback";
|
|
10553
10659
|
function chatCredentialOf(links2, exchange) {
|
|
10554
10660
|
return async (sender) => {
|
|
10555
10661
|
const key = links2.getKey(sender.id) ?? void 0;
|
|
@@ -10599,17 +10705,32 @@ var Credentials = class {
|
|
|
10599
10705
|
* before such an answer: connecting a machine and the rest of what a key may do are not held behind it.
|
|
10600
10706
|
*/
|
|
10601
10707
|
async identityAfterRefusal(chat) {
|
|
10708
|
+
return this.identityOnce(chat, IDENTITY_CARD_NOTICE, IDENTITY_CARD_INTERVAL_SECONDS, "identityRefused");
|
|
10709
|
+
}
|
|
10710
|
+
/**
|
|
10711
|
+
* After a message of a person the assistant is set to read first, which it could not take now and which went the ordinary way
|
|
10712
|
+
* instead: the card that confirms their identity, with a line that says what happened, once (`FALLBACK_CARD_INTERVAL_SECONDS`;
|
|
10713
|
+
* kept in the store, as `identityAfterRefusal`'s is). Only where confirming adds something: chats run on the exchange and the
|
|
10714
|
+
* person has not confirmed. Nothing otherwise (a person with no key is asked to bind by `credential`, which this card must not
|
|
10715
|
+
* double), and a card that was not sent leaves the allowance unspent.
|
|
10716
|
+
*/
|
|
10717
|
+
async identityAfterFallback(chat) {
|
|
10718
|
+
if (this.deps.store.links.getKey(chat.sender.id) === null) return false;
|
|
10719
|
+
return this.identityOnce(chat, FALLBACK_CARD_NOTICE, FALLBACK_CARD_INTERVAL_SECONDS, "identityFallback");
|
|
10720
|
+
}
|
|
10721
|
+
/** The binding card with the catalog's line `lead`, at most once per `interval` seconds, only to a person who has not confirmed. */
|
|
10722
|
+
async identityOnce(chat, kind, interval, lead) {
|
|
10602
10723
|
if (this.chatExchange === void 0) return false;
|
|
10603
10724
|
const token = await this.chatExchange.tokenFor(chat.sender.id);
|
|
10604
10725
|
if (token.ok || token.error.kind !== "not_bound") return false;
|
|
10605
10726
|
const notices = this.deps.store.reviewDelegation;
|
|
10606
10727
|
const userId = chat.sender.id;
|
|
10607
|
-
if (!notices.claimGithubNotice(userId,
|
|
10728
|
+
if (!notices.claimGithubNotice(userId, kind, interval)) return false;
|
|
10608
10729
|
let sent = false;
|
|
10609
10730
|
try {
|
|
10610
|
-
sent = await this.sendIdentityCard(chat, linkText.in(chat.lang())
|
|
10731
|
+
sent = await this.sendIdentityCard(chat, linkText.in(chat.lang())[lead]);
|
|
10611
10732
|
} finally {
|
|
10612
|
-
if (!sent) notices.releaseGithubNotice(userId,
|
|
10733
|
+
if (!sent) notices.releaseGithubNotice(userId, kind);
|
|
10613
10734
|
}
|
|
10614
10735
|
return sent;
|
|
10615
10736
|
}
|
|
@@ -13208,7 +13329,7 @@ var AccountCommands = class {
|
|
|
13208
13329
|
lead: lead.join("\n\n"),
|
|
13209
13330
|
bot: config.botName,
|
|
13210
13331
|
channel: chat.conversation.caps.name,
|
|
13211
|
-
understanding: assistant.understands(chat.sender.id),
|
|
13332
|
+
understanding: assistant.understands(chat.sender.id) && assistant.reachable(chat.sender.id),
|
|
13212
13333
|
...groupContext === void 0 ? {} : { groupContext }
|
|
13213
13334
|
})
|
|
13214
13335
|
);
|
|
@@ -14639,6 +14760,16 @@ var TurnStarter = class {
|
|
|
14639
14760
|
repo: chosen === null ? null : { url: `${REPO_HOST}/${chosen.repo}`, branch: chosen.branch }
|
|
14640
14761
|
};
|
|
14641
14762
|
}
|
|
14763
|
+
/**
|
|
14764
|
+
* The person's linked key, for a chat turn that runs on their exchanged token: it goes beside the token, as it does on the
|
|
14765
|
+
* assistant's path and for a review, because a service's token alone carries no key where the identity service verifies callers.
|
|
14766
|
+
* Nothing for a review (its own), for a person with no linked key, and for a credential that is the key itself.
|
|
14767
|
+
*/
|
|
14768
|
+
modelKeyOf(request) {
|
|
14769
|
+
if (request.review !== void 0 || isApiKey(request.credential)) return {};
|
|
14770
|
+
const linked = this.ctx.deps.store.links.getKey(request.chat.sender.id);
|
|
14771
|
+
return linked === null || linked === "" ? {} : { modelKey: linked };
|
|
14772
|
+
}
|
|
14642
14773
|
async runOf(request) {
|
|
14643
14774
|
const { chat, review } = request;
|
|
14644
14775
|
const { store, config, logger } = this.ctx.deps;
|
|
@@ -14655,6 +14786,7 @@ var TurnStarter = class {
|
|
|
14655
14786
|
...session,
|
|
14656
14787
|
conversation: chat.conversation,
|
|
14657
14788
|
credential: request.credential,
|
|
14789
|
+
...this.modelKeyOf(request),
|
|
14658
14790
|
provider: this.providerOf(request),
|
|
14659
14791
|
text: request.text,
|
|
14660
14792
|
messageId: request.messageId,
|
|
@@ -14904,9 +15036,11 @@ var PersonalText = class {
|
|
|
14904
15036
|
const { assistant } = this.ctx.deps;
|
|
14905
15037
|
const userId = chat.sender.id;
|
|
14906
15038
|
if (assistant.on(userId) && await this.ctx.admission.assistantOverLimit(chat, message.id, key)) return;
|
|
15039
|
+
const linked = isApiKey(key) ? null : this.ctx.deps.store.links.getKey(userId);
|
|
14907
15040
|
const routed = await assistant.route({
|
|
14908
15041
|
userId,
|
|
14909
15042
|
credential: key,
|
|
15043
|
+
...linked === null || linked === "" ? {} : { modelKey: linked },
|
|
14910
15044
|
prompt: said2.prompt || assistant.filesOnly(chat.lang()),
|
|
14911
15045
|
conversation: chat.conversation,
|
|
14912
15046
|
files: said2.files,
|
|
@@ -15229,20 +15363,46 @@ var PersonalRouter = class {
|
|
|
15229
15363
|
if (clawUserId !== void 0) links2.setClawUserId(userId, clawUserId);
|
|
15230
15364
|
}
|
|
15231
15365
|
async message(message, chat) {
|
|
15232
|
-
const {
|
|
15366
|
+
const { remote } = this.ctx.deps;
|
|
15233
15367
|
const userId = chat.sender.id;
|
|
15234
|
-
const understood =
|
|
15368
|
+
const { understood, unreached } = this.reading(userId);
|
|
15235
15369
|
const choice = message.choice === true;
|
|
15236
15370
|
const switching = understood && !choice && remote.enabled && switchCommand(message.text) !== null;
|
|
15237
15371
|
const forAssistant = understood && (choice || !exactCommand(message.text, { menuCommand, isKnownCommand })) && !switching;
|
|
15238
15372
|
const text9 = understood && !choice ? menuCommand(message.text) : this.text.textOf(message);
|
|
15239
15373
|
learnLang(this.ctx.deps.store, userId, message.text);
|
|
15374
|
+
if (unreached) await this.toldOnFallback(chat);
|
|
15240
15375
|
if (!choice && await this.beforeCredential(message, chat, text9, forAssistant)) return;
|
|
15241
15376
|
const key = await this.ctx.credentials.credential(chat, true);
|
|
15242
15377
|
if (key === void 0) return;
|
|
15243
15378
|
if (forAssistant && !this.text.talksToAgent(message)) await this.text.understand(message, chat, key);
|
|
15244
15379
|
else await this.text.onText(message, chat, key);
|
|
15245
15380
|
}
|
|
15381
|
+
/**
|
|
15382
|
+
* Whether the assistant reads this person's messages first now (`understood`), and whether it is set to but cannot be reached
|
|
15383
|
+
* (`unreached`). A person it cannot reach is read the ordinary way, as one who is not listed is (the rule layer, then the
|
|
15384
|
+
* assistant or a turn of Claw's), not told "cannot reach" and left with no turn.
|
|
15385
|
+
*/
|
|
15386
|
+
reading(userId) {
|
|
15387
|
+
const { assistant } = this.ctx.deps;
|
|
15388
|
+
const listed = assistant.understands(userId);
|
|
15389
|
+
const understood = listed && assistant.reachable(userId);
|
|
15390
|
+
return { understood, unreached: listed && !understood };
|
|
15391
|
+
}
|
|
15392
|
+
/**
|
|
15393
|
+
* A person the assistant is set to read first but cannot reach now, whose message goes the ordinary way: told once, where
|
|
15394
|
+
* confirming their identity would help, with the card that does it. A card that cannot be sent is logged and does not fail
|
|
15395
|
+
* their message.
|
|
15396
|
+
*/
|
|
15397
|
+
async toldOnFallback(chat) {
|
|
15398
|
+
const { logger } = this.ctx.deps;
|
|
15399
|
+
logger.info("the assistant cannot be reached for a person it reads first; the message goes the ordinary way");
|
|
15400
|
+
try {
|
|
15401
|
+
await this.ctx.credentials.identityAfterFallback(chat);
|
|
15402
|
+
} catch (error) {
|
|
15403
|
+
logger.warn("the card that confirms a person's identity could not be sent", { error: errorName(error) });
|
|
15404
|
+
}
|
|
15405
|
+
}
|
|
15246
15406
|
/** What a 1:1 message can do with no account: true when it was taken. */
|
|
15247
15407
|
async beforeCredential(message, chat, text9, forAssistant) {
|
|
15248
15408
|
const [first] = pySplit(text9);
|
|
@@ -16831,9 +16991,13 @@ var AssistantChat = class {
|
|
|
16831
16991
|
on(userId) {
|
|
16832
16992
|
return this.forUser(userId) && this.reachable(userId) && this.o.store.now() >= this.offUntil && !this.o.legacyTurn(userId);
|
|
16833
16993
|
}
|
|
16834
|
-
/**
|
|
16994
|
+
/**
|
|
16995
|
+
* Every 1:1 message of this person that is not an exact command goes to their assistant first: they are named, or the switch is
|
|
16996
|
+
* on for everybody, and the assistant is on for them. (Whether it can be reached now is `reachable`: the router reads that too,
|
|
16997
|
+
* and a person it cannot reach is read the ordinary way.)
|
|
16998
|
+
*/
|
|
16835
16999
|
understands(userId) {
|
|
16836
|
-
return this.o.understanding.has(userId.toLowerCase()) && this.forUser(userId);
|
|
17000
|
+
return (this.o.understandingAll === true || this.o.understanding.has(userId.toLowerCase())) && this.forUser(userId);
|
|
16837
17001
|
}
|
|
16838
17002
|
/** The assistant can answer this person: their subscription has its events and their Claw user id is known. */
|
|
16839
17003
|
reachable(userId) {
|
|
@@ -16867,7 +17031,8 @@ var AssistantChat = class {
|
|
|
16867
17031
|
}
|
|
16868
17032
|
/**
|
|
16869
17033
|
* A message of a person the assistant understands, with the chat's context. True when the assistant has it; otherwise the
|
|
16870
|
-
* person was told it could not be reached and nothing else was done with it.
|
|
17034
|
+
* person was told it could not be reached and nothing else was done with it. (The router reads a person the assistant cannot
|
|
17035
|
+
* reach the ordinary way and does not come here: this is for one that stopped being reachable since.)
|
|
16871
17036
|
*/
|
|
16872
17037
|
async understand(request) {
|
|
16873
17038
|
const notUnderstood = assistantChatText.in(request.lang).notUnderstood;
|
|
@@ -16899,7 +17064,12 @@ var AssistantChat = class {
|
|
|
16899
17064
|
const linkedKeyRefused = sent.error?.status === 401 || sent.error?.status === 403;
|
|
16900
17065
|
await this.notTaken(
|
|
16901
17066
|
request.conversation,
|
|
16902
|
-
|
|
17067
|
+
this.refusedAs(
|
|
17068
|
+
sent.error,
|
|
17069
|
+
request.conversation,
|
|
17070
|
+
request.lang,
|
|
17071
|
+
linkedKeyRefused && request.credential.startsWith("ak-") ? assistantChatText.in("en").rejected : notUnderstood
|
|
17072
|
+
)
|
|
16903
17073
|
);
|
|
16904
17074
|
return false;
|
|
16905
17075
|
}
|
|
@@ -16949,7 +17119,14 @@ var AssistantChat = class {
|
|
|
16949
17119
|
return false;
|
|
16950
17120
|
}
|
|
16951
17121
|
await request.conversation.send(
|
|
16952
|
-
text2(
|
|
17122
|
+
text2(
|
|
17123
|
+
this.refusedAs(
|
|
17124
|
+
refused3,
|
|
17125
|
+
request.conversation,
|
|
17126
|
+
this.langOf(request.userId, request.prompt),
|
|
17127
|
+
refused3 && (refused3.status === 401 || refused3.status === 403) ? t4.rejected : t4.unavailable
|
|
17128
|
+
)
|
|
17129
|
+
)
|
|
16953
17130
|
);
|
|
16954
17131
|
return true;
|
|
16955
17132
|
}
|
|
@@ -16970,6 +17147,7 @@ var AssistantChat = class {
|
|
|
16970
17147
|
};
|
|
16971
17148
|
await ready();
|
|
16972
17149
|
return this.o.claw.assistant.send(request.credential, sessionId, request.prompt, {
|
|
17150
|
+
...request.modelKey ? { modelKey: request.modelKey } : {},
|
|
16973
17151
|
...Object.keys(context2).length ? { context: context2 } : {},
|
|
16974
17152
|
...this.o.pluginId === void 0 ? {} : { plugin: this.o.pluginId }
|
|
16975
17153
|
});
|
|
@@ -16980,7 +17158,12 @@ var AssistantChat = class {
|
|
|
16980
17158
|
const refused3 = sent.error;
|
|
16981
17159
|
await this.notTaken(
|
|
16982
17160
|
request.conversation,
|
|
16983
|
-
|
|
17161
|
+
this.refusedAs(
|
|
17162
|
+
refused3,
|
|
17163
|
+
request.conversation,
|
|
17164
|
+
handing.lang,
|
|
17165
|
+
refused3 && (refused3.status === 401 || refused3.status === 403) ? t4.rejected : t4.unavailable
|
|
17166
|
+
)
|
|
16984
17167
|
);
|
|
16985
17168
|
}
|
|
16986
17169
|
return true;
|
|
@@ -17024,7 +17207,7 @@ var AssistantChat = class {
|
|
|
17024
17207
|
"the assistant did not take a message",
|
|
17025
17208
|
refused3 ? { status: refused3.status } : { error: errorName(error) }
|
|
17026
17209
|
);
|
|
17027
|
-
return { ok: false, error: refused3 ? { status: refused3.status } : void 0 };
|
|
17210
|
+
return { ok: false, error: refused3 ? { status: refused3.status, code: refused3.code } : void 0 };
|
|
17028
17211
|
} finally {
|
|
17029
17212
|
front?.abandon();
|
|
17030
17213
|
follower?.answers(messageId);
|
|
@@ -17098,6 +17281,17 @@ var AssistantChat = class {
|
|
|
17098
17281
|
}
|
|
17099
17282
|
};
|
|
17100
17283
|
}
|
|
17284
|
+
/**
|
|
17285
|
+
* What a person is told when Claw refused their message: when it holds no API key of theirs to run it with (403
|
|
17286
|
+
* `platform_key_required`, `claw-api/platform-key.ts`), which key and how to link one, since a retry cannot cure that and their
|
|
17287
|
+
* linked key was not rejected (they have none); otherwise `otherwise`.
|
|
17288
|
+
*/
|
|
17289
|
+
refusedAs(refused3, conversation, lang, otherwise) {
|
|
17290
|
+
const base = this.o.publicBaseUrl;
|
|
17291
|
+
if (base === void 0 || refused3?.status !== 403 || refused3.code !== PLATFORM_KEY_REQUIRED) return otherwise;
|
|
17292
|
+
const { channel, name } = conversation.caps;
|
|
17293
|
+
return keyNeededText.in(lang).keyNeeded({ page: linkPage(base, channel), channel: name });
|
|
17294
|
+
}
|
|
17101
17295
|
/** The message did not reach the assistant: said in the receipt's place when one is open (it closes it), else as a message. */
|
|
17102
17296
|
async notTaken(conversation, said2) {
|
|
17103
17297
|
const receipt = this.o.receipts.take(conversation.ref.id);
|
|
@@ -20137,6 +20331,8 @@ var remoteText = defineCatalog({
|
|
|
20137
20331
|
typedInTerminal: (p) => `\u{1F5A5} **Typed in the terminal:**
|
|
20138
20332
|
|
|
20139
20333
|
${p.quoted}`,
|
|
20334
|
+
/** What a message that showed a prompt typed in the terminal is changed to when the terminal took the prompt back and the chat cannot delete it. */
|
|
20335
|
+
typedTakenBack: "\u{1F5A5} _Taken back in the terminal._",
|
|
20140
20336
|
shareConnect: "Connect (the terminal keeps working)",
|
|
20141
20337
|
shareWatch: "Watch only (the terminal keeps working)",
|
|
20142
20338
|
shareNoteTyped: "Open in a terminal: once connected, what you send here is typed into that terminal, and its replies and what is typed there show up here; the terminal keeps working, and you can leave at any time",
|
|
@@ -20323,6 +20519,7 @@ It installs the connector, pairs the machine with you and keeps it running. I wi
|
|
|
20323
20519
|
typedInTerminal: (p) => `\u{1F5A5} **\u7EC8\u7AEF\u91CC\u8F93\u5165\uFF1A**
|
|
20324
20520
|
|
|
20325
20521
|
${p.quoted}`,
|
|
20522
|
+
typedTakenBack: "\u{1F5A5} _\u7EC8\u7AEF\u91CC\u5DF2\u64A4\u56DE\u3002_",
|
|
20326
20523
|
shareConnect: "\u8FDE\u4E0A\uFF08\u7EC8\u7AEF\u7167\u5E38\u7528\uFF09",
|
|
20327
20524
|
shareWatch: "\u53EA\u770B\uFF08\u7EC8\u7AEF\u7167\u5E38\u7528\uFF09",
|
|
20328
20525
|
shareNoteTyped: "\u7EC8\u7AEF\u91CC\u6B63\u5728\u7528\uFF1A\u8FDE\u4E0A\u540E\uFF0C\u4F60\u5728\u8FD9\u91CC\u53D1\u7684\u6D88\u606F\u4F1A\u4F5C\u4E3A\u8F93\u5165\u6253\u8FDB\u90A3\u4E2A\u7EC8\u7AEF\uFF0C\u56DE\u590D\u548C\u7EC8\u7AEF\u91CC\u6572\u7684\u5185\u5BB9\u90FD\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\uFF1B\u7EC8\u7AEF\u7167\u5E38\u7528\uFF0C\u968F\u65F6\u53EF\u4EE5\u65AD\u5F00",
|
|
@@ -28213,6 +28410,7 @@ __export(remote_exports, {
|
|
|
28213
28410
|
takesFiles: () => takesFiles,
|
|
28214
28411
|
terminalClosedLine: () => terminalClosedLine,
|
|
28215
28412
|
typedLine: () => typedLine,
|
|
28413
|
+
typedTakenBackLine: () => typedTakenBackLine,
|
|
28216
28414
|
typesInto: () => typesInto,
|
|
28217
28415
|
unattendedAllowed: () => unattendedAllowed,
|
|
28218
28416
|
unsolicitedParts: () => unsolicitedParts,
|
|
@@ -28862,6 +29060,8 @@ var NOTHING2 = Object.freeze({
|
|
|
28862
29060
|
queuedSeq: null,
|
|
28863
29061
|
queuedHeld: false,
|
|
28864
29062
|
typed: null,
|
|
29063
|
+
typedId: null,
|
|
29064
|
+
retracted: null,
|
|
28865
29065
|
terminal: null,
|
|
28866
29066
|
terminalMode: null,
|
|
28867
29067
|
acp: null
|
|
@@ -28961,9 +29161,18 @@ function unwrapPasted(text9) {
|
|
|
28961
29161
|
return `${at > 0 ? "\n" : ""}${inner}${end < all.length ? "\n" : ""}`;
|
|
28962
29162
|
});
|
|
28963
29163
|
}
|
|
29164
|
+
var MESSAGE_ID_MAX = 128;
|
|
29165
|
+
function messageIdOf2(payload) {
|
|
29166
|
+
const id = str7(update(payload)["messageId"]);
|
|
29167
|
+
return id !== "" && id.length <= MESSAGE_ID_MAX ? id : null;
|
|
29168
|
+
}
|
|
28964
29169
|
function typed(payload) {
|
|
28965
29170
|
const text9 = pyStrip(unwrapPasted(textOf7(payload)));
|
|
28966
|
-
return text9 && !NOT_TYPED.test(text9) ? remoteStep({ typed: text9 }) : NOTHING2;
|
|
29171
|
+
return text9 && !NOT_TYPED.test(text9) ? remoteStep({ typed: text9, typedId: messageIdOf2(payload) }) : NOTHING2;
|
|
29172
|
+
}
|
|
29173
|
+
function retracted(payload) {
|
|
29174
|
+
const id = messageIdOf2(payload);
|
|
29175
|
+
return id === null ? NOTHING2 : remoteStep({ retracted: id });
|
|
28967
29176
|
}
|
|
28968
29177
|
var TOOL_NAME = /^[A-Za-z][\w.-]{0,63}$/u;
|
|
28969
29178
|
function toolNameOf(u) {
|
|
@@ -29069,6 +29278,7 @@ var READERS = {
|
|
|
29069
29278
|
agent_message_chunk: chunk,
|
|
29070
29279
|
agent_thought_chunk: chunk,
|
|
29071
29280
|
user_message_chunk: typed,
|
|
29281
|
+
user_message_retracted: retracted,
|
|
29072
29282
|
tool_call: tool,
|
|
29073
29283
|
tool_call_update: tool,
|
|
29074
29284
|
plan: (payload) => remoteStep({ plan: planLine(payload) }),
|
|
@@ -29210,6 +29420,9 @@ function typedLine(text9, lang) {
|
|
|
29210
29420
|
const quoted = pySplitlines(shown3).slice(0, TYPED_LINES_MAX).map((line3) => pyStrip(line3) ? `> ${line3}` : ">").join("\n");
|
|
29211
29421
|
return remoteText.in(lang).typedInTerminal({ quoted });
|
|
29212
29422
|
}
|
|
29423
|
+
function typedTakenBackLine(lang) {
|
|
29424
|
+
return remoteText.in(lang).typedTakenBack;
|
|
29425
|
+
}
|
|
29213
29426
|
var WAIT_LINE_MAX_ZH = 6;
|
|
29214
29427
|
var WAIT_LINE_MAX_EN = 16;
|
|
29215
29428
|
var QUEUED_KEYS = /* @__PURE__ */ new Map([
|
|
@@ -31365,6 +31578,65 @@ function perPerson(guard) {
|
|
|
31365
31578
|
};
|
|
31366
31579
|
}
|
|
31367
31580
|
|
|
31581
|
+
// packages/core/src/remote/follow/echoes.ts
|
|
31582
|
+
var ECHOES_KEPT = 16;
|
|
31583
|
+
var TypedEchoes = class {
|
|
31584
|
+
posted = /* @__PURE__ */ new Map();
|
|
31585
|
+
/** Prompts the terminal took back before any message of theirs was recorded (a post that landed late may still be). */
|
|
31586
|
+
early = /* @__PURE__ */ new Set();
|
|
31587
|
+
/** `message` shows `prompt` (or one more block of it). */
|
|
31588
|
+
remember(prompt, message) {
|
|
31589
|
+
const shown3 = this.posted.get(prompt) ?? { messages: [], tries: this.early.delete(prompt) ? 0 : null };
|
|
31590
|
+
this.posted.delete(prompt);
|
|
31591
|
+
shown3.messages.push(message);
|
|
31592
|
+
this.posted.set(prompt, shown3);
|
|
31593
|
+
for (const oldest of this.posted.keys()) {
|
|
31594
|
+
if (this.posted.size <= ECHOES_KEPT) break;
|
|
31595
|
+
this.posted.delete(oldest);
|
|
31596
|
+
}
|
|
31597
|
+
}
|
|
31598
|
+
/** The messages that show `prompt`, oldest first; none when it was not shown (or was let go). */
|
|
31599
|
+
of(prompt) {
|
|
31600
|
+
return this.posted.get(prompt)?.messages ?? [];
|
|
31601
|
+
}
|
|
31602
|
+
/**
|
|
31603
|
+
* The terminal took `prompt` back: false when it was not shown (nothing to take away now). One whose post is still in flight (it
|
|
31604
|
+
* lands after the reader was cancelled) is remembered as taken back, so that its message goes as soon as it is recorded.
|
|
31605
|
+
*/
|
|
31606
|
+
takeBack(prompt) {
|
|
31607
|
+
const shown3 = this.posted.get(prompt);
|
|
31608
|
+
if (shown3 === void 0) {
|
|
31609
|
+
this.early.delete(prompt);
|
|
31610
|
+
this.early.add(prompt);
|
|
31611
|
+
for (const oldest of this.early) {
|
|
31612
|
+
if (this.early.size <= ECHOES_KEPT) break;
|
|
31613
|
+
this.early.delete(oldest);
|
|
31614
|
+
}
|
|
31615
|
+
return false;
|
|
31616
|
+
}
|
|
31617
|
+
shown3.tries ??= 0;
|
|
31618
|
+
return true;
|
|
31619
|
+
}
|
|
31620
|
+
/** The prompts the terminal took back whose messages are still to be taken away, with the tries each has had since the first. */
|
|
31621
|
+
pending() {
|
|
31622
|
+
const pending = /* @__PURE__ */ new Map();
|
|
31623
|
+
for (const [prompt, shown3] of this.posted) if (shown3.tries !== null) pending.set(prompt, shown3.tries);
|
|
31624
|
+
return pending;
|
|
31625
|
+
}
|
|
31626
|
+
/** Another try at `prompt` is made: counted. */
|
|
31627
|
+
tried(prompt) {
|
|
31628
|
+
const shown3 = this.posted.get(prompt);
|
|
31629
|
+
if (shown3?.tries != null) shown3.tries += 1;
|
|
31630
|
+
}
|
|
31631
|
+
/** `left` are the messages of `prompt` still to be taken away (a taking away that failed): none forgets the prompt. */
|
|
31632
|
+
settle(prompt, left) {
|
|
31633
|
+
const shown3 = this.posted.get(prompt);
|
|
31634
|
+
if (shown3 === void 0) return;
|
|
31635
|
+
if (left.length === 0) this.posted.delete(prompt);
|
|
31636
|
+
else shown3.messages = [...left];
|
|
31637
|
+
}
|
|
31638
|
+
};
|
|
31639
|
+
|
|
31368
31640
|
// packages/core/src/remote/chats.ts
|
|
31369
31641
|
var TYPED_PATHS_KEPT = 20;
|
|
31370
31642
|
var TYPED_PATH_SECONDS = 3600;
|
|
@@ -31399,6 +31671,8 @@ var ChatRegistry = class {
|
|
|
31399
31671
|
/** Whether the agent of the attached session can take over a conversation a terminal has open. */
|
|
31400
31672
|
agentTakeover = /* @__PURE__ */ new Map();
|
|
31401
31673
|
typed = /* @__PURE__ */ new Map();
|
|
31674
|
+
/** The messages that show what was typed at the terminal the chat shares, to take one away when the terminal takes its prompt back. */
|
|
31675
|
+
echoes = /* @__PURE__ */ new Map();
|
|
31402
31676
|
readOnly = /* @__PURE__ */ new Map();
|
|
31403
31677
|
readOnlyKnown = /* @__PURE__ */ new Map();
|
|
31404
31678
|
terminalInput = /* @__PURE__ */ new Map();
|
|
@@ -31515,6 +31789,12 @@ var ChatRegistry = class {
|
|
|
31515
31789
|
this.rowHinted.set(chatKey, sessionId);
|
|
31516
31790
|
return true;
|
|
31517
31791
|
}
|
|
31792
|
+
/** The chat's record of the messages that show prompts typed at its terminal. */
|
|
31793
|
+
echoesOf(chatKey) {
|
|
31794
|
+
const kept = this.echoes.get(chatKey) ?? new TypedEchoes();
|
|
31795
|
+
this.echoes.set(chatKey, kept);
|
|
31796
|
+
return kept;
|
|
31797
|
+
}
|
|
31518
31798
|
/** What is sent to the chat's session is typed into a terminal on the machine. */
|
|
31519
31799
|
typesIntoTerminal(chatKey, sessionId) {
|
|
31520
31800
|
return sessionId !== null && this.terminalInput.get(chatKey) === sessionId;
|
|
@@ -31551,6 +31831,7 @@ var ChatRegistry = class {
|
|
|
31551
31831
|
/** Everything known of a chat whose person unlinked (its session's reader is stopped by the caller). */
|
|
31552
31832
|
forget(chatKey) {
|
|
31553
31833
|
this.typed.delete(chatKey);
|
|
31834
|
+
this.echoes.delete(chatKey);
|
|
31554
31835
|
this.agentUnattended.delete(chatKey);
|
|
31555
31836
|
this.readOnly.delete(chatKey);
|
|
31556
31837
|
this.readOnlyKnown.delete(chatKey);
|
|
@@ -32649,12 +32930,65 @@ var WATCH_TIMINGS = {
|
|
|
32649
32930
|
};
|
|
32650
32931
|
var RECONNECT_MAX_MS = 6e4;
|
|
32651
32932
|
var RETRY_MS = 15e3;
|
|
32933
|
+
var RETRACT_RETRY_MS = 2e3;
|
|
32652
32934
|
var STOP_WAIT_MS = 15e3;
|
|
32653
32935
|
var CURSOR_EVERY = 25;
|
|
32654
32936
|
function reconnectDelayMs(timings, failures) {
|
|
32655
32937
|
return Math.min(RECONNECT_MAX_MS, timings.reconnectMs * 2 ** Math.min(failures, 8));
|
|
32656
32938
|
}
|
|
32657
32939
|
|
|
32940
|
+
// packages/core/src/remote/follow/retract.ts
|
|
32941
|
+
var RETRACT_TRIES = 3;
|
|
32942
|
+
var RETRACT_DRAINS = 5;
|
|
32943
|
+
function unlessCutOff(work, signal) {
|
|
32944
|
+
if (signal === void 0) return work;
|
|
32945
|
+
if (signal.aborted) return Promise.reject(new Error("cut off"));
|
|
32946
|
+
return new Promise((resolve, reject) => {
|
|
32947
|
+
const onAbort = () => {
|
|
32948
|
+
reject(new Error("cut off"));
|
|
32949
|
+
};
|
|
32950
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
32951
|
+
work.then(resolve, reject).finally(() => {
|
|
32952
|
+
signal.removeEventListener("abort", onAbort);
|
|
32953
|
+
});
|
|
32954
|
+
});
|
|
32955
|
+
}
|
|
32956
|
+
async function takeAway(to, message, tries, cx) {
|
|
32957
|
+
for (let attempt = 0; attempt < tries; attempt += 1) {
|
|
32958
|
+
if (attempt > 0) {
|
|
32959
|
+
try {
|
|
32960
|
+
await unlessCutOff(cx.clock.sleep((cx.retryMs ?? RETRACT_RETRY_MS) * attempt), cx.cutOff);
|
|
32961
|
+
} catch {
|
|
32962
|
+
return false;
|
|
32963
|
+
}
|
|
32964
|
+
}
|
|
32965
|
+
try {
|
|
32966
|
+
if ((await unlessCutOff(to.delete(message), cx.cutOff)).ok) return true;
|
|
32967
|
+
await unlessCutOff(to.update(message, richMessage(typedTakenBackLine(cx.lang()))), cx.cutOff);
|
|
32968
|
+
return true;
|
|
32969
|
+
} catch (error) {
|
|
32970
|
+
cx.logger.warn("a prompt the terminal took back could not be taken away", { error: errorName(error) });
|
|
32971
|
+
}
|
|
32972
|
+
}
|
|
32973
|
+
return false;
|
|
32974
|
+
}
|
|
32975
|
+
async function takeAwayAll(echoes, prompt, to, tries, cx) {
|
|
32976
|
+
const left = [];
|
|
32977
|
+
for (const message of echoes.of(prompt)) if (!await takeAway(to, message, tries, cx)) left.push(message);
|
|
32978
|
+
echoes.settle(prompt, left);
|
|
32979
|
+
}
|
|
32980
|
+
async function drainTakenBack(echoes, to, cx) {
|
|
32981
|
+
for (const [prompt, tries] of echoes.pending()) {
|
|
32982
|
+
if (tries >= RETRACT_DRAINS) {
|
|
32983
|
+
cx.logger.warn("a prompt the terminal took back could not be taken away: given up");
|
|
32984
|
+
echoes.settle(prompt, []);
|
|
32985
|
+
} else {
|
|
32986
|
+
echoes.tried(prompt);
|
|
32987
|
+
await takeAwayAll(echoes, prompt, to, 1, cx);
|
|
32988
|
+
}
|
|
32989
|
+
}
|
|
32990
|
+
}
|
|
32991
|
+
|
|
32658
32992
|
// packages/core/src/remote/follow/speaker.ts
|
|
32659
32993
|
var BurstSpeaker = class {
|
|
32660
32994
|
// the id of the last event while text waits: what a hold of it is known by
|
|
@@ -32873,18 +33207,51 @@ var BurstSpeaker = class {
|
|
|
32873
33207
|
this.deps.logger.warn("the permission card of a remote agent could not be shown", { error: errorName(error) });
|
|
32874
33208
|
}
|
|
32875
33209
|
}
|
|
32876
|
-
/**
|
|
32877
|
-
|
|
33210
|
+
/**
|
|
33211
|
+
* A prompt typed at the terminal the chat shares: one message, so the reply that follows reads as its answer. `id`: what the
|
|
33212
|
+
* terminal's conversation calls the prompt; the message is kept under it so that `retract` can take it away.
|
|
33213
|
+
*/
|
|
33214
|
+
async typed(text9, id = null) {
|
|
32878
33215
|
const to = this.reachable(true);
|
|
32879
33216
|
if (to !== null) {
|
|
32880
|
-
|
|
32881
|
-
|
|
32882
|
-
|
|
32883
|
-
|
|
32884
|
-
);
|
|
33217
|
+
const message = richMessage(typedLine(text9, this.langOr("en")));
|
|
33218
|
+
const failed3 = "a prompt typed at the terminal could not be shown";
|
|
33219
|
+
if (id !== null && to.caps.messageIds && to.caps.delete) await this.tellAs(to, message, id, failed3);
|
|
33220
|
+
else await this.tell(to, message, failed3);
|
|
32885
33221
|
}
|
|
32886
33222
|
this.typedTurn = true;
|
|
32887
33223
|
}
|
|
33224
|
+
/**
|
|
33225
|
+
* The terminal took a prompt back (Claude Code put the text into its box again and the person sent another): the messages that
|
|
33226
|
+
* showed it go, so the chat shows what the terminal shows. Each is deleted; when the chat cannot delete it, it is edited down to a
|
|
33227
|
+
* line saying so; a refusal is tried again a few times at once. A message that stays (every try failed, the chat was out of reach)
|
|
33228
|
+
* is tried again at each of the next events of the session, a few times (`drainRetractions`). Nothing when the prompt was not shown
|
|
33229
|
+
* (the person could not be woken then, or the worker restarted since), and no one is woken by a message going.
|
|
33230
|
+
*/
|
|
33231
|
+
async retract(id) {
|
|
33232
|
+
if (!this.deps.echoes.takeBack(id)) return;
|
|
33233
|
+
const state = this.deps.remoteState.attachedRemote(this.chatKey);
|
|
33234
|
+
const reference = this.deps.references.getReference(this.chatKey);
|
|
33235
|
+
if (state === null || reference === null) return;
|
|
33236
|
+
this.typedTurn = false;
|
|
33237
|
+
await takeAwayAll(this.deps.echoes, id, this.deps.conversationFor(reference), RETRACT_TRIES, this.retractContext());
|
|
33238
|
+
}
|
|
33239
|
+
/** The messages of the prompts that could not be taken away yet are tried again, once each, until a few events went by. */
|
|
33240
|
+
async drainRetractions() {
|
|
33241
|
+
if (this.deps.echoes.pending().size === 0) return;
|
|
33242
|
+
const reference = this.deps.references.getReference(this.chatKey);
|
|
33243
|
+
if (reference === null || this.deps.remoteState.attachedRemote(this.chatKey) === null) return;
|
|
33244
|
+
await drainTakenBack(this.deps.echoes, this.deps.conversationFor(reference), this.retractContext());
|
|
33245
|
+
}
|
|
33246
|
+
retractContext() {
|
|
33247
|
+
return {
|
|
33248
|
+
clock: this.deps.clock,
|
|
33249
|
+
logger: this.deps.logger,
|
|
33250
|
+
...this.deps.timings.retractRetryMs === void 0 ? {} : { retryMs: this.deps.timings.retractRetryMs },
|
|
33251
|
+
lang: () => this.langOr("en"),
|
|
33252
|
+
...this.cutOff === void 0 ? {} : { cutOff: this.cutOff }
|
|
33253
|
+
};
|
|
33254
|
+
}
|
|
32888
33255
|
/** The connector restarted and this session is back: one line, never to wake anyone. */
|
|
32889
33256
|
async recovered(interrupted, continuing) {
|
|
32890
33257
|
const to = this.reachable(false);
|
|
@@ -32933,20 +33300,26 @@ var BurstSpeaker = class {
|
|
|
32933
33300
|
this.deps.logger.warn(failed3, { error: errorName(error) });
|
|
32934
33301
|
}
|
|
32935
33302
|
}
|
|
32936
|
-
|
|
32937
|
-
|
|
32938
|
-
|
|
32939
|
-
|
|
32940
|
-
|
|
32941
|
-
|
|
32942
|
-
|
|
33303
|
+
/** `tell`, keeping the message's id under `prompt` so that it can be taken away later. */
|
|
33304
|
+
async tellAs(to, message, prompt, failed3) {
|
|
33305
|
+
const posting = to.post(message);
|
|
33306
|
+
const remember = (posted) => {
|
|
33307
|
+
if (!posted) return;
|
|
33308
|
+
this.deps.echoes.remember(prompt, posted);
|
|
33309
|
+
if (this.deps.echoes.pending().has(prompt)) {
|
|
33310
|
+
const { clock: clock2, logger, retryMs, lang } = this.retractContext();
|
|
33311
|
+
const unbound = { clock: clock2, logger, lang, ...retryMs === void 0 ? {} : { retryMs } };
|
|
33312
|
+
void takeAwayAll(this.deps.echoes, prompt, to, 1, unbound).catch(() => void 0);
|
|
33313
|
+
}
|
|
32943
33314
|
};
|
|
32944
|
-
|
|
32945
|
-
|
|
32946
|
-
|
|
32947
|
-
|
|
32948
|
-
|
|
32949
|
-
}
|
|
33315
|
+
try {
|
|
33316
|
+
remember(await unlessCutOff(posting, this.cutOff));
|
|
33317
|
+
} catch (error) {
|
|
33318
|
+
posting.then(remember, () => void 0);
|
|
33319
|
+
this.deps.logger.warn(failed3, { error: errorName(error) });
|
|
33320
|
+
}
|
|
33321
|
+
}
|
|
33322
|
+
};
|
|
32950
33323
|
|
|
32951
33324
|
// packages/core/src/remote/follow/follower.ts
|
|
32952
33325
|
var CredentialUnavailable2 = class extends Error {
|
|
@@ -33168,6 +33541,7 @@ var Follower = class {
|
|
|
33168
33541
|
const now = this.deps.clock.monotonicMs();
|
|
33169
33542
|
if (saysModes(step)) this.deps.remoteState.setRemoteModes(this.chatKey, this.sessionId, step);
|
|
33170
33543
|
if (step.closed !== null) {
|
|
33544
|
+
await this.speaker.drainRetractions();
|
|
33171
33545
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33172
33546
|
await this.speaker.ended(step.closed);
|
|
33173
33547
|
return false;
|
|
@@ -33201,12 +33575,14 @@ var Follower = class {
|
|
|
33201
33575
|
this.deps.permissions.closeRemotePermission(this.sessionId, actionId, "decided");
|
|
33202
33576
|
}
|
|
33203
33577
|
}
|
|
33204
|
-
/** What is said between two stretches of the agent's text: a prompt typed at the terminal, the connector coming back. */
|
|
33578
|
+
/** What is said between two stretches of the agent's text: a prompt typed at the terminal (or taken back), the connector coming back. */
|
|
33205
33579
|
async sayBetween(step) {
|
|
33206
33580
|
if (step.typed) {
|
|
33207
33581
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33208
|
-
await this.speaker.typed(step.typed);
|
|
33582
|
+
await this.speaker.typed(step.typed, step.typedId);
|
|
33209
33583
|
}
|
|
33584
|
+
await this.speaker.drainRetractions();
|
|
33585
|
+
if (step.retracted !== null) await this.speaker.retract(step.retracted);
|
|
33210
33586
|
if (step.recovered !== null) {
|
|
33211
33587
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33212
33588
|
await this.speaker.recovered(step.recovered.interrupted, step.recovered.continuing);
|
|
@@ -33454,7 +33830,7 @@ function readyLine(state, lang, switched) {
|
|
|
33454
33830
|
}
|
|
33455
33831
|
|
|
33456
33832
|
// packages/core/src/remote/commands.ts
|
|
33457
|
-
function
|
|
33833
|
+
function refusalOf2(error, ctx, lang) {
|
|
33458
33834
|
if (error instanceof RemoteOff) return saidIn(lang, "notEnabled");
|
|
33459
33835
|
if (error instanceof ClawError) return failureText2(error, ctx.errors, ctx.clock.epochMs() / 1e3, lang);
|
|
33460
33836
|
if (isTransport2(error)) return saidIn(lang, "unreachable");
|
|
@@ -33482,7 +33858,7 @@ var AgentCommands = class {
|
|
|
33482
33858
|
try {
|
|
33483
33859
|
answer2 = await this.p.lists.agentsView(call.chatKey, call.key, this.lang(call), lead, machines);
|
|
33484
33860
|
} catch (error) {
|
|
33485
|
-
const said2 =
|
|
33861
|
+
const said2 = refusalOf2(error, this.p.ctx, this.lang(call));
|
|
33486
33862
|
if (said2 === null) throw error;
|
|
33487
33863
|
return this.say(call, said2);
|
|
33488
33864
|
}
|
|
@@ -33499,7 +33875,7 @@ var AgentCommands = class {
|
|
|
33499
33875
|
try {
|
|
33500
33876
|
await this.run(call, parsed.verb, parsed.rest);
|
|
33501
33877
|
} catch (error) {
|
|
33502
|
-
const said2 =
|
|
33878
|
+
const said2 = refusalOf2(error, this.p.ctx, this.lang(call));
|
|
33503
33879
|
if (said2 === null) throw error;
|
|
33504
33880
|
await this.say(call, said2);
|
|
33505
33881
|
}
|
|
@@ -33811,7 +34187,7 @@ var SessionClicks = class {
|
|
|
33811
34187
|
view7 = answer2.kind === "card" ? answer2.message : answer2.text;
|
|
33812
34188
|
}
|
|
33813
34189
|
} catch (error) {
|
|
33814
|
-
if (
|
|
34190
|
+
if (refusalOf2(error, this.p.ctx, this.lang(click)) === null) throw error;
|
|
33815
34191
|
await this.end(click, lead);
|
|
33816
34192
|
return;
|
|
33817
34193
|
}
|
|
@@ -33891,7 +34267,7 @@ var SessionClicks = class {
|
|
|
33891
34267
|
try {
|
|
33892
34268
|
answer2 = await this.p.lists.agentsView(click.chatKey, click.key, lang, lead);
|
|
33893
34269
|
} catch (error) {
|
|
33894
|
-
if (
|
|
34270
|
+
if (refusalOf2(error, this.p.ctx, lang) === null) throw error;
|
|
33895
34271
|
await this.end(click, lead, void 0, false);
|
|
33896
34272
|
return;
|
|
33897
34273
|
}
|
|
@@ -34073,6 +34449,7 @@ var FollowControl = class {
|
|
|
34073
34449
|
reach: this.ctx.reach,
|
|
34074
34450
|
remoteState: this.ctx.remoteState,
|
|
34075
34451
|
references: this.ctx.references,
|
|
34452
|
+
echoes: chats.echoesOf(chatKey),
|
|
34076
34453
|
permissions: this.ctx.permissions,
|
|
34077
34454
|
conversationFor: (reference) => this.ctx.conversationFor(reference),
|
|
34078
34455
|
showPermission: (key, sid, request, to) => this.hooks.showPermission(key, sid, request, to),
|
|
@@ -34134,6 +34511,9 @@ var FollowControl = class {
|
|
|
34134
34511
|
},
|
|
34135
34512
|
get stopWaitMs() {
|
|
34136
34513
|
return pick2().stopWaitMs ?? STOP_WAIT_MS;
|
|
34514
|
+
},
|
|
34515
|
+
get retractRetryMs() {
|
|
34516
|
+
return pick2().retractRetryMs ?? RETRACT_RETRY_MS;
|
|
34137
34517
|
}
|
|
34138
34518
|
};
|
|
34139
34519
|
}
|
|
@@ -35396,14 +35776,14 @@ var TurnRunner = class {
|
|
|
35396
35776
|
for await (const event of this.ctx.claw.stream(credential2, sid, reading.cursor || void 0, signal)) {
|
|
35397
35777
|
reading.came = true;
|
|
35398
35778
|
if (event.id) reading.cursor = event.id;
|
|
35399
|
-
await this.apply(request, fold.feed(event), display);
|
|
35779
|
+
await this.apply(request, fold.feed(event), display, signal);
|
|
35400
35780
|
reading.handled += 1;
|
|
35401
35781
|
if (event.id && reading.handled % CURSOR_EVERY2 === 0)
|
|
35402
35782
|
this.ctx.remoteState.setRemoteCursor(request.chatKey, sid, event.id);
|
|
35403
35783
|
if (isOver(fold)) break;
|
|
35404
35784
|
}
|
|
35405
35785
|
}
|
|
35406
|
-
async apply(request, step, display) {
|
|
35786
|
+
async apply(request, step, display, signal) {
|
|
35407
35787
|
if (step.replay) return;
|
|
35408
35788
|
const { chatKey, to } = request;
|
|
35409
35789
|
const sid = request.state.sessionId ?? "";
|
|
@@ -35413,7 +35793,7 @@ var TurnRunner = class {
|
|
|
35413
35793
|
}
|
|
35414
35794
|
if (step.queued !== null) await this.showWait(request, step, display);
|
|
35415
35795
|
else display.progress(step);
|
|
35416
|
-
|
|
35796
|
+
await this.terminalNotes(chatKey, sid, to, step, display, signal);
|
|
35417
35797
|
if (saysModes(step)) this.ctx.remoteState.setRemoteModes(chatKey, sid, step);
|
|
35418
35798
|
if (step.permission !== null) {
|
|
35419
35799
|
display.movedOn?.();
|
|
@@ -35424,6 +35804,31 @@ var TurnRunner = class {
|
|
|
35424
35804
|
await this.sayRecovered(chatKey, to, step.recovered.interrupted, step.recovered.continuing, display);
|
|
35425
35805
|
}
|
|
35426
35806
|
}
|
|
35807
|
+
/** What the terminal's own doing says to the chat while this turn reads the session: a prompt it took back, a registry row it cannot read. */
|
|
35808
|
+
async terminalNotes(chatKey, sid, to, step, display, signal) {
|
|
35809
|
+
await this.takeBackAgain(chatKey, to, signal);
|
|
35810
|
+
if (step.retracted !== null) await this.takeBack(chatKey, to, step.retracted, signal);
|
|
35811
|
+
if (step.rowUnreadable) await this.sayRowUnreadable(chatKey, sid, to, display);
|
|
35812
|
+
}
|
|
35813
|
+
/**
|
|
35814
|
+
* The terminal took back a prompt the chat showed (said while this turn reads the session, so the follower does not hear it): the
|
|
35815
|
+
* message that shows it goes now, in one try; what stays is tried again by the follower, at its next events.
|
|
35816
|
+
*/
|
|
35817
|
+
async takeBack(chatKey, to, prompt, signal) {
|
|
35818
|
+
const echoes = this.state.chats.echoesOf(chatKey);
|
|
35819
|
+
if (!echoes.takeBack(prompt)) return;
|
|
35820
|
+
await takeAwayAll(echoes, prompt, to, 1, this.retractContext(chatKey, signal));
|
|
35821
|
+
}
|
|
35822
|
+
/** One more try, at an event of the turn, at the messages of prompts the terminal took back that could not be taken away yet. */
|
|
35823
|
+
async takeBackAgain(chatKey, to, signal) {
|
|
35824
|
+
const echoes = this.state.chats.echoesOf(chatKey);
|
|
35825
|
+
if (echoes.pending().size === 0) return;
|
|
35826
|
+
await drainTakenBack(echoes, to, this.retractContext(chatKey, signal));
|
|
35827
|
+
}
|
|
35828
|
+
/** What taking a message away needs here: the turn being cancelled gives up what waits (the message stays kept for the follower). */
|
|
35829
|
+
retractContext(chatKey, cutOff) {
|
|
35830
|
+
return { clock: this.ctx.clock, logger: this.ctx.logger, lang: () => this.state.lang(chatKey), cutOff };
|
|
35831
|
+
}
|
|
35427
35832
|
/**
|
|
35428
35833
|
* This turn's message waits for the turn the terminal is running: the person is told at once, in the chat, once per message, and
|
|
35429
35834
|
* how to take it back (in the terminal when its own queue holds it; else /stop). A message queued behind a turn of this chat was
|
|
@@ -35976,7 +36381,7 @@ var RemoteAgents = class {
|
|
|
35976
36381
|
try {
|
|
35977
36382
|
await this.runOp(click, op);
|
|
35978
36383
|
} catch (error) {
|
|
35979
|
-
const said2 =
|
|
36384
|
+
const said2 = refusalOf2(error, this.ctx, lang);
|
|
35980
36385
|
if (said2 === null) throw error;
|
|
35981
36386
|
if (said2 === saidIn(lang, "notEnabled")) await click.settle(said2);
|
|
35982
36387
|
else await this.clicks.back(click, said2);
|
|
@@ -36199,6 +36604,8 @@ export {
|
|
|
36199
36604
|
EMAIL,
|
|
36200
36605
|
ENV_PREFIX,
|
|
36201
36606
|
EVENT_CLAIM_LEASE_SECONDS,
|
|
36607
|
+
FALLBACK_CARD_INTERVAL_SECONDS,
|
|
36608
|
+
FALLBACK_CARD_NOTICE,
|
|
36202
36609
|
FEEDBACK_ASK_TTL_SECONDS,
|
|
36203
36610
|
FEEDBACK_DEDUPE_SECONDS,
|
|
36204
36611
|
FEEDBACK_KEEP_SECONDS,
|
|
@@ -36258,6 +36665,8 @@ export {
|
|
|
36258
36665
|
MAX_TEXT_CHARS,
|
|
36259
36666
|
MENU_COMMANDS,
|
|
36260
36667
|
MODEL_ID,
|
|
36668
|
+
MODEL_KEY_INVALID,
|
|
36669
|
+
MODEL_KEY_MISSING,
|
|
36261
36670
|
MessageRateLimiter,
|
|
36262
36671
|
NAME_CHARS3 as NAME_CHARS,
|
|
36263
36672
|
NAME_MAX2 as NAME_MAX,
|
|
@@ -36295,6 +36704,7 @@ export {
|
|
|
36295
36704
|
PERSISTED_SECURITY_LOGGER,
|
|
36296
36705
|
PERSISTED_SHOWN_WHOLE,
|
|
36297
36706
|
PERSONAL_ONLY_COMMANDS,
|
|
36707
|
+
PLATFORM_KEY_REQUIRED,
|
|
36298
36708
|
PROCESSED_TTL_SECONDS,
|
|
36299
36709
|
PRUNE_EVERY,
|
|
36300
36710
|
PR_SHORT_SOURCE,
|
|
@@ -36402,6 +36812,7 @@ export {
|
|
|
36402
36812
|
TITLE_ID,
|
|
36403
36813
|
TOKEN,
|
|
36404
36814
|
TURN_DEADLINE_SECONDS2 as TURN_DEADLINE_SECONDS,
|
|
36815
|
+
TURN_FAILURE_REASON_FIELD,
|
|
36405
36816
|
TYPED_MODE_HINT,
|
|
36406
36817
|
TaskAdmission,
|
|
36407
36818
|
TerminalApprovalsCommand,
|
|
@@ -36590,6 +37001,9 @@ export {
|
|
|
36590
37001
|
messageContent,
|
|
36591
37002
|
modePrompt,
|
|
36592
37003
|
modelFieldPattern,
|
|
37004
|
+
modelKeyFailureCode,
|
|
37005
|
+
modelKeyRefusalOf,
|
|
37006
|
+
modelKeyRefusalOfCode,
|
|
36593
37007
|
monthName,
|
|
36594
37008
|
nameWords,
|
|
36595
37009
|
namedIn,
|