opencrowd 0.13.1 → 0.13.3
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/bundle/opencrowd.js +38 -13
- package/package.json +1 -1
package/bundle/opencrowd.js
CHANGED
|
@@ -57861,8 +57861,13 @@ async function recordReviewSubmitted(session, purchaseId, rating) {
|
|
|
57861
57861
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
57862
57862
|
});
|
|
57863
57863
|
}
|
|
57864
|
-
async function recordReviewFailed(session, purchaseId) {
|
|
57865
|
-
await appendPurchaseEvent(session, {
|
|
57864
|
+
async function recordReviewFailed(session, purchaseId, options = {}) {
|
|
57865
|
+
await appendPurchaseEvent(session, {
|
|
57866
|
+
type: "review_failed",
|
|
57867
|
+
purchase_id: purchaseId,
|
|
57868
|
+
attempted_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
57869
|
+
...options.permanent ? { permanent: true } : {}
|
|
57870
|
+
});
|
|
57866
57871
|
}
|
|
57867
57872
|
async function skipPendingReviews(session) {
|
|
57868
57873
|
for (const state of await pendingRequiredReviews(session))
|
|
@@ -57907,7 +57912,7 @@ async function listPurchases(session) {
|
|
|
57907
57912
|
} else if (event.type === "review_failed") {
|
|
57908
57913
|
const state = states.get(event.purchase_id);
|
|
57909
57914
|
if (state)
|
|
57910
|
-
state.reviewAttempts = (state.reviewAttempts ?? 0) + 1;
|
|
57915
|
+
state.reviewAttempts = event.permanent ? MAX_REVIEW_ATTEMPTS : (state.reviewAttempts ?? 0) + 1;
|
|
57911
57916
|
} else if (event.type === "review_submitted") {
|
|
57912
57917
|
const state = states.get(event.purchase_id);
|
|
57913
57918
|
if (state) {
|
|
@@ -58036,7 +58041,7 @@ function numberArg(value) {
|
|
|
58036
58041
|
function slugUrl(url3) {
|
|
58037
58042
|
return url3.replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").slice(0, 80) || "service";
|
|
58038
58043
|
}
|
|
58039
|
-
var GATEWAY_TOOL_NAMES, VERIFIED_RAILS, EconomyGateway, GATEWAY_TOOL_DEFINITIONS;
|
|
58044
|
+
var GATEWAY_TOOL_NAMES, VERIFIED_RAILS, PERMANENT_REVIEW_REJECTION, isPermanentReviewRejection, EconomyGateway, GATEWAY_TOOL_DEFINITIONS;
|
|
58040
58045
|
var init_gateway = __esm({
|
|
58041
58046
|
"../../packages/economy/dist/gateway.js"() {
|
|
58042
58047
|
"use strict";
|
|
@@ -58061,6 +58066,8 @@ var init_gateway = __esm({
|
|
|
58061
58066
|
"bridge_usdc"
|
|
58062
58067
|
];
|
|
58063
58068
|
VERIFIED_RAILS = ["x402-base", "x402-solana", "x402-monad", "mppx"];
|
|
58069
|
+
PERMANENT_REVIEW_REJECTION = /service identity conflict|payment target is shared by multiple services|service not found|unknown purchase/i;
|
|
58070
|
+
isPermanentReviewRejection = (error53) => !!error53 && PERMANENT_REVIEW_REJECTION.test(error53);
|
|
58064
58071
|
EconomyGateway = class {
|
|
58065
58072
|
options;
|
|
58066
58073
|
/**
|
|
@@ -58343,6 +58350,8 @@ var init_gateway = __esm({
|
|
|
58343
58350
|
// Confirmed paid successes AND paid failures require reviews; free,
|
|
58344
58351
|
// SIWX, and unknown outcomes create no paid receipt to review.
|
|
58345
58352
|
review_required: paid && supportedRail && await this.crowdcodeEnabled(),
|
|
58353
|
+
// Our own failure, not the seller's: recorded, never reviewable.
|
|
58354
|
+
...result.callerError ? { caller_error: true } : {},
|
|
58346
58355
|
// x402 Solana receipts carry no payee; CrowdCode needs it to verify a new
|
|
58347
58356
|
// service, so use the inspected offer's when the payment settled on that rail.
|
|
58348
58357
|
evidence: result.payment && !result.payment.payTo && inspection.payTo && railUsed === inspection.rail ? { ...result.payment, payTo: inspection.payTo } : result.payment,
|
|
@@ -58483,6 +58492,12 @@ var init_gateway = __esm({
|
|
|
58483
58492
|
if (state.reviewStatus === "submitted") {
|
|
58484
58493
|
return { ok: false, error: `purchase ${purchaseId} is already reviewed` };
|
|
58485
58494
|
}
|
|
58495
|
+
if (state.record.caller_error) {
|
|
58496
|
+
return {
|
|
58497
|
+
ok: false,
|
|
58498
|
+
error: `purchase ${purchaseId} never reached ${state.record.endpoint}: it was refused before the request was sent (${state.record.notes ?? "no payment was made"}). That is not something the service did, so there is nothing to review. Fix the cause and call the service again.`
|
|
58499
|
+
};
|
|
58500
|
+
}
|
|
58486
58501
|
const evidence = state.record.evidence;
|
|
58487
58502
|
const result = await this.options.crowdcode.reviewService({
|
|
58488
58503
|
rating,
|
|
@@ -58498,7 +58513,14 @@ var init_gateway = __esm({
|
|
|
58498
58513
|
taskContext: stringArg(args.task_context)
|
|
58499
58514
|
});
|
|
58500
58515
|
if (!result.ok) {
|
|
58501
|
-
|
|
58516
|
+
const permanent = isPermanentReviewRejection(result.error);
|
|
58517
|
+
await recordReviewFailed(this.options.session, purchaseId, { permanent });
|
|
58518
|
+
if (permanent) {
|
|
58519
|
+
return {
|
|
58520
|
+
ok: false,
|
|
58521
|
+
error: `CrowdCode could not attach this review to a registered service (${result.error}). This will not change on a retry, so the review is recorded as unsendable; it no longer blocks later purchases. Do not call review_paid_service for ${purchaseId} again.`
|
|
58522
|
+
};
|
|
58523
|
+
}
|
|
58502
58524
|
const deferred = (state.reviewAttempts ?? 0) + 1 >= MAX_REVIEW_ATTEMPTS;
|
|
58503
58525
|
return { ok: false, error: `CrowdCode review failed (${result.error}); the review stays pending${deferred ? " for manual retry, without blocking completion or later purchases" : " \u2014 retry review_paid_service"}` };
|
|
58504
58526
|
}
|
|
@@ -58850,7 +58872,10 @@ var init_mocks = __esm({
|
|
|
58850
58872
|
}
|
|
58851
58873
|
async reviewService(review) {
|
|
58852
58874
|
if (this.options.failReviews) {
|
|
58853
|
-
return {
|
|
58875
|
+
return {
|
|
58876
|
+
ok: false,
|
|
58877
|
+
error: typeof this.options.failReviews === "string" ? this.options.failReviews : "mock review submission failure"
|
|
58878
|
+
};
|
|
58854
58879
|
}
|
|
58855
58880
|
this.reviews.push(review);
|
|
58856
58881
|
return { ok: true, raw: { accepted: true } };
|
|
@@ -81463,9 +81488,9 @@ var init_hosted_economy = __esm({
|
|
|
81463
81488
|
return this.discovery.inspect(input2);
|
|
81464
81489
|
}
|
|
81465
81490
|
async fetch(request2) {
|
|
81466
|
-
const refuse = (error53) => ({ ok: false, ambiguous: false, data: void 0, error: error53 });
|
|
81491
|
+
const refuse = (error53, ours = false) => ({ ok: false, ambiguous: false, data: void 0, error: error53, ...ours ? { callerError: true } : {} });
|
|
81467
81492
|
if (!HOSTED_RAILS.includes(request2.rail)) {
|
|
81468
|
-
return refuse(`this service settles on a payment network hosted agents cannot pay; hosted agents pay ${describeRails(HOSTED_RAILS)}
|
|
81493
|
+
return refuse(`this service settles on a payment network hosted agents cannot pay; hosted agents pay ${describeRails(HOSTED_RAILS)}`, true);
|
|
81469
81494
|
}
|
|
81470
81495
|
const serviceId = await this.directory.resolveServiceId(request2.url) ?? `url:${createHash4("sha256").update(request2.url).digest("hex")}`;
|
|
81471
81496
|
const method = request2.method.toUpperCase();
|
|
@@ -81529,7 +81554,7 @@ var init_hosted_economy = __esm({
|
|
|
81529
81554
|
return this.fetchUnpaid(request2.url, method, body, request2.headers);
|
|
81530
81555
|
}
|
|
81531
81556
|
if (reply.code === "funding_required") {
|
|
81532
|
-
return refuse(`${reply.error ?? "not enough USDC on this service's networks"} (funding_required)${await this.fundingHint(request2)}
|
|
81557
|
+
return refuse(`${reply.error ?? "not enough USDC on this service's networks"} (funding_required)${await this.fundingHint(request2)}`, true);
|
|
81533
81558
|
}
|
|
81534
81559
|
if (reply.code === "payment_unknown") {
|
|
81535
81560
|
return {
|
|
@@ -81604,7 +81629,7 @@ var init_hosted_economy = __esm({
|
|
|
81604
81629
|
const cost = `about $${MOVE_FEE_ESTIMATE_USD.toFixed(2)}`, size5 = `$${move.amount.toFixed(2)}`;
|
|
81605
81630
|
if (!move.worthwhile)
|
|
81606
81631
|
return `${line}${elsewhere} Moving funds is the other way, but the most ${move.from} can spare is ${size5}, and a fee of ${cost} is ${Math.round(move.feeShare * 100)}% of that \u2014 too much to spend without asking. If no equivalent service fits, say exactly that to the owner: this service is sold only on ${target}, moving ${size5} there would cost ${cost} in fees, and ask whether to do it.`;
|
|
81607
|
-
return `${line}${elsewhere} Otherwise move funds
|
|
81632
|
+
return `${line}${elsewhere} Otherwise move the funds yourself and retry \u2014 a move this size is within the policy and is not something to ask the owner about, any more than paying for the call is: bridge_usdc {"from":"${move.from}","to":"${target}","amount_usd":${move.amount}} (fee ${cost}, counted as spending; the spending guard pauses it for approval by itself if the owner's mode requires that), then retry this call.`;
|
|
81608
81633
|
}
|
|
81609
81634
|
/**
|
|
81610
81635
|
* Moves this agent's own USDC between its networks through the supervisor:
|
|
@@ -81757,7 +81782,7 @@ var init_hosted_economy = __esm({
|
|
|
81757
81782
|
};
|
|
81758
81783
|
HOSTED_BRIDGE_TOOL = {
|
|
81759
81784
|
name: "bridge_usdc",
|
|
81760
|
-
description: "Move your own USDC between your networks (base, solana, tempo); it always arrives at your own address. Use it when the owner asks, or when a paid call failed with funding_required and no equivalent service is sold on a network you already fund. quote_only shows the fee and expected amount without moving. Executing re-quotes, applies the owner's approval policy to the fee (it may pause for approval) and waits for the funds to arrive, usually within a minute. Fees are about $0.02-0.03 and count as spending, so aim for about $1 and one fee funds many calls; when the wallet holds less, move what the call needs plus the fee, as long as the fee stays under about a fifth of what moves (roughly $0.15 and up). Below
|
|
81785
|
+
description: "Move your own USDC between your networks (base, solana, tempo); it always arrives at your own address. Use it when the owner asks, or when a paid call failed with funding_required and no equivalent service is sold on a network you already fund. quote_only shows the fee and expected amount without moving. Executing re-quotes, applies the owner's approval policy to the fee (it may pause for approval) and waits for the funds to arrive, usually within a minute. Fees are about $0.02-0.03 and count as spending, so aim for about $1 and one fee funds many calls; when the wallet holds less, move what the call needs plus the fee, as long as the fee stays under about a fifth of what moves (roughly $0.15 and up). A move within that rule needs no permission from the owner: the spending guard applies their approval mode to the fee by itself. Below the rule, quote_only first and ask, rather than spending most of the move on its fee. Pass transfer_id alone to check a pending move.",
|
|
81761
81786
|
parameters: {
|
|
81762
81787
|
type: "object",
|
|
81763
81788
|
properties: {
|
|
@@ -82509,9 +82534,9 @@ async function runAgentTaskDetailed(session, task, options = {}) {
|
|
|
82509
82534
|
if (options.hosted)
|
|
82510
82535
|
systemPromptParts.push("Files the owner sends you: an attached file is saved in this session under uploads/ before its message reaches you, and the message names each one with its path, size and type. Read a text file with read_file at uploads/<name>, and any file with run_shell at artifacts/uploads/<name> from the session directory. Those files are already the owner's and already in their file list: work from them, and never copy or re-save one under artifacts/ to hand it back. Write your own outputs elsewhere under artifacts/; uploads/ is the owner's directory and nothing you write there is delivered. If a file the message names is missing, say so and ask the owner to send it again rather than guessing at its contents.", "Files you produce: only the artifacts/ directory of this session reaches the owner. save_file writes there; anything you write elsewhere is scratch they never see. The owner sees each file at its path without that prefix, so artifacts/generated/report.pdf is generated/report.pdf to them. Name a produced file in your final message by exactly that path as plain text and nothing else \u2014 the owner's interface turns it into a working download and preview link. Never invent a download URL, a sandbox: link, a /mnt/data path, or any other path the owner cannot open, and never claim a file exists before you have verified it.");
|
|
82511
82536
|
if (options.dynamicTools) {
|
|
82512
|
-
systemPromptParts.push("When the local computer is not the right environment, or after one clear local capability failure, buy external capability: find_paid_service to discover, inspect_paid_service to see the exact schema/price/reputation, call_paid_service to execute through the enforced purchase lifecycle, and review_paid_service for the required review after every confirmed paid call (success or failure). The same review tool accepts unpaid experiences; review relevant free results or failed attempts without inventing payment evidence. Distinguish provider faults from local errors and uncertain failures. A platform judge, not you, writes the public score and text of a paid review from the platform's record of the call; your rating and notes are evidence it reads, so report accurately and never try to talk it into a rating.", `Choosing a service: find_paid_service with a short capability query (for example "web search" or "object storage", not the task's subject) searches every catalog (AgentCash, Coinbase's x402 catalog, the MPP catalog and CrowdCode's reviews) across Base, Solana and Tempo and returns services you can pay, ranked best first by CrowdCode: quality (score and verified reviews), then effective price on the service's best network, including about $0.03 to move USDC between your own networks when that network's balance is short, then your balance there. Prefer the highest-ranked service that fits the task, whatever its network; a better or cheaper service on Solana or Tempo beats a Base default. Each result also lists \`networks\`, the networks it can be paid on; between services that fit the task equally well, one you can pay from a balance you already hold beats one that needs a transfer first, because a move costs about $0.03. When the chosen service is marked transfer_needed, move USDC between your own networks first if you have a tool for that; otherwise tell the user which network needs funds. When the ranking is unavailable, compare candidates yourself with inspect_paid_service (reputation, price and network) against your per-network balances.`, ...options.hosted ? [
|
|
82537
|
+
systemPromptParts.push("When the local computer is not the right environment, or after one clear local capability failure, buy external capability: find_paid_service to discover, inspect_paid_service to see the exact schema/price/reputation, call_paid_service to execute through the enforced purchase lifecycle, and review_paid_service for the required review after every confirmed paid call (success or failure). The same review tool accepts unpaid experiences; review relevant free results or failed attempts without inventing payment evidence. Distinguish provider faults from local errors and uncertain failures: a call that never reached the seller is never the seller's fault. funding_required means your USDC is on the wrong network, a cap or a declined approval means the owner's policy stopped you, and an unpayable rail means you could not pay at all \u2014 in every one of those the service was never asked, so it gets no review and certainly not a low rating. Fix the cause and call it again instead; the gateway refuses those reviews, and trying anyway wastes a turn. A platform judge, not you, writes the public score and text of a paid review from the platform's record of the call; your rating and notes are evidence it reads, so report accurately and never try to talk it into a rating.", `Choosing a service: find_paid_service with a short capability query (for example "web search" or "object storage", not the task's subject) searches every catalog (AgentCash, Coinbase's x402 catalog, the MPP catalog and CrowdCode's reviews) across Base, Solana and Tempo and returns services you can pay, ranked best first by CrowdCode: quality (score and verified reviews), then effective price on the service's best network, including about $0.03 to move USDC between your own networks when that network's balance is short, then your balance there. Prefer the highest-ranked service that fits the task, whatever its network; a better or cheaper service on Solana or Tempo beats a Base default. Each result also lists \`networks\`, the networks it can be paid on; between services that fit the task equally well, one you can pay from a balance you already hold beats one that needs a transfer first, because a move costs about $0.03. When the chosen service is marked transfer_needed, move USDC between your own networks first if you have a tool for that; otherwise tell the user which network needs funds. When the ranking is unavailable, compare candidates yourself with inspect_paid_service (reputation, price and network) against your per-network balances.`, ...options.hosted ? [
|
|
82513
82538
|
"You can use new services without prior CrowdCode reviews. Payable: x402 USDC on Base or Solana and MPP USDC.e on Tempo; the hosted gateway pays the cheapest offered network your balance on that network covers. Other networks, including Monad, are not payable here. Payments stay within the user's configured limits; over-limit quotes request approval. Use read_service for authenticated job polling and never resubmit a pending generation job.",
|
|
82514
|
-
"funding_required means your USDC is on the wrong network, not that you are out of money, and a wallet with money in it finishes the job. First go back to find_paid_service and look for an equivalent service sold on a network you already hold USDC on \u2014 every result lists its `networks`, and paying from an existing balance costs no transfer fee. If none fits, move funds with bridge_usdc and retry the same call: aim for about $1 so one fee funds many later calls, and when the wallet holds less than that, move what the call needs plus the fee, as long as the fee stays under about a fifth of what moves (roughly $0.15 and up at a $0.03 fee). Only below that is a move not worth making on your own: quote_only it, then ask
|
|
82539
|
+
"funding_required means your USDC is on the wrong network, not that you are out of money, and a wallet with money in it finishes the job. First go back to find_paid_service and look for an equivalent service sold on a network you already hold USDC on \u2014 every result lists its `networks`, and paying from an existing balance costs no transfer fee. If none fits, move funds with bridge_usdc and retry the same call: aim for about $1 so one fee funds many later calls, and when the wallet holds less than that, move what the call needs plus the fee, as long as the fee stays under about a fifth of what moves (roughly $0.15 and up at a $0.03 fee). A move inside that rule is ordinary work, not a decision for the owner: make it and retry, exactly as you would pay for the call itself. The spending guard applies the owner's approval mode to the fee by itself and pauses the run if it has to, so you never need permission before calling bridge_usdc. Stopping to ask whether you may spend three cents moving the owner's own money to the network a seller wants is the dead end this rule exists to prevent. Only below that threshold is a move not worth making on your own: quote_only it, then ask. When the owner asks you to move funds, quote first, state the fee, then execute and report both transaction ids and the amount received. Moves follow the owner's approval mode like payments; never move funds without a reason.",
|
|
82515
82540
|
"When money is what blocks a task, say exactly that and nothing else: which network the service is sold on, what you hold where, and the single thing you need \u2014 permission for a move you have quoted, or USDC added on that network. Never dress a funding problem up as the service being unsuitable or unavailable, never imply your wallet is empty when it is not, and never offer a recorded request_service as though it were the answer the owner asked for."
|
|
82516
82541
|
] : [], capabilityIndex ?? DEFAULT_CAPABILITY_INDEX, "When a task needs current web facts, search results, or unfamiliar page content, make one paid web search your FIRST move \u2014 do not serially guess URLs with curl; one paid search replaces minutes of blind fetching and costs less than the LLM turns it saves.", "Approval, budget, reputation, and payment rails are enforced in code \u2014 you cannot bypass them, so state costs plainly and never invent payment details.", "When the user says CrowdCode on/off, call set_crowdcode_enabled; default to session scope unless they ask for a persistent default. Use list_my_reviews and delete_my_review for user-directed review management, including while off. Before finishing a substantive task, consider concrete paid services that would fix real shortcomings and submit qualifying demand with request_service (input, output, problem, price_per_call), unless CrowdCode is off. Never invent a purchase or demand.", "Each tool result includes the budget before and after that tool call. Never ask for wallet private keys or secrets.", ...options.promptSections ?? []);
|
|
82517
82542
|
} else {
|
package/package.json
CHANGED