@optimizely-opal/opal-tool-ocp-sdk 0.0.0-beta.1
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.
- package/README.md +576 -0
- package/dist/decorator/Decorator.d.ts +46 -0
- package/dist/decorator/Decorator.d.ts.map +1 -0
- package/dist/decorator/Decorator.js +31 -0
- package/dist/decorator/Decorator.js.map +1 -0
- package/dist/decorator/Decorator.test.d.ts +2 -0
- package/dist/decorator/Decorator.test.d.ts.map +1 -0
- package/dist/decorator/Decorator.test.js +418 -0
- package/dist/decorator/Decorator.test.js.map +1 -0
- package/dist/function/ToolFunction.d.ts +15 -0
- package/dist/function/ToolFunction.d.ts.map +1 -0
- package/dist/function/ToolFunction.js +25 -0
- package/dist/function/ToolFunction.js.map +1 -0
- package/dist/function/ToolFunction.test.d.ts +2 -0
- package/dist/function/ToolFunction.test.d.ts.map +1 -0
- package/dist/function/ToolFunction.test.js +189 -0
- package/dist/function/ToolFunction.test.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/service/Service.d.ts +78 -0
- package/dist/service/Service.d.ts.map +1 -0
- package/dist/service/Service.js +204 -0
- package/dist/service/Service.js.map +1 -0
- package/dist/service/Service.test.d.ts +2 -0
- package/dist/service/Service.test.d.ts.map +1 -0
- package/dist/service/Service.test.js +341 -0
- package/dist/service/Service.test.js.map +1 -0
- package/dist/types/Models.d.ts +126 -0
- package/dist/types/Models.d.ts.map +1 -0
- package/dist/types/Models.js +181 -0
- package/dist/types/Models.js.map +1 -0
- package/package.json +58 -0
- package/src/decorator/Decorator.test.ts +523 -0
- package/src/decorator/Decorator.ts +83 -0
- package/src/function/ToolFunction.test.ts +224 -0
- package/src/function/ToolFunction.ts +25 -0
- package/src/index.ts +4 -0
- package/src/service/Service.test.ts +550 -0
- package/src/service/Service.ts +182 -0
- package/src/types/Models.ts +163 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const Decorator_1 = require("./Decorator");
|
|
10
|
+
const Service_1 = require("../service/Service");
|
|
11
|
+
const Models_1 = require("../types/Models");
|
|
12
|
+
// Mock the toolsService
|
|
13
|
+
jest.mock('../service/Service', () => ({
|
|
14
|
+
toolsService: {
|
|
15
|
+
registerTool: jest.fn(),
|
|
16
|
+
registerInteraction: jest.fn()
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
describe('Decorators', () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
describe('@tool decorator', () => {
|
|
24
|
+
it('should register a tool with minimal configuration', () => {
|
|
25
|
+
const config = {
|
|
26
|
+
name: 'testTool',
|
|
27
|
+
description: 'A test tool',
|
|
28
|
+
parameters: [],
|
|
29
|
+
endpoint: '/test-tool'
|
|
30
|
+
};
|
|
31
|
+
class TestClass {
|
|
32
|
+
async testMethod(_params) {
|
|
33
|
+
return { result: 'success' };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, Decorator_1.tool)(config)
|
|
38
|
+
], TestClass.prototype, "testMethod", null);
|
|
39
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('testTool', 'A test tool', expect.any(Function), [], '/test-tool', []);
|
|
40
|
+
// Ensure TestClass is considered "used" by TypeScript
|
|
41
|
+
expect(TestClass).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
it('should register a tool with parameters', () => {
|
|
44
|
+
const parameterConfig = {
|
|
45
|
+
name: 'inputParam',
|
|
46
|
+
type: Models_1.ParameterType.String,
|
|
47
|
+
description: 'An input parameter',
|
|
48
|
+
required: true
|
|
49
|
+
};
|
|
50
|
+
const config = {
|
|
51
|
+
name: 'toolWithParams',
|
|
52
|
+
description: 'A tool with parameters',
|
|
53
|
+
parameters: [parameterConfig],
|
|
54
|
+
endpoint: '/tool-with-params'
|
|
55
|
+
};
|
|
56
|
+
class TestClass {
|
|
57
|
+
async toolWithParams(_params) {
|
|
58
|
+
return { result: _params.inputParam };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, Decorator_1.tool)(config)
|
|
63
|
+
], TestClass.prototype, "toolWithParams", null);
|
|
64
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('toolWithParams', 'A tool with parameters', expect.any(Function), expect.arrayContaining([
|
|
65
|
+
expect.objectContaining({
|
|
66
|
+
name: 'inputParam',
|
|
67
|
+
type: Models_1.ParameterType.String,
|
|
68
|
+
description: 'An input parameter',
|
|
69
|
+
required: true
|
|
70
|
+
})
|
|
71
|
+
]), '/tool-with-params', []);
|
|
72
|
+
// Ensure TestClass is considered "used" by TypeScript
|
|
73
|
+
expect(TestClass).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
it('should register a tool with auth requirements', () => {
|
|
76
|
+
const authRequirementConfig = {
|
|
77
|
+
provider: 'optiId',
|
|
78
|
+
scopeBundle: 'calendar',
|
|
79
|
+
required: true
|
|
80
|
+
};
|
|
81
|
+
const config = {
|
|
82
|
+
name: 'toolWithAuth',
|
|
83
|
+
description: 'A tool with auth requirements',
|
|
84
|
+
parameters: [],
|
|
85
|
+
authRequirements: [authRequirementConfig],
|
|
86
|
+
endpoint: '/tool-with-auth'
|
|
87
|
+
};
|
|
88
|
+
class TestClass {
|
|
89
|
+
async toolWithAuth(_params, _authData) {
|
|
90
|
+
return { result: 'authenticated' };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, Decorator_1.tool)(config)
|
|
95
|
+
], TestClass.prototype, "toolWithAuth", null);
|
|
96
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('toolWithAuth', 'A tool with auth requirements', expect.any(Function), [], '/tool-with-auth', expect.arrayContaining([
|
|
97
|
+
expect.objectContaining({
|
|
98
|
+
provider: 'optiId',
|
|
99
|
+
scopeBundle: 'calendar',
|
|
100
|
+
required: true
|
|
101
|
+
})
|
|
102
|
+
]));
|
|
103
|
+
// Ensure TestClass is considered "used" by TypeScript
|
|
104
|
+
expect(TestClass).toBeDefined();
|
|
105
|
+
});
|
|
106
|
+
it('should register a tool with multiple parameters and auth requirements', () => {
|
|
107
|
+
const parameterConfigs = [
|
|
108
|
+
{
|
|
109
|
+
name: 'param1',
|
|
110
|
+
type: Models_1.ParameterType.String,
|
|
111
|
+
description: 'First parameter',
|
|
112
|
+
required: true
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'param2',
|
|
116
|
+
type: Models_1.ParameterType.Integer,
|
|
117
|
+
description: 'Second parameter',
|
|
118
|
+
required: false
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
const authRequirementConfigs = [
|
|
122
|
+
{
|
|
123
|
+
provider: 'optiId',
|
|
124
|
+
scopeBundle: 'calendar',
|
|
125
|
+
required: true
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
provider: 'Bearer',
|
|
129
|
+
scopeBundle: 'drive',
|
|
130
|
+
required: false
|
|
131
|
+
}
|
|
132
|
+
];
|
|
133
|
+
const config = {
|
|
134
|
+
name: 'complexTool',
|
|
135
|
+
description: 'A complex tool with multiple configs',
|
|
136
|
+
parameters: parameterConfigs,
|
|
137
|
+
authRequirements: authRequirementConfigs,
|
|
138
|
+
endpoint: '/complex-tool'
|
|
139
|
+
};
|
|
140
|
+
class TestClass {
|
|
141
|
+
async complexTool(_params, _authData) {
|
|
142
|
+
return { result: 'complex operation completed' };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
__decorate([
|
|
146
|
+
(0, Decorator_1.tool)(config)
|
|
147
|
+
], TestClass.prototype, "complexTool", null);
|
|
148
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('complexTool', 'A complex tool with multiple configs', expect.any(Function), expect.arrayContaining([
|
|
149
|
+
expect.objectContaining({
|
|
150
|
+
name: 'param1',
|
|
151
|
+
type: Models_1.ParameterType.String,
|
|
152
|
+
description: 'First parameter',
|
|
153
|
+
required: true
|
|
154
|
+
}),
|
|
155
|
+
expect.objectContaining({
|
|
156
|
+
name: 'param2',
|
|
157
|
+
type: Models_1.ParameterType.Integer,
|
|
158
|
+
description: 'Second parameter',
|
|
159
|
+
required: false
|
|
160
|
+
})
|
|
161
|
+
]), '/complex-tool', expect.arrayContaining([
|
|
162
|
+
expect.objectContaining({
|
|
163
|
+
provider: 'optiId',
|
|
164
|
+
scopeBundle: 'calendar',
|
|
165
|
+
required: true
|
|
166
|
+
}),
|
|
167
|
+
expect.objectContaining({
|
|
168
|
+
provider: 'Bearer',
|
|
169
|
+
scopeBundle: 'drive',
|
|
170
|
+
required: false
|
|
171
|
+
})
|
|
172
|
+
]));
|
|
173
|
+
// Ensure TestClass is considered "used" by TypeScript
|
|
174
|
+
expect(TestClass).toBeDefined();
|
|
175
|
+
});
|
|
176
|
+
it('should handle empty parameters array', () => {
|
|
177
|
+
const config = {
|
|
178
|
+
name: 'emptyParamsTool',
|
|
179
|
+
description: 'Tool with empty parameters',
|
|
180
|
+
parameters: [],
|
|
181
|
+
endpoint: '/empty-params'
|
|
182
|
+
};
|
|
183
|
+
class TestClass {
|
|
184
|
+
async emptyParamsTool() {
|
|
185
|
+
return { result: 'no params needed' };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
__decorate([
|
|
189
|
+
(0, Decorator_1.tool)(config)
|
|
190
|
+
], TestClass.prototype, "emptyParamsTool", null);
|
|
191
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('emptyParamsTool', 'Tool with empty parameters', expect.any(Function), [], '/empty-params', []);
|
|
192
|
+
expect(TestClass).toBeDefined();
|
|
193
|
+
});
|
|
194
|
+
it('should handle empty auth requirements array', () => {
|
|
195
|
+
const config = {
|
|
196
|
+
name: 'noAuthTool',
|
|
197
|
+
description: 'Tool with no auth requirements',
|
|
198
|
+
parameters: [],
|
|
199
|
+
authRequirements: [],
|
|
200
|
+
endpoint: '/no-auth'
|
|
201
|
+
};
|
|
202
|
+
class TestClass {
|
|
203
|
+
async noAuthTool(_params) {
|
|
204
|
+
return { result: 'no auth needed' };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, Decorator_1.tool)(config)
|
|
209
|
+
], TestClass.prototype, "noAuthTool", null);
|
|
210
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('noAuthTool', 'Tool with no auth requirements', expect.any(Function), [], '/no-auth', []);
|
|
211
|
+
expect(TestClass).toBeDefined();
|
|
212
|
+
});
|
|
213
|
+
it('should register the actual method as the handler', () => {
|
|
214
|
+
const config = {
|
|
215
|
+
name: 'handlerTest',
|
|
216
|
+
description: 'Test handler registration',
|
|
217
|
+
parameters: [],
|
|
218
|
+
endpoint: '/handler-test'
|
|
219
|
+
};
|
|
220
|
+
class TestClass {
|
|
221
|
+
async handlerTest(_params) {
|
|
222
|
+
return { result: 'handler called' };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
__decorate([
|
|
226
|
+
(0, Decorator_1.tool)(config)
|
|
227
|
+
], TestClass.prototype, "handlerTest", null);
|
|
228
|
+
const mockedRegisterTool = jest.mocked(Service_1.toolsService.registerTool);
|
|
229
|
+
const registerToolCall = mockedRegisterTool.mock.calls[0];
|
|
230
|
+
const registeredHandler = registerToolCall[2]; // Third argument is the handler
|
|
231
|
+
expect(typeof registeredHandler).toBe('function');
|
|
232
|
+
expect(TestClass).toBeDefined();
|
|
233
|
+
});
|
|
234
|
+
it('should handle different parameter types', () => {
|
|
235
|
+
const parameterConfigs = [
|
|
236
|
+
{ name: 'stringParam', type: Models_1.ParameterType.String, description: 'String param', required: true },
|
|
237
|
+
{ name: 'intParam', type: Models_1.ParameterType.Integer, description: 'Integer param', required: true },
|
|
238
|
+
{ name: 'numberParam', type: Models_1.ParameterType.Number, description: 'Number param', required: false },
|
|
239
|
+
{ name: 'boolParam', type: Models_1.ParameterType.Boolean, description: 'Boolean param', required: false },
|
|
240
|
+
{ name: 'listParam', type: Models_1.ParameterType.List, description: 'List param', required: false },
|
|
241
|
+
{ name: 'dictParam', type: Models_1.ParameterType.Dictionary, description: 'Dictionary param', required: false }
|
|
242
|
+
];
|
|
243
|
+
const config = {
|
|
244
|
+
name: 'multiTypeTool',
|
|
245
|
+
description: 'Tool with multiple parameter types',
|
|
246
|
+
parameters: parameterConfigs,
|
|
247
|
+
endpoint: '/multi-type'
|
|
248
|
+
};
|
|
249
|
+
class TestClass {
|
|
250
|
+
async multiTypeTool(_params) {
|
|
251
|
+
return { result: 'multi-type processing' };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
__decorate([
|
|
255
|
+
(0, Decorator_1.tool)(config)
|
|
256
|
+
], TestClass.prototype, "multiTypeTool", null);
|
|
257
|
+
expect(TestClass).toBeDefined();
|
|
258
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('multiTypeTool', 'Tool with multiple parameter types', expect.any(Function), expect.arrayContaining([
|
|
259
|
+
expect.objectContaining({ name: 'stringParam', type: Models_1.ParameterType.String }),
|
|
260
|
+
expect.objectContaining({ name: 'intParam', type: Models_1.ParameterType.Integer }),
|
|
261
|
+
expect.objectContaining({ name: 'numberParam', type: Models_1.ParameterType.Number }),
|
|
262
|
+
expect.objectContaining({ name: 'boolParam', type: Models_1.ParameterType.Boolean }),
|
|
263
|
+
expect.objectContaining({ name: 'listParam', type: Models_1.ParameterType.List }),
|
|
264
|
+
expect.objectContaining({ name: 'dictParam', type: Models_1.ParameterType.Dictionary })
|
|
265
|
+
]), '/multi-type', []);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
describe('@interaction decorator', () => {
|
|
269
|
+
it('should register an interaction with minimal configuration', () => {
|
|
270
|
+
const config = {
|
|
271
|
+
name: 'testInteraction',
|
|
272
|
+
endpoint: '/test-interaction'
|
|
273
|
+
};
|
|
274
|
+
class TestClass {
|
|
275
|
+
async testInteraction(_data) {
|
|
276
|
+
return { message: 'interaction completed' };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
__decorate([
|
|
280
|
+
(0, Decorator_1.interaction)(config)
|
|
281
|
+
], TestClass.prototype, "testInteraction", null);
|
|
282
|
+
expect(TestClass).toBeDefined();
|
|
283
|
+
expect(Service_1.toolsService.registerInteraction).toHaveBeenCalledWith('testInteraction', expect.any(Function), '/test-interaction');
|
|
284
|
+
});
|
|
285
|
+
it('should register the actual method as the handler', () => {
|
|
286
|
+
const config = {
|
|
287
|
+
name: 'handlerInteraction',
|
|
288
|
+
endpoint: '/handler-interaction'
|
|
289
|
+
};
|
|
290
|
+
class TestClass {
|
|
291
|
+
async handlerInteraction(_data) {
|
|
292
|
+
return { message: 'handler interaction' };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
__decorate([
|
|
296
|
+
(0, Decorator_1.interaction)(config)
|
|
297
|
+
], TestClass.prototype, "handlerInteraction", null);
|
|
298
|
+
const mockedRegisterInteraction = jest.mocked(Service_1.toolsService.registerInteraction);
|
|
299
|
+
const registerInteractionCall = mockedRegisterInteraction.mock.calls[0];
|
|
300
|
+
const registeredHandler = registerInteractionCall[1]; // Second argument is the handler
|
|
301
|
+
expect(TestClass).toBeDefined();
|
|
302
|
+
expect(typeof registeredHandler).toBe('function');
|
|
303
|
+
});
|
|
304
|
+
it('should handle multiple interactions in the same class', () => {
|
|
305
|
+
class TestClass {
|
|
306
|
+
async interaction1(_data) {
|
|
307
|
+
return { message: 'interaction 1' };
|
|
308
|
+
}
|
|
309
|
+
async interaction2(_data) {
|
|
310
|
+
return { message: 'interaction 2' };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
__decorate([
|
|
314
|
+
(0, Decorator_1.interaction)({ name: 'interaction1', endpoint: '/interaction1' })
|
|
315
|
+
], TestClass.prototype, "interaction1", null);
|
|
316
|
+
__decorate([
|
|
317
|
+
(0, Decorator_1.interaction)({ name: 'interaction2', endpoint: '/interaction2' })
|
|
318
|
+
], TestClass.prototype, "interaction2", null);
|
|
319
|
+
expect(TestClass).toBeDefined();
|
|
320
|
+
expect(Service_1.toolsService.registerInteraction).toHaveBeenCalledTimes(2);
|
|
321
|
+
expect(Service_1.toolsService.registerInteraction).toHaveBeenNthCalledWith(1, 'interaction1', expect.any(Function), '/interaction1');
|
|
322
|
+
expect(Service_1.toolsService.registerInteraction).toHaveBeenNthCalledWith(2, 'interaction2', expect.any(Function), '/interaction2');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
describe('mixed decorators', () => {
|
|
326
|
+
it('should handle both tool and interaction decorators in the same class', () => {
|
|
327
|
+
const toolConfig = {
|
|
328
|
+
name: 'mixedTool',
|
|
329
|
+
description: 'A tool in mixed class',
|
|
330
|
+
parameters: [
|
|
331
|
+
{ name: 'param1', type: Models_1.ParameterType.String, description: 'String param', required: true }
|
|
332
|
+
],
|
|
333
|
+
endpoint: '/mixed-tool'
|
|
334
|
+
};
|
|
335
|
+
const interactionConfig = {
|
|
336
|
+
name: 'mixedInteraction',
|
|
337
|
+
endpoint: '/mixed-interaction'
|
|
338
|
+
};
|
|
339
|
+
class MixedClass {
|
|
340
|
+
async mixedTool(_params) {
|
|
341
|
+
return { result: 'tool result' };
|
|
342
|
+
}
|
|
343
|
+
async mixedInteraction(_data) {
|
|
344
|
+
return { message: 'interaction result' };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
__decorate([
|
|
348
|
+
(0, Decorator_1.tool)(toolConfig)
|
|
349
|
+
], MixedClass.prototype, "mixedTool", null);
|
|
350
|
+
__decorate([
|
|
351
|
+
(0, Decorator_1.interaction)(interactionConfig)
|
|
352
|
+
], MixedClass.prototype, "mixedInteraction", null);
|
|
353
|
+
expect(MixedClass).toBeDefined();
|
|
354
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('mixedTool', 'A tool in mixed class', expect.any(Function), expect.arrayContaining([
|
|
355
|
+
expect.objectContaining({
|
|
356
|
+
name: 'param1',
|
|
357
|
+
type: Models_1.ParameterType.String,
|
|
358
|
+
description: 'String param',
|
|
359
|
+
required: true
|
|
360
|
+
})
|
|
361
|
+
]), '/mixed-tool', []);
|
|
362
|
+
expect(Service_1.toolsService.registerInteraction).toHaveBeenCalledWith('mixedInteraction', expect.any(Function), '/mixed-interaction');
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
describe('edge cases', () => {
|
|
366
|
+
it('should handle auth requirements with default required value', () => {
|
|
367
|
+
const authRequirementConfig = {
|
|
368
|
+
provider: 'optiId',
|
|
369
|
+
scopeBundle: 'calendar'
|
|
370
|
+
// required is not specified, should default to true in AuthRequirement constructor
|
|
371
|
+
};
|
|
372
|
+
const config = {
|
|
373
|
+
name: 'defaultAuthTool',
|
|
374
|
+
description: 'Tool with default auth requirement',
|
|
375
|
+
parameters: [],
|
|
376
|
+
authRequirements: [authRequirementConfig],
|
|
377
|
+
endpoint: '/default-auth'
|
|
378
|
+
};
|
|
379
|
+
class TestClass {
|
|
380
|
+
async defaultAuthTool(_params, _authData) {
|
|
381
|
+
return { result: 'default auth' };
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
__decorate([
|
|
385
|
+
(0, Decorator_1.tool)(config)
|
|
386
|
+
], TestClass.prototype, "defaultAuthTool", null);
|
|
387
|
+
expect(TestClass).toBeDefined();
|
|
388
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('defaultAuthTool', 'Tool with default auth requirement', expect.any(Function), [], '/default-auth', expect.arrayContaining([
|
|
389
|
+
expect.objectContaining({
|
|
390
|
+
provider: 'optiId',
|
|
391
|
+
scopeBundle: 'calendar',
|
|
392
|
+
required: true // Should default to true
|
|
393
|
+
})
|
|
394
|
+
]));
|
|
395
|
+
});
|
|
396
|
+
it('should handle undefined parameters and authRequirements arrays', () => {
|
|
397
|
+
const config = {
|
|
398
|
+
name: 'undefinedArraysTool',
|
|
399
|
+
description: 'Tool with undefined arrays',
|
|
400
|
+
endpoint: '/undefined-arrays'
|
|
401
|
+
// parameters and authRequirements are not defined
|
|
402
|
+
};
|
|
403
|
+
class TestClass {
|
|
404
|
+
async undefinedArraysTool(_params) {
|
|
405
|
+
return { result: 'undefined arrays handled' };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
__decorate([
|
|
409
|
+
(0, Decorator_1.tool)(config)
|
|
410
|
+
], TestClass.prototype, "undefinedArraysTool", null);
|
|
411
|
+
expect(TestClass).toBeDefined();
|
|
412
|
+
expect(Service_1.toolsService.registerTool).toHaveBeenCalledWith('undefinedArraysTool', 'Tool with undefined arrays', expect.any(Function), [], // Should be empty array when parameters is undefined
|
|
413
|
+
'/undefined-arrays', [] // Should be empty array when authRequirements is undefined
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
//# sourceMappingURL=Decorator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Decorator.test.js","sourceRoot":"","sources":["../../src/decorator/Decorator.test.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAAuH;AACvH,gDAAkD;AAClD,4CAAgD;AAEhD,wBAAwB;AACxB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,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zC,CAAC;aACH,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;YACxE,MAAM,MAAM,GAAG;gBACb,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EAAE,4BAA4B;gBACzC,QAAQ,EAAE,mBAAmB;gBAC7B,kDAAkD;aACrC,CAAC;YAEhB,MAAM,SAAS;gBAEA,AAAN,KAAK,CAAC,mBAAmB,CAAC,OAAY;oBAC3C,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;gBAChD,CAAC;aACF;YAHc;gBADZ,IAAA,gBAAI,EAAC,MAAM,CAAC;gEAGZ;YAGH,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YAChC,MAAM,CAAC,sBAAY,CAAC,YAAY,CAAC,CAAC,oBAAoB,CACpD,qBAAqB,EACrB,4BAA4B,EAC5B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EACpB,EAAE,EAAE,qDAAqD;YACzD,mBAAmB,EACnB,EAAE,CAAC,2DAA2D;aAC/D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Function, Response } from '@zaiusinc/app-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for tool-based function execution
|
|
4
|
+
* Provides a standard interface for processing requests through registered tools
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ToolFunction extends Function {
|
|
7
|
+
/**
|
|
8
|
+
* Process the incoming request using the tools service
|
|
9
|
+
*
|
|
10
|
+
* @returns Response as the HTTP response
|
|
11
|
+
*/
|
|
12
|
+
perform(): Promise<Response>;
|
|
13
|
+
protected abstract validateBearerToken(bearerToken: string): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ToolFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolFunction.d.ts","sourceRoot":"","sources":["../../src/function/ToolFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;GAGG;AACH,8BAAsB,YAAa,SAAQ,QAAQ;IAEjD;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;IASzC,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;CACrE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolFunction = void 0;
|
|
4
|
+
const app_sdk_1 = require("@zaiusinc/app-sdk");
|
|
5
|
+
const Service_1 = require("../service/Service");
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for tool-based function execution
|
|
8
|
+
* Provides a standard interface for processing requests through registered tools
|
|
9
|
+
*/
|
|
10
|
+
class ToolFunction extends app_sdk_1.Function {
|
|
11
|
+
/**
|
|
12
|
+
* Process the incoming request using the tools service
|
|
13
|
+
*
|
|
14
|
+
* @returns Response as the HTTP response
|
|
15
|
+
*/
|
|
16
|
+
async perform() {
|
|
17
|
+
const bearerToken = Service_1.toolsService.extractBearerToken(this.request.headers);
|
|
18
|
+
if (bearerToken && !this.validateBearerToken(bearerToken)) {
|
|
19
|
+
return new app_sdk_1.Response(403, { error: 'Forbidden' });
|
|
20
|
+
}
|
|
21
|
+
return Service_1.toolsService.processRequest(this.request);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ToolFunction = ToolFunction;
|
|
25
|
+
//# sourceMappingURL=ToolFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolFunction.js","sourceRoot":"","sources":["../../src/function/ToolFunction.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AACvD,gDAAkD;AAElD;;;GAGG;AACH,MAAsB,YAAa,SAAQ,kBAAQ;IAEjD;;;;OAIG;IACI,KAAK,CAAC,OAAO;QAClB,MAAM,WAAW,GAAG,sBAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1E,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,kBAAQ,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,sBAAY,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;CAGF;AAjBD,oCAiBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolFunction.test.d.ts","sourceRoot":"","sources":["../../src/function/ToolFunction.test.ts"],"names":[],"mappings":""}
|