@elevasis/sdk 0.4.1 → 0.4.2

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/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";
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;
@@ -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.1",
3
+ "version": "0.4.2",
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",
@@ -23,10 +23,6 @@
23
23
  "dist/worker/index.js",
24
24
  "dist/cli.cjs"
25
25
  ],
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
26
  "dependencies": {
31
27
  "esbuild": "^0.25.0",
32
28
  "jiti": "^2.0.0"
@@ -35,17 +31,22 @@
35
31
  "zod": "^4.1.0"
36
32
  },
37
33
  "devDependencies": {
38
- "@repo/core": "workspace:*",
39
- "@repo/typescript-config": "workspace:*",
40
34
  "@types/node": "^22.0.0",
41
35
  "chalk": "^5.3.0",
42
36
  "commander": "^11.0.0",
43
37
  "dotenv": "^16.0.0",
38
+ "gray-matter": "^4.0.3",
44
39
  "ora": "^7.0.1",
45
40
  "rollup": "^4.59.0",
46
41
  "rollup-plugin-dts": "^6.3.0",
47
42
  "tsup": "^8.0.0",
48
43
  "typescript": "5.9.2",
49
- "zod": "^4.1.0"
44
+ "zod": "^4.1.0",
45
+ "@repo/typescript-config": "0.0.0",
46
+ "@repo/core": "0.0.0"
47
+ },
48
+ "scripts": {
49
+ "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\"",
50
+ "check-types": "tsc --noEmit"
50
51
  }
51
- }
52
+ }