@xyo-network/diviner-forecasting-memory 5.3.22 → 5.3.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-forecasting-memory",
3
- "version": "5.3.22",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,51 +30,47 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
35
  "!**/*.test.*",
37
36
  "README.md"
38
37
  ],
39
38
  "dependencies": {
40
- "@xyo-network/archivist-model": "~5.3.22",
41
- "@xyo-network/diviner-boundwitness-model": "~5.3.22",
42
- "@xyo-network/diviner-forecasting-abstract": "~5.3.22",
43
- "@xyo-network/diviner-forecasting-method-arima": "~5.3.22",
44
- "@xyo-network/diviner-forecasting-model": "~5.3.22",
45
- "@xyo-network/diviner-model": "~5.3.22",
46
- "@xyo-network/module-model": "~5.3.22",
47
- "@xyo-network/payload-model": "~5.3.22",
48
- "jsonpath": "~1.3.0"
39
+ "jsonpath": "~1.3.0",
40
+ "@xyo-network/diviner-boundwitness-model": "~5.3.24",
41
+ "@xyo-network/diviner-forecasting-abstract": "~5.3.24",
42
+ "@xyo-network/diviner-forecasting-method-arima": "~5.3.24",
43
+ "@xyo-network/diviner-forecasting-model": "~5.3.24",
44
+ "@xyo-network/diviner-model": "~5.3.24",
45
+ "@xyo-network/module-model": "~5.3.24",
46
+ "@xyo-network/archivist-model": "~5.3.24",
47
+ "@xyo-network/payload-model": "~5.3.24"
49
48
  },
50
49
  "devDependencies": {
51
50
  "@opentelemetry/api": "^1.9.1",
52
51
  "@types/jsonpath": "~0.2.4",
53
52
  "@types/node": "^25.5.0",
54
- "@xylabs/sdk-js": "^5.0.91",
55
- "@xylabs/ts-scripts-common": "~7.6.8",
56
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
57
- "@xylabs/tsconfig": "~7.6.8",
58
- "@xyo-network/archivist-model": "~5.3.22",
59
- "@xyo-network/boundwitness-model": "~5.3.22",
60
- "@xyo-network/diviner-boundwitness-model": "~5.3.22",
61
- "@xyo-network/diviner-forecasting-abstract": "~5.3.22",
62
- "@xyo-network/diviner-forecasting-method-arima": "~5.3.22",
63
- "@xyo-network/diviner-forecasting-model": "~5.3.22",
64
- "@xyo-network/diviner-model": "~5.3.22",
65
- "@xyo-network/module-model": "~5.3.22",
66
- "@xyo-network/payload-model": "~5.3.22",
53
+ "@xylabs/sdk-js": "^5.0.93",
54
+ "@xylabs/ts-scripts-common": "~7.6.16",
55
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
56
+ "@xylabs/tsconfig": "~7.6.16",
67
57
  "acorn": "^8.16.0",
68
58
  "axios": "^1.14.0",
69
- "cosmiconfig": "^9.0.1",
70
- "esbuild": "^0.27.4",
71
- "eslint": "^10.1.0",
59
+ "esbuild": "^0.28.0",
72
60
  "ethers": "^6.16.0",
73
61
  "jsonpath": "~1.3.0",
74
- "rollup": "^4.60.1",
75
62
  "tslib": "^2.8.1",
76
63
  "typescript": "~5.9.3",
77
- "zod": "^4.3.6"
64
+ "zod": "^4.3.6",
65
+ "@xyo-network/archivist-model": "~5.3.24",
66
+ "@xyo-network/boundwitness-model": "~5.3.24",
67
+ "@xyo-network/diviner-forecasting-abstract": "~5.3.24",
68
+ "@xyo-network/diviner-boundwitness-model": "~5.3.24",
69
+ "@xyo-network/diviner-forecasting-method-arima": "~5.3.24",
70
+ "@xyo-network/diviner-forecasting-model": "~5.3.24",
71
+ "@xyo-network/module-model": "~5.3.24",
72
+ "@xyo-network/payload-model": "~5.3.24",
73
+ "@xyo-network/diviner-model": "~5.3.24"
78
74
  },
