@dainprotocol/service-sdk 2.0.78 → 2.0.80
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/dist/client/api-sdk.d.ts +5 -42
- package/dist/client/api-sdk.js +130 -261
- package/dist/client/api-sdk.js.map +1 -1
- package/dist/client/client-auth.d.ts +1 -69
- package/dist/client/client-auth.js +26 -105
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client.d.ts +25 -116
- package/dist/client/client.js +157 -758
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.js +9 -14
- package/dist/client/types.js.map +1 -1
- package/dist/extensions/telegram-oauth.d.ts +6 -2
- package/dist/extensions/telegram-oauth.js +31 -333
- package/dist/extensions/telegram-oauth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -26
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/lib/convertToVercelTool.d.ts +11 -3
- package/dist/lib/convertToVercelTool.js +0 -1
- package/dist/lib/convertToVercelTool.js.map +1 -1
- package/dist/lib/payments/index.d.ts +14 -23
- package/dist/lib/payments/index.js +33 -47
- package/dist/lib/payments/index.js.map +1 -1
- package/dist/lib/schemaConversion.d.ts +0 -14
- package/dist/lib/schemaConversion.js +26 -56
- package/dist/lib/schemaConversion.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +1 -7
- package/dist/lib/schemaStructure.js +26 -57
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/plugins/base.d.ts +1 -29
- package/dist/plugins/base.js +1 -33
- package/dist/plugins/base.js.map +1 -1
- package/dist/plugins/citations-plugin.d.ts +6 -81
- package/dist/plugins/citations-plugin.js +46 -161
- package/dist/plugins/citations-plugin.js.map +1 -1
- package/dist/plugins/crypto-plugin.d.ts +18 -123
- package/dist/plugins/crypto-plugin.js +41 -248
- package/dist/plugins/crypto-plugin.js.map +1 -1
- package/dist/plugins/time-plugin.d.ts +8 -90
- package/dist/plugins/time-plugin.js +24 -131
- package/dist/plugins/time-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +5 -36
- package/dist/service/auth.d.ts +1 -49
- package/dist/service/auth.js +21 -99
- package/dist/service/auth.js.map +1 -1
- package/dist/service/cloudflareService.js +5 -6
- package/dist/service/cloudflareService.js.map +1 -1
- package/dist/service/core.js +23 -54
- package/dist/service/core.js.map +1 -1
- package/dist/service/denoService.js +14 -18
- package/dist/service/denoService.js.map +1 -1
- package/dist/service/nextService.d.ts +7 -10
- package/dist/service/nextService.js +18 -65
- package/dist/service/nextService.js.map +1 -1
- package/dist/service/nodeService.d.ts +1 -1
- package/dist/service/nodeService.js +18 -30
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/processes.d.ts +34 -36
- package/dist/service/processes.js +133 -285
- package/dist/service/processes.js.map +1 -1
- package/dist/service/server.d.ts +2 -9
- package/dist/service/server.js +164 -430
- package/dist/service/server.js.map +1 -1
- package/dist/service/webhooks.d.ts +15 -172
- package/dist/service/webhooks.js +52 -184
- package/dist/service/webhooks.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,119 +4,72 @@ exports.MemoryProcessStore = exports.RedisProcessStore = exports.ProcessHandler
|
|
|
4
4
|
exports.createNextDainService = createNextDainService;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const service_1 = require("./service");
|
|
7
|
+
const processes_1 = require("./processes");
|
|
8
|
+
Object.defineProperty(exports, "ProcessHandler", { enumerable: true, get: function () { return processes_1.ProcessHandler; } });
|
|
9
|
+
Object.defineProperty(exports, "RedisProcessStore", { enumerable: true, get: function () { return processes_1.RedisProcessStore; } });
|
|
10
|
+
Object.defineProperty(exports, "MemoryProcessStore", { enumerable: true, get: function () { return processes_1.MemoryProcessStore; } });
|
|
7
11
|
const core_1 = require("./core");
|
|
8
12
|
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return core_1.createTool; } });
|
|
9
13
|
Object.defineProperty(exports, "createService", { enumerable: true, get: function () { return core_1.createService; } });
|
|
10
14
|
Object.defineProperty(exports, "createToolbox", { enumerable: true, get: function () { return core_1.createToolbox; } });
|
|
11
15
|
Object.defineProperty(exports, "CoreUtils", { enumerable: true, get: function () { return core_1.CoreUtils; } });
|
|
12
16
|
Object.defineProperty(exports, "createOAuth2Tool", { enumerable: true, get: function () { return core_1.createOAuth2Tool; } });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
};
|
|
17
|
+
function jsonResponse(body, init) {
|
|
18
|
+
return new Response(JSON.stringify(body), {
|
|
19
|
+
...init,
|
|
20
|
+
headers: { 'content-type': 'application/json', ...(init?.headers || {}) },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
29
23
|
function createNextDainService(config) {
|
|
30
24
|
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
25
|
const createHandler = (options) => {
|
|
37
26
|
const service = baseService.startService();
|
|
38
|
-
// Return the route handler function for Next.js App Router
|
|
39
27
|
return async function handler(request, context) {
|
|
40
28
|
try {
|
|
41
|
-
// Get the URL from the request
|
|
42
29
|
const url = new URL(request.url);
|
|
43
|
-
// Determine the base path
|
|
44
30
|
let basePath = options?.basePath;
|
|
45
31
|
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
32
|
const pathParam = context.params.path;
|
|
49
33
|
if (Array.isArray(pathParam)) {
|
|
50
|
-
// Calculate base path by removing the dynamic segments
|
|
51
|
-
const fullPath = url.pathname;
|
|
52
34
|
const dynamicPath = '/' + pathParam.join('/');
|
|
53
|
-
basePath =
|
|
35
|
+
basePath = url.pathname.replace(dynamicPath, '') || '/';
|
|
54
36
|
}
|
|
55
37
|
}
|
|
56
|
-
// If still no base path, try to extract from the URL
|
|
57
38
|
if (!basePath) {
|
|
58
|
-
// Look for common patterns like /api/something/tools/...
|
|
59
39
|
const pathSegments = url.pathname.split('/');
|
|
60
40
|
const toolsIndex = pathSegments.findIndex(seg => ['tools', 'metadata', 'contexts', 'widgets', 'datasources', 'health', 'ping'].includes(seg));
|
|
61
|
-
|
|
62
|
-
basePath = '/' + pathSegments.slice(1, toolsIndex).join('/');
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
basePath = '';
|
|
66
|
-
}
|
|
41
|
+
basePath = toolsIndex > 0 ? '/' + pathSegments.slice(1, toolsIndex).join('/') : '';
|
|
67
42
|
}
|
|
68
|
-
// Extract the path after the base path
|
|
69
43
|
const pathname = basePath && url.pathname.startsWith(basePath)
|
|
70
44
|
? url.pathname.slice(basePath.length) || "/"
|
|
71
45
|
: url.pathname;
|
|
72
|
-
// Create a Request object that Hono can process
|
|
73
46
|
const honoRequest = new Request(`http://localhost${pathname}${url.search}`, {
|
|
74
47
|
method: request.method,
|
|
75
48
|
headers: request.headers,
|
|
76
49
|
body: request.body,
|
|
77
|
-
// @ts-
|
|
50
|
+
// @ts-expect-error duplex is needed for streaming
|
|
78
51
|
duplex: 'half',
|
|
79
52
|
});
|
|
80
|
-
// Let Hono handle the request
|
|
81
53
|
const honoResponse = await service.fetch(honoRequest);
|
|
82
|
-
// Convert Hono response to NextResponse
|
|
83
54
|
const responseHeaders = new Headers(honoResponse.headers);
|
|
84
|
-
// Handle streaming responses
|
|
85
55
|
if (responseHeaders.get('content-type')?.includes('text/event-stream')) {
|
|
86
|
-
|
|
87
|
-
return new Response(honoResponse.body, {
|
|
88
|
-
status: honoResponse.status,
|
|
89
|
-
headers: responseHeaders,
|
|
90
|
-
});
|
|
56
|
+
return new Response(honoResponse.body, { status: honoResponse.status, headers: responseHeaders });
|
|
91
57
|
}
|
|
92
|
-
|
|
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
|
-
});
|
|
58
|
+
return new Response(await honoResponse.text(), { status: honoResponse.status, headers: responseHeaders });
|
|
99
59
|
}
|
|
100
60
|
catch (error) {
|
|
101
61
|
console.error("DAIN Next.js handler error:", error);
|
|
102
|
-
return
|
|
62
|
+
return jsonResponse({ error: "Internal server error" }, { status: 500 });
|
|
103
63
|
}
|
|
104
64
|
};
|
|
105
65
|
};
|
|
106
|
-
// Create handlers for specific HTTP methods (for better Next.js integration)
|
|
107
66
|
const createHandlers = (options) => {
|
|
108
67
|
const handler = createHandler(options);
|
|
109
|
-
return {
|
|
110
|
-
GET: handler,
|
|
111
|
-
POST: handler,
|
|
112
|
-
PUT: handler,
|
|
113
|
-
DELETE: handler,
|
|
114
|
-
OPTIONS: handler,
|
|
115
|
-
};
|
|
68
|
+
return { GET: handler, POST: handler, PUT: handler, DELETE: handler, OPTIONS: handler };
|
|
116
69
|
};
|
|
117
70
|
return {
|
|
118
71
|
...baseService,
|
|
119
|
-
startNext,
|
|
72
|
+
startNext: async () => { throw new Error("startNext is not needed. Use createHandler() instead."); },
|
|
120
73
|
createHandler,
|
|
121
74
|
createHandlers,
|
|
122
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextService.js","sourceRoot":"","sources":["../../src/service/nextService.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"nextService.js","sourceRoot":"","sources":["../../src/service/nextService.ts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
|
|
1
1
|
import { DAINServiceConfig, DAINService } from "./types";
|
|
2
|
-
import { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, createAgent } from "./core";
|
|
3
2
|
import { ProcessHandler, RedisProcessStore, MemoryProcessStore } from "./processes";
|
|
4
3
|
import { WebhookTriggerRegistry, createWebhookTriggerRegistry, createSimpleTrigger, createTypedTrigger, type WebhookTrigger, type WebhookTriggerDefinition, type WebhookProcessResult } from "./webhooks";
|
|
5
4
|
import { HITLHandler, routeActionToService } from "./hitl";
|
|
6
5
|
import { forwardTriggerToAutomationCore, type TriggerForwardingConfig, type TriggerForwardResult } from "./trigger-forwarder";
|
|
7
6
|
import { SkillRegistry, createSkillRegistry, createGetSkillTool, type Skill } from "./skills";
|
|
8
7
|
import { ActionableToolBaseSchema, ActionSchema, MetadataSchema, extendActionableSchema, buildActionableTool, validateActionableSchema, type ActionableToolInput, type Action, type AutomationMetadata } from "./actionable-tools";
|
|
8
|
+
import { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, createAgent } from "./core";
|
|
9
9
|
export declare function defineDAINService(config: DAINServiceConfig): DAINService;
|
|
10
10
|
export { createTool, createService, createToolbox, CoreUtils, createOAuth2Tool, createAgent, ProcessHandler, RedisProcessStore, MemoryProcessStore, WebhookTriggerRegistry, createWebhookTriggerRegistry, createSimpleTrigger, createTypedTrigger, type WebhookTrigger, type WebhookTriggerDefinition, type WebhookProcessResult, SkillRegistry, createSkillRegistry, createGetSkillTool, type Skill, HITLHandler, routeActionToService, forwardTriggerToAutomationCore, type TriggerForwardingConfig, type TriggerForwardResult, ActionableToolBaseSchema, ActionSchema, MetadataSchema, extendActionableSchema, buildActionableTool, validateActionableSchema, type ActionableToolInput, type Action, type AutomationMetadata, };
|
|
11
11
|
export * from "./types";
|
|
@@ -4,13 +4,6 @@ exports.validateActionableSchema = exports.buildActionableTool = exports.extendA
|
|
|
4
4
|
exports.defineDAINService = defineDAINService;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
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
|
-
Object.defineProperty(exports, "createAgent", { enumerable: true, get: function () { return core_1.createAgent; } });
|
|
14
7
|
const processes_1 = require("./processes");
|
|
15
8
|
Object.defineProperty(exports, "ProcessHandler", { enumerable: true, get: function () { return processes_1.ProcessHandler; } });
|
|
16
9
|
Object.defineProperty(exports, "RedisProcessStore", { enumerable: true, get: function () { return processes_1.RedisProcessStore; } });
|
|
@@ -36,24 +29,22 @@ Object.defineProperty(exports, "MetadataSchema", { enumerable: true, get: functi
|
|
|
36
29
|
Object.defineProperty(exports, "extendActionableSchema", { enumerable: true, get: function () { return actionable_tools_1.extendActionableSchema; } });
|
|
37
30
|
Object.defineProperty(exports, "buildActionableTool", { enumerable: true, get: function () { return actionable_tools_1.buildActionableTool; } });
|
|
38
31
|
Object.defineProperty(exports, "validateActionableSchema", { enumerable: true, get: function () { return actionable_tools_1.validateActionableSchema; } });
|
|
32
|
+
const core_1 = require("./core");
|
|
33
|
+
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return core_1.createTool; } });
|
|
34
|
+
Object.defineProperty(exports, "createService", { enumerable: true, get: function () { return core_1.createService; } });
|
|
35
|
+
Object.defineProperty(exports, "createToolbox", { enumerable: true, get: function () { return core_1.createToolbox; } });
|
|
36
|
+
Object.defineProperty(exports, "CoreUtils", { enumerable: true, get: function () { return core_1.CoreUtils; } });
|
|
37
|
+
Object.defineProperty(exports, "createOAuth2Tool", { enumerable: true, get: function () { return core_1.createOAuth2Tool; } });
|
|
38
|
+
Object.defineProperty(exports, "createAgent", { enumerable: true, get: function () { return core_1.createAgent; } });
|
|
39
39
|
function defineDAINService(config) {
|
|
40
40
|
const baseService = (0, service_1.createBaseDAINService)(config);
|
|
41
|
-
const startNode = async (options = {
|
|
42
|
-
port:
|
|
43
|
-
}) => {
|
|
44
|
-
const { port = process.env.PORT ? parseInt(process.env.PORT) : 2022 } = options;
|
|
41
|
+
const startNode = async (options = {}) => {
|
|
42
|
+
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 2022);
|
|
45
43
|
const { serve } = await Promise.resolve().then(() => tslib_1.__importStar(require("@hono/node-server")));
|
|
46
44
|
const service = baseService.startService();
|
|
47
45
|
try {
|
|
48
|
-
const server = serve({
|
|
49
|
-
|
|
50
|
-
port,
|
|
51
|
-
});
|
|
52
|
-
if (config.serverExtensions) {
|
|
53
|
-
config.serverExtensions.forEach((extension) => {
|
|
54
|
-
extension.connect(service, server);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
46
|
+
const server = serve({ fetch: service.fetch, port });
|
|
47
|
+
config.serverExtensions?.forEach(extension => extension.connect(service, server));
|
|
57
48
|
console.log(`Server is listening on port ${port} -- Node Environment`);
|
|
58
49
|
console.log(`DAIN Service is running on version ${config.metadata.version}`);
|
|
59
50
|
return {
|
|
@@ -64,25 +55,22 @@ function defineDAINService(config) {
|
|
|
64
55
|
},
|
|
65
56
|
app: service,
|
|
66
57
|
oauth2: service.oauth2,
|
|
67
|
-
oauth2Client: service.oauth2
|
|
68
|
-
setupManager: service.oauth2
|
|
69
|
-
server
|
|
58
|
+
oauth2Client: service.oauth2?.getClient(),
|
|
59
|
+
setupManager: service.oauth2?.getSetupManager(),
|
|
60
|
+
server,
|
|
70
61
|
};
|
|
71
62
|
}
|
|
72
63
|
catch (error) {
|
|
73
64
|
if (error instanceof Error && error.message.includes('EADDRINUSE')) {
|
|
74
65
|
const devMessage = process.env.DAIN_DEV
|
|
75
|
-
?
|
|
66
|
+
? "\n\nIn development mode, you can start the service with a different port using:\n\n npm run dev --port " + (port + 1) + "\n"
|
|
76
67
|
: '';
|
|
77
|
-
throw new Error(
|
|
68
|
+
throw new Error("EADDRINUSE\n\nPort " + port + " is already in use." + devMessage);
|
|
78
69
|
}
|
|
79
|
-
throw error;
|
|
70
|
+
throw error;
|
|
80
71
|
}
|
|
81
72
|
};
|
|
82
|
-
return {
|
|
83
|
-
...baseService,
|
|
84
|
-
startNode,
|
|
85
|
-
};
|
|
73
|
+
return { ...baseService, startNode };
|
|
86
74
|
}
|
|
87
75
|
// Re-export all types
|
|
88
76
|
tslib_1.__exportStar(require("./types"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeService.js","sourceRoot":"","sources":["../../src/service/nodeService.ts"],"names":[],"mappings":";;;AA6CA,
|
|
1
|
+
{"version":3,"file":"nodeService.js","sourceRoot":"","sources":["../../src/service/nodeService.ts"],"names":[],"mappings":";;;AA6CA,8CA0CC;;AAtFD,uCAAkD;AAElD,2CAAoF;AA6FlF,+FA7FO,0BAAc,OA6FP;AACd,kGA9FuB,6BAAiB,OA8FvB;AACjB,mGA/F0C,8BAAkB,OA+F1C;AA9FpB,yCAQoB;AAwFlB,uGA/FA,iCAAsB,OA+FA;AACtB,6GA/FA,uCAA4B,OA+FA;AAC5B,oGA/FA,8BAAmB,OA+FA;AACnB,mGA/FA,6BAAkB,OA+FA;AA1FpB,iCAA2D;AAoGzD,4FApGO,kBAAW,OAoGP;AACX,qGArGoB,2BAAoB,OAqGpB;AApGtB,2DAI6B;AAkG3B,+GArGA,kDAA8B,OAqGA;AAjGhC,qCAKkB;AAoFhB,8FAxFA,sBAAa,OAwFA;AACb,oGAxFA,4BAAmB,OAwFA;AACnB,mGAxFA,2BAAkB,OAwFA;AArFpB,yDAU4B;AAqF1B,yGA9FA,2CAAwB,OA8FA;AACxB,6FA9FA,+BAA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EAAE,IAAI,EAAE,CAAC;gBACzB,QAAQ,EAAE,KAAK,IAAI,EAAE;oBACnB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;oBAC7C,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,CAAC;gBACD,GAAG,EAAE,OAAO;gBACZ,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE;gBACzC,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,eAAe,EAAE;gBAC/C,MAAM;aACP,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACnE,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ;oBACrC,CAAC,CAAC,0GAA0G,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI;oBAChI,CAAC,CAAC,EAAE,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,IAAI,GAAG,qBAAqB,GAAG,UAAU,CAAC,CAAC;YACrF,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,GAAG,WAAW,EAAE,SAAS,EAAiB,CAAC;AACtD,CAAC;AA4CD,sBAAsB;AACtB,kDAAwB"}
|
|
@@ -36,7 +36,7 @@ export interface HumanActionStep {
|
|
|
36
36
|
id: string;
|
|
37
37
|
processId: string;
|
|
38
38
|
message: string;
|
|
39
|
-
ui?:
|
|
39
|
+
ui?: unknown;
|
|
40
40
|
actions: {
|
|
41
41
|
id: string;
|
|
42
42
|
title: string;
|
|
@@ -49,11 +49,11 @@ export interface HumanActionStep {
|
|
|
49
49
|
actionId: string;
|
|
50
50
|
responseText?: string;
|
|
51
51
|
timestamp: Date;
|
|
52
|
-
data?:
|
|
52
|
+
data?: unknown;
|
|
53
53
|
};
|
|
54
54
|
createdAt: Date;
|
|
55
55
|
timeoutAt?: Date;
|
|
56
|
-
_metadata?: Record<string,
|
|
56
|
+
_metadata?: Record<string, unknown>;
|
|
57
57
|
}
|
|
58
58
|
export type HumanActionRequestedPayload = WebhookPayloadBase & {
|
|
59
59
|
type: "human_action_requested";
|
|
@@ -66,8 +66,8 @@ export type HumanActionCompletedPayload = WebhookPayloadBase & {
|
|
|
66
66
|
export type WebhookPayload = ProcessCreatedPayload | ProcessUpdatePayload | ProcessResultPayload | ProcessFailedPayload | HumanActionRequestedPayload | HumanActionCompletedPayload;
|
|
67
67
|
export interface ProcessResult {
|
|
68
68
|
text: string;
|
|
69
|
-
data:
|
|
70
|
-
ui?:
|
|
69
|
+
data: unknown;
|
|
70
|
+
ui?: unknown;
|
|
71
71
|
}
|
|
72
72
|
export interface Process {
|
|
73
73
|
id: string;
|
|
@@ -82,41 +82,46 @@ export interface Process {
|
|
|
82
82
|
agentInfo: AgentInfo;
|
|
83
83
|
humanActions: HumanActionStep[];
|
|
84
84
|
}
|
|
85
|
-
export
|
|
86
|
-
private processes;
|
|
85
|
+
export interface ProcessStoreAdapter {
|
|
87
86
|
saveProcess(process: Process): Promise<void>;
|
|
88
87
|
getProcess(processId: string): Promise<Process | null>;
|
|
89
88
|
updateProcess(processId: string, updates: Partial<Process>): Promise<void>;
|
|
90
89
|
getHumanAction(processId: string, stepId: string): Promise<HumanActionStep | null>;
|
|
91
90
|
updateHumanAction(processId: string, stepId: string, updates: Partial<HumanActionStep>): Promise<void>;
|
|
92
91
|
}
|
|
93
|
-
|
|
94
|
-
saveProcess(process: Process): Promise<void>;
|
|
95
|
-
getProcess(processId: string): Promise<Process | null>;
|
|
92
|
+
declare abstract class BaseProcessStore implements ProcessStoreAdapter {
|
|
93
|
+
abstract saveProcess(process: Process): Promise<void>;
|
|
94
|
+
abstract getProcess(processId: string): Promise<Process | null>;
|
|
96
95
|
updateProcess(processId: string, updates: Partial<Process>): Promise<void>;
|
|
97
96
|
getHumanAction(processId: string, stepId: string): Promise<HumanActionStep | null>;
|
|
98
97
|
updateHumanAction(processId: string, stepId: string, updates: Partial<HumanActionStep>): Promise<void>;
|
|
99
98
|
}
|
|
100
|
-
export declare class
|
|
99
|
+
export declare class MemoryProcessStore extends BaseProcessStore {
|
|
100
|
+
private processes;
|
|
101
|
+
saveProcess(process: Process): Promise<void>;
|
|
102
|
+
getProcess(processId: string): Promise<Process | null>;
|
|
103
|
+
}
|
|
104
|
+
export declare class RedisProcessStore extends BaseProcessStore {
|
|
101
105
|
private redis;
|
|
102
106
|
private prefix;
|
|
103
107
|
constructor(redisUrl?: string);
|
|
104
108
|
saveProcess(process: Process): Promise<void>;
|
|
105
109
|
getProcess(processId: string): Promise<Process | null>;
|
|
106
|
-
updateProcess(processId: string, updates: Partial<Process>): Promise<void>;
|
|
107
|
-
getHumanAction(processId: string, stepId: string): Promise<HumanActionStep | null>;
|
|
108
|
-
updateHumanAction(processId: string, stepId: string, updates: Partial<HumanActionStep>): Promise<void>;
|
|
109
110
|
}
|
|
110
|
-
export declare class UpstashProcessStore
|
|
111
|
+
export declare class UpstashProcessStore extends BaseProcessStore {
|
|
111
112
|
private baseUrl;
|
|
112
113
|
private token;
|
|
113
114
|
constructor();
|
|
114
115
|
private fetchRedis;
|
|
115
116
|
saveProcess(process: Process): Promise<void>;
|
|
116
117
|
getProcess(processId: string): Promise<Process | null>;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
}
|
|
119
|
+
export interface HumanActionResponseData {
|
|
120
|
+
process: Process;
|
|
121
|
+
stepId: string;
|
|
122
|
+
actionId: string;
|
|
123
|
+
responseText?: string;
|
|
124
|
+
data?: unknown;
|
|
120
125
|
}
|
|
121
126
|
export declare class ProcessHandler {
|
|
122
127
|
private store;
|
|
@@ -124,29 +129,21 @@ export declare class ProcessHandler {
|
|
|
124
129
|
private privateKey;
|
|
125
130
|
private baseUrl?;
|
|
126
131
|
private onHumanActionResponse?;
|
|
127
|
-
constructor(
|
|
132
|
+
constructor(options: {
|
|
128
133
|
serviceId?: string;
|
|
129
134
|
baseUrl?: string;
|
|
130
|
-
onHumanActionResponse?: (response:
|
|
131
|
-
|
|
132
|
-
stepId: string;
|
|
133
|
-
actionId: string;
|
|
134
|
-
responseText?: string;
|
|
135
|
-
data?: any;
|
|
136
|
-
}) => Promise<void>;
|
|
135
|
+
onHumanActionResponse?: (response: HumanActionResponseData) => Promise<void>;
|
|
136
|
+
store?: ProcessStoreAdapter;
|
|
137
137
|
} & ({
|
|
138
138
|
privateKey: Uint8Array;
|
|
139
139
|
apiKey?: never;
|
|
140
|
-
serviceId?: string;
|
|
141
140
|
} | {
|
|
142
141
|
apiKey: string;
|
|
143
142
|
privateKey?: never;
|
|
144
|
-
|
|
145
|
-
}) & {
|
|
146
|
-
store?: ProcessStoreAdapter;
|
|
147
|
-
});
|
|
143
|
+
}));
|
|
148
144
|
private generateProcessId;
|
|
149
145
|
private signWebhookPayload;
|
|
146
|
+
private sendWebhook;
|
|
150
147
|
createProcess(agentInfo: AgentInfo, type: "one-time" | "recurring", name?: string, description?: string): Promise<string>;
|
|
151
148
|
addUpdate(processId: string, update: Omit<ProcessUpdate, "createdAt">): Promise<void>;
|
|
152
149
|
addResult(processId: string, result: ProcessResult): Promise<void>;
|
|
@@ -161,13 +158,13 @@ export declare class ProcessHandler {
|
|
|
161
158
|
} | null>;
|
|
162
159
|
requestHumanAction(processId: string, options: {
|
|
163
160
|
message: string;
|
|
164
|
-
ui?:
|
|
161
|
+
ui?: unknown;
|
|
165
162
|
actions: Array<{
|
|
166
163
|
id: string;
|
|
167
164
|
title: string;
|
|
168
165
|
requiresResponse?: boolean;
|
|
169
166
|
}>;
|
|
170
|
-
metadata?:
|
|
167
|
+
metadata?: unknown;
|
|
171
168
|
timeoutMs?: number;
|
|
172
169
|
}): Promise<string>;
|
|
173
170
|
checkHumanAction(processId: string, stepId: string): Promise<{
|
|
@@ -175,13 +172,14 @@ export declare class ProcessHandler {
|
|
|
175
172
|
response?: {
|
|
176
173
|
actionId: string;
|
|
177
174
|
responseText?: string;
|
|
178
|
-
data?:
|
|
175
|
+
data?: unknown;
|
|
179
176
|
};
|
|
180
177
|
}>;
|
|
181
178
|
waitForHumanAction(processId: string, stepId: string, timeoutMs?: number): Promise<{
|
|
182
179
|
actionId: string;
|
|
183
180
|
responseText?: string;
|
|
184
|
-
data?:
|
|
181
|
+
data?: unknown;
|
|
185
182
|
}>;
|
|
186
|
-
respondToHumanAction(processId: string, stepId: string, actionId: string, responseText?: string, data?:
|
|
183
|
+
respondToHumanAction(processId: string, stepId: string, actionId: string, responseText?: string, data?: unknown): Promise<void>;
|
|
187
184
|
}
|
|
185
|
+
export {};
|