@super_studio/ecforce-ai-agent-server 0.2.0-canary.2 → 0.2.0-canary.4

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,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ export {
34
+ __spreadValues,
35
+ __spreadProps,
36
+ __objRest
37
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+
34
+
35
+
36
+
37
+ exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__objRest = __objRest;
package/dist/index.js CHANGED
@@ -1,34 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkORMEWXMHjs = require('./chunk-ORMEWXMH.js');
32
6
 
33
7
  // src/lib/constants.ts
34
8
  var API_ENDPOINT = "http://localhost:4043";
@@ -105,7 +79,7 @@ var HttpClient = class {
105
79
  format,
106
80
  baseUrl,
107
81
  cancelToken
108
- } = _b, params = __objRest(_b, [
82
+ } = _b, params = _chunkORMEWXMHjs.__objRest.call(void 0, _b, [
109
83
  "body",
110
84
  "secure",
111
85
  "path",
@@ -122,8 +96,8 @@ var HttpClient = class {
122
96
  const responseFormat = format || requestParams.format;
123
97
  return this.customFetch(
124
98
  `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`,
125
- __spreadProps(__spreadValues({}, requestParams), {
126
- headers: __spreadValues(__spreadValues({}, requestParams.headers || {}), type && type !== "multipart/form-data" /* FormData */ ? { "Content-Type": type } : {}),
99
+ _chunkORMEWXMHjs.__spreadProps.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, {}, requestParams), {
100
+ headers: _chunkORMEWXMHjs.__spreadValues.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, {}, requestParams.headers || {}), type && type !== "multipart/form-data" /* FormData */ ? { "Content-Type": type } : {}),
127
101
  signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
128
102
  body: typeof body === "undefined" || body === null ? null : payloadFormatter(body)
129
103
  })
@@ -176,8 +150,8 @@ var HttpClient = class {
176
150
  return queryString ? `?${queryString}` : "";
177
151
  }
178
152
  mergeRequestParams(params1, params2) {
179
- return __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.baseApiParams), params1), params2 || {}), {
180
- headers: __spreadValues(__spreadValues(__spreadValues({}, this.baseApiParams.headers || {}), params1.headers || {}), params2 && params2.headers || {})
153
+ return _chunkORMEWXMHjs.__spreadProps.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, {}, this.baseApiParams), params1), params2 || {}), {
154
+ headers: _chunkORMEWXMHjs.__spreadValues.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, _chunkORMEWXMHjs.__spreadValues.call(void 0, {}, this.baseApiParams.headers || {}), params1.headers || {}), params2 && params2.headers || {})
181
155
  });
182
156
  }
183
157
  };
