@ultrst-armada/kloks 1.24.4 → 1.24.8

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.
Files changed (60) hide show
  1. package/.krusbl-release-attestation.json +3 -3
  2. package/README.md +11 -0
  3. package/package.json +15 -12
  4. package/packages/audio-midi/dist/index.js +16 -16
  5. package/packages/backend/dist/ai-inference/index.js +0 -1
  6. package/packages/backend/dist/ai-keys/index.js +0 -1
  7. package/packages/backend/dist/ai-models/index.js +0 -1
  8. package/packages/backend/dist/ai-provider/index.js +0 -1
  9. package/packages/backend/dist/ai-routing/index.js +0 -1
  10. package/packages/backend/dist/ai-tools/index.js +0 -1
  11. package/packages/backend/dist/api/index.js +0 -1
  12. package/packages/backend/dist/auth/index.d.ts +5 -74
  13. package/packages/backend/dist/auth/index.js +16 -19
  14. package/packages/backend/dist/{chunk-2OPIDIIB.js → chunk-3VWBZEMG.js} +26 -2
  15. package/packages/backend/dist/{chunk-AHJ2EWQW.js → chunk-6D55GT3L.js} +9 -28
  16. package/packages/backend/dist/chunk-ED32WV3T.js +75 -0
  17. package/packages/backend/dist/chunk-EO5VUYYU.js +20 -0
  18. package/packages/backend/dist/{chunk-B3VJ4HDV.js → chunk-JOTDEFRG.js} +1 -1
  19. package/packages/backend/dist/{chunk-OB65KZ2M.js → chunk-M45KQRPR.js} +1 -1
  20. package/packages/backend/dist/chunk-SXDYW3QA.js +579 -0
  21. package/packages/backend/dist/client/index.js +0 -1
  22. package/packages/backend/dist/connectivity/index.js +0 -1
  23. package/packages/backend/dist/control-plane/index.d.ts +3 -3
  24. package/packages/backend/dist/control-plane/index.js +0 -1
  25. package/packages/backend/dist/development/client.d.ts +20 -6
  26. package/packages/backend/dist/development/client.js +42 -28
  27. package/packages/backend/dist/development/index.d.ts +20 -6
  28. package/packages/backend/dist/development/index.js +652 -30
  29. package/packages/backend/dist/development/playwrightInspectionService.js +2 -3
  30. package/packages/backend/dist/development/playwrightInspectionTypes.d.ts +1 -0
  31. package/packages/backend/dist/index.d.ts +3 -57
  32. package/packages/backend/dist/index.js +44 -188
  33. package/packages/backend/dist/krnl-ai-services.js +2 -3
  34. package/packages/backend/dist/krnl-services.js +6 -7
  35. package/packages/backend/dist/services/index.js +4 -5
  36. package/packages/backend/dist/srkl/index.js +1 -2
  37. package/packages/backend/dist/storage/index.js +0 -1
  38. package/packages/backend/dist/workspace/index.js +0 -1
  39. package/packages/backend/package.json +3 -10
  40. package/packages/client/dist/index.d.ts +2 -0
  41. package/packages/client/dist/index.js +29 -1
  42. package/packages/client/package.json +2 -1
  43. package/packages/fod/dist/index.d.ts +11 -1
  44. package/packages/fod/dist/index.js +2 -0
  45. package/packages/fod/package.json +2 -3
  46. package/packages/functions/dist/index.js +16 -16
  47. package/packages/functions/package.json +2 -1
  48. package/packages/services/dist/index.d.ts +46 -1
  49. package/packages/services/dist/index.js +96 -18
  50. package/packages/services/kloks.manifest.json +19 -0
  51. package/packages/state-graph/dist/index.js +25 -25
  52. package/packages/backend/dist/BaseAccountProvider-DduKf5HG.d.ts +0 -66
  53. package/packages/backend/dist/chunk-2HCQ2SIR.js +0 -213
  54. package/packages/backend/dist/chunk-A3BE6ROS.js +0 -180
  55. package/packages/backend/dist/chunk-FJ5LZFBV.js +0 -667
  56. package/packages/backend/dist/chunk-MWSYNRNZ.js +0 -871
  57. package/packages/backend/dist/chunk-QGM4M3NI.js +0 -37
  58. package/packages/backend/dist/dist-XMSSRYDR.js +0 -899
  59. package/packages/backend/dist/transformers.node-HWHOAE4H.js +0 -43879
  60. package/packages/backend/dist/{chunk-IGZB4RYT.js → chunk-R6ZNF6FW.js} +3 -3
