@dainprotocol/service-sdk 1.1.22 → 1.1.24

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.
@@ -322,14 +322,14 @@ export declare const ServiceWidgetSchema: z.ZodObject<{
322
322
  icon: z.ZodString;
323
323
  }, "strip", z.ZodTypeAny, {
324
324
  id?: string;
325
+ icon?: string;
325
326
  name?: string;
326
327
  description?: string;
327
- icon?: string;
328
328
  }, {
329
329
  id?: string;
330
+ icon?: string;
330
331
  name?: string;
331
332
  description?: string;
332
- icon?: string;
333
333
  }>;
334
334
  export declare const ServiceWidgetWithDataSchema: z.ZodObject<z.objectUtil.extendShape<{
335
335
  id: z.ZodString;
@@ -343,19 +343,19 @@ export declare const ServiceWidgetWithDataSchema: z.ZodObject<z.objectUtil.exten
343
343
  }>, "strip", z.ZodTypeAny, {
344
344
  id?: string;
345
345
  ui?: any;
346
+ icon?: string;
346
347
  name?: string;
347
348
  description?: string;
348
349
  text?: string;
349
350
  data?: any;
350
- icon?: string;
351
351
  }, {
352
352
  id?: string;
353
353
  ui?: any;
354
+ icon?: string;
354
355
  name?: string;
355
356
  description?: string;
356
357
  text?: string;
357
358
  data?: any;
358
- icon?: string;
359
359
  }>;
