@fatagnus/dink-sdk 2.1.0 → 2.4.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.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Method builder for fluent API to add AI context and examples to methods.
3
+ */
4
+ class MethodBuilder {
5
+ methodDescriptor;
6
+ parent;
7
+ constructor(parent, name, description) {
8
+ this.parent = parent;
9
+ this.methodDescriptor = {
10
+ name,
11
+ description,
12
+ };
13
+ }
14
+ /**
15
+ * Add AI context to this method.
16
+ */
17
+ withAI(aiContext) {
18
+ this.methodDescriptor.ai_context = aiContext;
19
+ return this;
20
+ }
21
+ /**
22
+ * Add another method to the service (returns to service builder context).
23
+ */
24
+ method(name, description) {
25
+ return this.parent.method(name, description);
26
+ }
27
+ /**
28
+ * Build the final ServiceDescriptor.
29
+ */
30
+ build() {
31
+ return this.parent.build();
32
+ }
33
+ /**
34
+ * Create a ServiceHandler from the builder with the given implementation.
35
+ */
36
+ toHandler(impl) {
37
+ return this.parent.toHandler(impl);
38
+ }
39
+ /**
40
+ * Internal: Get the method descriptor.
41
+ */
42
+ _getDescriptor() {
43
+ return this.methodDescriptor;
44
+ }
45
+ }
46
+ /**
47
+ * ServiceBuilder provides a fluent API for building ServiceDescriptor with AI context.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const builder = new ServiceBuilder('SensorService', '1.0.0')
52
+ * .description('Manages sensor data')
53
+ * .withAI({
54
+ * overview: 'Service for reading and managing sensor data',
55
+ * capabilities: ['read temperature', 'set thresholds'],
56
+ * })
57
+ * .method('ReadTemperature', 'Reads current temperature')
58
+ * .withAI({ when_to_use: 'When you need current sensor readings' })
59
+ * .withExample('typescript', 'await sensor.readTemperature()', 'Basic usage')
60
+ * .method('SetThreshold')
61
+ * .withAI({ when_to_use: 'When you need to configure alerts' });
62
+ *
63
+ * const handler = builder.toHandler({
64
+ * ReadTemperature: async () => ({ value: 23.5 }),
65
+ * SetThreshold: async (data) => ({ success: true }),
66
+ * });
67
+ *
68
+ * await edge.exposeService(handler);
69
+ * ```
70
+ */
71
+ export class ServiceBuilder {
72
+ descriptor;
73
+ methodBuilders = [];
74
+ currentMethodBuilder = null;
75
+ constructor(name, version) {
76
+ this.descriptor = {
77
+ name,
78
+ version,
79
+ };
80
+ }
81
+ /**
82
+ * Set the service description.
83
+ */
84
+ description(desc) {
85
+ this.descriptor.description = desc;
86
+ return this;
87
+ }
88
+ /**
89
+ * Add AI context to the service.
90
+ */
91
+ withAI(aiContext) {
92
+ this.descriptor.ai_context = aiContext;
93
+ return this;
94
+ }
95
+ /**
96
+ * Add a related service.
97
+ */
98
+ relatedService(serviceName) {
99
+ if (!this.descriptor.related_services) {
100
+ this.descriptor.related_services = [];
101
+ }
102
+ this.descriptor.related_services.push(serviceName);
103
+ return this;
104
+ }
105
+ /**
106
+ * Add a method to the service. Returns a MethodBuilder for fluent chaining.
107
+ */
108
+ method(name, description) {
109
+ // Finalize previous method builder if any
110
+ if (this.currentMethodBuilder) {
111
+ this.methodBuilders.push(this.currentMethodBuilder);
112
+ }
113
+ this.currentMethodBuilder = new MethodBuilder(this, name, description);
114
+ return this.currentMethodBuilder;
115
+ }
116
+ /**
117
+ * Build the final ServiceDescriptor.
118
+ */
119
+ build() {
120
+ // Finalize current method builder
121
+ if (this.currentMethodBuilder) {
122
+ this.methodBuilders.push(this.currentMethodBuilder);
123
+ this.currentMethodBuilder = null;
124
+ }
125
+ // Build methods array from method builders
126
+ this.descriptor.methods = this.methodBuilders.map((mb) => mb._getDescriptor());
127
+ return { ...this.descriptor };
128
+ }
129
+ /**
130
+ * Create a ServiceHandler from the builder with the given implementation.
131
+ *
132
+ * @param impl - Object mapping method names to handler functions
133
+ * @returns A ServiceHandler that can be passed to EdgeClient.exposeService()
134
+ */
135
+ toHandler(impl) {
136
+ const descriptor = this.build();
137
+ const methodNames = descriptor.methods?.map((m) => m.name) || [];
138
+ const definition = {
139
+ name: descriptor.name,
140
+ version: descriptor.version,
141
+ methods: methodNames,
142
+ };
143
+ return {
144
+ _descriptor: descriptor,
145
+ definition() {
146
+ return definition;
147
+ },
148
+ async handleRequest(method, data) {
149
+ const handler = impl[method];
150
+ if (!handler) {
151
+ throw new Error(`Method ${method} not implemented`);
152
+ }
153
+ let input;
154
+ try {
155
+ input = JSON.parse(new TextDecoder().decode(data));
156
+ }
157
+ catch {
158
+ input = {};
159
+ }
160
+ const result = await handler(input);
161
+ return new TextEncoder().encode(JSON.stringify(result));
162
+ },
163
+ };
164
+ }
165
+ }
166
+ //# sourceMappingURL=service-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-builder.js","sourceRoot":"","sources":["../../src/edge/service-builder.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,aAAa;IACT,gBAAgB,CAAmB;IACnC,MAAM,CAAiB;IAE/B,YAAY,MAAsB,EAAE,IAAY,EAAE,WAAoB;QACpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,gBAAgB,GAAG;YACtB,IAAI;YACJ,WAAW;SACZ,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAA0B;QAC/B,IAAI,CAAC,gBAAgB,CAAC,UAAU,GAAG,SAAS,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY,EAAE,WAAoB;QACvC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,IAAyD;QACjE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,C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MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;gBACpC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1D,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './types.js';
2
+ export * from './introspect.js';
3
+ export * from './introspect-utils.js';
2
4
  export { EdgeClient } from './edge/client.js';