@@ -0,0 +1,20 @@
1
+ // src/auth/CanonicalAuthClient.ts
2
+ import {
3
+ LuthAuthClient,
4
+ createLuthAuthClient,
5
+ resolveClientOrigin,
6
+ resolveClientEnvironment
7
+ } from "@dinilmusick/gutts";
8
+ import { LuthAuthError } from "@dinilmusick/gutts";
9
+ import { LuthAuthClient as LuthAuthClient2 } from "@dinilmusick/gutts";
10
+ import { createLuthAuthClient as createLuthAuthClient2 } from "@dinilmusick/gutts";
11
+
12
+ export {
13
+ LuthAuthClient,
14
+ createLuthAuthClient,
15
+ resolveClientOrigin,
16
+ resolveClientEnvironment,
17
+ LuthAuthError,
18
+ LuthAuthClient2,
19
+ createLuthAuthClient2
20
+ };
@@ -3,7 +3,7 @@ import {
3
3
  createService,
4
4
  createServiceDefinition,
5
5
  createServiceProxy
6
- } from "./chunk-MWSYNRNZ.js";
6
+ } from "./chunk-SXDYW3QA.js";
7
7
 
8
8
  // src/services/ServiceBoundary.ts
9
9
  function createLocalService(definition) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  createService,
6
6
  createServiceDefinition
7
- } from "./chunk-MWSYNRNZ.js";
7
+ } from "./chunk-SXDYW3QA.js";
8
8
  import {
9
9
  inferenceExecutor
10
10
  } from "./chunk-GCTQY24J.js";
