@metamask-previews/ai-controllers 0.8.0-preview-5b293ee50 → 0.8.0-preview-3866c0ff1
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/CHANGELOG.md +1 -0
- package/dist/{AiDigestController-method-action-types.d.mts → AiDigestController-method-action-types.d.ts} +2 -2
- package/dist/AiDigestController-method-action-types.d.ts.map +1 -0
- package/dist/{AiDigestController-method-action-types.mjs → AiDigestController-method-action-types.js} +1 -1
- package/dist/AiDigestController-method-action-types.js.map +1 -0
- package/dist/{AiDigestController.d.cts → AiDigestController.d.ts} +7 -7
- package/dist/AiDigestController.d.ts.map +1 -0
- package/dist/{AiDigestController.mjs → AiDigestController.js} +35 -43
- package/dist/AiDigestController.js.map +1 -0
- package/dist/{AiDigestService.d.cts → AiDigestService.d.ts} +2 -2
- package/dist/AiDigestService.d.ts.map +1 -0
- package/dist/{AiDigestService.mjs → AiDigestService.js} +8 -21
- package/dist/AiDigestService.js.map +1 -0
- package/dist/ai-digest-constants.d.ts +10 -0
- package/dist/ai-digest-constants.d.ts.map +1 -0
- package/dist/{ai-digest-constants.mjs → ai-digest-constants.js} +1 -1
- package/dist/ai-digest-constants.js.map +1 -0
- package/dist/{ai-digest-types.d.cts → ai-digest-types.d.ts} +1 -1
- package/dist/ai-digest-types.d.ts.map +1 -0
- package/dist/{ai-digest-types.mjs → ai-digest-types.js} +1 -1
- package/dist/ai-digest-types.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +8 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +12 -16
- package/dist/AiDigestController-method-action-types.cjs +0 -7
- package/dist/AiDigestController-method-action-types.cjs.map +0 -1
- package/dist/AiDigestController-method-action-types.d.cts +0 -49
- package/dist/AiDigestController-method-action-types.d.cts.map +0 -1
- package/dist/AiDigestController-method-action-types.d.mts.map +0 -1
- package/dist/AiDigestController-method-action-types.mjs.map +0 -1
- package/dist/AiDigestController.cjs +0 -173
- package/dist/AiDigestController.cjs.map +0 -1
- package/dist/AiDigestController.d.cts.map +0 -1
- package/dist/AiDigestController.d.mts +0 -52
- package/dist/AiDigestController.d.mts.map +0 -1
- package/dist/AiDigestController.mjs.map +0 -1
- package/dist/AiDigestService.cjs +0 -217
- package/dist/AiDigestService.cjs.map +0 -1
- package/dist/AiDigestService.d.cts.map +0 -1
- package/dist/AiDigestService.d.mts +0 -40
- package/dist/AiDigestService.d.mts.map +0 -1
- package/dist/AiDigestService.mjs.map +0 -1
- package/dist/ai-digest-constants.cjs +0 -13
- package/dist/ai-digest-constants.cjs.map +0 -1
- package/dist/ai-digest-constants.d.cts +0 -10
- package/dist/ai-digest-constants.d.cts.map +0 -1
- package/dist/ai-digest-constants.d.mts +0 -10
- package/dist/ai-digest-constants.d.mts.map +0 -1
- package/dist/ai-digest-constants.mjs.map +0 -1
- package/dist/ai-digest-types.cjs +0 -6
- package/dist/ai-digest-types.cjs.map +0 -1
- package/dist/ai-digest-types.d.cts.map +0 -1
- package/dist/ai-digest-types.d.mts +0 -214
- package/dist/ai-digest-types.d.mts.map +0 -1
- package/dist/ai-digest-types.mjs.map +0 -1
- package/dist/index.cjs +0 -14
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -8
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
12
13
|
- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#9754](https://github.com/MetaMask/core/pull/9754))
|
|
13
14
|
|
|
14
15
|
## [0.8.0]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { AiDigestController } from
|
|
5
|
+
import type { AiDigestController } from './AiDigestController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Fetches market insights for a given asset identifier.
|
|
8
8
|
* Returns cached data if still fresh, otherwise calls the service.
|
|
@@ -46,4 +46,4 @@ export type AiDigestControllerFetchFrontPageItemAction = {
|
|
|
46
46
|
* Union of all AiDigestController action types.
|
|
47
47
|
*/
|
|
48
48
|
export type AiDigestControllerMethodActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerFetchMarketOverviewAction | AiDigestControllerFetchFrontPageItemAction;
|
|
49
|
-
//# sourceMappingURL=AiDigestController-method-action-types.d.
|
|
49
|
+
//# sourceMappingURL=AiDigestController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController-method-action-types.d.ts","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,2CAA2C,GAC3C,2CAA2C,GAC3C,0CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController-method-action-types.js","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AiDigestController } from './AiDigestController.js';\n\n/**\n * Fetches market insights for a given asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps\n * market symbol (e.g. `ETH`). The service handles choosing the correct API\n * query parameter automatically.\n *\n * @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).\n * @returns The market insights report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `AiDigestController:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\n/**\n * Fetches the market overview report.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @returns The market overview report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketOverviewAction = {\n type: `AiDigestController:fetchMarketOverview`;\n handler: AiDigestController['fetchMarketOverview'];\n};\n\n/**\n * Fetches a single market overview front page by id.\n *\n * Unlike the market overview report (which only returns the latest items),\n * this resolves an older item that has since dropped out of the report, so\n * clients can render it directly (e.g. from a deep link).\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists.\n */\nexport type AiDigestControllerFetchFrontPageItemAction = {\n type: `AiDigestController:fetchFrontPageItem`;\n handler: AiDigestController['fetchFrontPageItem'];\n};\n\n/**\n * Union of all AiDigestController action types.\n */\nexport type AiDigestControllerMethodActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerFetchMarketOverviewAction\n | AiDigestControllerFetchFrontPageItemAction;\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ControllerStateChangeEvent, ControllerGetStateAction } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import { controllerName } from
|
|
5
|
-
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from
|
|
6
|
-
import type { AiDigestControllerMethodActions } from
|
|
1
|
+
import type { ControllerStateChangeEvent, ControllerGetStateAction } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import { controllerName } from './ai-digest-constants.js';
|
|
5
|
+
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from './ai-digest-types.js';
|
|
6
|
+
import type { AiDigestControllerMethodActions } from './AiDigestController-method-action-types.js';
|
|
7
7
|
export type AiDigestControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AiDigestControllerState>;
|
|
8
8
|
export type AiDigestControllerActions = AiDigestControllerGetStateAction | AiDigestControllerMethodActions;
|
|
9
9
|
export type AiDigestControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AiDigestControllerState>;
|
|
@@ -49,4 +49,4 @@ export declare class AiDigestController extends BaseController<typeof controller
|
|
|
49
49
|
*/
|
|
50
50
|
fetchFrontPageItem(id: string): Promise<MarketOverviewFrontPage | null>;
|
|
51
51
|
}
|
|
52
|
-
//# sourceMappingURL=AiDigestController.d.
|
|
52
|
+
//# sourceMappingURL=AiDigestController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.d.ts","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAEL,cAA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AAG,IAAI,CAAC,CAMzC;CAmCF"}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _AiDigestController_instances, _AiDigestController_digestService, _AiDigestController_evictStaleCachedEntries;
|
|
13
|
-
import { BaseController } from "@metamask/base-controller";
|
|
14
|
-
import { AiDigestControllerErrorMessage, controllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES } from "./ai-digest-constants.mjs";
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import { AiDigestControllerErrorMessage, controllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, } from './ai-digest-constants.js';
|
|
15
3
|
export function getDefaultAiDigestControllerState() {
|
|
16
4
|
return {
|
|
17
5
|
marketInsights: {},
|
|
@@ -38,6 +26,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
38
26
|
'fetchFrontPageItem',
|
|
39
27
|
];
|
|
40
28
|
export class AiDigestController extends BaseController {
|
|
29
|
+
#digestService;
|
|
41
30
|
constructor({ messenger, state, digestService }) {
|
|
42
31
|
super({
|
|
43
32
|
name: controllerName,
|
|
@@ -48,9 +37,7 @@ export class AiDigestController extends BaseController {
|
|
|
48
37
|
},
|
|
49
38
|
messenger,
|
|
50
39
|
});
|
|
51
|
-
|
|
52
|
-
_AiDigestController_digestService.set(this, void 0);
|
|
53
|
-
__classPrivateFieldSet(this, _AiDigestController_digestService, digestService, "f");
|
|
40
|
+
this.#digestService = digestService;
|
|
54
41
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
55
42
|
}
|
|
56
43
|
/**
|
|
@@ -75,7 +62,7 @@ export class AiDigestController extends BaseController {
|
|
|
75
62
|
return existing.data;
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
|
-
const data = await
|
|
65
|
+
const data = await this.#digestService.searchDigest(assetIdentifier);
|
|
79
66
|
if (data === null) {
|
|
80
67
|
// No insights available for this asset — clear any stale cache entry
|
|
81
68
|
this.update((state) => {
|
|
@@ -90,7 +77,7 @@ export class AiDigestController extends BaseController {
|
|
|
90
77
|
};
|
|
91
78
|
this.update((state) => {
|
|
92
79
|
state.marketInsights[assetIdentifier] = entry;
|
|
93
|
-
|
|
80
|
+
this.#evictStaleCachedEntries(state.marketInsights);
|
|
94
81
|
});
|
|
95
82
|
return data;
|
|
96
83
|
}
|
|
@@ -108,7 +95,7 @@ export class AiDigestController extends BaseController {
|
|
|
108
95
|
return existing.data;
|
|
109
96
|
}
|
|
110
97
|
}
|
|
111
|
-
const data = await
|
|
98
|
+
const data = await this.#digestService.fetchMarketOverview();
|
|
112
99
|
if (data === null) {
|
|
113
100
|
this.update((state) => {
|
|
114
101
|
state.marketOverview = null;
|
|
@@ -138,31 +125,36 @@ export class AiDigestController extends BaseController {
|
|
|
138
125
|
if (!id) {
|
|
139
126
|
throw new Error(AiDigestControllerErrorMessage.INVALID_FRONT_PAGE_ID);
|
|
140
127
|
}
|
|
141
|
-
return
|
|
128
|
+
return this.#digestService.fetchFrontPageItem(id);
|
|
142
129
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Evicts stale (TTL expired) and oldest entries (FIFO) if cache exceeds max size.
|
|
132
|
+
*
|
|
133
|
+
* @param cache - The cache record to evict entries from.
|
|
134
|
+
*/
|
|
135
|
+
#evictStaleCachedEntries(cache) {
|
|
136
|
+
const now = Date.now();
|
|
137
|
+
const entries = Object.entries(cache);
|
|
138
|
+
const keysToDelete = [];
|
|
139
|
+
const freshEntries = [];
|
|
140
|
+
for (const [key, entry] of entries) {
|
|
141
|
+
if (now - entry.fetchedAt >= CACHE_DURATION_MS) {
|
|
142
|
+
keysToDelete.push(key);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
freshEntries.push([key, entry]);
|
|
146
|
+
}
|
|
152
147
|
}
|
|
153
|
-
|
|
154
|
-
freshEntries.
|
|
148
|
+
if (freshEntries.length > MAX_CACHE_ENTRIES) {
|
|
149
|
+
freshEntries.sort((a, b) => a[1].fetchedAt - b[1].fetchedAt);
|
|
150
|
+
const entriesToRemove = freshEntries.length - MAX_CACHE_ENTRIES;
|
|
151
|
+
for (let i = 0; i < entriesToRemove; i++) {
|
|
152
|
+
keysToDelete.push(freshEntries[i][0]);
|
|
153
|
+
}
|
|
155
154
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
freshEntries.sort((a, b) => a[1].fetchedAt - b[1].fetchedAt);
|
|
159
|
-
const entriesToRemove = freshEntries.length - MAX_CACHE_ENTRIES;
|
|
160
|
-
for (let i = 0; i < entriesToRemove; i++) {
|
|
161
|
-
keysToDelete.push(freshEntries[i][0]);
|
|
155
|
+
for (const key of keysToDelete) {
|
|
156
|
+
delete cache[key];
|
|
162
157
|
}
|
|
163
158
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
//# sourceMappingURL=AiDigestController.mjs.map
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=AiDigestController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.js","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EACL,8BAA8B,EAC9B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAwClC,MAAM,UAAU,iCAAiC;IAC/C,OAAO;QACL,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,IAAI;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,0BAA0B,GAA2C;IACzE,cAAc,EAAE;QACd,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,cAAc,EAAE;QACd,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,yBAAyB,GAAG;IAChC,qBAAqB;IACrB,qBAAqB;IACrB,oBAAoB;CACZ,CAAC;AAEX,MAAM,OAAO,kBAAmB,SAAQ,cAIvC;IACU,cAAc,CAAgB;IAEvC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAA6B;QACxE,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,0BAA0B;YACpC,KAAK,EAAE;gBACL,GAAG,iCAAiC,EAAE;gBACtC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,mBAAmB,CACvB,eAAuB;QAEvB,IAAI,CAAC,eAAe,EAA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AS,IAAI,iBAAiB,EAAE,CAAC;gBAC/C,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACN,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,IAAI,YAAY,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;YAC5C,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAC7D,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,GAAG,iBAAiB,CAAC;YAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;gBACzC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n StateMetadata,\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport {\n AiDigestControllerErrorMessage,\n controllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n} from './ai-digest-constants.js';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketInsightsEntry,\n MarketOverview,\n MarketOverviewEntry,\n MarketOverviewFrontPage,\n} from './ai-digest-types.js';\nimport type { AiDigestControllerMethodActions } from './AiDigestController-method-action-types.js';\n\nexport type AiDigestControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerActions =\n | AiDigestControllerGetStateAction\n | AiDigestControllerMethodActions;\n\nexport type AiDigestControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AiDigestControllerState\n>;\n\nexport type AiDigestControllerEvents = AiDigestControllerStateChangeEvent;\n\nexport type AiDigestControllerMessenger = Messenger<\n typeof controllerName,\n AiDigestControllerActions,\n AiDigestControllerEvents\n>;\n\nexport type AiDigestControllerOptions = {\n messenger: AiDigestControllerMessenger;\n state?: Partial<AiDigestControllerState>;\n digestService: DigestService;\n};\n\nexport function getDefaultAiDigestControllerState(): AiDigestControllerState {\n return {\n marketInsights: {},\n marketOverview: null,\n };\n}\n\nconst aiDigestControllerMetadata: StateMetadata<AiDigestControllerState> = {\n marketInsights: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n marketOverview: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n};\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchMarketInsights',\n 'fetchMarketOverview',\n 'fetchFrontPageItem',\n] as const;\n\nexport class AiDigestController extends BaseController<\n typeof controllerName,\n AiDigestControllerState,\n AiDigestControllerMessenger\n> {\n readonly #digestService: DigestService;\n\n constructor({ messenger, state, digestService }: AiDigestControllerOptions) {\n super({\n name: controllerName,\n metadata: aiDigestControllerMetadata,\n state: {\n ...getDefaultAiDigestControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#digestService = digestService;\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches market insights for a given asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps\n * market symbol (e.g. `ETH`). The service handles choosing the correct API\n * query parameter automatically.\n *\n * @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).\n * @returns The market insights report, or `null` if none exists.\n */\n async fetchMarketInsights(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n if (!assetIdentifier) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_ASSET_IDENTIFIER);\n }\n\n const existing = this.state.marketInsights[assetIdentifier];\n if (existing) {\n const age = Date.now() - existing.fetchedAt;\n if (age < CACHE_DURATION_MS) {\n return existing.data;\n }\n }\n\n const data = await this.#digestService.searchDigest(assetIdentifier);\n\n if (data === null) {\n // No insights available for this asset — clear any stale cache entry\n this.update((state) => {\n delete state.marketInsights[assetIdentifier];\n });\n return null;\n }\n\n const entry: MarketInsightsEntry = {\n assetIdentifier,\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketInsights[assetIdentifier] = entry;\n this.#evictStaleCachedEntries(state.marketInsights);\n });\n\n return data;\n }\n\n /**\n * Fetches the market overview report.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @returns The market overview report, or `null` if none exists.\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const existing = this.state.marketOverview;\n if (existing) {\n const age = Date.now() - existing.fetchedAt;\n if (age < CACHE_DURATION_MS) {\n return existing.data;\n }\n }\n\n const data = await this.#digestService.fetchMarketOverview();\n\n if (data === null) {\n this.update((state) => {\n state.marketOverview = null;\n });\n return null;\n }\n\n const entry: MarketOverviewEntry = {\n fetchedAt: Date.now(),\n data,\n };\n\n this.update((state) => {\n state.marketOverview = entry;\n });\n\n return data;\n }\n\n /**\n * Fetches a single market overview front page by id.\n *\n * Unlike the market overview report (which only returns the latest items),\n * this resolves an older item that has since dropped out of the report, so\n * clients can render it directly (e.g. from a deep link).\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists.\n */\n async fetchFrontPageItem(\n id: string,\n ): Promise<MarketOverviewFrontPage | null> {\n if (!id) {\n throw new Error(AiDigestControllerErrorMessage.INVALID_FRONT_PAGE_ID);\n }\n\n return this.#digestService.fetchFrontPageItem(id);\n }\n\n /**\n * Evicts stale (TTL expired) and oldest entries (FIFO) if cache exceeds max size.\n *\n * @param cache - The cache record to evict entries from.\n */\n #evictStaleCachedEntries<EntryType extends { fetchedAt: number }>(\n cache: Record<string, EntryType>,\n ): void {\n const now = Date.now();\n const entries = Object.entries(cache);\n const keysToDelete: string[] = [];\n const freshEntries: [string, EntryType][] = [];\n\n for (const [key, entry] of entries) {\n if (now - entry.fetchedAt >= CACHE_DURATION_MS) {\n keysToDelete.push(key);\n } else {\n freshEntries.push([key, entry]);\n }\n }\n\n if (freshEntries.length > MAX_CACHE_ENTRIES) {\n freshEntries.sort((a, b) => a[1].fetchedAt - b[1].fetchedAt);\n const entriesToRemove = freshEntries.length - MAX_CACHE_ENTRIES;\n for (let i = 0; i < entriesToRemove; i++) {\n keysToDelete.push(freshEntries[i][0]);\n }\n }\n\n for (const key of keysToDelete) {\n delete cache[key];\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from
|
|
1
|
+
import type { DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from './ai-digest-types.js';
|
|
2
2
|
export type AiDigestServiceConfig = {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
};
|
|
@@ -37,4 +37,4 @@ export declare class AiDigestService implements DigestService {
|
|
|
37
37
|
*/
|
|
38
38
|
searchDigest(assetIdentifier: string): Promise<MarketInsightsReport | null>;
|
|
39
39
|
}
|
|
40
|
-
//# sourceMappingURL=AiDigestService.d.
|
|
40
|
+
//# sourceMappingURL=AiDigestService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestService.d.ts","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EAExB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA2JF,qBAAa,eAAgB,YAAW,aAAa;;IAGnD,YAAY,MAAM,EAAE,qBAAqB,EAExC;IAED;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAoB1D;IAED;;;;;;;OAOG;IACG,kBAAkB,CACtB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAsBzC;IAED;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAsBtC;CACF"}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _AiDigestService_baseUrl;
|
|
13
|
-
import { array, enums, is, optional, string, type as structType } from "@metamask/superstruct";
|
|
14
|
-
import { AiDigestControllerErrorMessage } from "./ai-digest-constants.mjs";
|
|
1
|
+
import { array, enums, is, optional, string, type as structType, } from '@metamask/superstruct';
|
|
2
|
+
import { AiDigestControllerErrorMessage } from './ai-digest-constants.js';
|
|
15
3
|
// Shared sub-type structs
|
|
16
4
|
const ArticleStruct = structType({
|
|
17
5
|
title: string(),
|
|
@@ -134,9 +122,9 @@ const getNormalizedMarketInsightsReport = (value) => {
|
|
|
134
122
|
return null;
|
|
135
123
|
};
|
|
136
124
|
export class AiDigestService {
|
|
125
|
+
#baseUrl;
|
|
137
126
|
constructor(config) {
|
|
138
|
-
|
|
139
|
-
__classPrivateFieldSet(this, _AiDigestService_baseUrl, config.baseUrl, "f");
|
|
127
|
+
this.#baseUrl = config.baseUrl;
|
|
140
128
|
}
|
|
141
129
|
/**
|
|
142
130
|
* Fetch the market overview report.
|
|
@@ -146,7 +134,7 @@ export class AiDigestService {
|
|
|
146
134
|
* @returns The market overview report, or `null` if none exists (404).
|
|
147
135
|
*/
|
|
148
136
|
async fetchMarketOverview() {
|
|
149
|
-
const response = await fetch(`${
|
|
137
|
+
const response = await fetch(`${this.#baseUrl}/market-overview`);
|
|
150
138
|
if (response.status === 404) {
|
|
151
139
|
return null;
|
|
152
140
|
}
|
|
@@ -168,7 +156,7 @@ export class AiDigestService {
|
|
|
168
156
|
* @returns The market overview front page, or `null` if none exists (404).
|
|
169
157
|
*/
|
|
170
158
|
async fetchFrontPageItem(id) {
|
|
171
|
-
const response = await fetch(`${
|
|
159
|
+
const response = await fetch(`${this.#baseUrl}/market-overview/front-page/${encodeURIComponent(id)}`);
|
|
172
160
|
if (response.status === 404) {
|
|
173
161
|
return null;
|
|
174
162
|
}
|
|
@@ -195,7 +183,7 @@ export class AiDigestService {
|
|
|
195
183
|
* @returns The market insights report, or `null` if none exists (404).
|
|
196
184
|
*/
|
|
197
185
|
async searchDigest(assetIdentifier) {
|
|
198
|
-
const response = await fetch(`${
|
|
186
|
+
const response = await fetch(`${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`);
|
|
199
187
|
if (response.status === 404) {
|
|
200
188
|
return null;
|
|
201
189
|
}
|
|
@@ -209,5 +197,4 @@ export class AiDigestService {
|
|
|
209
197
|
return report;
|
|
210
198
|
}
|
|
211
199
|
}
|
|
212
|
-
|
|
213
|
-
//# sourceMappingURL=AiDigestService.mjs.map
|
|
200
|
+
//# sourceMappingURL=AiDigestService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestService.js","sourceRoot":"","sources":["../src/AiDigestService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,EAAE,EACF,QAAQ,EACR,MAAM,EACN,IAAI,IAAI,UAAU,GACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAa1E,0BAA0B;AAE1B,MAAM,aAAa,GAAG,UAAU,CAAC;IAC/B,KAAK,EAAE,MAAM,EAAE;IACf,GAAG,EAAE,MAAM,EAAE;IACb,MAAM,EAAE,MAAM,EAAE;IAChB,IAAI,EAAE,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,UAAU,CAAC;IAC7B,cAAc,EAAE,MAAM,EAAE;IACxB,GAAG,EAAE,MAAM,EAAE;IACb,MAAM,EAAE,MAAM,EAAE;IAChB,IAAI,EAAE,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,UAAU,CAAC;IAC9B,IAAI,EAAE,MAAM,EAAE;IACd,GAAG,EAAE,MAAM,EAAE;IACb,IAAI,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;CACjD,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,UAAU,CAAC;IAC1C,QAAQ,EAAE,MAAM,EAAE;CACnB,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG;IAC1B,cAAc;IACd,OAAO;IACP,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,OAAO;CACC,CAAC;AAEX,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,CAAU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Q,GAAG,MAAM,KAAK,CAC1B,GAAG,IAAI,CAAC,QAAQ,wBAAwB,kBAAkB,CAAC,eAAe,CAAC,EAAE,CAC9E,CAAC;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,GAAG,8BAA8B,CAAC,kBAAkB,KAAK,QAAQ,CAAC,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,oBAAoB,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n array,\n enums,\n is,\n optional,\n string,\n type as structType,\n} from '@metamask/superstruct';\n\nimport { AiDigestControllerErrorMessage } from './ai-digest-constants.js';\nimport type {\n DigestService,\n MarketInsightsReport,\n MarketOverview,\n MarketOverviewFrontPage,\n MarketOverviewTrend,\n} from './ai-digest-types.js';\n\nexport type AiDigestServiceConfig = {\n baseUrl: string;\n};\n\n// Shared sub-type structs\n\nconst ArticleStruct = structType({\n title: string(),\n url: string(),\n source: string(),\n date: string(),\n});\n\nconst TweetStruct = structType({\n contentSummary: string(),\n url: string(),\n author: string(),\n date: string(),\n});\n\nconst SourceStruct = structType({\n name: string(),\n url: string(),\n type: enums(['news', 'data', 'social'] as const),\n});\n\nconst AIResponseMetadataStruct = structType({\n provider: string(),\n});\n\nconst trendCategoryValues = [\n 'geopolitical',\n 'macro',\n 'regulatory',\n 'technical',\n 'social',\n 'other',\n] as const;\n\nconst trendImpactValues = ['positive', 'negative', 'neutral'] as const;\n\n// Market Insights structs\n\nconst MarketInsightsTrendStruct = structType({\n title: string(),\n description: string(),\n category: enums(trendCategoryValues),\n impact: enums(trendImpactValues),\n articles: array(ArticleStruct),\n tweets: array(TweetStruct),\n});\n\nconst MarketInsightsReportStruct = structType({\n version: optional(string()),\n asset: string(),\n generatedAt: string(),\n headline: string(),\n summary: string(),\n trends: array(MarketInsightsTrendStruct),\n social: optional(array(TweetStruct)),\n sources: array(SourceStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketInsightsDigestEnvelopeStruct = structType({\n id: string(),\n digest: MarketInsightsReportStruct,\n});\n\n// Market Overview structs\n\nconst RelatedAssetStruct = structType({\n name: optional(string()),\n symbol: string(),\n caip19: optional(array(string())),\n sourceAssetId: optional(string()),\n hlPerpsMarket: optional(array(string())),\n});\n\nconst MarketOverviewTrendStruct = structType({\n title: string(),\n description: string(),\n category: optional(enums(trendCategoryValues)),\n impact: optional(enums(trendImpactValues)),\n articles: array(ArticleStruct),\n relatedAssets: array(RelatedAssetStruct),\n});\n\nconst MarketOverviewStruct = structType({\n version: optional(string()),\n generatedAt: string(),\n trends: array(MarketOverviewTrendStruct),\n metadata: optional(array(AIResponseMetadataStruct)),\n});\n\nconst MarketOverviewReportEnvelopeStruct = structType({\n report: MarketOverviewStruct,\n});\n\n// A single front-page row. `item` shares the exact same schema as an\n// individual market overview trend; `ctaTitle`/`ctaDescription` are the\n// AI-authored call-to-action copy layered on top.\nconst MarketOverviewFrontPageStruct = structType({\n id: string(),\n item: MarketOverviewTrendStruct,\n ctaTitle: string(),\n ctaDescription: string(),\n createdAt: string(),\n});\n\nconst normalizeItemRelatedAssets = (\n item: MarketOverviewTrend,\n): MarketOverviewTrend => ({\n ...item,\n relatedAssets: item.relatedAssets.map((asset) => ({\n ...asset,\n caip19: asset.caip19 ?? [],\n })),\n});\n\nconst normalizeRelatedAssets = (raw: MarketOverview): MarketOverview => ({\n ...raw,\n trends: raw.trends.map(normalizeItemRelatedAssets),\n});\n\nconst getNormalizedMarketOverview = (value: unknown): MarketOverview | null => {\n if (is(value, MarketOverviewStruct)) {\n return normalizeRelatedAssets(value);\n }\n\n if (is(value, MarketOverviewReportEnvelopeStruct)) {\n return normalizeRelatedAssets(value.report);\n }\n\n return null;\n};\n\nconst getNormalizedFrontPage = (\n value: unknown,\n): MarketOverviewFrontPage | null => {\n if (!is(value, MarketOverviewFrontPageStruct)) {\n return null;\n }\n\n return { ...value, item: normalizeItemRelatedAssets(value.item) };\n};\n\nconst getNormalizedMarketInsightsReport = (\n value: unknown,\n): MarketInsightsReport | null => {\n if (is(value, MarketInsightsDigestEnvelopeStruct)) {\n return { ...value.digest, digestId: value.id };\n }\n\n return null;\n};\n\nexport class AiDigestService implements DigestService {\n readonly #baseUrl: string;\n\n constructor(config: AiDigestServiceConfig) {\n this.#baseUrl = config.baseUrl;\n }\n\n /**\n * Fetch the market overview report.\n *\n * Calls `GET ${this.#baseUrl}/market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n const response = await fetch(`${this.#baseUrl}/market-overview`);\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const overview = getNormalizedMarketOverview(await response.json());\n\n if (!overview) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return overview;\n }\n\n /**\n * Fetch a single market overview front page by id.\n *\n * Calls `GET ${this.#baseUrl}/market-overview/front-page/:id`.\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists (404).\n */\n async fetchFrontPageItem(\n id: string,\n ): Promise<MarketOverviewFrontPage | null> {\n const response = await fetch(\n `${this.#baseUrl}/market-overview/front-page/${encodeURIComponent(id)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const frontPage = getNormalizedFrontPage(await response.json());\n\n if (!frontPage) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return frontPage;\n }\n\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands (CAIP-19 asset type, ticker\n * symbol, asset name, HyperLiquid perps market id, etc.) and forwards it\n * unchanged via the universal `asset` query parameter.\n *\n * Calls `GET ${baseUrl}/asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier (e.g. `eip155:1/slip44:60`,\n * `ETH`, `Bitcoin`, `xyz:TSLA`).\n * @returns The market insights report, or `null` if none exists (404).\n */\n async searchDigest(\n assetIdentifier: string,\n ): Promise<MarketInsightsReport | null> {\n const response = await fetch(\n `${this.#baseUrl}/asset-summary?asset=${encodeURIComponent(assetIdentifier)}`,\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new Error(\n `${AiDigestControllerErrorMessage.API_REQUEST_FAILED}: ${response.status}`,\n );\n }\n\n const report = getNormalizedMarketInsightsReport(await response.json());\n\n if (!report) {\n throw new Error(AiDigestControllerErrorMessage.API_INVALID_RESPONSE);\n }\n\n return report;\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const controllerName = "AiDigestController";
|
|
2
|
+
export declare const CACHE_DURATION_MS: number;
|
|
3
|
+
export declare const MAX_CACHE_ENTRIES = 50;
|
|
4
|
+
export declare const AiDigestControllerErrorMessage: {
|
|
5
|
+
readonly API_REQUEST_FAILED: 'API request failed';
|
|
6
|
+
readonly API_INVALID_RESPONSE: 'API returned invalid response';
|
|
7
|
+
readonly INVALID_ASSET_IDENTIFIER: 'Invalid asset identifier';
|
|
8
|
+
readonly INVALID_FRONT_PAGE_ID: 'Invalid front page id';
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=ai-digest-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-digest-constants.d.ts","sourceRoot":"","sources":["../src/ai-digest-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,QAAiB,CAAC;AAEhD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,8BAA8B;aACzC,kBAAkB,EAAE,oBAAoB;aACxC,oBAAoB,EAAE,+BAA+B;aACrD,wBAAwB,EAAE,0BAA0B;aACpD,qBAAqB,EAAE,uBAAuB;CACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-digest-constants.js","sourceRoot":"","sources":["../src/ai-digest-constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAE9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,kBAAkB,EAAE,oBAAoB;IACxC,oBAAoB,EAAE,+BAA+B;IACrD,wBAAwB,EAAE,0BAA0B;IACpD,qBAAqB,EAAE,uBAAuB;CACtC,CAAC","sourcesContent":["export const controllerName = 'AiDigestController';\n\nexport const CACHE_DURATION_MS = 10 * 60 * 1000; // 10 minutes\n\nexport const MAX_CACHE_ENTRIES = 50;\n\nexport const AiDigestControllerErrorMessage = {\n API_REQUEST_FAILED: 'API request failed',\n API_INVALID_RESPONSE: 'API returned invalid response',\n INVALID_ASSET_IDENTIFIER: 'Invalid asset identifier',\n INVALID_FRONT_PAGE_ID: 'Invalid front page id',\n} as const;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-digest-types.d.ts","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,OAAO,GAA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,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAEtD;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;CACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-digest-types.js","sourceRoot":"","sources":["../src/ai-digest-types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E","sourcesContent":["// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\n/**\n * A news article referenced by a trend.\n */\nexport type Article = {\n /** Article title */\n title: string;\n /** Full URL to the article */\n url: string;\n /** Source domain name (e.g. \"coindesk.com\") */\n source: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A social media post referenced by a trend.\n */\nexport type Tweet = {\n /** Summary of the tweet content */\n contentSummary: string;\n /** Full URL to the tweet */\n url: string;\n /** Author handle (e.g. \"@saylordocs\") */\n author: string;\n /** ISO date string */\n date: string;\n};\n\n/**\n * A data source used to generate a report.\n */\nexport type Source = {\n /** Source name (e.g. \"CoinDesk\") */\n name: string;\n /** Source URL */\n url: string;\n /** Source type */\n type: 'news' | 'data' | 'social';\n};\n\nexport type MarketInsightsArticle = Article;\nexport type MarketInsightsTweet = Tweet;\nexport type MarketInsightsSource = Source;\n\n// ---------------------------------------------------------------------------\n// Market Insights types (asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A key market trend identified in the insights report.\n */\nexport type MarketInsightsTrend = {\n /** Trend title (e.g. \"Institutions Buying the Dip\") */\n title: string;\n /** Detailed description of the trend */\n description: string;\n /** Category of the trend */\n category:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n /** Impact direction */\n impact: 'positive' | 'negative' | 'neutral';\n /** Related news articles */\n articles: Article[];\n /** Related social media posts */\n tweets: Tweet[];\n};\n\n/**\n * AI-generated market insights report for a crypto asset.\n * Returned by `GET /asset-summary?asset=<identifier>`.\n */\nexport type MarketInsightsReport = {\n /** Unique identifier for this digest, sourced from the API response envelope. */\n digestId: string;\n /** API version */\n version?: string;\n /** Asset symbol (lowercase, e.g. \"btc\") */\n asset: string;\n /** ISO date string when the report was generated */\n generatedAt: string;\n /** Main headline */\n headline: string;\n /** Summary paragraph */\n summary: string;\n /** Key market trends */\n trends: MarketInsightsTrend[];\n /** Optional top-level social posts included by the API */\n social?: Tweet[];\n /** Data sources used to generate the report */\n sources: Source[];\n /** Provider metadata */\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A cached market insights entry.\n */\nexport type MarketInsightsEntry = {\n /** Asset identifier — either a CAIP-19 ID (e.g. \"eip155:1/slip44:60\") or a perps market symbol (e.g. \"ETH\") */\n assetIdentifier: string;\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market insights report data */\n data: MarketInsightsReport;\n};\n\n/**\n * A cached market overview entry.\n */\nexport type MarketOverviewEntry = {\n /** Timestamp when the entry was fetched */\n fetchedAt: number;\n /** The market overview data */\n data: MarketOverview;\n};\n\n// ---------------------------------------------------------------------------\n// Market Overview types (non-asset-specific)\n// ---------------------------------------------------------------------------\n\n/**\n * A crypto asset related to a market overview trend.\n * Returned by the `/market-overview` API as a rich object.\n */\nexport type RelatedAsset = {\n /**\n * Human-readable asset name (e.g. \"Bitcoin\"). Optional — clients must fall\n * back to `symbol` when absent.\n */\n name?: string;\n /** Ticker symbol (e.g. \"BTC\"). The only field guaranteed to be present. */\n symbol: string;\n /**\n * CAIP-19 identifiers for this asset across chains. May be absent for\n * purely synthetic / perps-only assets (e.g. ETHFI). The service\n * normalises missing values to `[]`.\n */\n caip19?: string[];\n /**\n * Canonical source asset identifier (e.g. \"bitcoin\"). Optional — may be\n * absent when the API pipeline cannot enrich the asset record.\n */\n sourceAssetId?: string;\n /**\n * Optional HyperLiquid market identifiers for this asset (e.g. `BTC`, `ETH`,\n * `xyz:TSLA`). Covers both regular crypto tokens that trade on HyperLiquid\n * and purely synthetic perps assets. Use this to resolve Perps icon URLs via\n * `getAssetIconUrls` on clients when `caip19` is empty.\n */\n hlPerpsMarket?: string[];\n};\n\nexport type MarketOverviewTrend = {\n title: string;\n description: string;\n category?:\n | 'geopolitical'\n | 'macro'\n | 'regulatory'\n | 'technical'\n | 'social'\n | 'other';\n impact?: 'positive' | 'negative' | 'neutral';\n articles: Article[];\n relatedAssets: RelatedAsset[];\n};\n\n/**\n * Provider metadata included in AI API responses.\n */\nexport type AIResponseMetadata = {\n provider: string;\n};\n\nexport type MarketOverview = {\n version?: string;\n generatedAt: string;\n trends: MarketOverviewTrend[];\n metadata?: AIResponseMetadata[];\n};\n\n/**\n * A single market overview item. Shares the exact same schema as a\n * {@link MarketOverviewTrend} — i.e. one entry of `MarketOverview.trends`.\n */\nexport type MarketOverviewItem = MarketOverviewTrend;\n\n/**\n * A market overview \"front page\": a single AI-selected item (mirroring the\n * front page of a newspaper) plus its call-to-action copy, addressable by id.\n *\n * Returned by `GET /market-overview/front-page/:id` (and `.../latest`). Unlike\n * `/market-overview`, which only ever returns the latest report, this lets\n * clients fetch an older item that has since dropped out of the report.\n */\nexport type MarketOverviewFrontPage = {\n /** Unique identifier of the front-page row (UUID). */\n id: string;\n /** The selected item — same schema as an individual market overview item. */\n item: MarketOverviewItem;\n /** Call-to-action title for the front-page item. */\n ctaTitle: string;\n /** Call-to-action description for the front-page item. */\n ctaDescription: string;\n /** ISO date string when the front-page row was created. */\n createdAt: string;\n};\n\n// ---------------------------------------------------------------------------\n// Controller state\n// ---------------------------------------------------------------------------\n\nexport type AiDigestControllerState = {\n marketInsights: Record<string, MarketInsightsEntry>;\n marketOverview: MarketOverviewEntry | null;\n};\n\n// ---------------------------------------------------------------------------\n// Service interface\n// ---------------------------------------------------------------------------\n\nexport type DigestService = {\n /**\n * Search for market insights by asset identifier.\n *\n * Accepts any identifier the API understands — CAIP-19 asset type\n * (e.g. `eip155:1/slip44:60`), ticker symbol (e.g. `ETH`), asset name\n * (e.g. `Bitcoin`), or HyperLiquid perps market id (e.g. `xyz:TSLA`).\n *\n * Calls `GET /asset-summary?asset=<assetIdentifier>`.\n *\n * @param assetIdentifier - The asset identifier.\n * @returns The market insights report, or `null` if no insights exist (404).\n */\n searchDigest(assetIdentifier: string): Promise<MarketInsightsReport | null>;\n\n /**\n * Fetch the market overview report.\n * Calls `GET /market-overview`.\n *\n * @returns The market overview report, or `null` if none exists (404).\n */\n fetchMarketOverview(): Promise<MarketOverview | null>;\n\n /**\n * Fetch a single market overview front page by id.\n * Calls `GET /market-overview/front-page/:id`.\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists (404).\n */\n fetchFrontPageItem(id: string): Promise<MarketOverviewFrontPage | null>;\n};\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from
|
|
2
|
-
export { AiDigestController, getDefaultAiDigestControllerState, } from
|
|
3
|
-
export type { AiDigestControllerFetchMarketInsightsAction, AiDigestControllerFetchMarketOverviewAction, AiDigestControllerFetchFrontPageItemAction, } from
|
|
4
|
-
export type { AiDigestServiceConfig } from
|
|
5
|
-
export { AiDigestService } from
|
|
6
|
-
export type { AiDigestControllerState, AIResponseMetadata, Article, DigestService, MarketInsightsArticle, MarketInsightsEntry, MarketInsightsReport, MarketInsightsSource, MarketInsightsTrend, MarketInsightsTweet, MarketOverview, MarketOverviewEntry, MarketOverviewFrontPage, MarketOverviewItem, MarketOverviewTrend, RelatedAsset, Source, Tweet, } from
|
|
7
|
-
export { controllerName as aiDigestControllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, AiDigestControllerErrorMessage, } from
|
|
8
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export type { AiDigestControllerActions, AiDigestControllerEvents, AiDigestControllerGetStateAction, AiDigestControllerMessenger, AiDigestControllerOptions, AiDigestControllerStateChangeEvent, } from './AiDigestController.js';
|
|
2
|
+
export { AiDigestController, getDefaultAiDigestControllerState, } from './AiDigestController.js';
|
|
3
|
+
export type { AiDigestControllerFetchMarketInsightsAction, AiDigestControllerFetchMarketOverviewAction, AiDigestControllerFetchFrontPageItemAction, } from './AiDigestController-method-action-types.js';
|
|
4
|
+
export type { AiDigestServiceConfig } from './AiDigestService.js';
|
|
5
|
+
export { AiDigestService } from './AiDigestService.js';
|
|
6
|
+
export type { AiDigestControllerState, AIResponseMetadata, Article, DigestService, MarketInsightsArticle, MarketInsightsEntry, MarketInsightsReport, MarketInsightsSource, MarketInsightsTrend, MarketInsightsTweet, MarketOverview, MarketOverviewEntry, MarketOverviewFrontPage, MarketOverviewItem, MarketOverviewTrend, RelatedAsset, Source, Tweet, } from './ai-digest-types.js';
|
|
7
|
+
export { controllerName as aiDigestControllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, AiDigestControllerErrorMessage, } from './ai-digest-constants.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,GACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,0CAA0C,GAC3C,MAAM,6CAA6C,CAAC;AAErD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,KAAK,GACN,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,IAAI,sBAAsB,EACxC,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AiDigestController, getDefaultAiDigestControllerState, } from './AiDigestController.js';
|
|
2
|
+
export { AiDigestService } from './AiDigestService.js';
|
|
3
|
+
export { controllerName as aiDigestControllerName, CACHE_DURATION_MS, MAX_CACHE_ENTRIES, AiDigestControllerErrorMessage, } from './ai-digest-constants.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AAQjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAuBvD,OAAO,EACL,cAAc,IAAI,sBAAsB,EACxC,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC","sourcesContent":["export type {\n AiDigestControllerActions,\n AiDigestControllerEvents,\n AiDigestControllerGetStateAction,\n AiDigestControllerMessenger,\n AiDigestControllerOptions,\n AiDigestControllerStateChangeEvent,\n} from './AiDigestController.js';\nexport {\n AiDigestController,\n getDefaultAiDigestControllerState,\n} from './AiDigestController.js';\nexport type {\n AiDigestControllerFetchMarketInsightsAction,\n AiDigestControllerFetchMarketOverviewAction,\n AiDigestControllerFetchFrontPageItemAction,\n} from './AiDigestController-method-action-types.js';\n\nexport type { AiDigestServiceConfig } from './AiDigestService.js';\nexport { AiDigestService } from './AiDigestService.js';\n\nexport type {\n AiDigestControllerState,\n AIResponseMetadata,\n Article,\n DigestService,\n MarketInsightsArticle,\n MarketInsightsEntry,\n MarketInsightsReport,\n MarketInsightsSource,\n MarketInsightsTrend,\n MarketInsightsTweet,\n MarketOverview,\n MarketOverviewEntry,\n MarketOverviewFrontPage,\n MarketOverviewItem,\n MarketOverviewTrend,\n RelatedAsset,\n Source,\n Tweet,\n} from './ai-digest-types.js';\n\nexport {\n controllerName as aiDigestControllerName,\n CACHE_DURATION_MS,\n MAX_CACHE_ENTRIES,\n AiDigestControllerErrorMessage,\n} from './ai-digest-constants.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/ai-controllers",
|
|
3
|
-
"version": "0.8.0-preview-
|
|
3
|
+
"version": "0.8.0-preview-3866c0ff1",
|
|
4
4
|
"description": "A collection of AI-related controllers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/ai-controllers",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/ai-controllers",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -62,17 +57,18 @@
|
|
|
62
57
|
},
|
|
63
58
|
"devDependencies": {
|
|
64
59
|
"@metamask/auto-changelog": "^6.1.0",
|
|
65
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
66
60
|
"@types/jest": "^30.0.0",
|
|
61
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
67
62
|
"deepmerge": "^4.2.2",
|
|
68
63
|
"jest": "^30.4.2",
|
|
64
|
+
"rimraf": "^5.0.5",
|
|
69
65
|
"ts-jest": "^29.4.11",
|
|
70
66
|
"tsx": "^4.20.5",
|
|
71
67
|
"typedoc": "^0.25.13",
|
|
72
68
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
73
|
-
"typescript": "
|
|
69
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
74
70
|
},
|
|
75
71
|
"engines": {
|
|
76
|
-
"node": "^
|
|
72
|
+
"node": "^22.14.0 || ^24"
|
|
77
73
|
}
|
|
78
74
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController-method-action-types.cjs","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AiDigestController } from './AiDigestController.js';\n\n/**\n * Fetches market insights for a given asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps\n * market symbol (e.g. `ETH`). The service handles choosing the correct API\n * query parameter automatically.\n *\n * @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).\n * @returns The market insights report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `AiDigestController:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\n/**\n * Fetches the market overview report.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @returns The market overview report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketOverviewAction = {\n type: `AiDigestController:fetchMarketOverview`;\n handler: AiDigestController['fetchMarketOverview'];\n};\n\n/**\n * Fetches a single market overview front page by id.\n *\n * Unlike the market overview report (which only returns the latest items),\n * this resolves an older item that has since dropped out of the report, so\n * clients can render it directly (e.g. from a deep link).\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists.\n */\nexport type AiDigestControllerFetchFrontPageItemAction = {\n type: `AiDigestController:fetchFrontPageItem`;\n handler: AiDigestController['fetchFrontPageItem'];\n};\n\n/**\n * Union of all AiDigestController action types.\n */\nexport type AiDigestControllerMethodActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerFetchMarketOverviewAction\n | AiDigestControllerFetchFrontPageItemAction;\n"]}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { AiDigestController } from "./AiDigestController.cjs";
|
|
6
|
-
/**
|
|
7
|
-
* Fetches market insights for a given asset identifier.
|
|
8
|
-
* Returns cached data if still fresh, otherwise calls the service.
|
|
9
|
-
*
|
|
10
|
-
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
11
|
-
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
12
|
-
* query parameter automatically.
|
|
13
|
-
*
|
|
14
|
-
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
15
|
-
* @returns The market insights report, or `null` if none exists.
|
|
16
|
-
*/
|
|
17
|
-
export type AiDigestControllerFetchMarketInsightsAction = {
|
|
18
|
-
type: `AiDigestController:fetchMarketInsights`;
|
|
19
|
-
handler: AiDigestController['fetchMarketInsights'];
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Fetches the market overview report.
|
|
23
|
-
* Returns cached data if still fresh, otherwise calls the service.
|
|
24
|
-
*
|
|
25
|
-
* @returns The market overview report, or `null` if none exists.
|
|
26
|
-
*/
|
|
27
|
-
export type AiDigestControllerFetchMarketOverviewAction = {
|
|
28
|
-
type: `AiDigestController:fetchMarketOverview`;
|
|
29
|
-
handler: AiDigestController['fetchMarketOverview'];
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Fetches a single market overview front page by id.
|
|
33
|
-
*
|
|
34
|
-
* Unlike the market overview report (which only returns the latest items),
|
|
35
|
-
* this resolves an older item that has since dropped out of the report, so
|
|
36
|
-
* clients can render it directly (e.g. from a deep link).
|
|
37
|
-
*
|
|
38
|
-
* @param id - The front-page identifier (UUID).
|
|
39
|
-
* @returns The market overview front page, or `null` if none exists.
|
|
40
|
-
*/
|
|
41
|
-
export type AiDigestControllerFetchFrontPageItemAction = {
|
|
42
|
-
type: `AiDigestController:fetchFrontPageItem`;
|
|
43
|
-
handler: AiDigestController['fetchFrontPageItem'];
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Union of all AiDigestController action types.
|
|
47
|
-
*/
|
|
48
|
-
export type AiDigestControllerMethodActions = AiDigestControllerFetchMarketInsightsAction | AiDigestControllerFetchMarketOverviewAction | AiDigestControllerFetchFrontPageItemAction;
|
|
49
|
-
//# sourceMappingURL=AiDigestController-method-action-types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAAgC;AAElE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,2CAA2C,GAC3C,2CAA2C,GAC3C,0CAA0C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAAgC;AAElE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,2CAA2C,GAC3C,2CAA2C,GAC3C,0CAA0C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiDigestController-method-action-types.mjs","sourceRoot":"","sources":["../src/AiDigestController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AiDigestController } from './AiDigestController.js';\n\n/**\n * Fetches market insights for a given asset identifier.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps\n * market symbol (e.g. `ETH`). The service handles choosing the correct API\n * query parameter automatically.\n *\n * @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).\n * @returns The market insights report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketInsightsAction = {\n type: `AiDigestController:fetchMarketInsights`;\n handler: AiDigestController['fetchMarketInsights'];\n};\n\n/**\n * Fetches the market overview report.\n * Returns cached data if still fresh, otherwise calls the service.\n *\n * @returns The market overview report, or `null` if none exists.\n */\nexport type AiDigestControllerFetchMarketOverviewAction = {\n type: `AiDigestController:fetchMarketOverview`;\n handler: AiDigestController['fetchMarketOverview'];\n};\n\n/**\n * Fetches a single market overview front page by id.\n *\n * Unlike the market overview report (which only returns the latest items),\n * this resolves an older item that has since dropped out of the report, so\n * clients can render it directly (e.g. from a deep link).\n *\n * @param id - The front-page identifier (UUID).\n * @returns The market overview front page, or `null` if none exists.\n */\nexport type AiDigestControllerFetchFrontPageItemAction = {\n type: `AiDigestController:fetchFrontPageItem`;\n handler: AiDigestController['fetchFrontPageItem'];\n};\n\n/**\n * Union of all AiDigestController action types.\n */\nexport type AiDigestControllerMethodActions =\n | AiDigestControllerFetchMarketInsightsAction\n | AiDigestControllerFetchMarketOverviewAction\n | AiDigestControllerFetchFrontPageItemAction;\n"]}
|