@t2000/engine 0.7.6 → 0.7.8

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 CHANGED
@@ -87,7 +87,7 @@ QueryEngine.submitMessage()
87
87
 
88
88
  ## Built-in Tools
89
89
 
90
- ### Read Tools (19 — parallel, auto-approved)
90
+ ### Read Tools (20 — parallel, auto-approved)
91
91
 
92
92
  | Tool | Description |
93
93
  |------|-------------|
@@ -96,6 +96,7 @@ QueryEngine.submitMessage()
96
96
  | `health_check` | Health factor with risk assessment |
97
97
  | `rates_info` | Current supply/borrow APYs |
98
98
  | `transaction_history` | Recent transaction log |
99
+ | `allowance_status` | Agent budget allowance and permissions |
99
100
  | `explain_tx` | Human-readable transaction explanation from digest |
100
101
  | `web_search` | Web search via Brave Search API |
101
102
  | `swap_quote` | Preview swap route, output amount, and price impact (no execution) |
package/dist/index.d.ts CHANGED
@@ -850,6 +850,7 @@ declare const withdrawTool: Tool<{
850
850
  declare const sendTransferTool: Tool<{
851
851
  amount: number;
852
852
  to: string;
853
+ memo?: string | undefined;
853
854
  }, {
854
855
  success: boolean;
855
856
  tx: string;
@@ -859,6 +860,7 @@ declare const sendTransferTool: Tool<{
859
860
  gasCost: number;
860
861
  gasMethod: _t2000_sdk.GasMethod;
861
862
  balance: _t2000_sdk.BalanceResponse;
863
+ memo: string | null;
862
864
  }>;
863
865
 
864
866
  declare const borrowTool: Tool<{
package/dist/index.js CHANGED
@@ -1135,7 +1135,8 @@ var sendTransferTool = buildTool({
1135
1135
  description: "Send USDC to another Sui address or contact name. Validates the address, checks balance, and executes the on-chain transfer. Returns tx hash, gas cost, and updated balance.",
1136
1136
  inputSchema: z.object({
1137
1137
  to: z.string().min(1),
1138
- amount: z.number().positive()
1138
+ amount: z.number().positive(),
1139
+ memo: z.string().optional()
1139
1140
  }),
1140
1141
  jsonSchema: {
1141
1142
  type: "object",
@@ -1147,6 +1148,10 @@ var sendTransferTool = buildTool({
1147
1148
  amount: {
1148
1149
  type: "number",
1149
1150
  description: "Amount in USD to send"
1151
+ },
1152
+ memo: {
1153
+ type: "string",
1154
+ description: "Optional note attached to the transfer (shown in transaction receipt)"
1150
1155
  }
1151
1156
  },
1152
1157
  required: ["to", "amount"]
@@ -1165,7 +1170,8 @@ var sendTransferTool = buildTool({
1165
1170
  contactName: result.contactName,
1166
1171
  gasCost: result.gasCost,
1167
1172
  gasMethod: result.gasMethod,
1168
- balance: result.balance
1173
+ balance: result.balance,
1174
+ memo: input.memo ?? null
1169
1175
  },
1170
1176
  displayText: `Sent $${result.amount.toFixed(2)} to ${result.contactName ?? result.to.slice(0, 10)}\u2026 (tx: ${result.tx.slice(0, 8)}\u2026)`
1171
1177
  };
@@ -1295,7 +1301,15 @@ var payApiTool = buildTool({
1295
1301
 
1296
1302
  Use mpp_services tool first to discover available services and get the correct endpoint URL, required body parameters, and pricing. Then call this tool with the full URL and JSON body.
1297
1303
 
1298
- Always use POST. Construct the URL from the gateway base + service path. Pass parameters as a JSON string in body.`,
1304
+ Always use POST. Construct the URL from the gateway base + service path. Pass parameters as a JSON string in body.
1305
+
1306
+ CRITICAL \u2014 non-retryable errors: If the result contains "doNotRetry": true or "paymentConfirmed": true, the user has ALREADY been charged. NEVER call pay_api again for the same request. Report the error to the user.
1307
+
1308
+ Lob (postcards/letters) \u2014 MULTI-STEP, NEVER skip:
1309
+ 1. Generate design image FIRST via fal/fal-ai/flux/dev ($0.03). Show the image to the user as markdown ![design](url).
1310
+ 2. Ask the user to confirm before mailing ("Here's the design. Print and mail for $1.00?").
1311
+ 3. ONLY after user confirms: call lob/v1/postcards with the image URL in the front HTML (<img src="URL" style="width:100%;height:100%;object-fit:cover"/>).
1312
+ Always use ISO-3166 country codes (GB not UK, US not USA). A return address ("from") is added automatically \u2014 do not include one.`,
1299
1313
  inputSchema: z.object({
1300
1314
  url: z.string().url(),
1301
1315
  method: z.enum(["GET", "POST", "PUT", "DELETE"]).optional(),
@@ -1971,6 +1985,246 @@ Risks: ${riskFactors.join("; ")}`
1971
1985
  };
1972
1986
  }
1973
1987
  });
1988
+ var allowanceStatusTool = buildTool({
1989
+ name: "allowance_status",
1990
+ description: "Check the agent spending allowance status: whether it is enabled, the daily USDC limit, amount spent today, remaining budget, which service categories are permitted, and when the budget resets. Use this when the user asks about their agent budget, spending limits, or autonomous transaction permissions.",
1991
+ inputSchema: z.object({}),
1992
+ jsonSchema: { type: "object", properties: {}, required: [] },
1993
+ isReadOnly: true,
1994
+ async call(_input, context) {
1995
+ if (!context.env?.ALLOWANCE_API_URL || !context.walletAddress) {
1996
+ return {
1997
+ data: {
1998
+ enabled: false,
1999
+ dailyLimit: 0,
2000
+ spent: 0,
2001
+ remaining: 0,
2002
+ permissions: [],
2003
+ resetsAt: null
2004
+ },
2005
+ displayText: "Agent allowance is not configured."
2006
+ };
2007
+ }
2008
+ const disabledResult = {
2009
+ data: {
2010
+ enabled: false,
2011
+ dailyLimit: 0,
2012
+ spent: 0,
2013
+ remaining: 0,
2014
+ permissions: [],
2015
+ resetsAt: null
2016
+ },
2017
+ displayText: "Unable to fetch allowance status."
2018
+ };
2019
+ let allowance;
2020
+ try {
2021
+ const url = `${context.env.ALLOWANCE_API_URL}/api/allowance/${context.walletAddress}`;
2022
+ const res = await fetch(url, {
2023
+ signal: context.signal,
2024
+ headers: context.env.AUDRIC_INTERNAL_KEY ? { "x-internal-key": context.env.AUDRIC_INTERNAL_KEY } : void 0
2025
+ });
2026
+ if (!res.ok) return disabledResult;
2027
+ allowance = await res.json();
2028
+ } catch {
2029
+ return disabledResult;
2030
+ }
2031
+ const statusText = allowance.enabled ? `Allowance active: $${allowance.spent.toFixed(2)} / $${allowance.dailyLimit.toFixed(2)} used today. ${allowance.permissions.length} service categories enabled.` : "Agent allowance is disabled.";
2032
+ return {
2033
+ data: allowance,
2034
+ displayText: statusText
2035
+ };
2036
+ }
2037
+ });
2038
+ var PaymentLinkSchema = z.object({
2039
+ amount: z.number().positive().optional().describe("Amount in USDC. Omit for open-amount links."),
2040
+ label: z.string().optional().describe('Human-readable label e.g. "Consulting fee March"'),
2041
+ memo: z.string().optional().describe("Optional note shown to the payer"),
2042
+ expiresInHours: z.number().positive().optional().describe("Hours until the link expires. Omit for permanent links.")
2043
+ });
2044
+ var InvoiceSchema = z.object({
2045
+ amount: z.number().positive().describe("Total invoice amount in USDC"),
2046
+ label: z.string().describe('Invoice title e.g. "Web design \u2014 March 2026"'),
2047
+ memo: z.string().optional().describe("Optional note or payment terms"),
2048
+ recipientName: z.string().optional().describe("Name of the person or company being invoiced"),
2049
+ recipientEmail: z.string().optional().describe("Email address of the recipient"),
2050
+ dueDays: z.number().int().positive().optional().describe("Days until payment is due. Omit for no due date."),
2051
+ items: z.array(z.object({
2052
+ description: z.string(),
2053
+ amount: z.number().positive()
2054
+ })).optional().describe("Line items. If omitted, a single line item matching the total is implied.")
2055
+ });
2056
+ var createPaymentLinkTool = buildTool({
2057
+ name: "create_payment_link",
2058
+ description: 'Create a shareable payment link so someone can send USDC to the user. Returns a URL the user can share. Use when the user says "create a payment link", "generate a payment link", "I want to get paid", or similar.',
2059
+ inputSchema: PaymentLinkSchema,
2060
+ jsonSchema: {
2061
+ type: "object",
2062
+ properties: {
2063
+ amount: { type: "number", description: "Amount in USDC. Omit for open-amount links." },
2064
+ label: { type: "string", description: 'Human-readable label e.g. "Consulting fee March"' },
2065
+ memo: { type: "string", description: "Optional note shown to the payer" },
2066
+ expiresInHours: { type: "number", description: "Hours until the link expires. Omit for permanent links." }
2067
+ },
2068
+ required: []
2069
+ },
2070
+ isReadOnly: false,
2071
+ async call(input, context) {
2072
+ const apiUrl = context.env?.ALLOWANCE_API_URL;
2073
+ const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2074
+ if (!apiUrl || !context.walletAddress) {
2075
+ return { data: null, displayText: "Payment link creation is not available." };
2076
+ }
2077
+ try {
2078
+ const res = await fetch(`${apiUrl}/api/internal/payment-links`, {
2079
+ method: "POST",
2080
+ signal: context.signal,
2081
+ headers: {
2082
+ "Content-Type": "application/json",
2083
+ "x-sui-address": context.walletAddress,
2084
+ ...internalKey ? { "x-internal-key": internalKey } : {}
2085
+ },
2086
+ body: JSON.stringify(input)
2087
+ });
2088
+ if (!res.ok) {
2089
+ const err = await res.json().catch(() => ({}));
2090
+ return { data: null, displayText: err.error ?? "Failed to create payment link." };
2091
+ }
2092
+ const link = await res.json();
2093
+ const amountStr = link.amount != null ? `$${link.amount.toFixed(2)} ${link.currency}` : `any amount ${link.currency}`;
2094
+ return {
2095
+ data: link,
2096
+ displayText: `Payment link created for ${amountStr}${link.label ? ` \u2014 ${link.label}` : ""}. Share: ${link.url}`
2097
+ };
2098
+ } catch {
2099
+ return { data: null, displayText: "Failed to create payment link." };
2100
+ }
2101
+ }
2102
+ });
2103
+ var listPaymentLinksTool = buildTool({
2104
+ name: "list_payment_links",
2105
+ description: `List the user's payment links \u2014 active, paid, expired, and cancelled. Use when the user asks "show my payment links", "what payment links do I have", or wants to check payment status.`,
2106
+ inputSchema: z.object({}),
2107
+ jsonSchema: { type: "object", properties: {}, required: [] },
2108
+ isReadOnly: true,
2109
+ async call(_input, context) {
2110
+ const apiUrl = context.env?.ALLOWANCE_API_URL;
2111
+ const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2112
+ if (!apiUrl || !context.walletAddress) {
2113
+ return { data: { links: [] }, displayText: "No payment links found." };
2114
+ }
2115
+ try {
2116
+ const res = await fetch(`${apiUrl}/api/internal/payment-links`, {
2117
+ signal: context.signal,
2118
+ headers: {
2119
+ "x-sui-address": context.walletAddress,
2120
+ ...internalKey ? { "x-internal-key": internalKey } : {}
2121
+ }
2122
+ });
2123
+ if (!res.ok) return { data: { links: [] }, displayText: "Could not fetch payment links." };
2124
+ const data = await res.json();
2125
+ const count = data.links.length;
2126
+ return {
2127
+ data,
2128
+ displayText: count === 0 ? "No payment links yet." : `${count} payment link${count !== 1 ? "s" : ""} found.`
2129
+ };
2130
+ } catch {
2131
+ return { data: { links: [] }, displayText: "Could not fetch payment links." };
2132
+ }
2133
+ }
2134
+ });
2135
+ var createInvoiceTool = buildTool({
2136
+ name: "create_invoice",
2137
+ description: 'Create a formal invoice that the user can share with a client or customer. Returns a URL for the invoice page. Use when the user says "create an invoice", "generate an invoice", "bill a client", or similar.',
2138
+ inputSchema: InvoiceSchema,
2139
+ jsonSchema: {
2140
+ type: "object",
2141
+ properties: {
2142
+ amount: { type: "number", description: "Total invoice amount in USDC" },
2143
+ label: { type: "string", description: 'Invoice title e.g. "Web design \u2014 March 2026"' },
2144
+ memo: { type: "string", description: "Optional note or payment terms" },
2145
+ recipientName: { type: "string", description: "Name of the person or company being invoiced" },
2146
+ recipientEmail: { type: "string", description: "Email address of the recipient" },
2147
+ dueDays: { type: "number", description: "Days until payment is due. Omit for no due date." },
2148
+ items: {
2149
+ type: "array",
2150
+ items: {
2151
+ type: "object",
2152
+ properties: {
2153
+ description: { type: "string" },
2154
+ amount: { type: "number" }
2155
+ },
2156
+ required: ["description", "amount"]
2157
+ },
2158
+ description: "Line items. If omitted, a single line item matching the total is implied."
2159
+ }
2160
+ },
2161
+ required: ["amount", "label"]
2162
+ },
2163
+ isReadOnly: false,
2164
+ async call(input, context) {
2165
+ const apiUrl = context.env?.ALLOWANCE_API_URL;
2166
+ const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2167
+ if (!apiUrl || !context.walletAddress) {
2168
+ return { data: null, displayText: "Invoice creation is not available." };
2169
+ }
2170
+ try {
2171
+ const res = await fetch(`${apiUrl}/api/internal/invoices`, {
2172
+ method: "POST",
2173
+ signal: context.signal,
2174
+ headers: {
2175
+ "Content-Type": "application/json",
2176
+ "x-sui-address": context.walletAddress,
2177
+ ...internalKey ? { "x-internal-key": internalKey } : {}
2178
+ },
2179
+ body: JSON.stringify(input)
2180
+ });
2181
+ if (!res.ok) {
2182
+ const err = await res.json().catch(() => ({}));
2183
+ return { data: null, displayText: err.error ?? "Failed to create invoice." };
2184
+ }
2185
+ const invoice = await res.json();
2186
+ const dueStr = invoice.dueDate ? ` due ${new Date(invoice.dueDate).toLocaleDateString()}` : "";
2187
+ return {
2188
+ data: invoice,
2189
+ displayText: `Invoice created for $${invoice.amount.toFixed(2)} ${invoice.currency}${dueStr} \u2014 ${invoice.label}. Share: ${invoice.url}`
2190
+ };
2191
+ } catch {
2192
+ return { data: null, displayText: "Failed to create invoice." };
2193
+ }
2194
+ }
2195
+ });
2196
+ var listInvoicesTool = buildTool({
2197
+ name: "list_invoices",
2198
+ description: `List the user's invoices \u2014 pending, overdue, paid, and cancelled. Use when the user asks "show my invoices", "what invoices do I have", or wants to check invoice status.`,
2199
+ inputSchema: z.object({}),
2200
+ jsonSchema: { type: "object", properties: {}, required: [] },
2201
+ isReadOnly: true,
2202
+ async call(_input, context) {
2203
+ const apiUrl = context.env?.ALLOWANCE_API_URL;
2204
+ const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2205
+ if (!apiUrl || !context.walletAddress) {
2206
+ return { data: { invoices: [] }, displayText: "No invoices found." };
2207
+ }
2208
+ try {
2209
+ const res = await fetch(`${apiUrl}/api/internal/invoices`, {
2210
+ signal: context.signal,
2211
+ headers: {
2212
+ "x-sui-address": context.walletAddress,
2213
+ ...internalKey ? { "x-internal-key": internalKey } : {}
2214
+ }
2215
+ });
2216
+ if (!res.ok) return { data: { invoices: [] }, displayText: "Could not fetch invoices." };
2217
+ const data = await res.json();
2218
+ const count = data.invoices.length;
2219
+ return {
2220
+ data,
2221
+ displayText: count === 0 ? "No invoices yet." : `${count} invoice${count !== 1 ? "s" : ""} found.`
2222
+ };
2223
+ } catch {
2224
+ return { data: { invoices: [] }, displayText: "Could not fetch invoices." };
2225
+ }
2226
+ }
2227
+ });
1974
2228
  var LLAMA_API2 = "https://api.llama.fi";
1975
2229
  var YIELDS_API2 = "https://yields.llama.fi";
1976
2230
  var COINS_API = "https://coins.llama.fi";
@@ -2273,7 +2527,10 @@ var READ_TOOLS = [
2273
2527
  defillamaPriceChangeTool,
2274
2528
  defillamaChainTvlTool,
2275
2529
  defillamaProtocolFeesTool,
2276
- defillamaSuiProtocolsTool
2530
+ defillamaSuiProtocolsTool,
2531
+ allowanceStatusTool,
2532
+ listPaymentLinksTool,
2533
+ listInvoicesTool
2277
2534
  ];
2278
2535
  var WRITE_TOOLS = [
2279
2536
  saveDepositTool,
@@ -2286,7 +2543,9 @@ var WRITE_TOOLS = [
2286
2543
  swapExecuteTool,
2287
2544
  voloStakeTool,
2288
2545
  voloUnstakeTool,
2289
- saveContactTool
2546
+ saveContactTool,
2547
+ createPaymentLinkTool,
2548
+ createInvoiceTool
2290
2549
  ];
2291
2550
  function getDefaultTools() {
2292
2551
  return [...READ_TOOLS, ...WRITE_TOOLS];