@metamask-previews/ai-controllers 0.8.0-preview-3866c0ff1 → 0.8.0-preview-e3275932a
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 +7 -1
- package/dist/AiDigestController-method-action-types.cjs +7 -0
- package/dist/AiDigestController-method-action-types.cjs.map +1 -0
- package/dist/{AiDigestController-method-action-types.d.ts → AiDigestController-method-action-types.d.cts} +5 -5
- package/dist/AiDigestController-method-action-types.d.cts.map +1 -0
- package/dist/AiDigestController-method-action-types.d.mts +49 -0
- package/dist/AiDigestController-method-action-types.d.mts.map +1 -0
- package/dist/{AiDigestController-method-action-types.js → AiDigestController-method-action-types.mjs} +1 -1
- package/dist/AiDigestController-method-action-types.mjs.map +1 -0
- package/dist/AiDigestController.cjs +85 -0
- package/dist/AiDigestController.cjs.map +1 -0
- package/dist/{AiDigestController.d.ts → AiDigestController.d.cts} +11 -12
- package/dist/AiDigestController.d.cts.map +1 -0
- package/dist/AiDigestController.d.mts +51 -0
- package/dist/AiDigestController.d.mts.map +1 -0
- package/dist/AiDigestController.mjs +80 -0
- package/dist/AiDigestController.mjs.map +1 -0
- package/dist/AiDigestService.cjs +217 -0
- package/dist/AiDigestService.cjs.map +1 -0
- package/dist/{AiDigestService.d.ts → AiDigestService.d.cts} +2 -2
- package/dist/AiDigestService.d.cts.map +1 -0
- package/dist/AiDigestService.d.mts +40 -0
- package/dist/AiDigestService.d.mts.map +1 -0
- package/dist/{AiDigestService.js → AiDigestService.mjs} +21 -8
- package/dist/AiDigestService.mjs.map +1 -0
- package/dist/ai-digest-constants.cjs +11 -0
- package/dist/ai-digest-constants.cjs.map +1 -0
- package/dist/ai-digest-constants.d.cts +8 -0
- package/dist/ai-digest-constants.d.cts.map +1 -0
- package/dist/ai-digest-constants.d.mts +8 -0
- package/dist/ai-digest-constants.d.mts.map +1 -0
- package/dist/{ai-digest-constants.js → ai-digest-constants.mjs} +1 -3
- package/dist/ai-digest-constants.mjs.map +1 -0
- package/dist/ai-digest-types.cjs +6 -0
- package/dist/ai-digest-types.cjs.map +1 -0
- package/dist/{ai-digest-types.d.ts → ai-digest-types.d.cts} +6 -25
- package/dist/ai-digest-types.d.cts.map +1 -0
- package/dist/ai-digest-types.d.mts +195 -0
- package/dist/ai-digest-types.d.mts.map +1 -0
- package/dist/{ai-digest-types.js → ai-digest-types.mjs} +1 -1
- package/dist/ai-digest-types.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -12
- package/dist/AiDigestController-method-action-types.d.ts.map +0 -1
- package/dist/AiDigestController-method-action-types.js.map +0 -1
- package/dist/AiDigestController.d.ts.map +0 -1
- package/dist/AiDigestController.js +0 -160
- package/dist/AiDigestController.js.map +0 -1
- package/dist/AiDigestService.d.ts.map +0 -1
- package/dist/AiDigestService.js.map +0 -1
- package/dist/ai-digest-constants.d.ts +0 -10
- package/dist/ai-digest-constants.d.ts.map +0 -1
- package/dist/ai-digest-constants.js.map +0 -1
- package/dist/ai-digest-types.d.ts.map +0 -1
- package/dist/ai-digest-types.js.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,9 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
-
- **BREAKING:**
|
|
12
|
+
- **BREAKING:** `AiDigestController` no longer caches `fetchMarketInsights` or `fetchMarketOverview` results (no TTL, eviction, or persisted `marketInsights` / `marketOverview` state). Each call is a passthrough to `AiDigestService`. Clients must own freshness.
|
|
13
|
+
- `AiDigestControllerState` is now an empty object (`Record<string, never>`).
|
|
14
|
+
- The constructor no longer accepts a `state` option.
|
|
13
15
|
- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#9754](https://github.com/MetaMask/core/pull/9754))
|
|
14
16
|
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Remove `MarketInsightsEntry`, `MarketOverviewEntry`, `CACHE_DURATION_MS`, and `MAX_CACHE_ENTRIES`. Cache policy belongs to clients.
|
|
20
|
+
|
|
15
21
|
## [0.8.0]
|
|
16
22
|
|
|
17
23
|
### Added
|
|
@@ -0,0 +1 @@
|
|
|
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 *\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. Clients own freshness/caching.\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 *\n * Clients own freshness/caching.\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"]}
|
|
@@ -2,14 +2,13 @@
|
|
|
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.cjs";
|
|
6
6
|
/**
|
|
7
7
|
* Fetches market insights for a given asset identifier.
|
|
8
|
-
* Returns cached data if still fresh, otherwise calls the service.
|
|
9
8
|
*
|
|
10
9
|
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
11
10
|
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
12
|
-
* query parameter automatically.
|
|
11
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
13
12
|
*
|
|
14
13
|
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
15
14
|
* @returns The market insights report, or `null` if none exists.
|
|
@@ -20,7 +19,8 @@ export type AiDigestControllerFetchMarketInsightsAction = {
|
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
21
|
* Fetches the market overview report.
|
|
23
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* Clients own freshness/caching.
|
|
24
24
|
*
|
|
25
25
|
* @returns The market overview report, or `null` if none exists.
|
|
26
26
|
*/
|
|
@@ -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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;;;;;GASG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;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,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { AiDigestController } from "./AiDigestController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches market insights for a given asset identifier.
|
|
8
|
+
*
|
|
9
|
+
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
10
|
+
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
11
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
12
|
+
*
|
|
13
|
+
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
14
|
+
* @returns The market insights report, or `null` if none exists.
|
|
15
|
+
*/
|
|
16
|
+
export type AiDigestControllerFetchMarketInsightsAction = {
|
|
17
|
+
type: `AiDigestController:fetchMarketInsights`;
|
|
18
|
+
handler: AiDigestController['fetchMarketInsights'];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Fetches the market overview report.
|
|
22
|
+
*
|
|
23
|
+
* Clients own freshness/caching.
|
|
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;;;;;GASG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;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.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 *\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. Clients own freshness/caching.\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 *\n * Clients own freshness/caching.\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"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _AiDigestController_digestService;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AiDigestController = exports.getDefaultAiDigestControllerState = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const ai_digest_constants_js_1 = require("./ai-digest-constants.cjs");
|
|
18
|
+
function getDefaultAiDigestControllerState() {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
exports.getDefaultAiDigestControllerState = getDefaultAiDigestControllerState;
|
|
22
|
+
const aiDigestControllerMetadata = {};
|
|
23
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
24
|
+
'fetchMarketInsights',
|
|
25
|
+
'fetchMarketOverview',
|
|
26
|
+
'fetchFrontPageItem',
|
|
27
|
+
];
|
|
28
|
+
class AiDigestController extends base_controller_1.BaseController {
|
|
29
|
+
constructor({ messenger, digestService }) {
|
|
30
|
+
super({
|
|
31
|
+
name: ai_digest_constants_js_1.controllerName,
|
|
32
|
+
metadata: aiDigestControllerMetadata,
|
|
33
|
+
state: getDefaultAiDigestControllerState(),
|
|
34
|
+
messenger,
|
|
35
|
+
});
|
|
36
|
+
_AiDigestController_digestService.set(this, void 0);
|
|
37
|
+
__classPrivateFieldSet(this, _AiDigestController_digestService, digestService, "f");
|
|
38
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fetches market insights for a given asset identifier.
|
|
42
|
+
*
|
|
43
|
+
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
44
|
+
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
45
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
46
|
+
*
|
|
47
|
+
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
48
|
+
* @returns The market insights report, or `null` if none exists.
|
|
49
|
+
*/
|
|
50
|
+
async fetchMarketInsights(assetIdentifier) {
|
|
51
|
+
if (!assetIdentifier) {
|
|
52
|
+
throw new Error(ai_digest_constants_js_1.AiDigestControllerErrorMessage.INVALID_ASSET_IDENTIFIER);
|
|
53
|
+
}
|
|
54
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").searchDigest(assetIdentifier);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetches the market overview report.
|
|
58
|
+
*
|
|
59
|
+
* Clients own freshness/caching.
|
|
60
|
+
*
|
|
61
|
+
* @returns The market overview report, or `null` if none exists.
|
|
62
|
+
*/
|
|
63
|
+
async fetchMarketOverview() {
|
|
64
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchMarketOverview();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Fetches a single market overview front page by id.
|
|
68
|
+
*
|
|
69
|
+
* Unlike the market overview report (which only returns the latest items),
|
|
70
|
+
* this resolves an older item that has since dropped out of the report, so
|
|
71
|
+
* clients can render it directly (e.g. from a deep link).
|
|
72
|
+
*
|
|
73
|
+
* @param id - The front-page identifier (UUID).
|
|
74
|
+
* @returns The market overview front page, or `null` if none exists.
|
|
75
|
+
*/
|
|
76
|
+
async fetchFrontPageItem(id) {
|
|
77
|
+
if (!id) {
|
|
78
|
+
throw new Error(ai_digest_constants_js_1.AiDigestControllerErrorMessage.INVALID_FRONT_PAGE_ID);
|
|
79
|
+
}
|
|
80
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchFrontPageItem(id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.AiDigestController = AiDigestController;
|
|
84
|
+
_AiDigestController_digestService = new WeakMap();
|
|
85
|
+
//# sourceMappingURL=AiDigestController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.cjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAG3D,sEAGkC;AAqClC,SAAgB,iCAAiC;IAC/C,OAAO,EAAE,CAAC;AACZ,CAAC;AAFD,8EAEC;AAED,MAAM,0BAA0B,GAA2C,EAAE,CAAC;AAE9E,MAAM,yBAAyB,GAAG;IAChC,qBAAqB;IACrB,qBAAqB;IACrB,oBAAoB;CACZ,CAAC;AAEX,MAAa,kBAAmB,SAAQ,gCAIvC;IAGC,YAAY,EAAE,SAAS,EAAE,aAAa,EAA6B;QACjE,KAAK,CAAC;YACJ,IAAI,EAAE,uCAAc;YACpB,QAAQ,EAAE,0BAA0B;YACpC,KAAK,EAAE,iCAAiC,EAAE;YAC1C,SAAS;SACV,CAAC,CAAC;QARI,oDAA8B;QAUrC,uBAAA,IAAI,qCAAkB,aAAa,MAAA,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,mBAAmB,CACvB,eAAuB;QAEvB,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,uDAA8B,CAAC,wBAAwB,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,uBAAA,IAAI,yCAAe,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,yCAAe,CAAC,mBAAmB,EAAE,CAAC;IACnD,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,kBAAkB,CACtB,EAAU;QAEV,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,uDAA8B,CAAC,qBAAqB,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,uBAAA,IAAI,yCAAe,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AAxED,gDAwEC","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} from './ai-digest-constants.js';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketOverview,\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 digestService: DigestService;\n};\n\nexport function getDefaultAiDigestControllerState(): AiDigestControllerState {\n return {};\n}\n\nconst aiDigestControllerMetadata: StateMetadata<AiDigestControllerState> = {};\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, digestService }: AiDigestControllerOptions) {\n super({\n name: controllerName,\n metadata: aiDigestControllerMetadata,\n state: getDefaultAiDigestControllerState(),\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 *\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. Clients own freshness/caching.\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 return this.#digestService.searchDigest(assetIdentifier);\n }\n\n /**\n * Fetches the market overview report.\n *\n * Clients own freshness/caching.\n *\n * @returns The market overview report, or `null` if none exists.\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n return this.#digestService.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 */\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"]}
|
|
@@ -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.cjs";
|
|
5
|
+
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from "./ai-digest-types.cjs";
|
|
6
|
+
import type { AiDigestControllerMethodActions } from "./AiDigestController-method-action-types.cjs";
|
|
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>;
|
|
@@ -11,20 +11,18 @@ export type AiDigestControllerEvents = AiDigestControllerStateChangeEvent;
|
|
|
11
11
|
export type AiDigestControllerMessenger = Messenger<typeof controllerName, AiDigestControllerActions, AiDigestControllerEvents>;
|
|
12
12
|
export type AiDigestControllerOptions = {
|
|
13
13
|
messenger: AiDigestControllerMessenger;
|
|
14
|
-
state?: Partial<AiDigestControllerState>;
|
|
15
14
|
digestService: DigestService;
|
|
16
15
|
};
|
|
17
16
|
export declare function getDefaultAiDigestControllerState(): AiDigestControllerState;
|
|
18
17
|
export declare class AiDigestController extends BaseController<typeof controllerName, AiDigestControllerState, AiDigestControllerMessenger> {
|
|
19
18
|
#private;
|
|
20
|
-
constructor({ messenger,
|
|
19
|
+
constructor({ messenger, digestService }: AiDigestControllerOptions);
|
|
21
20
|
/**
|
|
22
21
|
* Fetches market insights for a given asset identifier.
|
|
23
|
-
* Returns cached data if still fresh, otherwise calls the service.
|
|
24
22
|
*
|
|
25
23
|
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
26
24
|
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
27
|
-
* query parameter automatically.
|
|
25
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
28
26
|
*
|
|
29
27
|
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
30
28
|
* @returns The market insights report, or `null` if none exists.
|
|
@@ -32,7 +30,8 @@ export declare class AiDigestController extends BaseController<typeof controller
|
|
|
32
30
|
fetchMarketInsights(assetIdentifier: string): Promise<MarketInsightsReport | null>;
|
|
33
31
|
/**
|
|
34
32
|
* Fetches the market overview report.
|
|
35
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* Clients own freshness/caching.
|
|
36
35
|
*
|
|
37
36
|
* @returns The market overview report, or `null` if none exists.
|
|
38
37
|
*/
|
|
@@ -49,4 +48,4 @@ export declare class AiDigestController extends BaseController<typeof controller
|
|
|
49
48
|
*/
|
|
50
49
|
fetchFrontPageItem(id: string): Promise<MarketOverviewFrontPage | null>;
|
|
51
50
|
}
|
|
52
|
-
//# sourceMappingURL=AiDigestController.d.
|
|
51
|
+
//# sourceMappingURL=AiDigestController.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.d.cts","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAEL,cAAc,EACf,kCAAiC;AAClC,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACxB,8BAA6B;AAC9B,OAAO,KAAK,EAAE,+BAA+B,EAAE,qDAAoD;AAEnG,MAAM,MAAM,gCAAgC,GAAG,wBAAwB,CACrE,OAAO,cAAc,EACrB,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,gCAAgC,GAChC,+BAA+B,CAAC;AAEpC,MAAM,MAAM,kCAAkC,GAAG,0BAA0B,CACzE,OAAO,cAAc,EACrB,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,kCAAkC,CAAC;AAE1E,MAAM,MAAM,2BAA2B,GAAG,SAAS,CACjD,OAAO,cAAc,EACrB,yBAAyB,EACzB,wBAAwB,CACzB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,2BAA2B,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,wBAAgB,iCAAiC,IAAI,uBAAuB,CAE3E;AAUD,qBAAa,kBAAmB,SAAQ,cAAc,CACpD,OAAO,cAAc,EACrB,uBAAuB,EACvB,2BAA2B,CAC5B;;gBAGa,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,yBAAyB;IAenE;;;;;;;;;OASG;IACG,mBAAmB,CACvB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAQvC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI3D;;;;;;;;;OASG;IACG,kBAAkB,CACtB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;CAO3C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.mjs";
|
|
5
|
+
import type { AiDigestControllerState, DigestService, MarketInsightsReport, MarketOverview, MarketOverviewFrontPage } from "./ai-digest-types.mjs";
|
|
6
|
+
import type { AiDigestControllerMethodActions } from "./AiDigestController-method-action-types.mjs";
|
|
7
|
+
export type AiDigestControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AiDigestControllerState>;
|
|
8
|
+
export type AiDigestControllerActions = AiDigestControllerGetStateAction | AiDigestControllerMethodActions;
|
|
9
|
+
export type AiDigestControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AiDigestControllerState>;
|
|
10
|
+
export type AiDigestControllerEvents = AiDigestControllerStateChangeEvent;
|
|
11
|
+
export type AiDigestControllerMessenger = Messenger<typeof controllerName, AiDigestControllerActions, AiDigestControllerEvents>;
|
|
12
|
+
export type AiDigestControllerOptions = {
|
|
13
|
+
messenger: AiDigestControllerMessenger;
|
|
14
|
+
digestService: DigestService;
|
|
15
|
+
};
|
|
16
|
+
export declare function getDefaultAiDigestControllerState(): AiDigestControllerState;
|
|
17
|
+
export declare class AiDigestController extends BaseController<typeof controllerName, AiDigestControllerState, AiDigestControllerMessenger> {
|
|
18
|
+
#private;
|
|
19
|
+
constructor({ messenger, digestService }: AiDigestControllerOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Fetches market insights for a given asset identifier.
|
|
22
|
+
*
|
|
23
|
+
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
24
|
+
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
25
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
26
|
+
*
|
|
27
|
+
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
28
|
+
* @returns The market insights report, or `null` if none exists.
|
|
29
|
+
*/
|
|
30
|
+
fetchMarketInsights(assetIdentifier: string): Promise<MarketInsightsReport | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetches the market overview report.
|
|
33
|
+
*
|
|
34
|
+
* Clients own freshness/caching.
|
|
35
|
+
*
|
|
36
|
+
* @returns The market overview report, or `null` if none exists.
|
|
37
|
+
*/
|
|
38
|
+
fetchMarketOverview(): Promise<MarketOverview | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Fetches a single market overview front page by id.
|
|
41
|
+
*
|
|
42
|
+
* Unlike the market overview report (which only returns the latest items),
|
|
43
|
+
* this resolves an older item that has since dropped out of the report, so
|
|
44
|
+
* clients can render it directly (e.g. from a deep link).
|
|
45
|
+
*
|
|
46
|
+
* @param id - The front-page identifier (UUID).
|
|
47
|
+
* @returns The market overview front page, or `null` if none exists.
|
|
48
|
+
*/
|
|
49
|
+
fetchFrontPageItem(id: string): Promise<MarketOverviewFrontPage | null>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=AiDigestController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.d.mts","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAEL,cAAc,EACf,kCAAiC;AAClC,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACxB,8BAA6B;AAC9B,OAAO,KAAK,EAAE,+BAA+B,EAAE,qDAAoD;AAEnG,MAAM,MAAM,gCAAgC,GAAG,wBAAwB,CACrE,OAAO,cAAc,EACrB,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,gCAAgC,GAChC,+BAA+B,CAAC;AAEpC,MAAM,MAAM,kCAAkC,GAAG,0BAA0B,CACzE,OAAO,cAAc,EACrB,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,kCAAkC,CAAC;AAE1E,MAAM,MAAM,2BAA2B,GAAG,SAAS,CACjD,OAAO,cAAc,EACrB,yBAAyB,EACzB,wBAAwB,CACzB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,2BAA2B,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,wBAAgB,iCAAiC,IAAI,uBAAuB,CAE3E;AAUD,qBAAa,kBAAmB,SAAQ,cAAc,CACpD,OAAO,cAAc,EACrB,uBAAuB,EACvB,2BAA2B,CAC5B;;gBAGa,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,yBAAyB;IAenE;;;;;;;;;OASG;IACG,mBAAmB,CACvB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAQvC;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI3D;;;;;;;;;OASG;IACG,kBAAkB,CACtB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;CAO3C"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
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_digestService;
|
|
13
|
+
import { BaseController } from "@metamask/base-controller";
|
|
14
|
+
import { AiDigestControllerErrorMessage, controllerName } from "./ai-digest-constants.mjs";
|
|
15
|
+
export function getDefaultAiDigestControllerState() {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const aiDigestControllerMetadata = {};
|
|
19
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
20
|
+
'fetchMarketInsights',
|
|
21
|
+
'fetchMarketOverview',
|
|
22
|
+
'fetchFrontPageItem',
|
|
23
|
+
];
|
|
24
|
+
export class AiDigestController extends BaseController {
|
|
25
|
+
constructor({ messenger, digestService }) {
|
|
26
|
+
super({
|
|
27
|
+
name: controllerName,
|
|
28
|
+
metadata: aiDigestControllerMetadata,
|
|
29
|
+
state: getDefaultAiDigestControllerState(),
|
|
30
|
+
messenger,
|
|
31
|
+
});
|
|
32
|
+
_AiDigestController_digestService.set(this, void 0);
|
|
33
|
+
__classPrivateFieldSet(this, _AiDigestController_digestService, digestService, "f");
|
|
34
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetches market insights for a given asset identifier.
|
|
38
|
+
*
|
|
39
|
+
* Accepts either a CAIP-19 asset type (e.g. `eip155:1/slip44:60`) or a perps
|
|
40
|
+
* market symbol (e.g. `ETH`). The service handles choosing the correct API
|
|
41
|
+
* query parameter automatically. Clients own freshness/caching.
|
|
42
|
+
*
|
|
43
|
+
* @param assetIdentifier - The asset identifier (CAIP-19 ID or perps market symbol).
|
|
44
|
+
* @returns The market insights report, or `null` if none exists.
|
|
45
|
+
*/
|
|
46
|
+
async fetchMarketInsights(assetIdentifier) {
|
|
47
|
+
if (!assetIdentifier) {
|
|
48
|
+
throw new Error(AiDigestControllerErrorMessage.INVALID_ASSET_IDENTIFIER);
|
|
49
|
+
}
|
|
50
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").searchDigest(assetIdentifier);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetches the market overview report.
|
|
54
|
+
*
|
|
55
|
+
* Clients own freshness/caching.
|
|
56
|
+
*
|
|
57
|
+
* @returns The market overview report, or `null` if none exists.
|
|
58
|
+
*/
|
|
59
|
+
async fetchMarketOverview() {
|
|
60
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchMarketOverview();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Fetches a single market overview front page by id.
|
|
64
|
+
*
|
|
65
|
+
* Unlike the market overview report (which only returns the latest items),
|
|
66
|
+
* this resolves an older item that has since dropped out of the report, so
|
|
67
|
+
* clients can render it directly (e.g. from a deep link).
|
|
68
|
+
*
|
|
69
|
+
* @param id - The front-page identifier (UUID).
|
|
70
|
+
* @returns The market overview front page, or `null` if none exists.
|
|
71
|
+
*/
|
|
72
|
+
async fetchFrontPageItem(id) {
|
|
73
|
+
if (!id) {
|
|
74
|
+
throw new Error(AiDigestControllerErrorMessage.INVALID_FRONT_PAGE_ID);
|
|
75
|
+
}
|
|
76
|
+
return __classPrivateFieldGet(this, _AiDigestController_digestService, "f").fetchFrontPageItem(id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
_AiDigestController_digestService = new WeakMap();
|
|
80
|
+
//# sourceMappingURL=AiDigestController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiDigestController.mjs","sourceRoot":"","sources":["../src/AiDigestController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EACL,8BAA8B,EAC9B,cAAc,EACf,kCAAiC;AAqClC,MAAM,UAAU,iCAAiC;IAC/C,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,0BAA0B,GAA2C,EAAE,CAAC;AAE9E,MAAM,yBAAyB,GAAG;IAChC,qBAAqB;IACrB,qBAAqB;IACrB,oBAAoB;CACZ,CAAC;AAEX,MAAM,OAAO,kBAAmB,SAAQ,cAIvC;IAGC,YAAY,EAAE,SAAS,EAAE,aAAa,EAA6B;QACjE,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,0BAA0B;YACpC,KAAK,EAAE,iCAAiC,EAAE;YAC1C,SAAS;SACV,CAAC,CAAC;QARI,oDAA8B;QAUrC,uBAAA,IAAI,qCAAkB,aAAa,MAAA,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,mBAAmB,CACvB,eAAuB;QAEvB,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,wBAAwB,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,uBAAA,IAAI,yCAAe,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,yCAAe,CAAC,mBAAmB,EAAE,CAAC;IACnD,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,kBAAkB,CACtB,EAAU;QAEV,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,qBAAqB,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,uBAAA,IAAI,yCAAe,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACpD,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} from './ai-digest-constants.js';\nimport type {\n AiDigestControllerState,\n DigestService,\n MarketInsightsReport,\n MarketOverview,\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 digestService: DigestService;\n};\n\nexport function getDefaultAiDigestControllerState(): AiDigestControllerState {\n return {};\n}\n\nconst aiDigestControllerMetadata: StateMetadata<AiDigestControllerState> = {};\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, digestService }: AiDigestControllerOptions) {\n super({\n name: controllerName,\n metadata: aiDigestControllerMetadata,\n state: getDefaultAiDigestControllerState(),\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 *\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. Clients own freshness/caching.\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 return this.#digestService.searchDigest(assetIdentifier);\n }\n\n /**\n * Fetches the market overview report.\n *\n * Clients own freshness/caching.\n *\n * @returns The market overview report, or `null` if none exists.\n */\n async fetchMarketOverview(): Promise<MarketOverview | null> {\n return this.#digestService.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 */\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"]}
|