@anuma/sdk 8.0.1 → 8.1.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.
@@ -20933,6 +20933,17 @@ function missingConfirmFields(action, parameters) {
20933
20933
  return requirement.fields.filter((field10) => !shown.has(field10));
20934
20934
  }
20935
20935
 
20936
+ // src/tools/walletPaymentConstants.ts
20937
+ var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
20938
+ var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
20939
+ var FLIGHT_BOOK_TOOL_SET = "flight-book";
20940
+ var FLIGHT_SERVER_TOOL_NAMES = [
20941
+ "AnumaPaymentsMCP-anuma_search_flights",
20942
+ "AnumaPaymentsMCP-anuma_flight_offer_details",
20943
+ "AnumaPaymentsMCP-anuma_create_flight_intent",
20944
+ "AnumaPaymentsMCP-anuma_get_flight_booking"
20945
+ ];
20946
+
20936
20947
  // src/lib/chat/toolLoop.ts
20937
20948
  init_redactor();
20938
20949
 
@@ -21486,7 +21497,8 @@ var BUILT_IN_TOOL_SETS = [
21486
21497
  "AnumaPaymentsMCP-anuma_cancel_reservation"
21487
21498
  ],
21488
21499
  anchors: []
21489
- }
21500
+ },
21501
+ { name: FLIGHT_BOOK_TOOL_SET, members: [...FLIGHT_SERVER_TOOL_NAMES], anchors: [] }
21490
21502
  ];