@@ -194,7 +168,7 @@ var Api = class extends HttpClient {
194
168
  * @request GET:/v1/version
195
169
  * @secure
196
170
  */
197
- getVersion: (params = {}) => this.request(__spreadValues({
171
+ getVersion: (params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
198
172
  path: `/v1/version`,
199
173
  method: "GET",
200
174
  secure: true,
@@ -211,7 +185,7 @@ var Api = class extends HttpClient {
211
185
  * @request POST:/v1/internal/create-session
212
186
  * @secure
213
187
  */
214
- createSession: (data, params = {}) => this.request(__spreadValues({
188
+ createSession: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
215
189
  path: `/v1/internal/create-session`,
216
190
  method: "POST",
217
191
  body: data,
@@ -230,7 +204,7 @@ var Api = class extends HttpClient {
230
204
  * @request GET:/v1/agent
231
205
  * @secure
232
206
  */
233
- list: (params = {}) => this.request(__spreadValues({
207
+ list: (params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
234
208
  path: `/v1/agent`,
235
209
  method: "GET",
236
210
  secure: true,
@@ -245,7 +219,7 @@ var Api = class extends HttpClient {
245
219
  * @request POST:/v1/agent
246
220
  * @secure
247
221
  */
248
- create: (data, params = {}) => this.request(__spreadValues({
222
+ create: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
249
223
  path: `/v1/agent`,
250
224
  method: "POST",
251
225
  body: data,
@@ -262,7 +236,7 @@ var Api = class extends HttpClient {
262
236
  * @request GET:/v1/agent/{id}
263
237
  * @secure
264
238
  */
265
- get: (id, params = {}) => this.request(__spreadValues({
239
+ get: (id, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
266
240
  path: `/v1/agent/${id}`,
267
241
  method: "GET",
268
242
  secure: true,
@@ -277,7 +251,7 @@ var Api = class extends HttpClient {
277
251
  * @request PUT:/v1/agent/{id}
278
252
  * @secure
279
253
  */
280
- update: (id, data, params = {}) => this.request(__spreadValues({
254
+ update: (id, data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
281
255
  path: `/v1/agent/${id}`,
282
256
  method: "PUT",
283
257
  body: data,
@@ -294,7 +268,7 @@ var Api = class extends HttpClient {
294
268
  * @request DELETE:/v1/agent/{id}
295
269
  * @secure
296
270
  */
297
- delete: (id, data, params = {}) => this.request(__spreadValues({
271
+ delete: (id, data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
298
272
  path: `/v1/agent/${id}`,
299
273
  method: "DELETE",
300
274
  body: data,
@@ -311,7 +285,7 @@ var Api = class extends HttpClient {
311
285
  * @request GET:/v1/agent/{id}/interface-features
312
286
  * @secure
313
287
  */
314
- getInterfaceFeatures: (id, params = {}) => this.request(__spreadValues({
288
+ getInterfaceFeatures: (id, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
315
289
  path: `/v1/agent/${id}/interface-features`,
316
290
  method: "GET",
317
291
  secure: true,
@@ -326,7 +300,7 @@ var Api = class extends HttpClient {
326
300
  * @request POST:/v1/agent/tool-settings
327
301
  * @secure
328
302
  */
329
- getToolSettings: (data, params = {}) => this.request(__spreadValues({
303
+ getToolSettings: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
330
304
  path: `/v1/agent/tool-settings`,
331
305
  method: "POST",
332
306
  body: data,
@@ -345,7 +319,7 @@ var Api = class extends HttpClient {
345
319
  * @request GET:/v1/account
346
320
  * @secure
347
321
  */
348
- list: (params = {}) => this.request(__spreadValues({
322
+ list: (params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
349
323
  path: `/v1/account`,
350
324
  method: "GET",
351
325
  secure: true,
@@ -360,7 +334,7 @@ var Api = class extends HttpClient {
360
334
  * @request GET:/v1/account/{projectId}
361
335
  * @secure
362
336
  */
363
- get: (projectId, params = {}) => this.request(__spreadValues({
337
+ get: (projectId, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
364
338
  path: `/v1/account/${projectId}`,
365
339
  method: "GET",
366
340
  secure: true,
@@ -377,7 +351,7 @@ var Api = class extends HttpClient {
377
351
  * @request GET:/v1/api-keys/{type}
378
352
  * @secure
379
353
  */
380
- list: (type, params = {}) => this.request(__spreadValues({
354
+ list: (type, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
381
355
  path: `/v1/api-keys/${type}`,
382
356
  method: "GET",
383
357
  secure: true,
@@ -392,7 +366,7 @@ var Api = class extends HttpClient {
392
366
  * @request POST:/v1/api-keys
393
367
  * @secure
394
368
  */
395
- create: (data, params = {}) => this.request(__spreadValues({
369
+ create: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
396
370
  path: `/v1/api-keys`,
397
371
  method: "POST",
398
372
  body: data,
@@ -409,7 +383,7 @@ var Api = class extends HttpClient {
409
383
  * @request PATCH:/v1/api-keys/{id}
410
384
  * @secure
411
385
  */
412
- update: (id, data, params = {}) => this.request(__spreadValues({
386
+ update: (id, data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
413
387
  path: `/v1/api-keys/${id}`,
414
388
  method: "PATCH",
415
389
  body: data,
@@ -426,7 +400,7 @@ var Api = class extends HttpClient {
426
400
  * @request DELETE:/v1/api-keys/{id}
427
401
  * @secure
428
402
  */
429
- delete: (id, data, params = {}) => this.request(__spreadValues({
403
+ delete: (id, data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
430
404
  path: `/v1/api-keys/${id}`,
431
405
  method: "DELETE",
432
406
  body: data,
@@ -445,7 +419,7 @@ var Api = class extends HttpClient {
445
419
  * @request POST:/v1/chat/list-messages
446
420
  * @secure
447
421
  */
448
- listMessages: (data, params = {}) => this.request(__spreadValues({
422
+ listMessages: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
449
423
  path: `/v1/chat/list-messages`,
450
424
  method: "POST",
451
425
  body: data,
@@ -462,7 +436,7 @@ var Api = class extends HttpClient {
462
436
  * @request POST:/v1/chat/my-list
463
437
  * @secure
464
438
  */
465
- myList: (data, params = {}) => this.request(__spreadValues({
439
+ myList: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
466
440
  path: `/v1/chat/my-list`,
467
441
  method: "POST",
468
442
  body: data,
@@ -479,7 +453,7 @@ var Api = class extends HttpClient {
479
453
  * @request POST:/v1/chat/get-title
480
454
  * @secure
481
455
  */
482
- getTitle: (data, params = {}) => this.request(__spreadValues({
456
+ getTitle: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
483
457
  path: `/v1/chat/get-title`,
484
458
  method: "POST",
485
459
  body: data,
@@ -496,7 +470,7 @@ var Api = class extends HttpClient {
496
470
  * @request POST:/v1/chat/submit-feedback
497
471
  * @secure
498
472
  */
499
- submitFeedback: (data, params = {}) => this.request(__spreadValues({
473
+ submitFeedback: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
500
474
  path: `/v1/chat/submit-feedback`,
501
475
  method: "POST",
502
476
  body: data,
@@ -513,7 +487,7 @@ var Api = class extends HttpClient {
513
487
  * @request POST:/v1/chat/delete-feedback
514
488
  * @secure
515
489
  */
516
- deleteFeedback: (data, params = {}) => this.request(__spreadValues({
490
+ deleteFeedback: (data, params = {}) => this.request(_chunkORMEWXMHjs.__spreadValues.call(void 0, {
517
491
  path: `/v1/chat/delete-feedback`,
518
492
  method: "POST",
519
493
  body: data,
package/dist/index.mjs CHANGED
@@ -1,34 +1,8 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
1
+ import {
2
+ __objRest,
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "./chunk-FWCSY2DS.mjs";
32
6
 
33
7
  // src/lib/constants.ts
34
8
  var API_ENDPOINT = "http://localhost:4043";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * このロジックは最新(@auth/core@0.37.2)のAuth.jsのjwt.tsからコピーされました。
3
+ */
4
+ /** Issues a JWT. By default, the JWT is encrypted using "A256CBC-HS512". */
5
+ export declare function encode<Payload = object>(params: JWTEncodeParams<Payload>): Promise<string>;
6
+ /** Decodes an Auth.js issued JWT. */
7
+ export declare function decode<Payload = object>(params: JWTDecodeParams): Promise<Payload | null>;
8
+ export interface JWTEncodeParams<Payload = object> {
9
+ /**
10
+ * The maximum age of the Auth.js issued JWT in seconds.
11
+ *
12
+ * @default 30 * 24 * 60 * 60 // 30 days
13
+ */
14
+ maxAge?: number;
15
+ /** Used in combination with `secret`, to derive the encryption secret for JWTs. */
16
+ salt: string;
17
+ /** Used in combination with `salt`, to derive the encryption secret for JWTs. */
18
+ secret: string | string[];
19
+ /** The JWT payload. */
20
+ token?: Payload;
21
+ }
22
+ export interface JWTDecodeParams {
23
+ /** Used in combination with `secret`, to derive the encryption secret for JWTs. */
24
+ salt: string;
25
+ /**
26
+ * Used in combination with `salt`, to derive the encryption secret for JWTs.
27
+ *
28
+ * @note
29
+ * You can also pass an array of secrets, in which case the first secret that successfully
30
+ * decrypts the JWT will be used. This is useful for rotating secrets without invalidating existing sessions.
31
+ * The newer secret should be added to the start of the array, which will be used for all new sessions.
32
+ */
33
+ secret: string | string[];
34
+ /** The Auth.js issued JWT to be decoded */
35
+ token?: string;
36
+ }
37
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/lib/jwt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkBH,4EAA4E;AAC5E,wBAAsB,MAAM,CAAC,OAAO,GAAG,MAAM,EAC3C,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,mBAqBjC;AAED,qCAAqC;AACrC,wBAAsB,MAAM,CAAC,OAAO,GAAG,MAAM,EAC3C,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAqCzB;AA2BD,MAAM,WAAW,eAAe,CAAC,OAAO,GAAG,MAAM;IAC/C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,uBAAuB;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 共通のMCPトークンのペイロード。
3
+ * すべてのapps(cdp, ma, bi)はこのトークンの形になります。
4
+ */
5
+ export type MCPTokenPayload = {
6
+ source: string;
7
+ user: {
8
+ id: string;
9
+ name: string;
10
+ email: string;
11
+ projectId: string;
12
+ };
13
+ };
14
+ /**
15
+ * Uses Auth.js JWT encoding/decoding.
16
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
17
+ */
18
+ export declare function createMCPToken(payload: MCPTokenPayload, options?: {
19
+ secret?: string;
20
+ salt?: string;
21
+ maxAge?: number;
22
+ }): Promise<{
23
+ token: string;
24
+ expiresAt: Date;
25
+ }>;
26
+ /**
27
+ * Uses Auth.js JWT encoding/decoding.
28
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
29
+ */
30
+ export declare function decodeMCPToken(token: string, options?: {
31
+ secret?: string;
32
+ salt?: string;
33
+ }): Promise<MCPTokenPayload>;
34
+ export declare function getMcpToken(req: Request): string;
35
+ //# sourceMappingURL=mcp-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth.d.ts","sourceRoot":"","sources":["../src/mcp-auth.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAKF;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;GAkBF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACA,OAAO,CAAC,eAAe,CAAC,CAe1B;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,UAMvC"}
@@ -0,0 +1,136 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-ORMEWXMH.js');
2
+
3
+ // src/lib/jwt.ts
4
+ var _hkdf = require('@panva/hkdf');
5
+
6
+
7
+
8
+
9
+
10
+ var _jose = require('jose');
11
+ var DEFAULT_MAX_AGE = 30 * 24 * 60 * 60;
12
+ var now = () => Date.now() / 1e3 | 0;
13
+ var alg = "dir";
14
+ var enc = "A256CBC-HS512";
15
+ async function encode(params) {
16
+ const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
17
+ const secrets = Array.isArray(secret) ? secret : [secret];
18
+ const encryptionSecret = await getDerivedEncryptionKey(
19
+ enc,
20
+ secrets[0],
21
+ salt
22
+ );
23
+ const thumbprint = await _jose.calculateJwkThumbprint.call(void 0,
24
+ { kty: "oct", k: _jose.base64url.encode(encryptionSecret) },
25
+ `sha${encryptionSecret.byteLength << 3}`
26
+ );
27
+ return await new (0, _jose.EncryptJWT)(token).setProtectedHeader({ alg, enc, kid: thumbprint }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(crypto.randomUUID()).encrypt(encryptionSecret);
28
+ }
29
+ async function decode(params) {
30
+ const { token, secret, salt } = params;
31
+ const secrets = Array.isArray(secret) ? secret : [secret];
32
+ if (!token) {
33
+ return null;
34
+ }
35
+ const { payload } = await _jose.jwtDecrypt.call(void 0,
36
+ token,
37
+ async ({ kid, enc: enc2 }) => {
38
+ for (const secret2 of secrets) {
39
+ const encryptionSecret = await getDerivedEncryptionKey(
40
+ enc2,
41
+ secret2,
42
+ salt
43
+ );
44
+ if (kid === void 0) {
45
+ return encryptionSecret;
46
+ }
47
+ const thumbprint = await _jose.calculateJwkThumbprint.call(void 0,
48
+ { kty: "oct", k: _jose.base64url.encode(encryptionSecret) },
49
+ `sha${encryptionSecret.byteLength << 3}`
50
+ );
51
+ if (kid === thumbprint) {
52
+ return encryptionSecret;
53
+ }
54
+ }
55
+ throw new Error("no matching decryption secret");
56
+ },
57
+ {
58
+ clockTolerance: 15,
59
+ keyManagementAlgorithms: [alg],
60
+ contentEncryptionAlgorithms: [enc, "A256GCM"]
61
+ }
62
+ );
63
+ return payload;
64
+ }
65
+ async function getDerivedEncryptionKey(enc2, keyMaterial, salt) {
66
+ let length;
67
+ switch (enc2) {
68
+ case "A256CBC-HS512":
69
+ length = 64;
70
+ break;
71
+ case "A256GCM":
72
+ length = 32;
73
+ break;
74
+ default:
75
+ throw new Error("Unsupported JWT Content Encryption Algorithm");
76
+ }
77
+ return await _hkdf.hkdf.call(void 0,
78
+ "sha256",
79
+ keyMaterial,
80
+ salt,
81
+ `Auth.js Generated Encryption Key (${salt})`,
82
+ length
83
+ );
84
+ }
85
+
86
+ // src/mcp-auth.ts
87
+ var DEFAULT_MAX_AGE2 = 60 * 10;
88
+ var DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
89
+ async function createMCPToken(payload, options) {
90
+ var _a, _b, _c;
91
+ const maxAge = (_a = options == null ? void 0 : options.maxAge) != null ? _a : DEFAULT_MAX_AGE2;
92
+ const secret = (_b = options == null ? void 0 : options.secret) != null ? _b : process.env.MCP_TOKEN_SECRET;
93
+ const salt = (_c = options == null ? void 0 : options.salt) != null ? _c : DEFAULT_SALT;
94
+ if (!secret || !salt) {
95
+ throw new Error("Secret or salt is not set");
96
+ }
97
+ const token = await encode({
98
+ token: payload,
99
+ secret,
100
+ salt,
101
+ maxAge
102
+ });
103
+ return {
104
+ token,
105
+ expiresAt: new Date(Date.now() + maxAge * 1e3)
106
+ };
107
+ }
108
+ async function decodeMCPToken(token, options) {
109
+ var _a, _b;
110
+ const secret = (_a = options == null ? void 0 : options.secret) != null ? _a : process.env.MCP_TOKEN_SECRET;
111
+ const salt = (_b = options == null ? void 0 : options.salt) != null ? _b : DEFAULT_SALT;
112
+ if (!secret || !salt) {
113
+ throw new Error("Secret or salt is not set");
114
+ }
115
+ const decoded = await decode({
116
+ token,
117
+ secret,
118
+ salt
119
+ });
120
+ if (!decoded) {
121
+ throw new Error("Invalid token");
122
+ }
123
+ return decoded;
124
+ }
125
+ function getMcpToken(req) {
126
+ const mcpToken = req.headers.get("X-MCP-Token");
127
+ if (!mcpToken || typeof mcpToken !== "string") {
128
+ throw new Error("Unauthorized");
129
+ }
130
+ return mcpToken;
131
+ }
132
+
133
+
134
+
135
+
136
+ exports.createMCPToken = createMCPToken; exports.decodeMCPToken = decodeMCPToken; exports.getMcpToken = getMcpToken;
@@ -0,0 +1,136 @@
1
+ import "./chunk-FWCSY2DS.mjs";
2
+
3
+ // src/lib/jwt.ts
4
+ import { hkdf } from "@panva/hkdf";
5
+ import {
6
+ base64url,
7
+ calculateJwkThumbprint,
8
+ EncryptJWT,
9
+ jwtDecrypt
10
+ } from "jose";
11
+ var DEFAULT_MAX_AGE = 30 * 24 * 60 * 60;
12
+ var now = () => Date.now() / 1e3 | 0;
13
+ var alg = "dir";
14
+ var enc = "A256CBC-HS512";
15
+ async function encode(params) {
16
+ const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
17
+ const secrets = Array.isArray(secret) ? secret : [secret];
18
+ const encryptionSecret = await getDerivedEncryptionKey(
19
+ enc,
20
+ secrets[0],
21
+ salt
22
+ );
23
+ const thumbprint = await calculateJwkThumbprint(
24
+ { kty: "oct", k: base64url.encode(encryptionSecret) },
25
+ `sha${encryptionSecret.byteLength << 3}`
26
+ );
27
+ return await new EncryptJWT(token).setProtectedHeader({ alg, enc, kid: thumbprint }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(crypto.randomUUID()).encrypt(encryptionSecret);
28
+ }
29
+ async function decode(params) {
30
+ const { token, secret, salt } = params;
31
+ const secrets = Array.isArray(secret) ? secret : [secret];
32
+ if (!token) {
33
+ return null;
34
+ }
35
+ const { payload } = await jwtDecrypt(
36
+ token,
37
+ async ({ kid, enc: enc2 }) => {
38
+ for (const secret2 of secrets) {
39
+ const encryptionSecret = await getDerivedEncryptionKey(
40
+ enc2,
41
+ secret2,
42
+ salt
43
+ );
44
+ if (kid === void 0) {
45
+ return encryptionSecret;
46
+ }
47
+ const thumbprint = await calculateJwkThumbprint(
48
+ { kty: "oct", k: base64url.encode(encryptionSecret) },
49
+ `sha${encryptionSecret.byteLength << 3}`
50
+ );
51
+ if (kid === thumbprint) {
52
+ return encryptionSecret;
53
+ }
54
+ }
55
+ throw new Error("no matching decryption secret");
56
+ },
57
+ {
58
+ clockTolerance: 15,
59
+ keyManagementAlgorithms: [alg],
60
+ contentEncryptionAlgorithms: [enc, "A256GCM"]
61
+ }
62
+ );
63
+ return payload;
64
+ }
65
+ async function getDerivedEncryptionKey(enc2, keyMaterial, salt) {
66
+ let length;
67
+ switch (enc2) {
68
+ case "A256CBC-HS512":
69
+ length = 64;
70
+ break;
71
+ case "A256GCM":
72
+ length = 32;
73
+ break;
74
+ default:
75
+ throw new Error("Unsupported JWT Content Encryption Algorithm");
76
+ }
77
+ return await hkdf(
78
+ "sha256",
79
+ keyMaterial,
80
+ salt,
81
+ `Auth.js Generated Encryption Key (${salt})`,
82
+ length
83
+ );
84
+ }
85
+
86
+ // src/mcp-auth.ts
87
+ var DEFAULT_MAX_AGE2 = 60 * 10;
88
+ var DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
89
+ async function createMCPToken(payload, options) {
90
+ var _a, _b, _c;
91
+ const maxAge = (_a = options == null ? void 0 : options.maxAge) != null ? _a : DEFAULT_MAX_AGE2;
92
+ const secret = (_b = options == null ? void 0 : options.secret) != null ? _b : process.env.MCP_TOKEN_SECRET;
93
+ const salt = (_c = options == null ? void 0 : options.salt) != null ? _c : DEFAULT_SALT;
94
+ if (!secret || !salt) {
95
+ throw new Error("Secret or salt is not set");
96
+ }
97
+ const token = await encode({
98
+ token: payload,
99
+ secret,
100
+ salt,
101
+ maxAge
102
+ });
103
+ return {
104
+ token,
105
+ expiresAt: new Date(Date.now() + maxAge * 1e3)
106
+ };
107
+ }
108
+ async function decodeMCPToken(token, options) {
109
+ var _a, _b;
110
+ const secret = (_a = options == null ? void 0 : options.secret) != null ? _a : process.env.MCP_TOKEN_SECRET;
111
+ const salt = (_b = options == null ? void 0 : options.salt) != null ? _b : DEFAULT_SALT;
112
+ if (!secret || !salt) {
113
+ throw new Error("Secret or salt is not set");
114
+ }
115
+ const decoded = await decode({
116
+ token,
117
+ secret,
118
+ salt
119
+ });
120
+ if (!decoded) {
121
+ throw new Error("Invalid token");
122
+ }
123
+ return decoded;
124
+ }
125
+ function getMcpToken(req) {
126
+ const mcpToken = req.headers.get("X-MCP-Token");
127
+ if (!mcpToken || typeof mcpToken !== "string") {
128
+ throw new Error("Unauthorized");
129
+ }
130
+ return mcpToken;
131
+ }
132
+ export {
133
+ createMCPToken,
134
+ decodeMCPToken,
135
+ getMcpToken
136
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super_studio/ecforce-ai-agent-server",
3
- "version": "0.2.0-canary.2",
3
+ "version": "0.2.0-canary.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,11 @@
14
14
  "import": "./dist/index.mjs",
15
15
  "require": "./dist/index.js",
16
16
  "default": "./dist/index.js"
17
+ },
18
+ "./mcp-auth": {
19
+ "import": "./dist/mcp-auth.mjs",
20
+ "require": "./dist/mcp-auth.js",
21
+ "default": "./dist/mcp-auth.js"
17
22
  }
18
23
  },
19
24
  "publishConfig": {
@@ -26,6 +31,10 @@
26
31
  "tsup": "8.5.0",
27
32
  "tsx": "4.19.3"
28
33
  },
34
+ "dependencies": {
35
+ "@panva/hkdf": "^1.2.1",
36
+ "jose": "^6.0.6"
37
+ },
29
38
  "scripts": {
30
39
  "dev": "npm-run-all --parallel dev:main dev:types",
31
40
  "dev:main": "tsup --watch",
package/src/lib/jwt.ts ADDED
@@ -0,0 +1,142 @@
1
+ /**
2
+ * このロジックは最新(@auth/core@0.37.2)のAuth.jsのjwt.tsからコピーされました。
3
+ */
4
+
5
+ import { hkdf } from "@panva/hkdf";
6
+ import {
7
+ base64url,
8
+ calculateJwkThumbprint,
9
+ EncryptJWT,
10
+ jwtDecrypt,
11
+ } from "jose";
12
+
13
+ const DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days
14
+
15
+ const now = () => (Date.now() / 1000) | 0;
16
+
17
+ const alg = "dir";
18
+ const enc = "A256CBC-HS512";
19
+ type Digest = Parameters<typeof calculateJwkThumbprint>[1];
20
+
21
+ /** Issues a JWT. By default, the JWT is encrypted using "A256CBC-HS512". */
22
+ export async function encode<Payload = object>(
23
+ params: JWTEncodeParams<Payload>,
24
+ ) {
25
+ const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
26
+ const secrets = Array.isArray(secret) ? secret : [secret];
27
+ const encryptionSecret = await getDerivedEncryptionKey(
28
+ enc,
29
+ secrets[0]!,
30
+ salt,
31
+ );
32
+
33
+ const thumbprint = await calculateJwkThumbprint(
34
+ { kty: "oct", k: base64url.encode(encryptionSecret) },
35
+ `sha${encryptionSecret.byteLength << 3}` as Digest,
36
+ );
37
+ // @ts-expect-error `jose` allows any object as payload.
38
+ return await new EncryptJWT(token)
39
+ .setProtectedHeader({ alg, enc, kid: thumbprint })
40
+ .setIssuedAt()
41
+ .setExpirationTime(now() + maxAge)
42
+ .setJti(crypto.randomUUID())
43
+ .encrypt(encryptionSecret);
44
+ }
45
+
46
+ /** Decodes an Auth.js issued JWT. */
47
+ export async function decode<Payload = object>(
48
+ params: JWTDecodeParams,
49
+ ): Promise<Payload | null> {
50
+ const { token, secret, salt } = params;
51
+ const secrets = Array.isArray(secret) ? secret : [secret];
52
+ if (!token) {
53
+ return null;
54
+ }
55
+ const { payload } = await jwtDecrypt(
56
+ token,
57
+ async ({ kid, enc }) => {
58
+ for (const secret of secrets) {
59
+ const encryptionSecret = await getDerivedEncryptionKey(
60
+ enc,
61
+ secret,
62
+ salt,
63
+ );
64
+ if (kid === undefined) {
65
+ return encryptionSecret;
66
+ }
67
+
68
+ const thumbprint = await calculateJwkThumbprint(
69
+ { kty: "oct", k: base64url.encode(encryptionSecret) },
70
+ `sha${encryptionSecret.byteLength << 3}` as Digest,
71
+ );
72
+ if (kid === thumbprint) {
73
+ return encryptionSecret;
74
+ }
75
+ }
76
+
77
+ throw new Error("no matching decryption secret");
78
+ },
79
+ {
80
+ clockTolerance: 15,
81
+ keyManagementAlgorithms: [alg],
82
+ contentEncryptionAlgorithms: [enc, "A256GCM"],
83
+ },
84
+ );
85
+ return payload as Payload;
86
+ }
87
+
88
+ async function getDerivedEncryptionKey(
89
+ enc: string,
90
+ keyMaterial: Parameters<typeof hkdf>[1],
91
+ salt: Parameters<typeof hkdf>[2],
92
+ ) {
93
+ let length: number;
94
+ switch (enc) {
95
+ case "A256CBC-HS512":
96
+ length = 64;
97
+ break;
98
+ case "A256GCM":
99
+ length = 32;
100
+ break;
101
+ default:
102
+ throw new Error("Unsupported JWT Content Encryption Algorithm");
103
+ }
104
+ return await hkdf(
105
+ "sha256",
106
+ keyMaterial,
107
+ salt,
108
+ `Auth.js Generated Encryption Key (${salt})`,
109
+ length,
110
+ );
111
+ }
112
+
113
+ export interface JWTEncodeParams<Payload = object> {
114
+ /**
115
+ * The maximum age of the Auth.js issued JWT in seconds.
116
+ *
117
+ * @default 30 * 24 * 60 * 60 // 30 days
118
+ */
119
+ maxAge?: number;
120
+ /** Used in combination with `secret`, to derive the encryption secret for JWTs. */
121
+ salt: string;
122
+ /** Used in combination with `salt`, to derive the encryption secret for JWTs. */
123
+ secret: string | string[];
124
+ /** The JWT payload. */
125
+ token?: Payload;
126
+ }
127
+
128
+ export interface JWTDecodeParams {
129
+ /** Used in combination with `secret`, to derive the encryption secret for JWTs. */
130
+ salt: string;
131
+ /**
132
+ * Used in combination with `salt`, to derive the encryption secret for JWTs.
133
+ *
134
+ * @note
135
+ * You can also pass an array of secrets, in which case the first secret that successfully
136
+ * decrypts the JWT will be used. This is useful for rotating secrets without invalidating existing sessions.
137
+ * The newer secret should be added to the start of the array, which will be used for all new sessions.
138
+ */
139
+ secret: string | string[];
140
+ /** The Auth.js issued JWT to be decoded */
141
+ token?: string;
142
+ }
@@ -0,0 +1,83 @@
1
+ import { decode, encode } from "./lib/jwt";
2
+
3
+ /**
4
+ * 共通のMCPトークンのペイロード。
5
+ * すべてのapps(cdp, ma, bi)はこのトークンの形になります。
6
+ */
7
+ export type MCPTokenPayload = {
8
+ source: string;
9
+ user: {
10
+ id: string;
11
+ name: string;
12
+ email: string;
13
+ projectId: string;
14
+ };
15
+ };
16
+
17
+ const DEFAULT_MAX_AGE = 60 * 10; // 10 minutes
18
+ const DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
19
+
20
+ /**
21
+ * Uses Auth.js JWT encoding/decoding.
22
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
23
+ */
24
+ export async function createMCPToken(
25
+ payload: MCPTokenPayload,
26
+ options?: {
27
+ secret?: string;
28
+ salt?: string;
29
+ maxAge?: number;
30
+ },
31
+ ) {
32
+ const maxAge = options?.maxAge ?? DEFAULT_MAX_AGE;
33
+ const secret = options?.secret ?? process.env.MCP_TOKEN_SECRET;
34
+ const salt = options?.salt ?? DEFAULT_SALT;
35
+ if (!secret || !salt) {
36
+ throw new Error("Secret or salt is not set");
37
+ }
38
+ const token = await encode<MCPTokenPayload>({
39
+ token: payload,
40
+ secret,
41
+ salt,
42
+ maxAge,
43
+ });
44
+ return {
45
+ token,
46
+ expiresAt: new Date(Date.now() + maxAge * 1000),
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Uses Auth.js JWT encoding/decoding.
52
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
53
+ */
54
+ export async function decodeMCPToken(
55
+ token: string,
56
+ options?: {
57
+ secret?: string;
58
+ salt?: string;
59
+ },
60
+ ): Promise<MCPTokenPayload> {
61
+ const secret = options?.secret ?? process.env.MCP_TOKEN_SECRET;
62
+ const salt = options?.salt ?? DEFAULT_SALT;
63
+ if (!secret || !salt) {
64
+ throw new Error("Secret or salt is not set");
65
+ }
66
+ const decoded = await decode<MCPTokenPayload>({
67
+ token,
68
+ secret,
69
+ salt,
70
+ });
71
+ if (!decoded) {
72
+ throw new Error("Invalid token");
73
+ }
74
+ return decoded;
75
+ }
76
+
77
+ export function getMcpToken(req: Request) {
78
+ const mcpToken = req.headers.get("X-MCP-Token");
79
+ if (!mcpToken || typeof mcpToken !== "string") {
80
+ throw new Error("Unauthorized");
81
+ }
82
+ return mcpToken;
83
+ }