@viji-dev/core 0.6.1 → 0.7.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/dist/index.d.ts CHANGED
@@ -1699,6 +1699,107 @@ export declare type Resolution = {
1699
1699
  height: number;
1700
1700
  };
1701
1701
 
1702
+ /**
1703
+ * Structured scene console envelope surfaced via `VijiCore.onSceneConsole`.
1704
+ *
1705
+ * Only artist `console.*` calls reach this listener (the wrapper is injected
1706
+ * as a function argument on the scene IIFE; engine code uses `globalThis.console`
1707
+ * and is not surfaced). The wrapper calls the real `console[level](...args)`
1708
+ * first before forwarding, so DevTools output is preserved.
1709
+ *
1710
+ * Arguments are pre-stringified in the worker with cycle-safe depth-bounded
1711
+ * inspection, a per-argument byte cap (`consoleArgMaxBytes`), and an argument
1712
+ * count cap (`consoleMaxArgsPerCall`). High-cardinality logs are rate-limited
1713
+ * by `consoleMaxUniqueSignaturesPerSecond`.
1714
+ */
1715
+ export declare interface SceneConsoleMessage {
1716
+ /** Console method invoked. */
1717
+ level: 'log' | 'info' | 'warn' | 'error';
1718
+ /** Stringified arguments. Each entry is bounded by `consoleArgMaxBytes`. */
1719
+ args: string[];
1720
+ /** Stable hash of `level` and the stringified arguments, used for coalescing. */
1721
+ signatureHash: string;
1722
+ /** Number of occurrences of this signature accumulated in the current window. */
1723
+ count: number;
1724
+ /** Millisecond timestamp of the first occurrence of this signature in the current window. */
1725
+ firstSeenAt: number;
1726
+ /** Millisecond timestamp of the most recent occurrence. */
1727
+ lastSeenAt: number;
1728
+ /**
1729
+ * Source location of the `console.*` call site in artist-source coordinates.
1730
+ * Captured via `new Error().stack` inside the wrapper. Absent when stack
1731
+ * frame parsing fails.
1732
+ */
1733
+ sourceLocation?: SceneSourceLocation;
1734
+ }
1735
+
1736
+ /**
1737
+ * Discriminator for scene runtime errors surfaced via `onSceneRuntimeError`.
1738
+ *
1739
+ * - `SCENE_CODE_ERROR`: thrown during `setSceneCode` parse/eval (native, P5).
1740
+ * - `RENDER_ERROR`: synchronous throw inside the artist's `render()` function.
1741
+ * - `UNCAUGHT_ERROR`: caught by the worker's `self.onerror` (async / RAF / setTimeout).
1742
+ * - `UNHANDLED_REJECTION`: caught by the worker's `unhandledrejection` handler.
1743
+ * - `SHADER_COMPILE_ERROR`: GLSL compile failure (shader mode).
1744
+ * - `P5_INIT_ERROR`: failure during P5 mode initialization (e.g. missing `render`).
1745
+ * - `ENGINE_INTERNAL`: engine path with no artist attribution.
1746
+ */
1747
+ export declare type SceneErrorCode = 'SCENE_CODE_ERROR' | 'RENDER_ERROR' | 'UNCAUGHT_ERROR' | 'UNHANDLED_REJECTION' | 'SHADER_COMPILE_ERROR' | 'P5_INIT_ERROR' | 'ENGINE_INTERNAL';
1748
+
1749
+ /**
1750
+ * Structured scene runtime error envelope surfaced via `VijiCore.onSceneRuntimeError`.
1751
+ *
1752
+ * Identical signatures are coalesced inside the worker: the first occurrence in
1753
+ * a window fires with `count: 1`, subsequent occurrences increment `count`, and
1754
+ * a trailing rollup fires at window close if more than one occurrence was seen.
1755
+ *
1756
+ * The host-side `console.error('Scene error:', data)` tee continues to fire
1757
+ * alongside the listener (never silenced based on listener presence).
1758
+ */
1759
+ export declare interface SceneRuntimeError {
1760
+ /** Error message, equivalent to `Error.message`. */
1761
+ message: string;
1762
+ /** Raw V8 stack trace, when available. Not resolved to artist-source coordinates. */
1763
+ stack?: string;
1764
+ /**
1765
+ * Attribution: `'scene'` when at least one stack frame originates in the
1766
+ * artist's compiled scene IIFE; `'engine'` otherwise.
1767
+ */
1768
+ source: 'scene' | 'engine';
1769
+ /**
1770
+ * Lifecycle phase: `'init'` before the first successful render frame
1771
+ * completes; `'render'` afterwards.
1772
+ */
1773
+ phase: 'init' | 'render';
1774
+ /** Error code; see `SceneErrorCode`. */
1775
+ code: SceneErrorCode;
1776
+ /** Stable hash of `message` and the first artist stack frame, used for coalescing. */
1777
+ signatureHash: string;
1778
+ /** Number of occurrences of this signature accumulated in the current window. */
1779
+ count: number;
1780
+ /** Millisecond timestamp of the first occurrence of this signature in the current window. */
1781
+ firstSeenAt: number;
1782
+ /** Millisecond timestamp of the most recent occurrence. */
1783
+ lastSeenAt: number;
1784
+ /**
1785
+ * Source location resolved to artist-source coordinates when available.
1786
+ * Absent when no artist stack frame is found (engine errors), when shader
1787
+ * compile logs lack column info, or when sourcemap resolution fails.
1788
+ */
1789
+ sourceLocation?: SceneSourceLocation;
1790
+ }
1791
+
1792
+ /**
1793
+ * Resolved source location in artist-source coordinates. `line` is 1-based and
1794
+ * matches the artist's authored TypeScript / GLSL line numbers. `column` is
1795
+ * 1-based when present; absent when sourcemap resolution failed or the source
1796
+ * is GLSL (which doesn't reliably emit column information in compile logs).
1797
+ */
1798
+ export declare interface SceneSourceLocation {
1799
+ line: number;
1800
+ column?: number;
1801
+ }
1802
+
1702
1803
  /**
1703
1804
  * Per-pixel person/background segmentation mask. Mask dimensions reflect the
1704
1805
  * ML model's output and may differ from the source video frame.
@@ -2267,7 +2368,7 @@ declare type TrackingState = 'TRACKING' | 'LOCKED' | 'BREAKDOWN' | 'LOST';
2267
2368
  /** Returned by `on*` listener registration calls; invoke to unsubscribe. */
