@optimizely-opal/opal-tool-ocp-sdk 0.0.0-OCP-1487.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 +631 -0
- package/dist/auth/AuthUtils.d.ts +31 -0
- package/dist/auth/AuthUtils.d.ts.map +1 -0
- package/dist/auth/AuthUtils.js +64 -0
- package/dist/auth/AuthUtils.js.map +1 -0
- package/dist/auth/AuthUtils.test.d.ts +2 -0
- package/dist/auth/AuthUtils.test.d.ts.map +1 -0
- package/dist/auth/AuthUtils.test.js +469 -0
- package/dist/auth/AuthUtils.test.js.map +1 -0
- package/dist/auth/TokenVerifier.d.ts +31 -0
- package/dist/auth/TokenVerifier.d.ts.map +1 -0
- package/dist/auth/TokenVerifier.js +127 -0
- package/dist/auth/TokenVerifier.js.map +1 -0
- package/dist/auth/TokenVerifier.test.d.ts +2 -0
- package/dist/auth/TokenVerifier.test.d.ts.map +1 -0
- package/dist/auth/TokenVerifier.test.js +125 -0
- package/dist/auth/TokenVerifier.test.js.map +1 -0
- package/dist/decorator/Decorator.d.ts +48 -0
- package/dist/decorator/Decorator.d.ts.map +1 -0
- package/dist/decorator/Decorator.js +53 -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 +528 -0
- package/dist/decorator/Decorator.test.js.map +1 -0
- package/dist/function/GlobalToolFunction.d.ts +28 -0
- package/dist/function/GlobalToolFunction.d.ts.map +1 -0
- package/dist/function/GlobalToolFunction.js +56 -0
- package/dist/function/GlobalToolFunction.js.map +1 -0
- package/dist/function/GlobalToolFunction.test.d.ts +2 -0
- package/dist/function/GlobalToolFunction.test.d.ts.map +1 -0
- package/dist/function/GlobalToolFunction.test.js +425 -0
- package/dist/function/GlobalToolFunction.test.js.map +1 -0
- package/dist/function/ToolFunction.d.ts +28 -0
- package/dist/function/ToolFunction.d.ts.map +1 -0
- package/dist/function/ToolFunction.js +60 -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 +314 -0
- package/dist/function/ToolFunction.test.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/service/Service.d.ts +80 -0
- package/dist/service/Service.d.ts.map +1 -0
- package/dist/service/Service.js +210 -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 +427 -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 +64 -0
- package/src/auth/AuthUtils.test.ts +586 -0
- package/src/auth/AuthUtils.ts +66 -0
- package/src/auth/TokenVerifier.test.ts +165 -0
- package/src/auth/TokenVerifier.ts +145 -0
- package/src/decorator/Decorator.test.ts +649 -0
- package/src/decorator/Decorator.ts +111 -0
- package/src/function/GlobalToolFunction.test.ts +505 -0
- package/src/function/GlobalToolFunction.ts +61 -0
- package/src/function/ToolFunction.test.ts +374 -0
- package/src/function/ToolFunction.ts +64 -0
- package/src/index.ts +5 -0
- package/src/service/Service.test.ts +661 -0
- package/src/service/Service.ts +213 -0
- package/src/types/Models.ts +163 -0
|
@@ -0,0 +1,528 @@
|
|
|
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
|
+
describe('handler instance context', () => {
|
|
418
|
+
it('should allow tool handler to call class methods', async () => {
|
|
419
|
+
class TestClass {
|
|
420
|
+
getValue() {
|
|
421
|
+
return 'class-method-called';
|
|
422
|
+
}
|
|
423
|
+
async instanceMethodTest(_params) {
|
|
424
|
+
return { result: this.getValue() };
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
__decorate([
|
|
428
|
+
(0, Decorator_1.tool)({
|
|
429
|
+
name: 'instanceMethodTest',
|
|
430
|
+
description: 'Test calling class methods',
|
|
431
|
+
parameters: [],
|
|
432
|
+
endpoint: '/instance-method-test'
|
|
433
|
+
})
|
|
434
|
+
], TestClass.prototype, "instanceMethodTest", null);
|
|
435
|
+
// Get the registered handler
|
|
436
|
+
const mockedRegisterTool = jest.mocked(Service_1.toolsService.registerTool);
|
|
437
|
+
const registerToolCall = mockedRegisterTool.mock.calls.find((call) => call[0] === 'instanceMethodTest');
|
|
438
|
+
const registeredHandler = registerToolCall[2];
|
|
439
|
+
// Call the handler
|
|
440
|
+
const result = await registeredHandler(undefined, {}, {});
|
|
441
|
+
// Should be able to call class methods through 'this'
|
|
442
|
+
expect(result.result).toBe('class-method-called');
|
|
443
|
+
expect(TestClass).toBeDefined();
|
|
444
|
+
});
|
|
445
|
+
it('should allow interaction handler to call class methods', async () => {
|
|
446
|
+
class TestClass {
|
|
447
|
+
processData() {
|
|
448
|
+
return 'interaction-processed';
|
|
449
|
+
}
|
|
450
|
+
async instanceInteractionTest(_data) {
|
|
451
|
+
return { message: this.processData() };
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
__decorate([
|
|
455
|
+
(0, Decorator_1.interaction)({
|
|
456
|
+
name: 'instanceInteractionTest',
|
|
457
|
+
endpoint: '/instance-interaction-test'
|
|
458
|
+
})
|
|
459
|
+
], TestClass.prototype, "instanceInteractionTest", null);
|
|
460
|
+
// Get the registered handler
|
|
461
|
+
const mockedRegisterInteraction = jest.mocked(Service_1.toolsService.registerInteraction);
|
|
462
|
+
const registerInteractionCall = mockedRegisterInteraction.mock.calls.find((call) => call[0] === 'instanceInteractionTest');
|
|
463
|
+
const registeredHandler = registerInteractionCall[1];
|
|
464
|
+
// Call the handler
|
|
465
|
+
const result = await registeredHandler(undefined, {});
|
|
466
|
+
// Should be able to call class methods through 'this'
|
|
467
|
+
expect(result.message).toBe('interaction-processed');
|
|
468
|
+
expect(TestClass).toBeDefined();
|
|
469
|
+
});
|
|
470
|
+
it('should handle invalid functionContext gracefully for tool', async () => {
|
|
471
|
+
class TestClass {
|
|
472
|
+
getValue() {
|
|
473
|
+
return 'class-method-called';
|
|
474
|
+
}
|
|
475
|
+
async invalidContextTest(_params) {
|
|
476
|
+
return { result: this.getValue() };
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
__decorate([
|
|
480
|
+
(0, Decorator_1.tool)({
|
|
481
|
+
name: 'invalidContextTest',
|
|
482
|
+
description: 'Test handling invalid context',
|
|
483
|
+
parameters: [],
|
|
484
|
+
endpoint: '/invalid-context-test'
|
|
485
|
+
})
|
|
486
|
+
], TestClass.prototype, "invalidContextTest", null);
|
|
487
|
+
// Get the registered handler
|
|
488
|
+
const mockedRegisterTool = jest.mocked(Service_1.toolsService.registerTool);
|
|
489
|
+
const registerToolCall = mockedRegisterTool.mock.calls.find((call) => call[0] === 'invalidContextTest');
|
|
490
|
+
const registeredHandler = registerToolCall[2];
|
|
491
|
+
// Call the handler with an invalid functionContext (truthy but wrong type)
|
|
492
|
+
// This should trigger the instanceof check and create a new instance instead
|
|
493
|
+
const invalidContext = { notAnInstance: true, someOtherProperty: 'invalid' };
|
|
494
|
+
const result = await registeredHandler(invalidContext, {}, {});
|
|
495
|
+
// Should still work by creating a new instance
|
|
496
|
+
expect(result.result).toBe('class-method-called');
|
|
497
|
+
expect(TestClass).toBeDefined();
|
|
498
|
+
});
|
|
499
|
+
it('should handle invalid functionContext gracefully for interaction', async () => {
|
|
500
|
+
class TestClass {
|
|
501
|
+
processData() {
|
|
502
|
+
return 'interaction-processed';
|
|
503
|
+
}
|
|
504
|
+
async invalidContextInteractionTest(_data) {
|
|
505
|
+
return { message: this.processData() };
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
__decorate([
|
|
509
|
+
(0, Decorator_1.interaction)({
|
|
510
|
+
name: 'invalidContextInteractionTest',
|
|
511
|
+
endpoint: '/invalid-context-interaction-test'
|
|
512
|
+
})
|
|
513
|
+
], TestClass.prototype, "invalidContextInteractionTest", null);
|
|
514
|
+
// Get the registered handler
|
|
515
|
+
const mockedRegisterInteraction = jest.mocked(Service_1.toolsService.registerInteraction);
|
|
516
|
+
const registerInteractionCall = mockedRegisterInteraction.mock.calls.find((call) => call[0] === 'invalidContextInteractionTest');
|
|
517
|
+
const registeredHandler = registerInteractionCall[1];
|
|
518
|
+
// Call the handler with an invalid functionContext (truthy but wrong type)
|
|
519
|
+
// This should trigger the instanceof check and create a new instance instead
|
|
520
|
+
const invalidContext = { notAnInstance: true, someOtherProperty: 'invalid' };
|
|
521
|
+
const result = await registeredHandler(invalidContext, {});
|
|
522
|
+
// Should still work by creating a new instance
|
|
523
|
+
expect(result.message).toBe('interaction-processed');
|
|
524
|
+
expect(TestClass).toBeDefined();
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
//# 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,YAAY,EAAE;QACZ,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE;QACvB,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;KAC/B;CACF,CAAC,CAAC,CAAC;AACJ,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,MAAM,GAAe;gBACzB,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,aAAa;gBAC1B,UAAU,EAAE,EAAE;gBACd,QAAQ,EAAE,YAAY;aACvB,CAAC;YAEF,MAAM,SAAS;gBAEA,AAAN,KAAK,CAAC,UAAU,CAAC,OAAY;oBAClC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;gBAC/B,CAAC;aACF;YAHc;gBADZ,IAAA,gBAAI,EAAC,MAAM,CAAC;uDAGZ;YAGH,MAAM,CAAC,sBAAY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,CACvE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,+BAA+B,CACtD,CAAC;YACF,MAAM,iBAAiB,GAAG,uBAAwB,CAAC,CAAC,CAAC,CAAC;YAEtD,2EAA2E;YAC3E,6EAA6E;YAC7E,MAAM,cAAc,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC;YAC7E,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,cAAqB,EAAE,EAAE,CAAC,CAAC;YAElE,+CAA+C;YAC/C,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAC9D,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GlobalFunction, Response } from '@zaiusinc/app-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for global tool-based function execution
|
|
4
|
+
* Provides a standard interface for processing requests through registered tools
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class GlobalToolFunction extends GlobalFunction {
|
|
7
|
+
/**
|
|
8
|
+
* Override this method to implement any required credentials and/or other configuration
|
|
9
|
+
* exist and are valid. Reasonable caching should be utilized to prevent excessive requests to external resources.
|
|
10
|
+
* @async
|
|
11
|
+
* @returns true if the opal function is ready to use
|
|
12
|
+
*/
|
|
13
|
+
protected ready(): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Process the incoming request using the tools service
|
|
16
|
+
*
|
|
17
|
+
* @returns Response as the HTTP response
|
|
18
|
+
*/
|
|
19
|
+
perform(): Promise<Response>;
|
|
20
|
+
/**
|
|
21
|
+
* Authenticate the incoming request by validating only the OptiID token
|
|
22
|
+
*
|
|
23
|
+
* @param request - The incoming request
|
|
24
|
+
* @returns true if authentication succeeds
|
|
25
|
+
*/
|
|
26
|
+
private authorizeRequest;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=GlobalToolFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalToolFunction.d.ts","sourceRoot":"","sources":["../../src/function/GlobalToolFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAI9E;;;GAGG;AACH,8BAAsB,kBAAmB,SAAQ,cAAc;IAE7D;;;;;OAKG;IACH,SAAS,CAAC,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;IAezC;;;;;OAKG;YACW,gBAAgB;CAc/B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalToolFunction = void 0;
|
|
4
|
+
const app_sdk_1 = require("@zaiusinc/app-sdk");
|
|
5
|
+
const AuthUtils_1 = require("../auth/AuthUtils");
|
|
6
|
+
const Service_1 = require("../service/Service");
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for global tool-based function execution
|
|
9
|
+
* Provides a standard interface for processing requests through registered tools
|
|
10
|
+
*/
|
|
11
|
+
class GlobalToolFunction extends app_sdk_1.GlobalFunction {
|
|
12
|
+
/**
|
|
13
|
+
* Override this method to implement any required credentials and/or other configuration
|
|
14
|
+
* exist and are valid. Reasonable caching should be utilized to prevent excessive requests to external resources.
|
|
15
|
+
* @async
|
|
16
|
+
* @returns true if the opal function is ready to use
|
|
17
|
+
*/
|
|
18
|
+
ready() {
|
|
19
|
+
return Promise.resolve(true);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Process the incoming request using the tools service
|
|
23
|
+
*
|
|
24
|
+
* @returns Response as the HTTP response
|
|
25
|
+
*/
|
|
26
|
+
async perform() {
|
|
27
|
+
(0, app_sdk_1.amendLogContext)({ opalThreadId: this.request.headers.get('x-opal-thread-id') || '' });
|
|
28
|
+
if (!(await this.authorizeRequest())) {
|
|
29
|
+
return new app_sdk_1.Response(403, { error: 'Forbidden' });
|
|
30
|
+
}
|
|
31
|
+
if (this.request.path === '/ready') {
|
|
32
|
+
const isReady = await this.ready();
|
|
33
|
+
return new app_sdk_1.Response(200, { ready: isReady });
|
|
34
|
+
}
|
|
35
|
+
return Service_1.toolsService.processRequest(this.request, this);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Authenticate the incoming request by validating only the OptiID token
|
|
39
|
+
*
|
|
40
|
+
* @param request - The incoming request
|
|
41
|
+
* @returns true if authentication succeeds
|
|
42
|
+
*/
|
|
43
|
+
async authorizeRequest() {
|
|
44
|
+
if (this.request.path === '/discovery' || this.request.path === '/ready') {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const authInfo = AuthUtils_1.AuthUtils.extractAuthData(this.request);
|
|
48
|
+
if (!authInfo) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const { accessToken } = authInfo;
|
|
52
|
+
return await AuthUtils_1.AuthUtils.validateAccessToken(accessToken);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.GlobalToolFunction = GlobalToolFunction;
|
|
56
|
+
//# sourceMappingURL=GlobalToolFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalToolFunction.js","sourceRoot":"","sources":["../../src/function/GlobalToolFunction.ts"],"names":[],"mappings":";;;AAAA,+CAA8E;AAC9E,iDAA8C;AAC9C,gDAAkD;AAElD;;;GAGG;AACH,MAAsB,kBAAmB,SAAQ,wBAAc;IAE7D;;;;;OAKG;IACO,KAAK;QACb,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OA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