21491
21503
  var CONFIRMED_ACTION_TOOL_SETS = /* @__PURE__ */ new Map([
21492
21504
  ["book_restaurant", "restaurant-book"],
@@ -21618,6 +21630,16 @@ var SERVER_TOOL_DEPENDENCY_SETS = [
21618
21630
  members: ["AnumaPaymentsMCP-anuma_list_reservations"],
21619
21631
  anchors: ["AnumaPaymentsMCP-anuma_cancel_reservation"],
21620
21632
  anchorMinSimilarity: 0.5
21633
+ },
21634
+ {
21635
+ name: "flight-book-lookup",
21636
+ members: [
21637
+ "AnumaPaymentsMCP-anuma_flight_offer_details",
21638
+ "AnumaPaymentsMCP-anuma_create_flight_intent",
21639
+ "AnumaPaymentsMCP-anuma_get_flight_booking"
21640
+ ],
21641
+ anchors: ["AnumaPaymentsMCP-anuma_search_flights"],
21642
+ anchorMinSimilarity: 0.5
21621
21643
  }
21622
21644
  ];
21623
21645
  var defaultServerToolsFilter = createServerToolsFilter({
@@ -23905,7 +23927,14 @@ function getToolName(tool) {
23905
23927
  function toolsAfterConfirmation(apiTools, executionResults) {
23906
23928
  const members = /* @__PURE__ */ new Set();
23907
23929
  let keepConfirm = false;
23930
+ let keepPaymentTools = false;
23908
23931
  for (const r of executionResults) {
23932
+ if (r.name === SELECT_PAYMENT_WALLET_TOOL_NAME && r.result?.confirmed === true) {
23933
+ const flightSet = BUILT_IN_TOOL_SETS.find((s) => s.name === FLIGHT_BOOK_TOOL_SET);
23934
+ for (const member of flightSet?.members ?? []) members.add(member);
23935
+ keepPaymentTools = true;
23936
+ continue;
23937
+ }
23909
23938
  if (r.name !== CONFIRM_TOOL_NAME) continue;
23910
23939
  const answer = r.result;
23911
23940
  if (answer?.confirmed !== true || typeof answer.action !== "string") continue;
@@ -23917,7 +23946,7 @@ function toolsAfterConfirmation(apiTools, executionResults) {
23917
23946
  if (!apiTools.some((t) => members.has(getToolName(t) ?? ""))) return void 0;
23918
23947
  return apiTools.filter((t) => {
23919
23948
  const name = getToolName(t) ?? "";
23920
- return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME;
23949
+ return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME || keepPaymentTools && (name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME);
23921
23950
  });
23922
23951
  }
23923
23952
  var STREAM_RESUMABLE_HEADER = "X-Stream-Resumable";
@@ -26309,6 +26338,9 @@ __decorateClass([
26309
26338
  __decorateClass([
26310
26339
  (0, import_decorators10.text)("personality")
26311
26340
  ], UserPreference.prototype, "personality", 2);
26341
+ __decorateClass([
26342
+ (0, import_decorators10.text)("external_wallets")
26343
+ ], UserPreference.prototype, "externalWallets", 2);
26312
26344
  __decorateClass([
26313
26345
  (0, import_decorators10.field)("created_at")
26314
26346
  ], UserPreference.prototype, "createdAt", 2);
@@ -26346,7 +26378,7 @@ __decorateClass([
26346
26378
  ], VaultFolder.prototype, "context", 2);
26347
26379
 
26348
26380
  // src/lib/db/schema.ts
26349
- var SDK_SCHEMA_VERSION = 48;
26381
+ var SDK_SCHEMA_VERSION = 49;
26350
26382
  var sdkSchema = (0, import_watermelondb15.appSchema)({
26351
26383
  version: SDK_SCHEMA_VERSION,
26352
26384
  tables: [
@@ -26432,6 +26464,7 @@ var sdkSchema = (0, import_watermelondb15.appSchema)({
26432
26464
  { name: "description", type: "string", isOptional: true },
26433
26465
  { name: "models", type: "string", isOptional: true },
26434
26466
  { name: "personality", type: "string", isOptional: true },
26467
+ { name: "external_wallets", type: "string", isOptional: true },
26435
26468
  { name: "created_at", type: "number" },
26436
26469
  { name: "updated_at", type: "number" }
26437
26470
  ]
@@ -27136,6 +27169,15 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
27136
27169
  "UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
27137
27170
  )
27138
27171
  ]
27172
+ },
27173
+ {
27174
+ toVersion: 49,
27175
+ steps: [
27176
+ (0, import_migrations.addColumns)({
27177
+ table: "userPreferences",
27178
+ columns: [{ name: "external_wallets", type: "string", isOptional: true }]
27179
+ })
27180
+ ]
27139
27181
  }
27140
27182
  ]
27141
27183
  });
@@ -30325,6 +30367,7 @@ function userPreferenceToStored(preference) {
30325
30367
  description: preference.description,
30326
30368
  models: preference.models,
30327
30369
  personality: preference.personality,
30370
+ externalWallets: preference.externalWallets,
30328
30371
  createdAt: preference.createdAt,
30329
30372
  updatedAt: preference.updatedAt
30330
30373
  };
@@ -30343,6 +30386,7 @@ async function createUserPreferenceOp(ctx, opts) {
30343
30386
  if (opts.description) pref._setRaw("description", opts.description);
30344
30387
  if (opts.models) pref._setRaw("models", opts.models);
30345
30388
  if (opts.personality) pref._setRaw("personality", opts.personality);
30389
+ if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
30346
30390
  pref._setRaw("created_at", now);
30347
30391
  pref._setRaw("updated_at", now);
30348
30392
  });
@@ -30370,6 +30414,9 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
30370
30414
  if (opts.personality !== void 0) {
30371
30415
  pref._setRaw("personality", opts.personality || null);
30372
30416
  }
30417
+ if (opts.externalWallets !== void 0) {
30418
+ pref._setRaw("external_wallets", opts.externalWallets || null);
30419
+ }
30373
30420
  pref._setRaw("updated_at", Date.now());
30374
30421
  });
30375
30422
  });
@@ -30397,6 +30444,9 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
30397
30444
  if (opts.personality !== void 0) {
30398
30445
  pref._setRaw("personality", opts.personality || null);
30399
30446
  }
30447
+ if (opts.externalWallets !== void 0) {
30448
+ pref._setRaw("external_wallets", opts.externalWallets || null);
30449
+ }
30400
30450
  pref._setRaw("updated_at", now);
30401
30451
  });
30402
30452
  return preference;
@@ -30408,6 +30458,7 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
30408
30458
  if (opts.description) pref._setRaw("description", opts.description);
30409
30459
  if (opts.models) pref._setRaw("models", opts.models);
30410
30460
  if (opts.personality) pref._setRaw("personality", opts.personality);
30461
+ if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
30411
30462
  pref._setRaw("created_at", now);
