@substrate-ai/core 0.20.77 → 0.20.78
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/debug-swallow.d.ts +40 -0
- package/dist/utils/debug-swallow.d.ts.map +1 -0
- package/dist/utils/debug-swallow.js +56 -0
- package/dist/utils/debug-swallow.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './git/index.js';
|
|
|
18
18
|
export * from './version-manager/index.js';
|
|
19
19
|
export * from './supervisor/index.js';
|
|
20
20
|
export * from './budget/index.js';
|
|
21
|
+
export { swallowDebug } from './utils/debug-swallow.js';
|
|
21
22
|
export { estimateCost as estimateCostForProvider } from './cost-tracker/token-rates.js';
|
|
22
23
|
export type { CostTracker, CostTrackerOptions } from './cost-tracker/index.js';
|
|
23
24
|
export { CostTrackerImpl, createCostTracker } from './cost-tracker/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,YAAY,CAAA;AAI1B,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACrE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGpF,cAAc,qBAAqB,CAAA;AAGnC,cAAc,wBAAwB,CAAA;AAGtC,cAAc,oBAAoB,CAAA;AAGlC,cAAc,mBAAmB,CAAA;AAOjC,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,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O,EAAE,YAAY,IAAI,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvF,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAC5F,YAAY,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AAC3E,YAAY,EACV,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAChC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAKvG,YAAY,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAChG,cAAc,oBAAoB,CAAA;AAGlC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,10 @@ export * from './version-manager/index.js';
|
|
|
28
28
|
export * from './supervisor/index.js';
|
|
29
29
|
// Budget: BudgetTracker interface and stub implementation
|
|
30
30
|
export * from './budget/index.js';
|
|
31
|
+
// Utilities: small cross-cutting helpers
|
|
32
|
+
// swallowDebug: build a `.catch()` handler that silently swallows errors in
|
|
33
|
+
// production but surfaces them to stderr when SUBSTRATE_DEBUG enables the label
|
|
34
|
+
export { swallowDebug } from './utils/debug-swallow.js';
|
|
31
35
|
// CostTracker: token rates, cost tracking, and subscriber
|
|
32
36
|
// estimateCost: telemetry's (model, tokens) version is the canonical @substrate-ai/core export (exported above).
|
|
33
37
|
// estimateCostForProvider: cost-tracker variant (provider, model, inputTokens, outputTokens, rateTable?)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,qEAAqE;AACrE,+EAA+E;AAC/E,4EAA4E;AAC5E,cAAc,YAAY,CAAA;AAM1B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGrE,wFAAwF;AACxF,cAAc,qBAAqB,CAAA;AAEnC,gGAAgG;AAChG,cAAc,wBAAwB,CAAA;AAEtC,6EAA6E;AAC7E,cAAc,oBAAoB,CAAA;AAElC,4CAA4C;AAC5C,cAAc,mBAAmB,CAAA;AAQjC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,cAAc,sBAAsB,CAAA;AAEpC,yFAAyF;AACzF,cAAc,qBAAqB,CAAA;AAEnC,6FAA6F;AAC7F,cAAc,oBAAoB,CAAA;AAElC,wEAAwE;AACxE,cAAc,0BAA0B,CAAA;AAExC,sDAAsD;AACtD,cAAc,gBAAgB,CAAA;AAE9B,0FAA0F;AAC1F,cAAc,4BAA4B,CAAA;AAE1C,sDAAsD;AACtD,cAAc,uBAAuB,CAAA;AAErC,0DAA0D;AAC1D,cAAc,mBAAmB,CAAA;AAEjC,0DAA0D;AAC1D,iHAAiH;AACjH,yGAAyG;AACzG,wFAAwF;AACxF,4FAA4F;AAC5F,qEAAqE;AACrE,sFAAsF;AACtF,qFAAqF;AACrF,gGAAgG;AAChG,OAAO,EAAE,YAAY,IAAI,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAEvF,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAS5F,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MA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AAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAS5F,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAMvG,cAAc,oBAAoB,CAAA;AAElC,kEAAkE;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug-mode unmasking for `.catch()` wrappers that silently swallow errors.
|
|
3
|
+
*
|
|
4
|
+
* Background: many substrate code paths use `.catch(() => {})` to make a
|
|
5
|
+
* background or non-critical operation non-blocking — version checks,
|
|
6
|
+
* telemetry outbox drains, manifest updates after a process exits. The
|
|
7
|
+
* pattern is correct (these failures must NOT block the user-facing flow)
|
|
8
|
+
* but it hides ship-blocking bugs. v0.20.74's pre-dispatch version advisory
|
|
9
|
+
* silently failed to fire in production for 4 CI-green ships because tsdown
|
|
10
|
+
* bundled a broken lazy-chunk; the chunk's SyntaxError on instantiation was
|
|
11
|
+
* swallowed by the advisory's `.catch(() => {})`. Caught only by user-driven
|
|
12
|
+
* e2e smoke against the published bundle.
|
|
13
|
+
*
|
|
14
|
+
* **The discipline (codified here):** every `.catch(() => {})` should be
|
|
15
|
+
* replaced with `.catch(swallowDebug('label'))`. When `SUBSTRATE_DEBUG`
|
|
16
|
+
* contains the label (or `*`), the swallowed error surfaces to stderr.
|
|
17
|
+
* Otherwise the original silent-failure semantic is preserved.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* import { swallowDebug } from '@substrate-ai/core'
|
|
21
|
+
* await fooThatMayFail().catch(swallowDebug('advisory'))
|
|
22
|
+
*
|
|
23
|
+
* # In production: silent
|
|
24
|
+
* substrate run --stories 1-1
|
|
25
|
+
*
|
|
26
|
+
* # When investigating silent failure:
|
|
27
|
+
* SUBSTRATE_DEBUG=advisory substrate run --stories 1-1
|
|
28
|
+
* SUBSTRATE_DEBUG=* substrate run --stories 1-1 # all swallow sites
|
|
29
|
+
* SUBSTRATE_DEBUG=advisory,mesh substrate run --stories 1-1
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Build an error handler that silently swallows errors in normal operation
|
|
33
|
+
* but writes them to stderr when `SUBSTRATE_DEBUG` enables the given label.
|
|
34
|
+
*
|
|
35
|
+
* Match rules: `SUBSTRATE_DEBUG=*` enables every label; otherwise the env
|
|
36
|
+
* var is parsed as a comma-separated list (whitespace-tolerant) and matches
|
|
37
|
+
* by exact label string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function swallowDebug(label: string): (err: unknown) => void;
|
|
40
|
+
//# sourceMappingURL=debug-swallow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-swallow.d.ts","sourceRoot":"","sources":["../../src/utils/debug-swallow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAelE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug-mode unmasking for `.catch()` wrappers that silently swallow errors.
|
|
3
|
+
*
|
|
4
|
+
* Background: many substrate code paths use `.catch(() => {})` to make a
|
|
5
|
+
* background or non-critical operation non-blocking — version checks,
|
|
6
|
+
* telemetry outbox drains, manifest updates after a process exits. The
|
|
7
|
+
* pattern is correct (these failures must NOT block the user-facing flow)
|
|
8
|
+
* but it hides ship-blocking bugs. v0.20.74's pre-dispatch version advisory
|
|
9
|
+
* silently failed to fire in production for 4 CI-green ships because tsdown
|
|
10
|
+
* bundled a broken lazy-chunk; the chunk's SyntaxError on instantiation was
|
|
11
|
+
* swallowed by the advisory's `.catch(() => {})`. Caught only by user-driven
|
|
12
|
+
* e2e smoke against the published bundle.
|
|
13
|
+
*
|
|
14
|
+
* **The discipline (codified here):** every `.catch(() => {})` should be
|
|
15
|
+
* replaced with `.catch(swallowDebug('label'))`. When `SUBSTRATE_DEBUG`
|
|
16
|
+
* contains the label (or `*`), the swallowed error surfaces to stderr.
|
|
17
|
+
* Otherwise the original silent-failure semantic is preserved.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* import { swallowDebug } from '@substrate-ai/core'
|
|
21
|
+
* await fooThatMayFail().catch(swallowDebug('advisory'))
|
|
22
|
+
*
|
|
23
|
+
* # In production: silent
|
|
24
|
+
* substrate run --stories 1-1
|
|
25
|
+
*
|
|
26
|
+
* # When investigating silent failure:
|
|
27
|
+
* SUBSTRATE_DEBUG=advisory substrate run --stories 1-1
|
|
28
|
+
* SUBSTRATE_DEBUG=* substrate run --stories 1-1 # all swallow sites
|
|
29
|
+
* SUBSTRATE_DEBUG=advisory,mesh substrate run --stories 1-1
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Build an error handler that silently swallows errors in normal operation
|
|
33
|
+
* but writes them to stderr when `SUBSTRATE_DEBUG` enables the given label.
|
|
34
|
+
*
|
|
35
|
+
* Match rules: `SUBSTRATE_DEBUG=*` enables every label; otherwise the env
|
|
36
|
+
* var is parsed as a comma-separated list (whitespace-tolerant) and matches
|
|
37
|
+
* by exact label string.
|
|
38
|
+
*/
|
|
39
|
+
export function swallowDebug(label) {
|
|
40
|
+
return (err) => {
|
|
41
|
+
const debugEnv = process.env['SUBSTRATE_DEBUG'];
|
|
42
|
+
if (debugEnv === undefined || debugEnv === '')
|
|
43
|
+
return;
|
|
44
|
+
const enabled = debugEnv === '*' ||
|
|
45
|
+
debugEnv
|
|
46
|
+
.split(',')
|
|
47
|
+
.map((s) => s.trim())
|
|
48
|
+
.includes(label);
|
|
49
|
+
if (!enabled)
|
|
50
|
+
return;
|
|
51
|
+
const message = err instanceof Error ? `${err.name}: ${err.message}` : String(err);
|
|
52
|
+
const stack = err instanceof Error && err.stack ? `\n${err.stack}` : '';
|
|
53
|
+
process.stderr.write(`[debug:${label}] swallowed: ${message}${stack}\n`);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=debug-swallow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-swallow.js","sourceRoot":"","sources":["../../src/utils/debug-swallow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,CAAC,GAAY,EAAQ,EAAE;QAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC/C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAM;QACrD,MAAM,OAAO,GACX,QAAQ,KAAK,GAAG;YAChB,QAAQ;iBACL,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpB,QAAQ,CAAC,KAAK,CAAC,CAAA;QACpB,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClF,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,gBAAgB,OAAO,GAAG,KAAK,IAAI,CAAC,CAAA;IAC1E,CAAC,CAAA;AACH,CAAC"}
|