viveworker 0.5.5 → 0.6.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/README.md +178 -27
- package/package.json +7 -2
- package/scripts/a2a-cli.mjs +11 -6
- package/scripts/moltbook-api.mjs +319 -72
- package/scripts/share-cli.mjs +576 -0
- package/scripts/viveworker-bridge.mjs +61 -14
- package/scripts/viveworker.mjs +771 -130
- package/web/i18n.js +164 -6
|
@@ -18,7 +18,7 @@ import { generatePairingCredentials, shouldRotatePairing, upsertEnvText } from "
|
|
|
18
18
|
import { renderMarkdownHtml } from "./lib/markdown-render.mjs";
|
|
19
19
|
import { buildAgentCard, handleA2ARequest, resolveA2ATaskDecision, completeA2ATask, failA2ATask } from "./a2a-handler.mjs";
|
|
20
20
|
import { registerWithRelay, startRelayPolling, stopRelayPolling, postRelayResult, getRelayStatus, updatePublicTasksFlag } from "./a2a-relay-client.mjs";
|
|
21
|
-
import { createMoltbookClient, readScoutState, writeScoutState, rollScoutDayIfNeeded, markPostSeen, recordComposeAttempt, writeDraft, readDraft, deleteDraft, listPendingDrafts, solveVerificationPuzzle, solvePuzzleWithLLM, listInboxItems } from "./moltbook-api.mjs";
|
|
21
|
+
import { createMoltbookClient, readScoutState, writeScoutState, rollScoutDayIfNeeded, markPostSeen, recordComposeAttempt, writeDraft, readDraft, deleteDraft, listPendingDrafts, solveVerificationPuzzle, solvePuzzleWithLLM, recordPuzzleAttempt, listInboxItems } from "./moltbook-api.mjs";
|
|
22
22
|
|
|
23
23
|
const __filename = fileURLToPath(import.meta.url);
|
|
24
24
|
const __dirname = path.dirname(__filename);
|
|
@@ -15038,6 +15038,12 @@ async function executeMoltbookDraftPost(draft, config, runtime, state) {
|
|
|
15038
15038
|
const finalTitle = draft.decision.title || draft.postTitle;
|
|
15039
15039
|
|
|
15040
15040
|
let verification;
|
|
15041
|
+
// Captured so the post-verify history record knows which post/comment the
|
|
15042
|
+
// challenge_text was attached to. `draft.postId` only exists for replies;
|
|
15043
|
+
// for `original_post` drafts the id only shows up in the POST /posts
|
|
15044
|
+
// response.
|
|
15045
|
+
let createdPostId = null;
|
|
15046
|
+
let createdCommentId = null;
|
|
15041
15047
|
|
|
15042
15048
|
if (draft.draftType === "original_post") {
|
|
15043
15049
|
const result = await mb("/posts", {
|
|
@@ -15051,6 +15057,7 @@ async function executeMoltbookDraftPost(draft, config, runtime, state) {
|
|
|
15051
15057
|
});
|
|
15052
15058
|
const post = result?.post || null;
|
|
15053
15059
|
verification = post?.verification || null;
|
|
15060
|
+
createdPostId = post?.id || null;
|
|
15054
15061
|
console.log(`[moltbook-draft-post] Posted original post (id=${post?.id})`);
|
|
15055
15062
|
|
|
15056
15063
|
const scoutState = rollScoutDayIfNeeded(await readScoutState());
|
|
@@ -15066,6 +15073,8 @@ async function executeMoltbookDraftPost(draft, config, runtime, state) {
|
|
|
15066
15073
|
});
|
|
15067
15074
|
const comment = result?.comment || null;
|
|
15068
15075
|
verification = comment?.verification || null;
|
|
15076
|
+
createdPostId = draft.postId || null;
|
|
15077
|
+
createdCommentId = comment?.id || null;
|
|
15069
15078
|
console.log(`[moltbook-draft-post] Posted reply (commentId=${comment?.id}) to post ${draft.postId}`);
|
|
15070
15079
|
|
|
15071
15080
|
const scoutState = rollScoutDayIfNeeded(await readScoutState());
|
|
@@ -15080,41 +15089,79 @@ async function executeMoltbookDraftPost(draft, config, runtime, state) {
|
|
|
15080
15089
|
}
|
|
15081
15090
|
|
|
15082
15091
|
// Solve verification puzzle if present.
|
|
15092
|
+
//
|
|
15093
|
+
// Every attempt — success, server rejection, or complete failure — gets
|
|
15094
|
+
// recorded via `recordPuzzleAttempt` so we can build a corpus of
|
|
15095
|
+
// challenge_text at `~/.viveworker/moltbook-verify-history.jsonl`. This is
|
|
15096
|
+
// the only way to reconstruct failing puzzles; Moltbook only returns
|
|
15097
|
+
// `challenge_text` in the initial POST response.
|
|
15083
15098
|
if (verification) {
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15099
|
+
const solverAnswer = solveVerificationPuzzle(verification.challenge_text);
|
|
15100
|
+
let submittedAnswer = solverAnswer;
|
|
15101
|
+
let llmAnswer = null;
|
|
15102
|
+
let outcome = "unknown";
|
|
15103
|
+
let verifyError = null;
|
|
15104
|
+
|
|
15105
|
+
if (submittedAnswer == null) {
|
|
15106
|
+
llmAnswer = await solvePuzzleWithLLM(verification.challenge_text);
|
|
15107
|
+
submittedAnswer = llmAnswer;
|
|
15088
15108
|
}
|
|
15089
|
-
|
|
15109
|
+
|
|
15110
|
+
if (submittedAnswer != null) {
|
|
15090
15111
|
try {
|
|
15091
15112
|
await mb("/verify", {
|
|
15092
15113
|
method: "POST",
|
|
15093
|
-
body: JSON.stringify({ verification_code: verification.verification_code, answer }),
|
|
15114
|
+
body: JSON.stringify({ verification_code: verification.verification_code, answer: submittedAnswer }),
|
|
15094
15115
|
});
|
|
15095
|
-
console.log(`[moltbook-draft-verify] Verified with answer ${
|
|
15096
|
-
|
|
15116
|
+
console.log(`[moltbook-draft-verify] Verified with answer ${submittedAnswer}`);
|
|
15117
|
+
outcome = solverAnswer != null && llmAnswer == null ? "solver-verified" : "llm-verified";
|
|
15118
|
+
} catch (err) {
|
|
15119
|
+
verifyError = err.message;
|
|
15097
15120
|
// Wrong answer from solver — retry with LLM.
|
|
15098
|
-
if (/incorrect/i.test(
|
|
15099
|
-
|
|
15100
|
-
if (llmAnswer && llmAnswer !==
|
|
15121
|
+
if (/incorrect/i.test(err.message) && solverAnswer != null && llmAnswer == null) {
|
|
15122
|
+
llmAnswer = await solvePuzzleWithLLM(verification.challenge_text);
|
|
15123
|
+
if (llmAnswer && llmAnswer !== solverAnswer) {
|
|
15101
15124
|
try {
|
|
15102
15125
|
await mb("/verify", {
|
|
15103
15126
|
method: "POST",
|
|
15104
15127
|
body: JSON.stringify({ verification_code: verification.verification_code, answer: llmAnswer }),
|
|
15105
15128
|
});
|
|
15106
15129
|
console.log(`[moltbook-draft-verify] Verified with LLM retry answer ${llmAnswer}`);
|
|
15130
|
+
submittedAnswer = llmAnswer;
|
|
15131
|
+
verifyError = null;
|
|
15132
|
+
outcome = "solver-incorrect-llm-verified";
|
|
15107
15133
|
} catch (retryError) {
|
|
15108
15134
|
console.error(`[moltbook-draft-verify] LLM retry failed: ${retryError.message}`);
|
|
15135
|
+
verifyError = retryError.message;
|
|
15136
|
+
outcome = "both-incorrect";
|
|
15109
15137
|
}
|
|
15138
|
+
} else {
|
|
15139
|
+
outcome = "solver-incorrect-llm-agreed-or-null";
|
|
15110
15140
|
}
|
|
15111
15141
|
} else {
|
|
15112
|
-
console.error(`[moltbook-draft-verify] Failed: ${
|
|
15142
|
+
console.error(`[moltbook-draft-verify] Failed: ${err.message}`);
|
|
15143
|
+
outcome = solverAnswer != null ? "solver-rejected" : "llm-rejected";
|
|
15113
15144
|
}
|
|
15114
15145
|
}
|
|
15115
15146
|
} else {
|
|
15116
15147
|
console.error(`[moltbook-draft-verify] Could not solve puzzle for draft ${draft.token}`);
|
|
15117
|
-
|
|
15148
|
+
outcome = "both-failed-to-solve";
|
|
15149
|
+
}
|
|
15150
|
+
|
|
15151
|
+
// Best-effort corpus write. Never throws.
|
|
15152
|
+
await recordPuzzleAttempt({
|
|
15153
|
+
draftToken: draft.token,
|
|
15154
|
+
draftType: draft.draftType,
|
|
15155
|
+
postId: createdPostId,
|
|
15156
|
+
commentId: createdCommentId,
|
|
15157
|
+
challenge_text: verification.challenge_text,
|
|
15158
|
+
verification_code: verification.verification_code,
|
|
15159
|
+
solverAnswer,
|
|
15160
|
+
llmAnswer,
|
|
15161
|
+
submittedAnswer,
|
|
15162
|
+
outcome,
|
|
15163
|
+
verifyError,
|
|
15164
|
+
});
|
|
15118
15165
|
}
|
|
15119
15166
|
|
|
15120
15167
|
// Push notification for successful post.
|