2268
2369
  export declare type Unsubscribe = () => void;
2269
2370
 
2270
- export declare const VERSION = "0.5.7";
2371
+ export declare const VERSION = "0.7.0";
2271
2372
 
2272
2373
  /**
2273
2374
  * Real-time video API: drawable frame, dimensions, and the source-side
@@ -2633,6 +2734,8 @@ export declare class VijiCore {
2633
2734
  private parameterErrorListeners;
2634
2735
  private capabilitiesChangeListeners;
2635
2736
  private stateImportErrorListeners;
2737
+ private sceneRuntimeErrorListeners;
2738
+ private sceneConsoleListeners;
2636
2739
  private stats;
2637
2740
  constructor(config: VijiCoreConfig);
2638
2741
  /**
@@ -2928,6 +3031,42 @@ export declare class VijiCore {
2928
3031
  */
2929
3032
  onStateImportError(listener: (error: StateImportError) => void): Unsubscribe;
2930
3033
  private fireStateImportError;
3034
+ /**
3035
+ * Listen for scene runtime errors surfaced by the worker. Errors caused by
3036
+ * the artist's scene code (`SCENE_CODE_ERROR`, `RENDER_ERROR`,
3037
+ * `SHADER_COMPILE_ERROR`, `P5_INIT_ERROR`, plus async / unhandled-rejection
3038
+ * paths originating in the scene) are coalesced on the worker side: identical
3039
+ * signatures within `VijiCoreConfig.errorCoalescingWindowMs` (default 1s)
3040
+ * collapse to a single leading-edge listener call plus an optional trailing
3041
+ * rollup with the final `count`.
3042
+ *
3043
+ * The legacy `console.error('Worker error:', data)` host log continues to
3044
+ * fire alongside this listener (tee semantics, never silenced).
3045
+ *
3046
+ * @returns Unsubscribe function. Call to remove the listener.
3047
+ */
3048
+ onSceneRuntimeError(listener: (error: SceneRuntimeError) => void): Unsubscribe;
3049
+ private fireSceneRuntimeError;
3050
+ /**
3051
+ * Listen for `console.*` calls made from the artist's scene code. The
3052
+ * worker injects a wrapped `console` as an additional function-argument
3053
+ * binding to the artist's IIFE; the wrapper calls the real `console[level]`
3054
+ * first (preserving DevTools output) and then forwards a coalesced, bounded
3055
+ * envelope through this listener.
3056
+ *
3057
+ * Coalescing window: `VijiCoreConfig.consoleCoalescingWindowMs` (default 1s).
3058
+ * Argument bounds: `consoleArgMaxBytes` (default 512B per arg),
3059
+ * `consoleMaxArgsPerCall` (default 8 args). Rate cap on distinct signatures:
3060
+ * `consoleMaxUniqueSignaturesPerSecond` (default 32).
3061
+ *
3062
+ * Only the four forwarded levels (`log`, `info`, `warn`, `error`) reach
3063
+ * this listener. Other console methods (`debug`, `trace`, `dir`, `group`,
3064
+ * etc.) pass through to the real console unchanged but are not surfaced.
3065
+ *
3066
+ * @returns Unsubscribe function. Call to remove the listener.
3067
+ */
3068
+ onSceneConsole(listener: (message: SceneConsoleMessage) => void): Unsubscribe;
3069
+ private fireSceneConsole;
2931
3070
  /**
2932
3071
  * Notify parameter change listeners
2933
3072
  */