@@ -0,0 +1,579 @@
1
+ // ../../node_modules/.pnpm/@ultrst-armada+krnl@1.0.9_@types+node@22.20.5/node_modules/@ultrst-armada/krnl/packages/core/dist/index.js
2
+ import { randomUUID } from "crypto";
3
+ import { tryParseJson } from "@dinilmusick/gutts";
4
+ import * as gutts from "@dinilmusick/gutts";
5
+ var ServiceStateStore = class {
6
+ state;
7
+ listeners = /* @__PURE__ */ new Set();
8
+ constructor(initialState) {
9
+ this.state = { ...initialState };
10
+ }
11
+ getState() {
12
+ return Object.freeze({ ...this.state });
13
+ }
14
+ setState(mutation) {
15
+ this.state = { ...this.state, ...mutation };
16
+ const snapshot = this.getState();
17
+ for (const listener of this.listeners) {
18
+ listener(snapshot, mutation);
19
+ }
20
+ }
21
+ subscribe(listener) {
22
+ this.listeners.add(listener);
23
+ return () => {
24
+ this.listeners.delete(listener);
25
+ };
26
+ }
27
+ reset(newState) {
28
+ this.state = { ...newState || {} };
29
+ }
30
+ };
31
+ var TRANSITIONS = {
32
+ uninitialized: ["initializing"],
33
+ initializing: ["ready", "uninitialized"],
34
+ ready: ["starting"],
35
+ starting: ["running", "ready"],
36
+ running: ["stopping"],
37
+ stopping: ["stopped", "running"],
38
+ stopped: ["starting"]
39
+ };
40
+ var LifecycleManager = class {
41
+ status = "uninitialized";
42
+ getStatus() {
43
+ return this.status;
44
+ }
45
+ canTransitionTo(next) {
46
+ return TRANSITIONS[this.status].includes(next);
47
+ }
48
+ transitionTo(next) {
49
+ if (!this.canTransitionTo(next)) {
50
+ throw new Error("[Lifecycle] Invalid transition '" + this.status + "' -> '" + next + "'.");
51
+ }
52
+ this.status = next;
53
+ }
54
+ setStatus(next) {
55
+ this.transitionTo(next);
56
+ }
57
+ assertRunning(serviceName) {
58
+ if (this.status !== "running") {
59
+ throw new Error(
60
+ "[Service:" + serviceName + "] Cannot invoke operation while status is '" + this.status + "' (expected 'running')."
61
+ );
62
+ }
63
+ }
64
+ };
65
+ var runtimeProcess = typeof globalThis !== "undefined" ? globalThis.process : void 0;
66
+ var runtimePerformance = typeof globalThis !== "undefined" ? globalThis.performance : void 0;
67
+ function telemetryNow() {
68
+ return runtimePerformance?.now ? runtimePerformance.now() : Date.now();
69
+ }
70
+ function sampleResources() {
71
+ const memory = runtimeProcess?.memoryUsage?.();
72
+ const cpu = runtimeProcess?.cpuUsage?.();
73
+ const eventLoop = runtimePerformance?.eventLoopUtilization?.();
74
+ return {
75
+ cpuUserMicros: cpu?.user,
76
+ cpuSystemMicros: cpu?.system,
77
+ heapUsedBytes: memory?.heapUsed,
78
+ heapTotalBytes: memory?.heapTotal,
79
+ rssBytes: memory?.rss,
80
+ externalBytes: memory?.external,
81
+ arrayBuffersBytes: memory?.arrayBuffers,
82
+ eventLoopUtilization: eventLoop?.utilization,
83
+ scope: memory || cpu || eventLoop ? "process" : "runtime"
84
+ };
85
+ }
86
+ function deltaResources(start, end) {
87
+ const delta = (a, b) => a === void 0 || b === void 0 ? void 0 : b - a;
88
+ return {
89
+ cpuUserMicros: delta(start.cpuUserMicros, end.cpuUserMicros),
90
+ cpuSystemMicros: delta(start.cpuSystemMicros, end.cpuSystemMicros),
91
+ heapUsedBytes: delta(start.heapUsedBytes, end.heapUsedBytes),
92
+ heapTotalBytes: delta(start.heapTotalBytes, end.heapTotalBytes),
93
+ rssBytes: delta(start.rssBytes, end.rssBytes),
94
+ externalBytes: delta(start.externalBytes, end.externalBytes),
95
+ arrayBuffersBytes: delta(start.arrayBuffersBytes, end.arrayBuffersBytes),
96
+ eventLoopUtilization: delta(start.eventLoopUtilization, end.eventLoopUtilization),
97
+ scope: start.scope
98
+ };
99
+ }
100
+ var id = (prefix) => `${prefix}_${randomUUID()}`;
101
+ function percentiles(values) {
102
+ if (!values.length) return { min: 0, mean: 0, p50: 0, p90: 0, p95: 0, p99: 0, max: 0 };
103
+ const sorted = [...values].sort((a, b) => a - b);
104
+ const pick = (p) => sorted[Math.min(sorted.length - 1, Math.floor((sorted.length - 1) * p))];
105
+ return {
106
+ min: sorted[0],
107
+ mean: sorted.reduce((sum, value) => sum + value, 0) / sorted.length,
108
+ p50: pick(0.5),
109
+ p90: pick(0.9),
110
+ p95: pick(0.95),
111
+ p99: pick(0.99),
112
+ max: sorted[sorted.length - 1]
113
+ };
114
+ }
115
+ var TelemetryController = class {
116
+ constructor(serviceId, options = {}) {
117
+ this.serviceId = serviceId;
118
+ this.mode = options.mode ?? "off";
119
+ this.maxSamples = Math.max(1, options.maxSamples ?? 2048);
120
+ this.maxRecentInvocations = Math.max(1, options.maxRecentInvocations ?? 100);
121
+ }
122
+ serviceId;
123
+ mode;
124
+ maxSamples;
125
+ maxRecentInvocations;
126
+ samples = [];
127
+ active = /* @__PURE__ */ new Map();
128
+ totalInvocationCount = 0;
129
+ totalSuccessCount = 0;
130
+ totalErrorCount = 0;
131
+ lastInvocationAt;
132
+ enable(mode = "standard") {
133
+ this.mode = mode;
134
+ }
135
+ disable() {
136
+ this.mode = "off";
137
+ this.active.clear();
138
+ }
139
+ setMode(mode) {
140
+ this.mode = mode;
141
+ if (mode === "off") this.active.clear();
142
+ }
143
+ getMode() {
144
+ return this.mode;
145
+ }
146
+ status() {
147
+ return {
148
+ enabled: this.mode !== "off",
149
+ mode: this.mode,
150
+ serviceId: this.serviceId,
151
+ invocationCount: this.totalInvocationCount,
152
+ activeInvocations: this.active.size,
153
+ lastInvocationAt: this.lastInvocationAt
154
+ };
155
+ }
156
+ begin(target, kind, correlationId, parentSpanId) {
157
+ if (this.mode === "off") {
158
+ return {
159
+ invocationId: "",
160
+ traceId: "",
161
+ spanId: "",
162
+ parentSpanId,
163
+ end: () => void 0
164
+ };
165
+ }
166
+ const invocationId = id("inv");
167
+ const spanId = id("span");
168
+ const traceId = parentSpanId ? this.findTraceId(parentSpanId) ?? id("trace") : id("trace");
169
+ const active = {
170
+ invocationId,
171
+ traceId,
172
+ spanId,
173
+ parentSpanId,
174
+ serviceId: this.serviceId,
175
+ target,
176
+ kind,
177
+ correlationId,
178
+ startedAt: telemetryNow(),
179
+ resourcesStart: this.mode === "standard" ? void 0 : sampleResources()
180
+ };
181
+ this.active.set(invocationId, active);
182
+ return {
183
+ invocationId,
184
+ traceId,
185
+ spanId,
186
+ parentSpanId,
187
+ end: (error) => this.finish(active, error)
188
+ };
189
+ }
190
+ reset() {
191
+ this.samples.length = 0;
192
+ this.active.clear();
193
+ this.totalInvocationCount = 0;
194
+ this.totalSuccessCount = 0;
195
+ this.totalErrorCount = 0;
196
+ this.lastInvocationAt = void 0;
197
+ }
198
+ snapshot() {
199
+ const invocations = this.samples.slice();
200
+ const durations = invocations.map((item) => item.durationMs);
201
+ const targetMap = /* @__PURE__ */ new Map();
202
+ for (const invocation of invocations) {
203
+ const key = `${invocation.kind}:${invocation.target}`;
204
+ const group = targetMap.get(key) ?? [];
205
+ group.push(invocation);
206
+ targetMap.set(key, group);
207
+ }
208
+ const targets = [...targetMap.values()].map((group) => ({
209
+ target: group[0].target,
210
+ kind: group[0].kind,
211
+ count: group.length,
212
+ successCount: group.filter((item) => item.status === "completed").length,
213
+ errorCount: group.filter((item) => item.status === "failed").length,
214
+ durationMs: percentiles(group.map((item) => item.durationMs)),
215
+ lastInvocationAt: group[group.length - 1]?.completedAt
216
+ }));
217
+ return {
218
+ serviceId: this.serviceId,
219
+ mode: this.mode,
220
+ capturedAt: Date.now(),
221
+ status: this.status(),
222
+ totals: {
223
+ invocationCount: this.totalInvocationCount,
224
+ successCount: this.totalSuccessCount,
225
+ errorCount: this.totalErrorCount,
226
+ durationMs: percentiles(durations)
227
+ },
228
+ targets,
229
+ activeInvocations: this.active.size,
230
+ recentInvocations: invocations.slice(-this.maxRecentInvocations)
231
+ };
232
+ }
233
+ functionality(name) {
234
+ return this.snapshot().targets.find((target) => target.kind === "functionality" && target.target === name);
235
+ }
236
+ functionalities() {
237
+ return this.snapshot().targets.filter((target) => target.kind === "functionality");
238
+ }
239
+ findTraceId(parentSpanId) {
240
+ for (let index = this.samples.length - 1; index >= 0; index -= 1) {
241
+ if (this.samples[index].spanId === parentSpanId) return this.samples[index].traceId;
242
+ }
243
+ for (const active of this.active.values()) {
244
+ if (active.spanId === parentSpanId) return active.traceId;
245
+ }
246
+ return void 0;
247
+ }
248
+ finish(active, error) {
249
+ if (!this.active.delete(active.invocationId)) return;
250
+ const completedAt = telemetryNow();
251
+ const resourcesEnd = this.mode === "standard" ? void 0 : sampleResources();
252
+ const invocation = {
253
+ invocationId: active.invocationId,
254
+ traceId: active.traceId,
255
+ spanId: active.spanId,
256
+ parentSpanId: active.parentSpanId,
257
+ serviceId: active.serviceId,
258
+ target: active.target,
259
+ kind: active.kind,
260
+ correlationId: active.correlationId,
261
+ startedAt: active.startedAt,
262
+ completedAt,
263
+ durationMs: Math.max(0, completedAt - active.startedAt),
264
+ status: error === void 0 ? "completed" : "failed",
265
+ error: error === void 0 ? void 0 : {
266
+ name: error instanceof Error ? error.name : "Error",
267
+ message: error instanceof Error ? error.message : String(error)
268
+ },
269
+ resources: active.resourcesStart && resourcesEnd ? { start: active.resourcesStart, end: resourcesEnd, delta: deltaResources(active.resourcesStart, resourcesEnd) } : void 0
270
+ };
271
+ this.samples.push(invocation);
272
+ this.totalInvocationCount += 1;
273
+ if (invocation.status === "completed") this.totalSuccessCount += 1;
274
+ else this.totalErrorCount += 1;
275
+ if (this.samples.length > this.maxSamples) this.samples.splice(0, this.samples.length - this.maxSamples);
276
+ this.lastInvocationAt = Date.now();
277
+ }
278
+ };
279
+ var ServiceInstance = class {
280
+ constructor(definition) {
281
+ this.definition = definition;
282
+ this.id = definition.id;
283
+ this.name = definition.name;
284
+ this.version = definition.version;
285
+ this.telemetry = new TelemetryController(this.id);
286
+ this.lifecycle = new LifecycleManager();
287
+ if (definition.state) {
288
+ this.stateStore = new ServiceStateStore(definition.state.initial);
289
+ }
290
+ }
291
+ definition;
292
+ id;
293
+ name;
294
+ version;
295
+ telemetry;
296
+ stateStore;
297
+ lifecycle;
298
+ initialized = false;
299
+ disposed = false;
300
+ getDefinition() {
301
+ return this.definition;
302
+ }
303
+ getStatus() {
304
+ return this.lifecycle.getStatus();
305
+ }
306
+ async start() {
307
+ if (this.disposed) throw new Error("[Service:" + this.name + "] Cannot start a disposed service.");
308
+ const current = this.lifecycle.getStatus();
309
+ if (current === "running") return;
310
+ if (current === "initializing" || current === "starting" || current === "stopping") {
311
+ throw new Error("[Service:" + this.name + "] Cannot start while status is '" + current + "'.");
312
+ }
313
+ if (!this.initialized) {
314
+ this.lifecycle.transitionTo("initializing");
315
+ try {
316
+ await this.definition.lifecycle?.onInit?.();
317
+ this.initialized = true;
318
+ this.lifecycle.transitionTo("ready");
319
+ } catch (error) {
320
+ this.lifecycle.transitionTo("uninitialized");
321
+ throw error;
322
+ }
323
+ }
324
+ this.lifecycle.transitionTo("starting");
325
+ try {
326
+ await this.definition.lifecycle?.onStart?.();
327
+ this.lifecycle.transitionTo("running");
328
+ } catch (error) {
329
+ this.lifecycle.transitionTo("ready");
330
+ throw error;
331
+ }
332
+ }
333
+ async stop() {
334
+ const current = this.lifecycle.getStatus();
335
+ if (current === "stopped") return;
336
+ if (current !== "running") {
337
+ throw new Error("[Service:" + this.name + "] Cannot stop while status is '" + current + "'.");
338
+ }
339
+ this.lifecycle.transitionTo("stopping");
340
+ try {
341
+ await this.definition.lifecycle?.onStop?.();
342
+ this.lifecycle.transitionTo("stopped");
343
+ } catch (error) {
344
+ this.lifecycle.transitionTo("running");
345
+ throw error;
346
+ }
347
+ }
348
+ async dispose() {
349
+ if (this.disposed) return;
350
+ if (this.lifecycle.getStatus() === "running") await this.stop();
351
+ await this.definition.lifecycle?.onDispose?.();
352
+ this.disposed = true;
353
+ }
354
+ async call(op, input, ctx = {}) {
355
+ this.lifecycle.assertRunning(this.name);
356
+ const operation = this.definition.operations[op];
357
+ if (!operation) {
358
+ throw new Error("[Service:" + this.name + "] Operation '" + op + "' not found.");
359
+ }
360
+ if (ctx.metadata?.__krnlTelemetryInternal === true) {
361
+ return await operation.handler(input, ctx);
362
+ }
363
+ const parentSpanId = typeof ctx.metadata?.__krnlTelemetryParentSpanId === "string" ? ctx.metadata.__krnlTelemetryParentSpanId : void 0;
364
+ const handle = this.telemetry.begin(op, "service", ctx.correlationId, parentSpanId);
365
+ try {
366
+ const output = await operation.handler(input, ctx);
367
+ handle.end();
368
+ return output;
369
+ } catch (error) {
370
+ handle.end(error);
371
+ throw error;
372
+ }
373
+ }
374
+ getState() {
375
+ return this.stateStore?.getState() ?? Object.freeze({});
376
+ }
377
+ setState(mutation) {
378
+ if (!this.stateStore) {
379
+ this.stateStore = new ServiceStateStore({ ...mutation });
380
+ return;
381
+ }
382
+ this.stateStore.setState(mutation);
383
+ }
384
+ };
385
+ var ServiceProxy = class {
386
+ constructor(definition, adapter, endpoint) {
387
+ this.definition = definition;
388
+ this.adapter = adapter;
389
+ this.endpoint = endpoint;
390
+ if (!definition) {
391
+ throw new Error("[ServiceProxy] Missing service definition.");
392
+ }
393
+ if (!adapter || typeof adapter.send !== "function") {
394
+ throw new Error("[ServiceProxy:" + (definition.name || "unknown") + "] Missing or invalid protocol adapter.");
395
+ }
396
+ if (!endpoint || typeof endpoint.address !== "string" || endpoint.address.length === 0) {
397
+ throw new Error("[ServiceProxy:" + (definition.name || "unknown") + "] Missing or invalid endpoint descriptor.");
398
+ }
399
+ this.id = definition.id;
400
+ this.name = definition.name;
401
+ this.version = definition.version;
402
+ this.telemetry = new TelemetryController(this.id);
403
+ this.stateCache = { ...definition.state?.initial ?? {} };
404
+ }
405
+ definition;
406
+ adapter;
407
+ endpoint;
408
+ id;
409
+ name;
410
+ version;
411
+ telemetry;
412
+ stateCache;
413
+ eventHandlers = /* @__PURE__ */ new Map();
414
+ lifecycle = new LifecycleManager();
415
+ disposed = false;
416
+ getDefinition() {
417
+ return this.definition;
418
+ }
419
+ getStatus() {
420
+ return this.lifecycle.getStatus();
421
+ }
422
+ async start() {
423
+ if (this.disposed) {
424
+ throw new Error("[ServiceProxy:" + this.name + "] Cannot start a disposed service proxy.");
425
+ }
426
+ const status = this.lifecycle.getStatus();
427
+ if (status === "running") return;
428
+ if (status === "stopping" || status === "starting" || status === "initializing") {
429
+ throw new Error("[ServiceProxy:" + this.name + "] Cannot start while status is '" + status + "'.");
430
+ }
431
+ if (status === "uninitialized") {
432
+ this.lifecycle.transitionTo("initializing");
433
+ this.lifecycle.transitionTo("ready");
434
+ }
435
+ this.lifecycle.transitionTo("starting");
436
+ this.lifecycle.transitionTo("running");
437
+ }
438
+ async stop() {
439
+ const status = this.lifecycle.getStatus();
440
+ if (status === "stopped") return;
441
+ if (status !== "running") {
442
+ throw new Error("[ServiceProxy:" + this.name + "] Cannot stop while status is '" + status + "'.");
443
+ }
444
+ this.lifecycle.transitionTo("stopping");
445
+ this.lifecycle.transitionTo("stopped");
446
+ }
447
+ async dispose() {
448
+ if (this.disposed) return;
449
+ if (this.lifecycle.getStatus() === "running") await this.stop();
450
+ this.disposed = true;
451
+ }
452
+ async call(op, input, ctx = {}) {
453
+ if (!this.definition.operations[op]) {
454
+ throw new Error("[ServiceProxy:" + this.name + "] Operation '" + op + "' not found.");
455
+ }
456
+ if (this.lifecycle.getStatus() !== "running") {
457
+ await this.start();
458
+ }
459
+ if (!this.adapter.send) {
460
+ throw new Error("[ServiceProxy:" + this.name + "] Adapter does not support send().");
461
+ }
462
+ const envelope = {
463
+ id: "req-" + Date.now() + "-" + Math.random().toString(36).slice(2, 7),
464
+ type: "request",
465
+ operation: op,
466
+ payload: input,
467
+ timestamp: Date.now()
468
+ };
469
+ const parentSpanId = typeof ctx.metadata?.__krnlTelemetryParentSpanId === "string" ? ctx.metadata.__krnlTelemetryParentSpanId : void 0;
470
+ const handle = this.telemetry.begin(op, "service", ctx.correlationId, parentSpanId);
471
+ try {
472
+ const response = await this.adapter.send(this.endpoint, envelope);
473
+ if (response.error) {
474
+ const error = new Error("[ServiceProxy:" + this.name + "] Remote error: " + response.error);
475
+ handle.end(error);
476
+ throw error;
477
+ }
478
+ handle.end();
479
+ return response.payload;
480
+ } catch (error) {
481
+ handle.end(error);
482
+ throw error;
483
+ }
484
+ }
485
+ getState() {
486
+ return Object.freeze({ ...this.stateCache });
487
+ }
488
+ setState(mutation) {
489
+ this.stateCache = { ...this.stateCache, ...mutation };
490
+ }
491
+ on(event, handler) {
492
+ if (!this.eventHandlers.has(event)) this.eventHandlers.set(event, /* @__PURE__ */ new Set());
493
+ const handlers = this.eventHandlers.get(event);
494
+ handlers.add(handler);
495
+ return () => handlers.delete(handler);
496
+ }
497
+ emit(event, payload) {
498
+ const handlers = this.eventHandlers.get(event);
499
+ if (!handlers) return;
500
+ for (const handler of Array.from(handlers)) {
501
+ try {
502
+ handler(payload);
503
+ } catch (error) {
504
+ console.error("[ServiceProxy:" + this.name + "] Event handler error for '" + event + "':", error);
505
+ }
506
+ }
507
+ }
508
+ };
509
+ function assertRecord(value, field) {
510
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
511
+ throw new Error("[KrnlTS] Invalid service definition: '" + field + "' must be an object.");
512
+ }
513
+ }
514
+ function assertNonEmptyString(value, field) {
515
+ if (typeof value !== "string" || value.trim().length === 0) {
516
+ throw new Error("[KrnlTS] Invalid service definition: '" + field + "' must be a non-empty string.");
517
+ }
518
+ }
519
+ function validateServiceDefinition(definition) {
520
+ if (!definition || typeof definition !== "object") {
521
+ throw new Error("[KrnlTS] Invalid service definition: expected an object.");
522
+ }
523
+ assertNonEmptyString(definition.id, "id");
524
+ assertNonEmptyString(definition.name, "name");
525
+ assertNonEmptyString(definition.version, "version");
526
+ if (!definition.operations || typeof definition.operations !== "object") {
527
+ throw new Error("[Service:" + definition.name + "] Invalid operations: expected an object.");
528
+ }
529
+ for (const [key, operation] of Object.entries(definition.operations)) {
530
+ if (!operation || typeof operation !== "object") {
531
+ throw new Error("[Service:" + definition.name + "] Invalid operation '" + key + "'.");
532
+ }
533
+ assertNonEmptyString(operation.id, "operations." + key + ".id");
534
+ assertNonEmptyString(operation.name, "operations." + key + ".name");
535
+ if (operation.inputSchema !== void 0) assertRecord(operation.inputSchema, "operations." + key + ".inputSchema");
536
+ if (operation.outputSchema !== void 0) assertRecord(operation.outputSchema, "operations." + key + ".outputSchema");
537
+ if (typeof operation.handler !== "function") {
538
+ throw new Error("[Service:" + definition.name + "] Operation '" + key + "' must define a handler.");
539
+ }
540
+ }
541
+ for (const [key, schema] of Object.entries(definition.inputs ?? {})) assertRecord(schema, "inputs." + key);
542
+ for (const [key, schema] of Object.entries(definition.outputs ?? {})) assertRecord(schema, "outputs." + key);
543
+ if (definition.state?.schema !== void 0) assertRecord(definition.state.schema, "state.schema");
544
+ for (const capability of definition.capabilities ?? []) {
545
+ assertNonEmptyString(capability.id, "capability.id");
546
+ assertNonEmptyString(capability.name, "capability.name");
547
+ if (!Array.isArray(capability.protocols)) {
548
+ throw new Error("[Service:" + definition.name + "] Capability '" + capability.name + "' protocols must be an array.");
549
+ }
550
+ }
551
+ for (const dependency of definition.dependencies ?? []) {
552
+ assertNonEmptyString(dependency.serviceId, "dependency.serviceId");
553
+ }
554
+ return definition;
555
+ }
556
+ function createServiceDefinition(definition) {
557
+ return validateServiceDefinition(definition);
558
+ }
559
+ function createService(definition) {
560
+ return new ServiceInstance(validateServiceDefinition(definition));
561
+ }
562
+ function createServiceProxy(definition, adapter, endpoint) {
563
+ validateServiceDefinition(definition);
564
+ if (!adapter || typeof adapter.send !== "function") {
565
+ throw new Error("[ServiceProxy:" + definition.name + "] Adapter must implement send().");
566
+ }
567
+ if (!endpoint || typeof endpoint.address !== "string" || endpoint.address.length === 0) {
568
+ throw new Error("[ServiceProxy:" + definition.name + "] Endpoint must have an address.");
569
+ }
570
+ return new ServiceProxy(definition, adapter, endpoint);
571
+ }
572
+ var asyncHooks = globalThis.process?.getBuiltinModule?.("node:async_hooks");
573
+
574
+ export {
575
+ TelemetryController,
576
+ createServiceDefinition,
577
+ createService,
578
+ createServiceProxy
579
+ };
@@ -14,7 +14,6 @@ import {
14
14
  WebSocketTransport,
15
15
  createBackendClient
16
16
  } from "../chunk-NIP22V2G.js";
