@t2000/engine 0.36.1 → 0.36.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/dist/index.js CHANGED
@@ -2394,9 +2394,17 @@ var InvoiceSchema = z.object({
2394
2394
  amount: z.number().positive()
2395
2395
  })).optional().describe("Line items. If omitted, a single line item matching the total is implied.")
2396
2396
  });
2397
+ function internalHeaders(context) {
2398
+ const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2399
+ return {
2400
+ "Content-Type": "application/json",
2401
+ "x-sui-address": context.walletAddress ?? "",
2402
+ ...internalKey ? { "x-internal-key": internalKey } : {}
2403
+ };
2404
+ }
2397
2405
  var createPaymentLinkTool = buildTool({
2398
2406
  name: "create_payment_link",
2399
- 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.',
2407
+ description: 'Create a shareable payment link so someone can send USDC to the user. Returns a URL the user can share. Payers can connect their wallet, scan a QR code, or send manually. Use when the user says "create a payment link", "generate a payment link", "I want to get paid", or similar.',
2400
2408
  inputSchema: PaymentLinkSchema,
2401
2409
  jsonSchema: {
2402
2410
  type: "object",
@@ -2411,20 +2419,15 @@ var createPaymentLinkTool = buildTool({
2411
2419
  isReadOnly: true,
2412
2420
  async call(input, context) {
2413
2421
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2414
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2415
2422
  if (!apiUrl || !context.walletAddress) {
2416
2423
  return { data: null, displayText: "Payment link creation is not available." };
2417
2424
  }
2418
2425
  try {
2419
- const res = await fetch(`${apiUrl}/api/internal/payment-links`, {
2426
+ const res = await fetch(`${apiUrl}/api/internal/payments`, {
2420
2427
  method: "POST",
2421
2428
  signal: context.signal,
2422
- headers: {
2423
- "Content-Type": "application/json",
2424
- "x-sui-address": context.walletAddress,
2425
- ...internalKey ? { "x-internal-key": internalKey } : {}
2426
- },
2427
- body: JSON.stringify(input)
2429
+ headers: internalHeaders(context),
2430
+ body: JSON.stringify({ ...input, type: "link" })
2428
2431
  });
2429
2432
  if (!res.ok) {
2430
2433
  const err = await res.json().catch(() => ({}));
@@ -2434,7 +2437,7 @@ var createPaymentLinkTool = buildTool({
2434
2437
  const amountStr = link.amount != null ? `$${link.amount.toFixed(2)} ${link.currency}` : `any amount ${link.currency}`;
2435
2438
  return {
2436
2439
  data: link,
2437
- displayText: `Payment link created for ${amountStr}${link.label ? ` \u2014 ${link.label}` : ""}. Share: ${link.url}`
2440
+ displayText: `Payment link created for ${amountStr}${link.label ? ` \u2014 ${link.label}` : ""}. Payers can connect their wallet, scan the QR code, or send manually. Share: ${link.url}`
2438
2441
  };
2439
2442
  } catch {
2440
2443
  return { data: null, displayText: "Failed to create payment link." };
@@ -2449,23 +2452,20 @@ var listPaymentLinksTool = buildTool({
2449
2452
  isReadOnly: true,
2450
2453
  async call(_input, context) {
2451
2454
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2452
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2453
2455
  if (!apiUrl || !context.walletAddress) {
2454
2456
  return { data: { links: [] }, displayText: "No payment links found." };
2455
2457
  }
2456
2458
  try {
2457
- const res = await fetch(`${apiUrl}/api/internal/payment-links`, {
2459
+ const res = await fetch(`${apiUrl}/api/internal/payments?type=link`, {
2458
2460
  signal: context.signal,
2459
- headers: {
2460
- "x-sui-address": context.walletAddress,
2461
- ...internalKey ? { "x-internal-key": internalKey } : {}
2462
- }
2461
+ headers: internalHeaders(context)
2463
2462
  });
2464
2463
  if (!res.ok) return { data: { links: [] }, displayText: "Could not fetch payment links." };
2465
- const data = await res.json();
2466
- const count = data.links.length;
2464
+ const raw = await res.json();
2465
+ const links = raw.payments;
2466
+ const count = links.length;
2467
2467
  return {
2468
- data,
2468
+ data: { links },
2469
2469
  displayText: count === 0 ? "No payment links yet." : `${count} payment link${count !== 1 ? "s" : ""} found.`
2470
2470
  };
2471
2471
  } catch {
@@ -2475,7 +2475,7 @@ var listPaymentLinksTool = buildTool({
2475
2475
  });
2476
2476
  var createInvoiceTool = buildTool({
2477
2477
  name: "create_invoice",
2478
- 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.',
2478
+ description: 'Create a formal invoice that the user can share with a client or customer. Returns a URL for the invoice page. Payers can connect their wallet, scan a QR code, or send manually. Use when the user says "create an invoice", "generate an invoice", "bill a client", or similar.',
2479
2479
  inputSchema: InvoiceSchema,
2480
2480
  jsonSchema: {
2481
2481
  type: "object",
@@ -2504,20 +2504,15 @@ var createInvoiceTool = buildTool({
2504
2504
  isReadOnly: true,
2505
2505
  async call(input, context) {
2506
2506
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2507
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2508
2507
  if (!apiUrl || !context.walletAddress) {
2509
2508
  return { data: null, displayText: "Invoice creation is not available." };
2510
2509
  }
2511
2510
  try {
2512
- const res = await fetch(`${apiUrl}/api/internal/invoices`, {
2511
+ const res = await fetch(`${apiUrl}/api/internal/payments`, {
2513
2512
  method: "POST",
2514
2513
  signal: context.signal,
2515
- headers: {
2516
- "Content-Type": "application/json",
2517
- "x-sui-address": context.walletAddress,
2518
- ...internalKey ? { "x-internal-key": internalKey } : {}
2519
- },
2520
- body: JSON.stringify(input)
2514
+ headers: internalHeaders(context),
2515
+ body: JSON.stringify({ ...input, type: "invoice" })
2521
2516
  });
2522
2517
  if (!res.ok) {
2523
2518
  const err = await res.json().catch(() => ({}));
@@ -2527,7 +2522,7 @@ var createInvoiceTool = buildTool({
2527
2522
  const dueStr = invoice.dueDate ? ` due ${new Date(invoice.dueDate).toLocaleDateString()}` : "";
2528
2523
  return {
2529
2524
  data: invoice,
2530
- displayText: `Invoice created for $${invoice.amount.toFixed(2)} ${invoice.currency}${dueStr} \u2014 ${invoice.label}. Share: ${invoice.url}`
2525
+ displayText: `Invoice created for $${invoice.amount.toFixed(2)} ${invoice.currency}${dueStr} \u2014 ${invoice.label}. Payers can connect their wallet, scan the QR code, or send manually. Share: ${invoice.url}`
2531
2526
  };
2532
2527
  } catch {
2533
2528
  return { data: null, displayText: "Failed to create invoice." };
@@ -2550,19 +2545,14 @@ var cancelPaymentLinkTool = buildTool({
2550
2545
  isReadOnly: true,
2551
2546
  async call(input, context) {
2552
2547
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2553
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2554
2548
  if (!apiUrl || !context.walletAddress) {
2555
2549
  return { data: null, displayText: "Payment link cancellation is not available." };
2556
2550
  }
2557
2551
  try {
2558
- const res = await fetch(`${apiUrl}/api/internal/payment-links`, {
2552
+ const res = await fetch(`${apiUrl}/api/internal/payments`, {
2559
2553
  method: "PATCH",
2560
2554
  signal: context.signal,
2561
- headers: {
2562
- "Content-Type": "application/json",
2563
- "x-sui-address": context.walletAddress,
2564
- ...internalKey ? { "x-internal-key": internalKey } : {}
2565
- },
2555
+ headers: internalHeaders(context),
2566
2556
  body: JSON.stringify({ slug: input.slug, action: "cancel" })
2567
2557
  });
2568
2558
  if (!res.ok) {
@@ -2595,19 +2585,14 @@ var cancelInvoiceTool = buildTool({
2595
2585
  isReadOnly: true,
2596
2586
  async call(input, context) {
2597
2587
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2598
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2599
2588
  if (!apiUrl || !context.walletAddress) {
2600
2589
  return { data: null, displayText: "Invoice cancellation is not available." };
2601
2590
  }
2602
2591
  try {
2603
- const res = await fetch(`${apiUrl}/api/internal/invoices`, {
2592
+ const res = await fetch(`${apiUrl}/api/internal/payments`, {
2604
2593
  method: "PATCH",
2605
2594
  signal: context.signal,
2606
- headers: {
2607
- "Content-Type": "application/json",
2608
- "x-sui-address": context.walletAddress,
2609
- ...internalKey ? { "x-internal-key": internalKey } : {}
2610
- },
2595
+ headers: internalHeaders(context),
2611
2596
  body: JSON.stringify({ slug: input.slug, action: "cancel" })
2612
2597
  });
2613
2598
  if (!res.ok) {
@@ -2632,23 +2617,20 @@ var listInvoicesTool = buildTool({
2632
2617
  isReadOnly: true,
2633
2618
  async call(_input, context) {
2634
2619
  const apiUrl = context.env?.ALLOWANCE_API_URL;
2635
- const internalKey = context.env?.AUDRIC_INTERNAL_KEY;
2636
2620
  if (!apiUrl || !context.walletAddress) {
2637
2621
  return { data: { invoices: [] }, displayText: "No invoices found." };
2638
2622
  }
2639
2623
  try {
2640
- const res = await fetch(`${apiUrl}/api/internal/invoices`, {
2624
+ const res = await fetch(`${apiUrl}/api/internal/payments?type=invoice`, {
2641
2625
  signal: context.signal,
2642
- headers: {
2643
- "x-sui-address": context.walletAddress,
2644
- ...internalKey ? { "x-internal-key": internalKey } : {}
2645
- }
2626
+ headers: internalHeaders(context)
2646
2627
  });
2647
2628
  if (!res.ok) return { data: { invoices: [] }, displayText: "Could not fetch invoices." };
2648
- const data = await res.json();
2649
- const count = data.invoices.length;
2629
+ const raw = await res.json();
2630
+ const invoices = raw.payments;
2631
+ const count = invoices.length;
2650
2632
  return {
2651
- data,
2633
+ data: { invoices },
2652
2634
  displayText: count === 0 ? "No invoices yet." : `${count} invoice${count !== 1 ? "s" : ""} found.`
2653
2635
  };
2654
2636
  } catch {