@elevasis/sdk 0.4.1 → 0.4.3
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/cli.cjs +4132 -298
- package/dist/index.d.ts +5 -2
- package/dist/index.js +12 -2
- package/dist/types/worker/index.d.ts +19 -0
- package/dist/types/worker/platform.d.ts +50 -0
- package/dist/worker/index.js +97 -7
- package/package.json +14 -9
package/dist/index.d.ts
CHANGED
|
@@ -1584,6 +1584,8 @@ interface ResourceDefinition {
|
|
|
1584
1584
|
domains?: ResourceDomain[];
|
|
1585
1585
|
/** Whether the agent supports multi-turn sessions (agents only) */
|
|
1586
1586
|
sessionCapable?: boolean;
|
|
1587
|
+
/** Whether the resource is local (monorepo) or remote (externally deployed) */
|
|
1588
|
+
origin?: 'local' | 'remote';
|
|
1587
1589
|
}
|
|
1588
1590
|
/**
|
|
1589
1591
|
* Domain definition for Command View filtering
|
|
@@ -1877,6 +1879,7 @@ interface HumanCheckpointDefinition extends ResourceDefinition {
|
|
|
1877
1879
|
|
|
1878
1880
|
declare const DOMAINS: {
|
|
1879
1881
|
readonly ACQUISITION: "acquisition";
|
|
1882
|
+
readonly LEADS: "leads";
|
|
1880
1883
|
readonly SUPPORT: "support";
|
|
1881
1884
|
readonly DELIVERY: "delivery";
|
|
1882
1885
|
readonly OPERATIONS: "operations";
|
|
@@ -1923,9 +1926,9 @@ interface ElevasConfig {
|
|
|
1923
1926
|
/**
|
|
1924
1927
|
* Runtime values for SDK developers.
|
|
1925
1928
|
*
|
|
1926
|
-
* These are standalone definitions (not re-exported from
|
|
1929
|
+
* These are standalone definitions (not re-exported from the core package)
|
|
1927
1930
|
* to avoid pulling in the entire execution engine dependency tree (~3.5MB).
|
|
1928
|
-
* Values are identical to their
|
|
1931
|
+
* Values are identical to their core package counterparts.
|
|
1929
1932
|
*/
|
|
1930
1933
|
/** Step connection type for multi-step workflows */
|
|
1931
1934
|
declare enum StepType {
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ var ToolingError = class extends ExecutionError {
|
|
|
43
43
|
var DOMAINS = {
|
|
44
44
|
// Business domains
|
|
45
45
|
ACQUISITION: "acquisition",
|
|
46
|
+
LEADS: "leads",
|
|
46
47
|
SUPPORT: "support",
|
|
47
48
|
DELIVERY: "delivery",
|
|
48
49
|
OPERATIONS: "operations",
|
|
@@ -61,6 +62,12 @@ var ACQUISITION_DOMAIN = {
|
|
|
61
62
|
description: "Client acquisition pipeline and lead database management",
|
|
62
63
|
color: "blue"
|
|
63
64
|
};
|
|
65
|
+
var LEADS_DOMAIN = {
|
|
66
|
+
id: DOMAINS.LEADS,
|
|
67
|
+
name: "Lead Database",
|
|
68
|
+
description: "Lead import, enrichment, qualification, and personalization",
|
|
69
|
+
color: "cyan"
|
|
70
|
+
};
|
|
64
71
|
var SUPPORT_DOMAIN = {
|
|
65
72
|
id: DOMAINS.SUPPORT,
|
|
66
73
|
name: "Customer Support",
|
|
@@ -123,6 +130,7 @@ var DIAGNOSTIC_DOMAIN = {
|
|
|
123
130
|
};
|
|
124
131
|
var DOMAIN_MAP = {
|
|
125
132
|
[DOMAINS.ACQUISITION]: ACQUISITION_DOMAIN,
|
|
133
|
+
[DOMAINS.LEADS]: LEADS_DOMAIN,
|
|
126
134
|
[DOMAINS.SUPPORT]: SUPPORT_DOMAIN,
|
|
127
135
|
[DOMAINS.DELIVERY]: DELIVERY_DOMAIN,
|
|
128
136
|
[DOMAINS.OPERATIONS]: OPERATIONS_DOMAIN,
|
|
@@ -3234,7 +3242,8 @@ var ResourceRegistry = class {
|
|
|
3234
3242
|
description: def.config.description,
|
|
3235
3243
|
version: def.config.version,
|
|
3236
3244
|
type: def.config.type,
|
|
3237
|
-
status: def.config.status
|
|
3245
|
+
status: def.config.status,
|
|
3246
|
+
origin: this.remoteResources.has(`${organizationName}/${def.config.resourceId}`) ? "remote" : "local"
|
|
3238
3247
|
})).filter((resource) => {
|
|
3239
3248
|
if (environment) {
|
|
3240
3249
|
return resource.status === environment;
|
|
@@ -3248,7 +3257,8 @@ var ResourceRegistry = class {
|
|
|
3248
3257
|
version: def.config.version,
|
|
3249
3258
|
type: def.config.type,
|
|
3250
3259
|
status: def.config.status,
|
|
3251
|
-
sessionCapable: def.config.sessionCapable ?? false
|
|
3260
|
+
sessionCapable: def.config.sessionCapable ?? false,
|
|
3261
|
+
origin: this.remoteResources.has(`${organizationName}/${def.config.resourceId}`) ? "remote" : "local"
|
|
3252
3262
|
})).filter((resource) => {
|
|
3253
3263
|
if (environment) {
|
|
3254
3264
|
return resource.status === environment;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Worker Runtime
|
|
3
|
+
*
|
|
4
|
+
* Runs inside a worker_threads Worker, replacing the HTTP-based server runtime.
|
|
5
|
+
* Communicates with the parent (API process) via postMessage().
|
|
6
|
+
*
|
|
7
|
+
* Message protocol:
|
|
8
|
+
* Parent -> Worker: { type: 'manifest' }
|
|
9
|
+
* Worker -> Parent: { type: 'manifest', workflows: [...], agents: [...] }
|
|
10
|
+
*
|
|
11
|
+
* Parent -> Worker: { type: 'execute', resourceId, executionId, input, organizationId?, organizationName? }
|
|
12
|
+
* Worker -> Parent: { type: 'result', status, output?, error?, logs }
|
|
13
|
+
*
|
|
14
|
+
* Worker -> Parent: { type: 'tool-call', id, tool, method, params, credential? }
|
|
15
|
+
* Parent -> Worker: { type: 'tool-result', id, result?, error?, code? }
|
|
16
|
+
*/
|
|
17
|
+
import type { OrganizationResources } from '../index.js';
|
|
18
|
+
export { platform, PlatformToolError } from './platform.js';
|
|
19
|
+
export declare function startWorker(org: OrganizationResources): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform Tool Proxy (Worker Side)
|
|
3
|
+
*
|
|
4
|
+
* Provides platform.call() for external developers to invoke platform tools
|
|
5
|
+
* from within worker threads. Communicates with the parent process via
|
|
6
|
+
* postMessage() -- the parent dispatches to the real service layer.
|
|
7
|
+
*/
|
|
8
|
+
/** Inbound tool-result from parent */
|
|
9
|
+
interface ToolResultMessage {
|
|
10
|
+
type: 'tool-result';
|
|
11
|
+
id: string;
|
|
12
|
+
result?: unknown;
|
|
13
|
+
error?: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class PlatformToolError extends Error {
|
|
17
|
+
/** ToolingErrorType code from the platform */
|
|
18
|
+
readonly code: string;
|
|
19
|
+
/** Whether the error is retryable */
|
|
20
|
+
readonly retryable: boolean;
|
|
21
|
+
constructor(message: string,
|
|
22
|
+
/** ToolingErrorType code from the platform */
|
|
23
|
+
code: string,
|
|
24
|
+
/** Whether the error is retryable */
|
|
25
|
+
retryable: boolean);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Handle a tool-result message from the parent process.
|
|
29
|
+
* Called from the parentPort.on('message') handler in index.ts.
|
|
30
|
+
*/
|
|
31
|
+
export declare function handleToolResult(msg: ToolResultMessage): void;
|
|
32
|
+
export declare const platform: {
|
|
33
|
+
/**
|
|
34
|
+
* Call a platform tool from the worker thread.
|
|
35
|
+
*
|
|
36
|
+
* @param options.tool - Tool name (e.g., 'gmail', 'storage', 'attio')
|
|
37
|
+
* @param options.method - Method name (e.g., 'sendEmail', 'upload')
|
|
38
|
+
* @param options.params - Method parameters
|
|
39
|
+
* @param options.credential - Credential name (required for integration tools)
|
|
40
|
+
* @returns Promise resolving to the tool result
|
|
41
|
+
* @throws PlatformToolError on failure (with code and retryable fields)
|
|
42
|
+
*/
|
|
43
|
+
call(options: {
|
|
44
|
+
tool: string;
|
|
45
|
+
method: string;
|
|
46
|
+
params?: unknown;
|
|
47
|
+
credential?: string;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
package/dist/worker/index.js
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
1
|
import { parentPort } from 'worker_threads';
|
|
2
2
|
|
|
3
|
+
// src/worker/index.ts
|
|
4
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
5
|
+
"rate_limit_exceeded",
|
|
6
|
+
"network_error",
|
|
7
|
+
"timeout_error",
|
|
8
|
+
"api_error",
|
|
9
|
+
"service_unavailable",
|
|
10
|
+
"server_unavailable"
|
|
11
|
+
]);
|
|
12
|
+
var PlatformToolError = class extends Error {
|
|
13
|
+
constructor(message, code, retryable) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.retryable = retryable;
|
|
17
|
+
this.name = "PlatformToolError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var pendingCalls = /* @__PURE__ */ new Map();
|
|
21
|
+
var callCounter = 0;
|
|
22
|
+
function handleToolResult(msg) {
|
|
23
|
+
const pending = pendingCalls.get(msg.id);
|
|
24
|
+
if (!pending) return;
|
|
25
|
+
pendingCalls.delete(msg.id);
|
|
26
|
+
if (msg.error) {
|
|
27
|
+
const code = msg.code ?? "unknown_error";
|
|
28
|
+
pending.reject(new PlatformToolError(msg.error, code, RETRYABLE_CODES.has(code)));
|
|
29
|
+
} else {
|
|
30
|
+
pending.resolve(msg.result);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
var platform = {
|
|
34
|
+
/**
|
|
35
|
+
* Call a platform tool from the worker thread.
|
|
36
|
+
*
|
|
37
|
+
* @param options.tool - Tool name (e.g., 'gmail', 'storage', 'attio')
|
|
38
|
+
* @param options.method - Method name (e.g., 'sendEmail', 'upload')
|
|
39
|
+
* @param options.params - Method parameters
|
|
40
|
+
* @param options.credential - Credential name (required for integration tools)
|
|
41
|
+
* @returns Promise resolving to the tool result
|
|
42
|
+
* @throws PlatformToolError on failure (with code and retryable fields)
|
|
43
|
+
*/
|
|
44
|
+
async call(options) {
|
|
45
|
+
if (!parentPort) {
|
|
46
|
+
throw new PlatformToolError(
|
|
47
|
+
"platform.call() can only be used inside a worker thread",
|
|
48
|
+
"service_unavailable",
|
|
49
|
+
false
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const id = `tc_${++callCounter}_${Date.now()}`;
|
|
53
|
+
const message = {
|
|
54
|
+
type: "tool-call",
|
|
55
|
+
id,
|
|
56
|
+
tool: options.tool,
|
|
57
|
+
method: options.method,
|
|
58
|
+
params: options.params ?? {},
|
|
59
|
+
credential: options.credential
|
|
60
|
+
};
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const timer = setTimeout(() => {
|
|
63
|
+
pendingCalls.delete(id);
|
|
64
|
+
reject(new PlatformToolError(
|
|
65
|
+
`Platform tool call timed out after 60s: ${options.tool}.${options.method}`,
|
|
66
|
+
"timeout_error",
|
|
67
|
+
true
|
|
68
|
+
));
|
|
69
|
+
}, 6e4);
|
|
70
|
+
pendingCalls.set(id, {
|
|
71
|
+
resolve: (value) => {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
resolve(value);
|
|
74
|
+
},
|
|
75
|
+
reject: (error) => {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
reject(error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
parentPort.postMessage(message);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
3
85
|
// src/worker/index.ts
|
|
4
86
|
function resolveNext(next, data) {
|
|
5
87
|
if (next === null) return null;
|
|
@@ -9,7 +91,7 @@ function resolveNext(next, data) {
|
|
|
9
91
|
}
|
|
10
92
|
return next.default;
|
|
11
93
|
}
|
|
12
|
-
async function executeWorkflow(workflow, input) {
|
|
94
|
+
async function executeWorkflow(workflow, input, context) {
|
|
13
95
|
const logs = [];
|
|
14
96
|
const origLog = console.log;
|
|
15
97
|
const origWarn = console.warn;
|
|
@@ -31,9 +113,9 @@ async function executeWorkflow(workflow, input) {
|
|
|
31
113
|
}
|
|
32
114
|
const stepInput = step.inputSchema.parse(currentData);
|
|
33
115
|
const rawOutput = await step.handler(stepInput, {
|
|
34
|
-
executionId:
|
|
35
|
-
organizationId:
|
|
36
|
-
organizationName:
|
|
116
|
+
executionId: context.executionId,
|
|
117
|
+
organizationId: context.organizationId,
|
|
118
|
+
organizationName: context.organizationName,
|
|
37
119
|
resourceId: workflow.config.resourceId,
|
|
38
120
|
executionDepth: 0,
|
|
39
121
|
store: /* @__PURE__ */ new Map(),
|
|
@@ -91,15 +173,23 @@ function startWorker(org) {
|
|
|
91
173
|
});
|
|
92
174
|
return;
|
|
93
175
|
}
|
|
176
|
+
if (msg.type === "tool-result") {
|
|
177
|
+
handleToolResult(msg);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
94
180
|
if (msg.type === "execute") {
|
|
95
|
-
const { resourceId, executionId, input } = msg;
|
|
181
|
+
const { resourceId, executionId, input, organizationId, organizationName } = msg;
|
|
96
182
|
console.log(`[SDK-WORKER] Execute request: resourceId=${resourceId}, executionId=${executionId}`);
|
|
97
183
|
const workflow = workflows.get(resourceId);
|
|
98
184
|
if (workflow) {
|
|
99
185
|
try {
|
|
100
186
|
console.log(`[SDK-WORKER] Running workflow '${resourceId}' (${Object.keys(workflow.steps).length} steps)`);
|
|
101
187
|
const startTime = Date.now();
|
|
102
|
-
const { output, logs } = await executeWorkflow(workflow, input
|
|
188
|
+
const { output, logs } = await executeWorkflow(workflow, input, {
|
|
189
|
+
executionId,
|
|
190
|
+
organizationId: organizationId ?? "",
|
|
191
|
+
organizationName: organizationName ?? ""
|
|
192
|
+
});
|
|
103
193
|
console.log(`[SDK-WORKER] Workflow '${resourceId}' completed (${Date.now() - startTime}ms)`);
|
|
104
194
|
parentPort.postMessage({ type: "result", status: "completed", output, logs });
|
|
105
195
|
} catch (err) {
|
|
@@ -129,4 +219,4 @@ function startWorker(org) {
|
|
|
129
219
|
});
|
|
130
220
|
}
|
|
131
221
|
|
|
132
|
-
export { startWorker };
|
|
222
|
+
export { PlatformToolError, platform, startWorker };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elevasis/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "SDK for building Elevasis organization resources",
|
|
5
5
|
"comment:bin": "IMPORTANT: This package shares the 'elevasis' binary name with @repo/cli. They never conflict because @elevasis/sdk must NEVER be added as a dependency of any workspace package (apps/*, packages/*, organizations/*). Workspace projects use @repo/cli for the 'elevasis' binary. External developers (outside the workspace) get this SDK's binary via npm install.",
|
|
6
6
|
"type": "module",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"import": "./dist/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./worker": {
|
|
17
|
+
"types": "./dist/types/worker/index.d.ts",
|
|
17
18
|
"import": "./dist/worker/index.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
@@ -21,12 +22,10 @@
|
|
|
21
22
|
"dist/index.js",
|
|
22
23
|
"dist/index.d.ts",
|
|
23
24
|
"dist/worker/index.js",
|
|
25
|
+
"dist/types/worker/index.d.ts",
|
|
26
|
+
"dist/types/worker/platform.d.ts",
|
|
24
27
|
"dist/cli.cjs"
|
|
25
28
|
],
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.core-dts.json && tsc -p tsconfig.build.json && tsup && rollup -c rollup.dts.config.mjs && esbuild src/cli/index.ts --bundle --platform=node --outfile=dist/cli.cjs --format=cjs --external:esbuild --external:jiti --banner:js=\"#!/usr/bin/env node\"",
|
|
28
|
-
"check-types": "tsc --noEmit"
|
|
29
|
-
},
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"esbuild": "^0.25.0",
|
|
32
31
|
"jiti": "^2.0.0"
|
|
@@ -35,17 +34,23 @@
|
|
|
35
34
|
"zod": "^4.1.0"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"@repo/core": "workspace:*",
|
|
39
|
-
"@repo/typescript-config": "workspace:*",
|
|
40
37
|
"@types/node": "^22.0.0",
|
|
41
38
|
"chalk": "^5.3.0",
|
|
42
39
|
"commander": "^11.0.0",
|
|
43
40
|
"dotenv": "^16.0.0",
|
|
41
|
+
"gray-matter": "^4.0.3",
|
|
44
42
|
"ora": "^7.0.1",
|
|
45
43
|
"rollup": "^4.59.0",
|
|
46
44
|
"rollup-plugin-dts": "^6.3.0",
|
|
47
45
|
"tsup": "^8.0.0",
|
|
48
46
|
"typescript": "5.9.2",
|
|
49
|
-
"zod": "^4.1.0"
|
|
47
|
+
"zod": "^4.1.0",
|
|
48
|
+
"@repo/core": "0.0.0",
|
|
49
|
+
"@repo/typescript-config": "0.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.core-dts.json && tsc -p tsconfig.build.json && tsup && rollup -c rollup.dts.config.mjs && esbuild src/cli/index.ts --bundle --platform=node --outfile=dist/cli.cjs --format=cjs --external:esbuild --external:jiti --banner:js=\"#!/usr/bin/env node\"",
|
|
53
|
+
"check-types": "tsc --noEmit",
|
|
54
|
+
"test:bundle": "pnpm build && vitest run --config vitest.bundle.config.ts"
|
|
50
55
|
}
|
|
51
|
-
}
|
|
56
|
+
}
|