@chucky.cloud/sdk 0.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.
Files changed (86) hide show
  1. package/README.md +330 -0
  2. package/dist/browser.d.ts +8 -0
  3. package/dist/browser.d.ts.map +1 -0
  4. package/dist/browser.js +12 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/client/ChuckyClient.d.ts +187 -0
  7. package/dist/client/ChuckyClient.d.ts.map +1 -0
  8. package/dist/client/ChuckyClient.js +232 -0
  9. package/dist/client/ChuckyClient.js.map +1 -0
  10. package/dist/client/Session.d.ts +146 -0
  11. package/dist/client/Session.d.ts.map +1 -0
  12. package/dist/client/Session.js +405 -0
  13. package/dist/client/Session.js.map +1 -0
  14. package/dist/client/index.d.ts +10 -0
  15. package/dist/client/index.d.ts.map +1 -0
  16. package/dist/client/index.js +8 -0
  17. package/dist/client/index.js.map +1 -0
  18. package/dist/index.d.ts +69 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +73 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/node.d.ts +8 -0
  23. package/dist/node.d.ts.map +1 -0
  24. package/dist/node.js +11 -0
  25. package/dist/node.js.map +1 -0
  26. package/dist/tools/McpServer.d.ts +117 -0
  27. package/dist/tools/McpServer.d.ts.map +1 -0
  28. package/dist/tools/McpServer.js +142 -0
  29. package/dist/tools/McpServer.js.map +1 -0
  30. package/dist/tools/index.d.ts +9 -0
  31. package/dist/tools/index.d.ts.map +1 -0
  32. package/dist/tools/index.js +8 -0
  33. package/dist/tools/index.js.map +1 -0
  34. package/dist/tools/tool.d.ts +146 -0
  35. package/dist/tools/tool.d.ts.map +1 -0
  36. package/dist/tools/tool.js +232 -0
  37. package/dist/tools/tool.js.map +1 -0
  38. package/dist/transport/Transport.d.ts +82 -0
  39. package/dist/transport/Transport.d.ts.map +1 -0
  40. package/dist/transport/Transport.js +45 -0
  41. package/dist/transport/Transport.js.map +1 -0
  42. package/dist/transport/WebSocketTransport.d.ts +78 -0
  43. package/dist/transport/WebSocketTransport.d.ts.map +1 -0
  44. package/dist/transport/WebSocketTransport.js +253 -0
  45. package/dist/transport/WebSocketTransport.js.map +1 -0
  46. package/dist/transport/index.d.ts +10 -0
  47. package/dist/transport/index.d.ts.map +1 -0
  48. package/dist/transport/index.js +8 -0
  49. package/dist/transport/index.js.map +1 -0
  50. package/dist/types/index.d.ts +12 -0
  51. package/dist/types/index.d.ts.map +1 -0
  52. package/dist/types/index.js +8 -0
  53. package/dist/types/index.js.map +1 -0
  54. package/dist/types/messages.d.ts +195 -0
  55. package/dist/types/messages.d.ts.map +1 -0
  56. package/dist/types/messages.js +70 -0
  57. package/dist/types/messages.js.map +1 -0
  58. package/dist/types/options.d.ts +210 -0
  59. package/dist/types/options.d.ts.map +1 -0
  60. package/dist/types/options.js +8 -0
  61. package/dist/types/options.js.map +1 -0
  62. package/dist/types/results.d.ts +182 -0
  63. package/dist/types/results.d.ts.map +1 -0
  64. package/dist/types/results.js +7 -0
  65. package/dist/types/results.js.map +1 -0
  66. package/dist/types/token.d.ts +124 -0
  67. package/dist/types/token.d.ts.map +1 -0
  68. package/dist/types/token.js +7 -0
  69. package/dist/types/token.js.map +1 -0
  70. package/dist/types/tools.d.ts +160 -0
  71. package/dist/types/tools.d.ts.map +1 -0
  72. package/dist/types/tools.js +8 -0
  73. package/dist/types/tools.js.map +1 -0
  74. package/dist/utils/errors.d.ts +80 -0
  75. package/dist/utils/errors.d.ts.map +1 -0
  76. package/dist/utils/errors.js +158 -0
  77. package/dist/utils/errors.js.map +1 -0
  78. package/dist/utils/index.d.ts +8 -0
  79. package/dist/utils/index.d.ts.map +1 -0
  80. package/dist/utils/index.js +8 -0
  81. package/dist/utils/index.js.map +1 -0
  82. package/dist/utils/token.d.ts +93 -0
  83. package/dist/utils/token.d.ts.map +1 -0
  84. package/dist/utils/token.js +195 -0
  85. package/dist/utils/token.js.map +1 -0
  86. package/package.json +63 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * MCP Server Builder
