@vapi-network/core 0.9.0 → 0.9.2
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/api-key.js.map +1 -1
- package/dist/backup.js.map +1 -1
- package/dist/call-contracts-wire.d.ts +48 -12
- package/dist/call-contracts-wire.d.ts.map +1 -1
- package/dist/call-contracts.d.ts +7 -1
- package/dist/call-contracts.d.ts.map +1 -1
- package/dist/cloud-backup.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1000 -957
- package/dist/index.js.map +3 -3
- package/dist/marketplace-contracts.d.ts +22 -10
- package/dist/marketplace-contracts.d.ts.map +1 -1
- package/dist/router-client.js +1 -1
- package/dist/router-client.js.map +1 -1
- package/dist/searches.d.ts +1 -0
- package/dist/searches.d.ts.map +1 -1
- package/dist/secrets.js.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/tasks/chain-error.d.ts.map +1 -1
- package/dist/tasks/chain-port.d.ts +2 -0
- package/dist/tasks/chain-port.d.ts.map +1 -1
- package/dist/tasks/chain.d.ts.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/index.d.ts +1 -0
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/operation-support.d.ts.map +1 -1
- package/dist/tasks/operations.d.ts +56 -1
- package/dist/tasks/operations.d.ts.map +1 -1
- package/dist/tasks/types.d.ts +5 -5
- package/dist/tasks/types.d.ts.map +1 -1
- package/dist/tasks/wait.d.ts +18 -0
- package/dist/tasks/wait.d.ts.map +1 -0
- package/dist/tasks.js +247 -45
- package/dist/tasks.js.map +3 -3
- package/dist/x402-networks.d.ts +1 -0
- package/dist/x402-networks.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/tasks.js
CHANGED
|
@@ -38100,6 +38100,7 @@ function guardError(url2) {
|
|
|
38100
38100
|
|
|
38101
38101
|
// src/tasks/types.ts
|
|
38102
38102
|
var uuidSchema = external_exports.uuid();
|
|
38103
|
+
var profileIdSchema = external_exports.string().min(1).max(64).regex(/^[A-Za-z0-9_-]+$/);
|
|
38103
38104
|
var isoDateTimeSchema = external_exports.iso.datetime();
|
|
38104
38105
|
var addressSchema2 = external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/).transform((value) => value.toLowerCase());
|
|
38105
38106
|
var bytes32Schema = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((value) => value.toLowerCase());
|
|
@@ -38437,7 +38438,7 @@ var deliveryResponseSchema = external_exports.looseObject({
|
|
|
38437
38438
|
version: external_exports.number().int().positive(),
|
|
38438
38439
|
manifest: manifestResponseSchema,
|
|
38439
38440
|
manifestHash: bytes32Schema,
|
|
38440
|
-
submittedByProfileId:
|
|
38441
|
+
submittedByProfileId: profileIdSchema,
|
|
38441
38442
|
createdAt: isoDateTimeSchema
|
|
38442
38443
|
});
|
|
38443
38444
|
var orderDeliveryResponseSchema = external_exports.looseObject({
|
|
@@ -38543,7 +38544,7 @@ var reviewResponseSchema = external_exports.looseObject({
|
|
|
38543
38544
|
id: uuidSchema,
|
|
38544
38545
|
workOrderId: uuidSchema,
|
|
38545
38546
|
clientAddress: addressSchema2,
|
|
38546
|
-
vendorProfileId:
|
|
38547
|
+
vendorProfileId: profileIdSchema,
|
|
38547
38548
|
rating: external_exports.number().int().min(1).max(5),
|
|
38548
38549
|
body: external_exports.string(),
|
|
38549
38550
|
subRatings: external_exports.json().nullable(),
|
|
@@ -39086,12 +39087,15 @@ function createTasksClient(options) {
|
|
|
39086
39087
|
const parsed2 = serverErrorSchema.safeParse(errorBody);
|
|
39087
39088
|
const server = parsed2.success ? parsed2.data : void 0;
|
|
39088
39089
|
const nested = typeof server?.error === "object" ? server.error : void 0;
|
|
39089
|
-
const
|
|
39090
|
+
const serverCode = nested?.code ?? server?.code;
|
|
39091
|
+
const serverMessage = (typeof server?.error === "string" ? server.error : nested?.message) || server?.message;
|
|
39092
|
+
const fallback = response.statusText || `HTTP ${response.status}`;
|
|
39093
|
+
const message = response.status === 401 || response.status === 403 ? serverCode ?? fallback : serverMessage || (errorBody === void 0 && raw.trim() ? raw.replace(/\s+/gu, " ").trim().slice(0, 300) : fallback);
|
|
39090
39094
|
throw new TasksClientError(
|
|
39091
39095
|
"http",
|
|
39092
39096
|
message,
|
|
39093
39097
|
response.status,
|
|
39094
|
-
|
|
39098
|
+
serverCode,
|
|
39095
39099
|
response.headers.get("Retry-After") ?? void 0
|
|
39096
39100
|
);
|
|
39097
39101
|
}
|
|
@@ -39494,9 +39498,10 @@ function safeTasksChainError(cause, broadcast, authorizationExposed, txHash) {
|
|
|
39494
39498
|
let message = "Task chain operation failed.";
|
|
39495
39499
|
if (cause instanceof TasksValidationError || cause instanceof TasksChainError)
|
|
39496
39500
|
message = cause.message;
|
|
39497
|
-
else if (cause instanceof TasksClientError)
|
|
39498
|
-
|
|
39499
|
-
|
|
39501
|
+
else if (cause instanceof TasksClientError) {
|
|
39502
|
+
const code = cause.serverCode ?? (cause.status ? `http_${cause.status}` : cause.code);
|
|
39503
|
+
message = cause.status === 401 || cause.status === 403 ? `${code} (status ${cause.status})` : `${code}: ${cause.message}`;
|
|
39504
|
+
} else if (cause instanceof Error) {
|
|
39500
39505
|
const short = "shortMessage" in cause && typeof cause.shortMessage === "string" ? cause.shortMessage : void 0;
|
|
39501
39506
|
let statusCode;
|
|
39502
39507
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -40463,6 +40468,44 @@ function createTasksChain(options) {
|
|
|
40463
40468
|
return idempotencyKey;
|
|
40464
40469
|
});
|
|
40465
40470
|
}
|
|
40471
|
+
async function prepareOrResume(prepare, expected, idempotencyKey, kind, steps, authorizationExposed = false, beforeSign) {
|
|
40472
|
+
let prepared;
|
|
40473
|
+
let resumedFromServer = false;
|
|
40474
|
+
try {
|
|
40475
|
+
prepared = await prepare();
|
|
40476
|
+
} catch (error61) {
|
|
40477
|
+
if (!uncertainPreparation(error61)) throw error61;
|
|
40478
|
+
const fresh = await order(expected.milestone.workOrderId);
|
|
40479
|
+
const matches = fresh.milestones.filter((item) => item.id === expected.milestone.id);
|
|
40480
|
+
if (matches.length !== 1 || matches[0].workOrderId !== fresh.id)
|
|
40481
|
+
throw new TasksValidationError("The task milestone does not match its parent order.");
|
|
40482
|
+
const selected = matches[0];
|
|
40483
|
+
const operation = selected.chainOperation;
|
|
40484
|
+
if (expected.verb === "deliver" && selected.delivery && !operation)
|
|
40485
|
+
throw new TasksValidationError(
|
|
40486
|
+
"The server recorded this delivery but has no chain operation for it; open the task in the console to continue."
|
|
40487
|
+
);
|
|
40488
|
+
if (!operation || operation.kind !== kind || !(typeof steps === "string" ? [steps] : steps).includes(operation.step) || !["prepared", "submitted", "confirmed"].includes(operation.state))
|
|
40489
|
+
throw error61;
|
|
40490
|
+
if (expected.verb === "deliver" && selected.delivery && selected.delivery.manifestHash !== expected.manifestHash)
|
|
40491
|
+
throw new TasksValidationError(
|
|
40492
|
+
"The server recorded a different delivery manifest; refusing to continue."
|
|
40493
|
+
);
|
|
40494
|
+
prepared = {
|
|
40495
|
+
operation,
|
|
40496
|
+
milestone: { id: selected.id, workOrderId: selected.workOrderId }
|
|
40497
|
+
};
|
|
40498
|
+
resumedFromServer = true;
|
|
40499
|
+
}
|
|
40500
|
+
const result = await execute(
|
|
40501
|
+
prepared,
|
|
40502
|
+
expected,
|
|
40503
|
+
idempotencyKey,
|
|
40504
|
+
authorizationExposed,
|
|
40505
|
+
beforeSign
|
|
40506
|
+
);
|
|
40507
|
+
return resumedFromServer ? { ...result, resumedFromServer: true } : result;
|
|
40508
|
+
}
|
|
40466
40509
|
async function verifyReceipt(operation, expected, hash5) {
|
|
40467
40510
|
const rpc = rpcFor(expected.deployment.chainId);
|
|
40468
40511
|
const receipt = await rpc.waitForTransactionReceipt({ hash: hash5, confirmations });
|
|
@@ -40504,6 +40547,7 @@ function createTasksChain(options) {
|
|
|
40504
40547
|
throw new TasksValidationError(
|
|
40505
40548
|
"The RPC transaction input does not match the verified task plan."
|
|
40506
40549
|
);
|
|
40550
|
+
return receipt.blockNumber.toString();
|
|
40507
40551
|
}
|
|
40508
40552
|
async function retryConflict(call2) {
|
|
40509
40553
|
let waited = 0;
|
|
@@ -40531,6 +40575,7 @@ function createTasksChain(options) {
|
|
|
40531
40575
|
current = { ...initial, operation: live };
|
|
40532
40576
|
let broadcast = current.operation.state === "submitted";
|
|
40533
40577
|
let txHash = current.operation.transactionHash ?? void 0;
|
|
40578
|
+
let blockNumber;
|
|
40534
40579
|
const operationId = initial.operation.id;
|
|
40535
40580
|
function checkTransition(previous, next) {
|
|
40536
40581
|
if (previous !== next && !(previous === "approve-usdc" && next === afterApproval))
|
|
@@ -40566,7 +40611,7 @@ function createTasksChain(options) {
|
|
|
40566
40611
|
if (!operation.transactionHash)
|
|
40567
40612
|
throw new TasksValidationError("The confirmed task operation has no transaction hash.");
|
|
40568
40613
|
if (!checkpoint) {
|
|
40569
|
-
await verifyReceipt(operation, expected, operation.transactionHash);
|
|
40614
|
+
blockNumber = await verifyReceipt(operation, expected, operation.transactionHash);
|
|
40570
40615
|
await pending.complete(operation.id, operation.step, current);
|
|
40571
40616
|
}
|
|
40572
40617
|
const fresh = await order(expected.milestone.workOrderId);
|
|
@@ -40575,7 +40620,12 @@ function createTasksChain(options) {
|
|
|
40575
40620
|
);
|
|
40576
40621
|
if (!resultMilestone)
|
|
40577
40622
|
throw new TasksValidationError("The reconciled task milestone is unavailable.");
|
|
40578
|
-
return {
|
|
40623
|
+
return {
|
|
40624
|
+
txHash: operation.transactionHash,
|
|
40625
|
+
operation,
|
|
40626
|
+
milestone: resultMilestone,
|
|
40627
|
+
blockNumber
|
|
40628
|
+
};
|
|
40579
40629
|
}
|
|
40580
40630
|
const rpc = rpcFor(expected.deployment.chainId);
|
|
40581
40631
|
if (operation.state === "prepared") {
|
|
@@ -40771,7 +40821,7 @@ function createTasksChain(options) {
|
|
|
40771
40821
|
}
|
|
40772
40822
|
if (operation.state !== "submitted" || !operation.transactionHash)
|
|
40773
40823
|
throw new TasksValidationError("The task operation has no submitted transaction.");
|
|
40774
|
-
await verifyReceipt(operation, expected, operation.transactionHash);
|
|
40824
|
+
blockNumber = await verifyReceipt(operation, expected, operation.transactionHash);
|
|
40775
40825
|
const reconciled = await retryConflict(
|
|
40776
40826
|
() => client.reconcileOperation(
|
|
40777
40827
|
operation.id,
|
|
@@ -40794,6 +40844,7 @@ function createTasksChain(options) {
|
|
|
40794
40844
|
if (reconciled.operation.state !== "confirmed" && !(operation.step === "approve-usdc" && reconciled.operation.state === "prepared" && reconciled.operation.step === afterApproval))
|
|
40795
40845
|
throw new TasksValidationError("The task transaction was not reconciled.");
|
|
40796
40846
|
await pending.complete(operation.id, operation.step, reconciled);
|
|
40847
|
+
if (reconciled.operation.step !== operation.step) blockNumber = void 0;
|
|
40797
40848
|
current = reconciled;
|
|
40798
40849
|
}
|
|
40799
40850
|
throw new TasksValidationError("The task operation exceeded its allowed step transitions.");
|
|
@@ -40828,14 +40879,16 @@ function createTasksChain(options) {
|
|
|
40828
40879
|
);
|
|
40829
40880
|
const prepareKey = await preparation(input2, verb, { evidenceHash: input2.evidenceHash });
|
|
40830
40881
|
const call2 = verb === "dispute" ? client.disputeEscrow.bind(client) : client.counterEvidenceEscrow.bind(client);
|
|
40831
|
-
return await
|
|
40832
|
-
|
|
40882
|
+
return await prepareOrResume(
|
|
40883
|
+
() => call2(
|
|
40833
40884
|
input2.escrowId,
|
|
40834
40885
|
{ evidenceHash: input2.evidenceHash },
|
|
40835
40886
|
{ idempotencyKey: prepareKey }
|
|
40836
40887
|
),
|
|
40837
40888
|
{ ...expected, evidenceHash: input2.evidenceHash },
|
|
40838
40889
|
prepareKey,
|
|
40890
|
+
verb === "dispute" ? "escrow-dispute" : "escrow-counter-evidence",
|
|
40891
|
+
expected.steps,
|
|
40839
40892
|
exposed,
|
|
40840
40893
|
input2.beforeSign
|
|
40841
40894
|
);
|
|
@@ -40855,11 +40908,34 @@ function createTasksChain(options) {
|
|
|
40855
40908
|
await options.bindings.put(binding);
|
|
40856
40909
|
},
|
|
40857
40910
|
createEscrow: (input2) => safe(async () => {
|
|
40858
|
-
|
|
40911
|
+
let workOrder = await order(input2.orderId);
|
|
40859
40912
|
const ready = await deployment();
|
|
40860
|
-
|
|
40861
|
-
|
|
40862
|
-
|
|
40913
|
+
let prepared;
|
|
40914
|
+
let resumedFromServer = false;
|
|
40915
|
+
try {
|
|
40916
|
+
prepared = await client.createEscrow(input2.orderId, {
|
|
40917
|
+
idempotencyKey: input2.idempotencyKey
|
|
40918
|
+
});
|
|
40919
|
+
} catch (error61) {
|
|
40920
|
+
if (!uncertainPreparation(error61)) throw error61;
|
|
40921
|
+
const fresh = await order(input2.orderId);
|
|
40922
|
+
const candidates = fresh.milestones.filter((item) => {
|
|
40923
|
+
const previous = workOrder.milestones.find((prior) => prior.id === item.id);
|
|
40924
|
+
const operation = item.chainOperation;
|
|
40925
|
+
return item.workOrderId === input2.orderId && previous && operation && operation.kind === "escrow-create" && operation.step === "create-escrow" && (previous.escrowState === null || previous.chainOperation?.id === operation.id);
|
|
40926
|
+
});
|
|
40927
|
+
if (candidates.length !== 1) throw error61;
|
|
40928
|
+
const selected2 = candidates[0];
|
|
40929
|
+
prepared = {
|
|
40930
|
+
operation: selected2.chainOperation,
|
|
40931
|
+
milestone: {
|
|
40932
|
+
id: selected2.id,
|
|
40933
|
+
workOrderId: selected2.workOrderId
|
|
40934
|
+
}
|
|
40935
|
+
};
|
|
40936
|
+
workOrder = fresh;
|
|
40937
|
+
resumedFromServer = true;
|
|
40938
|
+
}
|
|
40863
40939
|
const selected = workOrder.milestones.find((item) => item.id === prepared.milestone.id);
|
|
40864
40940
|
if (!selected || selected.workOrderId !== input2.orderId)
|
|
40865
40941
|
throw new TasksValidationError(
|
|
@@ -40869,11 +40945,12 @@ function createTasksChain(options) {
|
|
|
40869
40945
|
{ escrowId: selected.id, idempotencyKey: input2.idempotencyKey },
|
|
40870
40946
|
"createEscrow"
|
|
40871
40947
|
);
|
|
40872
|
-
|
|
40948
|
+
const result = await execute(
|
|
40873
40949
|
prepared,
|
|
40874
40950
|
await expectation(selected, ready, "createEscrow", ["create-escrow"], input2.counterparty),
|
|
40875
40951
|
prepareKey
|
|
40876
40952
|
);
|
|
40953
|
+
return resumedFromServer ? { ...result, resumedFromServer: true } : result;
|
|
40877
40954
|
}),
|
|
40878
40955
|
async fund(input2) {
|
|
40879
40956
|
let exposed = true;
|
|
@@ -40961,10 +41038,14 @@ function createTasksChain(options) {
|
|
|
40961
41038
|
}
|
|
40962
41039
|
exposed = true;
|
|
40963
41040
|
await pending.markExposure(selected.id);
|
|
40964
|
-
|
|
40965
|
-
idempotencyKey: prepareKey
|
|
40966
|
-
|
|
40967
|
-
|
|
41041
|
+
return await prepareOrResume(
|
|
41042
|
+
() => client.fundEscrow(input2.escrowId, body, { idempotencyKey: prepareKey }),
|
|
41043
|
+
expected,
|
|
41044
|
+
prepareKey,
|
|
41045
|
+
"escrow-funding",
|
|
41046
|
+
expected.steps,
|
|
41047
|
+
exposed
|
|
41048
|
+
);
|
|
40968
41049
|
} catch (cause) {
|
|
40969
41050
|
throw chainError(cause, false, exposed);
|
|
40970
41051
|
}
|
|
@@ -40989,22 +41070,26 @@ function createTasksChain(options) {
|
|
|
40989
41070
|
manifest: frozen.manifest,
|
|
40990
41071
|
note: input2.note
|
|
40991
41072
|
});
|
|
40992
|
-
|
|
40993
|
-
|
|
40994
|
-
|
|
40995
|
-
|
|
40996
|
-
|
|
40997
|
-
|
|
40998
|
-
|
|
40999
|
-
|
|
41000
|
-
|
|
41001
|
-
|
|
41002
|
-
|
|
41073
|
+
return await prepareOrResume(
|
|
41074
|
+
async () => {
|
|
41075
|
+
const prepared = await client.deliverEscrow(
|
|
41076
|
+
input2.escrowId,
|
|
41077
|
+
{ fileIds: frozen.manifest.files.map((file2) => file2.fileId), note: input2.note },
|
|
41078
|
+
{ idempotencyKey: prepareKey }
|
|
41079
|
+
);
|
|
41080
|
+
if (prepared.delivery.manifestHash !== frozen.manifestHash)
|
|
41081
|
+
throw new TasksValidationError(
|
|
41082
|
+
"The server task delivery manifest hash does not match the local manifest."
|
|
41083
|
+
);
|
|
41084
|
+
return prepared;
|
|
41085
|
+
},
|
|
41003
41086
|
{
|
|
41004
41087
|
...expected,
|
|
41005
41088
|
manifestHash: frozen.manifestHash
|
|
41006
41089
|
},
|
|
41007
|
-
prepareKey
|
|
41090
|
+
prepareKey,
|
|
41091
|
+
"escrow-delivery",
|
|
41092
|
+
"submit-delivery"
|
|
41008
41093
|
);
|
|
41009
41094
|
}),
|
|
41010
41095
|
release: (input2) => safe(async () => {
|
|
@@ -41018,10 +41103,12 @@ function createTasksChain(options) {
|
|
|
41018
41103
|
input2.counterparty
|
|
41019
41104
|
);
|
|
41020
41105
|
const prepareKey = await preparation(input2, "release");
|
|
41021
|
-
return await
|
|
41022
|
-
|
|
41106
|
+
return await prepareOrResume(
|
|
41107
|
+
() => client.releaseEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
41023
41108
|
expected,
|
|
41024
|
-
prepareKey
|
|
41109
|
+
prepareKey,
|
|
41110
|
+
"escrow-release",
|
|
41111
|
+
"release-funds"
|
|
41025
41112
|
);
|
|
41026
41113
|
}),
|
|
41027
41114
|
refund: (input2) => safe(async () => {
|
|
@@ -41035,10 +41122,12 @@ function createTasksChain(options) {
|
|
|
41035
41122
|
input2.counterparty
|
|
41036
41123
|
);
|
|
41037
41124
|
const prepareKey = await preparation(input2, "refund");
|
|
41038
|
-
return await
|
|
41039
|
-
|
|
41125
|
+
return await prepareOrResume(
|
|
41126
|
+
() => client.refundEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
41040
41127
|
expected,
|
|
41041
|
-
prepareKey
|
|
41128
|
+
prepareKey,
|
|
41129
|
+
"escrow-release",
|
|
41130
|
+
"refund-buyer"
|
|
41042
41131
|
);
|
|
41043
41132
|
}),
|
|
41044
41133
|
disputeFee: (input2) => safe(async () => {
|
|
@@ -41066,16 +41155,21 @@ function createTasksChain(options) {
|
|
|
41066
41155
|
input2.counterparty
|
|
41067
41156
|
);
|
|
41068
41157
|
const prepareKey = await preparation(input2, "resolve-unmatched");
|
|
41069
|
-
return
|
|
41070
|
-
|
|
41158
|
+
return prepareOrResume(
|
|
41159
|
+
() => client.resolveUnmatchedEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
41071
41160
|
expected,
|
|
41072
|
-
prepareKey
|
|
41161
|
+
prepareKey,
|
|
41162
|
+
"escrow-unmatched-resolution",
|
|
41163
|
+
"resolve-unmatched-dispute"
|
|
41073
41164
|
);
|
|
41074
41165
|
}),
|
|
41075
41166
|
signScopeMessage: (message) => safe(() => account.signMessage({ message }))
|
|
41076
41167
|
};
|
|
41077
41168
|
}
|
|
41078
41169
|
var chainError = safeTasksChainError;
|
|
41170
|
+
function uncertainPreparation(error61) {
|
|
41171
|
+
return error61 instanceof TasksClientError && ((error61.status ?? 0) >= 400 || error61.code === "network" || error61.code === "timeout");
|
|
41172
|
+
}
|
|
41079
41173
|
function retryDelay(header, now) {
|
|
41080
41174
|
if (/^\d+(?:\.\d+)?$/u.test(header.trim())) return Math.max(1, Math.ceil(Number(header) * 1e3));
|
|
41081
41175
|
const date5 = Date.parse(header);
|
|
@@ -41092,6 +41186,60 @@ function alreadySent(error61) {
|
|
|
41092
41186
|
return error61 instanceof Error && /already known|known transaction|nonce (?:is )?too low/iu.test(error61.message);
|
|
41093
41187
|
}
|
|
41094
41188
|
|
|
41189
|
+
// src/tasks/wait.ts
|
|
41190
|
+
async function waitForMilestone(client, input2) {
|
|
41191
|
+
const timeoutMs = input2.timeoutMs ?? 12e4;
|
|
41192
|
+
const intervalMs = input2.intervalMs ?? 3e3;
|
|
41193
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0)
|
|
41194
|
+
throw new RangeError("The milestone wait timeout must be non-negative and finite.");
|
|
41195
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0)
|
|
41196
|
+
throw new RangeError("The milestone wait interval must be positive and finite.");
|
|
41197
|
+
const sleep = input2.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
41198
|
+
const now = input2.now ?? (() => /* @__PURE__ */ new Date());
|
|
41199
|
+
const started = now().getTime();
|
|
41200
|
+
const deadline = started + timeoutMs;
|
|
41201
|
+
let polls = 0;
|
|
41202
|
+
let milestone;
|
|
41203
|
+
function result(reached) {
|
|
41204
|
+
return { reached, milestone, polls, elapsedMs: now().getTime() - started };
|
|
41205
|
+
}
|
|
41206
|
+
for (; ; ) {
|
|
41207
|
+
const remaining = deadline - now().getTime();
|
|
41208
|
+
if (remaining <= 0) return result(false);
|
|
41209
|
+
const controller = new AbortController();
|
|
41210
|
+
const timer = setTimeout(() => controller.abort(), remaining);
|
|
41211
|
+
let response;
|
|
41212
|
+
polls++;
|
|
41213
|
+
try {
|
|
41214
|
+
response = await client.getOrder(input2.orderId, { signal: controller.signal });
|
|
41215
|
+
} catch (error61) {
|
|
41216
|
+
if (controller.signal.aborted) return result(false);
|
|
41217
|
+
throw error61;
|
|
41218
|
+
} finally {
|
|
41219
|
+
clearTimeout(timer);
|
|
41220
|
+
}
|
|
41221
|
+
if (controller.signal.aborted || now().getTime() >= deadline) return result(false);
|
|
41222
|
+
const { workOrder } = response;
|
|
41223
|
+
milestone = workOrder.id === input2.orderId && workOrder.version === "work-order-view-v1" ? workOrder.milestones.find(
|
|
41224
|
+
(item) => item.id === input2.milestoneId && item.workOrderId === input2.orderId
|
|
41225
|
+
) : void 0;
|
|
41226
|
+
if (milestone && reachedTarget(milestone, input2.target)) return result(true);
|
|
41227
|
+
await sleep(Math.min(intervalMs, deadline - now().getTime()));
|
|
41228
|
+
}
|
|
41229
|
+
}
|
|
41230
|
+
function reachedTarget(milestone, target) {
|
|
41231
|
+
switch (target) {
|
|
41232
|
+
case "created":
|
|
41233
|
+
return milestone.escrowState !== null;
|
|
41234
|
+
case "locked":
|
|
41235
|
+
return ["locked", "submitted", "disputed", "resolved"].includes(milestone.escrowState ?? "");
|
|
41236
|
+
case "delivered":
|
|
41237
|
+
return ["submitted", "disputed", "resolved"].includes(milestone.escrowState ?? "");
|
|
41238
|
+
case "released":
|
|
41239
|
+
return milestone.escrowState === "resolved";
|
|
41240
|
+
}
|
|
41241
|
+
}
|
|
41242
|
+
|
|
41095
41243
|
// src/tasks/rpc.ts
|
|
41096
41244
|
function createTasksRpcFor(config2, options = {}) {
|
|
41097
41245
|
const clients = /* @__PURE__ */ new Map();
|
|
@@ -42949,7 +43097,10 @@ async function taskRequest(verb, route, operation, options) {
|
|
|
42949
43097
|
"not_signed_in",
|
|
42950
43098
|
`${verb} needs sign-in. ${options.signInHint}`
|
|
42951
43099
|
);
|
|
42952
|
-
throw new TaskOperationError(
|
|
43100
|
+
throw new TaskOperationError(
|
|
43101
|
+
error61.serverCode ?? (error61.status ? `http_${error61.status}` : error61.code),
|
|
43102
|
+
error61.message
|
|
43103
|
+
);
|
|
42953
43104
|
}
|
|
42954
43105
|
throw error61;
|
|
42955
43106
|
}
|
|
@@ -43070,7 +43221,8 @@ function proposalTerms(id, address3, deployment, terms) {
|
|
|
43070
43221
|
return {
|
|
43071
43222
|
version: "work-proposal-v1",
|
|
43072
43223
|
workOrderId: id,
|
|
43073
|
-
|
|
43224
|
+
// The server lowercases addresses before canonicalizing the signed payload.
|
|
43225
|
+
providerAddress: address3.toLowerCase(),
|
|
43074
43226
|
pricingModel: "fixed",
|
|
43075
43227
|
milestones: [
|
|
43076
43228
|
{
|
|
@@ -43457,6 +43609,55 @@ async function showTask(context, input2) {
|
|
|
43457
43609
|
};
|
|
43458
43610
|
}
|
|
43459
43611
|
async function taskStatus(context, input2) {
|
|
43612
|
+
if (input2.signedIn) {
|
|
43613
|
+
const chainState = await taskRequest(
|
|
43614
|
+
"status",
|
|
43615
|
+
"chainState",
|
|
43616
|
+
async () => {
|
|
43617
|
+
try {
|
|
43618
|
+
return await context.client.chainState(input2.id);
|
|
43619
|
+
} catch (error61) {
|
|
43620
|
+
if (error61 instanceof TasksClientError && error61.status === 404) {
|
|
43621
|
+
if (isMissingTaskEntity(error61.serverCode, error61.message))
|
|
43622
|
+
throw new TaskOperationError("not_found", error61.message);
|
|
43623
|
+
throw new TaskOperationError(
|
|
43624
|
+
"not_available",
|
|
43625
|
+
"GET /v1/work-orders/:id/chain-state is not available on this server."
|
|
43626
|
+
);
|
|
43627
|
+
}
|
|
43628
|
+
throw error61;
|
|
43629
|
+
}
|
|
43630
|
+
},
|
|
43631
|
+
context
|
|
43632
|
+
);
|
|
43633
|
+
if (chainState.workOrderId !== input2.id)
|
|
43634
|
+
throw new TaskOperationError("invalid_response", "The response belongs to a different task.");
|
|
43635
|
+
const page = await taskRequest(
|
|
43636
|
+
"status",
|
|
43637
|
+
"events",
|
|
43638
|
+
async () => {
|
|
43639
|
+
try {
|
|
43640
|
+
return await context.client.events(input2.id, { wait: 0 });
|
|
43641
|
+
} catch (error61) {
|
|
43642
|
+
if (error61 instanceof TasksClientError && error61.status === 404) {
|
|
43643
|
+
if (isMissingTaskEntity(error61.serverCode, error61.message)) return null;
|
|
43644
|
+
throw new TaskOperationError(
|
|
43645
|
+
"not_available",
|
|
43646
|
+
"GET /v1/work-orders/:id/events is not available on this server."
|
|
43647
|
+
);
|
|
43648
|
+
}
|
|
43649
|
+
throw error61;
|
|
43650
|
+
}
|
|
43651
|
+
},
|
|
43652
|
+
context
|
|
43653
|
+
);
|
|
43654
|
+
return {
|
|
43655
|
+
task: { id: input2.id },
|
|
43656
|
+
chainState,
|
|
43657
|
+
events: page ? [...page.events].sort((a, b) => a.sequence - b.sequence) : null,
|
|
43658
|
+
nextAfter: page?.nextAfter ?? null
|
|
43659
|
+
};
|
|
43660
|
+
}
|
|
43460
43661
|
const task = await taskRequest(
|
|
43461
43662
|
"status",
|
|
43462
43663
|
"publicTask",
|
|
@@ -43901,6 +44102,7 @@ export {
|
|
|
43901
44102
|
taskStateMatches,
|
|
43902
44103
|
taskStatus,
|
|
43903
44104
|
threadTask,
|
|
43904
|
-
validTaskBrief
|
|
44105
|
+
validTaskBrief,
|
|
44106
|
+
waitForMilestone
|
|
43905
44107
|
};
|
|
43906
44108
|
//# sourceMappingURL=tasks.js.map
|