oracular 0.3.0 → 0.4.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.cts CHANGED
@@ -764,4 +764,63 @@ declare function deserialize(json: string, opts?: DeserializeOptions): EngineSta
764
764
  */
765
765
  declare function createState(config: EngineConfig): EngineState;
766
766
 
767
- export { type DeserializeOptions, type EndRecord, type EngineConfig, type EngineState, type EpisodeIntentRecord, type EpisodeState, type EvaluateOptions, type Evaluation, type EventRecord, type ExplainOptions, type IntentConfig, type IntentEvent, type IntentState, type LearningConfig, type Migrate, type Prediction, RECORD_VERSION, type RecordMode, type RecordOptions, type RecordedDecision, type RecorderRecord, type RevealOptions, STATE_VERSION, type SignalContribution, type SignalExplanation, type SignalRecord, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, observe, predict, serialize, shouldReveal };
767
+ /** The units of {@link ms}: each takes a count and returns milliseconds. */
768
+ interface Units {
769
+ /** `n` seconds in milliseconds: `n × 1000`. */
770
+ readonly seconds: (n: number) => number;
771
+ /** `n` minutes in milliseconds: `n × 60 000`. */
772
+ readonly minutes: (n: number) => number;
773
+ /** `n` hours in milliseconds: `n × 3 600 000`. */
774
+ readonly hours: (n: number) => number;
775
+ /** `n` days in milliseconds: `n × 86 400 000`. */
776
+ readonly days: (n: number) => number;
777
+ /** `n` weeks in milliseconds: `n × 604 800 000`. */
778
+ readonly weeks: (n: number) => number;
779
+ }
780
+ /**
781
+ * Durations in milliseconds, the unit of `Date.now()`: `ms.days(7)` is `604800000`. Plain
782
+ * multiplications and nothing else, for `halfLife`, `cooldown`, `episodeTimeout` and
783
+ * `learning.halfLife` when your timestamps are in milliseconds. If your `at` is in another unit,
784
+ * write durations in that unit instead: the engine only needs the two to agree.
785
+ *
786
+ * @example
787
+ * ```ts
788
+ * const config = {
789
+ * episodeTimeout: ms.minutes(30),
790
+ * intents: {
791
+ * upgrade: {
792
+ * prior: 0.05,
793
+ * priorStrength: 10,
794
+ * halfLife: ms.days(7),
795
+ * signals: { 'pricing.viewed': 3 },
796
+ * reveal: { cooldown: ms.weeks(2) },
797
+ * },
798
+ * },
799
+ * };
800
+ * ```
801
+ */
802
+ declare const ms: Units;
803
+
804
+ /**
805
+ * Checks a config exactly as {@link createState} and {@link deserialize} do, without building a
806
+ * state, and returns the normalized copy they would store: only the recognised keys, in a fixed
807
+ * order, with every `undefined` dropped, so it survives a JSON round trip unchanged. Use it to
808
+ * fail fast at startup or in a test, or on a config loaded from a file, before the engine runs.
809
+ *
810
+ * @param config - The config to check. Typed `unknown` so parsed JSON can be passed as it is.
811
+ * @returns A fresh, normalized {@link EngineConfig}. `config` is not mutated.
812
+ * @throws `TypeError` when a value has the wrong type or a key is not recognised.
813
+ * @throws `RangeError` when a number is out of range: a `prior` outside (0, 1), a signal weight of
814
+ * 0, or a weight, `priorStrength`, `learning.gain` or `learning.priorEpisodes` beyond 1e6.
815
+ * @example
816
+ * ```ts
817
+ * import { readFileSync } from 'node:fs';
818
+ * import { validateConfig } from 'oracular';
819
+ *
820
+ * // Throws with the offending path in the message, e.g. config.intents["upgrade"].prior
821
+ * const config = validateConfig(JSON.parse(readFileSync('oracular.config.json', 'utf8')));
822
+ * ```
823
+ */
824
+ declare function validateConfig(config: unknown): EngineConfig;
825
+
826
+ export { type DeserializeOptions, type EndRecord, type EngineConfig, type EngineState, type EpisodeIntentRecord, type EpisodeState, type EvaluateOptions, type Evaluation, type EventRecord, type ExplainOptions, type IntentConfig, type IntentEvent, type IntentState, type LearningConfig, type Migrate, type Prediction, RECORD_VERSION, type RecordMode, type RecordOptions, type RecordedDecision, type RecorderRecord, type RevealOptions, STATE_VERSION, type SignalContribution, type SignalExplanation, type SignalRecord, type Units, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, ms, observe, predict, serialize, shouldReveal, validateConfig };
package/dist/index.d.ts CHANGED
@@ -764,4 +764,63 @@ declare function deserialize(json: string, opts?: DeserializeOptions): EngineSta
764
764
  */
765
765
  declare function createState(config: EngineConfig): EngineState;
766
766
 
