@ultrst-armada/kloks 1.17.0 → 1.19.0

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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "packageName": "@ultrst-armada/kloks",
4
- "version": "1.17.0",
5
- "sourceCommit": "b54b0084d09f1e314ac1c1ab6e4ed320a623025f",
4
+ "version": "1.19.0",
5
+ "sourceCommit": "5af44cb81c5dcd3db7c1118ada75b24d619b3adb",
6
6
  "releaseWorkflow": "npm Release",
7
- "workflowRunId": "40837780737"
7
+ "workflowRunId": "40941286261"
8
8
  }
package/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './packages/services/dist/index.d.ts';
5
5
  export * from './packages/backend/dist/index.d.ts';
6
6
  export * from './packages/orchestrations/dist/index.d.ts';
7
7
  export * from './packages/contracts/dist/index.d.ts';
8
+ export * from './packages/fod/dist/index.d.ts';
package/index.js CHANGED
@@ -5,3 +5,4 @@ export * from './packages/services/dist/index.js';
5
5
  export * from './packages/backend/dist/index.js';
6
6
  export * from './packages/orchestrations/dist/index.js';
7
7
  export * from './packages/contracts/dist/index.js';
8
+ export * from './packages/fod/dist/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultrst-armada/kloks",
3
- "version": "1.17.0",
3
+ "version": "1.19.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -144,6 +144,11 @@
144
144
  "types": "./packages/backend/dist/krnl-ai-services.d.ts",
145
145
  "import": "./packages/backend/dist/krnl-ai-services.js",
146
146
  "default": "./packages/backend/dist/krnl-ai-services.js"
147
+ },
148
+ "./fod": {
149
+ "types": "./packages/fod/dist/index.d.ts",
150
+ "import": "./packages/fod/dist/index.js",
151
+ "default": "./packages/fod/dist/index.js"
147
152
  }
148
153
  },
149
154
  "scripts": {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-SHZAQTIT.js";
4
4
  import {
5
5
  findUserWorkspace
6
- } from "./chunk-6K75XXFD.js";
6
+ } from "./chunk-VN2YMZJO.js";
7
7
 
8
8
  // src/services/workspaceGraphService.ts
9
9
  function slugify(name) {
@@ -4,7 +4,7 @@ import {
4
4
  findUserWorkspace,
5
5
  getWorkspaces,
6
6
  updateWorkspace
7
- } from "./chunk-6K75XXFD.js";
7
+ } from "./chunk-VN2YMZJO.js";
8
8
  import {
9
9
  b2DownloadFile,
10
10
  b2ListFileNames,
@@ -17,7 +17,7 @@ import {
17
17
  } from "./chunk-WTBAG4AV.js";
18
18
  import {
19
19
  workspaceGraphService
20
- } from "./chunk-VKSGYMAH.js";
20
+ } from "./chunk-47IVAXPJ.js";
21
21
  import {
22
22
  StorageAdapterFactory
23
23
  } from "./chunk-SHZAQTIT.js";
@@ -27,7 +27,7 @@ import {
27
27
  findUserWorkspace,
28
28
  getWorkspaces,
29
29
  updateWorkspace
30
- } from "./chunk-6K75XXFD.js";
30
+ } from "./chunk-VN2YMZJO.js";
31
31
  import {
32
32
  queryUnifiedDb
33
33
  } from "./chunk-VAFCR2MS.js";
@@ -353,15 +353,23 @@ async function renameAppInWorkspaceData(userId, workspaceId, appId, newName, env
353
353
  }
354
354
 
355
355
  // src/core/workspaceCore.ts
