@chucky.cloud/sdk 0.2.5 → 0.3.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 (95) hide show
  1. package/README.md +6 -1
  2. package/dist/browser.cjs +1361 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.cts +1 -0
  5. package/dist/browser.d.ts +1 -8
  6. package/dist/browser.js +1278 -11
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.cjs +1361 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +1973 -0
  11. package/dist/index.d.ts +1953 -48
  12. package/dist/index.js +1278 -72
  13. package/dist/index.js.map +1 -1
  14. package/dist/node.cjs +1361 -0
  15. package/dist/node.cjs.map +1 -0
  16. package/dist/node.d.cts +1 -0
  17. package/dist/node.d.ts +1 -8
  18. package/dist/node.js +1278 -10
  19. package/dist/node.js.map +1 -1
  20. package/package.json +31 -9
  21. package/dist/browser.d.ts.map +0 -1
  22. package/dist/client/ChuckyClient.d.ts +0 -141
  23. package/dist/client/ChuckyClient.d.ts.map +0 -1
  24. package/dist/client/ChuckyClient.js +0 -209
  25. package/dist/client/ChuckyClient.js.map +0 -1
  26. package/dist/client/Session.d.ts +0 -167
  27. package/dist/client/Session.d.ts.map +0 -1
  28. package/dist/client/Session.js +0 -392
  29. package/dist/client/Session.js.map +0 -1
  30. package/dist/client/index.d.ts +0 -10
  31. package/dist/client/index.d.ts.map +0 -1
  32. package/dist/client/index.js +0 -9
  33. package/dist/client/index.js.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/node.d.ts.map +0 -1
  36. package/dist/tools/McpServer.d.ts +0 -117
  37. package/dist/tools/McpServer.d.ts.map +0 -1
  38. package/dist/tools/McpServer.js +0 -142
  39. package/dist/tools/McpServer.js.map +0 -1
  40. package/dist/tools/index.d.ts +0 -9
  41. package/dist/tools/index.d.ts.map +0 -1
  42. package/dist/tools/index.js +0 -8
  43. package/dist/tools/index.js.map +0 -1
  44. package/dist/tools/tool.d.ts +0 -146
  45. package/dist/tools/tool.d.ts.map +0 -1
  46. package/dist/tools/tool.js +0 -232
  47. package/dist/tools/tool.js.map +0 -1
  48. package/dist/transport/Transport.d.ts +0 -82
  49. package/dist/transport/Transport.d.ts.map +0 -1
  50. package/dist/transport/Transport.js +0 -47
  51. package/dist/transport/Transport.js.map +0 -1
  52. package/dist/transport/WebSocketTransport.d.ts +0 -78
  53. package/dist/transport/WebSocketTransport.d.ts.map +0 -1
  54. package/dist/transport/WebSocketTransport.js +0 -258
  55. package/dist/transport/WebSocketTransport.js.map +0 -1
  56. package/dist/transport/index.d.ts +0 -10
  57. package/dist/transport/index.d.ts.map +0 -1
  58. package/dist/transport/index.js +0 -8
  59. package/dist/transport/index.js.map +0 -1
  60. package/dist/types/index.d.ts +0 -12
  61. package/dist/types/index.d.ts.map +0 -1
  62. package/dist/types/index.js +0 -8
  63. package/dist/types/index.js.map +0 -1
  64. package/dist/types/messages.d.ts +0 -327
  65. package/dist/types/messages.d.ts.map +0 -1
  66. package/dist/types/messages.js +0 -133
  67. package/dist/types/messages.js.map +0 -1
  68. package/dist/types/options.d.ts +0 -212
  69. package/dist/types/options.d.ts.map +0 -1
  70. package/dist/types/options.js +0 -8
  71. package/dist/types/options.js.map +0 -1
  72. package/dist/types/results.d.ts +0 -186
  73. package/dist/types/results.d.ts.map +0 -1
  74. package/dist/types/results.js +0 -7
  75. package/dist/types/results.js.map +0 -1
  76. package/dist/types/token.d.ts +0 -124
  77. package/dist/types/token.d.ts.map +0 -1
  78. package/dist/types/token.js +0 -7
  79. package/dist/types/token.js.map +0 -1
  80. package/dist/types/tools.d.ts +0 -234
  81. package/dist/types/tools.d.ts.map +0 -1
  82. package/dist/types/tools.js +0 -31
  83. package/dist/types/tools.js.map +0 -1
  84. package/dist/utils/errors.d.ts +0 -80
  85. package/dist/utils/errors.d.ts.map +0 -1
  86. package/dist/utils/errors.js +0 -158
  87. package/dist/utils/errors.js.map +0 -1
  88. package/dist/utils/index.d.ts +0 -8
  89. package/dist/utils/index.d.ts.map +0 -1
  90. package/dist/utils/index.js +0 -8
  91. package/dist/utils/index.js.map +0 -1
  92. package/dist/utils/token.d.ts +0 -104
  93. package/dist/utils/token.d.ts.map +0 -1
  94. package/dist/utils/token.js +0 -209
  95. package/dist/utils/token.js.map +0 -1