767
- export { type DeserializeOptions, type EndRecord, type EngineConfig, type EngineState, type EpisodeIntentRecord, type EpisodeState, type EvaluateOptions, type Evaluation, type EventRecord, type ExplainOptions, type IntentConfig, type IntentEvent, type IntentState, type LearningConfig, type Migrate, type Prediction, RECORD_VERSION, type RecordMode, type RecordOptions, type RecordedDecision, type RecorderRecord, type RevealOptions, STATE_VERSION, type SignalContribution, type SignalExplanation, type SignalRecord, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, observe, predict, serialize, shouldReveal };
767
+ /** The units of {@link ms}: each takes a count and returns milliseconds. */
768
+ interface Units {
769
+ /** `n` seconds in milliseconds: `n × 1000`. */
770
+ readonly seconds: (n: number) => number;
771
+ /** `n` minutes in milliseconds: `n × 60 000`. */
772
+ readonly minutes: (n: number) => number;
773
+ /** `n` hours in milliseconds: `n × 3 600 000`. */
774
+ readonly hours: (n: number) => number;
775
+ /** `n` days in milliseconds: `n × 86 400 000`. */
776
+ readonly days: (n: number) => number;
777
+ /** `n` weeks in milliseconds: `n × 604 800 000`. */
778
+ readonly weeks: (n: number) => number;
779
+ }
780
+ /**
781
+ * Durations in milliseconds, the unit of `Date.now()`: `ms.days(7)` is `604800000`. Plain
782
+ * multiplications and nothing else, for `halfLife`, `cooldown`, `episodeTimeout` and
783
+ * `learning.halfLife` when your timestamps are in milliseconds. If your `at` is in another unit,
784
+ * write durations in that unit instead: the engine only needs the two to agree.
785
+ *
786
+ * @example
787
+ * ```ts
788
+ * const config = {
789
+ * episodeTimeout: ms.minutes(30),
790
+ * intents: {
791
+ * upgrade: {
792
+ * prior: 0.05,
793
+ * priorStrength: 10,
794
+ * halfLife: ms.days(7),
795
+ * signals: { 'pricing.viewed': 3 },
796
+ * reveal: { cooldown: ms.weeks(2) },
797
+ * },
798
+ * },
799
+ * };
800
+ * ```
801
+ */
802
+ declare const ms: Units;
803
+
804
+ /**
805
+ * Checks a config exactly as {@link createState} and {@link deserialize} do, without building a
806
+ * state, and returns the normalized copy they would store: only the recognised keys, in a fixed
807
+ * order, with every `undefined` dropped, so it survives a JSON round trip unchanged. Use it to
808
+ * fail fast at startup or in a test, or on a config loaded from a file, before the engine runs.
809
+ *
810
+ * @param config - The config to check. Typed `unknown` so parsed JSON can be passed as it is.
811
+ * @returns A fresh, normalized {@link EngineConfig}. `config` is not mutated.
812
+ * @throws `TypeError` when a value has the wrong type or a key is not recognised.
813
+ * @throws `RangeError` when a number is out of range: a `prior` outside (0, 1), a signal weight of
814
+ * 0, or a weight, `priorStrength`, `learning.gain` or `learning.priorEpisodes` beyond 1e6.
815
+ * @example
816
+ * ```ts
817
+ * import { readFileSync } from 'node:fs';
818
+ * import { validateConfig } from 'oracular';
819
+ *
820
+ * // Throws with the offending path in the message, e.g. config.intents["upgrade"].prior
821
+ * const config = validateConfig(JSON.parse(readFileSync('oracular.config.json', 'utf8')));
822
+ * ```
823
+ */
824
+ declare function validateConfig(config: unknown): EngineConfig;
825
+
826
+ export { type DeserializeOptions, type EndRecord, type EngineConfig, type EngineState, type EpisodeIntentRecord, type EpisodeState, type EvaluateOptions, type Evaluation, type EventRecord, type ExplainOptions, type IntentConfig, type IntentEvent, type IntentState, type LearningConfig, type Migrate, type Prediction, RECORD_VERSION, type RecordMode, type RecordOptions, type RecordedDecision, type RecorderRecord, type RevealOptions, STATE_VERSION, type SignalContribution, type SignalExplanation, type SignalRecord, type Units, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, ms, observe, predict, serialize, shouldReveal, validateConfig };
package/dist/index.js CHANGED
@@ -941,6 +941,20 @@ function reconcile(raw, config) {
941
941
  };
942
942
  }
943
943
 
944
- export { RECORD_VERSION, STATE_VERSION, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, observe, predict, serialize, shouldReveal };
944
+ // src/units.ts
945
+ var ms = {
946
+ seconds: (n) => n * 1e3,
947
+ minutes: (n) => n * 6e4,
948
+ hours: (n) => n * 36e5,
949
+ days: (n) => n * 864e5,
950
+ weeks: (n) => n * 6048e5
951
+ };
952
+
953
+ // src/validate.ts
954
+ function validateConfig(config) {
955
+ return normalizeConfig(config);
956
+ }
957
+
958
+ export { RECORD_VERSION, STATE_VERSION, createEndRecord, createRecord, createState, deserialize, endEpisode, episodeClosed, evaluate, evidenceToReveal, explain, markRevealed, ms, observe, predict, serialize, shouldReveal, validateConfig };
945
959
  //# sourceMappingURL=index.js.map
946
960
  //# sourceMappingURL=index.js.map