356
+ function workspaceAppId(env) {
357
+ const value = String(env?.WORKSPACE_APP_ID ?? "depm").trim().toLowerCase();
358
+ return value || "depm";
359
+ }
360
+ function appProfile(profiles, appId) {
361
+ if (!profiles[appId] || typeof profiles[appId] !== "object") profiles[appId] = {};
362
+ return profiles[appId];
363
+ }
356
364
  async function findUserWorkspace(workspaceId, env) {
357
365
  const res = await queryUnifiedDb(`SELECT id, email, username, app_profiles FROM "ultrst-users"`, [], env);
358
366
  for (const user of res.rows) {
359
367
  const profiles = typeof user.app_profiles === "string" ? JSON.parse(user.app_profiles) : user.app_profiles || {};
360
- const depm = profiles.depm || {};
361
- const workspaces = Array.isArray(depm.workspaces) ? depm.workspaces : [];
368
+ const app = appProfile(profiles, workspaceAppId(env));
369
+ const workspaces = Array.isArray(app.workspaces) ? app.workspaces : [];
362
370
  const ws = workspaces.find((w) => w.id === workspaceId);
363
371
  if (ws) {
364
- const conns = depm.storage_connections || profiles.srkl?.storage_connections || profiles.docustack?.storage_connections || [];
372
+ const conns = app.storage_connections || profiles.srkl?.storage_connections || profiles.docustack?.storage_connections || [];
365
373
  const conn = conns.find((c) => c.id === ws.storageConnectionId) || conns.find((c) => c.role === "primary") || conns[0] || null;
366
374
  return { user, workspace: ws, connection: conn };
367
375
  }
@@ -378,10 +386,10 @@ async function getWorkspaces(userId, env) {
378
386
  return { success: true, workspaces: [], activeWorkspaceId: null, storage_connections: [] };
379
387
  }
380
388
  const profiles = typeof userRow.app_profiles === "string" ? JSON.parse(userRow.app_profiles) : userRow.app_profiles || {};
381
- const depm = profiles.depm || {};
382
- const workspaces = Array.isArray(depm.workspaces) ? depm.workspaces : [];
383
- const activeWorkspaceId = depm.activeWorkspaceId || null;
384
- const conns = depm.storage_connections?.length ? depm.storage_connections : profiles.srkl?.storage_connections || [];
389
+ const app = appProfile(profiles, workspaceAppId(env));
390
+ const workspaces = Array.isArray(app.workspaces) ? app.workspaces : [];
391
+ const activeWorkspaceId = app.activeWorkspaceId || null;
392
+ const conns = app.storage_connections?.length ? app.storage_connections : profiles.srkl?.storage_connections || [];
385
393
  return { success: true, workspaces, activeWorkspaceId, storage_connections: conns };
386
394
  }
387
395
  async function createWorkspace(userId, wsData, env) {
@@ -389,12 +397,13 @@ async function createWorkspace(userId, wsData, env) {
389
397
  const user = uRes.rows[0];
390
398
  if (!user) throw new Error("User account not found.");
391
399
  const profiles = typeof user.app_profiles === "string" ? JSON.parse(user.app_profiles) : user.app_profiles || {};
392
- if (!profiles.depm) profiles.depm = {};
393
- const workspaces = Array.isArray(profiles.depm.workspaces) ? profiles.depm.workspaces : [];
400
+ const app = appProfile(profiles, workspaceAppId(env));
401
+ const workspaces = Array.isArray(app.workspaces) ? app.workspaces : [];
402
+ const appId = workspaceAppId(env);
394
403
  const wsName = (wsData.name || "New Workspace").trim();
395
- const wsId = wsData.id || `ws-depm-${Date.now()}`;
404
+ const wsId = wsData.id || `ws-${appId}-${Date.now()}`;
396
405
  const userName = user.username || user.name || "user";
397
- const folderKey = `ultrst_depm_${userName.toLowerCase().replace(/[^a-z0-9]/g, "_")}_${wsName.toLowerCase().replace(/[^a-z0-9]/g, "_")}`;
406
+ const folderKey = `ultrst_${appId}_${userName.toLowerCase().replace(/[^a-z0-9]/g, "_")}_${wsName.toLowerCase().replace(/[^a-z0-9]/g, "_")}`;
398
407
  const newWs = {
399
408
  ...wsData,
400
409
  id: wsId,
@@ -403,13 +412,13 @@ async function createWorkspace(userId, wsData, env) {
403
412
  localFolderKey: folderKey,
404
413
  workspacePath: `./${folderKey}`,
405
414
  storageProvider: wsData.storageProvider || "backblaze_b2",
406
- b2BucketName: wsData.b2BucketName || "ultrst-apps",
415
+ b2BucketName: wsData.b2BucketName || void 0,
407
416
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
408
417
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
409
418
  };
410
419
  workspaces.push(newWs);
411
- profiles.depm.workspaces = workspaces;
412
- profiles.depm.activeWorkspaceId = wsId;
420
+ app.workspaces = workspaces;
421
+ app.activeWorkspaceId = wsId;
413
422
  await queryUnifiedDb(`UPDATE "ultrst-users" SET app_profiles = $1, updated_at = NOW() WHERE id = $2`, [JSON.stringify(profiles), user.id], env);
414
423
  const conn = resolveWorkspaceConnection(profiles, newWs);
415
424
  await syncWorkspaceCreateToBucket(newWs, conn, env);
@@ -420,14 +429,14 @@ async function updateWorkspace(userId, params, env) {
420
429
  const user = uRes.rows[0];
421
430
  if (!user) throw new Error("User not found.");
422
431
  const profiles = typeof user.app_profiles === "string" ? JSON.parse(user.app_profiles) : user.app_profiles || {};
423
- if (!profiles.depm) profiles.depm = {};
424
- const workspaces = Array.isArray(profiles.depm.workspaces) ? profiles.depm.workspaces : [];
432
+ const app = appProfile(profiles, workspaceAppId(env));
433
+ const workspaces = Array.isArray(app.workspaces) ? app.workspaces : [];
425
434
  const { action, workspaceId, updates } = params;
426
435
  const targetId = workspaceId || updates?.id;
427
436
  const match = workspaces.find((w) => w.id === targetId);
428
437
  if (!match) throw new Error("Workspace not found.");
429
438
  if (action === "switch") {
430
- profiles.depm.activeWorkspaceId = targetId;
439
+ app.activeWorkspaceId = targetId;
431
440
  } else {
432
441
  const safeUpdates = { ...updates || params };
433
442
  delete safeUpdates.storageProvider;
@@ -452,21 +461,22 @@ async function deleteWorkspace(userId, wsId, env) {
452
461
  const user = uRes.rows[0];
453
462
  if (!user) throw new Error("User not found.");
454
463
  const profiles = typeof user.app_profiles === "string" ? JSON.parse(user.app_profiles) : user.app_profiles || {};
455
- if (!profiles.depm?.workspaces) return { success: true, workspaces: [] };
456
- const targetWs = profiles.depm.workspaces.find((w) => w.id === wsId);
464
+ const app = appProfile(profiles, workspaceAppId(env));
465
+ if (!app.workspaces) return { success: true, workspaces: [] };
466
+ const targetWs = app.workspaces.find((w) => w.id === wsId);
457
467
  const conn = targetWs ? resolveWorkspaceConnection(profiles, targetWs) : null;
458
- profiles.depm.workspaces = profiles.depm.workspaces.filter((w) => w.id !== wsId);
459
- if (profiles.depm.activeWorkspaceId === wsId) {
460
- profiles.depm.activeWorkspaceId = profiles.depm.workspaces[0]?.id || null;
468
+ app.workspaces = app.workspaces.filter((w) => w.id !== wsId);
469
+ if (app.activeWorkspaceId === wsId) {
470
+ app.activeWorkspaceId = app.workspaces[0]?.id || null;
461
471
  }
462
- if (profiles.depm.workspace_data?.[wsId]) {
463
- delete profiles.depm.workspace_data[wsId];
472
+ if (app.workspace_data?.[wsId]) {
473
+ delete app.workspace_data[wsId];
464
474
  }
465
475
  await queryUnifiedDb(`UPDATE "ultrst-users" SET app_profiles = $1, updated_at = NOW() WHERE id = $2`, [JSON.stringify(profiles), user.id], env);
466
476
  if (targetWs && conn) {
467
477
  await syncWorkspaceDeleteToBucket(targetWs, conn, env);
468
478
  }
469
- return { success: true, workspaces: profiles.depm.workspaces };
479
+ return { success: true, workspaces: app.workspaces };
470
480
  }
471
481
 
472
482
  // src/core/workspaceStorageDetailsCore.ts
@@ -666,19 +666,19 @@ declare function findUserWorkspace(workspaceId: string, env?: Record<string, unk
666
666
  }>;
667
667
  declare function getWorkspaces(userId?: string, env?: Record<string, unknown>): Promise<{
668
668
  success: boolean;
669
- workspaces: any;
669
+ workspaces: any[];
670
670
  activeWorkspaceId: any;
671
671
  storage_connections: any;
672
672
  }>;
673
673
  declare function createWorkspace(userId: string, wsData: any, env?: Record<string, unknown>): Promise<{
674
674
  success: boolean;
675
675
  workspace: any;
676
- workspaces: any;
676
+ workspaces: any[];
677
677
  }>;
678
678
  declare function updateWorkspace(userId: string, params: any, env?: Record<string, unknown>): Promise<{
679
679
  success: boolean;
680
680
  workspace: any;
681
- workspaces: any;
681
+ workspaces: any[];
682
682
  }>;
683
683
  declare function deleteWorkspace(userId: string, wsId: string, env?: Record<string, unknown>): Promise<{
684
684
  success: boolean;
@@ -34,7 +34,7 @@ import {
34
34
  setWorkingWorkspaceConfig,
35
35
  syncWorkspace,
36
36
  workingWorkspaceService
37
- } from "./chunk-BTMIK44G.js";
37
+ } from "./chunk-6DNGLKAV.js";
38
38
  import {
39
39
  validateToolInput
40
40
  } from "./chunk-6GQNYRD6.js";
@@ -178,7 +178,7 @@ import {
178
178
  krnlWorkspaceGraphServiceFacade,
179
179
  krnlWorkspaceServiceDefinition,
180
180
  krnlWorkspaceServiceFacade
181
- } from "./chunk-T26VJ22Y.js";
181
+ } from "./chunk-LCRK2QSY.js";
182
182
  import {
183
183
  getPrimarySrklDeploymentUrl,
184
184
  getSrklAccounts,
@@ -205,7 +205,7 @@ import {
205
205
  } from "./chunk-WTBAG4AV.js";
206
206
  import {
207
207
  workspaceGraphService
208
- } from "./chunk-VKSGYMAH.js";
208
+ } from "./chunk-47IVAXPJ.js";
209
209
  import {
210
210
  BackblazeB2Adapter,
211
211
  LocalFSAdapter,
@@ -240,7 +240,7 @@ import {
240
240
  syncWorkspaceDeleteToBucket,
241
241
  updateWorkspace,
242
242
  writeWorkspaceFile
243
- } from "./chunk-6K75XXFD.js";
243
+ } from "./chunk-VN2YMZJO.js";
244
244
  import {
245
245
  b2DeleteFileVersion,
246
246
  b2DeleteFolder,
@@ -31,14 +31,14 @@ import {
31
31
  krnlWorkspaceGraphServiceFacade,
32
32
  krnlWorkspaceServiceDefinition,
33
33
  krnlWorkspaceServiceFacade
34
- } from "./chunk-T26VJ22Y.js";
34
+ } from "./chunk-LCRK2QSY.js";
35
35
  import "./chunk-XHADDA75.js";
36
36
  import "./chunk-4QEMALXF.js";
37
37
  import "./chunk-FZKBTF34.js";
38
38
  import "./chunk-WTBAG4AV.js";
39
- import "./chunk-VKSGYMAH.js";
39
+ import "./chunk-47IVAXPJ.js";
40
40
  import "./chunk-SHZAQTIT.js";
41
- import "./chunk-6K75XXFD.js";
41
+ import "./chunk-VN2YMZJO.js";
42
42
  import "./chunk-VAFCR2MS.js";
43
43
  import "./chunk-KKRWZDMN.js";
44
44
  import "./chunk-TY32TUNI.js";
@@ -14,9 +14,9 @@ import {
14
14
  } from "../chunk-RBF2OGMC.js";
15
15
  import {
16
16
  workspaceGraphService
17
- } from "../chunk-VKSGYMAH.js";
17
+ } from "../chunk-47IVAXPJ.js";
18
18
  import "../chunk-SHZAQTIT.js";
19
- import "../chunk-6K75XXFD.js";
19
+ import "../chunk-VN2YMZJO.js";
20
20
  import "../chunk-VAFCR2MS.js";
21
21
  import "../chunk-KKRWZDMN.js";
22
22
  import "../chunk-TY32TUNI.js";
@@ -6,12 +6,12 @@ import {
6
6
  WorkspaceFS,
7
7
  remoteWorkspaceService,
8
8
  workingWorkspaceService
9
- } from "../chunk-BTMIK44G.js";
9
+ } from "../chunk-6DNGLKAV.js";
10
10
  import {
11
11
  formatCanonicalWorkspaceFolderName,
12
12
  sanitizeWorkspaceName
13
13
  } from "../chunk-FZKBTF34.js";
14
- import "../chunk-6K75XXFD.js";
14
+ import "../chunk-VN2YMZJO.js";
15
15
  import "../chunk-VAFCR2MS.js";
16
16
  import "../chunk-KKRWZDMN.js";
17
17
  export {
@@ -0,0 +1,155 @@
1
+ import * as _ultrst_armada_krnl from '@ultrst-armada/krnl';
2
+ import { ServiceDefinition } from '@ultrst-armada/krnl';
3
+
4
+ type FodPortDirection = 'input' | 'output';
5
+ type FodNodeCategory = 'host-app' | 'gutts' | 'flow' | 'system';
6
+ interface FodPort {
7
+ id: string;
8
+ name: string;
9
+ direction: FodPortDirection;
10
+ dataType: string;
11
+ required?: boolean;
12
+ description?: string;
13
+ schema?: Record<string, unknown>;
14
+ }
15
+ interface FodNodeDefinition {
16
+ type: string;
17
+ label: string;
18
+ description: string;
19
+ category: FodNodeCategory;
20
+ group: string;
21
+ inputs: FodPort[];
22
+ outputs: FodPort[];
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ interface FodEndpointDescriptor {
26
+ id: string;
27
+ serviceId: string;
28
+ serviceName: string;
29
+ operationId: string;
30
+ operationName: string;
31
+ description?: string;
32
+ runtime?: string;
33
+ deployment?: string;
34
+ inputSchema?: Record<string, unknown>;
35
+ outputSchema?: Record<string, unknown>;
36
+ invoke: (input: unknown) => Promise<unknown>;
37
+ }
38
+ interface FodFlowNode {
39
+ id: string;
40
+ type: string;
41
+ position: {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ data: Record<string, unknown>;
46
+ }
47
+ interface FodFlowEdge {
48
+ id: string;
49
+ source: string;
50
+ sourceHandle?: string;
51
+ target: string;
52
+ targetHandle?: string;
53
+ }
54
+ interface FodFlow {
55
+ id: string;
56
+ name: string;
57
+ description?: string;
58
+ version: number;
59
+ createdAt: string;
60
+ updatedAt: string;
61
+ nodes: FodFlowNode[];
62
+ edges: FodFlowEdge[];
63
+ viewport?: {
64
+ x: number;
65
+ y: number;
66
+ zoom: number;
67
+ };
68
+ metadata?: Record<string, unknown>;
69
+ }
70
+ interface FodExecutionEvent {
71
+ type: 'flow-started' | 'node-started' | 'node-completed' | 'node-failed' | 'flow-completed';
72
+ timestamp: number;
73
+ flowId: string;
74
+ nodeId?: string;
75
+ data?: unknown;
76
+ }
77
+ interface FodExecutionResult {
78
+ success: boolean;
79
+ flowId: string;
80
+ output: unknown;
81
+ outputs: Record<string, unknown>;
82
+ errors: Array<{
83
+ nodeId?: string;
84
+ message: string;
85
+ }>;
86
+ events: FodExecutionEvent[];
87
+ }
88
+ interface FodRuntimeOptions {
89
+ workspaceId: string;
90
+ workspaceService: any;
91
+ endpoints?: FodEndpointDescriptor[];
92
+ nodes?: FodNodeDefinition[];
93
+ onEvent?: (event: FodExecutionEvent) => void;
94
+ }
95
+
96
+ declare function scanBackendFacade(facade: Record<string, unknown>): FodEndpointDescriptor[];
97
+ declare function endpointToNode(endpoint: FodEndpointDescriptor): FodNodeDefinition;
98
+ declare function scanBackendFacadeToNodes(facade: Record<string, unknown>): {
99
+ endpoints: FodEndpointDescriptor[];
100
+ nodes: FodNodeDefinition[];
101
+ };
102
+
103
+ declare class FodFlowStore {
104
+ private readonly workspaceService;
105
+ constructor(workspaceService: any);
106
+ list(workspaceId: string): Promise<FodFlow[]>;
107
+ get(workspaceId: string, flowId: string): Promise<FodFlow | null>;
108
+ save(workspaceId: string, flow: FodFlow): Promise<FodFlow>;
109
+ delete(workspaceId: string, flowId: string): Promise<boolean>;
110
+ }
111
+
112
+ declare function executeFodFlow(flow: FodFlow, endpoints: Map<string, FodEndpointDescriptor>, onEvent?: (event: FodExecutionEvent) => void): Promise<FodExecutionResult>;
113
+
114
+ declare class FodRuntime {
115
+ private readonly options;
116
+ readonly flowStore: FodFlowStore;
117
+ private endpoints;
118
+ private nodes;
119
+ constructor(options: {
120
+ workspaceId: string;
121
+ workspaceService: any;
122
+ onEvent?: (event: any) => void;
123
+ });
124
+ setEndpoints(endpoints: FodEndpointDescriptor[], nodes?: FodNodeDefinition[]): void;
125
+ getNodeDefinitions(): FodNodeDefinition[];
126
+ getEndpoints(): FodEndpointDescriptor[];
127
+ listFlows(): Promise<FodFlow[]>;
128
+ getFlow(flowId: string): Promise<FodFlow | null>;
129
+ saveFlow(flow: FodFlow): Promise<FodFlow>;
130
+ deleteFlow(flowId: string): Promise<boolean>;
131
+ executeFlow(flowId: string): Promise<FodExecutionResult>;
132
+ }
133
+
134
+ declare function createFodServiceFacade(runtime: FodRuntime): {
135
+ id: string;
136
+ name: string;
137
+ version: string;
138
+ runtime: "server";
139
+ deployment: "local";
140
+ definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
141
+ createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
142
+ execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
143
+ };
144
+ declare function createFodServiceFacadeForWorkspace(buildRuntime: (workspaceId: string) => FodRuntime): {
145
+ id: string;
146
+ name: string;
147
+ version: string;
148
+ runtime: "server";
149
+ deployment: "local";
150
+ definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
151
+ createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
152
+ execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
153
+ };
154
+
155
+ export { type FodEndpointDescriptor, type FodExecutionEvent, type FodExecutionResult, type FodFlow, type FodFlowEdge, type FodFlowNode, FodFlowStore, type FodNodeCategory, type FodNodeDefinition, type FodPort, type FodPortDirection, FodRuntime, type FodRuntimeOptions, createFodServiceFacade, createFodServiceFacadeForWorkspace, endpointToNode, executeFodFlow, scanBackendFacade, scanBackendFacadeToNodes };
@@ -0,0 +1,254 @@
1
+ // src/endpointNodeProvider.ts
2
+ function portsFromSchema(schema, direction) {
3
+ if (!schema || schema.type !== "object") {
4
+ return [{ id: direction === "input" ? "input" : "result", name: direction === "input" ? "input" : "result", direction, dataType: String(schema?.type ?? "any") }];
5
+ }
6
+ const properties = schema.properties ?? {};
7
+ const required = new Set(Array.isArray(schema.required) ? schema.required.map(String) : []);
8
+ return Object.entries(properties).map(([id, value]) => ({
9
+ id,
10
+ name: id,
11
+ direction,
12
+ dataType: String(value?.type ?? "any"),
13
+ required: required.has(id),
14
+ description: typeof value?.description === "string" ? value.description : void 0,
15
+ schema: value
16
+ }));
17
+ }
18
+ function scanBackendFacade(facade) {
19
+ const endpoints = [];
20
+ const services = facade.services ?? {};
21
+ for (const [serviceKey, service] of Object.entries(services)) {
22
+ const definition = service?.definition;
23
+ if (!definition?.operations) continue;
24
+ for (const [operationKey, operation] of Object.entries(definition.operations)) {
25
+ if (typeof service.execute !== "function") continue;
26
+ endpoints.push({
27
+ id: String(operation.id ?? `${service.id ?? serviceKey}.${operationKey}`),
28
+ serviceId: String(service.id ?? serviceKey),
29
+ serviceName: String(service.name ?? serviceKey),
30
+ operationId: String(operation.id ?? operationKey),
31
+ operationName: String(operation.name ?? operationKey),
32
+ description: typeof operation.description === "string" ? operation.description : void 0,
33
+ runtime: typeof service.runtime === "string" ? service.runtime : void 0,
34
+ deployment: typeof service.deployment === "string" ? service.deployment : void 0,
35
+ inputSchema: operation.inputSchema,
36
+ outputSchema: operation.outputSchema,
37
+ invoke: (input) => service.execute(operationKey, input)
38
+ });
39
+ }
40
+ }
41
+ return endpoints;
42
+ }
43
+ function endpointToNode(endpoint) {
44
+ return {
45
+ type: `host/${endpoint.id}`,
46
+ label: endpoint.operationName,
47
+ description: endpoint.description ?? endpoint.operationId,
48
+ category: "host-app",
49
+ group: endpoint.serviceName,
50
+ inputs: portsFromSchema(endpoint.inputSchema, "input"),
51
+ outputs: portsFromSchema(endpoint.outputSchema, "output"),
52
+ metadata: {
53
+ endpointId: endpoint.id,
54
+ serviceId: endpoint.serviceId,
55
+ operationId: endpoint.operationId,
56
+ runtime: endpoint.runtime,
57
+ deployment: endpoint.deployment
58
+ }
59
+ };
60
+ }
61
+ function scanBackendFacadeToNodes(facade) {
62
+ const endpoints = scanBackendFacade(facade);
63
+ return { endpoints, nodes: endpoints.map(endpointToNode) };
64
+ }
65
+
66
+ // src/flowStore.ts
67
+ var ROOT = "FOD";
68
+ function pathFor(flowId) {
69
+ const safe = flowId.replace(/[^a-zA-Z0-9._-]/g, "_");
70
+ return `${ROOT}/${safe}.json`;
71
+ }
72
+ var FodFlowStore = class {
73
+ constructor(workspaceService) {
74
+ this.workspaceService = workspaceService;
75
+ }
76
+ workspaceService;
77
+ async list(workspaceId) {
78
+ const entries = await this.workspaceService.listFiles(workspaceId, ROOT);
79
+ const flows = [];
80
+ for (const entry of entries) {
81
+ if (entry.isFolder || !entry.name.endsWith(".json")) continue;
82
+ try {
83
+ const raw = await this.workspaceService.readFile(workspaceId, entry.path);
84
+ flows.push(JSON.parse(typeof raw === "string" ? raw : Buffer.from(raw).toString("utf8")));
85
+ } catch {
86
+ }
87
+ }
88
+ return flows.sort((a, b) => a.name.localeCompare(b.name));
89
+ }
90
+ async get(workspaceId, flowId) {
91
+ try {
92
+ const raw = await this.workspaceService.readFile(workspaceId, pathFor(flowId));
93
+ return JSON.parse(typeof raw === "string" ? raw : Buffer.from(raw).toString("utf8"));
94
+ } catch {
95
+ return null;
96
+ }
97
+ }
98
+ async save(workspaceId, flow) {
99
+ const now = (/* @__PURE__ */ new Date()).toISOString();
100
+ const next = { ...flow, updatedAt: now, version: Math.max(1, flow.version ?? 1) };
101
+ await this.workspaceService.writeFile(workspaceId, pathFor(flow.id), JSON.stringify(next, null, 2));
102
+ return next;
103
+ }
104
+ async delete(workspaceId, flowId) {
105
+ const result = await this.workspaceService.deleteFile(workspaceId, pathFor(flowId));
106
+ return Boolean(result?.success);
107
+ }
108
+ };
109
+
110
+ // src/executor.ts
111
+ async function executeFodFlow(flow, endpoints, onEvent) {
112
+ const events = [];
113
+ const errors = [];
114
+ const emit = (event) => {
115
+ events.push(event);
116
+ onEvent?.(event);
117
+ };
118
+ emit({ type: "flow-started", timestamp: Date.now(), flowId: flow.id });
119
+ const outputs = {};
120
+ const incoming = (nodeId) => flow.edges.filter((edge) => edge.target === nodeId);
121
+ const remaining = new Set(flow.nodes.map((node) => node.id));
122
+ const values = /* @__PURE__ */ new Map();
123
+ while (remaining.size) {
124
+ const ready = flow.nodes.filter((node) => remaining.has(node.id) && incoming(node.id).every((edge) => values.has(`${edge.source}:${edge.sourceHandle ?? "result"}`)));
125
+ if (!ready.length) {
126
+ const unresolved = [...remaining].join(", ");
127
+ const message = `Flow contains an unresolved dependency or cycle: ${unresolved}`;
128
+ errors.push({ message });
129
+ break;
130
+ }
131
+ for (const node of ready) {
132
+ remaining.delete(node.id);
133
+ emit({ type: "node-started", timestamp: Date.now(), flowId: flow.id, nodeId: node.id });
134
+ try {
135
+ const endpointId = String(node.data.endpointId ?? node.data.apiId ?? node.type.replace(/^(host|gutts)\//, ""));
136
+ const endpoint = endpoints.get(endpointId);
137
+ if (!endpoint) throw new Error(`No executable endpoint registered for node '${node.type}'.`);
138
+ const input = {};
139
+ for (const edge of incoming(node.id)) {
140
+ input[String(edge.targetHandle ?? "input")] = values.get(`${edge.source}:${edge.sourceHandle ?? "result"}`);
141
+ }
142
+ const configured = node.data.inputs ?? {};
143
+ Object.assign(input, configured);
144
+ const result = await endpoint.invoke(input);
145
+ outputs[node.id] = result;
146
+ values.set(`${node.id}:result`, result);
147
+ if (result && typeof result === "object") {
148
+ for (const [key, value] of Object.entries(result)) values.set(`${node.id}:${key}`, value);
149
+ }
150
+ emit({ type: "node-completed", timestamp: Date.now(), flowId: flow.id, nodeId: node.id, data: result });
151
+ } catch (error) {
152
+ const message = error instanceof Error ? error.message : String(error);
153
+ errors.push({ nodeId: node.id, message });
154
+ emit({ type: "node-failed", timestamp: Date.now(), flowId: flow.id, nodeId: node.id, data: message });
155
+ break;
156
+ }
157
+ }
158
+ if (errors.length) break;
159
+ }
160
+ const success = errors.length === 0 && remaining.size === 0;
161
+ const last = flow.nodes.at(-1);
162
+ emit({ type: "flow-completed", timestamp: Date.now(), flowId: flow.id, data: { success } });
163
+ return { success, flowId: flow.id, output: last ? outputs[last.id] : void 0, outputs, errors, events };
164
+ }
165
+
166
+ // src/runtime.ts
167
+ var FodRuntime = class {
168
+ constructor(options) {
169
+ this.options = options;
170
+ this.flowStore = new FodFlowStore(options.workspaceService);
171
+ }
172
+ options;
173
+ flowStore;
174
+ endpoints = /* @__PURE__ */ new Map();
175
+ nodes = [];
176
+ setEndpoints(endpoints, nodes = []) {
177
+ this.endpoints = new Map(endpoints.map((endpoint) => [endpoint.id, endpoint]));
178
+ this.nodes = nodes;
179
+ }
180
+ getNodeDefinitions() {
181
+ return [...this.nodes];
182
+ }
183
+ getEndpoints() {
184
+ return [...this.endpoints.values()];
185
+ }
186
+ async listFlows() {
187
+ return this.flowStore.list(this.options.workspaceId);
188
+ }
189
+ async getFlow(flowId) {
190
+ return this.flowStore.get(this.options.workspaceId, flowId);
191
+ }
192
+ async saveFlow(flow) {
193
+ return this.flowStore.save(this.options.workspaceId, flow);
194
+ }
195
+ async deleteFlow(flowId) {
196
+ return this.flowStore.delete(this.options.workspaceId, flowId);
197
+ }
198
+ async executeFlow(flowId) {
199
+ const flow = await this.getFlow(flowId);
200
+ if (!flow) throw new Error(`FOD flow '${flowId}' not found.`);
201
+ return executeFodFlow(flow, this.endpoints, this.options.onEvent);
202
+ }
203
+ };
204
+
205
+ // src/index.ts
206
+ import { createService } from "@ultrst-armada/krnl";
207
+ function createFodServiceFacade(runtime) {
208
+ const definition = {
209
+ id: "kloks.fod",
210
+ name: "FodService",
211
+ version: "1.0.0",
212
+ operations: {
213
+ listFlows: { id: "FodService.listFlows", name: "listFlows", inputSchema: { type: "object", properties: {} }, outputSchema: { type: "array" }, handler: async () => runtime.listFlows() },
214
+ getFlow: { id: "FodService.getFlow", name: "getFlow", inputSchema: { type: "object", properties: { flowId: { type: "string" } }, required: ["flowId"] }, outputSchema: { type: "object" }, handler: async (input) => runtime.getFlow(String(input.flowId)) },
215
+ saveFlow: { id: "FodService.saveFlow", name: "saveFlow", inputSchema: { type: "object" }, outputSchema: { type: "object" }, handler: async (input) => runtime.saveFlow(input.flow) },
216
+ deleteFlow: { id: "FodService.deleteFlow", name: "deleteFlow", inputSchema: { type: "object", properties: { flowId: { type: "string" } }, required: ["flowId"] }, outputSchema: { type: "object" }, handler: async (input) => ({ success: await runtime.deleteFlow(String(input.flowId)) }) },
217
+ executeFlow: { id: "FodService.executeFlow", name: "executeFlow", inputSchema: { type: "object", properties: { flowId: { type: "string" } }, required: ["flowId"] }, outputSchema: { type: "object" }, handler: async (input) => runtime.executeFlow(String(input.flowId)) }
218
+ }
219
+ };
220
+ const service = createService(definition);
221
+ return { id: definition.id, name: definition.name, version: definition.version, runtime: "server", deployment: "local", definition, createInstance: () => createService(definition), execute: async (op, input) => {
222
+ await service.start();
223
+ return service.call(op, input);
224
+ } };
225
+ }
226
+ function createFodServiceFacadeForWorkspace(buildRuntime) {
227
+ const definition = {
228
+ id: "kloks.fod",
229
+ name: "FodService",
230
+ version: "1.0.0",
231
+ operations: {
232
+ listFlows: { id: "FodService.listFlows", name: "listFlows", inputSchema: { type: "object", properties: { workspaceId: { type: "string" } }, required: ["workspaceId"] }, outputSchema: { type: "array" }, handler: async (input) => buildRuntime(String(input.workspaceId)).listFlows() },
233
+ getFlow: { id: "FodService.getFlow", name: "getFlow", inputSchema: { type: "object", properties: { workspaceId: { type: "string" }, flowId: { type: "string" } }, required: ["workspaceId", "flowId"] }, outputSchema: { type: "object" }, handler: async (input) => buildRuntime(String(input.workspaceId)).getFlow(String(input.flowId)) },
234
+ saveFlow: { id: "FodService.saveFlow", name: "saveFlow", inputSchema: { type: "object", properties: { workspaceId: { type: "string" }, flow: { type: "object" } }, required: ["workspaceId", "flow"] }, outputSchema: { type: "object" }, handler: async (input) => buildRuntime(String(input.workspaceId)).saveFlow(input.flow) },
235
+ deleteFlow: { id: "FodService.deleteFlow", name: "deleteFlow", inputSchema: { type: "object", properties: { workspaceId: { type: "string" }, flowId: { type: "string" } }, required: ["workspaceId", "flowId"] }, outputSchema: { type: "object" }, handler: async (input) => ({ success: await buildRuntime(String(input.workspaceId)).deleteFlow(String(input.flowId)) }) },
236
+ executeFlow: { id: "FodService.executeFlow", name: "executeFlow", inputSchema: { type: "object", properties: { workspaceId: { type: "string" }, flowId: { type: "string" } }, required: ["workspaceId", "flowId"] }, outputSchema: { type: "object" }, handler: async (input) => buildRuntime(String(input.workspaceId)).executeFlow(String(input.flowId)) }
237
+ }
238
+ };
239
+ const service = createService(definition);
240
+ return { id: definition.id, name: definition.name, version: definition.version, runtime: "server", deployment: "local", definition, createInstance: () => createService(definition), execute: async (op, input) => {
241
+ await service.start();
242
+ return service.call(op, input);
243
+ } };
244
+ }
245
+ export {
246
+ FodFlowStore,
247
+ FodRuntime,
248
+ createFodServiceFacade,
249
+ createFodServiceFacadeForWorkspace,
250
+ endpointToNode,
251
+ executeFodFlow,
252
+ scanBackendFacade,
253
+ scanBackendFacadeToNodes
254
+ };
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema":"https://skipo.dev/schemas/kloks-manifest.v1.json",
3
+ "package":"@kloks/fod",
4
+ "version":"1.0.0",
5
+ "services":[
6
+ {
7
+ "id":"fod",
8
+ "name":"FOD Workflow Module",
9
+ "version":"1.0.0",
10
+ "description":"Embedded workflow discovery, persistence, validation and execution capability for Skipo applications.",
11
+ "backend":{"package":"@ultrst-armada/kloks","subpath":"fod","export":"FodServiceFacade","facade":"FodServiceFacade"},
12
+ "modes":["backend","fullstack"],
13
+ "targets":{"backend":["BackendFacade.services"],"frontend":["Main.tabs.fod"]},
14
+ "dependencies":[]
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@kloks/fod",
3
+ "version": "1.0.0",
4
+ "description": "Embedded FOD workflow orchestration module for Skipo applications.",
5
+ "type": "module",
6
+ "private": false,
7
+ "publishConfig": {"access":"public","registry":"https://registry.npmjs.org/"},
8
+ "main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.js",
9
+ "exports": {".":{"import":"./dist/index.js","types":"./dist/index.d.ts","default":"./dist/index.js"}},
10
+ "scripts": {
11
+ "build":"tsup src/index.ts --format esm --dts --clean --external @ultrst-armada/krnl",
12
+ "typecheck":"tsc --noEmit",
13
+ "test":"vitest run",
14
+ "clean":"rm -rf dist"
15
+ },
16
+ "dependencies": {
17
+ "@kloks/backend":"workspace:*",
18
+ "@kloks/state-graph":"workspace:*"
19
+ },
20
+ "devDependencies": {
21
+ "@ultrst-armada/krnl":"^1.0.3",
22
+ "tsup":"^8.4.0",
23
+ "typescript":"^5.7.3",
24
+ "vitest":"^3.1.0"
25
+ }
26
+ }