@ultrst-armada/kloks 1.26.3 → 1.26.5
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/README.md +39 -0
- package/index.d.ts +16 -10
- package/index.js +3 -0
- package/package.json +60 -7
- package/packages/audio-midi/dist/{audioClipEngine-BOT33JKI.js → audioClipEngine-LKZRWTJ3.js} +2 -2
- package/packages/audio-midi/dist/{audioInputManager-BLDGGLAR.js → audioInputManager-5BNHLOJM.js} +1 -1
- package/packages/audio-midi/dist/{chunk-N55BWOC6.js → chunk-M4JFGTHE.js} +1 -1
- package/packages/audio-midi/dist/{chunk-3GRGELA4.js → chunk-OUOFTYHY.js} +50 -11
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Compressor/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Delay/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Equalizer/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Limiter/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/MultibandCompressor/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Reverb/manifest.json +7 -0
- package/packages/audio-midi/dist/engine/audio/entities/AudioEffects/functionalities/Saturation/manifest.json +7 -0
- package/packages/audio-midi/dist/index.d.ts +10 -1
- package/packages/audio-midi/dist/index.js +36 -20
- package/packages/audio-midi/package.json +8 -0
- package/packages/backend/dist/ai-models/index.js +2 -2
- package/packages/backend/dist/ai-routing/index.js +3 -3
- package/packages/backend/dist/api/BaseApiRoute.d.ts +1 -1
- package/packages/backend/dist/api/index.js +1 -1
- package/packages/backend/dist/auth/CanonicalAuthClient.d.ts +6 -6
- package/packages/backend/dist/auth/index.js +2 -1
- package/packages/backend/dist/chunk-2Y2EXYDK.js +0 -0
- package/packages/backend/dist/{chunk-3S2NSIFA.js → chunk-3FZSYSJC.js} +16 -10
- package/packages/backend/dist/chunk-5F5V7NAG.js +54 -0
- package/packages/backend/dist/{chunk-WAQDOIGQ.js → chunk-BVXGUHLZ.js} +1 -1
- package/packages/backend/dist/chunk-DAG2L4RN.js +0 -0
- package/packages/backend/dist/{chunk-KPZQUA7R.js → chunk-G7PPVOFP.js} +16 -53
- package/packages/backend/dist/{chunk-GKQ42CYW.js → chunk-H6ET362U.js} +3 -3
- package/packages/backend/dist/chunk-HUY4272L.js +69 -0
- package/packages/backend/dist/chunk-JQKKMUCT.js +0 -0
- package/packages/backend/dist/{chunk-PT6J6UEU.js → chunk-LMAU62ZG.js} +4 -4
- package/packages/backend/dist/{chunk-EDKCP5CQ.js → chunk-MZK362U4.js} +16 -16
- package/packages/backend/dist/{chunk-U4UI6KK4.js → chunk-NGEB3CF5.js} +3 -35
- package/packages/backend/dist/{chunk-3VWBZEMG.js → chunk-NTKUQVCQ.js} +4 -5
- package/packages/backend/dist/chunk-NY2SQOXI.js +34 -0
- package/packages/backend/dist/{chunk-JOTDEFRG.js → chunk-OXEP3AP6.js} +5 -4
- package/packages/backend/dist/chunk-RABSY2JU.js +0 -0
- package/packages/backend/dist/{chunk-GWCLYVJT.js → chunk-RFPGUJAZ.js} +9 -9
- package/packages/backend/dist/{chunk-TWCEVES2.js → chunk-WC6EPW3A.js} +1 -1
- package/packages/backend/dist/{chunk-FU6TYLI2.js → chunk-Y5ENDXU2.js} +72 -129
- package/packages/backend/dist/{chunk-EO5VUYYU.js → chunk-Y7ZE6D5H.js} +4 -4
- package/packages/backend/dist/{chunk-RCCQ7IRM.js → chunk-ZBNSK26X.js} +2 -2
- package/packages/backend/dist/control-plane/AuditLogger.d.ts +1 -1
- package/packages/backend/dist/control-plane/ControlPlaneManager.d.ts +1 -1
- package/packages/backend/dist/control-plane/index.js +1 -1
- package/packages/backend/dist/core/dynamicRouteResolver.d.ts +1 -1
- package/packages/backend/dist/core/routesCore.d.ts +1 -1
- package/packages/backend/dist/core/vercelTransformer.d.ts +1 -1
- package/packages/backend/dist/core/workspaceCore.d.ts +2 -2
- package/packages/backend/dist/data/BaseDataProvider.d.ts +1 -1
- package/packages/backend/dist/development/index.js +30 -17
- package/packages/backend/dist/development/playwrightInspectionService.js +1 -2
- package/packages/backend/dist/development/webContainerService.js +1 -2
- package/packages/backend/dist/index.d.ts +4 -24
- package/packages/backend/dist/index.js +12 -4655
- package/packages/backend/dist/krnl-ai-services.d.ts +9 -9
- package/packages/backend/dist/krnl-ai-services.js +5 -6
- package/packages/backend/dist/krnl-services.js +8 -7
- package/packages/backend/dist/node.d.ts +28 -0
- package/packages/backend/dist/node.js +4761 -0
- package/packages/backend/dist/resourceEngine/BaseResourceFetcher.d.ts +3 -3
- package/packages/backend/dist/resourceEngine/CloudflareResourceFetcher.d.ts +3 -3
- package/packages/backend/dist/resourceEngine/ResourceFetcherRegistry.d.ts +5 -5
- package/packages/backend/dist/resourceEngine/VercelResourceFetcher.d.ts +3 -3
- package/packages/backend/dist/resourceEngine/adapters/CloudflareResourceAdapter.d.ts +2 -2
- package/packages/backend/dist/resourceEngine/adapters/VercelResourceAdapter.d.ts +2 -2
- package/packages/backend/dist/resourceEngine/calculator/UniversalResourceCalculator.d.ts +1 -1
- package/packages/backend/dist/resourceEngine/calculator/types.d.ts +1 -1
- package/packages/backend/dist/resourceEngine/index.d.ts +6 -6
- package/packages/backend/dist/resourceEngine/types/depm/entities.d.ts +2 -2
- package/packages/backend/dist/resourceEngine/types.d.ts +1 -1
- package/packages/backend/dist/resourceEngine/weightEngine/helpers.d.ts +1 -1
- package/packages/backend/dist/resourceEngine/weightEngine/index.d.ts +2 -2
- package/packages/backend/dist/resourceEngine/weightEngine/weightEngine.d.ts +1 -1
- package/packages/backend/dist/resourceEngine/weightEngine.d.ts +1 -1
- package/packages/backend/dist/server/services/assetPoolService/assetPoolService.d.ts +3 -3
- package/packages/backend/dist/server/services/projectService/projectService.d.ts +3 -3
- package/packages/backend/dist/services/index.d.ts +2 -10
- package/packages/backend/dist/services/index.js +1 -37
- package/packages/backend/dist/services/node.d.ts +10 -0
- package/packages/backend/dist/services/node.js +38 -0
- package/packages/backend/dist/srkl/index.js +1 -1
- package/packages/backend/dist/storage/BaseStorageAdapter.d.ts +1 -1
- package/packages/backend/dist/storage/S3Adapter.d.ts +5 -0
- package/packages/backend/dist/storage/googleDriveSdk.d.ts +1 -7
- package/packages/backend/dist/storage/index.d.ts +1 -10
- package/packages/backend/dist/storage/index.js +5 -40
- package/packages/backend/dist/storage/node.d.ts +14 -0
- package/packages/backend/dist/storage/node.js +66 -0
- package/packages/backend/dist/workspace/WorkspaceCloneSyncEngine.d.ts +1 -1
- package/packages/backend/dist/workspace/index.d.ts +1 -5
- package/packages/backend/dist/workspace/index.js +4 -24
- package/packages/backend/dist/workspace/node.d.ts +8 -0
- package/packages/backend/dist/workspace/node.js +30 -0
- package/packages/backend/package.json +35 -3
- package/packages/functions/dist/base-DDYO-DzM.d.ts +64 -0
- package/packages/functions/dist/base.d.ts +1 -0
- package/packages/functions/dist/base.js +6 -0
- package/packages/functions/dist/chunk-6EHIZHO4.js +555 -0
- package/packages/functions/dist/chunk-Z4LM5TOJ.js +114 -0
- package/packages/functions/dist/index.d.ts +4 -373
- package/packages/functions/dist/index.js +53 -1693
- package/packages/functions/dist/node.d.ts +110 -0
- package/packages/functions/dist/node.js +442 -0
- package/packages/functions/dist/portable.d.ts +207 -0
- package/packages/functions/dist/portable.js +94 -0
- package/packages/functions/package.json +23 -1
- package/packages/{functions/dist/chunk-K6H7T3EP.js → services/dist/chunk-P54QSKOQ.js} +1 -3
- package/packages/{state-graph/dist/dist-es-TLPJYZTE.js → services/dist/dist-es-2P6LFFZL.js} +1 -1
- package/packages/{state-graph/dist/dist-es-5IACWOIO.js → services/dist/dist-es-OZCE67MW.js} +1 -1
- package/packages/services/dist/{dist-es-3DGJJFOU.js → dist-es-RUJB3ALN.js} +3 -3
- package/packages/{state-graph/dist/dist-es-QZ6GKMM7.js → services/dist/dist-es-SSJGP5AI.js} +4 -4
- package/packages/services/dist/{loadSso-M3ZIZDGO.js → loadSso-3PZYFUB7.js} +1 -1
- package/packages/{functions/dist/signin-YXALFRYB.js → services/dist/signin-WYPGSXHF.js} +1 -1
- package/packages/{state-graph/dist/sso-oidc-NXFKRL6O.js → services/dist/sso-oidc-PQMIMLJU.js} +1 -1
- package/packages/{state-graph/dist/sts-MICPT37B.js → services/dist/sts-Z7LR3AZH.js} +1 -1
- package/packages/state-graph/dist/browser.d.ts +8 -18
- package/packages/state-graph/dist/browser.js +334 -23
- package/packages/state-graph/dist/browser.test.d.ts +1 -0
- package/packages/state-graph/dist/{chunk-KG6QYS26.js → chunk-5KP74NMF.js} +80 -80
- package/packages/state-graph/dist/{chunk-4UVGXFEM.js → chunk-LVULR5M4.js} +1 -1
- package/packages/state-graph/dist/{chunk-S22PMERU.js → chunk-OXUDG6HE.js} +1 -1
- package/packages/state-graph/dist/{chunk-2CQQGFMF.js → chunk-UKTICGGV.js} +2616 -432
- package/packages/state-graph/dist/domain/index.js +2 -3
- package/packages/state-graph/dist/engine/AudioConcepts.d.ts +1 -1
- package/packages/state-graph/dist/engine/GraphConcepts.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/archetypes/audioArchetypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/archetypes/effectArchetypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/archetypes/primitiveArchetypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/archetypes/routingArchetypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/archetypes/triggerModuleArchetypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/assets/containerSprites.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/assets/effectSprites.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/assets/primitiveSprites.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/assets/routingSprites.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/canonicalIo/CanonicalAudioInputEndpoint.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/canonicalIo/CanonicalMidiInputEndpoint.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/canonicalIo/topLevelIoRegistry.d.ts +6 -6
- package/packages/state-graph/dist/engine/core/canonicalIo/types.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/graphDataService.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/hierarchy/index.d.ts +11 -11
- package/packages/state-graph/dist/engine/core/hierarchy/nodes/GraphNodeParent.d.ts +3 -3
- package/packages/state-graph/dist/engine/core/hierarchy/nodes/GraphNodeTypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/hierarchy/sockets/GraphSocketParent.d.ts +2 -2
- package/packages/state-graph/dist/engine/core/hierarchy/sockets/GraphSocketTypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/hierarchy/ui/UIElementBase.d.ts +3 -3
- package/packages/state-graph/dist/engine/core/hierarchy/wires/GraphWireParent.d.ts +2 -2
- package/packages/state-graph/dist/engine/core/hierarchy/wires/GraphWireTypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/nodeArchetypeRegistry.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/socketRegistry/containersSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/socketRegistry/customRegistry.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/socketRegistry/landmarksSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/socketRegistry/primitivesSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/socketRegistry/processorsSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/arrangementControlSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/audioSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/folderButtonSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/moduleSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/playbackSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/primitiveSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/routingSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/samplerSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/core/sockets/stripSockets.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/arrangementFactory.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/codeNodeParser/codeNodeParser.d.ts +2 -2
- package/packages/state-graph/dist/engine/functions/codeNodeParser/helpers.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/connection/portMatching.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/connection/signalCompatibility/helpers.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/connection/signalCompatibility/signalCompatibility.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/connection/signalCompatibility.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/connection/wireValidation.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/containerClipSync.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/containerFactory/containerFactory.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/effectLogic.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/graphManager/graphManager.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/graphManager.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/nodeFactory/nodeFactory.d.ts +8 -8
- package/packages/state-graph/dist/engine/functions/nodeFactory.d.ts +2 -2
- package/packages/state-graph/dist/engine/functions/signalTable/audioMidiSignals.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/signalTable/canonicalEffectsTable.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/signalTable/dataSignals.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/socketCompatibilitySpawner/helpers.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/socketCompatibilitySpawner/socketCompatibilitySpawner.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/socketCompatibilitySpawner.d.ts +1 -1
- package/packages/state-graph/dist/engine/functions/spawnNodeFactory.d.ts +1 -1
- package/packages/state-graph/dist/engine/predictive/predictiveGraphEngine/helpers.d.ts +1 -1
- package/packages/state-graph/dist/engine/predictive/predictiveGraphEngine.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/auth.d.ts +1 -1
- package/packages/state-graph/dist/engine/types/hardwareBus.d.ts +1 -1
- package/packages/state-graph/dist/engine/types/legacyTypes.d.ts +1 -1
- package/packages/state-graph/dist/engine/types/nodesArrangement.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/nodesAudio.d.ts +5 -5
- package/packages/state-graph/dist/engine/types/nodesControl.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/nodesPlayback.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/nodesPrimitives.d.ts +6 -6
- package/packages/state-graph/dist/engine/types/nodesRouting.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/sceneData.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/sceneState.d.ts +4 -4
- package/packages/state-graph/dist/engine/types/signals.d.ts +2 -2
- package/packages/state-graph/dist/engine/types/stripsTypes.d.ts +2 -2
- package/packages/state-graph/dist/index.js +110 -2850
- package/packages/state-graph/dist/rules/index.js +0 -1
- package/packages/state-graph/dist/spatial/index.js +0 -1
- package/packages/state-graph/dist/state/index.js +0 -1
- package/packages/state-graph/dist/store/CommandApi.d.ts +2 -2
- package/packages/state-graph/dist/store/index.js +2 -3
- package/packages/state-graph/package.json +7 -2
- package/scripts/normalize-package-declarations.mjs +63 -0
- package/packages/backend/dist/chunk-SXDYW3QA.js +0 -579
- package/packages/functions/dist/bowser-F6LIZBYW.js +0 -2821
- package/packages/functions/dist/chunk-34KJBG4F.js +0 -357
- package/packages/functions/dist/chunk-EAQYK3U2.js +0 -41
- package/packages/functions/dist/chunk-IOAPEUC7.js +0 -3424
- package/packages/functions/dist/chunk-J64ZDIIX.js +0 -2753
- package/packages/functions/dist/chunk-N3MSTUJN.js +0 -4785
- package/packages/functions/dist/chunk-VP26OHBN.js +0 -480
- package/packages/functions/dist/chunk-VRLVLNLG.js +0 -1727
- package/packages/functions/dist/dist-TKZ5TDRN.js +0 -1124
- package/packages/functions/dist/dist-W7ZJS3LZ.js +0 -899
- package/packages/functions/dist/dist-es-3DGJJFOU.js +0 -338
- package/packages/functions/dist/dist-es-5IACWOIO.js +0 -69
- package/packages/functions/dist/dist-es-BWLDIBIA.js +0 -47
- package/packages/functions/dist/dist-es-DO3F4OBN.js +0 -377
- package/packages/functions/dist/dist-es-NN7AKU7P.js +0 -175
- package/packages/functions/dist/dist-es-QZ6GKMM7.js +0 -220
- package/packages/functions/dist/dist-es-R3VEGXOP.js +0 -87
- package/packages/functions/dist/dist-es-TLPJYZTE.js +0 -294
- package/packages/functions/dist/event-streams-DRE6QVD6.js +0 -940
- package/packages/functions/dist/loadSso-M3ZIZDGO.js +0 -586
- package/packages/functions/dist/multipart-parser-YYFFJ4QD.js +0 -371
- package/packages/functions/dist/src-2QCYQXYH.js +0 -1396
- package/packages/functions/dist/sso-oidc-NXFKRL6O.js +0 -847
- package/packages/functions/dist/sts-MICPT37B.js +0 -1253
- package/packages/functions/dist/transformers.node-R6VHTGC2.js +0 -43879
- package/packages/services/dist/chunk-K6H7T3EP.js +0 -1991
- package/packages/services/dist/dist-es-5IACWOIO.js +0 -69
- package/packages/services/dist/dist-es-QZ6GKMM7.js +0 -220
- package/packages/services/dist/dist-es-TLPJYZTE.js +0 -294
- package/packages/services/dist/signin-YXALFRYB.js +0 -831
- package/packages/services/dist/sso-oidc-NXFKRL6O.js +0 -847
- package/packages/services/dist/sts-MICPT37B.js +0 -1253
- package/packages/state-graph/dist/bowser-F6LIZBYW.js +0 -2821
- package/packages/state-graph/dist/chunk-34KJBG4F.js +0 -357
- package/packages/state-graph/dist/chunk-EAQYK3U2.js +0 -41
- package/packages/state-graph/dist/chunk-IOAPEUC7.js +0 -3424
- package/packages/state-graph/dist/chunk-J64ZDIIX.js +0 -2753
- package/packages/state-graph/dist/chunk-K6H7T3EP.js +0 -1991
- package/packages/state-graph/dist/chunk-N3MSTUJN.js +0 -4785
- package/packages/state-graph/dist/chunk-VP26OHBN.js +0 -480
- package/packages/state-graph/dist/chunk-VRLVLNLG.js +0 -1727
- package/packages/state-graph/dist/dist-TKZ5TDRN.js +0 -1124
- package/packages/state-graph/dist/dist-W7ZJS3LZ.js +0 -899
- package/packages/state-graph/dist/dist-es-3DGJJFOU.js +0 -338
- package/packages/state-graph/dist/dist-es-BWLDIBIA.js +0 -47
- package/packages/state-graph/dist/dist-es-DO3F4OBN.js +0 -377
- package/packages/state-graph/dist/dist-es-NN7AKU7P.js +0 -175
- package/packages/state-graph/dist/dist-es-R3VEGXOP.js +0 -87
- package/packages/state-graph/dist/event-streams-DRE6QVD6.js +0 -940
- package/packages/state-graph/dist/loadSso-M3ZIZDGO.js +0 -586
- package/packages/state-graph/dist/multipart-parser-YYFFJ4QD.js +0 -371
- package/packages/state-graph/dist/signin-YXALFRYB.js +0 -831
- package/packages/state-graph/dist/src-2QCYQXYH.js +0 -1396
- package/packages/state-graph/dist/transformers.node-R6VHTGC2.js +0 -43879
- package/packages/backend/dist/{chunk-LMWXONZG.js → chunk-EREYT3WJ.js} +3 -3
|
@@ -1,579 +0,0 @@
|
|
|
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
|
-
};
|