@ambasada/sdk 0.7.5 → 0.8.0
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 +24 -25
- package/dist/apps.d.ts +2 -2
- package/dist/auth.d.ts +9 -9
- package/dist/client.d.ts +45 -145
- package/dist/define.d.ts +10 -35
- package/dist/errors.d.ts +12 -15
- package/dist/headers.d.ts +3 -0
- package/dist/index.d.ts +126 -23
- package/dist/index.js +1470 -277
- package/dist/platform.d.ts +20 -0
- package/dist/types.d.ts +2 -308
- package/dist/village/client.d.ts +148 -0
- package/dist/village/define.d.ts +44 -0
- package/dist/village/errors.d.ts +19 -0
- package/dist/village/index.d.ts +27 -0
- package/dist/{receipt.d.ts → village/receipt.d.ts} +2 -2
- package/dist/village/types.d.ts +307 -0
- package/dist/{webhook.d.ts → village/webhook.d.ts} +11 -3
- package/package.json +7 -7
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/** Village wire types. TON amounts are decimal numbers (`1`, `0.5`). */
|
|
2
|
+
/** What a seller learns from a Gateway call receipt (`x-village-receipt`). Same shape as `@ambasada/protocol`. */
|
|
3
|
+
export interface ReceiptClaims {
|
|
4
|
+
iss: string;
|
|
5
|
+
jti: string;
|
|
6
|
+
call_id: string;
|
|
7
|
+
/** Buyer company id. */
|
|
8
|
+
buyer: string;
|
|
9
|
+
/** Your company id. */
|
|
10
|
+
seller: string;
|
|
11
|
+
/** `<seller>/<offering name>` */
|
|
12
|
+
offering: string;
|
|
13
|
+
/** TON */
|
|
14
|
+
amount: number;
|
|
15
|
+
/** 1 for a direct buy; forward it with `buy(…, { parent })`. */
|
|
16
|
+
depth: number;
|
|
17
|
+
/** TON you may still spend downstream on behalf of this call. */
|
|
18
|
+
budget?: number;
|
|
19
|
+
deal_id?: string;
|
|
20
|
+
body_sha256: string;
|
|
21
|
+
iat: number;
|
|
22
|
+
exp: number;
|
|
23
|
+
}
|
|
24
|
+
/** A verified paid call: the receipt plus the parsed JSON input. */
|
|
25
|
+
export interface PaidCall<Input = any> extends ReceiptClaims {
|
|
26
|
+
input: Input;
|
|
27
|
+
}
|
|
28
|
+
/** A checkout receipt (pay.js `village:paid`, or `session.receipt`). */
|
|
29
|
+
export interface CheckoutReceiptClaims {
|
|
30
|
+
iss: string;
|
|
31
|
+
jti: string;
|
|
32
|
+
kind: "checkout";
|
|
33
|
+
session: string;
|
|
34
|
+
/** The person's pseudonymous wallet id (`p_…`). */
|
|
35
|
+
buyer: string;
|
|
36
|
+
seller: string;
|
|
37
|
+
amount: number;
|
|
38
|
+
description: string;
|
|
39
|
+
ref?: string;
|
|
40
|
+
log_index: number;
|
|
41
|
+
iat: number;
|
|
42
|
+
exp: number;
|
|
43
|
+
}
|
|
44
|
+
export interface CheckoutInput {
|
|
45
|
+
/** TON, 0.1–500. Or give `offering` to charge one of your offerings' price. */
|
|
46
|
+
amount?: number;
|
|
47
|
+
offering?: string;
|
|
48
|
+
/** Shown to the person and written to the public ledger as the memo. No personal data. */
|
|
49
|
+
description: string;
|
|
50
|
+
/** `{CHECKOUT_SESSION_ID}` anywhere in the URL is replaced; otherwise `?session=cs_…` is appended. */
|
|
51
|
+
success_url: string;
|
|
52
|
+
cancel_url?: string;
|
|
53
|
+
client_reference_id?: string;
|
|
54
|
+
metadata?: Record<string, string>;
|
|
55
|
+
/** Seconds, 300–86400 (default 3600). */
|
|
56
|
+
expires_in?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface CheckoutSession {
|
|
59
|
+
id: string;
|
|
60
|
+
object: "checkout.session";
|
|
61
|
+
url: string;
|
|
62
|
+
status: "open" | "paid" | "expired" | (string & {});
|
|
63
|
+
amount: number;
|
|
64
|
+
description: string;
|
|
65
|
+
offering: string | null;
|
|
66
|
+
/** The payment link it came from (`pl_…`), if any. */
|
|
67
|
+
link: string | null;
|
|
68
|
+
client_reference_id: string | null;
|
|
69
|
+
metadata: Record<string, string>;
|
|
70
|
+
success_url: string;
|
|
71
|
+
cancel_url: string | null;
|
|
72
|
+
buyer: string | null;
|
|
73
|
+
paid_at: string | null;
|
|
74
|
+
log_index: number | null;
|
|
75
|
+
receipt: string | null;
|
|
76
|
+
created_at: string;
|
|
77
|
+
expires_at: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
export interface PaymentLinkInput {
|
|
81
|
+
amount?: number;
|
|
82
|
+
offering?: string;
|
|
83
|
+
description: string;
|
|
84
|
+
success_url: string;
|
|
85
|
+
cancel_url?: string;
|
|
86
|
+
metadata?: Record<string, string>;
|
|
87
|
+
}
|
|
88
|
+
export interface PaymentLink {
|
|
89
|
+
id: string;
|
|
90
|
+
object: "checkout.link";
|
|
91
|
+
url: string;
|
|
92
|
+
active: boolean;
|
|
93
|
+
amount: number;
|
|
94
|
+
description: string;
|
|
95
|
+
offering: string | null;
|
|
96
|
+
metadata: Record<string, string>;
|
|
97
|
+
success_url: string;
|
|
98
|
+
cancel_url: string | null;
|
|
99
|
+
created_at: string;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
export interface WebhookDelivery {
|
|
103
|
+
id: string;
|
|
104
|
+
type: string;
|
|
105
|
+
status: "pending" | "delivered" | "failed" | (string & {});
|
|
106
|
+
attempts: number;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
export interface WebhookEvent<Data = any> {
|
|
110
|
+
/** `webhook-id` header: dedupe on it, retries reuse it. */
|
|
111
|
+
id: string;
|
|
112
|
+
type: "checkout.paid" | "webhook.test" | (string & {});
|
|
113
|
+
timestamp: string;
|
|
114
|
+
data: Data;
|
|
115
|
+
}
|
|
116
|
+
export interface BuyOptions {
|
|
117
|
+
/** Refuse (PRICE_ABOVE_MAX) if the offering costs more than this, in TON. */
|
|
118
|
+
maxPrice?: number;
|
|
119
|
+
/** Retries with the same key never charge twice. Default: a random key per call (reused by the SDK's own retry). */
|
|
120
|
+
idempotencyKey?: string;
|
|
121
|
+
/** Inside a paid handler: forward the chain depth and remaining budget of the call you are serving. */
|
|
122
|
+
parent?: Pick<ReceiptClaims, "depth" | "budget">;
|
|
123
|
+
/** TON this call may spend downstream (`x-village-budget`). */
|
|
124
|
+
budget?: number;
|
|
125
|
+
/** An approved approval id, after APPROVAL_REQUIRED. */
|
|
126
|
+
approval?: string;
|
|
127
|
+
/** Why you are buying; shown to your team on approval requests. */
|
|
128
|
+
reason?: string;
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
}
|
|
131
|
+
export interface BuyResult<Output = any> {
|
|
132
|
+
output: Output;
|
|
133
|
+
callId: string | null;
|
|
134
|
+
/** TON charged. */
|
|
135
|
+
amount: number | null;
|
|
136
|
+
/** The signed receipt for the call (you hold it too). */
|
|
137
|
+
receipt: string | null;
|
|
138
|
+
/** Position in the public ledger log. */
|
|
139
|
+
logIndex: number | null;
|
|
140
|
+
/** True when the Gateway replayed a previous result for the same idempotency key (no new charge). */
|
|
141
|
+
replayed: boolean;
|
|
142
|
+
/** For `need()`: which offering served it (`company/name`), if the Gateway says. */
|
|
143
|
+
offering: string | null;
|
|
144
|
+
}
|
|
145
|
+
export type ChatModel = "deepseek-v4.1-flash" | "deepseek-v4-pro" | "glm-5.3-flash" | (string & {});
|
|
146
|
+
export interface ChatMessage {
|
|
147
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
148
|
+
content: string;
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
/** OpenAI-compatible chat request. */
|
|
152
|
+
export interface ChatRequest {
|
|
153
|
+
model?: ChatModel;
|
|
154
|
+
messages: ChatMessage[];
|
|
155
|
+
temperature?: number;
|
|
156
|
+
max_tokens?: number;
|
|
157
|
+
response_format?: {
|
|
158
|
+
type: "text" | "json_object";
|
|
159
|
+
} | Record<string, unknown>;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}
|
|
162
|
+
export interface ChatResponse {
|
|
163
|
+
id: string;
|
|
164
|
+
object: "chat.completion";
|
|
165
|
+
model: string;
|
|
166
|
+
choices: {
|
|
167
|
+
index: number;
|
|
168
|
+
message: ChatMessage;
|
|
169
|
+
finish_reason: string | null;
|
|
170
|
+
}[];
|
|
171
|
+
usage?: {
|
|
172
|
+
prompt_tokens: number;
|
|
173
|
+
completion_tokens: number;
|
|
174
|
+
total_tokens: number;
|
|
175
|
+
};
|
|
176
|
+
[key: string]: unknown;
|
|
177
|
+
}
|
|
178
|
+
export interface ImageRequest {
|
|
179
|
+
model?: "nano_banana" | "gpt-image-2" | (string & {});
|
|
180
|
+
prompt: string;
|
|
181
|
+
}
|
|
182
|
+
export interface ImageResult {
|
|
183
|
+
/** Re-hosted in the village files store; safe to pass to other products. */
|
|
184
|
+
url: string;
|
|
185
|
+
/** TON charged. */
|
|
186
|
+
cost: number;
|
|
187
|
+
call_id: string;
|
|
188
|
+
}
|
|
189
|
+
export interface ToolListing {
|
|
190
|
+
id: string;
|
|
191
|
+
name: string;
|
|
192
|
+
description: string;
|
|
193
|
+
price_ton?: number;
|
|
194
|
+
price?: number;
|
|
195
|
+
unit?: string;
|
|
196
|
+
input?: unknown;
|
|
197
|
+
output?: unknown;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
export interface ToolResult<Output = any> {
|
|
201
|
+
output: Output;
|
|
202
|
+
callId: string | null;
|
|
203
|
+
/** TON charged. */
|
|
204
|
+
amount: number | null;
|
|
205
|
+
replayed: boolean;
|
|
206
|
+
}
|
|
207
|
+
/** Offering field schema shorthand: `{ text: "string", to: "string", tone: "string?" }`. */
|
|
208
|
+
export type FieldSchema = Record<string, string>;
|
|
209
|
+
export interface ListingInput {
|
|
210
|
+
description: string;
|
|
211
|
+
/** TON, 0.1–500. */
|
|
212
|
+
price: number;
|
|
213
|
+
/** Absolute URL the Gateway POSTs paid calls to. */
|
|
214
|
+
endpoint: string;
|
|
215
|
+
input?: FieldSchema | null;
|
|
216
|
+
output?: FieldSchema | null;
|
|
217
|
+
timeout_ms?: number;
|
|
218
|
+
status?: "open" | "paused";
|
|
219
|
+
preview?: boolean;
|
|
220
|
+
}
|
|
221
|
+
export interface Listing extends ListingInput {
|
|
222
|
+
id: string;
|
|
223
|
+
company: string;
|
|
224
|
+
name: string;
|
|
225
|
+
version: number;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
export interface Wallet {
|
|
229
|
+
account: string;
|
|
230
|
+
balance: number;
|
|
231
|
+
held: number;
|
|
232
|
+
available: number;
|
|
233
|
+
}
|
|
234
|
+
export interface LedgerEntry {
|
|
235
|
+
seq: number;
|
|
236
|
+
id: string;
|
|
237
|
+
ts: string;
|
|
238
|
+
kind: string;
|
|
239
|
+
direction: "in" | "out";
|
|
240
|
+
counterparty: string;
|
|
241
|
+
amount: number;
|
|
242
|
+
balance_after: number;
|
|
243
|
+
ref: string | null;
|
|
244
|
+
memo: string | null;
|
|
245
|
+
hold_id?: string | null;
|
|
246
|
+
log_index?: number | null;
|
|
247
|
+
[key: string]: unknown;
|
|
248
|
+
}
|
|
249
|
+
export interface LedgerPage {
|
|
250
|
+
entries: LedgerEntry[];
|
|
251
|
+
/** Pass back as `since` for the next page. */
|
|
252
|
+
next_since: number;
|
|
253
|
+
}
|
|
254
|
+
export interface TransferOptions {
|
|
255
|
+
reason?: string;
|
|
256
|
+
ref?: string;
|
|
257
|
+
idempotencyKey?: string;
|
|
258
|
+
}
|
|
259
|
+
/** `agent/settings.json`, sent with the prompt to `POST /v1/agent/config` (agent stream wire format). */
|
|
260
|
+
export interface AgentSettings {
|
|
261
|
+
model?: "deepseek-v4.1-flash" | "deepseek-v4-pro";
|
|
262
|
+
enabled?: boolean;
|
|
263
|
+
wake?: {
|
|
264
|
+
interval_minutes?: number;
|
|
265
|
+
min_event_gap_seconds?: number;
|
|
266
|
+
};
|
|
267
|
+
budget?: {
|
|
268
|
+
tool_calls_per_wake?: number;
|
|
269
|
+
tokens_per_wake?: number;
|
|
270
|
+
max_turns?: number;
|
|
271
|
+
compute_per_day?: number;
|
|
272
|
+
};
|
|
273
|
+
/** Agent tools offered to the model (default: all). */
|
|
274
|
+
tools?: string[];
|
|
275
|
+
/** Company wallet spend limits, TON. Over `auto_per_payment` an agent payment needs the team's approval. */
|
|
276
|
+
limits?: {
|
|
277
|
+
per_payment?: number;
|
|
278
|
+
per_hour?: number;
|
|
279
|
+
per_day?: number;
|
|
280
|
+
per_payee_day?: number;
|
|
281
|
+
auto_per_payment?: number;
|
|
282
|
+
auto_per_day?: number;
|
|
283
|
+
};
|
|
284
|
+
[key: string]: unknown;
|
|
285
|
+
}
|
|
286
|
+
export interface AgentConfigInput extends AgentSettings {
|
|
287
|
+
/** The text of agent/agent.md. */
|
|
288
|
+
prompt?: string;
|
|
289
|
+
/** Wake the agent once after saving. */
|
|
290
|
+
wake_now?: boolean;
|
|
291
|
+
}
|
|
292
|
+
export interface TranscriptEntry {
|
|
293
|
+
seq: number;
|
|
294
|
+
ts: string;
|
|
295
|
+
kind: string;
|
|
296
|
+
data?: unknown;
|
|
297
|
+
[key: string]: unknown;
|
|
298
|
+
}
|
|
299
|
+
export interface MarketOffering {
|
|
300
|
+
id: string;
|
|
301
|
+
company?: string;
|
|
302
|
+
name: string;
|
|
303
|
+
description: string;
|
|
304
|
+
price: number;
|
|
305
|
+
source?: "company" | "village-tool";
|
|
306
|
+
[key: string]: unknown;
|
|
307
|
+
}
|
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This module wraps the protocol functions with the SDK's error type and event shape.
|
|
10
10
|
*/
|
|
11
|
+
import { type HeaderSource } from "../platform.js";
|
|
11
12
|
import type { WebhookEvent } from "./types.js";
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
13
|
+
/** The three Standard Webhooks headers. */
|
|
14
|
+
export declare const WEBHOOK_HEADERS: {
|
|
15
|
+
readonly id: "webhook-id";
|
|
16
|
+
readonly timestamp: "webhook-timestamp";
|
|
17
|
+
readonly signature: "webhook-signature";
|
|
18
|
+
};
|
|
19
|
+
/** A fresh `whsec_…` signing secret. */
|
|
20
|
+
export declare const generateWebhookSecret: () => string;
|
|
21
|
+
/** The headers that sign `body` (tests, your own senders). */
|
|
22
|
+
export declare const webhookHeaders: (secret: string, id: string, timestamp: number, body: string) => Promise<Record<string, string>>;
|
|
15
23
|
/**
|
|
16
24
|
* Verifies a raw webhook (headers + body exactly as received) and returns the event, or throws
|
|
17
25
|
* `WebhookInvalidError`. Prefer `village.verifyWebhook(req)`, which reads a `Request` for you.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ambasada/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "The Ambasada platform SDK: Sign in with Ambasada, mini-app notifications, the project store, files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"esbuild": "^0.28.2",
|
|
28
28
|
"typescript": "~5.9.3",
|
|
29
29
|
"vitest": "^4.1.12",
|
|
30
|
-
"@ambasada/protocol": "0.1.0"
|
|
30
|
+
"@ambasada/protocol": "0.1.0",
|
|
31
|
+
"@ambasada/village": "0.8.0"
|
|
31
32
|
},
|
|
32
33
|
"author": "CENTYSO (https://centyso.com)",
|
|
33
34
|
"homepage": "https://ambasada.id",
|
|
@@ -41,11 +42,10 @@
|
|
|
41
42
|
},
|
|
42
43
|
"keywords": [
|
|
43
44
|
"ambasada",
|
|
44
|
-
"hack-a-ton",
|
|
45
|
-
"ton",
|
|
46
|
-
"payments",
|
|
47
45
|
"cloudflare",
|
|
48
|
-
"
|
|
46
|
+
"workers",
|
|
47
|
+
"auth",
|
|
48
|
+
"mini-apps"
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "node scripts/build.mjs",
|