@txtcel/mcp 0.3.0 → 0.4.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/index.js +91 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3111,9 +3111,9 @@ var require_data = __commonJS({
|
|
|
3111
3111
|
}
|
|
3112
3112
|
});
|
|
3113
3113
|
|
|
3114
|
-
// node_modules/.pnpm/fast-uri@3.1.
|
|
3114
|
+
// node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/lib/utils.js
|
|
3115
3115
|
var require_utils = __commonJS({
|
|
3116
|
-
"node_modules/.pnpm/fast-uri@3.1.
|
|
3116
|
+
"node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/lib/utils.js"(exports, module) {
|
|
3117
3117
|
"use strict";
|
|
3118
3118
|
var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
|
|
3119
3119
|
var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
@@ -3424,9 +3424,9 @@ var require_utils = __commonJS({
|
|
|
3424
3424
|
}
|
|
3425
3425
|
});
|
|
3426
3426
|
|
|
3427
|
-
// node_modules/.pnpm/fast-uri@3.1.
|
|
3427
|
+
// node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/lib/schemes.js
|
|
3428
3428
|
var require_schemes = __commonJS({
|
|
3429
|
-
"node_modules/.pnpm/fast-uri@3.1.
|
|
3429
|
+
"node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/lib/schemes.js"(exports, module) {
|
|
3430
3430
|
"use strict";
|
|
3431
3431
|
var { isUUID } = require_utils();
|
|
3432
3432
|
var URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
|
|
@@ -3634,9 +3634,9 @@ var require_schemes = __commonJS({
|
|
|
3634
3634
|
}
|
|
3635
3635
|
});
|
|
3636
3636
|
|
|
3637
|
-
// node_modules/.pnpm/fast-uri@3.1.
|
|
3637
|
+
// node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/index.js
|
|
3638
3638
|
var require_fast_uri = __commonJS({
|
|
3639
|
-
"node_modules/.pnpm/fast-uri@3.1.
|
|
3639
|
+
"node_modules/.pnpm/fast-uri@3.1.3/node_modules/fast-uri/index.js"(exports, module) {
|
|
3640
3640
|
"use strict";
|
|
3641
3641
|
var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
|
|
3642
3642
|
var { SCHEMES, getSchemeHandler } = require_schemes();
|
|
@@ -3849,7 +3849,7 @@ var require_fast_uri = __commonJS({
|
|
|
3849
3849
|
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
|
|
3850
3850
|
if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
|
|
3851
3851
|
try {
|
|
3852
|
-
parsed.host = URL
|
|
3852
|
+
parsed.host = new URL("http://" + parsed.host).hostname;
|
|
3853
3853
|
} catch (e) {
|
|
3854
3854
|
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
|
|
3855
3855
|
}
|
|
@@ -6897,9 +6897,9 @@ var require_dist = __commonJS({
|
|
|
6897
6897
|
}
|
|
6898
6898
|
});
|
|
6899
6899
|
|
|
6900
|
-
// node_modules/.pnpm/bn.js@5.2.
|
|
6900
|
+
// node_modules/.pnpm/bn.js@5.2.4/node_modules/bn.js/lib/bn.js
|
|
6901
6901
|
var require_bn = __commonJS({
|
|
6902
|
-
"node_modules/.pnpm/bn.js@5.2.
|
|
6902
|
+
"node_modules/.pnpm/bn.js@5.2.4/node_modules/bn.js/lib/bn.js"(exports, module) {
|
|
6903
6903
|
"use strict";
|
|
6904
6904
|
(function(module2, exports2) {
|
|
6905
6905
|
"use strict";
|
|
@@ -7679,6 +7679,10 @@ var require_bn = __commonJS({
|
|
|
7679
7679
|
}
|
|
7680
7680
|
if (bitsLeft > 0) {
|
|
7681
7681
|
this.words[i] = ~this.words[i] & 67108863 >> 26 - bitsLeft;
|
|
7682
|
+
i++;
|
|
7683
|
+
}
|
|
7684
|
+
for (; i < this.length; i++) {
|
|
7685
|
+
this.words[i] = 0;
|
|
7682
7686
|
}
|
|
7683
7687
|
return this._strip();
|
|
7684
7688
|
};
|
|
@@ -12491,9 +12495,9 @@ var init_esm_node = __esm({
|
|
|
12491
12495
|
}
|
|
12492
12496
|
});
|
|
12493
12497
|
|
|
12494
|
-
// node_modules/.pnpm/jayson@4.3.0/node_modules/jayson/lib/generateRequest.js
|
|
12498
|
+
// node_modules/.pnpm/jayson@4.3.0_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/jayson/lib/generateRequest.js
|
|
12495
12499
|
var require_generateRequest = __commonJS({
|
|
12496
|
-
"node_modules/.pnpm/jayson@4.3.0/node_modules/jayson/lib/generateRequest.js"(exports, module) {
|
|
12500
|
+
"node_modules/.pnpm/jayson@4.3.0_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/jayson/lib/generateRequest.js"(exports, module) {
|
|
12497
12501
|
"use strict";
|
|
12498
12502
|
var uuid2 = (init_esm_node(), __toCommonJS(esm_node_exports)).v4;
|
|
12499
12503
|
var generateRequest = function(method, params, id, options) {
|
|
@@ -12535,9 +12539,9 @@ var require_generateRequest = __commonJS({
|
|
|
12535
12539
|
}
|
|
12536
12540
|
});
|
|
12537
12541
|
|
|
12538
|
-
// node_modules/.pnpm/jayson@4.3.0/node_modules/jayson/lib/client/browser/index.js
|
|
12542
|
+
// node_modules/.pnpm/jayson@4.3.0_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/jayson/lib/client/browser/index.js
|
|
12539
12543
|
var require_browser = __commonJS({
|
|
12540
|
-
"node_modules/.pnpm/jayson@4.3.0/node_modules/jayson/lib/client/browser/index.js"(exports, module) {
|
|
12544
|
+
"node_modules/.pnpm/jayson@4.3.0_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/jayson/lib/client/browser/index.js"(exports, module) {
|
|
12541
12545
|
"use strict";
|
|
12542
12546
|
var uuid2 = (init_esm_node(), __toCommonJS(esm_node_exports)).v4;
|
|
12543
12547
|
var generateRequest = require_generateRequest();
|
|
@@ -33498,7 +33502,7 @@ var StdioServerTransport = class {
|
|
|
33498
33502
|
}
|
|
33499
33503
|
};
|
|
33500
33504
|
|
|
33501
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
33505
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
33502
33506
|
import { Buffer as Buffer2 } from "buffer";
|
|
33503
33507
|
|
|
33504
33508
|
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/cryptoNode.js
|
|
@@ -35735,14 +35739,14 @@ _RistrettoPoint.ZERO = /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.
|
|
|
35735
35739
|
_RistrettoPoint.Fp = /* @__PURE__ */ (() => Fp)();
|
|
35736
35740
|
_RistrettoPoint.Fn = /* @__PURE__ */ (() => Fn)();
|
|
35737
35741
|
|
|
35738
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
35742
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
35739
35743
|
var import_bn = __toESM(require_bn());
|
|
35740
35744
|
var import_bs58 = __toESM(require_bs58());
|
|
35741
35745
|
|
|
35742
35746
|
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
|
|
35743
35747
|
var sha2562 = sha256;
|
|
35744
35748
|
|
|
35745
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
35749
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
35746
35750
|
var import_borsh = __toESM(require_lib());
|
|
35747
35751
|
var BufferLayout = __toESM(require_Layout());
|
|
35748
35752
|
var import_buffer_layout = __toESM(require_Layout());
|
|
@@ -36490,7 +36494,7 @@ var getU64Decoder = (config2 = {}) => numberDecoderFactory({
|
|
|
36490
36494
|
});
|
|
36491
36495
|
var getU64Codec = (config2 = {}) => combineCodec(getU64Encoder(config2), getU64Decoder(config2));
|
|
36492
36496
|
|
|
36493
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
36497
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
36494
36498
|
import require$$0 from "util";
|
|
36495
36499
|
import require$$0$1 from "http";
|
|
36496
36500
|
import require$$0$2, { Agent } from "https";
|
|
@@ -36907,7 +36911,7 @@ function coerce2(struct2, condition, coercer) {
|
|
|
36907
36911
|
});
|
|
36908
36912
|
}
|
|
36909
36913
|
|
|
36910
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
36914
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
36911
36915
|
var import_browser = __toESM(require_browser());
|
|
36912
36916
|
|
|
36913
36917
|
// node_modules/.pnpm/node-fetch@2.7.0/node_modules/node-fetch/lib/index.mjs
|
|
@@ -39795,7 +39799,7 @@ function sqrtMod(y) {
|
|
|
39795
39799
|
var Fpk1 = Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
|
|
39796
39800
|
var secp256k1 = createCurve({ ...secp256k1_CURVE, Fp: Fpk1, lowS: true, endo: secp256k1_ENDO }, sha256);
|
|
39797
39801
|
|
|
39798
|
-
// node_modules/.pnpm/@solana+web3.js@1.98.
|
|
39802
|
+
// node_modules/.pnpm/@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6/node_modules/@solana/web3.js/lib/index.esm.js
|
|
39799
39803
|
var generatePrivateKey = ed25519.utils.randomPrivateKey;
|
|
39800
39804
|
var generateKeypair = () => {
|
|
39801
39805
|
const privateScalar = ed25519.utils.randomPrivateKey();
|
|
@@ -47863,7 +47867,7 @@ function loadWallet() {
|
|
|
47863
47867
|
}
|
|
47864
47868
|
}
|
|
47865
47869
|
|
|
47866
|
-
// node_modules/.pnpm
|
|
47870
|
+
// node_modules/.pnpm/@txtcel+protocol@file+..+txtcel-protocol_@solana+web3.js@1.98.4_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_/node_modules/@txtcel/protocol/dist/index.js
|
|
47867
47871
|
var import_zorsh = __toESM(require_src2(), 1);
|
|
47868
47872
|
import { Buffer as Buffer3 } from "buffer";
|
|
47869
47873
|
var TAG_CONTENT = 1;
|
|
@@ -47879,7 +47883,7 @@ var ACCESS_DENIED = 1;
|
|
|
47879
47883
|
var ACCESS_FEE_EXEMPT = 2;
|
|
47880
47884
|
var KIND_TEXT = 0;
|
|
47881
47885
|
var CONTENT_SLOTS = 32;
|
|
47882
|
-
var EXTEND_THRESHOLD =
|
|
47886
|
+
var EXTEND_THRESHOLD = 24;
|
|
47883
47887
|
var MAX_BODY_LEN = 8192;
|
|
47884
47888
|
var MAX_TITLE_LEN = 64;
|
|
47885
47889
|
var INDEX_NONE = 4294967295;
|
|
@@ -47961,6 +47965,7 @@ var ThreadNodeSchema = import_zorsh.b.struct({
|
|
|
47961
47965
|
author: Pubkey,
|
|
47962
47966
|
messageFee: import_zorsh.b.u64(),
|
|
47963
47967
|
likeFee: import_zorsh.b.u64(),
|
|
47968
|
+
lastExtendSlot: import_zorsh.b.u64(),
|
|
47964
47969
|
title: import_zorsh.b.bytes()
|
|
47965
47970
|
});
|
|
47966
47971
|
var ProgramSettingsSchema = import_zorsh.b.struct({
|
|
@@ -48033,7 +48038,8 @@ var FillSlotInstr = import_zorsh.b.struct({
|
|
|
48033
48038
|
});
|
|
48034
48039
|
var PrepareAllocInstr = import_zorsh.b.struct({
|
|
48035
48040
|
tag: import_zorsh.b.u8(),
|
|
48036
|
-
allocSeq: import_zorsh.b.u32()
|
|
48041
|
+
allocSeq: import_zorsh.b.u32(),
|
|
48042
|
+
witnessSlots: import_zorsh.b.vec(import_zorsh.b.u8())
|
|
48037
48043
|
});
|
|
48038
48044
|
var InitThreadAccessInstr = import_zorsh.b.struct({
|
|
48039
48045
|
tag: import_zorsh.b.u8(),
|
|
@@ -48391,10 +48397,11 @@ function buildFillSlotInstruction(opts) {
|
|
|
48391
48397
|
}))
|
|
48392
48398
|
});
|
|
48393
48399
|
}
|
|
48394
|
-
function buildPrepareAllocInstruction(programId, payer, seed, allocSeq) {
|
|
48400
|
+
function buildPrepareAllocInstruction(programId, payer, seed, allocSeq, witnessSlots = []) {
|
|
48395
48401
|
const currentAllocPda = deriveAllocPda(programId, seed, allocSeq);
|
|
48396
48402
|
const newAllocPda = deriveAllocPda(programId, seed, allocSeq + 1);
|
|
48397
48403
|
const threadAccount = deriveThreadPda(programId, seed);
|
|
48404
|
+
const witnessMetas = witnessSlots.map((slot) => readonlyMeta(deriveContentPda(programId, seed, allocSeq, slot)));
|
|
48398
48405
|
return new TransactionInstruction({
|
|
48399
48406
|
programId,
|
|
48400
48407
|
keys: [
|
|
@@ -48402,11 +48409,13 @@ function buildPrepareAllocInstruction(programId, payer, seed, allocSeq) {
|
|
|
48402
48409
|
writableMeta(currentAllocPda),
|
|
48403
48410
|
writableMeta(newAllocPda),
|
|
48404
48411
|
writableMeta(threadAccount),
|
|
48405
|
-
readonlyMeta(SystemProgram.programId)
|
|
48412
|
+
readonlyMeta(SystemProgram.programId),
|
|
48413
|
+
...witnessMetas
|
|
48406
48414
|
],
|
|
48407
48415
|
data: Buffer3.from(PrepareAllocInstr.serialize({
|
|
48408
48416
|
tag: Instruction.PrepareAlloc,
|
|
48409
|
-
allocSeq
|
|
48417
|
+
allocSeq,
|
|
48418
|
+
witnessSlots: new Uint8Array(witnessSlots)
|
|
48410
48419
|
}))
|
|
48411
48420
|
});
|
|
48412
48421
|
}
|
|
@@ -48438,11 +48447,10 @@ var CANDIDATE_SIZE = 4 + 1;
|
|
|
48438
48447
|
var ACCOUNT_KEY_SIZE = 32;
|
|
48439
48448
|
var FILL_SLOT_BASE_ACCOUNTS = 6;
|
|
48440
48449
|
var FILL_SLOT_ACCESS_ACCOUNTS = 2;
|
|
48441
|
-
var PREPARE_ALLOC_MARGINAL_SIZE = 2 * ACCOUNT_KEY_SIZE + 1 + 1 + 5 + 1 + (1 + 4);
|
|
48442
48450
|
var CONTENT_NODE_FIXED_SIZE = 89;
|
|
48443
48451
|
var MAX_FEE_SLIPPAGE_NUM = 2n;
|
|
48444
48452
|
var APPEND_INSTR_ACCOUNTS = 7;
|
|
48445
|
-
var APPEND_TX_OVERHEAD = TX_OVERHEAD + 1 + (APPEND_INSTR_ACCOUNTS + 1) * ACCOUNT_KEY_SIZE + 1 + 1 + 1 + APPEND_INSTR_ACCOUNTS + 2 + 1 + 4 + 2 + 1;
|
|
48453
|
+
var APPEND_TX_OVERHEAD = TX_OVERHEAD + 1 + (APPEND_INSTR_ACCOUNTS + 1) * ACCOUNT_KEY_SIZE + 1 + 1 + 1 + APPEND_INSTR_ACCOUNTS + 2 + 1 + 4 + 2 + 1 + 8;
|
|
48446
48454
|
function ensureTextBytes(text) {
|
|
48447
48455
|
const bytes = new TextEncoder().encode(text);
|
|
48448
48456
|
if (bytes.length === 0) {
|
|
@@ -48482,6 +48490,10 @@ function pageCandidates(programId, seed, allocSeq) {
|
|
|
48482
48490
|
slot
|
|
48483
48491
|
}));
|
|
48484
48492
|
}
|
|
48493
|
+
function pickWitnessSlots(occupiedSlots) {
|
|
48494
|
+
if (occupiedSlots.length < EXTEND_THRESHOLD) return null;
|
|
48495
|
+
return shuffle(occupiedSlots).slice(0, EXTEND_THRESHOLD).sort((a, b2) => a - b2);
|
|
48496
|
+
}
|
|
48485
48497
|
async function buildSendMessageTransactions(connection, programId, payerKey, seed, text, replyTo) {
|
|
48486
48498
|
const textBytes = ensureTextBytes(text);
|
|
48487
48499
|
const threadPda = deriveThreadPda(programId, seed);
|
|
@@ -48492,10 +48504,9 @@ async function buildSendMessageTransactions(connection, programId, payerKey, see
|
|
|
48492
48504
|
const freeInWindow = windowCandidates.filter((_, i) => windowInfos[i] === null);
|
|
48493
48505
|
const treasuryShardIdx = randomTreasuryShard();
|
|
48494
48506
|
const authorFeeShardIdx = randomAuthorFeeShard();
|
|
48495
|
-
const
|
|
48496
|
-
const selected =
|
|
48497
|
-
const
|
|
48498
|
-
const maxFirst = maxFillSlotTextLen(selected.length, reserve);
|
|
48507
|
+
const extendFirst = freeInWindow.length === 0;
|
|
48508
|
+
const selected = extendFirst ? pageCandidates(programId, seed, lastAllocSeq + 1).slice(0, DESIRED_CANDIDATES) : shuffle(freeInWindow).slice(0, DESIRED_CANDIDATES);
|
|
48509
|
+
const maxFirst = maxFillSlotTextLen(selected.length);
|
|
48499
48510
|
const firstChunkLen = Math.min(textBytes.length, maxFirst);
|
|
48500
48511
|
const firstChunk = textBytes.subarray(0, firstChunkLen);
|
|
48501
48512
|
const settings = await loadProgramSettings(connection, programId);
|
|
@@ -48518,12 +48529,21 @@ async function buildSendMessageTransactions(connection, programId, payerKey, see
|
|
|
48518
48529
|
replyAllocSeq: replyTo?.allocSeq ?? null,
|
|
48519
48530
|
replySlot: replyTo?.slot ?? null
|
|
48520
48531
|
});
|
|
48521
|
-
const
|
|
48522
|
-
if (
|
|
48523
|
-
|
|
48532
|
+
const transactions = [];
|
|
48533
|
+
if (extendFirst) {
|
|
48534
|
+
const isAuthor = payerKey.toBase58() === thread.author;
|
|
48535
|
+
const occupiedTailSlots = windowCandidates.reduce((acc, candidate, index) => {
|
|
48536
|
+
if (candidate.allocSeq === lastAllocSeq && windowInfos[index] !== null) {
|
|
48537
|
+
acc.push(candidate.slot);
|
|
48538
|
+
}
|
|
48539
|
+
return acc;
|
|
48540
|
+
}, []);
|
|
48541
|
+
const witnessSlots = isAuthor ? [] : pickWitnessSlots(occupiedTailSlots) ?? [];
|
|
48542
|
+
transactions.push(
|
|
48543
|
+
new Transaction().add(buildPrepareAllocInstruction(programId, payerKey, seed, lastAllocSeq, witnessSlots))
|
|
48544
|
+
);
|
|
48524
48545
|
}
|
|
48525
|
-
|
|
48526
|
-
const transactions = [firstTx];
|
|
48546
|
+
transactions.push(new Transaction().add(fillSlotIx));
|
|
48527
48547
|
if (firstChunkLen < textBytes.length) {
|
|
48528
48548
|
const remaining = textBytes.subarray(firstChunkLen);
|
|
48529
48549
|
const appendMax = maxAppendChunkLen();
|
|
@@ -48562,10 +48582,18 @@ async function buildExtendAllocTransaction(connection, programId, payerKey, seed
|
|
|
48562
48582
|
const lastAllocSeq = thread.lastAllocSeq;
|
|
48563
48583
|
const tailCandidates = pageCandidates(programId, seed, lastAllocSeq);
|
|
48564
48584
|
const tailInfos = await connection.getMultipleAccountsInfo(tailCandidates.map((c) => c.pda));
|
|
48565
|
-
const
|
|
48566
|
-
|
|
48567
|
-
|
|
48568
|
-
|
|
48585
|
+
const occupiedTailSlots = tailCandidates.reduce((acc, candidate, index) => {
|
|
48586
|
+
if (tailInfos[index] !== null) {
|
|
48587
|
+
acc.push(candidate.slot);
|
|
48588
|
+
}
|
|
48589
|
+
return acc;
|
|
48590
|
+
}, []);
|
|
48591
|
+
const witnessSlots = pickWitnessSlots(occupiedTailSlots);
|
|
48592
|
+
if (witnessSlots === null) return null;
|
|
48593
|
+
const isAuthor = payerKey.toBase58() === thread.author;
|
|
48594
|
+
return new Transaction().add(
|
|
48595
|
+
buildPrepareAllocInstruction(programId, payerKey, seed, lastAllocSeq, isAuthor ? [] : witnessSlots)
|
|
48596
|
+
);
|
|
48569
48597
|
}
|
|
48570
48598
|
function buildCreateRootAllocInstruction(programId, payer, seed, messageFee = 0n, title = "") {
|
|
48571
48599
|
const titleBytes = new TextEncoder().encode(title);
|
|
@@ -49115,17 +49143,37 @@ function registerMessagingTools(server) {
|
|
|
49115
49143
|
"prepare_alloc",
|
|
49116
49144
|
{
|
|
49117
49145
|
title: "Prepare alloc",
|
|
49118
|
-
description: "Manually pre-create the next alloc page (allocSeq + 1) in a channel
|
|
49146
|
+
description: "Manually pre-create the next alloc page (allocSeq + 1) in a channel. Extension is occupancy-gated on-chain: unless the agent wallet is the channel author (or the last extension is older than the time hatch), the tail page must hold at least EXTEND_THRESHOLD messages \u2014 this tool gathers the witness proof automatically and fails with an explanation when occupancy is too low. Racy by design: it fails with InvalidAllocSeq if the chain tail moved on.",
|
|
49119
49147
|
inputSchema: {
|
|
49120
49148
|
channel: channelArg,
|
|
49121
49149
|
allocSeq: external_exports.number().int().describe("Current alloc seq to extend from.")
|
|
49122
49150
|
}
|
|
49123
49151
|
},
|
|
49124
49152
|
handler(async ({ channel, allocSeq }) => {
|
|
49125
|
-
const { programId } = loadConfig();
|
|
49153
|
+
const { connection, programId } = loadConfig();
|
|
49126
49154
|
const payer = loadWallet();
|
|
49127
49155
|
const seed = resolveSeed(channel);
|
|
49128
|
-
const
|
|
49156
|
+
const thread = await loadThreadNode(connection, programId, deriveThreadPda(programId, seed));
|
|
49157
|
+
const isAuthor = payer.publicKey.toBase58() === thread.author;
|
|
49158
|
+
let witnessSlots = [];
|
|
49159
|
+
if (!isAuthor) {
|
|
49160
|
+
const pdas = Array.from({ length: CONTENT_SLOTS }, (_, slot) => deriveContentPda(programId, seed, allocSeq, slot));
|
|
49161
|
+
const infos = await connection.getMultipleAccountsInfo(pdas);
|
|
49162
|
+
const occupied = infos.reduce((acc, info, slot) => {
|
|
49163
|
+
if (info !== null) acc.push(slot);
|
|
49164
|
+
return acc;
|
|
49165
|
+
}, []);
|
|
49166
|
+
if (occupied.length < EXTEND_THRESHOLD) {
|
|
49167
|
+
return jsonResult({
|
|
49168
|
+
error: "occupancy below extend threshold",
|
|
49169
|
+
occupied: occupied.length,
|
|
49170
|
+
required: EXTEND_THRESHOLD,
|
|
49171
|
+
hint: "Only the channel author (or the daily time hatch) can extend a page this empty."
|
|
49172
|
+
});
|
|
49173
|
+
}
|
|
49174
|
+
witnessSlots = occupied.slice(0, EXTEND_THRESHOLD);
|
|
49175
|
+
}
|
|
49176
|
+
const ix = buildPrepareAllocInstruction(programId, payer.publicKey, seed, allocSeq, witnessSlots);
|
|
49129
49177
|
const signature = await sendInstructions(payer, [ix]);
|
|
49130
49178
|
return jsonResult({ signature, explorer: explorerTx(signature) });
|
|
49131
49179
|
})
|