hybrid 1.3.1 → 1.3.2

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.
@@ -1,5 +1,5 @@
1
- import { z } from 'zod';
2
1
  import { UIMessage } from 'ai';
2
+ import { z } from 'zod';
3
3
  import { XmtpConversation, XmtpMessage, XmtpSender, XmtpSubjects, XmtpServiceClient } from '@hybrd/xmtp';
4
4
  import * as viem_chains from 'viem/chains';
5
5
  import * as viem from 'viem';
@@ -27,7 +27,7 @@ type DefaultRuntimeExtension = Record<string, never>;
27
27
  /**
28
28
  * Configuration interface for creating custom tools that integrate with AI SDK.
29
29
  */
30
- interface ToolConfig<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
30
+ interface ToolConfig<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
31
31
  /** Unique identifier for the tool */
32
32
  id: string;
33
33
  /** Human-readable description of what the tool does */
@@ -47,7 +47,7 @@ interface ToolConfig<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> =
47
47
  * Internal tool interface used throughout the agent framework.
48
48
  * Similar to ToolConfig but without the ID field, used after tool creation.
49
49
  */
50
- interface Tool<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
50
+ interface Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
51
51
  /** Human-readable description of what the tool does */
52
52
  description: string;
53
53
  /** Zod schema for validating tool input */
@@ -65,12 +65,12 @@ interface Tool<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodT
65
65
  * Factory function to create tools with custom runtime extensions.
66
66
  * Provides proper type inference for input/output schemas and runtime extensions.
67
67
  */
68
- declare function toolFactory<TRuntimeExtension = DefaultRuntimeExtension>(): <TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, TRuntimeExtension>) => Tool<TInput, TOutput, TRuntimeExtension>;
68
+ declare function toolFactory<TRuntimeExtension = DefaultRuntimeExtension>(): <TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, TRuntimeExtension>) => Tool<TInput, TOutput, TRuntimeExtension>;
69
69
  /**
70
70
  * Default tool factory with no runtime extensions.
71
71
  * Type-safe at creation time with proper schema inference.
72
72
  */
73
- declare const createTool: <TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, DefaultRuntimeExtension>) => Tool<TInput, TOutput, DefaultRuntimeExtension>;
73
+ declare const createTool: <TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, DefaultRuntimeExtension>) => Tool<TInput, TOutput, DefaultRuntimeExtension>;
74
74
 
