@elevasis/sdk 0.4.0 → 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/cli.cjs +4286 -400
- package/dist/index.d.ts +33 -23
- package/dist/index.js +104 -35
- package/dist/worker/index.js +108 -7
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -1104,11 +1104,12 @@ declare class ResourceRegistry {
|
|
|
1104
1104
|
*/
|
|
1105
1105
|
private serializedCache;
|
|
1106
1106
|
/**
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1107
|
+
* Per-resource remote configuration (external deployments)
|
|
1108
|
+
* Key: "orgName/resourceId", Value: RemoteOrgConfig for that resource.
|
|
1109
|
+
* Tracks which individual resources were added at runtime via deploy pipeline.
|
|
1110
|
+
* Static and remote resources coexist in the same org.
|
|
1110
1111
|
*/
|
|
1111
|
-
private
|
|
1112
|
+
private remoteResources;
|
|
1112
1113
|
constructor(registry: OrganizationRegistry);
|
|
1113
1114
|
/**
|
|
1114
1115
|
* Validates registry on construction
|
|
@@ -1145,47 +1146,53 @@ declare class ResourceRegistry {
|
|
|
1145
1146
|
*/
|
|
1146
1147
|
listAllResources(): OrganizationRegistry;
|
|
1147
1148
|
/**
|
|
1148
|
-
* Register
|
|
1149
|
+
* Register external resources at runtime
|
|
1149
1150
|
*
|
|
1150
1151
|
* Called during deploy pipeline when an external developer deploys their bundle.
|
|
1151
|
-
*
|
|
1152
|
-
* for worker thread execution branching.
|
|
1152
|
+
* Merges the incoming stub definitions into the org's registry and stores
|
|
1153
|
+
* per-resource remote config for worker thread execution branching.
|
|
1153
1154
|
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1155
|
+
* Static and remote resources coexist in the same org. If the org already
|
|
1156
|
+
* has static resources, the incoming remote resources are merged alongside them.
|
|
1157
|
+
* If redeploying (some resources already registered as remote for this org),
|
|
1158
|
+
* the previous remote resources are unregistered first.
|
|
1156
1159
|
*
|
|
1157
1160
|
* @param orgName - Organization name (used as registry key)
|
|
1158
1161
|
* @param org - Stub resource definitions (workflows/agents with placeholder handlers)
|
|
1159
1162
|
* @param remote - Remote configuration (bundle path, deployment ID, env vars)
|
|
1160
|
-
* @throws Error if
|
|
1163
|
+
* @throws Error if incoming resourceId conflicts with a static resource
|
|
1164
|
+
* @throws Error if incoming deployment contains duplicate resourceIds
|
|
1161
1165
|
*/
|
|
1162
1166
|
registerOrganization(orgName: string, org: OrganizationResources, remote: RemoteOrgConfig): void;
|
|
1163
1167
|
/**
|
|
1164
|
-
* Unregister
|
|
1168
|
+
* Unregister runtime-registered resources for an organization
|
|
1165
1169
|
*
|
|
1166
|
-
*
|
|
1167
|
-
* Static
|
|
1168
|
-
*
|
|
1170
|
+
* Removes only resources that were registered at runtime (via registerOrganization).
|
|
1171
|
+
* Static resources loaded at startup are preserved. If the org still has static
|
|
1172
|
+
* resources after removal, the serialization cache is rebuilt. If no resources
|
|
1173
|
+
* remain, the org is fully removed from the registry.
|
|
1174
|
+
* No-op if the org has no remote resources.
|
|
1169
1175
|
*
|
|
1170
|
-
* @param orgName - Organization name to unregister
|
|
1176
|
+
* @param orgName - Organization name to unregister remote resources from
|
|
1171
1177
|
*/
|
|
1172
1178
|
unregisterOrganization(orgName: string): void;
|
|
1173
1179
|
/**
|
|
1174
|
-
* Get remote configuration for
|
|
1180
|
+
* Get remote configuration for a specific resource
|
|
1175
1181
|
*
|
|
1176
|
-
* Returns the RemoteOrgConfig if the
|
|
1177
|
-
* or null if it's a static
|
|
1182
|
+
* Returns the RemoteOrgConfig if the resource was registered at runtime,
|
|
1183
|
+
* or null if it's a static resource or doesn't exist.
|
|
1178
1184
|
* Used by the execution coordinator to branch between local and worker execution.
|
|
1179
1185
|
*
|
|
1180
1186
|
* @param orgName - Organization name
|
|
1187
|
+
* @param resourceId - Resource ID
|
|
1181
1188
|
* @returns Remote config or null
|
|
1182
1189
|
*/
|
|
1183
|
-
getRemoteConfig(orgName: string): RemoteOrgConfig | null;
|
|
1190
|
+
getRemoteConfig(orgName: string, resourceId: string): RemoteOrgConfig | null;
|
|
1184
1191
|
/**
|
|
1185
|
-
* Check if an organization
|
|
1192
|
+
* Check if an organization has any remote (externally deployed) resources
|
|
1186
1193
|
*
|
|
1187
1194
|
* @param orgName - Organization name
|
|
1188
|
-
* @returns true if the org
|
|
1195
|
+
* @returns true if the org has at least one runtime-registered resource
|
|
1189
1196
|
*/
|
|
1190
1197
|
isRemote(orgName: string): boolean;
|
|
1191
1198
|
/**
|
|
@@ -1577,6 +1584,8 @@ interface ResourceDefinition {
|
|
|
1577
1584
|
domains?: ResourceDomain[];
|
|
1578
1585
|
/** Whether the agent supports multi-turn sessions (agents only) */
|
|
1579
1586
|
sessionCapable?: boolean;
|
|
1587
|
+
/** Whether the resource is local (monorepo) or remote (externally deployed) */
|
|
1588
|
+
origin?: 'local' | 'remote';
|
|
1580
1589
|
}
|
|
1581
1590
|
/**
|
|
1582
1591
|
* Domain definition for Command View filtering
|
|
@@ -1870,6 +1879,7 @@ interface HumanCheckpointDefinition extends ResourceDefinition {
|
|
|
1870
1879
|
|
|
1871
1880
|
declare const DOMAINS: {
|
|
1872
1881
|
readonly ACQUISITION: "acquisition";
|
|
1882
|
+
readonly LEADS: "leads";
|
|
1873
1883
|
readonly SUPPORT: "support";
|
|
1874
1884
|
readonly DELIVERY: "delivery";
|
|
1875
1885
|
readonly OPERATIONS: "operations";
|
|
@@ -1903,10 +1913,10 @@ declare class RegistryValidationError extends Error {
|
|
|
1903
1913
|
|
|
1904
1914
|
/**
|
|
1905
1915
|
* Project configuration for an external developer project.
|
|
1906
|
-
* Defined in
|
|
1916
|
+
* Defined in elevasis.config.ts at the project root.
|
|
1917
|
+
* Organization is derived from the ELEVASIS_API_KEY -- not configured here.
|
|
1907
1918
|
*/
|
|
1908
1919
|
interface ElevasConfig {
|
|
1909
|
-
organization: string;
|
|
1910
1920
|
defaultStatus?: ResourceStatus;
|
|
1911
1921
|
dev?: {
|
|
1912
1922
|
port?: number;
|
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,
|
|
@@ -3166,11 +3174,12 @@ var ResourceRegistry = class {
|
|
|
3166
3174
|
*/
|
|
3167
3175
|
serializedCache;
|
|
3168
3176
|
/**
|
|
3169
|
-
*
|
|
3170
|
-
*
|
|
3171
|
-
*
|
|
3177
|
+
* Per-resource remote configuration (external deployments)
|
|
3178
|
+
* Key: "orgName/resourceId", Value: RemoteOrgConfig for that resource.
|
|
3179
|
+
* Tracks which individual resources were added at runtime via deploy pipeline.
|
|
3180
|
+
* Static and remote resources coexist in the same org.
|
|
3172
3181
|
*/
|
|
3173
|
-
|
|
3182
|
+
remoteResources = /* @__PURE__ */ new Map();
|
|
3174
3183
|
/**
|
|
3175
3184
|
* Validates registry on construction
|
|
3176
3185
|
* - Checks for duplicate resourceIds within organizations
|
|
@@ -3233,7 +3242,8 @@ var ResourceRegistry = class {
|
|
|
3233
3242
|
description: def.config.description,
|
|
3234
3243
|
version: def.config.version,
|
|
3235
3244
|
type: def.config.type,
|
|
3236
|
-
status: def.config.status
|
|
3245
|
+
status: def.config.status,
|
|
3246
|
+
origin: this.remoteResources.has(`${organizationName}/${def.config.resourceId}`) ? "remote" : "local"
|
|
3237
3247
|
})).filter((resource) => {
|
|
3238
3248
|
if (environment) {
|
|
3239
3249
|
return resource.status === environment;
|
|
@@ -3247,7 +3257,8 @@ var ResourceRegistry = class {
|
|
|
3247
3257
|
version: def.config.version,
|
|
3248
3258
|
type: def.config.type,
|
|
3249
3259
|
status: def.config.status,
|
|
3250
|
-
sessionCapable: def.config.sessionCapable ?? false
|
|
3260
|
+
sessionCapable: def.config.sessionCapable ?? false,
|
|
3261
|
+
origin: this.remoteResources.has(`${organizationName}/${def.config.resourceId}`) ? "remote" : "local"
|
|
3251
3262
|
})).filter((resource) => {
|
|
3252
3263
|
if (environment) {
|
|
3253
3264
|
return resource.status === environment;
|
|
@@ -3273,67 +3284,125 @@ var ResourceRegistry = class {
|
|
|
3273
3284
|
// Runtime Organization Registration (External Deployments)
|
|
3274
3285
|
// ============================================================================
|
|
3275
3286
|
/**
|
|
3276
|
-
* Register
|
|
3287
|
+
* Register external resources at runtime
|
|
3277
3288
|
*
|
|
3278
3289
|
* Called during deploy pipeline when an external developer deploys their bundle.
|
|
3279
|
-
*
|
|
3280
|
-
* for worker thread execution branching.
|
|
3290
|
+
* Merges the incoming stub definitions into the org's registry and stores
|
|
3291
|
+
* per-resource remote config for worker thread execution branching.
|
|
3281
3292
|
*
|
|
3282
|
-
*
|
|
3283
|
-
*
|
|
3293
|
+
* Static and remote resources coexist in the same org. If the org already
|
|
3294
|
+
* has static resources, the incoming remote resources are merged alongside them.
|
|
3295
|
+
* If redeploying (some resources already registered as remote for this org),
|
|
3296
|
+
* the previous remote resources are unregistered first.
|
|
3284
3297
|
*
|
|
3285
3298
|
* @param orgName - Organization name (used as registry key)
|
|
3286
3299
|
* @param org - Stub resource definitions (workflows/agents with placeholder handlers)
|
|
3287
3300
|
* @param remote - Remote configuration (bundle path, deployment ID, env vars)
|
|
3288
|
-
* @throws Error if
|
|
3301
|
+
* @throws Error if incoming resourceId conflicts with a static resource
|
|
3302
|
+
* @throws Error if incoming deployment contains duplicate resourceIds
|
|
3289
3303
|
*/
|
|
3290
3304
|
registerOrganization(orgName, org, remote) {
|
|
3291
|
-
|
|
3292
|
-
|
|
3305
|
+
const incomingWorkflowIds = (org.workflows ?? []).map((w) => w.config.resourceId);
|
|
3306
|
+
const incomingAgentIds = (org.agents ?? []).map((a) => a.config.resourceId);
|
|
3307
|
+
const incomingIds = [...incomingWorkflowIds, ...incomingAgentIds];
|
|
3308
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3309
|
+
for (const id of incomingIds) {
|
|
3310
|
+
if (seen.has(id)) {
|
|
3311
|
+
throw new Error(
|
|
3312
|
+
`Duplicate resource ID '${id}' in deployment. Each resource must have a unique ID.`
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3315
|
+
seen.add(id);
|
|
3293
3316
|
}
|
|
3294
|
-
if (this.
|
|
3317
|
+
if (this.isRemote(orgName)) {
|
|
3295
3318
|
this.unregisterOrganization(orgName);
|
|
3296
3319
|
}
|
|
3297
|
-
this.registry[orgName]
|
|
3298
|
-
|
|
3299
|
-
|
|
3320
|
+
const existingOrg = this.registry[orgName];
|
|
3321
|
+
if (existingOrg) {
|
|
3322
|
+
const staticWorkflowIds = new Set((existingOrg.workflows ?? []).map((w) => w.config.resourceId));
|
|
3323
|
+
const staticAgentIds = new Set((existingOrg.agents ?? []).map((a) => a.config.resourceId));
|
|
3324
|
+
for (const id of incomingIds) {
|
|
3325
|
+
if (staticWorkflowIds.has(id) || staticAgentIds.has(id)) {
|
|
3326
|
+
throw new Error(
|
|
3327
|
+
`Resource '${id}' already exists in '${orgName}' as an internal resource. External deployments cannot override internal resources.`
|
|
3328
|
+
);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
if (existingOrg) {
|
|
3333
|
+
existingOrg.workflows = [...existingOrg.workflows ?? [], ...org.workflows ?? []];
|
|
3334
|
+
existingOrg.agents = [...existingOrg.agents ?? [], ...org.agents ?? []];
|
|
3335
|
+
} else {
|
|
3336
|
+
this.registry[orgName] = org;
|
|
3337
|
+
}
|
|
3338
|
+
for (const id of incomingIds) {
|
|
3339
|
+
this.remoteResources.set(`${orgName}/${id}`, remote);
|
|
3340
|
+
}
|
|
3341
|
+
this.serializedCache.set(orgName, serializeOrganization(this.registry[orgName]));
|
|
3300
3342
|
}
|
|
3301
3343
|
/**
|
|
3302
|
-
* Unregister
|
|
3344
|
+
* Unregister runtime-registered resources for an organization
|
|
3303
3345
|
*
|
|
3304
|
-
*
|
|
3305
|
-
* Static
|
|
3306
|
-
*
|
|
3346
|
+
* Removes only resources that were registered at runtime (via registerOrganization).
|
|
3347
|
+
* Static resources loaded at startup are preserved. If the org still has static
|
|
3348
|
+
* resources after removal, the serialization cache is rebuilt. If no resources
|
|
3349
|
+
* remain, the org is fully removed from the registry.
|
|
3350
|
+
* No-op if the org has no remote resources.
|
|
3307
3351
|
*
|
|
3308
|
-
* @param orgName - Organization name to unregister
|
|
3352
|
+
* @param orgName - Organization name to unregister remote resources from
|
|
3309
3353
|
*/
|
|
3310
3354
|
unregisterOrganization(orgName) {
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
this.
|
|
3314
|
-
|
|
3355
|
+
const prefix = `${orgName}/`;
|
|
3356
|
+
const remoteIds = /* @__PURE__ */ new Set();
|
|
3357
|
+
for (const key of this.remoteResources.keys()) {
|
|
3358
|
+
if (key.startsWith(prefix)) {
|
|
3359
|
+
remoteIds.add(key.slice(prefix.length));
|
|
3360
|
+
this.remoteResources.delete(key);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
if (remoteIds.size === 0) return;
|
|
3364
|
+
const orgResources = this.registry[orgName];
|
|
3365
|
+
if (!orgResources) return;
|
|
3366
|
+
orgResources.workflows = (orgResources.workflows ?? []).filter(
|
|
3367
|
+
(w) => !remoteIds.has(w.config.resourceId)
|
|
3368
|
+
);
|
|
3369
|
+
orgResources.agents = (orgResources.agents ?? []).filter(
|
|
3370
|
+
(a) => !remoteIds.has(a.config.resourceId)
|
|
3371
|
+
);
|
|
3372
|
+
const remaining = (orgResources.workflows?.length ?? 0) + (orgResources.agents?.length ?? 0) + (orgResources.triggers?.length ?? 0) + (orgResources.integrations?.length ?? 0) + (orgResources.externalResources?.length ?? 0) + (orgResources.humanCheckpoints?.length ?? 0);
|
|
3373
|
+
if (remaining > 0) {
|
|
3374
|
+
this.serializedCache.set(orgName, serializeOrganization(orgResources));
|
|
3375
|
+
} else {
|
|
3376
|
+
delete this.registry[orgName];
|
|
3377
|
+
this.serializedCache.delete(orgName);
|
|
3378
|
+
}
|
|
3315
3379
|
}
|
|
3316
3380
|
/**
|
|
3317
|
-
* Get remote configuration for
|
|
3381
|
+
* Get remote configuration for a specific resource
|
|
3318
3382
|
*
|
|
3319
|
-
* Returns the RemoteOrgConfig if the
|
|
3320
|
-
* or null if it's a static
|
|
3383
|
+
* Returns the RemoteOrgConfig if the resource was registered at runtime,
|
|
3384
|
+
* or null if it's a static resource or doesn't exist.
|
|
3321
3385
|
* Used by the execution coordinator to branch between local and worker execution.
|
|
3322
3386
|
*
|
|
3323
3387
|
* @param orgName - Organization name
|
|
3388
|
+
* @param resourceId - Resource ID
|
|
3324
3389
|
* @returns Remote config or null
|
|
3325
3390
|
*/
|
|
3326
|
-
getRemoteConfig(orgName) {
|
|
3327
|
-
return this.
|
|
3391
|
+
getRemoteConfig(orgName, resourceId) {
|
|
3392
|
+
return this.remoteResources.get(`${orgName}/${resourceId}`) ?? null;
|
|
3328
3393
|
}
|
|
3329
3394
|
/**
|
|
3330
|
-
* Check if an organization
|
|
3395
|
+
* Check if an organization has any remote (externally deployed) resources
|
|
3331
3396
|
*
|
|
3332
3397
|
* @param orgName - Organization name
|
|
3333
|
-
* @returns true if the org
|
|
3398
|
+
* @returns true if the org has at least one runtime-registered resource
|
|
3334
3399
|
*/
|
|
3335
3400
|
isRemote(orgName) {
|
|
3336
|
-
|
|
3401
|
+
const prefix = `${orgName}/`;
|
|
3402
|
+
for (const key of this.remoteResources.keys()) {
|
|
3403
|
+
if (key.startsWith(prefix)) return true;
|
|
3404
|
+
}
|
|
3405
|
+
return false;
|
|
3337
3406
|
}
|
|
3338
3407
|
// ============================================================================
|
|
3339
3408
|
// Resource Manifest Accessors
|
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(),
|
|
@@ -64,8 +146,12 @@ function startWorker(org) {
|
|
|
64
146
|
const agents = new Map(
|
|
65
147
|
(org.agents ?? []).map((a) => [a.config.resourceId, a])
|
|
66
148
|
);
|
|
149
|
+
console.log(`[SDK-WORKER] Worker started with ${workflows.size} workflow(s), ${agents.size} agent(s)`);
|
|
67
150
|
parentPort.on("message", async (msg) => {
|
|
68
151
|
if (msg.type === "manifest") {
|
|
152
|
+
const workflowList = (org.workflows ?? []).map((w) => w.config.resourceId);
|
|
153
|
+
const agentList = (org.agents ?? []).map((a) => a.config.resourceId);
|
|
154
|
+
console.log(`[SDK-WORKER] Manifest requested: workflows=[${workflowList.join(", ")}], agents=[${agentList.join(", ")}]`);
|
|
69
155
|
parentPort.postMessage({
|
|
70
156
|
type: "manifest",
|
|
71
157
|
workflows: (org.workflows ?? []).map((w) => ({
|
|
@@ -87,19 +173,33 @@ function startWorker(org) {
|
|
|
87
173
|
});
|
|
88
174
|
return;
|
|
89
175
|
}
|
|
176
|
+
if (msg.type === "tool-result") {
|
|
177
|
+
handleToolResult(msg);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
90
180
|
if (msg.type === "execute") {
|
|
91
|
-
const { resourceId, input } = msg;
|
|
181
|
+
const { resourceId, executionId, input, organizationId, organizationName } = msg;
|
|
182
|
+
console.log(`[SDK-WORKER] Execute request: resourceId=${resourceId}, executionId=${executionId}`);
|
|
92
183
|
const workflow = workflows.get(resourceId);
|
|
93
184
|
if (workflow) {
|
|
94
185
|
try {
|
|
95
|
-
|
|
186
|
+
console.log(`[SDK-WORKER] Running workflow '${resourceId}' (${Object.keys(workflow.steps).length} steps)`);
|
|
187
|
+
const startTime = Date.now();
|
|
188
|
+
const { output, logs } = await executeWorkflow(workflow, input, {
|
|
189
|
+
executionId,
|
|
190
|
+
organizationId: organizationId ?? "",
|
|
191
|
+
organizationName: organizationName ?? ""
|
|
192
|
+
});
|
|
193
|
+
console.log(`[SDK-WORKER] Workflow '${resourceId}' completed (${Date.now() - startTime}ms)`);
|
|
96
194
|
parentPort.postMessage({ type: "result", status: "completed", output, logs });
|
|
97
195
|
} catch (err) {
|
|
196
|
+
console.error(`[SDK-WORKER] Workflow '${resourceId}' failed: ${String(err)}`);
|
|
98
197
|
parentPort.postMessage({ type: "result", status: "failed", error: String(err), logs: [] });
|
|
99
198
|
}
|
|
100
199
|
return;
|
|
101
200
|
}
|
|
102
201
|
if (agents.has(resourceId)) {
|
|
202
|
+
console.error(`[SDK-WORKER] Agent execution not supported: ${resourceId}`);
|
|
103
203
|
parentPort.postMessage({
|
|
104
204
|
type: "result",
|
|
105
205
|
status: "failed",
|
|
@@ -108,6 +208,7 @@ function startWorker(org) {
|
|
|
108
208
|
});
|
|
109
209
|
return;
|
|
110
210
|
}
|
|
211
|
+
console.error(`[SDK-WORKER] Resource not found: ${resourceId}`);
|
|
111
212
|
parentPort.postMessage({
|
|
112
213
|
type: "result",
|
|
113
214
|
status: "failed",
|
|
@@ -118,4 +219,4 @@ function startWorker(org) {
|
|
|
118
219
|
});
|
|
119
220
|
}
|
|
120
221
|
|
|
121
|
-
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.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
|
+
}
|