79
75
  "peerDependencies": {
80
76
  "@xylabs/sdk-js": "^5",
@@ -85,4 +81,4 @@
85
81
  "publishConfig": {
86
82
  "access": "public"
87
83
  }
88
- }
84
+ }
@@ -1,126 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import { assertEx, exists } from '@xylabs/sdk-js'
3
- import { asArchivistInstance } from '@xyo-network/archivist-model'
4
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
6
- import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
7
- import type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'
8
- import { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract'
9
- import type {
10
- arimaForecastingName,
11
- seasonalArimaForecastingName,
12
- } from '@xyo-network/diviner-forecasting-method-arima'
13
- import {
14
- arimaForecastingMethod,
15
- seasonalArimaForecastingMethod,
16
- } from '@xyo-network/diviner-forecasting-method-arima'
17
- import type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'
18
- import { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model'
19
- import type { DivinerInstance } from '@xyo-network/diviner-model'
20
- import { asDivinerInstance } from '@xyo-network/diviner-model'
21
- import type { ModuleIdentifier } from '@xyo-network/module-model'
22
- import type { Payload, Schema } from '@xyo-network/payload-model'
23
- import jsonpath from 'jsonpath'
24
-
25
- export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName
26
-
27
- const getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {
28
- return (x: Payload): number => {
29
- const ret = jsonpath.value(x, pathExpression)
30
- if (typeof ret === 'number') return ret
31
- throw new Error('Parsed invalid payload value')
32
- }
33
- }
34
-
35
- const defaultBatchLimit = 1000
36
- const defaultMaxTrainingLength = 10_000
37
-
38
- export class MemoryForecastingDiviner<
39
- TParams extends ForecastingDivinerParams = ForecastingDivinerParams,
40
- > extends AbstractForecastingDiviner<TParams> {
41
- static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]
42
- static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema
43
-
44
- protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {
45
- arimaForecasting: arimaForecastingMethod,
46
- seasonalArimaForecasting: seasonalArimaForecastingMethod,
47
- }
48
-
49
- get boundWitnessDiviner(): ModuleIdentifier {
50
- return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured') as ModuleIdentifier
51
- }
52
-
53
- /**
54
- * The max number of records to search during the batch query
55
- */
56
- protected get batchLimit() {
57
- return this.config.batchLimit ?? defaultBatchLimit
58
- }
59
-
60
- protected override get forecastingMethod(): ForecastingMethod {
61
- const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType
62
- const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]
63
- if (forecastingMethod) return forecastingMethod
64
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)
65
- }
66
-
67
- protected get maxTrainingLength() {
68
- return this.config.maxTrainingLength ?? defaultMaxTrainingLength
69
- }
70
-
71
- protected override get transformer(): PayloadValueTransformer {
72
- const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')
73
- return getJsonPathTransformer(pathExpression)
74
- }
75
-
76
- protected override async getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]> {
77
- const addresses = this.config.witnessAddresses
78
- const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]
79
- const payloads: Payload[] = []
80
- const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist', { required: true })
81
- const bwDiviner = asDivinerInstance(
82
- await this.resolve(this.boundWitnessDiviner),
83
- 'Unable to resolve boundWitnessDiviner',
84
- ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>
85
- const limit = this.batchLimit
86
- const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')
87
- // let timestamp = stopTimestamp
88
- let more = true
89
-
90
- // TODO: Window size vs sample size
91
- // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window
92
- while (more || payloads.length < this.maxTrainingLength) {
93
- const query: BoundWitnessDivinerQueryPayload = {
94
- addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema,
95
- }
96
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
97
- // TODO; Replace with sequence
98
- // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,
99
- _ => true,
100
- )
101
- if (boundWitnesses.length === 0) break
102
-
103
- // Update the timestamp value for the next batch
104
- /* timestamp = boundWitnesses
105
- .map(bw => bw.$timestamp)
106
- .filter(exists)
107
- // eslint-disable-next-line unicorn/no-array-reduce
108
- .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)
109
- if (timestamp === Number.MAX_SAFE_INTEGER) break
110
- */
111
-
112
- // Set the more flag to false if there are fewer documents returned than the batch size
113
- more = boundWitnesses.length === limit
114
-
115
- // Get the corresponding payload hashes from the BWs
116
- const hashes = (boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]) as Hash[]).filter(exists)
117
-
118
- // Get the payloads corresponding to the BW hashes from the archivist
119
- if (hashes.length > 0) {
120
- const batchPayloads = (await archivist.get(hashes)).filter(exists)
121
- payloads.push(...batchPayloads)
122
- }
123
- }
124
- return payloads
125
- }
126
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './MemoryForecastingDiviner.ts'