75
75
  declare const SUPPORTED_CHAINS: {
76
76
  readonly mainnet: {
@@ -1564,14 +1564,14 @@ declare const sendMessageTool: Tool<z.ZodEffects<z.ZodObject<{
1564
1564
  }, "strip", z.ZodTypeAny, {
1565
1565
  content: string;
1566
1566
  success: boolean;
1567
- conversationId?: string | undefined;
1568
1567
  error?: string | undefined;
1568
+ conversationId?: string | undefined;
1569
1569
  messageId?: string | undefined;
1570
1570
  }, {
1571
1571
  content: string;
1572
1572
  success: boolean;
1573
- conversationId?: string | undefined;
1574
1573
  error?: string | undefined;
1574
+ conversationId?: string | undefined;
1575
1575
  messageId?: string | undefined;
1576
1576
  }>, {
1577
1577
  [x: string]: never;
@@ -1662,9 +1662,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1662
1662
  versionMinor?: number | undefined;
1663
1663
  }>>;
1664
1664
  }, "strip", z.ZodTypeAny, {
1665
+ id: string;
1665
1666
  conversationId: string;
1666
1667
  content: string | Record<string, unknown>;
1667
- id: string;
1668
1668
  senderInboxId: string;
1669
1669
  sentAt: string;
1670
1670
  contentType?: {
@@ -1674,9 +1674,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1674
1674
  versionMinor?: number | undefined;
1675
1675
  } | undefined;
1676
1676
  }, {
1677
+ id: string;
1677
1678
  conversationId: string;
1678
1679
  content: string | Record<string, unknown>;
1679
- id: string;
1680
1680
  senderInboxId: string;
1681
1681
  sentAt: string;
1682
1682
  contentType?: {
@@ -1690,9 +1690,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1690
1690
  }, "strip", z.ZodTypeAny, {
1691
1691
  success: boolean;
1692
1692
  message?: {
1693
+ id: string;
1693
1694
  conversationId: string;
1694
1695
  content: string | Record<string, unknown>;
1695
- id: string;
1696
1696
  senderInboxId: string;
1697
1697
  sentAt: string;
1698
1698
  contentType?: {
@@ -1706,9 +1706,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1706
1706
  }, {
1707
1707
  success: boolean;
1708
1708
  message?: {
1709
+ id: string;
1709
1710
  conversationId: string;
1710
1711
  content: string | Record<string, unknown>;
1711
- id: string;
1712
1712
  senderInboxId: string;
1713
1713
  sentAt: string;
1714
1714
  contentType?: {
@@ -1765,14 +1765,14 @@ declare const xmtpTools: {
1765
1765
  }, "strip", z.ZodTypeAny, {
1766
1766
  content: string;
1767
1767
  success: boolean;
1768
- conversationId?: string | undefined;
1769
1768
  error?: string | undefined;
1769
+ conversationId?: string | undefined;
1770
1770
  messageId?: string | undefined;
1771
1771
  }, {
1772
1772
  content: string;
1773
1773
  success: boolean;
1774
- conversationId?: string | undefined;
1775
1774
  error?: string | undefined;
1775
+ conversationId?: string | undefined;
1776
1776
  messageId?: string | undefined;
1777
1777
  }>, {
1778
1778
  [x: string]: never;
@@ -1862,9 +1862,9 @@ declare const xmtpTools: {
1862
1862
  versionMinor?: number | undefined;
1863
1863
  }>>;
1864
1864
  }, "strip", z.ZodTypeAny, {
1865
+ id: string;
1865
1866
  conversationId: string;
1866
1867
  content: string | Record<string, unknown>;
1867
- id: string;
1868
1868
  senderInboxId: string;
1869
1869
  sentAt: string;
1870
1870
  contentType?: {
@@ -1874,9 +1874,9 @@ declare const xmtpTools: {
1874
1874
  versionMinor?: number | undefined;
1875
1875
  } | undefined;
1876
1876
  }, {
1877
+ id: string;
1877
1878
  conversationId: string;
1878
1879
  content: string | Record<string, unknown>;
1879
- id: string;
1880
1880
  senderInboxId: string;
1881
1881
  sentAt: string;
1882
1882
  contentType?: {
@@ -1890,9 +1890,9 @@ declare const xmtpTools: {
1890
1890
  }, "strip", z.ZodTypeAny, {
1891
1891
  success: boolean;
1892
1892
  message?: {
1893
+ id: string;
1893
1894
  conversationId: string;
1894
1895
  content: string | Record<string, unknown>;
1895
- id: string;
1896
1896
  senderInboxId: string;
1897
1897
  sentAt: string;
1898
1898
  contentType?: {
@@ -1906,9 +1906,9 @@ declare const xmtpTools: {
1906
1906
  }, {
1907
1907
  success: boolean;
1908
1908
  message?: {
1909
+ id: string;
1909
1910
  conversationId: string;
1910
1911
  content: string | Record<string, unknown>;
1911
- id: string;
1912
1912
  senderInboxId: string;
1913
1913
  sentAt: string;
1914
1914
  contentType?: {
@@ -1,5 +1,5 @@
1
- import { z } from 'zod';
2
1
  import { UIMessage } from 'ai';
2
+ import { z } from 'zod';
3
3
  import { XmtpConversation, XmtpMessage, XmtpSender, XmtpSubjects, XmtpServiceClient } from '@hybrd/xmtp';
4
4
  import * as viem_chains from 'viem/chains';
5
5
  import * as viem from 'viem';
@@ -27,7 +27,7 @@ type DefaultRuntimeExtension = Record<string, never>;
27
27
  /**
28
28
  * Configuration interface for creating custom tools that integrate with AI SDK.
29
29
  */
30
- interface ToolConfig<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
30
+ interface ToolConfig<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
31
31
  /** Unique identifier for the tool */
32
32
  id: string;
33
33
  /** Human-readable description of what the tool does */
@@ -47,7 +47,7 @@ interface ToolConfig<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> =
47
47
  * Internal tool interface used throughout the agent framework.
48
48
  * Similar to ToolConfig but without the ID field, used after tool creation.
49
49
  */
50
- interface Tool<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
50
+ interface Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
51
51
  /** Human-readable description of what the tool does */
52
52
  description: string;
53
53
  /** Zod schema for validating tool input */
@@ -65,12 +65,12 @@ interface Tool<TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodT
65
65
  * Factory function to create tools with custom runtime extensions.
66
66
  * Provides proper type inference for input/output schemas and runtime extensions.
67
67
  */
68
- declare function toolFactory<TRuntimeExtension = DefaultRuntimeExtension>(): <TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, TRuntimeExtension>) => Tool<TInput, TOutput, TRuntimeExtension>;
68
+ declare function toolFactory<TRuntimeExtension = DefaultRuntimeExtension>(): <TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, TRuntimeExtension>) => Tool<TInput, TOutput, TRuntimeExtension>;
69
69
  /**
70
70
  * Default tool factory with no runtime extensions.
71
71
  * Type-safe at creation time with proper schema inference.
72
72
  */
73
- declare const createTool: <TInput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>, TOutput extends z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny> = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, DefaultRuntimeExtension>) => Tool<TInput, TOutput, DefaultRuntimeExtension>;
73
+ declare const createTool: <TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny>(config: ToolConfig<TInput, TOutput, DefaultRuntimeExtension>) => Tool<TInput, TOutput, DefaultRuntimeExtension>;
74
74
 
75
75
  declare const SUPPORTED_CHAINS: {
76
76
  readonly mainnet: {
@@ -1564,14 +1564,14 @@ declare const sendMessageTool: Tool<z.ZodEffects<z.ZodObject<{
1564
1564
  }, "strip", z.ZodTypeAny, {
1565
1565
  content: string;
1566
1566
  success: boolean;
1567
- conversationId?: string | undefined;
1568
1567
  error?: string | undefined;
1568
+ conversationId?: string | undefined;
1569
1569
  messageId?: string | undefined;
1570
1570
  }, {
1571
1571
  content: string;
1572
1572
  success: boolean;
1573
- conversationId?: string | undefined;
1574
1573
  error?: string | undefined;
1574
+ conversationId?: string | undefined;
1575
1575
  messageId?: string | undefined;
1576
1576
  }>, {
1577
1577
  [x: string]: never;
@@ -1662,9 +1662,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1662
1662
  versionMinor?: number | undefined;
1663
1663
  }>>;
1664
1664
  }, "strip", z.ZodTypeAny, {
1665
+ id: string;
1665
1666
  conversationId: string;
1666
1667
  content: string | Record<string, unknown>;
1667
- id: string;
1668
1668
  senderInboxId: string;
1669
1669
  sentAt: string;
1670
1670
  contentType?: {
@@ -1674,9 +1674,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1674
1674
  versionMinor?: number | undefined;
1675
1675
  } | undefined;
1676
1676
  }, {
1677
+ id: string;
1677
1678
  conversationId: string;
1678
1679
  content: string | Record<string, unknown>;
1679
- id: string;
1680
1680
  senderInboxId: string;
1681
1681
  sentAt: string;
1682
1682
  contentType?: {
@@ -1690,9 +1690,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1690
1690
  }, "strip", z.ZodTypeAny, {
1691
1691
  success: boolean;
1692
1692
  message?: {
1693
+ id: string;
1693
1694
  conversationId: string;
1694
1695
  content: string | Record<string, unknown>;
1695
- id: string;
1696
1696
  senderInboxId: string;
1697
1697
  sentAt: string;
1698
1698
  contentType?: {
@@ -1706,9 +1706,9 @@ declare const getMessageTool: Tool<z.ZodObject<{
1706
1706
  }, {
1707
1707
  success: boolean;
1708
1708
  message?: {
1709
+ id: string;
1709
1710
  conversationId: string;
1710
1711
  content: string | Record<string, unknown>;
1711
- id: string;
1712
1712
  senderInboxId: string;
1713
1713
  sentAt: string;
1714
1714
  contentType?: {
@@ -1765,14 +1765,14 @@ declare const xmtpTools: {
1765
1765
  }, "strip", z.ZodTypeAny, {
1766
1766
  content: string;
1767
1767
  success: boolean;
1768
- conversationId?: string | undefined;
1769
1768
  error?: string | undefined;
1769
+ conversationId?: string | undefined;
1770
1770
  messageId?: string | undefined;
1771
1771
  }, {
1772
1772
  content: string;
1773
1773
  success: boolean;
1774
- conversationId?: string | undefined;
1775
1774
  error?: string | undefined;
1775
+ conversationId?: string | undefined;
1776
1776
  messageId?: string | undefined;
1777
1777
  }>, {
1778
1778
  [x: string]: never;
@@ -1862,9 +1862,9 @@ declare const xmtpTools: {
1862
1862
  versionMinor?: number | undefined;
1863
1863
  }>>;
1864
1864
  }, "strip", z.ZodTypeAny, {
1865
+ id: string;
1865
1866
  conversationId: string;
1866
1867
  content: string | Record<string, unknown>;
1867
- id: string;
1868
1868
  senderInboxId: string;
1869
1869
  sentAt: string;
1870
1870
  contentType?: {
@@ -1874,9 +1874,9 @@ declare const xmtpTools: {
1874
1874
  versionMinor?: number | undefined;
1875
1875
  } | undefined;
1876
1876
  }, {
1877
+ id: string;
1877
1878
  conversationId: string;
1878
1879
  content: string | Record<string, unknown>;
1879
- id: string;
1880
1880
  senderInboxId: string;
1881
1881
  sentAt: string;
1882
1882
  contentType?: {
@@ -1890,9 +1890,9 @@ declare const xmtpTools: {
1890
1890
  }, "strip", z.ZodTypeAny, {
1891
1891
  success: boolean;
1892
1892
  message?: {
1893
+ id: string;
1893
1894
  conversationId: string;
1894
1895
  content: string | Record<string, unknown>;
1895
- id: string;
1896
1896
  senderInboxId: string;
1897
1897
  sentAt: string;
1898
1898
  contentType?: {
@@ -1906,9 +1906,9 @@ declare const xmtpTools: {
1906
1906
  }, {
1907
1907
  success: boolean;
1908
1908
  message?: {
1909
+ id: string;
1909
1910
  conversationId: string;
1910
1911
  content: string | Record<string, unknown>;
1911
- id: string;
1912
1912
  senderInboxId: string;
1913
1913
  sentAt: string;
1914
1914
  contentType?: {
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -35,7 +25,6 @@ __export(src_exports, {
35
25
  blockchainTools: () => blockchainTools,
36
26
  createTool: () => createTool,
37
27
  estimateGasTool: () => estimateGasTool,
38
- generateXMTPToolsToken: () => generateXMTPToolsToken,
39
28
  getBalanceTool: () => getBalanceTool,
40
29
  getBgState: () => getBgState,
41
30
  getBlockTool: () => getBlockTool,
@@ -77,55 +66,6 @@ var import_xmtp = require("@hybrd/xmtp");
77
66
  var import_node_crypto = require("crypto");
78
67
  var import_viem = require("viem");
79
68
  var import_chains = require("viem/chains");
80
-
81
- // src/lib/jwt.ts
82
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
83
- var JWT_SECRET = (() => {
84
- const secret = process.env.XMTP_ENCRYPTION_KEY;
85
- const nodeEnv = process.env.NODE_ENV || "development";
86
- if (nodeEnv === "production" && !secret) {
87
- throw new Error(
88
- "XMTP_ENCRYPTION_KEY environment variable is required in production. Generate a secure random secret for JWT token signing."
89
- );
90
- }
91
- if (!secret) {
92
- console.warn(
93
- "\u26A0\uFE0F [SECURITY] Using fallback JWT secret for development. Set XMTP_ENCRYPTION_KEY environment variable for production."
94
- );
95
- return "fallback-secret-for-dev-only";
96
- }
97
- return secret;
98
- })();
99
- var API_KEY = (() => {
100
- const apiKey = process.env.XMTP_API_KEY;
101
- const nodeEnv = process.env.NODE_ENV || "development";
102
- if (nodeEnv === "production" && !apiKey) {
103
- throw new Error(
104
- "XMTP_API_KEY environment variable is required in production. Generate a secure random API key for authentication."
105
- );
106
- }
107
- if (!apiKey) {
108
- console.warn(
109
- "\u26A0\uFE0F [SECURITY] Using fallback API key for development. Set XMTP_API_KEY environment variable for production."
110
- );
111
- return "fallback-api-key-for-dev-only";
112
- }
113
- return apiKey;
114
- })();
115
- var JWT_EXPIRY = 5 * 60;
116
- function generateXMTPToolsToken(payload) {
117
- const now = Math.floor(Date.now() / 1e3);
118
- const fullPayload = {
119
- ...payload,
120
- issued: now,
121
- expires: now + JWT_EXPIRY
122
- };
123
- return import_jsonwebtoken.default.sign(fullPayload, JWT_SECRET, {
124
- expiresIn: JWT_EXPIRY
125
- });
126
- }
127
-
128
- // src/server/processor.ts
129
69
  var BG_STARTED = Symbol("BG_STARTED");
130
70
  var BG_STATE = Symbol("BG_STATE");
131
71
  var BG_STOP = Symbol("BG_STOP");
@@ -216,7 +156,7 @@ function createBackgroundMessageProcessor(opts) {
216
156
  }
217
157
  ];
218
158
  const serviceUrl = process.env.AGENT_URL || "http://localhost:8454";
219
- const serviceToken = generateXMTPToolsToken({
159
+ const serviceToken = (0, import_xmtp.generateXMTPToolsToken)({
220
160
  action: "send",
221
161
  conversationId: messageEvent.message.conversationId,
222
162
  content: messageEvent.message.content?.toString() || ""
@@ -1446,7 +1386,6 @@ var xmtpTools = {
1446
1386
  blockchainTools,
1447
1387
  createTool,
1448
1388
  estimateGasTool,
1449
- generateXMTPToolsToken,
1450
1389
  getBalanceTool,
1451
1390
  getBgState,
1452
1391
  getBlockTool,