@@ -3406,6 +3545,34 @@ export declare interface VijiCoreConfig {
3406
3545
  _rh?: number;
3407
3546
  /** Called when the scene is visually live (render loop running, branding applied) but before audio/video/WASM setup completes. */
3408
3547
  onRenderStart?: () => void;
3548
+ /**
3549
+ * Coalescing window in milliseconds for `onSceneRuntimeError` listener. Identical signatures
3550
+ * within the window collapse into a single host-side message with an incremented `count`.
3551
+ * Default: `1000`.
3552
+ */
3553
+ errorCoalescingWindowMs?: number;
3554
+ /**
3555
+ * Coalescing window in milliseconds for `onSceneConsole` listener. Identical signatures
3556
+ * within the window collapse into a single host-side message with an incremented `count`.
3557
+ * Default: `1000`.
3558
+ */
3559
+ consoleCoalescingWindowMs?: number;
3560
+ /**
3561
+ * Per-argument byte cap for `onSceneConsole` payloads. Arguments longer than this are
3562
+ * truncated with a `…[truncated]` marker. Default: `512`.
3563
+ */
3564
+ consoleArgMaxBytes?: number;
3565
+ /**
3566
+ * Maximum arguments per `console.*` call forwarded through `onSceneConsole`. Excess arguments
3567
+ * are dropped. Default: `8`.
3568
+ */
3569
+ consoleMaxArgsPerCall?: number;
3570
+ /**
3571
+ * Rate cap on distinct console signatures forwarded per second. Excess unique signatures
3572
+ * are dropped with a single synthetic "console suppressed: high frequency" envelope per
3573
+ * overflow window. Default: `32`.
3574
+ */
3575
+ consoleMaxUniqueSignaturesPerSecond?: number;
3409
3576
  }
3410
3577
 
3411
3578
  export declare class VijiCoreError extends Error {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as a, V as i, a as s, b as e } from "./index-DfAcgMbB.js";
1
+ import { A as a, V as i, a as s, b as e } from "./index-BCIUaaLW.js";
2
2
  export {
3
3
  a as AudioSystem,
4
4
  i as VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viji-dev/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Universal execution engine for Viji Creative scenes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,6 +51,7 @@
51
51
  "prebuild": "node scripts/prebuild-clean.mjs",
52
52
  "build": "vite build && node scripts/copy-tasks-assets.mjs && node scripts/build-artist-types.mjs && node scripts/build-docs-api.mjs",
53
53
  "build:docs": "node scripts/build-docs-api.mjs",
54
+ "lint:ai-prompts-drift": "node scripts/lint-ai-prompts-drift.mjs",
54
55
  "dev": "vite build --watch",
55
56
  "integration": "vite --config integration-example/vite.config.ts",
56
57
  "test": "vitest",