@holoscript/core 6.0.4 → 7.0.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.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +3 -2
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/index.d.ts +501 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/tools/index.d.ts +22 -1
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +105 -57
- package/dist/GLTFPipeline-DEN36VNK.js +0 -12
- package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
- package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
- package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
- package/dist/USDZExporter-NTMBNTDB.js +0 -707
- package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2CWOLHTE.js +0 -69
- package/dist/chunk-33LSUQDD.cjs +0 -835
- package/dist/chunk-3FJCK5XA.js +0 -2232
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3SAK5KFL.cjs +0 -83
- package/dist/chunk-4XSNJCLC.cjs +0 -1859
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5BGSECRJ.cjs +0 -2237
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5O6TQC6M.cjs +0 -1871
- package/dist/chunk-5OEOHAAW.cjs +0 -682
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-5WUNN6ZN.cjs +0 -428
- package/dist/chunk-6TZPZCOJ.cjs +0 -1404
- package/dist/chunk-6UEHYZ7V.cjs +0 -773
- package/dist/chunk-6XSERL6L.js +0 -5678
- package/dist/chunk-72EQECGT.cjs +0 -908
- package/dist/chunk-7AGYRWKW.cjs +0 -507
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-A7PIMZGU.js +0 -263
- package/dist/chunk-ATSKSYVE.cjs +0 -51683
- package/dist/chunk-B5TCIAPQ.cjs +0 -117
- package/dist/chunk-BF2235SI.cjs +0 -5714
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BND3ST2K.cjs +0 -662
- package/dist/chunk-BU7VWW2K.js +0 -2522
- package/dist/chunk-BWFJEM5A.js +0 -5419
- package/dist/chunk-CAUCGUEA.cjs +0 -130
- package/dist/chunk-CBJSLA2E.cjs +0 -5423
- package/dist/chunk-CDPGV4DN.js +0 -114
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CS2EMTGF.js +0 -1966
- package/dist/chunk-DMG7C4H2.js +0 -975
- package/dist/chunk-DXJQDCFL.js +0 -468
- package/dist/chunk-E3FWRT3Z.js +0 -608
- package/dist/chunk-E3UALNFA.js +0 -421
- package/dist/chunk-EONILVMF.js +0 -762
- package/dist/chunk-EQV4R3EV.cjs +0 -769
- package/dist/chunk-F3HH56EB.cjs +0 -5538
- package/dist/chunk-F4IULT7N.js +0 -1488
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-FFKU7BTK.cjs +0 -1046
- package/dist/chunk-FHQVYCH2.js +0 -70
- package/dist/chunk-FSF7EQVA.cjs +0 -1974
- package/dist/chunk-G4VZTCIB.js +0 -659
- package/dist/chunk-G7CT3EMP.cjs +0 -1002
- package/dist/chunk-GGHSW2NN.js +0 -51334
- package/dist/chunk-GVUR45UF.cjs +0 -777
- package/dist/chunk-H5Z7NASB.js +0 -9662
- package/dist/chunk-HE7ULERA.cjs +0 -697
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HPS76H7Q.js +0 -309
- package/dist/chunk-HQUEA5R6.cjs +0 -424
- package/dist/chunk-HYNTS5CP.js +0 -422
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IBDG74G2.cjs +0 -1219
- package/dist/chunk-IFNQFCTM.js +0 -3098
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-IWI6J7FX.js +0 -421
- package/dist/chunk-K3JDKWGI.cjs +0 -270
- package/dist/chunk-K6EKD26I.js +0 -630
- package/dist/chunk-KCQ5NDYC.cjs +0 -3172
- package/dist/chunk-KED34ILP.js +0 -832
- package/dist/chunk-KSGXLT74.cjs +0 -457
- package/dist/chunk-L4G4RLXX.js +0 -767
- package/dist/chunk-LDP5OK6G.js +0 -1216
- package/dist/chunk-LGGRPKTV.cjs +0 -735
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-LSW7P7ML.js +0 -3675
- package/dist/chunk-LXJ4667L.cjs +0 -3874
- package/dist/chunk-LZ266PCM.cjs +0 -4499
- package/dist/chunk-MD6KDHVE.cjs +0 -237
- package/dist/chunk-MEASWI2Y.js +0 -126
- package/dist/chunk-MPXBVFHQ.js +0 -768
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUKG4SK.cjs +0 -3075
- package/dist/chunk-NDQNIJEH.js +0 -1715
- package/dist/chunk-NOZZ46QU.js +0 -168
- package/dist/chunk-OFKWH2IP.js +0 -449
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PMGODDJA.cjs +0 -319
- package/dist/chunk-Q4QX3AET.cjs +0 -1505
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-Q5JT3YML.cjs +0 -129
- package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
- package/dist/chunk-QGKNANZ3.js +0 -3071
- package/dist/chunk-QLEAOI3Q.cjs +0 -424
- package/dist/chunk-R7MA7QWV.js +0 -732
- package/dist/chunk-RVYPEYPX.js +0 -678
- package/dist/chunk-S2N5TNMA.js +0 -1855
- package/dist/chunk-S565K7NK.js +0 -752
- package/dist/chunk-SDAMZIRE.js +0 -765
- package/dist/chunk-T36DDXSF.js +0 -4250
- package/dist/chunk-T4NKMBDL.js +0 -5474
- package/dist/chunk-T7LEXZUZ.cjs +0 -2526
- package/dist/chunk-TEWCN33Y.js +0 -694
- package/dist/chunk-TQSZUOW5.cjs +0 -793
- package/dist/chunk-TSH3MSQU.cjs +0 -129
- package/dist/chunk-UERJ3YJV.js +0 -504
- package/dist/chunk-UPJBDCVF.js +0 -1395
- package/dist/chunk-V3NN3HPP.js +0 -4462
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-WB4Z63GG.js +0 -229
- package/dist/chunk-WDW67DZB.cjs +0 -9728
- package/dist/chunk-WGMEAYBG.js +0 -126
- package/dist/chunk-X4ZF6CNE.cjs +0 -473
- package/dist/chunk-X6SEAXAX.cjs +0 -3681
- package/dist/chunk-XCWFGZAA.js +0 -1043
- package/dist/chunk-XD6IYDUX.js +0 -903
- package/dist/chunk-XG23EUQX.cjs +0 -1717
- package/dist/chunk-XRKWN5PL.cjs +0 -173
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-XUTX5CBW.js +0 -126
- package/dist/chunk-XWPNTWDN.cjs +0 -755
- package/dist/chunk-XXINBTZK.cjs +0 -633
- package/dist/chunk-YCXFCXDS.js +0 -1868
- package/dist/chunk-YQK5JNFK.js +0 -3725
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-Z34RLXRA.cjs +0 -612
- package/dist/chunk-ZP4D3CSX.cjs +0 -72
- package/dist/cli/holoscript-runner.cjs +0 -2259
- package/dist/cli/holoscript-runner.js +0 -2234
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -28
- package/dist/compiler/agent-inference.js +0 -5
- package/dist/compiler/android-xr.cjs +0 -19
- package/dist/compiler/android-xr.js +0 -9
- package/dist/compiler/android.cjs +0 -20
- package/dist/compiler/android.js +0 -10
- package/dist/compiler/ar.cjs +0 -20
- package/dist/compiler/ar.js +0 -8
- package/dist/compiler/babylon.cjs +0 -17
- package/dist/compiler/babylon.js +0 -11
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -602
- package/dist/compiler/domain-block-utils.js +0 -8
- package/dist/compiler/dtdl.cjs +0 -24
- package/dist/compiler/dtdl.js +0 -8
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -15
- package/dist/compiler/godot.js +0 -9
- package/dist/compiler/incremental.cjs +0 -29
- package/dist/compiler/incremental.js +0 -4
- package/dist/compiler/index.cjs +0 -2578
- package/dist/compiler/index.js +0 -2383
- package/dist/compiler/ios.cjs +0 -20
- package/dist/compiler/ios.js +0 -10
- package/dist/compiler/multi-layer.cjs +0 -20
- package/dist/compiler/multi-layer.js +0 -11
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -15
- package/dist/compiler/openxr.js +0 -9
- package/dist/compiler/playcanvas.cjs +0 -16
- package/dist/compiler/playcanvas.js +0 -10
- package/dist/compiler/r3f.cjs +0 -34
- package/dist/compiler/r3f.js +0 -12
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -21
- package/dist/compiler/sdf.js +0 -9
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -17
- package/dist/compiler/state.js +0 -7
- package/dist/compiler/trait-composition.cjs +0 -26
- package/dist/compiler/trait-composition.js +0 -5
- package/dist/compiler/unity.cjs +0 -15
- package/dist/compiler/unity.js +0 -9
- package/dist/compiler/unreal.cjs +0 -19
- package/dist/compiler/unreal.js +0 -9
- package/dist/compiler/urdf.cjs +0 -45
- package/dist/compiler/urdf.js +0 -9
- package/dist/compiler/usd-physics.cjs +0 -23
- package/dist/compiler/usd-physics.js +0 -6
- package/dist/compiler/visionos.cjs +0 -15
- package/dist/compiler/visionos.js +0 -9
- package/dist/compiler/vrchat.cjs +0 -19
- package/dist/compiler/vrchat.js +0 -9
- package/dist/compiler/vrr.cjs +0 -21
- package/dist/compiler/vrr.js +0 -9
- package/dist/compiler/wasm.cjs +0 -33
- package/dist/compiler/wasm.js +0 -9
- package/dist/compiler/webgpu.cjs +0 -15
- package/dist/compiler/webgpu.js +0 -9
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -68
- package/dist/entries/scripting.js +0 -11
- package/dist/index.cjs +0 -40921
- package/dist/index.js +0 -37763
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
- package/dist/ml-dsa-WYLJHJO6.js +0 -1178
- package/dist/parser.cjs +0 -27
- package/dist/parser.js +0 -10
- package/dist/playwright-5OSAPTNH.js +0 -98660
- package/dist/playwright-RL6GY4F7.cjs +0 -98673
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14649
- package/dist/traits/index.js +0 -12243
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
package/dist/chunk-N5FTS757.cjs
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/interop/InteropBindingGenerator.ts
|
|
4
|
-
var InteropBindingGenerator = class {
|
|
5
|
-
/**
|
|
6
|
-
* Extract exports from a HoloScript AST
|
|
7
|
-
*/
|
|
8
|
-
extractExports(ast) {
|
|
9
|
-
const exports$1 = [];
|
|
10
|
-
if (!ast.body) return exports$1;
|
|
11
|
-
for (const node of ast.body) {
|
|
12
|
-
const nodeRecord = node;
|
|
13
|
-
const nodeType = nodeRecord.type;
|
|
14
|
-
const nodeName = nodeRecord.name;
|
|
15
|
-
if (nodeType === "FunctionDeclaration" || nodeType === "function") {
|
|
16
|
-
const params = nodeRecord.params || [];
|
|
17
|
-
exports$1.push({
|
|
18
|
-
name: nodeName || "anonymous",
|
|
19
|
-
type: "function",
|
|
20
|
-
parameters: params.map((p) => {
|
|
21
|
-
if (typeof p === "string") {
|
|
22
|
-
return { name: p, type: "any", optional: false };
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
name: p.name || "",
|
|
26
|
-
type: p.type || "any",
|
|
27
|
-
optional: p.optional || false
|
|
28
|
-
};
|
|
29
|
-
}),
|
|
30
|
-
returnType: nodeRecord.returnType || "void"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (nodeType === "template" || nodeType === "ClassDeclaration") {
|
|
34
|
-
exports$1.push({
|
|
35
|
-
name: nodeName || "UnnamedTemplate",
|
|
36
|
-
type: "class"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (nodeType === "composition") {
|
|
40
|
-
exports$1.push({
|
|
41
|
-
name: nodeName || "default",
|
|
42
|
-
type: "module"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
if (nodeType === "VariableDeclaration" || nodeType === "state") {
|
|
46
|
-
exports$1.push({
|
|
47
|
-
name: nodeName || "unnamed",
|
|
48
|
-
type: "constant",
|
|
49
|
-
value: nodeRecord.value
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return exports$1;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Generate Python bindings from HoloScript AST
|
|
57
|
-
*/
|
|
58
|
-
generatePythonBindings(ast, sourceFile) {
|
|
59
|
-
const exports$1 = this.extractExports(ast);
|
|
60
|
-
const lines = [
|
|
61
|
-
'"""',
|
|
62
|
-
`Auto-generated Python bindings for ${sourceFile}`,
|
|
63
|
-
`Generated by HoloScript InteropBindingGenerator`,
|
|
64
|
-
`Do not edit manually \u2014 regenerate with: holoscript compile ${sourceFile} --target python`,
|
|
65
|
-
'"""',
|
|
66
|
-
"",
|
|
67
|
-
"from typing import Any, Optional, Dict, List",
|
|
68
|
-
"import json",
|
|
69
|
-
""
|
|
70
|
-
];
|
|
71
|
-
for (const exp of exports$1) {
|
|
72
|
-
switch (exp.type) {
|
|
73
|
-
case "function": {
|
|
74
|
-
const params = (exp.parameters || []).map((p) => {
|
|
75
|
-
const pyType = this.tsPyType(p.type);
|
|
76
|
-
return p.optional ? `${p.name}: ${pyType} = None` : `${p.name}: ${pyType}`;
|
|
77
|
-
}).join(", ");
|
|
78
|
-
const retType = this.tsPyType(exp.returnType || "void");
|
|
79
|
-
lines.push(`def ${exp.name}(${params}) -> ${retType}:`);
|
|
80
|
-
lines.push(` """HoloScript function: ${exp.name}"""`);
|
|
81
|
-
lines.push(` raise NotImplementedError("Bridge to HoloScript runtime required")`);
|
|
82
|
-
lines.push("");
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case "class": {
|
|
86
|
-
lines.push(`class ${exp.name}:`);
|
|
87
|
-
lines.push(` """HoloScript template: ${exp.name}"""`);
|
|
88
|
-
lines.push(` def __init__(self, **kwargs: Any) -> None:`);
|
|
89
|
-
lines.push(` self._props = kwargs`);
|
|
90
|
-
lines.push("");
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
case "constant": {
|
|
94
|
-
lines.push(`${exp.name} = ${JSON.stringify(exp.value ?? "None")}`);
|
|
95
|
-
lines.push("");
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "module": {
|
|
99
|
-
lines.push(`class ${exp.name}Module:`);
|
|
100
|
-
lines.push(` """HoloScript composition: ${exp.name}"""`);
|
|
101
|
-
lines.push(` pass`);
|
|
102
|
-
lines.push("");
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
lines.push(`__all__ = [${exports$1.map((e) => `"${e.name}"`).join(", ")}]`);
|
|
108
|
-
return {
|
|
109
|
-
language: "python",
|
|
110
|
-
code: lines.join("\n"),
|
|
111
|
-
exports: exports$1.map((e) => e.name),
|
|
112
|
-
metadata: {
|
|
113
|
-
sourceFile,
|
|
114
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
115
|
-
holoScriptVersion: "5.0.0"
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Generate JavaScript (ESM) bindings from HoloScript AST
|
|
121
|
-
*/
|
|
122
|
-
generateJSBindings(ast, sourceFile) {
|
|
123
|
-
const exports$1 = this.extractExports(ast);
|
|
124
|
-
const lines = [
|
|
125
|
-
`// Auto-generated JS bindings for ${sourceFile}`,
|
|
126
|
-
`// Generated by HoloScript InteropBindingGenerator`,
|
|
127
|
-
`// Do not edit manually`,
|
|
128
|
-
""
|
|
129
|
-
];
|
|
130
|
-
for (const exp of exports$1) {
|
|
131
|
-
switch (exp.type) {
|
|
132
|
-
case "function": {
|
|
133
|
-
const params = (exp.parameters || []).map((p) => p.name).join(", ");
|
|
134
|
-
lines.push(`export function ${exp.name}(${params}) {`);
|
|
135
|
-
lines.push(` throw new Error("Bridge to HoloScript runtime required");`);
|
|
136
|
-
lines.push(`}`);
|
|
137
|
-
lines.push("");
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case "class": {
|
|
141
|
-
lines.push(`export class ${exp.name} {`);
|
|
142
|
-
lines.push(` constructor(props = {}) { this._props = props; }`);
|
|
143
|
-
lines.push(`}`);
|
|
144
|
-
lines.push("");
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
case "constant": {
|
|
148
|
-
lines.push(`export const ${exp.name} = ${JSON.stringify(exp.value ?? null)};`);
|
|
149
|
-
lines.push("");
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case "module": {
|
|
153
|
-
lines.push(`export const ${exp.name} = { /* HoloScript composition */ };`);
|
|
154
|
-
lines.push("");
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
language: "javascript",
|
|
161
|
-
code: lines.join("\n"),
|
|
162
|
-
exports: exports$1.map((e) => e.name),
|
|
163
|
-
metadata: {
|
|
164
|
-
sourceFile,
|
|
165
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
166
|
-
holoScriptVersion: "5.0.0"
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Map TypeScript types to Python types
|
|
172
|
-
*/
|
|
173
|
-
tsPyType(tsType) {
|
|
174
|
-
const mapping = {
|
|
175
|
-
string: "str",
|
|
176
|
-
number: "float",
|
|
177
|
-
int: "int",
|
|
178
|
-
boolean: "bool",
|
|
179
|
-
void: "None",
|
|
180
|
-
any: "Any",
|
|
181
|
-
unknown: "Any",
|
|
182
|
-
"string[]": "List[str]",
|
|
183
|
-
"number[]": "List[float]"
|
|
184
|
-
};
|
|
185
|
-
return mapping[tsType] || "Any";
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// src/resilience/ResiliencePatterns.ts
|
|
190
|
-
var CircuitBreakerState = /* @__PURE__ */ ((CircuitBreakerState2) => {
|
|
191
|
-
CircuitBreakerState2["CLOSED"] = "CLOSED";
|
|
192
|
-
CircuitBreakerState2["OPEN"] = "OPEN";
|
|
193
|
-
CircuitBreakerState2["HALF_OPEN"] = "HALF_OPEN";
|
|
194
|
-
return CircuitBreakerState2;
|
|
195
|
-
})(CircuitBreakerState || {});
|
|
196
|
-
var CircuitBreaker = class {
|
|
197
|
-
constructor(config = {}) {
|
|
198
|
-
this.state = "CLOSED" /* CLOSED */;
|
|
199
|
-
this.failureCount = 0;
|
|
200
|
-
this.successCount = 0;
|
|
201
|
-
this.lastFailureTime = null;
|
|
202
|
-
this.failures = [];
|
|
203
|
-
this.config = {
|
|
204
|
-
failureThreshold: 5,
|
|
205
|
-
successThreshold: 2,
|
|
206
|
-
resetTimeoutMs: 6e4,
|
|
207
|
-
// 1 minute
|
|
208
|
-
windowMs: 3e4,
|
|
209
|
-
// 30 seconds
|
|
210
|
-
isRetryable: (err) => err instanceof Error,
|
|
211
|
-
...config
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Execute function with circuit breaker protection
|
|
216
|
-
*/
|
|
217
|
-
async execute(fn) {
|
|
218
|
-
if (this.state === "OPEN" /* OPEN */) {
|
|
219
|
-
if (Date.now() - (this.lastFailureTime || 0) > this.config.resetTimeoutMs) {
|
|
220
|
-
this.state = "HALF_OPEN" /* HALF_OPEN */;
|
|
221
|
-
this.successCount = 0;
|
|
222
|
-
} else {
|
|
223
|
-
throw new Error(`Circuit breaker is OPEN. Retry after ${this.config.resetTimeoutMs}ms`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
const result = await fn();
|
|
228
|
-
this.onSuccess();
|
|
229
|
-
return result;
|
|
230
|
-
} catch (error) {
|
|
231
|
-
this.onFailure(error);
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
onSuccess() {
|
|
236
|
-
this.failureCount = 0;
|
|
237
|
-
this.failures = this.failures.filter((f) => Date.now() - f.timestamp < this.config.windowMs);
|
|
238
|
-
if (this.state === "HALF_OPEN" /* HALF_OPEN */) {
|
|
239
|
-
this.successCount++;
|
|
240
|
-
if (this.successCount >= this.config.successThreshold) {
|
|
241
|
-
this.state = "CLOSED" /* CLOSED */;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
onFailure(error) {
|
|
246
|
-
this.lastFailureTime = Date.now();
|
|
247
|
-
this.failureCount++;
|
|
248
|
-
this.failures.push({ timestamp: Date.now(), error });
|
|
249
|
-
this.failures = this.failures.filter((f) => Date.now() - f.timestamp < this.config.windowMs);
|
|
250
|
-
if (this.state === "HALF_OPEN" /* HALF_OPEN */) {
|
|
251
|
-
this.state = "OPEN" /* OPEN */;
|
|
252
|
-
} else if (this.failureCount >= this.config.failureThreshold) {
|
|
253
|
-
this.state = "OPEN" /* OPEN */;
|
|
254
|
-
console.error(`Circuit breaker OPEN after ${this.failureCount} failures: ${error.message}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
get currentState() {
|
|
258
|
-
return this.state;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Get current circuit breaker state (accessor method)
|
|
262
|
-
*/
|
|
263
|
-
getState() {
|
|
264
|
-
if (this.state === "OPEN" /* OPEN */ && Date.now() - (this.lastFailureTime || 0) > this.config.resetTimeoutMs) {
|
|
265
|
-
return "HALF_OPEN" /* HALF_OPEN */;
|
|
266
|
-
}
|
|
267
|
-
return this.state;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Get circuit breaker metrics
|
|
271
|
-
*/
|
|
272
|
-
getMetrics() {
|
|
273
|
-
return {
|
|
274
|
-
state: this.state,
|
|
275
|
-
totalFailures: this.failureCount,
|
|
276
|
-
totalSuccesses: this.successCount,
|
|
277
|
-
lastFailureTime: this.lastFailureTime,
|
|
278
|
-
totalRequests: this.failureCount + this.successCount
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
async function retryWithBackoff(fn, config = {}) {
|
|
283
|
-
const cfg = {
|
|
284
|
-
maxAttempts: 3,
|
|
285
|
-
initialBackoffMs: 100,
|
|
286
|
-
maxBackoffMs: 1e4,
|
|
287
|
-
multiplier: 2,
|
|
288
|
-
jitter: true,
|
|
289
|
-
isRetryable: (err, attempt) => attempt < cfg.maxAttempts,
|
|
290
|
-
...config
|
|
291
|
-
};
|
|
292
|
-
let lastError = null;
|
|
293
|
-
for (let attempt = 1; attempt <= cfg.maxAttempts; attempt++) {
|
|
294
|
-
try {
|
|
295
|
-
return await fn();
|
|
296
|
-
} catch (error) {
|
|
297
|
-
lastError = error;
|
|
298
|
-
if (!cfg.isRetryable(lastError, attempt)) {
|
|
299
|
-
throw lastError;
|
|
300
|
-
}
|
|
301
|
-
if (attempt < cfg.maxAttempts) {
|
|
302
|
-
const backoff = Math.min(
|
|
303
|
-
cfg.initialBackoffMs * Math.pow(cfg.multiplier, attempt - 1),
|
|
304
|
-
cfg.maxBackoffMs
|
|
305
|
-
);
|
|
306
|
-
const jitteredBackoff = cfg.jitter ? backoff * (0.5 + Math.random() * 0.5) : backoff;
|
|
307
|
-
console.warn(
|
|
308
|
-
`Attempt ${attempt} failed: ${lastError.message}. Retrying in ${Math.round(jitteredBackoff)}ms`
|
|
309
|
-
);
|
|
310
|
-
await sleep(jitteredBackoff);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
throw lastError || new Error("Max retry attempts exceeded");
|
|
315
|
-
}
|
|
316
|
-
function sleep(ms) {
|
|
317
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
318
|
-
}
|
|
319
|
-
async function withTimeout(promise, timeoutMs) {
|
|
320
|
-
return Promise.race([
|
|
321
|
-
promise,
|
|
322
|
-
new Promise(
|
|
323
|
-
(_, reject) => setTimeout(() => reject(new Error(`Operation timeout after ${timeoutMs}ms`)), timeoutMs)
|
|
324
|
-
)
|
|
325
|
-
]);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// src/mcp/MCPCircuitBreaker.ts
|
|
329
|
-
var MCPCircuitBreaker = class {
|
|
330
|
-
constructor(config = {}) {
|
|
331
|
-
this.breaker = new CircuitBreaker({
|
|
332
|
-
failureThreshold: config.failureThreshold ?? 5,
|
|
333
|
-
successThreshold: config.successThreshold ?? 2,
|
|
334
|
-
resetTimeoutMs: config.resetTimeoutMs ?? 3e4,
|
|
335
|
-
windowMs: config.windowMs ?? 6e4
|
|
336
|
-
});
|
|
337
|
-
this.baseUrl = config.baseUrl ?? "http://localhost:3000";
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Call an MCP tool with circuit breaker protection + retry + timeout
|
|
341
|
-
*/
|
|
342
|
-
async callTool(tool, args, timeoutMs = 15e3) {
|
|
343
|
-
try {
|
|
344
|
-
const result = await this.breaker.execute(async () => {
|
|
345
|
-
return retryWithBackoff(
|
|
346
|
-
async () => {
|
|
347
|
-
const response = await withTimeout(
|
|
348
|
-
fetch(`${this.baseUrl}/api/mcp/tools/${tool}`, {
|
|
349
|
-
method: "POST",
|
|
350
|
-
headers: { "Content-Type": "application/json" },
|
|
351
|
-
body: JSON.stringify({ arguments: args })
|
|
352
|
-
}),
|
|
353
|
-
timeoutMs
|
|
354
|
-
);
|
|
355
|
-
if (!response.ok) {
|
|
356
|
-
throw new Error(`MCP tool ${tool} failed: ${response.status} ${response.statusText}`);
|
|
357
|
-
}
|
|
358
|
-
return response.json();
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
maxAttempts: 2,
|
|
362
|
-
initialBackoffMs: 500,
|
|
363
|
-
maxBackoffMs: 3e3
|
|
364
|
-
}
|
|
365
|
-
);
|
|
366
|
-
});
|
|
367
|
-
return {
|
|
368
|
-
success: true,
|
|
369
|
-
content: result,
|
|
370
|
-
circuitState: this.breaker.getState()
|
|
371
|
-
};
|
|
372
|
-
} catch (error) {
|
|
373
|
-
return {
|
|
374
|
-
success: false,
|
|
375
|
-
error: error instanceof Error ? error.message : String(error),
|
|
376
|
-
circuitState: this.breaker.getState()
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Get current circuit breaker state
|
|
382
|
-
*/
|
|
383
|
-
getState() {
|
|
384
|
-
return this.breaker.getState();
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Get circuit breaker metrics
|
|
388
|
-
*/
|
|
389
|
-
getMetrics() {
|
|
390
|
-
return this.breaker.getMetrics();
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Check if MCP server is available (circuit not open)
|
|
394
|
-
*/
|
|
395
|
-
isAvailable() {
|
|
396
|
-
return this.breaker.getState() !== "OPEN" /* OPEN */;
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var defaultInstance = null;
|
|
400
|
-
function getMCPCircuitBreaker(config) {
|
|
401
|
-
if (!defaultInstance) {
|
|
402
|
-
defaultInstance = new MCPCircuitBreaker(config);
|
|
403
|
-
}
|
|
404
|
-
return defaultInstance;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
exports.CircuitBreaker = CircuitBreaker;
|
|
408
|
-
exports.CircuitBreakerState = CircuitBreakerState;
|
|
409
|
-
exports.InteropBindingGenerator = InteropBindingGenerator;
|
|
410
|
-
exports.MCPCircuitBreaker = MCPCircuitBreaker;
|
|
411
|
-
exports.getMCPCircuitBreaker = getMCPCircuitBreaker;
|
|
412
|
-
exports.retryWithBackoff = retryWithBackoff;
|
|
413
|
-
exports.withTimeout = withTimeout;
|
|
414
|
-
//# sourceMappingURL=chunk-N5FTS757.cjs.map
|
|
415
|
-
//# sourceMappingURL=chunk-N5FTS757.cjs.map
|