30412
30463
  pref._setRaw("updated_at", now);
30413
30464
  });
@@ -39754,10 +39805,18 @@ function hasSql(clauses) {
39754
39805
  (clause) => clause.type === "sql" || "conditions" in clause && hasSql(clause.conditions)
39755
39806
  );
39756
39807
  }
39808
+ function encodeSqlParameters(sql, values) {
39809
+ if (values.length === 0) return sql;
39810
+ const tokens = /[eE]'(?:\\[\s\S]|''|[^'\\])*'|'(?:''|[^'])*'|"(?:""|[^"])*"|(\$(?:[a-zA-Z_]\w*)?\$)[\s\S]*?\1|--[^\r\n]*|\/\*[\s\S]*?\*\/|\$\d+|\?/g;
39811
+ if (sql.match(tokens)?.some((token) => /^\$\d+$/.test(token))) return sql;
39812
+ let index = 0;
39813
+ return sql.replace(tokens, (token) => token === "?" ? `$${++index}` : token);
39814
+ }
39757
39815
  function encodeQuery(query, qualify, countMode = false, idsOnly = false) {
39758
39816
  const { table, description, associations } = query;
39759
39817
  if (description.sql) {
39760
- return [description.sql.sql, description.sql.values];
39818
+ const { sql, values } = description.sql;
39819
+ return [encodeSqlParameters(sql, values), values];
39761
39820
  }
39762
39821
  const params = [];
39763
39822
  const hasToManyJoins = associations.some((a) => a.info.type === "has_many");
@@ -7949,7 +7949,7 @@ declare function deleteConversationSummaryOp(ctx: SummaryOperationsContext, conv
7949
7949
  * - v48: Added kind, kind_value (encrypted) and level to memory_vault; level is
7950
7950
  * backfilled from scope where SQL steps run
7951
7951
  */
7952
- declare const SDK_SCHEMA_VERSION = 48;
7952
+ declare const SDK_SCHEMA_VERSION = 49;
7953
7953
  /**
7954
7954
  * Combined WatermelonDB schema for all SDK storage modules.
7955
7955
  *
@@ -8908,6 +8908,7 @@ declare class UserPreference extends Model {
8908
8908
  description?: string;
8909
8909
  models?: string;
8910
8910
  personality?: string;
8911
+ externalWallets?: string;
8911
8912
  createdAt: number;
8912
8913
  updatedAt: number;
8913
8914
  }
@@ -8961,6 +8962,8 @@ interface StoredUserPreference {
8961
8962
  description?: string;
8962
8963
  models?: string;
8963
8964
  personality?: string;
8965
+ /** JSON array of the user's saved external wallets, stored as given. */
8966
+ externalWallets?: string;
8964
8967
  createdAt: number;
8965
8968
  updatedAt: number;
8966
8969
  }
@@ -8974,6 +8977,7 @@ interface CreateUserPreferenceOptions {
8974
8977
  description?: string;
8975
8978
  models?: string;
8976
8979
  personality?: string;
8980
+ externalWallets?: string;
8977
8981
  }
8978
8982
  /**
8979
8983
  * Options for updating an existing user preference record
@@ -8984,6 +8988,7 @@ interface UpdateUserPreferenceOptions {
8984
8988
  description?: string;
8985
8989
  models?: string;
8986
8990
  personality?: string;
8991
+ externalWallets?: string;
8987
8992
  }
8988
8993
  /**
8989
8994
  * Profile-only update options
@@ -7949,7 +7949,7 @@ declare function deleteConversationSummaryOp(ctx: SummaryOperationsContext, conv
7949
7949
  * - v48: Added kind, kind_value (encrypted) and level to memory_vault; level is
7950
7950
  * backfilled from scope where SQL steps run
7951
7951
  */
7952
- declare const SDK_SCHEMA_VERSION = 48;
7952
+ declare const SDK_SCHEMA_VERSION = 49;
7953
7953
  /**
7954
7954
  * Combined WatermelonDB schema for all SDK storage modules.
7955
7955
  *
@@ -8908,6 +8908,7 @@ declare class UserPreference extends Model {
8908
8908
  description?: string;
8909
8909
  models?: string;
8910
8910
  personality?: string;
8911
+ externalWallets?: string;
8911
8912
  createdAt: number;
8912
8913
  updatedAt: number;
8913
8914
  }
@@ -8961,6 +8962,8 @@ interface StoredUserPreference {
8961
8962
  description?: string;
8962
8963
  models?: string;
8963
8964
  personality?: string;
8965
+ /** JSON array of the user's saved external wallets, stored as given. */
8966
+ externalWallets?: string;
8964
8967
  createdAt: number;
8965
8968
  updatedAt: number;
8966
8969
  }