3
+ *
4
+ * Builder pattern for creating MCP server definitions with multiple tools.
5
+ */
6
+ import type { ToolDefinition, McpServerDefinition } from '../types/tools.js';
7
+ import type { CreateToolOptions } from './tool.js';
8
+ /**
9
+ * MCP Server builder for creating server definitions
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const myServer = new McpServerBuilder('my-tools', '1.0.0')
14
+ * .addTool({
15
+ * name: 'greet',
16
+ * description: 'Greet someone',
17
+ * inputSchema: {
18
+ * type: 'object',
19
+ * properties: { name: { type: 'string' } },
20
+ * required: ['name'],
21
+ * },
22
+ * handler: async ({ name }) => ({
23
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
24
+ * }),
25
+ * })
26
+ * .addTool({
27
+ * name: 'farewell',
28
+ * description: 'Say goodbye',
29
+ * inputSchema: {
30
+ * type: 'object',
31
+ * properties: { name: { type: 'string' } },
32
+ * required: ['name'],
33
+ * },
34
+ * handler: async ({ name }) => ({
35
+ * content: [{ type: 'text', text: `Goodbye, ${name}!` }],
36
+ * }),
37
+ * })
38
+ * .build();
39
+ * ```
40
+ */
41
+ export declare class McpServerBuilder {
42
+ private name;
43
+ private version;
44
+ private tools;
45
+ /**
46
+ * Create a new MCP server builder
47
+ *
48
+ * @param name - Server name
49
+ * @param version - Server version (default: '1.0.0')
50
+ */
51
+ constructor(name: string, version?: string);
52
+ /**
53
+ * Add a tool to the server
54
+ *
55
+ * @param options - Tool configuration
56
+ * @returns This builder for chaining
57
+ */
58
+ addTool<TInput = Record<string, unknown>>(options: CreateToolOptions<TInput>): this;
59
+ /**
60
+ * Add an existing tool definition
61
+ *
62
+ * @param tool - Tool definition
63
+ * @returns This builder for chaining
64
+ */
65
+ add(tool: ToolDefinition): this;
66
+ /**
67
+ * Add multiple tools at once
68
+ *
69
+ * @param tools - Array of tool definitions
70
+ * @returns This builder for chaining
71
+ */
72
+ addTools(tools: ToolDefinition[]): this;
73
+ /**
74
+ * Build the MCP server definition
75
+ *
76
+ * @returns Complete MCP server definition
77
+ */
78
+ build(): McpServerDefinition;
79
+ }
80
+ /**
81
+ * Create an MCP server definition
82
+ *
83
+ * @param name - Server name
84
+ * @param tools - Array of tool definitions
85
+ * @param version - Server version
86
+ * @returns MCP server definition
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const server = createMcpServer('my-server', [
91
+ * tool('greet', 'Greet someone', { type: 'object', properties: { name: { type: 'string' } } }),
92
+ * tool('farewell', 'Say goodbye', { type: 'object', properties: { name: { type: 'string' } } }),
93
+ * ]);
94
+ * ```
95
+ */
96
+ export declare function createMcpServer(name: string, tools: ToolDefinition[], version?: string): McpServerDefinition;
97
+ /**
98
+ * Create an MCP server using the builder pattern
99
+ *
100
+ * @param name - Server name
101
+ * @param version - Server version
102
+ * @returns MCP server builder
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const server = mcpServer('my-tools')
107
+ * .addTool({
108
+ * name: 'hello',
109
+ * description: 'Say hello',
110
+ * inputSchema: { type: 'object', properties: {} },
111
+ * handler: async () => ({ content: [{ type: 'text', text: 'Hello!' }] }),
112
+ * })
113
+ * .build();
114
+ * ```
115
+ */
116
+ export declare function mcpServer(name: string, version?: string): McpServerBuilder;
117
+ //# sourceMappingURL=McpServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpServer.d.ts","sourceRoot":"","sources":["../../src/tools/McpServer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAwB;IAErC;;;;;OAKG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAgB;IAKnD;;;;;OAKG;IACH,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,GACjC,IAAI;IAKP;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAK/B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI;IAKvC;;;;OAIG;IACH,KAAK,IAAI,mBAAmB;CAO7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,GAAE,MAAgB,GACxB,mBAAmB,CAMrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAE1E"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * MCP Server Builder
3
+ *
4
+ * Builder pattern for creating MCP server definitions with multiple tools.
5
+ */
6
+ import { createTool } from './tool.js';
7
+ /**
8
+ * MCP Server builder for creating server definitions
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const myServer = new McpServerBuilder('my-tools', '1.0.0')
13
+ * .addTool({
14
+ * name: 'greet',
15
+ * description: 'Greet someone',
16
+ * inputSchema: {
17
+ * type: 'object',
18
+ * properties: { name: { type: 'string' } },
19
+ * required: ['name'],
20
+ * },
21
+ * handler: async ({ name }) => ({
22
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
23
+ * }),
24
+ * })
25
+ * .addTool({
26
+ * name: 'farewell',
27
+ * description: 'Say goodbye',
28
+ * inputSchema: {
29
+ * type: 'object',
30
+ * properties: { name: { type: 'string' } },
31
+ * required: ['name'],
32
+ * },
33
+ * handler: async ({ name }) => ({
34
+ * content: [{ type: 'text', text: `Goodbye, ${name}!` }],
35
+ * }),
36
+ * })
37
+ * .build();
38
+ * ```
39
+ */
40
+ export class McpServerBuilder {
41
+ name;
42
+ version;
43
+ tools = [];
44
+ /**
45
+ * Create a new MCP server builder
46
+ *
47
+ * @param name - Server name
48
+ * @param version - Server version (default: '1.0.0')
49
+ */
50
+ constructor(name, version = '1.0.0') {
51
+ this.name = name;
52
+ this.version = version;
53
+ }
54
+ /**
55
+ * Add a tool to the server
56
+ *
57
+ * @param options - Tool configuration
58
+ * @returns This builder for chaining
59
+ */
60
+ addTool(options) {
61
+ this.tools.push(createTool(options));
62
+ return this;
63
+ }
64
+ /**
65
+ * Add an existing tool definition
66
+ *
67
+ * @param tool - Tool definition
68
+ * @returns This builder for chaining
69
+ */
70
+ add(tool) {
71
+ this.tools.push(tool);
72
+ return this;
73
+ }
74
+ /**
75
+ * Add multiple tools at once
76
+ *
77
+ * @param tools - Array of tool definitions
78
+ * @returns This builder for chaining
79
+ */
80
+ addTools(tools) {
81
+ this.tools.push(...tools);
82
+ return this;
83
+ }
84
+ /**
85
+ * Build the MCP server definition
86
+ *
87
+ * @returns Complete MCP server definition
88
+ */
89
+ build() {
90
+ return {
91
+ name: this.name,
92
+ version: this.version,
93
+ tools: this.tools,
94
+ };
95
+ }
96
+ }
97
+ /**
98
+ * Create an MCP server definition
99
+ *
100
+ * @param name - Server name
101
+ * @param tools - Array of tool definitions
102
+ * @param version - Server version
103
+ * @returns MCP server definition
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const server = createMcpServer('my-server', [
108
+ * tool('greet', 'Greet someone', { type: 'object', properties: { name: { type: 'string' } } }),
109
+ * tool('farewell', 'Say goodbye', { type: 'object', properties: { name: { type: 'string' } } }),
110
+ * ]);
111
+ * ```
112
+ */
113
+ export function createMcpServer(name, tools, version = '1.0.0') {
114
+ return {
115
+ name,
116
+ version,
117
+ tools,
118
+ };
119
+ }
120
+ /**
121
+ * Create an MCP server using the builder pattern
122
+ *
123
+ * @param name - Server name
124
+ * @param version - Server version
125
+ * @returns MCP server builder
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const server = mcpServer('my-tools')
130
+ * .addTool({
131
+ * name: 'hello',
132
+ * description: 'Say hello',
133
+ * inputSchema: { type: 'object', properties: {} },
134
+ * handler: async () => ({ content: [{ type: 'text', text: 'Hello!' }] }),
135
+ * })
136
+ * .build();
137
+ * ```
138
+ */
139
+ export function mcpServer(name, version) {
140
+ return new McpServerBuilder(name, version);
141
+ }
142
+ //# sourceMappingURL=McpServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpServer.js","sourceRoot":"","sources":["../../src/tools/McpServer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,gBAAgB;IACnB,IAAI,CAAS;IACb,OAAO,CAAS;IAChB,KAAK,GAAqB,EAAE,CAAC;IAErC;;;;;OAKG;IACH,YAAY,IAAY,EAAE,UAAkB,OAAO;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,OAAO,CACL,OAAkC;QAElC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAmB,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAoB;QACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,KAAuB;QAC9B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,KAAuB,EACvB,UAAkB,OAAO;IAEzB,OAAO;QACL,IAAI;QACJ,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAAgB;IACtD,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tools Index
3
+ *
4
+ * Re-exports all tool helpers and builders.
5
+ */
6
+ export { createTool, tool, browserTool, serverTool, textResult, errorResult, imageResult, } from './tool.js';
7
+ export type { CreateToolOptions } from './tool.js';
8
+ export { McpServerBuilder, createMcpServer, mcpServer } from './McpServer.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,IAAI,EACJ,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tools Index
3
+ *
4
+ * Re-exports all tool helpers and builders.
5
+ */
6
+ export { createTool, tool, browserTool, serverTool, textResult, errorResult, imageResult, } from './tool.js';
7
+ export { McpServerBuilder, createMcpServer, mcpServer } from './McpServer.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,IAAI,EACJ,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Tool Helper
3
+ *
4
+ * Helper functions for defining tools with type safety.
5
+ * Supports both JSON Schema and Zod for input validation.
6
+ */
7
+ import type { ToolDefinition, ToolInputSchema, ToolHandler, ToolResult, ToolExecutionLocation } from '../types/tools.js';
8
+ /**
9
+ * Options for creating a tool
10
+ */
11
+ export interface CreateToolOptions<TInput = Record<string, unknown>> {
12
+ /** Tool name (must be unique) */
13
+ name: string;
14
+ /** Human-readable description */
15
+ description: string;
16
+ /** Input schema (JSON Schema or Zod schema) */
17
+ inputSchema: ToolInputSchema | ZodLikeSchema;
18
+ /** Where to execute the tool */
19
+ executeIn?: ToolExecutionLocation;
20
+ /** Handler function */
21
+ handler?: ToolHandler<TInput>;
22
+ }
23
+ /**
24
+ * Zod-like schema interface for compatibility
25
+ */
26
+ interface ZodLikeSchema {
27
+ _def?: unknown;
28
+ shape?: unknown;
29
+ safeParse?: (data: unknown) => {
30
+ success: boolean;
31
+ data?: unknown;
32
+ error?: unknown;
33
+ };
34
+ }
35
+ /**
36
+ * Create a tool definition
37
+ *
38
+ * @param options - Tool configuration
39
+ * @returns Tool definition ready to use
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * // With JSON Schema
44
+ * const weatherTool = createTool({
45
+ * name: 'get_weather',
46
+ * description: 'Get current weather for a city',
47
+ * inputSchema: {
48
+ * type: 'object',
49
+ * properties: {
50
+ * city: { type: 'string', description: 'City name' },
51
+ * unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
52
+ * },
53
+ * required: ['city'],
54
+ * },
55
+ * handler: async ({ city, unit }) => ({
56
+ * content: [{ type: 'text', text: `Weather in ${city}: Sunny, 72°${unit === 'celsius' ? 'C' : 'F'}` }],
57
+ * }),
58
+ * });
59
+ *
60
+ * // With Zod (optional peer dependency)
61
+ * import { z } from 'zod';
62
+ *
63
+ * const calculatorTool = createTool({
64
+ * name: 'calculate',
65
+ * description: 'Perform a calculation',
66
+ * inputSchema: z.object({
67
+ * expression: z.string().describe('Math expression to evaluate'),
68
+ * }),
69
+ * handler: async ({ expression }) => ({
70
+ * content: [{ type: 'text', text: `Result: ${eval(expression)}` }],
71
+ * }),
72
+ * });
73
+ * ```
74
+ */
75
+ export declare function createTool<TInput = Record<string, unknown>>(options: CreateToolOptions<TInput>): ToolDefinition<TInput>;
76
+ /**
77
+ * Shorthand for creating a tool
78
+ *
79
+ * @param name - Tool name
80
+ * @param description - Tool description
81
+ * @param inputSchema - Input schema
82
+ * @param handler - Handler function
83
+ * @returns Tool definition
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const greetTool = tool(
88
+ * 'greet',
89
+ * 'Greet a person by name',
90
+ * {
91
+ * type: 'object',
92
+ * properties: { name: { type: 'string' } },
93
+ * required: ['name'],
94
+ * },
95
+ * async ({ name }) => ({
96
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
97
+ * })
98
+ * );
99
+ * ```
100
+ */
101
+ export declare function tool<TInput = Record<string, unknown>>(name: string, description: string, inputSchema: ToolInputSchema | ZodLikeSchema, handler?: ToolHandler<TInput>): ToolDefinition<TInput>;
102
+ /**
103
+ * Create a browser-executed tool
104
+ *
105
+ * @param options - Tool configuration
106
+ * @returns Tool definition that executes in the browser
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const alertTool = browserTool({
111
+ * name: 'show_alert',
112
+ * description: 'Show an alert dialog',
113
+ * inputSchema: {
114
+ * type: 'object',
115
+ * properties: { message: { type: 'string' } },
116
+ * required: ['message'],
117
+ * },
118
+ * handler: async ({ message }) => {
119
+ * alert(message);
120
+ * return { content: [{ type: 'text', text: 'Alert shown' }] };
121
+ * },
122
+ * });
123
+ * ```
124
+ */
125
+ export declare function browserTool<TInput = Record<string, unknown>>(options: Omit<CreateToolOptions<TInput>, 'executeIn'>): ToolDefinition<TInput>;
126
+ /**
127
+ * Create a server-executed tool
128
+ *
129
+ * @param options - Tool configuration (handler is optional for server tools)
130
+ * @returns Tool definition that executes on the server
131
+ */
132
+ export declare function serverTool<TInput = Record<string, unknown>>(options: Omit<CreateToolOptions<TInput>, 'executeIn' | 'handler'>): ToolDefinition<TInput>;
133
+ /**
134
+ * Helper to create text content for tool results
135
+ */
136
+ export declare function textResult(text: string): ToolResult;
137
+ /**
138
+ * Helper to create error result for tools
139
+ */
140
+ export declare function errorResult(message: string): ToolResult;
141
+ /**
142
+ * Helper to create image content for tool results
143
+ */
144
+ export declare function imageResult(data: string, mimeType: string): ToolResult;
145
+ export {};
146
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,WAAW,EACX,UAAU,EACV,qBAAqB,EAEtB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACjE,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,WAAW,EAAE,eAAe,GAAG,aAAa,CAAC;IAC7C,gCAAgC;IAChC,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,uBAAuB;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC/B;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B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAInD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAKvD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAItE"}
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Tool Helper
3
+ *
4
+ * Helper functions for defining tools with type safety.
5
+ * Supports both JSON Schema and Zod for input validation.
6
+ */
7
+ /**
8
+ * Check if a schema is a Zod schema
9
+ */
10
+ function isZodSchema(schema) {
11
+ return (typeof schema === 'object' &&
12
+ schema !== null &&
13
+ ('_def' in schema || 'shape' in schema));
14
+ }
15
+ /**
16
+ * Convert Zod schema to JSON Schema (basic conversion)
17
+ */
18
+ function zodToJsonSchema(zodSchema) {
19
+ // This is a simplified conversion - for full support, use zod-to-json-schema
20
+ const def = zodSchema._def;
21
+ if (!def) {
22
+ return {
23
+ type: 'object',
24
+ properties: {},
25
+ };
26
+ }
27
+ const typeName = def.typeName;
28
+ if (typeName === 'ZodObject') {
29
+ const shape = def.shape?.() || {};
30
+ const properties = {};
31
+ const required = [];
32
+ for (const [key, value] of Object.entries(shape)) {
33
+ const valueDef = value._def;
34
+ if (valueDef) {
35
+ const prop = zodDefToJsonSchema(valueDef);
36
+ if (prop) {
37
+ properties[key] = prop;
38
+ // Check if required (not optional)
39
+ if (valueDef.typeName !== 'ZodOptional') {
40
+ required.push(key);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ return {
46
+ type: 'object',
47
+ properties,
48
+ required: required.length > 0 ? required : undefined,
49
+ };
50
+ }
51
+ return {
52
+ type: 'object',
53
+ properties: {},
54
+ };
55
+ }
56
+ /**
57
+ * Convert a Zod definition to JSON Schema property
58
+ */
59
+ function zodDefToJsonSchema(def) {
60
+ const typeName = def.typeName;
61
+ switch (typeName) {
62
+ case 'ZodString':
63
+ return { type: 'string', description: def.description };
64
+ case 'ZodNumber':
65
+ return { type: 'number', description: def.description };
66
+ case 'ZodBoolean':
67
+ return { type: 'boolean', description: def.description };
68
+ case 'ZodArray':
69
+ const innerDef = def.innerType?._def;
70
+ return {
71
+ type: 'array',
72
+ description: def.description,
73
+ items: innerDef ? zodDefToJsonSchema(innerDef) || { type: 'string' } : { type: 'string' },
74
+ };
75
+ case 'ZodEnum':
76
+ return {
77
+ type: 'string',
78
+ description: def.description,
79
+ enum: def.values,
80
+ };
81
+ case 'ZodOptional':
82
+ const innerOptDef = def.innerType?._def;
83
+ return innerOptDef ? zodDefToJsonSchema(innerOptDef) : null;
84
+ default:
85
+ return { type: 'string' };
86
+ }
87
+ }
88
+ /**
89
+ * Create a tool definition
90
+ *
91
+ * @param options - Tool configuration
92
+ * @returns Tool definition ready to use
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // With JSON Schema
97
+ * const weatherTool = createTool({
98
+ * name: 'get_weather',
99
+ * description: 'Get current weather for a city',
100
+ * inputSchema: {
101
+ * type: 'object',
102
+ * properties: {
103
+ * city: { type: 'string', description: 'City name' },
104
+ * unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
105
+ * },
106
+ * required: ['city'],
107
+ * },
108
+ * handler: async ({ city, unit }) => ({
109
+ * content: [{ type: 'text', text: `Weather in ${city}: Sunny, 72°${unit === 'celsius' ? 'C' : 'F'}` }],
110
+ * }),
111
+ * });
112
+ *
113
+ * // With Zod (optional peer dependency)
114
+ * import { z } from 'zod';
115
+ *
116
+ * const calculatorTool = createTool({
117
+ * name: 'calculate',
118
+ * description: 'Perform a calculation',
119
+ * inputSchema: z.object({
120
+ * expression: z.string().describe('Math expression to evaluate'),
121
+ * }),
122
+ * handler: async ({ expression }) => ({
123
+ * content: [{ type: 'text', text: `Result: ${eval(expression)}` }],
124
+ * }),
125
+ * });
126
+ * ```
127
+ */
128
+ export function createTool(options) {
129
+ let inputSchema;
130
+ if (isZodSchema(options.inputSchema)) {
131
+ inputSchema = zodToJsonSchema(options.inputSchema);
132
+ }
133
+ else {
134
+ inputSchema = options.inputSchema;
135
+ }
136
+ return {
137
+ name: options.name,
138
+ description: options.description,
139
+ inputSchema,
140
+ executeIn: options.executeIn ?? 'server',
141
+ handler: options.handler,
142
+ };
143
+ }
144
+ /**
145
+ * Shorthand for creating a tool
146
+ *
147
+ * @param name - Tool name
148
+ * @param description - Tool description
149
+ * @param inputSchema - Input schema
150
+ * @param handler - Handler function
151
+ * @returns Tool definition
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const greetTool = tool(
156
+ * 'greet',
157
+ * 'Greet a person by name',
158
+ * {
159
+ * type: 'object',
160
+ * properties: { name: { type: 'string' } },
161
+ * required: ['name'],
162
+ * },
163
+ * async ({ name }) => ({
164
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
165
+ * })
166
+ * );
167
+ * ```
168
+ */
169
+ export function tool(name, description, inputSchema, handler) {
170
+ return createTool({ name, description, inputSchema, handler });
171
+ }
172
+ /**
173
+ * Create a browser-executed tool
174
+ *
175
+ * @param options - Tool configuration
176
+ * @returns Tool definition that executes in the browser
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const alertTool = browserTool({
181
+ * name: 'show_alert',
182
+ * description: 'Show an alert dialog',
183
+ * inputSchema: {
184
+ * type: 'object',
185
+ * properties: { message: { type: 'string' } },
186
+ * required: ['message'],
187
+ * },
188
+ * handler: async ({ message }) => {
189
+ * alert(message);
190
+ * return { content: [{ type: 'text', text: 'Alert shown' }] };
191
+ * },
192
+ * });
193
+ * ```
194
+ */
195
+ export function browserTool(options) {
196
+ return createTool({ ...options, executeIn: 'browser' });
197
+ }
198
+ /**
199
+ * Create a server-executed tool
200
+ *
201
+ * @param options - Tool configuration (handler is optional for server tools)
202
+ * @returns Tool definition that executes on the server
203
+ */
204
+ export function serverTool(options) {
205
+ return createTool({ ...options, executeIn: 'server' });
206
+ }
207
+ /**
208
+ * Helper to create text content for tool results
209
+ */
210
+ export function textResult(text) {
211
+ return {
212
+ content: [{ type: 'text', text }],
213
+ };
214
+ }
215
+ /**
216
+ * Helper to create error result for tools
217
+ */
218
+ export function errorResult(message) {
219
+ return {
220
+ content: [{ type: 'text', text: message }],
221
+ isError: true,
222
+ };
223
+ }
224
+ /**
225
+ * Helper to create image content for tool results
226
+ */
227
+ export function imageResult(data, mimeType) {
228
+ return {
229
+ content: [{ type: 'image', data, mimeType }],
230
+ };
231
+ }
232
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoCH;;GAEG;AACH,SAAS,WAAW,CAAC,MAAe;IAClC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAC,MAAM,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,CAAC,CACxC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,SAAwB;IAC/C,6EAA6E;IAC7E,MAAM,GAAG,GAAI,SAAqF,CAAC,IAAI,CAAC;IAExG,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;SACf,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAE9B,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC;QAClC,MAAM,UAAU,GAAuC,EAAE,CAAC;QAC1D,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAI,KAAkG,CAAC,IAAI,CAAC;YAE1H,IAAI,QAAQ,EA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