@ambasada/village 0.8.10 → 0.8.11
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/cli.mjs +125 -37
- package/dist/client.d.ts +13 -1
- package/dist/index.js +25 -2
- package/dist/types.d.ts +4 -2
- package/package.json +4 -4
package/dist/client.d.ts
CHANGED
|
@@ -53,11 +53,23 @@ export declare class Village extends Ambasada {
|
|
|
53
53
|
/**
|
|
54
54
|
* Wraps a paid offering as a fetch handler: verifies the receipt (402 if missing or bad), runs
|
|
55
55
|
* `handler(input, call, req)` and answers JSON. A thrown `AmbasadaError` keeps its status (the
|
|
56
|
-
* Gateway then refunds the buyer).
|
|
56
|
+
* Gateway then refunds the buyer). The buyer pays only for what you deliver, so a handler that returns an error
|
|
57
|
+
* object (`{ error: { code, message } }`) or nothing (`undefined`, `null`, `""`) is answered as an error too, never
|
|
58
|
+
* 200 (dry run 7 #8: "busy, try again" answers were charged). If you can't deliver the paid thing (a tool you
|
|
59
|
+
* need is rate-limited, CAP_TOOLS_RATE, or down, TOOL_UNAVAILABLE), throw, or rethrow what you caught: the buyer
|
|
60
|
+
* is refunded and told when to try again.
|
|
57
61
|
*
|
|
58
62
|
* export default village.sell("translate", async ({ text, to }) => ({ text: await village.llm(`…`) }));
|
|
59
63
|
*/
|
|
60
64
|
sell<Input = any, Output = unknown>(offering: string, handler: SellHandler<Input, Output>): (req: Request) => Promise<Response>;
|
|
65
|
+
/**
|
|
66
|
+
* A warning worth seeing in `ambasada logs` even though the request succeeded, e.g. an answer degraded because a
|
|
67
|
+
* tool was rate-limited: `console.warn("[village]", …)`. The templates send a request's `[village]` lines along with
|
|
68
|
+
* any answer, and ambasada.dev keeps them as warnings (at most 50 an hour; never counted as errors).
|
|
69
|
+
*
|
|
70
|
+
* village.warn("wikipedia.search: CAP_TOOLS_RATE, answering from the model alone");
|
|
71
|
+
*/
|
|
72
|
+
warn(...message: unknown[]): void;
|
|
61
73
|
/**
|
|
62
74
|
* An async offering's answer to a paid call (`async: true` in offerings.ts): the work goes on as job `id` (in the
|
|
63
75
|
* template, a Jobs Durable Object named after it), and the Gateway asks `GET <endpoint>/jobs/<id>` until it is done.
|
package/dist/index.js
CHANGED
|
@@ -1749,7 +1749,11 @@ var Village = class extends Ambasada {
|
|
|
1749
1749
|
/**
|
|
1750
1750
|
* Wraps a paid offering as a fetch handler: verifies the receipt (402 if missing or bad), runs
|
|
1751
1751
|
* `handler(input, call, req)` and answers JSON. A thrown `AmbasadaError` keeps its status (the
|
|
1752
|
-
* Gateway then refunds the buyer).
|
|
1752
|
+
* Gateway then refunds the buyer). The buyer pays only for what you deliver, so a handler that returns an error
|
|
1753
|
+
* object (`{ error: { code, message } }`) or nothing (`undefined`, `null`, `""`) is answered as an error too, never
|
|
1754
|
+
* 200 (dry run 7 #8: "busy, try again" answers were charged). If you can't deliver the paid thing (a tool you
|
|
1755
|
+
* need is rate-limited, CAP_TOOLS_RATE, or down, TOOL_UNAVAILABLE), throw, or rethrow what you caught: the buyer
|
|
1756
|
+
* is refunded and told when to try again.
|
|
1753
1757
|
*
|
|
1754
1758
|
* export default village.sell("translate", async ({ text, to }) => ({ text: await village.llm(`…`) }));
|
|
1755
1759
|
*/
|
|
@@ -1765,7 +1769,16 @@ var Village = class extends Ambasada {
|
|
|
1765
1769
|
}
|
|
1766
1770
|
try {
|
|
1767
1771
|
const out = await handler(call.input, call, req);
|
|
1768
|
-
|
|
1772
|
+
if (out instanceof Response) return out;
|
|
1773
|
+
if (out === void 0 || out === null || out === "") {
|
|
1774
|
+
return new AmbasadaError3("UPSTREAM_ERROR", `the ${offering2} handler returned nothing; the buyer is refunded (return what was paid for, or throw)`, 502).toResponse();
|
|
1775
|
+
}
|
|
1776
|
+
const error = out.error;
|
|
1777
|
+
if (typeof error === "object" && error !== null && typeof error.code === "string") {
|
|
1778
|
+
const { code, message, ...details } = error;
|
|
1779
|
+
return new AmbasadaError3(code, typeof message === "string" ? message : code, void 0, details).toResponse();
|
|
1780
|
+
}
|
|
1781
|
+
return Response.json(out);
|
|
1769
1782
|
} catch (error) {
|
|
1770
1783
|
if (error instanceof AmbasadaError3) return error.toResponse();
|
|
1771
1784
|
console.error(error);
|
|
@@ -1773,6 +1786,16 @@ var Village = class extends Ambasada {
|
|
|
1773
1786
|
}
|
|
1774
1787
|
};
|
|
1775
1788
|
}
|
|
1789
|
+
/**
|
|
1790
|
+
* A warning worth seeing in `ambasada logs` even though the request succeeded, e.g. an answer degraded because a
|
|
1791
|
+
* tool was rate-limited: `console.warn("[village]", …)`. The templates send a request's `[village]` lines along with
|
|
1792
|
+
* any answer, and ambasada.dev keeps them as warnings (at most 50 an hour; never counted as errors).
|
|
1793
|
+
*
|
|
1794
|
+
* village.warn("wikipedia.search: CAP_TOOLS_RATE, answering from the model alone");
|
|
1795
|
+
*/
|
|
1796
|
+
warn(...message) {
|
|
1797
|
+
console.warn("[village]", ...message);
|
|
1798
|
+
}
|
|
1776
1799
|
/**
|
|
1777
1800
|
* An async offering's answer to a paid call (`async: true` in offerings.ts): the work goes on as job `id` (in the
|
|
1778
1801
|
* template, a Jobs Durable Object named after it), and the Gateway asks `GET <endpoint>/jobs/<id>` until it is done.
|
package/dist/types.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ReceiptClaims {
|
|
|
17
17
|
/** TON you may still spend downstream on behalf of this call. */
|
|
18
18
|
budget?: number;
|
|
19
19
|
deal_id?: string;
|
|
20
|
-
/** An async offering's call: when the buyer's max_wait_s runs out (unix seconds); `startJob(…, { deadline: call.deadline
|
|
20
|
+
/** An async offering's call: when the buyer's max_wait_s runs out (unix seconds); pass it as it is: `startJob(…, { deadline: call.deadline })` (the templates' jobs take seconds or ms). */
|
|
21
21
|
deadline?: number;
|
|
22
22
|
body_sha256: string;
|
|
23
23
|
iat: number;
|
|
@@ -159,7 +159,7 @@ export interface BuyOptions {
|
|
|
159
159
|
}
|
|
160
160
|
/** What an async offering's `GET <endpoint>/jobs/<id>` says (village.jobStatus): the Gateway settles on done or failed. */
|
|
161
161
|
export type JobAnswer =
|
|
162
|
-
/** `attempts`: the failed ones so far (the template's `jobAnswer(job)`); the buyer sees "working (attempt
|
|
162
|
+
/** `attempts`: the failed ones so far (the template's `jobAnswer(job)`); the buyer sees "working (attempt 1 failed: …; retrying)". */
|
|
163
163
|
{
|
|
164
164
|
status: "working";
|
|
165
165
|
attempts?: {
|
|
@@ -344,6 +344,8 @@ export interface AgentSettings {
|
|
|
344
344
|
};
|
|
345
345
|
/** Agent tools offered to the model (default: all). */
|
|
346
346
|
tools?: string[];
|
|
347
|
+
/** A wake changes one offering's price at most this often, in minutes (default 120; 0: any time). */
|
|
348
|
+
price_cooldown_minutes?: number;
|
|
347
349
|
/**
|
|
348
350
|
* The whole company's spend limits, TON: the product's own LLM and image calls count too, not only the agent's
|
|
349
351
|
* purchases. Over `auto_per_payment` (and `auto_per_day`) an agent payment needs the team's approval.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ambasada/village",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
4
4
|
"description": "The Hack A Ton add-on for Ambasada apps: TON checkout, receipts, offerings, LLM, the agent, the market; CLI commands and the local bank.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"node": ">=22"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ambasada/sdk": "^0.8.
|
|
30
|
+
"@ambasada/sdk": "^0.8.11"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^22.20.5",
|
|
34
34
|
"esbuild": "^0.28.2",
|
|
35
35
|
"typescript": "~5.9.3",
|
|
36
36
|
"vitest": "^4.1.12",
|
|
37
|
-
"@ambasada/
|
|
38
|
-
"@ambasada/
|
|
37
|
+
"@ambasada/cli": "0.8.11",
|
|
38
|
+
"@ambasada/protocol": "0.1.0"
|
|
39
39
|
},
|
|
40
40
|
"author": "CENTYSO (https://centyso.com)",
|
|
41
41
|
"homepage": "https://ambasada.id",
|