@@ -8974,6 +8977,7 @@ interface CreateUserPreferenceOptions {
8974
8977
  description?: string;
8975
8978
  models?: string;
8976
8979
  personality?: string;
8980
+ externalWallets?: string;
8977
8981
  }
8978
8982
  /**
8979
8983
  * Options for updating an existing user preference record
@@ -8984,6 +8988,7 @@ interface UpdateUserPreferenceOptions {
8984
8988
  description?: string;
8985
8989
  models?: string;
8986
8990
  personality?: string;
8991
+ externalWallets?: string;
8987
8992
  }
8988
8993
  /**
8989
8994
  * Profile-only update options
@@ -19242,6 +19242,17 @@ function missingConfirmFields(action, parameters) {
19242
19242
  return requirement.fields.filter((field10) => !shown.has(field10));
19243
19243
  }
19244
19244
 
19245
+ // src/tools/walletPaymentConstants.ts
19246
+ var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
19247
+ var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
19248
+ var FLIGHT_BOOK_TOOL_SET = "flight-book";
19249
+ var FLIGHT_SERVER_TOOL_NAMES = [
19250
+ "AnumaPaymentsMCP-anuma_search_flights",
19251
+ "AnumaPaymentsMCP-anuma_flight_offer_details",
19252
+ "AnumaPaymentsMCP-anuma_create_flight_intent",
19253
+ "AnumaPaymentsMCP-anuma_get_flight_booking"
19254
+ ];
19255
+
19245
19256
  // src/lib/storage/mcpImages.ts
19246
19257
  var IMAGE_TOOL_NAMES = /* @__PURE__ */ new Set([
19247
19258
  "AnumaMediaMCP-anuma_create_image",
@@ -19791,7 +19802,8 @@ var BUILT_IN_TOOL_SETS = [
19791
19802
  "AnumaPaymentsMCP-anuma_cancel_reservation"
19792
19803
  ],
19793
19804
  anchors: []
19794
- }
19805
+ },
19806
+ { name: FLIGHT_BOOK_TOOL_SET, members: [...FLIGHT_SERVER_TOOL_NAMES], anchors: [] }
19795
19807
  ];
