@tradejs/core 3.1.28-beta.258 → 3.1.29-beta.259

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/grid.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import {
2
- toJson
3
- } from "./chunk-OJPHC3S2.mjs";
4
1
  import {
5
2
  uuid
6
3
  } from "./chunk-U3GDILUZ.mjs";
4
+ import {
5
+ toJson
6
+ } from "./chunk-OJPHC3S2.mjs";
7
7
  import {
8
8
  getTimestamp
9
9
  } from "./chunk-S4KHOAXM.mjs";
package/dist/jev.d.mts ADDED
@@ -0,0 +1,21 @@
1
+ import { JevDimension, JevScores, JevConfig, JevFeature, JevTree } from '@tradejs/types';
2
+
3
+ declare const JEV_DIMENSIONS: JevDimension[];
4
+ declare const JEV_PROVIDERS: readonly [{
5
+ readonly label: "OpenRouter";
6
+ readonly endpoint: "https://openrouter.ai/api/alpha/decisions";
7
+ readonly model: "typesafe/jev-1.13";
8
+ }, {
9
+ readonly label: "TypeSafe";
10
+ readonly endpoint: "https://api.typesafe.ai/v1/systemone";
11
+ readonly model: "jev-1.13.0";
12
+ }];
13
+ declare const normalizeJevEndpoint: (value: unknown) => string;
14
+ declare const parseJevConfig: (value: unknown) => JevConfig | undefined;
15
+ declare const decideJev: (scores: JevScores, config: JevConfig, geometryStatus: "available" | "facts_only" | "absent" | "invalid", features: Record<string, JevFeature> | undefined, questions: JevDimension[]) => {
16
+ allowed: boolean;
17
+ reasons: string[];
18
+ };
19
+ declare const predictJevTree: (tree: JevTree, features: Record<string, JevFeature>) => number;
20
+
21
+ export { JEV_DIMENSIONS, JEV_PROVIDERS, decideJev, normalizeJevEndpoint, parseJevConfig, predictJevTree };
package/dist/jev.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { JevDimension, JevScores, JevConfig, JevFeature, JevTree } from '@tradejs/types';
2
+
3
+ declare const JEV_DIMENSIONS: JevDimension[];
4
+ declare const JEV_PROVIDERS: readonly [{
5
+ readonly label: "OpenRouter";
6
+ readonly endpoint: "https://openrouter.ai/api/alpha/decisions";
7
+ readonly model: "typesafe/jev-1.13";
8
+ }, {
9
+ readonly label: "TypeSafe";
10
+ readonly endpoint: "https://api.typesafe.ai/v1/systemone";
11
+ readonly model: "jev-1.13.0";
12
+ }];
13
+ declare const normalizeJevEndpoint: (value: unknown) => string;
14
+ declare const parseJevConfig: (value: unknown) => JevConfig | undefined;
15
+ declare const decideJev: (scores: JevScores, config: JevConfig, geometryStatus: "available" | "facts_only" | "absent" | "invalid", features: Record<string, JevFeature> | undefined, questions: JevDimension[]) => {
16
+ allowed: boolean;
17
+ reasons: string[];
18
+ };
19
+ declare const predictJevTree: (tree: JevTree, features: Record<string, JevFeature>) => number;
20
+
21
+ export { JEV_DIMENSIONS, JEV_PROVIDERS, decideJev, normalizeJevEndpoint, parseJevConfig, predictJevTree };
package/dist/jev.js ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/jev.ts
21
+ var jev_exports = {};
22
+ __export(jev_exports, {
23
+ JEV_DIMENSIONS: () => JEV_DIMENSIONS,
24
+ JEV_PROVIDERS: () => JEV_PROVIDERS,
25
+ decideJev: () => decideJev,
26
+ normalizeJevEndpoint: () => normalizeJevEndpoint,
27
+ parseJevConfig: () => parseJevConfig,
28
+ predictJevTree: () => predictJevTree
29
+ });
30
+ module.exports = __toCommonJS(jev_exports);
31
+ var JEV_DIMENSIONS = [
32
+ "trend",
33
+ "swing",
34
+ "participation",
35
+ "setupParticipation",
36
+ "extension",
37
+ "confirmation",
38
+ "setupStrength",
39
+ "geometry"
40
+ ];
41
+ var JEV_PROVIDERS = [
42
+ {
43
+ label: "OpenRouter",
44
+ endpoint: "https://openrouter.ai/api/alpha/decisions",
45
+ model: "typesafe/jev-1.13"
46
+ },
47
+ {
48
+ label: "TypeSafe",
49
+ endpoint: "https://api.typesafe.ai/v1/systemone",
50
+ model: "jev-1.13.0"
51
+ }
52
+ ];
53
+ var normalizeJevEndpoint = (value) => {
54
+ if (typeof value !== "string" || !value.trim()) return "";
55
+ try {
56
+ const url = new URL(value.trim());
57
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
58
+ return "";
59
+ return url.toString().replace(/\/$/, "");
60
+ } catch {
61
+ return "";
62
+ }
63
+ };
64
+ var parseJevConfig = (value) => {
65
+ if (value == null || value === false) return void 0;
66
+ if (typeof value !== "object" || Array.isArray(value))
67
+ throw new Error("JEV must be a configuration object");
68
+ const config = value;
69
+ const keys = /* @__PURE__ */ new Set([
70
+ "source",
71
+ "mode",
72
+ "provider",
73
+ "recordsDir",
74
+ "modelFile",
75
+ "modelSha256"
76
+ ]);
77
+ if (Object.keys(config).some((key) => !keys.has(key)))
78
+ throw new Error("Unknown JEV configuration field");
79
+ if (!["provider", "recorded", "local"].includes(config.source) || config.mode !== "observe")
80
+ throw new Error("JEV supports enrichment only (mode: observe)");
81
+ if (config.provider && (!normalizeJevEndpoint(config.provider.endpoint) || !config.provider.model?.trim() || Object.keys(config.provider).some(
82
+ (key) => !["endpoint", "model"].includes(key)
83
+ )))
84
+ throw new Error("Invalid JEV provider");
85
+ if (config.provider && /(?:latest|preview)$/i.test(config.provider.model))
86
+ throw new Error("Pin a versioned Jev model instead of latest or preview");
87
+ if (config.source === "recorded" && !config.provider)
88
+ throw new Error("Recorded Jev requires the original endpoint and model");
89
+ if (config.source === "local" && (!config.modelFile || !/^[a-f0-9]{64}$/.test(config.modelSha256 ?? "")))
90
+ throw new Error("Local Jev gate requires modelFile and modelSha256");
91
+ for (const key of ["recordsDir", "modelFile"])
92
+ if (config[key] != null && (typeof config[key] !== "string" || !config[key]?.trim()))
93
+ throw new Error(`Invalid JEV ${key}`);
94
+ return {
95
+ ...config,
96
+ ...config.provider ? {
97
+ provider: {
98
+ endpoint: normalizeJevEndpoint(config.provider.endpoint),
99
+ model: config.provider.model.trim()
100
+ }
101
+ } : {}
102
+ };
103
+ };
104
+ var decideJev = (scores, config, geometryStatus, features, questions) => {
105
+ const reasons = [];
106
+ if (features?.["signal.validLevels"] === false)
107
+ reasons.push("INVALID_SIGNAL_LEVELS");
108
+ if (geometryStatus === "invalid") reasons.push("INVALID_GEOMETRY");
109
+ if (!questions.length) reasons.push("NO_ELIGIBLE_QUESTIONS");
110
+ if (config.requireGeometry && (!questions.includes("geometry") || geometryStatus === "absent"))
111
+ reasons.push("GEOMETRY_UNAVAILABLE");
112
+ for (const dimension of questions) {
113
+ const score = scores[dimension];
114
+ if (score == null || !Number.isFinite(score))
115
+ reasons.push(`${dimension.toUpperCase()}_UNAVAILABLE`);
116
+ else if (score < (config.minScores?.[dimension] ?? 0.5))
117
+ reasons.push(`${dimension.toUpperCase()}_BELOW_MIN`);
118
+ }
119
+ return { allowed: reasons.length === 0, reasons };
120
+ };
121
+ var predictJevTree = (tree, features) => {
122
+ if ("samples" in tree) return tree.value;
123
+ const value = features[tree.feature];
124
+ const left = value == null ? tree.missingLeft : tree.operator === "lte" ? typeof value === "number" && value <= tree.value : value === tree.value;
125
+ return predictJevTree(left ? tree.left : tree.right, features);
126
+ };
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ JEV_DIMENSIONS,
130
+ JEV_PROVIDERS,
131
+ decideJev,
132
+ normalizeJevEndpoint,
133
+ parseJevConfig,
134
+ predictJevTree
135
+ });
package/dist/jev.mjs ADDED
@@ -0,0 +1,105 @@
1
+ // src/jev.ts
2
+ var JEV_DIMENSIONS = [
3
+ "trend",
4
+ "swing",
5
+ "participation",
6
+ "setupParticipation",
7
+ "extension",
8
+ "confirmation",
9
+ "setupStrength",
10
+ "geometry"
11
+ ];
12
+ var JEV_PROVIDERS = [
13
+ {
14
+ label: "OpenRouter",
15
+ endpoint: "https://openrouter.ai/api/alpha/decisions",
16
+ model: "typesafe/jev-1.13"
17
+ },
18
+ {
19
+ label: "TypeSafe",
20
+ endpoint: "https://api.typesafe.ai/v1/systemone",
21
+ model: "jev-1.13.0"
22
+ }
23
+ ];
24
+ var normalizeJevEndpoint = (value) => {
25
+ if (typeof value !== "string" || !value.trim()) return "";
26
+ try {
27
+ const url = new URL(value.trim());
28
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
29
+ return "";
30
+ return url.toString().replace(/\/$/, "");
31
+ } catch {
32
+ return "";
33
+ }
34
+ };
35
+ var parseJevConfig = (value) => {
36
+ if (value == null || value === false) return void 0;
37
+ if (typeof value !== "object" || Array.isArray(value))
38
+ throw new Error("JEV must be a configuration object");
39
+ const config = value;
40
+ const keys = /* @__PURE__ */ new Set([
41
+ "source",
42
+ "mode",
43
+ "provider",
44
+ "recordsDir",
45
+ "modelFile",
46
+ "modelSha256"
47
+ ]);
48
+ if (Object.keys(config).some((key) => !keys.has(key)))
49
+ throw new Error("Unknown JEV configuration field");
50
+ if (!["provider", "recorded", "local"].includes(config.source) || config.mode !== "observe")
51
+ throw new Error("JEV supports enrichment only (mode: observe)");
52
+ if (config.provider && (!normalizeJevEndpoint(config.provider.endpoint) || !config.provider.model?.trim() || Object.keys(config.provider).some(
53
+ (key) => !["endpoint", "model"].includes(key)
54
+ )))
55
+ throw new Error("Invalid JEV provider");
56
+ if (config.provider && /(?:latest|preview)$/i.test(config.provider.model))
57
+ throw new Error("Pin a versioned Jev model instead of latest or preview");
58
+ if (config.source === "recorded" && !config.provider)
59
+ throw new Error("Recorded Jev requires the original endpoint and model");
60
+ if (config.source === "local" && (!config.modelFile || !/^[a-f0-9]{64}$/.test(config.modelSha256 ?? "")))
61
+ throw new Error("Local Jev gate requires modelFile and modelSha256");
62
+ for (const key of ["recordsDir", "modelFile"])
63
+ if (config[key] != null && (typeof config[key] !== "string" || !config[key]?.trim()))
64
+ throw new Error(`Invalid JEV ${key}`);
65
+ return {
66
+ ...config,
67
+ ...config.provider ? {
68
+ provider: {
69
+ endpoint: normalizeJevEndpoint(config.provider.endpoint),
70
+ model: config.provider.model.trim()
71
+ }
72
+ } : {}
73
+ };
74
+ };
75
+ var decideJev = (scores, config, geometryStatus, features, questions) => {
76
+ const reasons = [];
77
+ if (features?.["signal.validLevels"] === false)
78
+ reasons.push("INVALID_SIGNAL_LEVELS");
79
+ if (geometryStatus === "invalid") reasons.push("INVALID_GEOMETRY");
80
+ if (!questions.length) reasons.push("NO_ELIGIBLE_QUESTIONS");
81
+ if (config.requireGeometry && (!questions.includes("geometry") || geometryStatus === "absent"))
82
+ reasons.push("GEOMETRY_UNAVAILABLE");
83
+ for (const dimension of questions) {
84
+ const score = scores[dimension];
85
+ if (score == null || !Number.isFinite(score))
86
+ reasons.push(`${dimension.toUpperCase()}_UNAVAILABLE`);
87
+ else if (score < (config.minScores?.[dimension] ?? 0.5))
88
+ reasons.push(`${dimension.toUpperCase()}_BELOW_MIN`);
89
+ }
90
+ return { allowed: reasons.length === 0, reasons };
91
+ };
92
+ var predictJevTree = (tree, features) => {
93
+ if ("samples" in tree) return tree.value;
94
+ const value = features[tree.feature];
95
+ const left = value == null ? tree.missingLeft : tree.operator === "lte" ? typeof value === "number" && value <= tree.value : value === tree.value;
96
+ return predictJevTree(left ? tree.left : tree.right, features);
97
+ };
98
+ export {
99
+ JEV_DIMENSIONS,
100
+ JEV_PROVIDERS,
101
+ decideJev,
102
+ normalizeJevEndpoint,
103
+ parseJevConfig,
104
+ predictJevTree
105
+ };
@@ -11926,15 +11926,20 @@ var buildStrategySignal = ({
11926
11926
  additionalIndicators,
11927
11927
  isConfigFromBacktest
11928
11928
  }) => {
11929
+ const jevEvidence = additionalIndicators?.jevEvidence;
11930
+ const strategyAdditionalIndicators = jevEvidence != null && additionalIndicators ? copyEnumerableDataPropertiesExcept(
11931
+ additionalIndicators,
11932
+ /* @__PURE__ */ new Set(["jevEvidence"])
11933
+ ) : additionalIndicators;
11929
11934
  const indicatorsRecord = indicators && typeof indicators === "object" ? indicators : {};
11930
11935
  const baseContext = indicatorsRecord.baseContext;
11931
11936
  const normalizedIndicators = baseContext == null ? indicators : copyEnumerableDataPropertiesExcept(
11932
11937
  indicatorsRecord,
11933
11938
  /* @__PURE__ */ new Set(["baseContext"])
11934
11939
  );
11935
- const mergedAdditionalIndicators = baseContext == null ? additionalIndicators : {
11936
- ...additionalIndicators ?? {},
11937
- baseContext: additionalIndicators?.baseContext ?? baseContext
11940
+ const mergedAdditionalIndicators = baseContext == null ? strategyAdditionalIndicators : {
11941
+ ...strategyAdditionalIndicators,
11942
+ baseContext: strategyAdditionalIndicators?.baseContext ?? baseContext
11938
11943
  };
11939
11944
  const normalizedAdditionalIndicators = normalizeAdditionalIndicatorsBaseContext(
11940
11945
  mergedAdditionalIndicators,
@@ -11952,6 +11957,7 @@ var buildStrategySignal = ({
11952
11957
  prices,
11953
11958
  indicators: normalizedIndicators,
11954
11959
  additionalIndicators: normalizedAdditionalIndicators,
11960
+ ...jevEvidence != null ? { jevEvidence } : {},
11955
11961
  isConfigFromBacktest
11956
11962
  };
11957
11963
  };
@@ -1187,15 +1187,20 @@ var buildStrategySignal = ({
1187
1187
  additionalIndicators,
1188
1188
  isConfigFromBacktest
1189
1189
  }) => {
1190
+ const jevEvidence = additionalIndicators?.jevEvidence;
1191
+ const strategyAdditionalIndicators = jevEvidence != null && additionalIndicators ? copyEnumerableDataPropertiesExcept(
1192
+ additionalIndicators,
1193
+ /* @__PURE__ */ new Set(["jevEvidence"])
1194
+ ) : additionalIndicators;
1190
1195
  const indicatorsRecord = indicators && typeof indicators === "object" ? indicators : {};
1191
1196
  const baseContext = indicatorsRecord.baseContext;
1192
1197
  const normalizedIndicators = baseContext == null ? indicators : copyEnumerableDataPropertiesExcept(
1193
1198
  indicatorsRecord,
1194
1199
  /* @__PURE__ */ new Set(["baseContext"])
1195
1200
  );
1196
- const mergedAdditionalIndicators = baseContext == null ? additionalIndicators : {
1197
- ...additionalIndicators ?? {},
1198
- baseContext: additionalIndicators?.baseContext ?? baseContext
1201
+ const mergedAdditionalIndicators = baseContext == null ? strategyAdditionalIndicators : {
1202
+ ...strategyAdditionalIndicators,
1203
+ baseContext: strategyAdditionalIndicators?.baseContext ?? baseContext
1199
1204
  };
1200
1205
  const normalizedAdditionalIndicators = normalizeAdditionalIndicatorsBaseContext(
1201
1206
  mergedAdditionalIndicators,
@@ -1213,6 +1218,7 @@ var buildStrategySignal = ({
1213
1218
  prices,
1214
1219
  indicators: normalizedIndicators,
1215
1220
  additionalIndicators: normalizedAdditionalIndicators,
1221
+ ...jevEvidence != null ? { jevEvidence } : {},
1216
1222
  isConfigFromBacktest
1217
1223
  };
1218
1224
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/core",
3
- "version": "3.1.28-beta.258",
3
+ "version": "3.1.29-beta.259",
4
4
  "description": "MIT-licensed browser-safe API for TradeJS config, strategy authoring, figures, and shared helpers.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -129,10 +129,15 @@
129
129
  "types": "./dist/time.d.ts",
130
130
  "import": "./dist/time.mjs",
131
131
  "require": "./dist/time.js"
132
+ },
133
+ "./jev": {
134
+ "types": "./dist/jev.d.ts",
135
+ "import": "./dist/jev.mjs",
136
+ "require": "./dist/jev.js"
132
137
  }
133
138
  },
134
139
  "dependencies": {
135
- "@tradejs/types": "^3.1.28-beta.258",
140
+ "@tradejs/types": "^3.1.29-beta.259",
136
141
  "date-fns": "^3.6.0",
137
142
  "fast-technical-indicators": "^1.1.4",
138
143
  "klinecharts": "10.0.0-alpha9",