360
360
  export declare const OAuth2ProviderInfoSchema: z.ZodObject<{
361
361
  name: z.ZodString;
@@ -19,6 +19,7 @@ export declare const CitationSchema: z.ZodObject<{
19
19
  date: z.ZodOptional<z.ZodString>;
20
20
  type: z.ZodOptional<z.ZodEnum<["article", "book", "document", "webpage", "video", "report", "other"]>>;
21
21
  source: z.ZodOptional<z.ZodString>;
22
+ icon: z.ZodOptional<z.ZodString>;
22
23
  }, "strip", z.ZodTypeAny, {
23
24
  id?: string;
24
25
  ui?: any;
@@ -28,6 +29,7 @@ export declare const CitationSchema: z.ZodObject<{
28
29
  date?: string;
29
30
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
30
31
  source?: string;
32
+ icon?: string;
31
33
  }, {
32
34
  id?: string;
33
35
  ui?: any;
@@ -37,6 +39,7 @@ export declare const CitationSchema: z.ZodObject<{
37
39
  date?: string;
38
40
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
39
41
  source?: string;
42
+ icon?: string;
40
43
  }>;
41
44
  export declare const ContentSchema: z.ZodObject<{
42
45
  content: z.ZodString;
@@ -50,6 +53,7 @@ export declare const ContentSchema: z.ZodObject<{
50
53
  date: z.ZodOptional<z.ZodString>;
51
54
  type: z.ZodOptional<z.ZodEnum<["article", "book", "document", "webpage", "video", "report", "other"]>>;
52
55
  source: z.ZodOptional<z.ZodString>;
56
+ icon: z.ZodOptional<z.ZodString>;
53
57
  }, "strip", z.ZodTypeAny, {
54
58
  id?: string;
55
59
  ui?: any;
@@ -59,6 +63,7 @@ export declare const ContentSchema: z.ZodObject<{
59
63
  date?: string;
60
64
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
61
65
  source?: string;
66
+ icon?: string;
62
67
  }, {
63
68
  id?: string;
64
69
  ui?: any;
@@ -68,6 +73,7 @@ export declare const ContentSchema: z.ZodObject<{
68
73
  date?: string;
69
74
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
70
75
  source?: string;
76
+ icon?: string;
71
77
  }>;
72
78
  }, "strip", z.ZodTypeAny, {
73
79
  id?: string;
@@ -81,6 +87,7 @@ export declare const ContentSchema: z.ZodObject<{
81
87
  date?: string;
82
88
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
83
89
  source?: string;
90
+ icon?: string;
84
91
  };
85
92
  }, {
86
93
  id?: string;
@@ -94,6 +101,7 @@ export declare const ContentSchema: z.ZodObject<{
94
101
  date?: string;
95
102
  type?: "article" | "book" | "document" | "webpage" | "video" | "report" | "other";
96
103
  source?: string;
104
+ icon?: string;
97
105
  };
98
106
  }>;
99
107
  export declare const KnowledgeSearchInterface: ToolInterface;
@@ -17,6 +17,7 @@ exports.CitationSchema = zod_1.z.object({
17
17
  date: zod_1.z.string().optional().describe("Publication date"),
18
18
  type: zod_1.z.enum(["article", "book", "document", "webpage", "video", "report", "other"]).optional().describe("Type of source"),
19
19
  source: zod_1.z.string().optional().describe("Source name/publication"),
20
+ icon: zod_1.z.string().optional().describe("Icon for the citation (emoji, URL, or icon name)"),
20
21
  });
21
22
  // Content schema
22
23
  exports.ContentSchema = zod_1.z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,iCAAiC;AACjC,IAAY,iBAEX;AAFD,WAAY,iBAAiB;IAC3B,0DAAqC,CAAA;AACvC,CAAC,EAFW,iBAAiB,iCAAjB,iBAAiB,QAE5B;AAYD,kBAAkB;AACL,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IAC7D,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAC5D,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC;IACjD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IAC9D,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC;IACrD,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IACxD,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC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,CAAC,oDAAoD,CAAC;QAC9F,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;QAC/E,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;KAC9E,CAAC;CACH,CAAC;AAEF,yBAAyB;AACZ,QAAA,eAAe,GAAG;IAC7B,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,gCAAwB;CACtD,CAAC"}
@@ -2,9 +2,10 @@ import { DAINServiceConfig, DAINService } from "./types";
2
2
  import { defineDAINService as defineNodeService } from "./nodeService";
3
3
  import { defineDAINService as defineDenoService } from "./denoService";
4
4
  import { defineDAINService as defineCloudflareService } from "./cloudflareService";
5
+ import { createNextDainService } from "./nextService";
5
6
  import { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool } from "./core";
6
7
  import { ProcessHandler, RedisProcessStore, MemoryProcessStore } from "./processes";
7
8
  export declare const defineDAINService: (config: DAINServiceConfig) => DAINService;
8
- export { defineNodeService, defineDenoService, defineCloudflareService, createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, ProcessHandler, RedisProcessStore, MemoryProcessStore, };
9
+ export { defineNodeService, defineDenoService, defineCloudflareService, createNextDainService, createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, ProcessHandler, RedisProcessStore, MemoryProcessStore, };
9
10
  export * from './types';
10
11
  export * from './oauth2Store';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // File: src/service/index.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MemoryProcessStore = exports.RedisProcessStore = exports.ProcessHandler = exports.createOAuth2Tool = exports.CoreUtils = exports.createToolbox = exports.createService = exports.createTool = exports.defineCloudflareService = exports.defineDenoService = exports.defineNodeService = exports.defineDAINService = void 0;
4
+ exports.MemoryProcessStore = exports.RedisProcessStore = exports.ProcessHandler = exports.createOAuth2Tool = exports.CoreUtils = exports.createToolbox = exports.createService = exports.createTool = exports.createNextDainService = exports.defineCloudflareService = exports.defineDenoService = exports.defineNodeService = exports.defineDAINService = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const nodeService_1 = require("./nodeService");
7
7
  Object.defineProperty(exports, "defineNodeService", { enumerable: true, get: function () { return nodeService_1.defineDAINService; } });
@@ -9,6 +9,8 @@ const denoService_1 = require("./denoService");
9
9
  Object.defineProperty(exports, "defineDenoService", { enumerable: true, get: function () { return denoService_1.defineDAINService; } });
10
10
  const cloudflareService_1 = require("./cloudflareService");
11
11
  Object.defineProperty(exports, "defineCloudflareService", { enumerable: true, get: function () { return cloudflareService_1.defineDAINService; } });
12
+ const nextService_1 = require("./nextService");
13
+ Object.defineProperty(exports, "createNextDainService", { enumerable: true, get: function () { return nextService_1.createNextDainService; } });
12
14
  const core_1 = require("./core");
13
15
  Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return core_1.createTool; } });
14
16
  Object.defineProperty(exports, "createService", { enumerable: true, get: function () { return core_1.createService; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;;AAG7B,+CAAuE;AAWrE,kGAX4B,+BAAiB,OAW5B;AAVnB,+CAAuE;AAWrE,kGAX4B,+BAAiB,OAW5B;AAVnB,2DAAmF;AAWjF,wGAX4B,qCAAuB,OAW5B;AAVzB,iCAA+F;AAW7F,2FAXO,iBAAU,OAWP;AACV,8FAZmB,oBAAa,OAYnB;AACb,8FAbkC,oBAAa,OAalC;AACb,0FAdiD,gBAAS,OAcjD;AACT,iGAf4D,uBAAgB,OAe5D;AAdlB,2CAAoF;AAelF,+FAfO,0BAAc,OAeP;AACd,kGAhBuB,6BAAiB,OAgBvB;AACjB,mGAjB0C,8BAAkB,OAiB1C;AAfb,MAAM,iBAAiB,GAAG,CAAC,MAAyB,EAAe,EAAE;IAC1E,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;AACrG,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAgBF,sBAAsB;AACtB,kDAAwB;AAExB,wDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;;AAG7B,+CAAuE;AAYrE,kGAZ4B,+BAAiB,OAY5B;AAXnB,+CAAuE;AAYrE,kGAZ4B,+BAAiB,OAY5B;AAXnB,2DAAmF;AAYjF,wGAZ4B,qCAAuB,OAY5B;AAXzB,+CAAsD;AAYpD,sGAZO,mCAAqB,OAYP;AAXvB,iCAA+F;AAY7F,2FAZO,iBAAU,OAYP;AACV,8FAbmB,oBAAa,OAanB;AACb,8FAdkC,oBAAa,OAclC;AACb,0FAfiD,gBAAS,OAejD;AACT,iGAhB4D,uBAAgB,OAgB5D;AAflB,2CAAoF;AAgBlF,+FAhBO,0BAAc,OAgBP;AACd,kGAjBuB,6BAAiB,OAiBvB;AACjB,mGAlB0C,8BAAkB,OAkB1C;AAhBb,MAAM,iBAAiB,GAAG,CAAC,MAAyB,EAAe,EAAE;IAC1E,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;AACrG,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAiBF,sBAAsB;AACtB,kDAAwB;AAExB,wDAA8B"}
@@ -0,0 +1,23 @@
1
+ import { DAINServiceConfig, DAINService } from "./types";
2
+ import { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool } from "./core";
3
+ import { ProcessHandler, RedisProcessStore, MemoryProcessStore } from "./processes";
4
+ type NextRequest = Request & {
5
+ nextUrl: URL;
6
+ cookies: any;
7
+ headers: Headers;
8
+ };
9
+ export interface NextDAINServiceOptions {
10
+ basePath?: string;
11
+ }
12
+ export declare function createNextDainService(config: DAINServiceConfig): DAINService & {
13
+ createHandler: (options?: NextDAINServiceOptions) => (request: NextRequest, context?: any) => Promise<Response>;
14
+ createHandlers: (options?: NextDAINServiceOptions) => {
15
+ GET: (request: NextRequest, context?: any) => Promise<Response>;
16
+ POST: (request: NextRequest, context?: any) => Promise<Response>;
17
+ PUT: (request: NextRequest, context?: any) => Promise<Response>;
18
+ DELETE: (request: NextRequest, context?: any) => Promise<Response>;
19
+ OPTIONS: (request: NextRequest, context?: any) => Promise<Response>;
20
+ };
21
+ };
22
+ export { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, ProcessHandler, RedisProcessStore, MemoryProcessStore, };
23
+ export * from "./types";
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryProcessStore = exports.RedisProcessStore = exports.ProcessHandler = exports.createOAuth2Tool = exports.CoreUtils = exports.createToolbox = exports.createService = exports.createTool = void 0;
4
+ exports.createNextDainService = createNextDainService;
5
+ const tslib_1 = require("tslib");
6
+ const service_1 = require("./service");
7
+ const core_1 = require("./core");
8
+ Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return core_1.createTool; } });
9
+ Object.defineProperty(exports, "createService", { enumerable: true, get: function () { return core_1.createService; } });
10
+ Object.defineProperty(exports, "createToolbox", { enumerable: true, get: function () { return core_1.createToolbox; } });
11
+ Object.defineProperty(exports, "CoreUtils", { enumerable: true, get: function () { return core_1.CoreUtils; } });
12
+ Object.defineProperty(exports, "createOAuth2Tool", { enumerable: true, get: function () { return core_1.createOAuth2Tool; } });
13
+ const processes_1 = require("./processes");
14
+ Object.defineProperty(exports, "ProcessHandler", { enumerable: true, get: function () { return processes_1.ProcessHandler; } });
15
+ Object.defineProperty(exports, "RedisProcessStore", { enumerable: true, get: function () { return processes_1.RedisProcessStore; } });
16
+ Object.defineProperty(exports, "MemoryProcessStore", { enumerable: true, get: function () { return processes_1.MemoryProcessStore; } });
17
+ // Next.js response helpers
18
+ const NextResponseHelpers = {
19
+ json: (body, init) => {
20
+ return new Response(JSON.stringify(body), {
21
+ ...init,
22
+ headers: {
23
+ 'content-type': 'application/json',
24
+ ...(init?.headers || {}),
25
+ },
26
+ });
27
+ }
28
+ };
29
+ function createNextDainService(config) {
30
+ const baseService = (0, service_1.createBaseDAINService)(config);
31
+ // Next.js doesn't need a start method since it uses route handlers
32
+ const startNext = async () => {
33
+ throw new Error("startNext is not needed. Use createHandler() to get the Next.js route handler.");
34
+ };
35
+ // Create a Next.js route handler with flexible base path
36
+ const createHandler = (options) => {
37
+ const service = baseService.startService();
38
+ // Return the route handler function for Next.js App Router
39
+ return async function handler(request, context) {
40
+ try {
41
+ // Get the URL from the request
42
+ const url = new URL(request.url);
43
+ // Determine the base path
44
+ let basePath = options?.basePath;
45
+ if (!basePath && context?.params) {
46
+ // Try to infer base path from dynamic route params
47
+ // For [...path] routes, we need to reconstruct the base path
48
+ const pathParam = context.params.path;
49
+ if (Array.isArray(pathParam)) {
50
+ // Calculate base path by removing the dynamic segments
51
+ const fullPath = url.pathname;
52
+ const dynamicPath = '/' + pathParam.join('/');
53
+ basePath = fullPath.replace(dynamicPath, '') || '/';
54
+ }
55
+ }
56
+ // If still no base path, try to extract from the URL
57
+ if (!basePath) {
58
+ // Look for common patterns like /api/something/tools/...
59
+ const pathSegments = url.pathname.split('/');
60
+ const toolsIndex = pathSegments.findIndex(seg => ['tools', 'metadata', 'contexts', 'widgets', 'datasources', 'health', 'ping'].includes(seg));
61
+ if (toolsIndex > 0) {
62
+ basePath = '/' + pathSegments.slice(1, toolsIndex).join('/');
63
+ }
64
+ else {
65
+ basePath = '';
66
+ }
67
+ }
68
+ // Extract the path after the base path
69
+ const pathname = basePath && url.pathname.startsWith(basePath)
70
+ ? url.pathname.slice(basePath.length) || "/"
71
+ : url.pathname;
72
+ // Create a Request object that Hono can process
73
+ const honoRequest = new Request(`http://localhost${pathname}${url.search}`, {
74
+ method: request.method,
75
+ headers: request.headers,
76
+ body: request.body,
77
+ // @ts-ignore - duplex is needed for streaming but not in TS types
78
+ duplex: 'half',
79
+ });
80
+ // Let Hono handle the request
81
+ const honoResponse = await service.fetch(honoRequest);
82
+ // Convert Hono response to NextResponse
83
+ const responseHeaders = new Headers(honoResponse.headers);
84
+ // Handle streaming responses
85
+ if (responseHeaders.get('content-type')?.includes('text/event-stream')) {
86
+ // For SSE, we need to return the response as-is
87
+ return new Response(honoResponse.body, {
88
+ status: honoResponse.status,
89
+ headers: responseHeaders,
90
+ });
91
+ }
92
+ // For regular responses, read the body
93
+ const responseBody = await honoResponse.text();
94
+ // Return Response with proper headers
95
+ return new Response(responseBody, {
96
+ status: honoResponse.status,
97
+ headers: responseHeaders,
98
+ });
99
+ }
100
+ catch (error) {
101
+ console.error("DAIN Next.js handler error:", error);
102
+ return NextResponseHelpers.json({ error: "Internal server error" }, { status: 500 });
103
+ }
104
+ };
105
+ };
106
+ // Create handlers for specific HTTP methods (for better Next.js integration)
107
+ const createHandlers = (options) => {
108
+ const handler = createHandler(options);
109
+ return {
110
+ GET: handler,
111
+ POST: handler,
112
+ PUT: handler,
113
+ DELETE: handler,
114
+ OPTIONS: handler,
115
+ };
116
+ };
117
+ return {
118
+ ...baseService,
119
+ startNext,
120
+ createHandler,
121
+ createHandlers,
122
+ };
123
+ }
124
+ // Re-export all types
125
+ tslib_1.__exportStar(require("./types"), exports);
126
+ //# sourceMappingURL=nextService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextService.js","sourceRoot":"","sources":["../../src/service/nextService.ts"],"names":[],"mappings":";;;AAuCA,sDAiIC;;AAvKD,uCAAkD;AAClD,iCAMgB;AAmKd,2FAxKA,iBAAU,OAwKA;AACV,8FAxKA,oBAAa,OAwKA;AACb,8FAxKA,oBAAa,OAwKA;AACb,0FAxKA,gBAAS,OAwKA;AACT,iGAxKA,uBAAgB,OAwKA;AAtKlB,2CAAoF;AAuKlF,+FAvKO,0BAAc,OAuKP;AACd,kGAxKuB,6BAAiB,OAwKvB;AACjB,mGAzK0C,8BAAkB,OAyK1C;AA5JpB,2BAA2B;AAC3B,MAAM,mBAAmB,GAAG;IAC1B,I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AO;SACjB,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,WAAW;QACd,SAAS;QACT,aAAa;QACb,cAAc;KACR,CAAC;AACX,CAAC;AAaD,sBAAsB;AACtB,kDAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/service-sdk",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "DAIN Service SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,6 +61,10 @@
61
61
  "types": "./dist/plugins/index.d.ts",
62
62
  "default": "./dist/plugins/index.js"
63
63
  },
64
+ "./next": {
65
+ "types": "./dist/service/nextService.d.ts",
66
+ "default": "./dist/service/nextService.js"
67
+ },
64
68
  "./client/*": {
65
69
  "types": "./dist/client/*.d.ts",
66
70
  "default": "./dist/client/*.js"
@@ -88,6 +92,9 @@
88
92
  "plugins": [
89
93
  "./dist/plugins/index.d.ts"
90
94
  ],
95
+ "next": [
96
+ "./dist/service/nextService.d.ts"
97
+ ],
91
98
  "client/*": [
92
99
  "./dist/client/*.d.ts"
93
100
  ],
@@ -147,6 +154,7 @@
147
154
  "ioredis": "^5.4.1",
148
155
  "iron-session": "^8.0.4",
149
156
  "json-schema": "^0.4.0",
157
+ "next": "^15.3.3",
150
158
  "stripe": "^17.2.1",
151
159
  "supertest": "^7.0.0",
152
160
  "telegram": "^2.26.16",