19796
19808
  var CONFIRMED_ACTION_TOOL_SETS = /* @__PURE__ */ new Map([
19797
19809
  ["book_restaurant", "restaurant-book"],
@@ -19923,6 +19935,16 @@ var SERVER_TOOL_DEPENDENCY_SETS = [
19923
19935
  members: ["AnumaPaymentsMCP-anuma_list_reservations"],
19924
19936
  anchors: ["AnumaPaymentsMCP-anuma_cancel_reservation"],
19925
19937
  anchorMinSimilarity: 0.5
19938
+ },
19939
+ {
19940
+ name: "flight-book-lookup",
19941
+ members: [
19942
+ "AnumaPaymentsMCP-anuma_flight_offer_details",
19943
+ "AnumaPaymentsMCP-anuma_create_flight_intent",
19944
+ "AnumaPaymentsMCP-anuma_get_flight_booking"
19945
+ ],
19946
+ anchors: ["AnumaPaymentsMCP-anuma_search_flights"],
19947
+ anchorMinSimilarity: 0.5
19926
19948
  }
19927
19949
  ];
19928
19950
  var defaultServerToolsFilter = createServerToolsFilter({
@@ -22206,7 +22228,14 @@ function getToolName(tool) {
22206
22228
  function toolsAfterConfirmation(apiTools, executionResults) {
22207
22229
  const members = /* @__PURE__ */ new Set();
22208
22230
  let keepConfirm = false;
22231
+ let keepPaymentTools = false;
22209
22232
  for (const r of executionResults) {
22233
+ if (r.name === SELECT_PAYMENT_WALLET_TOOL_NAME && r.result?.confirmed === true) {
22234
+ const flightSet = BUILT_IN_TOOL_SETS.find((s) => s.name === FLIGHT_BOOK_TOOL_SET);
22235
+ for (const member of flightSet?.members ?? []) members.add(member);
22236
+ keepPaymentTools = true;
22237
+ continue;
22238
+ }
22210
22239
  if (r.name !== CONFIRM_TOOL_NAME) continue;
22211
22240
  const answer = r.result;
22212
22241
  if (answer?.confirmed !== true || typeof answer.action !== "string") continue;
@@ -22218,7 +22247,7 @@ function toolsAfterConfirmation(apiTools, executionResults) {
22218
22247
  if (!apiTools.some((t) => members.has(getToolName(t) ?? ""))) return void 0;
22219
22248
  return apiTools.filter((t) => {
22220
22249
  const name = getToolName(t) ?? "";
22221
- return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME;
22250
+ return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME || keepPaymentTools && (name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME);
22222
22251
  });
22223
22252
  }
22224
22253
  var STREAM_RESUMABLE_HEADER = "X-Stream-Resumable";
@@ -24604,6 +24633,9 @@ __decorateClass([
24604
24633
  __decorateClass([
24605
24634
  (0, import_decorators10.text)("personality")
24606
24635
  ], UserPreference.prototype, "personality", 2);
24636
+ __decorateClass([
24637
+ (0, import_decorators10.text)("external_wallets")
24638
+ ], UserPreference.prototype, "externalWallets", 2);
24607
24639
  __decorateClass([
24608
24640
  (0, import_decorators10.field)("created_at")
24609
24641
  ], UserPreference.prototype, "createdAt", 2);
@@ -24641,7 +24673,7 @@ __decorateClass([
24641
24673
  ], VaultFolder.prototype, "context", 2);
24642
24674
 
24643
24675
  // src/lib/db/schema.ts
24644
- var SDK_SCHEMA_VERSION = 48;
24676
+ var SDK_SCHEMA_VERSION = 49;
24645
24677
  var sdkSchema = (0, import_watermelondb15.appSchema)({
24646
24678
  version: SDK_SCHEMA_VERSION,
24647
24679
  tables: [
@@ -24727,6 +24759,7 @@ var sdkSchema = (0, import_watermelondb15.appSchema)({
24727
24759
  { name: "description", type: "string", isOptional: true },
24728
24760
  { name: "models", type: "string", isOptional: true },
24729
24761
  { name: "personality", type: "string", isOptional: true },
24762
+ { name: "external_wallets", type: "string", isOptional: true },
24730
24763
  { name: "created_at", type: "number" },
24731
24764
  { name: "updated_at", type: "number" }
24732
24765
  ]
@@ -25431,6 +25464,15 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
25431
25464
  "UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
25432
25465
  )
25433
25466
  ]
25467
+ },
25468
+ {
25469
+ toVersion: 49,
25470
+ steps: [
25471
+ (0, import_migrations.addColumns)({
25472
+ table: "userPreferences",
25473
+ columns: [{ name: "external_wallets", type: "string", isOptional: true }]
25474
+ })
25475
+ ]
25434
25476
  }
25435
25477
  ]
25436
25478
  });
@@ -28614,6 +28656,7 @@ function userPreferenceToStored(preference) {
28614
28656
  description: preference.description,
28615
28657
  models: preference.models,
28616
28658
  personality: preference.personality,
28659
+ externalWallets: preference.externalWallets,
28617
28660
  createdAt: preference.createdAt,
28618
28661
  updatedAt: preference.updatedAt
28619
28662
  };
@@ -28632,6 +28675,7 @@ async function createUserPreferenceOp(ctx, opts) {
28632
28675
  if (opts.description) pref._setRaw("description", opts.description);
28633
28676
  if (opts.models) pref._setRaw("models", opts.models);
28634
28677
  if (opts.personality) pref._setRaw("personality", opts.personality);
28678
+ if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
28635
28679
  pref._setRaw("created_at", now);
28636
28680
  pref._setRaw("updated_at", now);
28637
28681
  });
@@ -28659,6 +28703,9 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
28659
28703
  if (opts.personality !== void 0) {
28660
28704
  pref._setRaw("personality", opts.personality || null);
28661
28705
  }
28706
+ if (opts.externalWallets !== void 0) {
28707
+ pref._setRaw("external_wallets", opts.externalWallets || null);
28708
+ }
28662
28709
  pref._setRaw("updated_at", Date.now());
28663
28710
  });
28664
28711
  });
@@ -28686,6 +28733,9 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
28686
28733
  if (opts.personality !== void 0) {
28687
28734
  pref._setRaw("personality", opts.personality || null);
28688
28735
  }
28736
+ if (opts.externalWallets !== void 0) {
28737
+ pref._setRaw("external_wallets", opts.externalWallets || null);
28738
+ }
28689
28739
  pref._setRaw("updated_at", now);
28690
28740
  });