17
- import "../chunk-QGM4M3NI.js";
18
17
  export {
19
18
  BackendClient,
20
19
  BackendProvider,
@@ -22,7 +22,6 @@ import {
22
22
  WebSocketTransport,
23
23
  createBackendClient
24
24
  } from "../chunk-NIP22V2G.js";
25
- import "../chunk-QGM4M3NI.js";
26
25
  export {
27
26
  BackendClient,
28
27
  BackendRegistry,
@@ -1,5 +1,5 @@
1
1
  import { SkipoBase } from '@ultrst-armada/kloks/functions';
2
- import { B as BaseAccountProvider } from '../BaseAccountProvider-DduKf5HG.js';
2
+ import { LuthAuthClient } from '@dinilmusick/gutts';
3
3
 
4
4
  interface ClusterConfig {
5
5
  nodes: string[];
@@ -47,10 +47,10 @@ declare function resolveSystemDatabaseClusterNodes(env?: Record<string, string |
47
47
  }>;
48
48
 
49
49
  declare class ControlPlaneManager extends SkipoBase {
50
- auth: BaseAccountProvider;
50
+ auth: LuthAuthClient;
51
51
  audit: AuditLogger;
52
52
  cluster: DatabaseClusterManager;
53
- constructor(auth: BaseAccountProvider, audit: AuditLogger, cluster: DatabaseClusterManager);
53
+ constructor(auth: LuthAuthClient, audit: AuditLogger, cluster: DatabaseClusterManager);
54
54
  }
55
55
 
56
56
  export { type AuditEvent, AuditLogger, type ClusterConfig, ControlPlaneManager, DatabaseClusterManager, type HealthStatus, detectDatabaseEngine, getSystemDatabaseUrls, resolveSystemDatabaseClusterNodes };
@@ -6,7 +6,6 @@ import {
6
6
  getSystemDatabaseUrls,
7
7
  resolveSystemDatabaseClusterNodes
8
8
  } from "../chunk-RCCQ7IRM.js";
9
- import "../chunk-QGM4M3NI.js";
10
9
  export {
11
10
  AuditLogger,
12
11
  ControlPlaneManager,