3
5
  export { CenterClient } from './center/client.js';
4
6
  export type { ConnectionQuality, ConnectionQualityLevel, ConnectionQualityConfig, ConnectionState, } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,YAAY,EACV,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,GAChB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,YAAY,EACV,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,GAChB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './types.js';
2
+ export * from './introspect.js';
3
+ export * from './introspect-utils.js';
2
4
  export { EdgeClient } from './edge/client.js';
3
5
  export { CenterClient } from './center/client.js';
4
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Utility functions for working with introspection data.
3
+ * These functions provide formatting, validation, and search capabilities
4
+ * for ServiceDescriptor and MethodDescriptor types.
5
+ */
6
+ import type { ServiceDescriptor, MethodDescriptor } from './introspect.js';
7
+ /**
8
+ * Result of searching for methods across services.
9
+ */
10
+ export interface MethodSearchResult {
11
+ serviceName: string;
12
+ serviceVersion: string;
13
+ method: MethodDescriptor;
14
+ }
15
+ /**
16
+ * Result of validating a request against a schema.
17
+ */
18
+ export interface ValidationResult {
19
+ valid: boolean;
20
+ errors: string[];
21
+ }
22
+ /**
23
+ * Format a ServiceDescriptor as LLM-friendly text (llm.txt format).
24
+ * This format is optimized for AI agent consumption with full documentation.
25
+ */
26
+ export declare function formatAsLLMTxt(descriptor: ServiceDescriptor): string;
27
+ /**
28
+ * Format multiple ServiceDescriptors as a combined llm.txt document.
29
+ */
30
+ export declare function formatMultipleServicesAsLLMTxt(services: ServiceDescriptor[]): string;
31
+ /**
32
+ * Format a ServiceDescriptor in a minimal token format for AI agents.
33
+ * This is optimized for context window efficiency while preserving essential information.
34
+ */
35
+ export declare function formatAsCompactAI(descriptor: ServiceDescriptor): string;
36
+ /**
37
+ * Validate request data against a method's input schema.
38
+ * Returns a ValidationResult with valid=true if no schema or validation passes.
39
+ */
40
+ export declare function validateRequest(method: MethodDescriptor, data: Record<string, unknown>): ValidationResult;
41
+ /**
42
+ * Generate an example request object from a method's input schema.
43
+ * Returns an empty object if no schema is defined.
44
+ */
45
+ export declare function generateExampleRequest(method: MethodDescriptor): Record<string, unknown>;
46
+ /**
47
+ * Search services for methods matching a query.
48
+ * The query is matched case-insensitively against:
49
+ * - Service capabilities
50
+ * - Method names
51
+ * - Method descriptions
52
+ * - Method AI context (when_to_use, why_to_use, how_to_use)
53
+ */
54
+ export declare function findMethodsFor(services: ServiceDescriptor[], query: string): MethodSearchResult[];
55
+ //# sourceMappingURL=introspect-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect-utils.d.ts","sourceRoot":"","sources":["../src/introspect-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,gBAAgB,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,iBAAiB,GAAG,MAAM,CAoHpE;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAUpF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,iBAAiB,GAAG,MAAM,CAuCvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,CAUzG;AAwGD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMxF;AA6CD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAqEjG"}
@@ -0,0 +1,372 @@
1
+ /**
2
+ * Utility functions for working with introspection data.
3
+ * These functions provide formatting, validation, and search capabilities
4
+ * for ServiceDescriptor and MethodDescriptor types.
5
+ */
6
+ /**
7
+ * Format a ServiceDescriptor as LLM-friendly text (llm.txt format).
8
+ * This format is optimized for AI agent consumption with full documentation.
9
+ */
10
+ export function formatAsLLMTxt(descriptor) {
11
+ const lines = [];
12
+ // Header
13
+ lines.push(`# ${descriptor.name} LLM Reference`);
14
+ lines.push('');
15
+ // Description as blockquote
16
+ if (descriptor.description) {
17
+ lines.push(`> ${descriptor.description}`);
18
+ lines.push('');
19
+ }
20
+ // Service AI Context sections
21
+ if (descriptor.ai_context) {
22
+ if (descriptor.ai_context.overview) {
23
+ lines.push('## When to Use This Service');
24
+ lines.push('');
25
+ lines.push(descriptor.ai_context.overview);
26
+ lines.push('');
27
+ }
28
+ if (descriptor.ai_context.capabilities && descriptor.ai_context.capabilities.length > 0) {
29
+ lines.push('## Capabilities');
30
+ lines.push('');
31
+ for (const cap of descriptor.ai_context.capabilities) {
32
+ lines.push(`- ${cap}`);
33
+ }
34
+ lines.push('');
35
+ }
36
+ if (descriptor.ai_context.limitations && descriptor.ai_context.limitations.length > 0) {
37
+ lines.push('## Limitations');
38
+ lines.push('');
39
+ for (const lim of descriptor.ai_context.limitations) {
40
+ lines.push(`- ${lim}`);
41
+ }
42
+ lines.push('');
43
+ }
44
+ }
45
+ // Methods section
46
+ if (descriptor.methods && descriptor.methods.length > 0) {
47
+ lines.push('## Methods');
48
+ lines.push('');
49
+ for (const method of descriptor.methods) {
50
+ lines.push(`### ${method.name}`);
51
+ lines.push('');
52
+ if (method.description) {
53
+ lines.push(method.description);
54
+ lines.push('');
55
+ }
56
+ if (method.ai_context) {
57
+ if (method.ai_context.when_to_use) {
58
+ lines.push(`**When to use:** ${method.ai_context.when_to_use}`);
59
+ lines.push('');
60
+ }
61
+ if (method.ai_context.why_to_use) {
62
+ lines.push(`**Why:** ${method.ai_context.why_to_use}`);
63
+ lines.push('');
64
+ }
65
+ if (method.ai_context.how_to_use) {
66
+ lines.push(`**How:** ${method.ai_context.how_to_use}`);
67
+ lines.push('');
68
+ }
69
+ if (method.ai_context.preconditions && method.ai_context.preconditions.length > 0) {
70
+ lines.push('**Preconditions:**');
71
+ lines.push('');
72
+ for (const pre of method.ai_context.preconditions) {
73
+ lines.push(`- ${pre}`);
74
+ }
75
+ lines.push('');
76
+ }
77
+ if (method.ai_context.side_effects && method.ai_context.side_effects.length > 0) {
78
+ lines.push('**Side Effects:**');
79
+ lines.push('');
80
+ for (const effect of method.ai_context.side_effects) {
81
+ lines.push(`- ${effect}`);
82
+ }
83
+ lines.push('');
84
+ }
85
+ if (method.ai_context.related_methods && method.ai_context.related_methods.length > 0) {
86
+ lines.push(`**Related Methods:** ${method.ai_context.related_methods.join(', ')}`);
87
+ lines.push('');
88
+ }
89
+ }
90
+ if (method.input_schema && Object.keys(method.input_schema).length > 0) {
91
+ lines.push('#### Request Schema');
92
+ lines.push('');
93
+ lines.push('```json');
94
+ lines.push(JSON.stringify(method.input_schema, null, 2));
95
+ lines.push('```');
96
+ lines.push('');
97
+ }
98
+ if (method.output_schema && Object.keys(method.output_schema).length > 0) {
99
+ lines.push('#### Response Schema');
100
+ lines.push('');
101
+ lines.push('```json');
102
+ lines.push(JSON.stringify(method.output_schema, null, 2));
103
+ lines.push('```');
104
+ lines.push('');
105
+ }
106
+ }
107
+ }
108
+ // Related Services
109
+ if (descriptor.related_services && descriptor.related_services.length > 0) {
110
+ lines.push('## Related Services');
111
+ lines.push('');
112
+ for (const svc of descriptor.related_services) {
113
+ lines.push(`- ${svc}`);
114
+ }
115
+ lines.push('');
116
+ }
117
+ return lines.join('\n');
118
+ }
119
+ /**
120
+ * Format multiple ServiceDescriptors as a combined llm.txt document.
121
+ */
122
+ export function formatMultipleServicesAsLLMTxt(services) {
123
+ if (services.length === 0) {
124
+ return '';
125
+ }
126
+ const parts = [];
127
+ for (const svc of services) {
128
+ parts.push(formatAsLLMTxt(svc));
129
+ }
130
+ return parts.join('\n---\n\n');
131
+ }
132
+ /**
133
+ * Format a ServiceDescriptor in a minimal token format for AI agents.
134
+ * This is optimized for context window efficiency while preserving essential information.
135
+ */
136
+ export function formatAsCompactAI(descriptor) {
137
+ const lines = [];
138
+ // Compact header
139
+ let header = `${descriptor.name} v${descriptor.version}`;
140
+ if (descriptor.description) {
141
+ header += ` - ${descriptor.description}`;
142
+ }
143
+ lines.push(header);
144
+ // Compact AI context (one line each)
145
+ if (descriptor.ai_context) {
146
+ if (descriptor.ai_context.overview) {
147
+ lines.push(`Overview: ${descriptor.ai_context.overview}`);
148
+ }
149
+ if (descriptor.ai_context.capabilities && descriptor.ai_context.capabilities.length > 0) {
150
+ lines.push(`Capabilities: ${descriptor.ai_context.capabilities.join(', ')}`);
151
+ }
152
+ if (descriptor.ai_context.limitations && descriptor.ai_context.limitations.length > 0) {
153
+ lines.push(`Limitations: ${descriptor.ai_context.limitations.join(', ')}`);
154
+ }
155
+ }
156
+ // Compact methods list
157
+ if (descriptor.methods && descriptor.methods.length > 0) {
158
+ lines.push('Methods:');
159
+ for (const m of descriptor.methods) {
160
+ let methodLine = ` ${m.name}`;
161
+ if (m.description) {
162
+ methodLine += `: ${m.description}`;
163
+ }
164
+ lines.push(methodLine);
165
+ if (m.ai_context?.when_to_use) {
166
+ lines.push(` When: ${m.ai_context.when_to_use}`);
167
+ }
168
+ }
169
+ }
170
+ return lines.join('\n');
171
+ }
172
+ /**
173
+ * Validate request data against a method's input schema.
174
+ * Returns a ValidationResult with valid=true if no schema or validation passes.
175
+ */
176
+ export function validateRequest(method, data) {
177
+ if (!method.input_schema || Object.keys(method.input_schema).length === 0) {
178
+ return { valid: true, errors: [] };
179
+ }
180
+ const errors = validateAgainstSchema(method.input_schema, data, '');
181
+ return {
182
+ valid: errors.length === 0,
183
+ errors,
184
+ };
185
+ }
186
+ /**
187
+ * Internal function to validate data against a JSON schema.
188
+ */
189
+ function validateAgainstSchema(schema, data, path) {
190
+ const errors = [];
191
+ // Check required fields
192
+ const required = schema.required;
193
+ if (required && Array.isArray(required)) {
194
+ for (const fieldName of required) {
195
+ if (!(fieldName in data)) {
196
+ const fieldPath = path ? `${path}.${fieldName}` : fieldName;
197
+ errors.push(`missing required field: ${fieldPath}`);
198
+ }
199
+ }
200
+ }
201
+ // Check property types
202
+ const props = schema.properties;
203
+ if (props && typeof props === 'object') {
204
+ for (const [fieldName, value] of Object.entries(data)) {
205
+ const propSchema = props[fieldName];
206
+ if (!propSchema) {
207
+ continue;
208
+ }
209
+ const fieldPath = path ? `${path}.${fieldName}` : fieldName;
210
+ const typeErrors = validateType(propSchema, value, fieldPath);
211
+ errors.push(...typeErrors);
212
+ }
213
+ }
214
+ return errors;
215
+ }
216
+ /**
217
+ * Internal function to validate a value against its expected type.
218
+ */
219
+ function validateType(schema, value, path) {
220
+ const errors = [];
221
+ const expectedType = schema.type;
222
+ if (!expectedType) {
223
+ return errors;
224
+ }
225
+ switch (expectedType) {
226
+ case 'string':
227
+ if (typeof value !== 'string') {
228
+ errors.push(`${path}: expected string, got ${typeof value}`);
229
+ }
230
+ break;
231
+ case 'integer':
232
+ if (typeof value !== 'number' || !Number.isInteger(value)) {
233
+ errors.push(`${path}: expected integer, got ${typeof value}`);
234
+ }
235
+ break;
236
+ case 'number':
237
+ if (typeof value !== 'number') {
238
+ errors.push(`${path}: expected number, got ${typeof value}`);
239
+ }
240
+ break;
241
+ case 'boolean':
242
+ if (typeof value !== 'boolean') {
243
+ errors.push(`${path}: expected boolean, got ${typeof value}`);
244
+ }
245
+ break;
246
+ case 'object':
247
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
248
+ const nestedErrors = validateAgainstSchema(schema, value, path);
249
+ errors.push(...nestedErrors);
250
+ }
251
+ else {
252
+ errors.push(`${path}: expected object, got ${typeof value}`);
253
+ }
254
+ break;
255
+ case 'array':
256
+ if (!Array.isArray(value)) {
257
+ errors.push(`${path}: expected array, got ${typeof value}`);
258
+ }
259
+ break;
260
+ }
261
+ return errors;
262
+ }
263
+ /**
264
+ * Generate an example request object from a method's input schema.
265
+ * Returns an empty object if no schema is defined.
266
+ */
267
+ export function generateExampleRequest(method) {
268
+ if (!method.input_schema || Object.keys(method.input_schema).length === 0) {
269
+ return {};
270
+ }
271
+ return generateFromSchema(method.input_schema);
272
+ }
273
+ /**
274
+ * Internal function to generate example data from a JSON schema.
275
+ */
276
+ function generateFromSchema(schema) {
277
+ const schemaType = schema.type;
278
+ switch (schemaType) {
279
+ case 'object': {
280
+ const result = {};
281
+ const props = schema.properties;
282
+ if (props && typeof props === 'object') {
283
+ for (const [name, propSchema] of Object.entries(props)) {
284
+ result[name] = generateFromSchema(propSchema);
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+ case 'array': {
290
+ const items = schema.items;
291
+ if (items) {
292
+ return [generateFromSchema(items)];
293
+ }
294
+ return [];
295
+ }
296
+ case 'string':
297
+ return 'example';
298
+ case 'integer':
299
+ return 0;
300
+ case 'number':
301
+ return 0.0;
302
+ case 'boolean':
303
+ return false;
304
+ default:
305
+ return null;
306
+ }
307
+ }
308
+ /**
309
+ * Search services for methods matching a query.
310
+ * The query is matched case-insensitively against:
311
+ * - Service capabilities
312
+ * - Method names
313
+ * - Method descriptions
314
+ * - Method AI context (when_to_use, why_to_use, how_to_use)
315
+ */
316
+ export function findMethodsFor(services, query) {
317
+ if (!query) {
318
+ return [];
319
+ }
320
+ const lowerQuery = query.toLowerCase();
321
+ const results = [];
322
+ for (const svc of services) {
323
+ // Check if service capabilities match
324
+ let serviceMatches = false;
325
+ if (svc.ai_context?.capabilities) {
326
+ for (const cap of svc.ai_context.capabilities) {
327
+ if (cap.toLowerCase().includes(lowerQuery)) {
328
+ serviceMatches = true;
329
+ break;
330
+ }
331
+ }
332
+ }
333
+ if (!svc.methods) {
334
+ continue;
335
+ }
336
+ for (const method of svc.methods) {
337
+ let methodMatches = false;
338
+ // If service capability matches, check if method relates to that capability
339
+ if (serviceMatches) {
340
+ if (method.name.toLowerCase().includes(lowerQuery) ||
341
+ (method.description?.toLowerCase().includes(lowerQuery) ?? false)) {
342
+ methodMatches = true;
343
+ }
344
+ }
345
+ // Check method name
346
+ if (method.name.toLowerCase().includes(lowerQuery)) {
347
+ methodMatches = true;
348
+ }
349
+ // Check method description
350
+ if (method.description?.toLowerCase().includes(lowerQuery)) {
351
+ methodMatches = true;
352
+ }
353
+ // Check method AI context
354
+ if (method.ai_context) {
355
+ if (method.ai_context.when_to_use?.toLowerCase().includes(lowerQuery) ||
356
+ method.ai_context.why_to_use?.toLowerCase().includes(lowerQuery) ||
357
+ method.ai_context.how_to_use?.toLowerCase().includes(lowerQuery)) {
358
+ methodMatches = true;
359
+ }
360
+ }
361
+ if (methodMatches) {
362
+ results.push({
363
+ serviceName: svc.name,
364
+ serviceVersion: svc.version,
365
+ method,
366
+ });
367
+ }
368
+ }
369
+ }
370
+ return results;
371
+ }
372
+ //# sourceMappingURL=introspect-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect-utils.js","sourceRoot":"","sources":["../src/introspect-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,UAA6B;IAC1D,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,SAAS;IACT,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,IAAI,gBAAgB,CAAC,CAAC;IACjD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,4BAA4B;IAC5B,IAAI,UAAU,CAAC,WAAW,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