28691
28741
  return preference;
@@ -28697,6 +28747,7 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
28697
28747
  if (opts.description) pref._setRaw("description", opts.description);
28698
28748
  if (opts.models) pref._setRaw("models", opts.models);
28699
28749
  if (opts.personality) pref._setRaw("personality", opts.personality);
28750
+ if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
28700
28751
  pref._setRaw("created_at", now);
28701
28752
  pref._setRaw("updated_at", now);
28702
28753
  });
@@ -37988,10 +38039,18 @@ function hasSql(clauses) {
37988
38039
  (clause) => clause.type === "sql" || "conditions" in clause && hasSql(clause.conditions)
37989
38040
  );
37990
38041
  }
38042
+ function encodeSqlParameters(sql, values) {
38043
+ if (values.length === 0) return sql;
38044
+ const tokens = /[eE]'(?:\\[\s\S]|''|[^'\\])*'|'(?:''|[^'])*'|"(?:""|[^"])*"|(\$(?:[a-zA-Z_]\w*)?\$)[\s\S]*?\1|--[^\r\n]*|\/\*[\s\S]*?\*\/|\$\d+|\?/g;
38045
+ if (sql.match(tokens)?.some((token) => /^\$\d+$/.test(token))) return sql;
38046
+ let index = 0;
38047
+ return sql.replace(tokens, (token) => token === "?" ? `$${++index}` : token);
38048
+ }
37991
38049
  function encodeQuery(query, qualify, countMode = false, idsOnly = false) {
37992
38050
  const { table, description, associations } = query;
37993
38051
  if (description.sql) {
37994
- return [description.sql.sql, description.sql.values];
38052
+ const { sql, values } = description.sql;
38053
+ return [encodeSqlParameters(sql, values), values];
37995
38054
  }
37996
38055
  const params = [];
37997
38056
  const hasToManyJoins = associations.some((a) => a.info.type === "has_many");
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  READ_FILE_SCHEMA: () => READ_FILE_SCHEMA,
62
62
  READ_SLIDES_SCHEMA: () => READ_SLIDES_SCHEMA,
63
63
  RUNTIME_ERROR_OVERLAY_SCRIPT: () => RUNTIME_ERROR_OVERLAY_SCRIPT,
64
+ SELECT_PAYMENT_WALLET_TOOL_NAME: () => SELECT_PAYMENT_WALLET_TOOL_NAME,
64
65
  SLIDES_FILE_PATH: () => SLIDES_FILE_PATH,
65
66
  SLIDE_CANVAS_HEIGHT: () => SLIDE_CANVAS_HEIGHT,
66
67
  SLIDE_CANVAS_WIDTH: () => SLIDE_CANVAS_WIDTH,
@@ -68,6 +69,7 @@ __export(index_exports, {
68
69
  SiwxUnsupportedError: () => SiwxUnsupportedError,
69
70
  THEME_ATTRS: () => THEME_ATTRS,
70
71
  VERIFY_APP_SCHEMA: () => VERIFY_APP_SCHEMA,
72
+ WALLET_PAYMENT_TOOL_NAME: () => WALLET_PAYMENT_TOOL_NAME,
71
73
  applyPatches: () => applyPatches,
72
74
  auditDesign: () => auditDesign,
73
75
  buildAppFileManifest: () => buildAppFileManifest,
@@ -119,8 +121,10 @@ __export(index_exports, {
119
121
  createNotionUpdateDataSourceTool: () => createNotionUpdateDataSourceTool,
120
122
  createNotionUpdatePageTool: () => createNotionUpdatePageTool,
121
123
  createPhoneCallOfferTool: () => createPhoneCallOfferTool,
124
+ createSelectPaymentWalletTool: () => createSelectPaymentWalletTool,
122
125
  createSlackTools: () => createSlackTools,
123
126
  createSlideTools: () => createSlideTools,
127
+ createWalletPaymentTool: () => createWalletPaymentTool,
124
128
  createWeatherTool: () => createWeatherTool,
125
129
  createXTools: () => createXTools,
126
130
  documentPath: () => documentPath,
@@ -13645,6 +13649,140 @@ ICONS: Material Symbols Rounded \u2014 bolt, lock, search, favorite, star, check
13645
13649
  COLOR TOKENS: textPrimary, textSecondary, textMuted, accent, card, border, background, slideBg`;
13646
13650
  }
13647
13651
 
13652
+ // src/tools/walletPaymentConstants.ts
13653
+ var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
13654
+ var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
13655
+
13656
+ // src/tools/walletPayment.ts
13657
+ var CANCELLED = { cancelled: true };
13658
+ function isNonEmptyString(value) {
13659
+ return typeof value === "string" && value.length > 0;
13660
+ }
13661
+ function hasPassengers(value) {
13662
+ return Array.isArray(value?.passengers);
13663
+ }
13664
+ function createSelectPaymentWalletTool(options) {
13665
+ const tool = createInteractiveTool(options, {
13666
+ name: SELECT_PAYMENT_WALLET_TOOL_NAME,
13667
+ description: "Show the user a card with the flight offer and their wallets, and let them pick the wallet to pay from. Call it after anuma_flight_offer_details, with the exact offer id, price and currency from that result. Returns the chosen wallet, or that the user declined.",
13668
+ parameters: {
13669
+ type: "object",
13670
+ properties: {
13671
+ offer_id: {
13672
+ type: "string",
13673
+ description: "The offer id from anuma_flight_offer_details"
13674
+ },
13675
+ summary: {
13676
+ type: "string",
13677
+ description: "Route, dates and fare of the offer, as shown to the user"
13678
+ },
13679
+ amount: {
13680
+ type: "string",
13681
+ description: "Total price of the offer, e.g. '412.50'"
13682
+ },
13683
+ currency: {
13684
+ type: "string",
13685
+ description: "Currency of the price, e.g. 'USD'"
13686
+ }
13687
+ },
13688
+ required: ["offer_id", "amount", "currency"]
13689
+ },
13690
+ interactionType: "select_payment_wallet",
13691
+ validate: (args) => isNonEmptyString(args.offer_id),
13692
+ mapArgs: ({ offer_id, summary, amount, currency, wallets }) => ({
13693
+ offer_id,
13694
+ summary,
13695
+ amount,
13696
+ currency,
13697
+ wallets
13698
+ }),
13699
+ mapResult: (result, args) => {
13700
+ if (result?.confirmed === true && isNonEmptyString(result.funding_wallet)) {
13701
+ return {
13702
+ confirmed: true,
13703
+ offer_id: args.offer_id,
13704
+ funding_wallet: result.funding_wallet
13705
+ };
13706
+ }
13707
+ if (result?.confirmed === false) return { confirmed: false };
13708
+ return CANCELLED;
13709
+ }
13710
+ });
13711
+ const showCard = tool.executor;
13712
+ return {
13713
+ ...tool,
13714
+ executor: async (args, signal) => {
13715
+ if (!isNonEmptyString(args.offer_id)) return CANCELLED;
13716
+ let wallets;
13717
+ try {
13718
+ wallets = await options.listWallets();
13719
+ } catch {
13720
+ return { error_code: "wallets_unavailable", retryable: true };
13721
+ }
13722
+ if (signal?.aborted) return CANCELLED;
13723
+ return showCard?.({ ...args, wallets }, signal);
13724
+ }
13725
+ };
13726
+ }
13727
+ function createWalletPaymentTool(options) {
13728
+ const tool = createInteractiveTool(options, {
13729
+ name: WALLET_PAYMENT_TOOL_NAME,
13730
+ description: "Show the user a card to enter the passengers, then pay the flight booking from the wallet they chose. Call it after anuma_create_flight_intent, with the provider and reference from that result. Returns whether the payment went through.",
13731
+ parameters: {
13732
+ type: "object",
13733
+ properties: {
13734
+ provider: {
13735
+ type: "string",
13736
+ description: "The payment provider from anuma_create_flight_intent"
13737
+ },
13738
+ reference: {
13739
+ type: "string",
13740
+ description: "The payment reference from anuma_create_flight_intent"
13741
+ },
13742
+ passenger_count: {
13743
+ type: "integer",
13744
+ minimum: 1,
13745
+ description: "How many passengers the booking is for"
13746
+ }
13747
+ },
13748
+ required: ["provider", "reference", "passenger_count"]
13749
+ },
13750
+ interactionType: "prompt_wallet_payment",
13751
+ validate: (args) => isNonEmptyString(args.provider) && isNonEmptyString(args.reference) && Number.isInteger(args.passenger_count) && args.passenger_count >= 1,
13752
+ mapArgs: ({ provider, reference, passenger_count }) => ({
13753
+ provider,
13754
+ reference,
13755
+ passenger_count
13756
+ }),
13757
+ mapResult: (result) => hasPassengers(result) ? { passengers: result.passengers } : CANCELLED
13758
+ });
13759
+ const showCard = tool.executor;
13760
+ return {
13761
+ ...tool,
13762
+ executor: async (args, signal) => {
13763
+ const answer = await showCard?.(args, signal);
13764
+ if (!hasPassengers(answer) || signal?.aborted) return CANCELLED;
13765
+ const provider = args.provider;
13766
+ const reference = args.reference;
13767
+ let outcome;
13768
+ try {
13769
+ outcome = await options.pay({ provider, reference, passengers: answer.passengers }, signal);
13770
+ } catch {
13771
+ return { paid: false, error_code: "payment_failed", retryable: false };
13772
+ }
13773
+ if (outcome.paid) {
13774
+ return {
13775
+ paid: true,
13776
+ provider: outcome.provider,
13777
+ reference: outcome.reference,
13778
+ status: outcome.status
13779
+ };
13780
+ }
13781
+ return { paid: false, error_code: outcome.error_code, retryable: outcome.retryable };
13782
+ }
13783
+ };
13784
+ }
13785
+
13648
13786
  // src/tools/weather.ts
13649
13787
  var DEFAULT_GEOCODING_BASE = "https://geocoding-api.open-meteo.com/v1";
13650
13788
  var DEFAULT_FORECAST_BASE = "https://api.open-meteo.com/v1";
@@ -13928,6 +14066,7 @@ function createXTools(callProxy) {
13928
14066
  READ_FILE_SCHEMA,
13929
14067
  READ_SLIDES_SCHEMA,
13930
14068
  RUNTIME_ERROR_OVERLAY_SCRIPT,
14069
+ SELECT_PAYMENT_WALLET_TOOL_NAME,
13931
14070
  SLIDES_FILE_PATH,
13932
14071
  SLIDE_CANVAS_HEIGHT,
13933
14072
  SLIDE_CANVAS_WIDTH,
@@ -13935,6 +14074,7 @@ function createXTools(callProxy) {
13935
14074
  SiwxUnsupportedError,
13936
14075
  THEME_ATTRS,
13937
14076
  VERIFY_APP_SCHEMA,
14077
+ WALLET_PAYMENT_TOOL_NAME,
13938
14078
  applyPatches,
13939
14079
  auditDesign,
13940
14080
  buildAppFileManifest,
@@ -13986,8 +14126,10 @@ function createXTools(callProxy) {
13986
14126
  createNotionUpdateDataSourceTool,
13987
14127
  createNotionUpdatePageTool,
13988
14128
  createPhoneCallOfferTool,
14129
+ createSelectPaymentWalletTool,
13989
14130
  createSlackTools,
13990
14131
  createSlideTools,
14132
+ createWalletPaymentTool,
13991
14133
  createWeatherTool,
13992
14134
  createXTools,
13993
14135
  documentPath,