@@ -1,142 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,146 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tools/tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAA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AED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GACpD,cAAc,CAAC,MAAM,CAAC,CAExB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,GAChE,cAAc,CAAC,MAAM,CAAC,CAExB;AAED;;GAEG;AACH,wBAAgB,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"}
@@ -1,232 +0,0 @@
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
@@ -1 +0,0 @@
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;Q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ACH,MAAM,UAAU,IAAI,CAClB,IAAY,EACZ,WAAmB,EACnB,WAA4C,EAC5C,OAA6B;IAE7B,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,WAAW,CACzB,OAAqD;IAErD,OAAO,UAAU,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,OAAiE;IAEjE,OAAO,UAAU,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAC1C,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,QAAgB;IACxD,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;KAC7C,CAAC;AACJ,CAAC"}
@@ -1,82 +0,0 @@
1
- /**
2
- * Transport Interface
3
- *
4
- * Abstract interface for communication between the SDK and Chucky server.
5
- * Implementations can use WebSocket (browser/Node.js) or other protocols.
6
- */
7
- import type { ConnectionStatus, ClientEventHandlers } from '../types/options.js';
8
- import type { OutgoingMessage, IncomingMessage } from '../types/messages.js';
9
- /**
10
- * Transport event types
11
- */
12
- export interface TransportEvents extends ClientEventHandlers {
13
- /** Called when a message is received */
14
- onMessage?: (message: IncomingMessage) => void;
15
- /** Called when the transport is closed */
16
- onClose?: (code?: number, reason?: string) => void;
17
- }
18
- /**
19
- * Transport configuration
20
- */
21
- export interface TransportConfig {
22
- /** Server URL */
23
- url: string;
24
- /** Authentication token */
25
- token: string;
26
- /** Connection timeout in milliseconds */
27
- timeout?: number;
28
- /** Keep-alive interval in milliseconds */
29
- keepAliveInterval?: number;
30
- /** Auto-reconnect on disconnect */
31
- autoReconnect?: boolean;
32
- /** Maximum reconnect attempts */
33
- maxReconnectAttempts?: number;
34
- /** Debug mode */
35
- debug?: boolean;
36
- }
37
- /**
38
- * Abstract transport interface
39
- */
40
- export interface Transport {
41
- /** Current connection status */
42
- readonly status: ConnectionStatus;
43
- /**
44
- * Connect to the server
45
- */
46
- connect(): Promise<void>;
47
- /**
48
- * Disconnect from the server
49
- */
50
- disconnect(): Promise<void>;
51
- /**
52
- * Send a message to the server
53
- */
54
- send(message: OutgoingMessage): Promise<void>;
55
- /**
56
- * Set event handlers
57
- */
58
- setEventHandlers(handlers: TransportEvents): void;
59
- /**
60
- * Wait for connection to be ready
61
- */
62
- waitForReady(): Promise<void>;
63
- }
64
- /**
65
- * Base transport class with common functionality
66
- */
67
- export declare abstract class BaseTransport implements Transport {
68
- protected _status: ConnectionStatus;
69
- protected handlers: TransportEvents;
70
- protected config: TransportConfig;
71
- constructor(config: TransportConfig);
72
- get status(): ConnectionStatus;
73
- protected setStatus(status: ConnectionStatus): void;
74
- protected log(...args: unknown[]): void;
75
- protected logError(...args: unknown[]): void;
76
- setEventHandlers(handlers: TransportEvents): void;
77
- abstract connect(): Promise<void>;
78
- abstract disconnect(): Promise<void>;
79
- abstract send(message: OutgoingMessage): Promise<void>;
80
- abstract waitForReady(): Promise<void>;
81
- }
82
- //# sourceMappingURL=Transport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Transport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