@t2000/engine 0.7.7 → 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/dist/index.js CHANGED
@@ -2035,6 +2035,196 @@ var allowanceStatusTool = buildTool({
2035
2035
  };
2036
2036
  }
2037
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
+ });
2038
2228
  var LLAMA_API2 = "https://api.llama.fi";
2039
2229
  var YIELDS_API2 = "https://yields.llama.fi";
2040
2230
  var COINS_API = "https://coins.llama.fi";
@@ -2338,7 +2528,9 @@ var READ_TOOLS = [
2338
2528
  defillamaChainTvlTool,
2339
2529
  defillamaProtocolFeesTool,
2340
2530
  defillamaSuiProtocolsTool,
2341
- allowanceStatusTool
2531
+ allowanceStatusTool,
2532
+ listPaymentLinksTool,
2533
+ listInvoicesTool
2342
2534
  ];
2343
2535
  var WRITE_TOOLS = [
2344
2536
  saveDepositTool,
@@ -2351,7 +2543,9 @@ var WRITE_TOOLS = [
2351
2543
  swapExecuteTool,
2352
2544
  voloStakeTool,
2353
2545
  voloUnstakeTool,
2354
- saveContactTool
2546
+ saveContactTool,
2547
+ createPaymentLinkTool,
2548
+ createInvoiceTool
2355
2549
  ];
2356
2550
  function getDefaultTools() {
2357
2551
  return [...READ_TOOLS, ...WRITE_TOOLS];